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

Commit

Permalink
Merge pull request #479 from ovh-ux/feature/bulkChangeType
Browse files Browse the repository at this point in the history
Feature/bulk change type
  • Loading branch information
Jisay authored Jan 3, 2018
2 parents 1b9d8f5 + 7eeb345 commit 11b1262
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
angular.module("managerApp").controller("TelecomTelephonyAliasConfigurationChangeTypeCtrl", function ($scope, $q, $translate, $state, $stateParams, TelephonyMediator, Toast) {
angular.module("managerApp").controller("TelecomTelephonyAliasConfigurationChangeTypeCtrl", function ($scope, $q, $translate, $state, $stateParams, TelephonyMediator, Toast, voipServiceTask, telephonyBulk) {
"use strict";

var self = this;

self.number = null;

self.noCache = false;
self.loading = {
changing: false,
line: true
};

self.successfulTasks = [];

/*= ==============================
= ACTIONS =
===============================*/
Expand Down Expand Up @@ -41,7 +43,7 @@ angular.module("managerApp").controller("TelecomTelephonyAliasConfigurationChang
function init () {
self.loading.line = true;

return TelephonyMediator.getGroup($stateParams.billingAccount).then(function (group) {
return TelephonyMediator.getGroup($stateParams.billingAccount, self.noCache).then(function (group) {
self.number = group.getNumber($stateParams.serviceName);
return self.number;
}).then(function () {
Expand All @@ -59,6 +61,7 @@ angular.module("managerApp").controller("TelecomTelephonyAliasConfigurationChang
];

self.number.feature.startEdition();
self.noCache = false;

return self.number;
}).catch(function (error) {
Expand All @@ -77,6 +80,96 @@ angular.module("managerApp").controller("TelecomTelephonyAliasConfigurationChang

/* ----- End of INITIALIZATION ------*/

init();
/* ===========================
= BULK =
============================ */

self.bulkDatas = {
infos: {
name: "configurationNumberChangeType",
actions: [{
name: "options",
route: "/telephony/{billingAccount}/number/{serviceName}/changeFeatureType",
method: "POST",
params: null
}]
}
};

self.getBulkParams = function () {
var data = {
featureType: self.number.feature.featureType
};

return data;
};

self.onBulkSuccess = function (bulkResult) {

// check if server tasks are all successful
self.checkServerTasksStatus(bulkResult.success).then(function () {

// if one of the promises fails, the failed result won't be store in tasksChecked
if (self.successfulTasks.length < bulkResult.success.length) {
Toast.warn([$translate.instant("telephony_alias_config_change_type_bulk_server_tasks_some_error")]);
}

telephonyBulk.getToastInfos(bulkResult, {
fullSuccess: $translate.instant("telephony_alias_config_change_type_bulk_all_success"),
partialSuccess: $translate.instant("telephony_alias_config_change_type_bulk_some_success", {
count: bulkResult.success.length
}),
error: $translate.instant("telephony_alias_config_change_type_bulk_error")
}).forEach(function (toastInfo) {
Toast[toastInfo.type](toastInfo.message, {
hideAfter: null
});
});

// force v7 reset cache
TelephonyMediator.getAll(true).then(function () {
$state.go("telecom.telephony.alias.configuration");
});
}, function () {
Toast.error([$translate.instant("telephony_alias_config_change_type_bulk_server_tasks_all_error")]);
self.loading.changing = false;
});
};

self.onBulkError = function (error) {
Toast.error([$translate.instant("telephony_alias_config_change_type_bulk_on_error"), _.get(error, "msg.data")].join(" "));
};


self.checkServerTasksStatus = function (updatedServices) {

function runPollOnTask (billingAccount, serviceName, taskId) {
return function () {
return voipServiceTask.startPolling(billingAccount, serviceName, taskId);
};
}

self.loading.changing = true;

var chain = $q.when();

_.forEach(updatedServices, function (service) {
var id = _.head(_.chain(service.values).map("value").filter(function (val) {
return val.action === "changeType";
}).value()).taskId;

// chaining each promises
chain = chain.then(runPollOnTask(service.billingAccount, service.serviceName, id)).then(function (result) {
if (result) {
self.successfulTasks.push(result);
}
});
});

return chain;
};

/* ----- End of BULK ------ */

init();
});
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ <h1 data-translate="telephony_alias_change_type_title"></h1>
<option value="" data-translate="telephony_alias_config_change_type_label_select" disabled></option>
</select>
</div>

<telephony-bulk-action data-service-type="alias"
data-billing-account="{{ AliasConfigurationChangeTypeCtrl.number.billingAccount }}"
data-service-name="{{ AliasConfigurationChangeTypeCtrl.number.serviceName }}"
data-custom-class="link d-block pl-0 mb-3"
data-bulk-infos="AliasConfigurationChangeTypeCtrl.bulkDatas.infos"
data-ng-disabled="!changeTypeForm.$valid"
data-get-bulk-params="AliasConfigurationChangeTypeCtrl.getBulkParams"
data-on-success="AliasConfigurationChangeTypeCtrl.onBulkSuccess"
data-on-error="AliasConfigurationChangeTypeCtrl.onBulkError">
</telephony-bulk-action>

<button type="submit"
class="btn btn-primary"
data-ng-disabled="!changeTypeForm.$valid || AliasConfigurationChangeTypeCtrl.loading.changing || !AliasConfigurationChangeTypeCtrl.number.feature.hasChange()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,10 @@
<translation id="telephony_alias_config_change_type_label_empty" qtlid="333230">Aucune fonctionnalité</translation>
<translation id="telephony_alias_config_change_type_desc_empty" qtlid="333243">Pas de fonctionnalité</translation>

<translation id="telephony_alias_config_change_type_bulk_all_success">La modification du type du numéro a bien été appliquée aux services sélectionnés</translation>
<translation id="telephony_alias_config_change_type_bulk_some_success">La modification du type du numéro à {{ count }} des services sélectionnés</translation>
<translation id="telephony_alias_config_change_type_bulk_error">La modification du type du numéro n'a pu être appliquée au(x) service(s) suivant(s) :</translation>
<translation id="telephony_alias_config_change_type_bulk_on_error">Oups ! Une erreur est survenue lors de la modfication du type du numéro</translation>
<translation id="telephony_alias_config_change_type_bulk_server_tasks_some_error">Attention : une erreur est survenue lors de la modification du type de numéro sur l'un des services sélectionnés</translation>
<translation id="telephony_alias_config_change_type_bulk_server_tasks_all_error">Oups ! Une erreur est survenue lors des tâches de modfication du type du numéro</translation>
</translations>
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,12 @@ angular.module("managerApp").controller("TelecomTelephonyAliasConfigurationCtrl"
self.loading.init = true;

return TelephonyMediator.getGroup($stateParams.billingAccount).then(function (group) {
self.number = group.getNumber($stateParams.serviceName);
return group.fetchService($stateParams.serviceName).then(function (number) {
self.number = number;

return self.number.feature.init().then(function () {
self.actions = initActions();
return self.number.feature.init().then(function () {
self.actions = initActions();
});
});
}).catch(function (error) {
Toast.error([$translate.instant("telephony_alias_configuration_load_error"), _.get(error, "data.message", "")].join(" "));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<translations>
<translation id="telephony_bulk_action_apply_to_alias">Appliquer à plusieurs numéros</translation>
<translation id="telephony_bulk_action_apply_to_line">Appliquer à plusieurs lignes</translation>
<translation id="telephony_bulk_action_apply_to_number">Appliquer à plusieurs numéros</translation>
<translation id="telephony_bulk_action_apply_to_service_explain">Choisissez les services auxquels appliquer les changements. Cette action remplacera toute configuration existante.</translation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,32 @@ angular.module("managerApp").factory("TelephonyGroup", function ($q, OvhApiTelep
});
};


TelephonyGroup.prototype.fetchService = function (serviceName) {
var self = this;
var number;

// TODO : handle when service is not an alias
return OvhApiTelephony.Number().Lexi().get({
billingAccount: self.billingAccount,
serviceName: serviceName
}).$promise.then(function (numberOptions) {
number = new TelephonyGroupNumber(angular.extend(numberOptions, {
billingAccount: self.billingAccount
}));

if (self.getNumber(number.serviceName)) {
self.numbers.splice(_.findIndex(self.numbers, function (n) {
return n.serviceName === number.serviceName;
}), 1, number);
} else {
self.addNumber(number);
}

return number;
});
};

/* ---------- REPAYMENT CONSUMPTION ----------*/

TelephonyGroup.prototype.getRepaymentConsumption = function () {
Expand Down

0 comments on commit 11b1262

Please sign in to comment.