(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 = deployment.stages.filter(function (s) { return s.type !== 'StartProgressTrackerWorkflow' && s.type !== 'CompleteProgressTracker' && s.type !== 'Finish'; }) 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 = null; } deployment.progress = Math.round((100 / deployment.stages.length) * deployment.stages.filter(function (s) { return s.log ? true : false }).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.orderByPredicate = 'user.firstName'; $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() { var userIds = []; dashboardDataContext.getWorkflowDeploymentsForOthers().then(function (deployments) { $scope.deployments = deployments; angular.forEach($scope.deployments, function (deployment) { if (deployment.blockingStage.stageType === 'DeployProgressTracker' || deployment.blockingStage.stageType === 'ManualActivity') deployment.blockingStage.actionLink = '#!/workflows/deployments/' + deployment.id + '/for/' + deployment.forId + '/stages/' + deployment.blockingStage.id; userIds.push(deployment.forId) }); $scope.getUserDetails(userIds); }); } $scope.getUserDetails = function (userIds) { user.getUsers(userIds).then(function (data) { angular.forEach($scope.deployments, function (deployment) { deployment.user = data.filter(function (u) { return u.id === deployment.forId })[0]; }); $scope.loadedWorkflowDeployments = true; }); }; $scope.signalWorkflow = function (deploymentId, forId, signal) { dashboardDataContext.signalWorkflowStage(deploymentId, forId, signal).then(function () { getDeployments(); }); }; } }]); })();