From e91c3ef939426d740ae7b7fb4f2b5ce857415d33 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Sun, 15 Dec 2024 16:16:13 +0200 Subject: [PATCH] integrations view impr --- .../templates/admin/integrations/index.tpl | 8 +- client/src/views/admin/integrations/index.js | 84 ++++++++++++------- 2 files changed, 57 insertions(+), 35 deletions(-) diff --git a/client/res/templates/admin/integrations/index.tpl b/client/res/templates/admin/integrations/index.tpl index 3d3efbf26c..b3a9e0c805 100644 --- a/client/res/templates/admin/integrations/index.tpl +++ b/client/res/templates/admin/integrations/index.tpl @@ -9,15 +9,15 @@
diff --git a/client/src/views/admin/integrations/index.js b/client/src/views/admin/integrations/index.js index e27b574221..cd8d16057c 100644 --- a/client/src/views/admin/integrations/index.js +++ b/client/src/views/admin/integrations/index.js @@ -32,68 +32,90 @@ export default class IntegrationsIndexView extends View { template = 'admin/integrations/index' - integrationList = null + /** + * @private + * @type {string[]} + */ + integrationList + integration = null data() { return { - integrationList: this.integrationList, + integrationDataList: this.getIntegrationDataList(), integration: this.integration, }; } - events = { - /** @this IntegrationsIndexView */ - 'click #integrations-menu a.integration-link': function (e) { - const name = $(e.currentTarget).data('name'); - - this.openIntegration(name); - }, - } - setup () { - this.integrationList = Object - .keys(this.getMetadata().get('integrations') || {}) + this.addHandler('click', 'a.integration-link', (e, target) => { + this.openIntegration(target.dataset.name); + }); + + this.integrationList = Object.keys(this.getMetadata().get('integrations') || {}) .sort((v1, v2) => this.translate(v1, 'titles', 'Integration') .localeCompare(this.translate(v2, 'titles', 'Integration')) ); this.integration = this.options.integration || null; + if (this.integration) { + this.createIntegrationView(this.integration); + } + this.on('after:render', () => { this.renderHeader(); if (!this.integration) { this.renderDefaultPage(); - } else { - this.openIntegration(this.integration); } }); } - openIntegration(integration) { + /** + * @return {{name: string, active: boolean}[]} + */ + getIntegrationDataList() { + return this.integrationList.map(it => { + return { + name: it, + active: this.integration === it, + }; + }) + } + + /** + * @param {string} integration + * @return {Promise} + */ + createIntegrationView(integration) { + const viewName = this.getMetadata().get(`integrations.${integration}.view`) || + 'views/admin/integrations/' + + Espo.Utils.camelCaseToHyphen(this.getMetadata().get(`integrations.${integration}.authMethod`)); + + return this.createView('content', viewName, { + fullSelector: '#integration-content', + integration: integration, + }); + } + + /** + * @param {string} integration + */ + async openIntegration(integration) { this.integration = integration; - this.getRouter().navigate('#Admin/integrations/name=' + integration, {trigger: false}); - - const viewName = this.getMetadata().get('integrations.' + integration + '.view') || - 'views/admin/integrations/' + - Espo.Utils.camelCaseToHyphen(this.getMetadata().get('integrations.' + integration + '.authMethod')); + this.getRouter().navigate(`#Admin/integrations/name=${integration}`, {trigger: false}); Espo.Ui.notify(' ... '); - this.createView('content', viewName, { - fullSelector: '#integration-content', - integration: integration, - }, view => { - this.renderHeader(); + await this.createIntegrationView(integration); - view.render(); + this.renderHeader(); + await this.reRender(); - Espo.Ui.notify(false); - - $(window).scrollTop(0); - }); + Espo.Ui.notify(false); + $(window).scrollTop(0); } afterRender() {