From 06c05778a108644f131f1c81083b15b3e80a4bf0 Mon Sep 17 00:00:00 2001 From: Stephanie Moallic Date: Fri, 24 Nov 2023 11:48:16 +0100 Subject: [PATCH] feat(dedicated.network-security): update way to set pagination ref: UXCT-502 Signed-off-by: Stephanie Moallic --- .../scrubbing-center.controller.js | 54 ++++++++----------- .../scrubbing-center/scrubbing-center.html | 7 +-- 2 files changed, 27 insertions(+), 34 deletions(-) diff --git a/packages/manager/apps/dedicated/client/app/network-security/scrubbing-center/scrubbing-center.controller.js b/packages/manager/apps/dedicated/client/app/network-security/scrubbing-center/scrubbing-center.controller.js index 00b422f584c7..7fdbbf8ea8e0 100644 --- a/packages/manager/apps/dedicated/client/app/network-security/scrubbing-center/scrubbing-center.controller.js +++ b/packages/manager/apps/dedicated/client/app/network-security/scrubbing-center/scrubbing-center.controller.js @@ -1,12 +1,15 @@ +import { AbstractCursorDatagridController } from '@ovh-ux/manager-ng-apiv2-helper'; import { PERIODS, PERIOD_LIST } from './scrubbing-center.constant'; import { PAGE_SIZE } from '../network-security.constant'; -export default class ScrubbingCenterController { +export default class ScrubbingCenterController extends AbstractCursorDatagridController { /* @ngInject */ - constructor($translate, Alerter, networkSecurityService) { + constructor($translate, Alerter, networkSecurityService, ouiDatagridService) { + super(); this.$translate = $translate; this.Alerter = Alerter; this.networkSecurityService = networkSecurityService; + this.ouiDatagridService = ouiDatagridService; this.PERIODS = PERIODS; this.PERIOD_LIST = PERIOD_LIST; @@ -14,6 +17,7 @@ export default class ScrubbingCenterController { } $onInit() { + this.datagridId = 'ScrubbingCenterController-Datagrid'; this.errorMessage = ''; this.periods = this.networkSecurityService.initPeriods(this.PERIODS); @@ -33,57 +37,45 @@ export default class ScrubbingCenterController { this.isLoading = false; } - getEventsList(cursor, after, subnets, pageSize) { - this.isLoading = true; + createItemsPromise({ cursor }) { const params = { - after, - subnets, + after: this.after, + subnets: this.selectedIp, }; - return this.networkSecurityService - .getEventsList({ - cursor, - params, - pageSize, - }) - .then((response) => { - if (response.data) { - this.events = this.events.concat(response.data); - } - if (response.cursor.next) { - this.getEventsList(response.cursor.next, after, subnets, pageSize); - } - }) - .finally(() => { - this.isLoading = false; - }); + const pageSize = this.PAGE_SIZE; + return this.networkSecurityService.getEventsList({ + cursor, + params, + pageSize, + }); } getAllEvents() { - this.isLoading = true; - this.events = []; - let after = ''; + this.after = ''; switch (this.period.name) { case this.PERIOD_LIST.lastMonth: - after = moment() + this.after = moment() .subtract(1, 'months') .toISOString(); break; case this.PERIOD_LIST.lastWeek: - after = moment() + this.after = moment() .subtract(7, 'days') .toISOString(); break; case this.PERIOD_LIST.lastYear: - after = moment() + this.after = moment() .subtract(1, 'years') .toISOString(); break; default: - after = moment() + this.after = moment() .subtract(1, 'days') .toISOString(); } - this.getEventsList(null, after, this.selectedIp, this.PAGE_SIZE); + this.reloadItems(this.PAGE_SIZE).then(() => { + this.ouiDatagridService.refresh(this.datagridId, true); + }); } selectService() { diff --git a/packages/manager/apps/dedicated/client/app/network-security/scrubbing-center/scrubbing-center.html b/packages/manager/apps/dedicated/client/app/network-security/scrubbing-center/scrubbing-center.html index f436debf2174..d199aefaf443 100644 --- a/packages/manager/apps/dedicated/client/app/network-security/scrubbing-center/scrubbing-center.html +++ b/packages/manager/apps/dedicated/client/app/network-security/scrubbing-center/scrubbing-center.html @@ -60,9 +60,10 @@