From 17c3efa547eaab5593d1741b1658998bb4158a17 Mon Sep 17 00:00:00 2001 From: Cyril Biencourt Date: Thu, 27 Jul 2023 16:19:03 +0200 Subject: [PATCH] feat: save datagrid preferences Signed-off-by: Cyril Biencourt --- .../dedicated/client/app/cdn/cdn.routes.js | 1 + .../manage/domains/domains.routes.js | 1 + .../app/dedicated/housing/housing.routing.js | 1 + .../client/app/dedicated/nas/nas.routing.js | 1 + .../dedicated/server/servers.controller.js | 26 +++++++++---------- .../client/app/dedicated/server/servers.html | 5 +--- .../dedicatedCloud/dedicatedClouds.routing.js | 1 + .../managed-baremetal.routing.js | 1 + packages/manager/apps/dedicated/package.json | 1 + packages/manager/apps/telecom/package.json | 1 + .../src/app/telecom/pack/packs.routing.js | 1 + .../services/services.routing.js | 1 + .../repayments/repayments.routing.js | 1 + .../telecom/telephony/telephony.routing.js | 1 + .../web/client/app/dns-zone/zone.routing.js | 1 + .../web/client/app/domain/domains.routing.js | 1 + .../list/list-domain-layout.controller.js | 17 +++++++++++- .../web/client/app/domain/list/template.html | 1 + .../web/client/app/hosting/hosting.routing.js | 1 + .../private-database.routing.js | 1 + packages/manager/apps/web/package.json | 1 + .../manager/modules/cda/src/cda.routing.js | 1 + .../src/cloud-connect.routing.js | 1 + .../modules/email-domain/src/email.routing.js | 2 ++ .../manager/modules/iplb/src/iplb.routing.js | 1 + .../modules/metrics/src/metrics.routing.js | 1 + .../nasha/src/directory/directory.routing.js | 1 + .../manager/modules/netapp/src/routing.js | 1 + .../modules/ng-layout-helpers/package.json | 1 + .../src/list/list-layout.controller.js | 16 ++++++++++++ .../ng-layout-helpers/src/list/template.html | 2 ++ .../modules/office/src/office.routing.js | 1 + .../overthebox/src/overtheboxes.routing.js | 1 + packages/manager/modules/pci/package.json | 1 + .../sharepoint/src/sharepoint.routing.js | 1 + .../manager/modules/sms/src/sms.routing.js | 1 + .../veeam-cloud-connect/src/veeam.routing.js | 1 + .../veeam-enterprise/src/veeam.routing.js | 1 + .../manager/modules/vps/src/vps.routing.js | 1 + .../modules/vrack/src/vrack.routing.js | 1 + .../template/src/routing.js | 1 + 41 files changed, 84 insertions(+), 19 deletions(-) diff --git a/packages/manager/apps/dedicated/client/app/cdn/cdn.routes.js b/packages/manager/apps/dedicated/client/app/cdn/cdn.routes.js index 6977ab317157..eeddb9d5ba1d 100644 --- a/packages/manager/apps/dedicated/client/app/cdn/cdn.routes.js +++ b/packages/manager/apps/dedicated/client/app/cdn/cdn.routes.js @@ -10,6 +10,7 @@ export default /* @ngInject */ ($stateProvider) => { ...ListLayoutHelper.stateResolves, apiPath: () => '/cdn/dedicated', dataModel: () => 'cdnanycast.Anycast', + id: () => 'cdns', defaultFilterColumn: () => 'service', header: /* @ngInject */ ($translate) => $translate.instant('cdn_title'), customizableColumns: () => true, diff --git a/packages/manager/apps/dedicated/client/app/cdn/dedicated/manage/domains/domains.routes.js b/packages/manager/apps/dedicated/client/app/cdn/dedicated/manage/domains/domains.routes.js index 5d62422a1a07..c92e50b93a08 100644 --- a/packages/manager/apps/dedicated/client/app/cdn/dedicated/manage/domains/domains.routes.js +++ b/packages/manager/apps/dedicated/client/app/cdn/dedicated/manage/domains/domains.routes.js @@ -13,6 +13,7 @@ export default /* @ngInject */ ($stateProvider) => { `/cdn/dedicated/${serviceName}/domains`, schema: /* @ngInject */ ($http) => $http.get('/cdn/dedicated.json').then(({ data }) => data), + id: () => 'domains', dataModel: () => 'cdnanycast.Domain', defaultFilterColumn: () => 'domain', customizableColumns: () => true, diff --git a/packages/manager/apps/dedicated/client/app/dedicated/housing/housing.routing.js b/packages/manager/apps/dedicated/client/app/dedicated/housing/housing.routing.js index cb34a2930f23..cf99e5a2e22e 100644 --- a/packages/manager/apps/dedicated/client/app/dedicated/housing/housing.routing.js +++ b/packages/manager/apps/dedicated/client/app/dedicated/housing/housing.routing.js @@ -9,6 +9,7 @@ export default /* @ngInject */ ($stateProvider) => { ...ListLayoutHelper.stateResolves, apiPath: () => '/dedicated/housing', dataModel: () => 'dedicated.housing.Housing', + id: () => 'housing', defaultFilterColumn: () => 'name', header: /* @ngInject */ ($translate) => $translate.instant('dedicated_housing'), diff --git a/packages/manager/apps/dedicated/client/app/dedicated/nas/nas.routing.js b/packages/manager/apps/dedicated/client/app/dedicated/nas/nas.routing.js index ff932c465823..9272276f6dc4 100644 --- a/packages/manager/apps/dedicated/client/app/dedicated/nas/nas.routing.js +++ b/packages/manager/apps/dedicated/client/app/dedicated/nas/nas.routing.js @@ -13,6 +13,7 @@ export default /* @ngInject */ ($stateProvider) => { ...ListLayoutHelper.stateResolves, apiPath: () => '/dedicated/nas', dataModel: () => 'dedicated.nas.Nas', + id: () => 'nashas', defaultFilterColumn: () => 'serviceName', header: () => 'NAS', customizableColumns: () => true, diff --git a/packages/manager/apps/dedicated/client/app/dedicated/server/servers.controller.js b/packages/manager/apps/dedicated/client/app/dedicated/server/servers.controller.js index 86f0ac586a03..11edc93379d6 100644 --- a/packages/manager/apps/dedicated/client/app/dedicated/server/servers.controller.js +++ b/packages/manager/apps/dedicated/client/app/dedicated/server/servers.controller.js @@ -2,17 +2,22 @@ import get from 'lodash/get'; import reduce from 'lodash/reduce'; import set from 'lodash/set'; import snakeCase from 'lodash/snakeCase'; +import { + retrieveColumnsConfig, + saveColumnsConfig, +} from '@ovh-ux/datagrid-preferences'; +/* eslint class-methods-use-this: ["error", { "exceptMethods": ["onColumnsParametersChange"] }] */ export default class ServersCtrl { /* @ngInject */ - constructor($q, $translate, ouiDatagridService, ovhUserPref) { + constructor($q, $translate, ouiDatagridService) { this.$q = $q; this.$translate = $translate; this.ouiDatagridService = ouiDatagridService; - this.ovhUserPref = ovhUserPref; } $onInit() { + this.datagridId = 'dg-servers'; this.criteria = JSON.parse(this.filter).map((criteria) => ({ property: get(criteria, 'field') || 'name', operator: get(criteria, 'comparator'), @@ -40,22 +45,15 @@ export default class ServersCtrl { } getColumnsPreferences() { - this.ovhUserPref - .getValue('DEDICATED_SERVER_DG_CONFIG') - .then((columns) => { + this.$q.when(retrieveColumnsConfig(this.datagridId)).then((columns) => { + if (columns) { this.columnsParameters = columns; - }) - .catch(() => { - // do nothing (defautl columns will be displayed) - }); + } + }); } onColumnsParametersChange(id, columns) { - // save cols - // todo: add debounce - this.ovhUserPref.create('DEDICATED_SERVER_DG_CONFIG', columns).catch(() => { - // fails to save: do nothing - }); + saveColumnsConfig(id, columns); } static toUpperSnakeCase(str) { diff --git a/packages/manager/apps/dedicated/client/app/dedicated/server/servers.html b/packages/manager/apps/dedicated/client/app/dedicated/server/servers.html index e121fe4bae89..7e5306ad0b63 100644 --- a/packages/manager/apps/dedicated/client/app/dedicated/server/servers.html +++ b/packages/manager/apps/dedicated/client/app/dedicated/server/servers.html @@ -4,7 +4,7 @@ >