From ccf4b73e57af03c5d0ea95b22f76e1bbfd3ca35e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20DE=20CESARE?= Date: Tue, 6 Feb 2018 17:36:51 +0100 Subject: [PATCH] feat(bulk): add bulk for phone function keys --- ...-line-phone-programmableKeys.controller.js | 99 ++++++++++++++++++- ...telephony-line-phone-programmableKeys.html | 12 +++ .../translations/Messages_fr_FR.xml | 6 ++ ...eature-line-line-phone-function.factory.js | 60 +++++++++++ ...eature-line-line-phone-function.service.js | 41 ++++++++ 5 files changed, 217 insertions(+), 1 deletion(-) create mode 100644 client/components/telecom/voip/feature/line/line/phone/function/voip-feature-line-line-phone-function.factory.js create mode 100644 client/components/telecom/voip/feature/line/line/phone/function/voip-feature-line-line-phone-function.service.js diff --git a/client/app/telecom/telephony/line/phone/programmableKeys/telecom-telephony-line-phone-programmableKeys.controller.js b/client/app/telecom/telephony/line/phone/programmableKeys/telecom-telephony-line-phone-programmableKeys.controller.js index ac8bc6767..c9d348279 100644 --- a/client/app/telecom/telephony/line/phone/programmableKeys/telecom-telephony-line-phone-programmableKeys.controller.js +++ b/client/app/telecom/telephony/line/phone/programmableKeys/telecom-telephony-line-phone-programmableKeys.controller.js @@ -1,4 +1,4 @@ -angular.module("managerApp").controller("TelecomTelephonyLinePhoneProgammableKeysCtrl", function ($translate, TelephonyMediator, $stateParams, $uibModal, Toast) { +angular.module("managerApp").controller("TelecomTelephonyLinePhoneProgammableKeysCtrl", function ($q, $translate, TelephonyMediator, $stateParams, $uibModal, Toast, OvhApiTelephony, telephonyBulk, voipLinePhoneFunction) { "use strict"; var self = this; @@ -83,6 +83,103 @@ angular.module("managerApp").controller("TelecomTelephonyLinePhoneProgammableKey }); }; + /* =========================== + = BULK = + ============================ */ + + self.bulkDatas = { + infos: { + name: "functionKeys", + actions: [{ + name: "" + }] + } + }; + + self.getBulkParams = function () { + self.bulkDatas.infos.actions = self.buildBulkActions(); + }; + + self.buildBulkActions = function () { + return _.map(self.functionKeys.raw, function (key) { + return { + name: "functionKey", + route: `/telephony/{billingAccount}/line/{serviceName}/phone/functionKey/${key.keyNum}`, + method: "PUT", + params: { + "function": key.function, + parameter: key.parameter + } + }; + }); + }; + + self.filterServices = function (services) { + var filteredServices = _.filter(services, function (service) { + return ["sip", "mgcp"].indexOf(service.featureType) > -1; + }); + + var sourceKeys = self.functionKeys.raw; + + return voipLinePhoneFunction.fetchAll().then((voipLinePhoneFunctionKeys) => { + filteredServices = _.filter(filteredServices, (service) => { + var editable = true; + var serviceKeys = _.filter(voipLinePhoneFunctionKeys, { serviceName: service.serviceName, billingAccount: service.billingAccount }); + + if (serviceKeys.length >= sourceKeys.length) { + _.forEach(sourceKeys, (key) => { + if (!_.some(serviceKeys, function (sKey) { + return sKey.keyNum === key.keyNum; + })) { + editable = false; + } + }); + } else { + editable = false; + } + + return editable; + }); + + return $q.when(filteredServices); + }); + }; + + self.onBulkSuccess = function (bulkResult) { + if (bulkResult.error.length) { + bulkResult.error = _.map(bulkResult.error, function (error) { + let errorDetails = _.get(error, "errors[0]"); + _.set(error, "errors[0].error", errorDetails.statusCode === 501 ? + $translate.instant("telephony_line_phone_programmableKeys_bulk_error_details") : errorDetails.error); + + return error; + }); + } + + // display message of success or error + telephonyBulk.getToastInfos(bulkResult, { + fullSuccess: $translate.instant("telephony_line_phone_programmableKeys_bulk_all_success"), + partialSuccess: $translate.instant("telephony_line_phone_programmableKeys_bulk_some_success", { + count: bulkResult.success.length + }), + error: $translate.instant("telephony_line_phone_programmableKeys_bulk_error") + }).forEach(function (toastInfo) { + Toast[toastInfo.type](toastInfo.message, { + hideAfter: null + }); + }); + + // reset initial values to be able to modify again the options + TelephonyMediator.resetAllCache(); + init(); + }; + + self.onBulkError = function (error) { + Toast.error([$translate.instant("telephony_line_phone_programmableKeys_bulk_on_error"), _.get(error, "msg.data")].join(" ")); + }; + + /* ----- End of BULK ------ */ + init(); } ); diff --git a/client/app/telecom/telephony/line/phone/programmableKeys/telecom-telephony-line-phone-programmableKeys.html b/client/app/telecom/telephony/line/phone/programmableKeys/telecom-telephony-line-phone-programmableKeys.html index 98def92c0..42a8de098 100644 --- a/client/app/telecom/telephony/line/phone/programmableKeys/telecom-telephony-line-phone-programmableKeys.html +++ b/client/app/telecom/telephony/line/phone/programmableKeys/telecom-telephony-line-phone-programmableKeys.html @@ -80,6 +80,18 @@ + + + + diff --git a/client/app/telecom/telephony/line/phone/programmableKeys/translations/Messages_fr_FR.xml b/client/app/telecom/telephony/line/phone/programmableKeys/translations/Messages_fr_FR.xml index 1c215afd0..362435627 100644 --- a/client/app/telecom/telephony/line/phone/programmableKeys/translations/Messages_fr_FR.xml +++ b/client/app/telecom/telephony/line/phone/programmableKeys/translations/Messages_fr_FR.xml @@ -67,6 +67,12 @@ Menu Répertoire + La modification de la présentation du numéro a bien été appliquée aux services sélectionnés. + La modification de la présentation du numéro a bien été appliquée à {{ count }} des services sélectionnés. + La modification de la présentation du numéro n'a pu être appliquée au(x) service(s) suivant(s) : + Cette fonction n'est pas supportée par ce téléphone + Oups ! Une erreur est survenue lors de la modification de la présentation du numéro. + Sélectionnez un paramètre Fax diff --git a/client/components/telecom/voip/feature/line/line/phone/function/voip-feature-line-line-phone-function.factory.js b/client/components/telecom/voip/feature/line/line/phone/function/voip-feature-line-line-phone-function.factory.js new file mode 100644 index 000000000..59e250380 --- /dev/null +++ b/client/components/telecom/voip/feature/line/line/phone/function/voip-feature-line-line-phone-function.factory.js @@ -0,0 +1,60 @@ +/** + * @ngdoc object + * @name managerApp.object:VoipLinePhoneFunction + * + * @description + *

Factory that describes a function key of a phone of a service with sip or mgcp feature type + * with attributes returned by `/telephony/{billingAccount}/line/{serviceName}/phone/functionKey/{keyNum}` API.

+ * + * @constructor + * @param {Object} options Options required for creating a new instance of VoipLinePhoneFunction + * (see {@link https://eu.api.ovh.com/console/#/telephony/%7BbillingAccount%7D/line/%7BserviceName%7D/phone/functionKey/%7BkeyNum%7D#GET `telephony.Phone.FunctionKey` enum} + * for available options properties). + * + * Note that `billingAccount` and `serviceName` options are mandatory. + */ +angular.module("managerApp").factory("VoipLinePhoneFunction", function () { + "use strict"; + + const mandatoryOptions = ["billingAccount", "serviceName"]; + + class VoipLinePhoneFunction { + constructor (options = {}) { + // check for mandatory options + mandatoryOptions.forEach((option) => { + if (!options[option]) { + throw new Error(`${option} option must be specified when creating a new VoipLinePhone`); + } + }); + + this.billingAccount = options.billingAccount; + this.serviceName = options.serviceName; + + this.setOptions(options); + } + + /** + * @ngdoc method + * @name managerApp.object:VoipLinePhoneFunction#setOptions + * @propertyOf managerApp.object:VoipLinePhoneFunction + * + * @description + * Set the options from `telephony.Phone.Function` enum. This is called by default by the constructor. + * + * @param {Object} options Optional options for creating a new instance of VoipLinePhoneFunction. + * + * @return {VoipLinePhoneFunction} The `VoipLinePhoneFunction` instance with options setted. + */ + setOptions (options) { + this.parameter = options.parameter; + this.function = options.function; + this.label = options.label; + this.default = options.default; + this.type = options.type; + this.keyNum = options.keyNum; + this.availableFunctions = options.availableFunctions || []; + } + } + + return VoipLinePhoneFunction; +}); diff --git a/client/components/telecom/voip/feature/line/line/phone/function/voip-feature-line-line-phone-function.service.js b/client/components/telecom/voip/feature/line/line/phone/function/voip-feature-line-line-phone-function.service.js new file mode 100644 index 000000000..2d05fc3e2 --- /dev/null +++ b/client/components/telecom/voip/feature/line/line/phone/function/voip-feature-line-line-phone-function.service.js @@ -0,0 +1,41 @@ +/** + * @ngdoc service + * @name managerApp.service:voipLinePhoneFunction + * + * @description + *

Service that manage function keys of phone linked to sip and mgcp features of services with serviceType line.

+ *

This service will manage API calls to `/telephony/{billingAccount}/line/{serviceName}/phone/functionKey/{keyNum}`

+ */ +angular.module("managerApp").service("voipLinePhoneFunction", class { + + constructor ($q, OvhApiTelephony, VoipLinePhoneFunction) { + this.$q = $q; + this.OvhApiTelephony = OvhApiTelephony; + this.VoipLinePhoneFunction = VoipLinePhoneFunction; + } + + /** + * @ngdoc method + * @name managerApp.service:voipLinePhoneFunction#fetchAll + * @methodOf managerApp.service:voipLinePhoneFunction + * + * @description + * Fetch all function keys of all phone of all services of serviceType line with featureType sip or mgcp from any billingAccount. This use APIv7 with wildcard and aggregation to achieve it. + * + * @return {Promise} That return an array of VoipLinePhoneFunction instances. + */ + fetchAll () { + return this.OvhApiTelephony.Line().Phone().FunctionKey().Erika().query().aggregate("billingAccount").aggregate("serviceName").aggregate("keyNum").expand().execute().$promise.then((phoneResults) => + phoneResults.map((phone) => { + let splittedPath = phone.path.split("/"); + + let functionKeysOptions = angular.extend(phone.value, { + billingAccount: splittedPath[2], + serviceName: splittedPath[4] + }); + + return new this.VoipLinePhoneFunction(functionKeysOptions); + }) + ); + } +});