SmartIT_Extensions/BMC/smart-it-full-helix/scripts/app/change/impact-analysis-controller.js

182 lines
7.8 KiB
JavaScript

"use strict";
/**
* Created by etang on 8/28/15.
*/
(function () {
'use strict';
angular.module('changeModule')
.controller('ImpactAnalysisController', ['$scope', 'ticketModel', 'relationModel', 'systemAlertService', '$filter', 'i18nService', '$stateParams', '$state', function ($scope, ticketModel, relationModel, systemAlertService, $filter, i18nService, $stateParams, $state) {
var services = [], impactedCIs = [];
$scope.state = {
isLoading: false,
preparingGraph: false,
largeData: false,
isFixed: false,
isFullScreen: false
};
$scope.edges = [];
$scope.nodes = [];
$scope.servicesCount = 0;
$scope.selections = [];
function init() {
$scope.state.isLoading = true;
$scope.displayId = $stateParams.displayId;
ticketModel.getImpactAnalysisVisualisationData($stateParams.type, $stateParams.id).then(function (impactData) {
impactedCIs = impactData.impactedCIs;
var relations = impactData.impactAssociations;
var nodesList = [], edgesList = [];
_.each(impactedCIs, function (ci) {
if (ci.isService) {
services.push(ci);
}
var icon = ci.subType.toLowerCase().replace(' ', '');
var node = {
group: 'nodes',
data: {
id: ci.reconciliationId,
label: ci.name,
icon: icon
},
classes: icon
};
nodesList.push(node);
});
$scope.servicesCount = services.length;
_.each(relations, function (relation) {
var impactingCI = relation.impactingCI, impactedCI = relation.impactedCI;
var edge = {
group: 'edges',
data: { source: impactingCI.reconciliationId, target: impactedCI.reconciliationId }
};
edgesList.push(edge);
});
$scope.edges = edgesList;
$scope.nodes = nodesList;
if ($scope.nodes.length > 1000) {
$scope.state.preparingGraph = true;
$scope.state.largeData = true;
}
$scope.state.isLoading = false;
});
}
$scope.$on('impactGraphInit', function (e, data) {
if (data.state === 1) {
$scope.state.preparingGraph = true;
}
else if (data.state === 0) {
$scope.state.preparingGraph = false;
}
});
init();
$scope.relateServices = function () {
var relatedCIs = [];
_.each(services, function (ci) {
if (!ci.isRelated) {
relatedCIs.push({
id: ci.reconciliationId,
desc: ci.name,
tag: "linkeditem",
relationshipType: "impacts",
type: "asset"
});
}
});
relate(relatedCIs);
};
$scope.relateSelected = function () {
var relatedCIs = [];
_.each($scope.selections, function (ci) {
relatedCIs.push({
id: ci,
tag: "linkeditem",
relationshipType: "impacts",
type: "asset"
});
});
relate(relatedCIs);
};
$scope.relateAll = function () {
var relatedCIs = [];
_.each(impactedCIs, function (ci) {
if (!ci.isRelated) {
relatedCIs.push({
id: ci.reconciliationId,
desc: ci.name,
tag: "linkeditem",
relationshipType: "impacts",
type: "asset"
});
}
});
relate(relatedCIs);
};
$scope.close = function () {
$state.go('change', { id: $stateParams.id });
};
$scope.discard = function () {
return systemAlertService.modal({
title: i18nService.getLocalizedString('impact.analysis.dismiss.modal.title'),
text: i18nService.getLocalizedString('impact.analysis.dismiss.modal.text'),
buttons: [
{
text: i18nService.getLocalizedString('common.button.yes'),
data: true
},
{
text: i18nService.getLocalizedString('common.button.no'),
data: false
}
]
}).result.then(function (data) {
if (data) {
discardImpactAnalysis();
}
});
};
function discardImpactAnalysis() {
var command = { "command": "dismiss" };
ticketModel.impactAnalysisAction($stateParams.id, EntityVO.TYPE_CHANGE, command);
$scope.close();
}
function relate(relatedCIs) {
var modalOptions = {
type: 'info',
title: i18nService.getLocalizedString('impactAnalysis.relateAndComplete.title'),
text: i18nService.getLocalizedStringwithParams('impactAnalysis.relateAndComplete.question', [relatedCIs.length]),
details: i18nService.getLocalizedString('impactAnalysis.relateAndComplete.details'),
buttons: [
{
text: i18nService.getLocalizedString('impactAnalysis.relateAndComplete.confirmation.yes'),
data: true
},
{
text: i18nService.getLocalizedString('impactAnalysis.relateAndComplete.confirmation.no'),
data: false
}
]
};
if (relatedCIs.length >= 80) {
modalOptions.additionalInfo = i18nService.getLocalizedString('create.change.wizard.ci.confirmCIRelation.text');
}
return systemAlertService.modal(modalOptions).result.then(function (data) {
if (data) {
return proceedWithRelatingCIs(relatedCIs);
}
});
}
function proceedWithRelatingCIs(relatedCIs) {
$scope.showProgressModal = true;
relationModel.addRelation({ uuid: $stateParams.id, type: EntityVO.TYPE_CHANGE }, relatedCIs)
.finally(function () {
$scope.showProgressModal = false;
systemAlertService.success({
text: $filter('i18n')('ticket.notification.link.message', relatedCIs.length),
hide: 10000
});
discardImpactAnalysis();
});
}
}
]);
})();