reduceCounter fix for badges in Mail tree

This commit is contained in:
milan 2024-03-07 17:00:51 +01:00
parent 556757ae5d
commit 9b5412a494
2 changed files with 29 additions and 12 deletions

View File

@ -33,7 +33,7 @@ export type TreeItemData = SelectOption & {
tooltip: String, tooltip: String,
userdata: any[] userdata: any[]
//here we can store the number of unread messages, if there are any //here we can store the number of unread messages, if there are any
badge?: String; badge?: string;
} }
/** /**
@ -111,11 +111,26 @@ export class Et2Tree extends Et2WidgetWithSelectMixin(LitElement)
this.selectedNodes = []; this.selectedNodes = [];
} }
private _initCurrent()
{
this._currentSlTreeItem = this.selected;
this._currentOption = this._currentSlTreeItem?this.getNode(this._currentSlTreeItem?.id):null
}
firstUpdated() firstUpdated()
{ {
// This is somehow required to set the autoload URL properly? // This is somehow required to set the autoload URL properly?
// TODO: Make this not needed, either this.autoload_url should be properly set or go away in favour of using this.autoload // TODO: Make this not needed, either this.autoload_url should be properly set or go away in favour of using this.autoload
this.createTree(); if (this.autoloading)
{
// @ts-ignore from static get properties
let url = this.autoloading;
if (url.charAt(0) != '/' && url.substr(0, 4) != 'http')
{
url = '/json.php?menuaction=' + url;
}
this.autoloading_url = url;
}
// Check if top level should be autoloaded // Check if top level should be autoloaded
if(this.autoloading && !this._selectOptions?.length) if(this.autoloading && !this._selectOptions?.length)
@ -123,9 +138,11 @@ export class Et2Tree extends Et2WidgetWithSelectMixin(LitElement)
this.handleLazyLoading({item: this._selectOptions}).then((results) => this.handleLazyLoading({item: this._selectOptions}).then((results) =>
{ {
this._selectOptions = results?.item ?? []; this._selectOptions = results?.item ?? [];
this._initCurrent()
this.requestUpdate("_selectOptions"); this.requestUpdate("_selectOptions");
}) })
} }
if (this._selectOptions?.length) this._initCurrent()
// Actions can't be initialized without being connected to InstanceManager // Actions can't be initialized without being connected to InstanceManager
this._initActions(); this._initActions();
@ -697,7 +714,7 @@ export class Et2Tree extends Et2WidgetWithSelectMixin(LitElement)
<span class="tree-item__label"> <span class="tree-item__label">
${selectOption.label ?? selectOption.text} ${selectOption.label ?? selectOption.text}
</span> </span>
${selectOption.badge ? ${(selectOption.badge) ?
html` html`
<sl-badge pill variant="danger">${selectOption.badge}</sl-badge> <sl-badge pill variant="danger">${selectOption.badge}</sl-badge>
` : nothing} ` : nothing}

View File

@ -1949,10 +1949,11 @@ app.classes.mail = AppJS.extend(
// display folder-name bold for unseen mails // display folder-name bold for unseen mails
if(_status[folderId]["unseenCount"]) if(_status[folderId]["unseenCount"])
{ {
ftree.set_badge(folderId,_status[folderId]["unseenCount"]);
ftree.setStyle(folderId, 'font-weight: bold !important'); ftree.setStyle(folderId, 'font-weight: bold !important');
}else {
ftree.setStyle(folderId, 'font-weight: normal');
} }
ftree.set_badge(folderId,_status[folderId]["unseenCount"]);
//alert(i +'->'+_status[i]); //alert(i +'->'+_status[i]);
} }
}, },
@ -2169,16 +2170,15 @@ app.classes.mail = AppJS.extend(
mail_reduceCounterWithoutServerRoundtrip: function() mail_reduceCounterWithoutServerRoundtrip: function()
{ {
var ftree = this.et2.getWidgetById(this.nm_index+'[foldertree]'); var ftree = this.et2.getWidgetById(this.nm_index+'[foldertree]');
var _foldernode = ftree.getSelectedNode(); var _foldernode = ftree.getSelectedItem();
var counter = _foldernode.text.match(this._unseen_regexp); var counter = _foldernode.badge;
var icounter = 0; var icounter = 0;
if ( counter ) icounter = parseInt(counter[0].replace(' (','').replace(')','')); if (counter) icounter = parseInt(counter);
if (icounter>0) if (icounter>0)
{ {
var newcounter = icounter-1; let newcounter = icounter - 1;
if (newcounter > 0) _foldernode.text = _foldernode.text.replace(' (' + String(icounter) + ')', ' (' + String(newcounter) + ')'); if (newcounter === 0) newcounter = null;
if (newcounter == 0) _foldernode.text = _foldernode.text.replace(' (' + String(icounter) + ')', ''); ftree.set_badge(_foldernode.id, newcounter)
ftree.setLabel(_foldernode.id, _foldernode.text);
} }
}, },