From 7ad8e57d2eb3abc06ec6280c3dadb978b16ccb92 Mon Sep 17 00:00:00 2001 From: nathangray Date: Fri, 26 Jun 2020 13:11:46 -0600 Subject: [PATCH] * Calendar: Optimize fetching participant names to reduce requests --- ...ss.calendar_owner_etemplate_widget.inc.php | 12 ++++++++- calendar/js/et2_widget_owner.js | 25 +++++++++++++++---- calendar/js/et2_widget_owner.ts | 23 +++++++++++++---- 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/calendar/inc/class.calendar_owner_etemplate_widget.inc.php b/calendar/inc/class.calendar_owner_etemplate_widget.inc.php index a644811acf..9129487214 100644 --- a/calendar/inc/class.calendar_owner_etemplate_widget.inc.php +++ b/calendar/inc/class.calendar_owner_etemplate_widget.inc.php @@ -140,12 +140,22 @@ class calendar_owner_etemplate_widget extends Etemplate\Widget\Taglist public static function ajax_owner($id = null) { // Handle a request for a single ID - if($id) + if($id && !is_array($id)) { $label = self::get_owner_label($id); Api\Json\Response::get()->data($label); return $label; } + else if($id && is_array($id)) + { + $labels = Array(); + foreach($id as $index => $_id) + { + $labels[$_id] = self::get_owner_label($_id); + } + Api\Json\Response::get()->data($labels); + return $labels; + } $bo = new calendar_bo(); $query = $_REQUEST['query']; diff --git a/calendar/js/et2_widget_owner.js b/calendar/js/et2_widget_owner.js index 35774afcc2..c9ce765a79 100644 --- a/calendar/js/et2_widget_owner.js +++ b/calendar/js/et2_widget_owner.js @@ -100,16 +100,31 @@ var et2_calendar_owner = /** @class */ (function (_super) { _super.prototype.set_value.call(this, _value); // If parent didn't find a label, label will be the same as ID so we // can find them that way + var missing_labels = []; for (var i = 0; i < this.options.value.length; i++) { var value = this.options.value[i]; if (value.id == value.label) { - // Proper label was not found by parent - ask directly - egw.json('calendar_owner_etemplate_widget::ajax_owner', value.id, function (data) { - this.widget.options.value[this.i].label = data; - this.widget.set_value(this.widget.options.value); - }, this, true, { widget: this, i: i }).sendRequest(); + missing_labels.push(value.id); } } + if (Object.keys(missing_labels).length > 0) { + // Proper label was not found by parent - ask directly + egw.json('calendar_owner_etemplate_widget::ajax_owner', [missing_labels], function (data) { + var _loop_1 = function (owner) { + if (!owner || typeof owner == "undefined") + return "continue"; + var idx = this_1.options.value.find(function (element) { return element.id == owner; }); + if (idx) { + idx.label = data[owner]; + } + }; + var this_1 = this; + for (var owner in data) { + _loop_1(owner); + } + this.set_value(this.options.value); + }, this, true, this).sendRequest(); + } if (this.taglist) { this.taglist.clear(true); this.taglist.addToSelection(this.options.value, true); diff --git a/calendar/js/et2_widget_owner.ts b/calendar/js/et2_widget_owner.ts index 70aefb6894..5e971975a2 100644 --- a/calendar/js/et2_widget_owner.ts +++ b/calendar/js/et2_widget_owner.ts @@ -120,18 +120,31 @@ export class et2_calendar_owner extends et2_taglist_email // If parent didn't find a label, label will be the same as ID so we // can find them that way + let missing_labels = []; for(var i = 0; i < this.options.value.length; i++) { var value = this.options.value[i]; if(value.id == value.label) { - // Proper label was not found by parent - ask directly - egw.json('calendar_owner_etemplate_widget::ajax_owner',value.id,function(data) { - this.widget.options.value[this.i].label = data; - this.widget.set_value(this.widget.options.value); - }, this,true,{widget: this, i: i}).sendRequest(); + missing_labels.push(value.id); } } + if(Object.keys(missing_labels).length > 0) + { + // Proper label was not found by parent - ask directly + egw.json('calendar_owner_etemplate_widget::ajax_owner',[missing_labels],function(data) { + for(let owner in data) + { + if(!owner || typeof owner == "undefined") continue; + let idx = this.options.value.find(element => element.id == owner); + if(idx) + { + idx.label = data[owner]; + } + } + this.set_value(this.options.value); + }, this,true,this).sendRequest(); + } if(this.taglist) {