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 @@ +