diff --git a/packages/manager/modules/cloud-connect/src/cloud-connect.service.js b/packages/manager/modules/cloud-connect/src/cloud-connect.service.js index 4cf84b290bd3..667110aeb05c 100644 --- a/packages/manager/modules/cloud-connect/src/cloud-connect.service.js +++ b/packages/manager/modules/cloud-connect/src/cloud-connect.service.js @@ -559,4 +559,12 @@ export default class CloudConnectService { `cloud_connect_common_${array[array.length - 1]}`, )}`; } + + getNotifications(cloudConnectId) { + return this.iceberg(`/ovhCloudConnect/${cloudConnectId}/incident`) + .query() + .expand('CachedObjectList-Pages') + .execute(null, true) + .$promise.then(({ data }) => data); + } } diff --git a/packages/manager/modules/cloud-connect/src/details/components/notifications/component.js b/packages/manager/modules/cloud-connect/src/details/components/notifications/component.js new file mode 100644 index 000000000000..eef909262cb8 --- /dev/null +++ b/packages/manager/modules/cloud-connect/src/details/components/notifications/component.js @@ -0,0 +1,10 @@ +import template from './template.html'; +import controller from './controller'; + +export default { + template, + controller, + bindings: { + notifications: '<', + }, +}; diff --git a/packages/manager/modules/cloud-connect/src/details/components/notifications/constants.js b/packages/manager/modules/cloud-connect/src/details/components/notifications/constants.js new file mode 100644 index 000000000000..3d31f8f9be13 --- /dev/null +++ b/packages/manager/modules/cloud-connect/src/details/components/notifications/constants.js @@ -0,0 +1,8 @@ +export const NOTIFICATION_TYPE = { + INCIDENT: 'incident', + MAINTENANCE: 'maintenance', +}; + +export default { + NOTIFICATION_TYPE, +}; diff --git a/packages/manager/modules/cloud-connect/src/details/components/notifications/controller.js b/packages/manager/modules/cloud-connect/src/details/components/notifications/controller.js new file mode 100644 index 000000000000..b4d16faf400c --- /dev/null +++ b/packages/manager/modules/cloud-connect/src/details/components/notifications/controller.js @@ -0,0 +1,67 @@ +import { NOTIFICATION_TYPE } from './constants'; + +export default class NotificationsController { + /* @ngInject */ + constructor(coreConfig) { + this.incident = undefined; + this.maintenances = []; + + this.dateTimeFormat = new Intl.DateTimeFormat( + coreConfig.getUserLocale().replace('_', '-'), + { + day: 'numeric', + month: 'numeric', + year: 'numeric', + hour: 'numeric', + minute: 'numeric', + second: 'numeric', + timeZoneName: 'short', + }, + ); + } + + $onInit() { + // If there is incident, display the incident with the earlier date time + this.incident = this.notifications + .filter( + (notification) => notification.type === NOTIFICATION_TYPE.INCIDENT, + ) + .reduce((earliestIncident, currentIncident) => { + const currentIncidentFormatted = { + ...currentIncident, + startDateFormatted: this.dateTimeFormat.format( + new Date(currentIncident.startDate), + ), + }; + + if (!earliestIncident) { + return currentIncidentFormatted; + } + + if (currentIncident.startDate < earliestIncident.startDate) { + return currentIncidentFormatted; + } + + return earliestIncident; + }, null); + + // Sort all maintenances with the earlier start date time first + this.maintenances = this.notifications + .filter( + (notification) => notification.type === NOTIFICATION_TYPE.MAINTENANCE, + ) + .sort( + (maintenanceA, maintenanceB) => + new Date(maintenanceA.startDate) - new Date(maintenanceB.startDate), + ) + .map((maintenance) => ({ + ...maintenance, + startDateFormatted: this.dateTimeFormat.format( + new Date(maintenance.startDate), + ), + endDateFormatted: this.dateTimeFormat.format( + new Date(maintenance.endDate), + ), + })); + } +} diff --git a/packages/manager/modules/cloud-connect/src/details/components/notifications/index.js b/packages/manager/modules/cloud-connect/src/details/components/notifications/index.js new file mode 100644 index 000000000000..31d1327b9786 --- /dev/null +++ b/packages/manager/modules/cloud-connect/src/details/components/notifications/index.js @@ -0,0 +1,13 @@ +import angular from 'angular'; +import 'angular-translate'; + +import component from './component'; + +const moduleName = 'ovhCloudConnectDetailsNotificationsModule'; + +angular + .module(moduleName, ['pascalprecht.translate']) + .component('ovhCloudConnectNotifications', component) + .run(/* @ngTranslationsInject:json ./translations */); + +export default moduleName; diff --git a/packages/manager/modules/cloud-connect/src/details/components/notifications/template.html b/packages/manager/modules/cloud-connect/src/details/components/notifications/template.html new file mode 100644 index 000000000000..9cd349131458 --- /dev/null +++ b/packages/manager/modules/cloud-connect/src/details/components/notifications/template.html @@ -0,0 +1,20 @@ +
+ + + + + + + +
diff --git a/packages/manager/modules/cloud-connect/src/details/components/notifications/translations/Messages_fr_FR.json b/packages/manager/modules/cloud-connect/src/details/components/notifications/translations/Messages_fr_FR.json new file mode 100644 index 000000000000..37c6e2516da2 --- /dev/null +++ b/packages/manager/modules/cloud-connect/src/details/components/notifications/translations/Messages_fr_FR.json @@ -0,0 +1,4 @@ +{ + "cloud_connect_notifications_incident": "Un incident pouvant impacter votre service a été déclaré le {{startDate}}", + "cloud_connect_notifications_maintenance": "Une opération de maintenance est prévue du {{startDate}} au {{endDate}}" +} diff --git a/packages/manager/modules/cloud-connect/src/details/details.component.js b/packages/manager/modules/cloud-connect/src/details/details.component.js index a9423116b995..bf7cce844da6 100644 --- a/packages/manager/modules/cloud-connect/src/details/details.component.js +++ b/packages/manager/modules/cloud-connect/src/details/details.component.js @@ -5,6 +5,7 @@ export default { cloudConnect: '<', guideUrl: '<', clearCache: '<', + notifications: '<', }, template, }; diff --git a/packages/manager/modules/cloud-connect/src/details/details.module.js b/packages/manager/modules/cloud-connect/src/details/details.module.js index 97d2bf16e7b3..6ee549023678 100644 --- a/packages/manager/modules/cloud-connect/src/details/details.module.js +++ b/packages/manager/modules/cloud-connect/src/details/details.module.js @@ -8,6 +8,7 @@ import routing from './details.routing'; import serviceKeys from './service-keys'; import tasks from './tasks'; import statistics from './statistics'; +import notifications from './components/notifications'; const moduleName = 'ovhCloudConnectDetails'; @@ -19,6 +20,7 @@ angular serviceKeys, tasks, statistics, + notifications, ]) .config(routing) .component('cloudConnectDetails', component) diff --git a/packages/manager/modules/cloud-connect/src/details/details.routing.js b/packages/manager/modules/cloud-connect/src/details/details.routing.js index efb128ee5a14..88e15795d90d 100644 --- a/packages/manager/modules/cloud-connect/src/details/details.routing.js +++ b/packages/manager/modules/cloud-connect/src/details/details.routing.js @@ -15,6 +15,8 @@ export default /* @ngInject */ ($stateProvider) => { clearCache: /* @ngInject */ (cloudConnectService) => () => cloudConnectService.clearAllCache(), breadcrumb: /* @ngInject */ (cloudConnectId) => cloudConnectId, + notifications: /* @ngInject */ (cloudConnectId, cloudConnectService) => + cloudConnectService.getNotifications(cloudConnectId), }, }); }; diff --git a/packages/manager/modules/cloud-connect/src/details/template.html b/packages/manager/modules/cloud-connect/src/details/template.html index 0d72e5d4315c..9157a8888806 100644 --- a/packages/manager/modules/cloud-connect/src/details/template.html +++ b/packages/manager/modules/cloud-connect/src/details/template.html @@ -28,4 +28,7 @@ +