(function () { 'use strict'; var app = angular.module('dashboard'); var templatePath = modulesSharedResourcesUrl + 'Modules/Dashboard/Views/'; app.directive('userDashboard', ['$rootScope', 'common', 'terminology', 'user', 'dashboardDataContext', 'branding', function ($rootScope, common, terminology, user, dashboardDataContext, branding) { return { restrict: 'E', templateUrl: templatePath + 'userdashboard.html', link: link }; function link($scope, elem, attrs) { var getLogFn = common.logger.getLogFn; var log = getLogFn('dashboard'); $scope.branding = branding; $scope.terminology = terminology; $scope.loadedWorkflowDeployments = false; activate(); $rootScope.$on('roleTokenSet', function (event, args) { activate(); }); function activate() { user.getProfile(true).then(function (theUser) { $scope.user = theUser; getDeployments(); }); NProgress.done(); log('Activated Dashboard View'); } function getDeployments() { dashboardDataContext.getWorkflowDeploymentsForMe().then(function (deployments) { $scope.deployments = deployments; angular.forEach($scope.deployments, function (deployment) { deployment.stages.shift(); deployment.stages.pop(); for (let i = 0; i < deployment.stages.length; i++) { deployment.stages[i].state = JSON.parse(deployment.stages[i].state); if (deployment.stages[i].canAccess && (deployment.stages[i].blocking || deployment.stages[i].log)) { deployment.stages[i].actionLink = `#!/workflows/deployments/${deployment.id}/for/${$scope.user.userId}/stages/${deployment.stages[i].stageId}`; } else { deployment.stages[i].actionLink = 'javascript:void'; } deployment.progress = Math.round((100 / deployment.stages.length) * deployment.stages.filter(s => s.log).length) } }); $scope.loadedWorkflowDeployments = true; }); } $scope.signalWorkflow = function (deploymentId, forId, signal) { dashboardDataContext.signalWorkflowStage(deploymentId, forId, signal).then(function () { getDeployments(); }); }; } }]); app.directive('adminDashboard', ['$rootScope', 'common', 'terminology', 'user', 'dashboardDataContext', 'branding', function ($rootScope, common, terminology, user, dashboardDataContext, branding) { return { restrict: 'E', templateUrl: templatePath + 'admindashboard.html', link: link }; function link($scope, elem, attrs) { var getLogFn = common.logger.getLogFn; var log = getLogFn('dashboard'); $scope.branding = branding; $scope.terminology = terminology; $scope.loadedWorkflowDeployments = false; $scope.pagination = { current: 1 }; $scope.pageSize = 5; activate(); $rootScope.$on('roleTokenSet', function (event, args) { activate(); }); function activate() { getUser(true); getDeployments(); NProgress.done(); log('Activated Dashboard View'); } function getUser(refresh) { user.getProfile(refresh).then(function (theUser) { $scope.user = theUser; }); } function getDeployments() { dashboardDataContext.getWorkflowDeploymentsForOthers().then(function (deployments) { $scope.deployments = deployments; angular.forEach($scope.deployments, function (deployment) { for (let i = 0; i < deployment.stages.length; i++) { deployment.stages[i].state = JSON.parse(deployment.stages[i].state); if (deployment.stages[i].type === 'DeployProgressTracker' || deployment.stages[i].type === 'ManualActivity') deployment.stages[i].actionLink = `#!/workflows/deployments/${deployment.id}/for/${deployment.forId}/stages/${deployment.stages[i].stageId}`; } $scope.getUserDetails(deployment); }); $scope.loadedWorkflowDeployments = true; }); } $scope.getUserDetails = function (model) { if (model) { user.getUserProfile(model.forId).then(function (data) { return model.user = data; }); } }; $scope.signalWorkflow = function (deploymentId, forId, signal) { dashboardDataContext.signalWorkflowStage(deploymentId, forId, signal).then(function () { getDeployments(); }); }; } }]); })();