From a00cf5e69677bbcb474a12f2b60aa71b4e4c902c Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 16 Feb 2024 16:38:52 +0200 Subject: [PATCH] entity manager show primary filters --- .../Resources/i18n/en_US/EntityManager.json | 3 +- .../templates/admin/entity-manager/scope.tpl | 35 +------ .../entity-manager/fields/primary-filters.js | 80 ++++++++++++++++ .../src/views/admin/entity-manager/scope.js | 94 +++++++++++++++++++ 4 files changed, 177 insertions(+), 35 deletions(-) create mode 100644 client/src/views/admin/entity-manager/fields/primary-filters.js diff --git a/application/Espo/Resources/i18n/en_US/EntityManager.json b/application/Espo/Resources/i18n/en_US/EntityManager.json index 64affe11d0..fe110c8719 100644 --- a/application/Espo/Resources/i18n/en_US/EntityManager.json +++ b/application/Espo/Resources/i18n/en_US/EntityManager.json @@ -46,7 +46,8 @@ "layout": "Layout", "author": "Author", "module": "Module", - "version": "Version" + "version": "Version", + "primaryFilters": "Primary Filters" }, "options": { "type": { diff --git a/client/res/templates/admin/entity-manager/scope.tpl b/client/res/templates/admin/entity-manager/scope.tpl index b2bc2bffd4..145b68ee95 100644 --- a/client/res/templates/admin/entity-manager/scope.tpl +++ b/client/res/templates/admin/entity-manager/scope.tpl @@ -26,43 +26,10 @@ +
{{{record}}}
-
-
-
-
- -
- {{scope}} -
-
- {{#if type}} -
- -
- {{type}} -
-
- {{/if}} -
-
-
- -
- {{label}} -
-
-
-
-
diff --git a/client/src/views/admin/entity-manager/fields/primary-filters.js b/client/src/views/admin/entity-manager/fields/primary-filters.js new file mode 100644 index 0000000000..79f904becc --- /dev/null +++ b/client/src/views/admin/entity-manager/fields/primary-filters.js @@ -0,0 +1,80 @@ +/************************************************************************ + * This file is part of EspoCRM. + * + * EspoCRM – Open Source CRM application. + * Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko + * Website: https://www.espocrm.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * The interactive user interfaces in modified source and object code versions + * of this program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU Affero General Public License version 3. + * + * In accordance with Section 7(b) of the GNU Affero General Public License version 3, + * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. + ************************************************************************/ + +import ArrayFieldView from 'views/fields/array'; + +class EntityManagerPrimaryFiltersFieldView extends ArrayFieldView { + + // language=Handlebars + detailTemplateContent = ` + {{#unless isEmpty}} + + + {{#each dateList}} + + + + + {{/each}} + +
{{name}}{{label}}
+ {{else}} + {{#if valueIsSet}} + {{translate 'None'}} + {{else}} + + {{/if}} + {{/unless}} + ` + + // noinspection JSCheckFunctionSignatures + data() { + // noinspection JSValidateTypes + return { + ...super.data(), + dateList: this.getValuesItems(), + }; + } + + constructor(options) { + super(options); + + this.targetEntityType = options.targetEntityType; + } + + getValuesItems() { + return (this.model.get(this.name) || []).map(/** string */item => { + return { + name: item, + label: this.translate(item, 'presetFilters', this.targetEntityType), + }; + }); + } +} + +export default EntityManagerPrimaryFiltersFieldView; diff --git a/client/src/views/admin/entity-manager/scope.js b/client/src/views/admin/entity-manager/scope.js index 551c4196c4..a5adfb12d0 100644 --- a/client/src/views/admin/entity-manager/scope.js +++ b/client/src/views/admin/entity-manager/scope.js @@ -27,6 +27,9 @@ ************************************************************************/ import View from 'view'; +import DetailRecordView from 'views/record/detail'; +import Model from 'model'; +import EntityManagerPrimaryFiltersFieldView from 'views/admin/entity-manager/fields/primary-filters'; class EntityManagerScopeView extends View { @@ -68,6 +71,84 @@ class EntityManagerScopeView extends View { this.scope = this.options.scope; this.setupScopeData(); + + this.model = new Model({ + name: this.scope, + type: this.type, + label: this.label, + primaryFilters: this.getPrimaryFilters(), + }); + + this.model.setDefs({ + fields: { + name: { + type: 'varchar', + }, + type: { + type: 'varchar', + }, + label: { + type: 'varchar', + }, + primaryFilters: { + type: 'array', + }, + } + }); + + this.recordView = new DetailRecordView({ + model: this.model, + inlineEditDisabled: true, + buttonsDisabled: true, + readOnly: true, + detailLayout: [ + { + tabBreak: true, + tabLabel: this.translate('General', 'labels', 'Settings'), + rows: [ + [ + { + name: 'name', + labelText: this.translate('name', 'fields', 'EntityManager'), + }, + { + name: 'type', + labelText: this.translate('type', 'fields', 'EntityManager'), + } + ], + [ + { + name: 'label', + labelText: this.translate('label', 'fields', 'EntityManager'), + }, + false + ] + ] + }, + { + tabBreak: true, + tabLabel: this.translate('Details'), + rows: [ + [ + { + view: new EntityManagerPrimaryFiltersFieldView({ + name: 'primaryFilters', + labelText: this.translate('primaryFilters', 'fields', 'EntityManager'), + targetEntityType: this.scope, + }), + }, + false + ] + ] + } + ], + }); + + this.assignView('record', this.recordView, '.record-container'); + + if (!this.type) { + this.recordView.hideField('type'); + } } setupScopeData() { @@ -182,6 +263,19 @@ class EntityManagerScopeView extends View { this.getHelper().broadcastChannel.postMessage('update:metadata'); this.getHelper().broadcastChannel.postMessage('update:settings'); } + + /** + * @return {string[]} + */ + getPrimaryFilters() { + return this.getMetadata().get(`clientDefs.${this.scope}.filterList`, []).map(item => { + if (typeof item === 'object' && item.name) { + return item.name; + } + + return item.toString(); + }); + } } export default EntityManagerScopeView;