* Calendar: Optimize fetching participant names to reduce requests

This commit is contained in:
nathangray 2020-06-26 13:11:46 -06:00
parent 9463a0f395
commit 7ad8e57d2e
3 changed files with 49 additions and 11 deletions

View File

@ -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'];

View File

@ -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);

View File

@ -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)
{