Skip to content
This repository has been archived by the owner on Dec 23, 2019. It is now read-only.

Commit

Permalink
feat(bulk): add bulk for phone function keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Jérémy DE CESARE committed Feb 12, 2018
1 parent fc937f6 commit ccf4b73
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@
</button>
</th>
</thead>

<telephony-bulk-action data-billing-account="{{ ProgrammableKeysCtrl.line.billingAccount }}"
data-service-name="{{ ProgrammableKeysCtrl.line.serviceName }}"
data-custom-class="link d-block pl-0 mb-3"
data-bulk-infos="ProgrammableKeysCtrl.bulkDatas.infos"
data-ng-disabled="!ProgrammableKeysCtrl.functionKeys.raw.length && !ProgrammableKeysCtrl.loading.keys"
data-filter-services="ProgrammableKeysCtrl.filterServices"
data-get-bulk-params="ProgrammableKeysCtrl.getBulkParams"
data-on-success="ProgrammableKeysCtrl.onBulkSuccess"
data-on-error="ProgrammableKeysCtrl.onBulkError">
</telephony-bulk-action>

<tbody data-ng-if="ProgrammableKeysCtrl.functionKeys.raw.length && !ProgrammableKeysCtrl.loading.keys">
<tr data-ng-repeat="key in ProgrammableKeysCtrl.functionKeys.raw | orderBy:ProgrammableKeysCtrl.order.by:ProgrammableKeysCtrl.order.desc track by $index">
<td headers="keys" data-ng-bind="key.label || '-'"></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@
<translation id="telephony_line_phone_programmableKeys_MENU" qtlid="304576">Menu</translation>
<translation id="telephony_line_phone_programmableKeys_DIRECTORY" qtlid="61656">Répertoire</translation>

<translation id="telephony_line_phone_programmableKeys_bulk_all_success">La modification de la présentation du numéro a bien été appliquée aux services sélectionnés.</translation>
<translation id="telephony_line_phone_programmableKeys_bulk_some_success">La modification de la présentation du numéro a bien été appliquée à {{ count }} des services sélectionnés.</translation>
<translation id="telephony_line_phone_programmableKeys_bulk_error">La modification de la présentation du numéro n'a pu être appliquée au(x) service(s) suivant(s) :</translation>
<translation id="telephony_line_phone_programmableKeys_bulk_error_details">Cette fonction n'est pas supportée par ce téléphone</translation>
<translation id="telephony_line_phone_programmableKeys_bulk_on_error">Oups ! Une erreur est survenue lors de la modification de la présentation du numéro.</translation>

<translation id="telephony_line_phone_programmableKeys_available_function_param_select" qtlid="337533">Sélectionnez un paramètre</translation>
<translation id="telephony_line_phone_programmableKeys_FAX" qtlid="32926">Fax</translation>
</translations>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* @ngdoc object
* @name managerApp.object:VoipLinePhoneFunction
*
* @description
* <p>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.</p>
*
* @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;
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @ngdoc service
* @name managerApp.service:voipLinePhoneFunction
*
* @description
* <p>Service that manage function keys of phone linked to sip and mgcp features of services with serviceType line.</p>
* <p>This service will manage API calls to `/telephony/{billingAccount}/line/{serviceName}/phone/functionKey/{keyNum}`</p>
*/
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);
})
);
}
});

0 comments on commit ccf4b73

Please sign in to comment.