From 166168b5bf84444b3302361ae727936eeb529c53 Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 27 Oct 2022 11:13:04 -0600 Subject: [PATCH] Admin: Push for categories --- admin/inc/class.admin_cmd_customfield.inc.php | 9 ++++- admin/inc/class.admin_customfields.inc.php | 17 ++++----- admin/js/app.ts | 7 +++- api/src/Storage/Customfields.php | 35 +++++++++++++++++++ 4 files changed, 58 insertions(+), 10 deletions(-) diff --git a/admin/inc/class.admin_cmd_customfield.inc.php b/admin/inc/class.admin_cmd_customfield.inc.php index e859f001dc..1985d98957 100644 --- a/admin/inc/class.admin_cmd_customfield.inc.php +++ b/admin/inc/class.admin_cmd_customfield.inc.php @@ -74,9 +74,16 @@ class admin_cmd_customfield extends admin_cmd if(array_keys($this->set) == array('id','name')) { // Delete - $so = new Api\Storage\Base('phpgwapi','egw_customfields',null,'',true); + $so = new Api\Storage\Base('phpgwapi', 'egw_customfields', null, '', true); $so->delete($this->set['id']); $deleted = true; + + $push = new Api\Json\Push(Api\Json\Push::ALL); + $push->apply("egw.push", [[ + 'app' => Api\Storage\Customfields::PUSH_APP, + 'id' => $this->set['id'], + 'type' => 'delete' + ]]); } else { diff --git a/admin/inc/class.admin_customfields.inc.php b/admin/inc/class.admin_customfields.inc.php index dc86bd89de..6484a87310 100644 --- a/admin/inc/class.admin_customfields.inc.php +++ b/admin/inc/class.admin_customfields.inc.php @@ -205,14 +205,15 @@ class admin_customfields { // Initialize nextmatch $content['nm'] = array( - 'get_rows' => 'admin.admin_customfields.get_rows', - 'no_cat' => 'true', - 'no_filter' => 'true', - 'no_filter2' => 'true', - 'row_id' => 'cf_id', - 'order' => 'cf_order',// IO name of the column to sort - 'sort' => 'ASC',// IO direction of the sort: 'ASC' or 'DESC' - 'actions' => $this->get_actions() + 'get_rows' => 'admin.admin_customfields.get_rows', + 'no_cat' => 'true', + 'no_filter' => 'true', + 'no_filter2' => 'true', + 'row_id' => 'cf_id', + 'order' => 'cf_order',// IO name of the column to sort + 'sort' => 'ASC',// IO direction of the sort: 'ASC' or 'DESC' + 'actions' => $this->get_actions(), + 'dataStorePrefix' => 'customfield' ); } $content['nm']['appname'] = $this->appname; diff --git a/admin/js/app.ts b/admin/js/app.ts index bdbdfb850e..185dd65326 100644 --- a/admin/js/app.ts +++ b/admin/js/app.ts @@ -326,12 +326,13 @@ class AdminApp extends EgwApp push(pushData : PushData) { // Filter out what we're not interested in - if([this.appname, "api-cats"].indexOf(pushData.app) == -1) + if([this.appname, "api-cats", "api-cf"].indexOf(pushData.app) == -1) { return; } const cat_template = "admin.categories.index"; + const cf_template = "admin.customfields"; if(this.appname.indexOf(pushData.app) != -1 && pushData.id > 0) { @@ -349,6 +350,10 @@ class AdminApp extends EgwApp { (etemplate2.getByTemplate(cat_template)[0].widgetContainer.getWidgetById("nm")).refresh(pushData.id, pushData.type); } + else if(pushData.app == "api-cf" && etemplate2.getByTemplate(cf_template).length == 1) + { + (etemplate2.getByTemplate(cf_template)[0].widgetContainer.getWidgetById("nm")).refresh(pushData.id, pushData.type); + } } /** diff --git a/api/src/Storage/Customfields.php b/api/src/Storage/Customfields.php index f79028d5f7..09259335c3 100644 --- a/api/src/Storage/Customfields.php +++ b/api/src/Storage/Customfields.php @@ -13,6 +13,7 @@ namespace EGroupware\Api\Storage; use EGroupware\Api; +use EGroupware\Api\Json\Push; /** * Managing custom-field definitions @@ -51,6 +52,11 @@ class Customfields implements \IteratorAggregate */ protected $iterator; + /** + * App name used to push custom field changes + */ + const PUSH_APP = 'api-cf'; + /** * Constructor * @@ -441,6 +447,35 @@ class Customfields implements \IteratorAggregate } self::invalidate_cache($cf['app']); + + // push category change + $type = 'update'; + if(!$cf['id']) + { + $cfs = self::get($cf['app'], true); + $cf = $cfs[$cf['name']]; + $type = 'add'; + } + $accounts = Push::ALL; + if(count($cf['private']) > 0) + { + $accounts = []; + foreach($cf['private'] as $account_id) + { + $accounts = array_merge( + $account_id > 0 ? [$account_id] : + $GLOBALS['egw']->accounts->members($account_id, true) + ); + } + } + $push = new Push($accounts); + $push->apply("egw.push", [[ + 'app' => self::PUSH_APP, + 'id' => $cf['id'], + 'type' => $type, + 'acl' => ['private' => $cf['private']], + 'account_id' => $GLOBALS['egw_info']['user']['account_id'] + ]]); } /**