From 76a5793a0a656f36f7a5112f02c1a80c2fbddf83 Mon Sep 17 00:00:00 2001 From: nathangray Date: Thu, 23 Jan 2020 11:03:29 -0700 Subject: [PATCH] New push method, with base implementation of delete client side --- api/js/jsapi/egw_app.js | 22 +++++++++--------- api/js/jsapi/egw_app.ts | 22 +++++++++--------- api/js/jsapi/egw_message.js | 41 ++++++++++++++++++++++++++++++++- timesheet/js/app.js | 36 ----------------------------- timesheet/js/app.ts | 45 ------------------------------------- 5 files changed, 60 insertions(+), 106 deletions(-) diff --git a/api/js/jsapi/egw_app.js b/api/js/jsapi/egw_app.js index 1f6505c3b9..97ecb4809f 100644 --- a/api/js/jsapi/egw_app.js +++ b/api/js/jsapi/egw_app.js @@ -133,26 +133,24 @@ var EgwApp = /** @class */ (function () { EgwApp.prototype.observer = function (_msg, _app, _id, _type, _msg_type, _links) { }; /** - * Push method receives push notification about updates to entries from the application + * Handle a push notification about entry changes from the websocket * - * It can use the extra _data parameter to determine if the client has read access to - * the entry - if an update of the list is necessary. - * - * @param _type either 'update', 'edit', 'delete', 'add' or null + * @param pushData + * @param {string} pushData.app application name + * @param {(string|number)} pushData.id id of entry to refresh or null + * @param {string} pushData.type either 'update', 'edit', 'delete', 'add' or null * - update: request just modified data from given rows. Sorting is not considered, * so if the sort field is changed, the row will not be moved. * - edit: rows changed, but sorting may be affected. Requires full reload. * - delete: just delete the given rows clientside (no server interaction neccessary) * - add: requires full reload for proper sorting - * @param _app application name incl. sub-type eg. "projectmanager-element" - * @param _id id of entry to refresh or null - * @param _data eg. owner or responsible to decide if update is necessary - * @returns {undefined} + * @param {object|null} pushData.acl Extra data for determining relevance. eg: owner or responsible to decide if update is necessary + * @param {number} pushData.account_id User that caused the notification */ - EgwApp.prototype.push = function (_type, _app, _id, _data) { + EgwApp.prototype.push = function (pushData) { // only handle delete by default, for simple case of uid === "$app::$id" - if (_type === 'delete') { - egw(window).refresh('', _app, _id, "delete"); + if (pushData.type === 'delete') { + egw.dataStoreUID(pushData.app + '::' + pushData.id, null); } }; /** diff --git a/api/js/jsapi/egw_app.ts b/api/js/jsapi/egw_app.ts index ba806540ac..e64e4997dc 100644 --- a/api/js/jsapi/egw_app.ts +++ b/api/js/jsapi/egw_app.ts @@ -204,28 +204,26 @@ export abstract class EgwApp } /** - * Push method receives push notification about updates to entries from the application + * Handle a push notification about entry changes from the websocket * - * It can use the extra _data parameter to determine if the client has read access to - * the entry - if an update of the list is necessary. - * - * @param _type either 'update', 'edit', 'delete', 'add' or null + * @param pushData + * @param {string} pushData.app application name + * @param {(string|number)} pushData.id id of entry to refresh or null + * @param {string} pushData.type either 'update', 'edit', 'delete', 'add' or null * - update: request just modified data from given rows. Sorting is not considered, * so if the sort field is changed, the row will not be moved. * - edit: rows changed, but sorting may be affected. Requires full reload. * - delete: just delete the given rows clientside (no server interaction neccessary) * - add: requires full reload for proper sorting - * @param _app application name incl. sub-type eg. "projectmanager-element" - * @param _id id of entry to refresh or null - * @param _data eg. owner or responsible to decide if update is necessary - * @returns {undefined} + * @param {object|null} pushData.acl Extra data for determining relevance. eg: owner or responsible to decide if update is necessary + * @param {number} pushData.account_id User that caused the notification */ - push(_type : string, _app : string, _id : string|number, _data? : any) + push(pushData) { // only handle delete by default, for simple case of uid === "$app::$id" - if (_type === 'delete') + if (pushData.type === 'delete') { - egw(window).refresh('', _app, _id, "delete"); + egw.dataStoreUID(pushData.app + '::' + pushData.id, null); } } diff --git a/api/js/jsapi/egw_message.js b/api/js/jsapi/egw_message.js index 6095d15e3d..c30c6ba885 100644 --- a/api/js/jsapi/egw_message.js +++ b/api/js/jsapi/egw_message.js @@ -395,6 +395,45 @@ egw.extend('message', egw.MODULE_WND_LOCAL, function(_app, _wnd) } //alert('egw_refresh() about to call '+href); win.location.href = href; - } + }, + + + /** + * Handle a push notification about entry changes from the websocket + * + * @param pushData + * @param {string} pushData.app application name + * @param {(string|number)} pushData.id id of entry to refresh or null + * @param {string} pushData.type either 'update', 'edit', 'delete', 'add' or null + * - update: request just modified data from given rows. Sorting is not considered, + * so if the sort field is changed, the row will not be moved. + * - edit: rows changed, but sorting may be affected. Requires full reload. + * - delete: just delete the given rows clientside (no server interaction neccessary) + * - add: requires full reload for proper sorting + * @param {object|null} pushData.acl Extra data for determining relevance. eg: owner or responsible to decide if update is necessary + * @param {number} pushData.account_id User that caused the notification + */ + push: function(pushData) + { + // Log for debugging purposes + this.debug("log", "push(%o)", pushData); + + if (typeof pushData == "undefined") + { + this.debug('warn', "Push sent nothing"); + return; + } + + // notify app observers + for (var app in _wnd.egw.window.app) // run observers in main window (eg. not iframe, which might be opener!) + { + var app_obj = _wnd.egw.window.app[app]; + if (typeof app_obj.push == 'function') + { + app_obj.push(pushData); + } + } + } }; + }); diff --git a/timesheet/js/app.js b/timesheet/js/app.js index bb98b19ad2..63bf2661ce 100644 --- a/timesheet/js/app.js +++ b/timesheet/js/app.js @@ -56,17 +56,6 @@ var TimesheetApp = /** @class */ (function (_super) { this.filter2_change(); } }; - TimesheetApp.prototype.observer = function (_msg, _app, _id, _type, _msg_type, _links) { - switch (_app) { - case 'timesheet': - switch (_type) { - case 'delete': - egw.dataStoreUID(_app + '::' + _id, null); - break; - } - break; - } - }; /** * */ @@ -181,31 +170,6 @@ var TimesheetApp = /** @class */ (function (_super) { if (widget) return widget.options.value; }; - /** - * Push method receives push notification about updates to entries from the application - * - * It can use the extra _data parameter to determine if the client has read access to - * the entry - if an update of the list is necessary. - * - * @param _type either 'update', 'edit', 'delete', 'add' or null - * - update: request just modified data from given rows. Sorting is not considered, - * so if the sort field is changed, the row will not be moved. - * - edit: rows changed, but sorting may be affected. Requires full reload. - * - delete: just delete the given rows clientside (no server interaction neccessary) - * - add: requires full reload for proper sorting - * @param _app application name incl. sub-type eg. "projectmanager-element" - * @param _id id of entry to refresh or null - * @param _data eg. owner or responsible to decide if update is necessary - * @returns {undefined} - */ - TimesheetApp.prototype.push = function (_type, _app, _id, _data) { - console.log('app.timesheet.push', arguments); - switch (_type) { - case 'delete': - _super.prototype.push.apply(this, arguments); - break; - } - }; return TimesheetApp; }(egw_app_1.EgwApp)); app.classes.timesheet = TimesheetApp; diff --git a/timesheet/js/app.ts b/timesheet/js/app.ts index 031f52f005..17da1918c0 100644 --- a/timesheet/js/app.ts +++ b/timesheet/js/app.ts @@ -48,22 +48,6 @@ class TimesheetApp extends EgwApp } } - observer(_msg, _app, _id, _type, _msg_type, _links) { - - switch(_app) - { - case 'timesheet': - switch(_type) - { - case 'delete': - egw.dataStoreUID(_app + '::' + _id, null); - break; - } - break; - } - - } - /** * */ @@ -207,35 +191,6 @@ class TimesheetApp extends EgwApp var widget = this.et2.getWidgetById('ts_title'); if(widget) return widget.options.value; } - - /** - * Push method receives push notification about updates to entries from the application - * - * It can use the extra _data parameter to determine if the client has read access to - * the entry - if an update of the list is necessary. - * - * @param _type either 'update', 'edit', 'delete', 'add' or null - * - update: request just modified data from given rows. Sorting is not considered, - * so if the sort field is changed, the row will not be moved. - * - edit: rows changed, but sorting may be affected. Requires full reload. - * - delete: just delete the given rows clientside (no server interaction neccessary) - * - add: requires full reload for proper sorting - * @param _app application name incl. sub-type eg. "projectmanager-element" - * @param _id id of entry to refresh or null - * @param _data eg. owner or responsible to decide if update is necessary - * @returns {undefined} - */ - push(_type : string, _app : string, _id : string|number, _data? : any) - { - console.log('app.timesheet.push', arguments); - - switch (_type) - { - case 'delete': - super.push.apply(this, arguments); - break; - } - } } app.classes.timesheet = TimesheetApp;