From 5ebee4bec750911c09623d05a45c00461a76ab24 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 26 Jan 2024 15:23:32 +0200 Subject: [PATCH] roles quick search --- client/res/templates/role/table-edit.tpl | 36 ++++++++-- client/res/templates/role/table.tpl | 17 ++++- client/src/views/role/record/table.js | 90 +++++++++++++++++++++++- client/src/views/user/modals/access.js | 1 + frontend/less/espo/elements/modal.less | 5 ++ 5 files changed, 136 insertions(+), 13 deletions(-) diff --git a/client/res/templates/role/table-edit.tpl b/client/res/templates/role/table-edit.tpl index 859dabab39..6677d7440c 100644 --- a/client/res/templates/role/table-edit.tpl +++ b/client/res/templates/role/table-edit.tpl @@ -1,4 +1,15 @@ +
+ +
+

{{translate 'Scope Level' scope='Role'}}

@@ -14,9 +25,12 @@ {{/each}} {{#each tableDataList}} - - {{translate name category='scopeNamesPlural'}} - + + +
+ {{translate name category='scopeNamesPlural'}} +
+ + +
+

{{translate 'Scope Level' scope='Role'}}

@@ -14,7 +25,7 @@ {{/each}} {{#each tableDataList}} - + {{translate name category='scopeNamesPlural'}} @@ -71,14 +82,14 @@ {{#each fieldTableDataList}} {{#if list.length}} - + {{translate name category='scopeNamesPlural'}} {{/if}} {{#each list}} - + {{translate name category='fields' scope=../name}} {{#each list}} diff --git a/client/src/views/role/record/table.js b/client/src/views/role/record/table.js index 2660361017..75b0558412 100644 --- a/client/src/views/role/record/table.js +++ b/client/src/views/role/record/table.js @@ -97,6 +97,10 @@ class RoleRecordTableView extends View { } events = { + /** @this FieldManagerListView */ + 'keyup input[data-name="quick-search"]': function (e) { + this.processQuickSearch(e.currentTarget.value); + }, /** @this RoleRecordTableView */ 'click .action[data-action="addField"]': function (e) { const scope = $(e.currentTarget).data().scope; @@ -282,7 +286,7 @@ class RoleRecordTableView extends View { this.setupData(); if (this.isRendered()) { - this.reRender(); + this.reRenderPreserveSearch(); } }); @@ -478,6 +482,8 @@ class RoleRecordTableView extends View { } afterRender() { + this.$quickSearch = this.$el.find('input[data-name="quick-search"]'); + if (this.mode === 'edit') { this.scopeList.forEach(scope => { const $read = this.$el.find('select[name="' + scope + '-read"]'); @@ -666,7 +672,9 @@ class RoleRecordTableView extends View { }); }); - this.reRender(); + const searchText = this.$quickSearch.val(); + + this.reRenderPreserveSearch(); }); }); } @@ -690,11 +698,21 @@ class RoleRecordTableView extends View { if (~index) { scopeData.list.splice(index, 1); - this.reRender(); + this.reRenderPreserveSearch(); } }); } + reRenderPreserveSearch() { + const searchText = this.$quickSearch.val(); + + this.reRender() + .then(() => { + this.$quickSearch.val(searchText); + this.processQuickSearch(searchText); + }); + } + initStickyHeader(type) { const $sticky = this.$el.find('.sticky-header-' + type); const $window = $(window); @@ -801,6 +819,72 @@ class RoleRecordTableView extends View { $o.css('color', color); }); } + + processQuickSearch(text) { + text = text.trim(); + + //const $noData = this.$noData; + + //$noData.addClass('hidden'); + + if (!text) { + this.$el.find('table tr.item-row').removeClass('hidden'); + + return; + } + + const matchedList = []; + + const lowerCaseText = text.toLowerCase(); + + this.scopeList.forEach(/** string */item => { + let matched = false; + + const translation = this.getLanguage().translate(item, 'scopeNamesPlural'); + + if ( + translation.toLowerCase().indexOf(lowerCaseText) === 0 || + item.toLowerCase().indexOf(lowerCaseText) === 0 + ) { + matched = true; + } + + if (!matched) { + const wordList = translation.split(' ') + .concat(translation.split(' ')); + + wordList.forEach((word) => { + if (word.toLowerCase().indexOf(lowerCaseText) === 0) { + matched = true; + } + }); + } + + if (matched) { + matchedList.push(item); + } + }); + + if (matchedList.length === 0) { + this.$el.find('table tr.item-row').addClass('hidden'); + + //$noData.removeClass('hidden'); + + return; + } + + this.scopeList.forEach(/** string */item => { + const $row = this.$el.find(`table tr.item-row[data-name="${item}"]`); + + if (!~matchedList.indexOf(item)) { + $row.addClass('hidden'); + + return; + } + + $row.removeClass('hidden'); + }); + } } export default RoleRecordTableView; diff --git a/client/src/views/user/modals/access.js b/client/src/views/user/modals/access.js index e5496c5266..7d8ad26407 100644 --- a/client/src/views/user/modals/access.js +++ b/client/src/views/user/modals/access.js @@ -95,6 +95,7 @@ define('views/user/modals/access', ['views/modal'], function (Dep) { fieldData: fieldTable, }, final: true, + selector: '.user-access-table', }); this.headerText = this.translate('Access'); diff --git a/frontend/less/espo/elements/modal.less b/frontend/less/espo/elements/modal.less index 81b7db08b0..c02fe5ec09 100644 --- a/frontend/less/espo/elements/modal.less +++ b/frontend/less/espo/elements/modal.less @@ -238,6 +238,11 @@ .modal-body > .no-side-margin { margin-left: -@panel-padding; margin-right: -@panel-padding; + + > .negate-no-side-margin { + margin-left: @panel-padding; + margin-right: @panel-padding; + } } .modal.in .modal.in {