(function () { 'use strict'; var app = angular.module('tasks'); var templatePath = modulesSharedResourcesUrl + 'Modules/Tasks/Views/'; //a directive that renders the task classes list app.directive('taskList', ['tasksDataContext', 'tasksService', 'common', '$location', '$modal', function (tasksDataContext, tasksService, common, $location, $modal) { return { restrict: 'E', templateUrl: templatePath + 'tasklist.html?version=270122', link: link }; function link($scope, elem, attrs) { var getLogFn = common.logger.getLogFn; var logSuccess = getLogFn("taskClass", "success"); var logError = getLogFn("taskClass", "error"); $scope.orderByPredicate = '-dateAssigned'; // Define the status filters $scope.filters = [ { name: 'Assigned', value: null, class: 'text-primary' }, { name: 'In progress', value: 9, class: 'text-warning' }, { name: 'Submitted', value: 4, class: 'text-dark' }, { name: 'Under review', value: 5, class: 'text-warning' }, { name: 'Reviewed', value: 6, class: 'text-success' }, { name: 'Completed', value: 8, class: 'text-success' }, { name: 'Returned', value: 7, class: 'text-danger' }, { name: 'Recalled', value: 1, class: 'text-danger' } ]; $scope.filterValues = [null, 0, 4, 5, 6, 7, 8, 9]; // Apply the status filters $scope.applyStatusFilter = function (value, index) { return $scope.filterValues.indexOf(value.status) !== -1; } // Table headers for tasks $scope.tableHeaders = [ { name: "Name", minWidth: "300px" }, { name: "Description", }, { name: "Assigned on", width: "150px" }, { name: "Status", width: "160px" }, { name: "Deadline", width: "120px" } ]; // Order options for tasks $scope.orderOptions = [ { name: 'Name', value: { predicate: 'taskRecord.name', reverse: false }, }, { name: 'Description', value: { predicate: 'taskRecord.description', reverse: false }, }, { name: 'Assigned on', value: { predicate: 'dateAssigned', reverse: true }, }, { name: 'Status', value: { predicate: 'status', reverse: false }, }, { name: 'Deadline', value: { predicate: 'deadline', reverse: false }, } ]; // Currently selected order option $scope.currentOrder = $scope.orderOptions[0]; function getMyTasks() { tasksDataContext.getAssignedTasks().then(function (tasks) { $scope.tasks = tasks; angular.forEach($scope.tasks, function(task){ task.name = task.taskRecord.name; task.description = task.taskRecord.description; var responseTypes = task.taskRecord.taskResponseTypes; var responses = task.taskAssignmentResponses; //There are no database 'inprogress' or 'completed' statuses so figure these out now // if there's should be a response but not one submitted yet, then it should be inprogress if(task.status == 0 && responses != null && responses.length > 0){ task.status = 8; } // otherwise assigned if(task.status != 1 && responses != null && responses.length == 0){ task.status = 0; } // if there should be response and one has been submitted if(task.status == 4 && responseTypes != null && responseTypes.length > 0){ task.status = 4; } // otherwise completed if(task.status == 4 && (responseTypes == null || responseTypes.length == 0)){ task.status = 9; } if (task.taskAssignmentResponses.length == 0 && task.status !== 1) { task.status = null; } }) $scope.tasksLoaded = true; }); } $scope.startAssignedTask = function (assignedTask) { tasksService.setCurrentAssignedTask(assignedTask); } getMyTasks(); } }]); //a directive that renders the task classes list app.directive('viewTask', ['tasksDataContext', 'tasksService', 'commentsDataContext', 'datacontext', 'user', 'myFormsService', 'myFormsDataContext', 'common', '$location', '$rootScope', '$filter', 'config', '$window', function (tasksDataContext, tasksService, commentsDataContext, datacontext, user, myFormsService, myFormsDataContext, common, $location, $rootScope, $filter, config, $window) { return { restrict: 'E', templateUrl: templatePath + 'viewtask.html?version=270122', link: link }; function link($scope, elem, attrs) { var getLogFn = common.logger.getLogFn; var logSuccess = getLogFn("taskClass", "success"); var logError = getLogFn("taskClass", "error"); $scope.currentAssignedTask = tasksService.getCurrentAssignedTask(); if ($scope.currentAssignedTask) { $window.document.title = "MyShowcase > Task: " + $scope.currentAssignedTask.name; } $scope.comment = { content: '', isPrivate: false, }; $scope.showcases = []; $scope.siteUrl = config.siteUrl; $scope.formTypes = tasksService.getFormTypes(); $scope.selectedItemId = null; // Focus the task menu, creating a tab loop $scope.focusTaskMenu = function () { $('#focus-loopback-toolbar a:first-child').focus(); } //get showcases for this user function getShowcases() { datacontext.getShowcases().then(function (result) { for (var i = 0; i < result.length; i++) { if (result[i].showcaseState == "Published") { $scope.showcases.push(result[i]); } } if ($scope.showcases.length == 0) { $scope.noShowcases = true; } }); } // Get all the available forms for a user function getAllForms(type) { myFormsDataContext.getAvailableTemplates($scope.currentAssignedTask.ownerId).then(function (data) { //Don't include activity forms var filteredTemplates = $filter('filter')(data, function(template){ return template.formType != 5; }); if (type) { $scope.availableForms = []; for (i in data) { if (data[i].formType == type) { $scope.availableForms.push(data[i]); } } } else { $scope.availableForms = filteredTemplates; } $scope.availableFormsLoaded = true; }); } //get items for this user function getItems() { datacontext.getMyItemsRequest().then(function (items) { if (items.length == 0) { $scope.noItems = true; return; } if (items.items) $scope.items = items.items; else $scope.items = items; }); } function getComment() { if ($scope.currentAssignedTask.latestResponse) { if ($scope.currentAssignedTask.latestResponse.commentId !== "00000000-0000-0000-0000-000000000000") { commentsDataContext.getCommentById($scope.currentAssignedTask.latestResponse.commentId).then(function (comment) { $scope.comment = comment; }); } } } /* * Get showcase data from web service then set in selectedShowcase variable */ function getShowcaseDetail(showcaseId) { tasksDataContext.getShowcase(showcaseId).then(function (showcase) { $scope.selectedShowcase = showcase; }); } /* * Pick the matching showcase from she showcases array using an id */ function getSelectedShowcaseDetail(showcaseId){ angular.forEach($scope.showcases, function(s){ if(s.showcaseId == showcaseId){ $scope.selectedShowcase = s; $scope.deliverableValue = showcaseId return; } }); } /* * Get item data from web service then set in selectedItem variable */ $scope.getItemDetail = function (itemId) { $scope.item = null; if (itemId) { datacontext.getItem(itemId).then(function (item) { $scope.item = item; $scope.deliverableValue = config.myShowcaseItemApiUrl + item.type.replace(/\s/g, '') + 'items/' + item.itemId; }); } } $scope.getItemDetailBySource = function (source) { if (source) { datacontext.getItemDetailBySource(source).then(function (item) { $scope.item = item; $scope.deliverableValue = config.myShowcaseItemApiUrl + item.type.replace(/\s/g, '') + 'items/' + item.id; }); } } $scope.getFormDetail = function(formId) { tasksDataContext.getFormTemplate(formId).then(function (form) { $scope.selectedForm = myFormsService.createFormFromTemplate(form) }); } function getCompletedFormDetail(formId) { tasksDataContext.getCompletedForm(formId).then(function (form) { $scope.availableFormsLoaded = true; $scope.selectedForm = form; }); } if (!$scope.currentAssignedTask) { $location.path('/tasks'); } else { getItems(); datacontext.getShowcases().then(function (result) { for (var i = 0; i < result.length; i++) { if (result[i].showcaseState == "Published") { $scope.showcases.push(result[i]); } } if ($scope.showcases.length == 0) { $scope.noShowcases = true; } if ($scope.currentAssignedTask.latestResponse) { getComment(); if ($scope.currentAssignedTask.taskRecord.taskResponseTypes.length > 0) { if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskClassResponseType.name == 'Showcase') { $scope.responseType = 'Showcase'; getSelectedShowcaseDetail($scope.currentAssignedTask.latestResponse.taskAssignmentResponseDeliverables[0].value) } if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskClassResponseType.name == 'Stuff item') { $scope.responseType = 'Stuff item'; $scope.getItemDetailBySource($scope.currentAssignedTask.latestResponse.taskAssignmentResponseDeliverables[0].value) } if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskClassResponseType.name == 'Form') { $scope.responseType = 'Form'; $scope.deliverableValue = $scope.currentAssignedTask.latestResponse.taskAssignmentResponseDeliverables[0].value if($scope.deliverableValue != null){ getCompletedFormDetail($scope.currentAssignedTask.latestResponse.taskAssignmentResponseDeliverables[0].value); } if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskResponseTypeProperties.length > 0) { if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskResponseTypeProperties[0].name == 'formType') { getAllForms($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskResponseTypeProperties[0].value); } else { getAllForms(); } }else { getAllForms(); } } } } else { if ($scope.currentAssignedTask.taskRecord.taskResponseTypes.length > 0) { if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskClassResponseType.name == 'Form') { $scope.responseType = 'Form'; if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskResponseTypeProperties.length > 0) { if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskResponseTypeProperties[0].name == 'formTemplateId') { var formId = $scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskResponseTypeProperties[0].value; if(formId != null){ $scope.getFormDetail(formId); } } else { getAllForms($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskResponseTypeProperties[0].value); } } else { getAllForms(); } } } } }); } // if status == 0 we save, else 1 is submit $scope.saveResponse = function (status, noRedirect, formResponse) { if ($scope.currentAssignedTask.taskRecord.taskResponseTypes.length > 0) { if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskClassResponseType.name == 'Form') { $scope.submitStatus = status; if($scope.selectedForm != null){ $scope.selectedForm.externalId = $scope.currentAssignedTask.ownerId; $rootScope.$broadcast('saveFormResponse', { isComplete: status, isHosted: true }); } else { $scope.doSubmit(status, noRedirect, formResponse); } } else { $scope.doSubmit(status, noRedirect, formResponse); } } else { $scope.doSubmit(status, noRedirect, formResponse); } } $scope.doSubmit = function (status, noRedirect, formResponse) { commentsDataContext.createComment($scope.comment).then(function (data) { var response = { taskIndividualAssignmentId: $scope.currentAssignedTask.id, commentId: data.id, taskAssignmentResponseDeliverables: [], status: status, toComplete: status == 1 //Tell the service whether or not this is 'save' or 'complete' } if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0]) { response.taskAssignmentResponseDeliverables = [{ taskResponseTypeId: $scope.currentAssignedTask.taskRecord.taskResponseTypes[0].id, value: $scope.deliverableValue }]; if ($scope.currentAssignedTask.latestResponse) { if ($scope.currentAssignedTask.latestResponse.taskAssignmentResponseDeliverables.length > 0) { $scope.currentAssignedTask.latestResponse.taskAssignmentResponseDeliverables[0].value = $scope.deliverableValue; delete $scope.currentAssignedTask.latestResponse.taskAssignmentResponseDeliverables[0].id; } } } // It's a brand new response if (!$scope.currentAssignedTask.latestResponse) { if ($scope.currentAssignedTask.taskRecord.autoComplete) { response.status = status == 1 ? 6 : 0; tasksDataContext.submitAutoCompleteTaskResponse(response).then(function (data) { if (status == 0) { logSuccess("Response successfully saved"); } if (status == 1) { logSuccess("Response successfully submitted"); } if (!noRedirect) $location.path('/tasks'); }); } else { tasksDataContext.submitTaskResponse(response).then(function (data) { if (status == 0) { logSuccess("Response successfully saved"); } if (status == 1) { logSuccess("Response successfully submitted"); } if (!noRedirect) $location.path('/tasks'); }); } } else { $scope.currentAssignedTask.latestResponse.status = status; $scope.currentAssignedTask.latestResponse.commentId = data.id; $scope.currentAssignedTask.latestResponse.toComplete = status == 1; if ($scope.currentAssignedTask.taskRecord.autoComplete) { $scope.currentAssignedTask.latestResponse.status = status == 1 ? 6 : 0; tasksDataContext.updateAutoCompleteTaskResponse($scope.currentAssignedTask.latestResponse).then(function (data) { if (status == 0) { logSuccess("Response successfully saved"); } if (status == 1) { logSuccess("Response successfully submitted"); } if (!noRedirect) $location.path('/tasks'); }); } else { tasksDataContext.updateTaskResponse($scope.currentAssignedTask.latestResponse).then(function (data) { if (status == 0) { logSuccess("Response successfully saved"); } if (status == 1) { logSuccess("Response successfully submitted"); } if (!noRedirect) $location.path('/tasks'); }); } } }); } //Set the selected showcase $scope.setSelectedShowcase = function (selectedShowcase) { $scope.selectedShowcase = selectedShowcase; if (selectedShowcase) { $scope.deliverableValue = selectedShowcase.showcaseId; } } $scope.getMarkingSchemeDetailsForValue = function (markingScheme) { for (var i = 0; i < $scope.currentAssignedTask.taskRecord.taskMarkingSchemes.length; i++) { if (markingScheme.taskMarkingSchemeId == $scope.currentAssignedTask.taskRecord.taskMarkingSchemes[i].id) { $scope.getMarkingScheme(markingScheme, $scope.currentAssignedTask.taskRecord.taskMarkingSchemes[i].markingSchemeId); } } } $scope.getMarkingScheme = function (markingScheme, markingSchemeId) { tasksDataContext.getMarkingScheme(markingSchemeId).then(function (data) { markingScheme.markingScheme = data; return markingScheme; }); } $scope.getAssignerDetails = function (assigner) { if (assigner) { user.getUserProfile(assigner.createdBy).then(function (data) { assigner.user = data; }); } } $scope.getUserDetails = function (assignedTask) { if (assignedTask) { user.getUserProfile(assignedTask.ownerId).then(function (data) { assignedTask.user = data; }); } } $scope.checkResponseValidility = function () { if ($scope.currentAssignedTask.taskRecord.taskResponseTypes.length>0) { if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskClassResponseType.name == 'Showcase') { if (!$scope.selectedShowcase) { return true; } } if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskClassResponseType.name == 'Form') { if (!$scope.selectedForm) { return true; } } if ($scope.currentAssignedTask.taskRecord.taskResponseTypes[0].taskClassResponseType.name == 'Stuff item') { if (!$scope.item) { return true; } } } } $scope.onFormItemCreated = function (form) { $scope.deliverableValue = form.formId; $scope.doSubmit($scope.submitStatus, false); } $scope.downloadFile = function (fileUrl, fileName) { var url; user.getUploadBucketSas().then(function (sas) { $scope.sasToken = sas.sas; $scope.requiresAuth = true; //set the sas token start and end dates $scope.tokenStart = new Date().getTime(); $scope.tokenEnd = $scope.tokenStart + 1800000; url = fileUrl + $scope.sasToken; $window.open(url); }); } $scope.canManageTasks = function () { return $rootScope.currentRole.functions.find(item => item === 'mytasks_manage'); } } }]); // MyProgress Assessment items app.directive('itemAssessment', function () { return { restrict: 'E', templateUrl: templatePath + 'templates/assessment2.html', scope: { myShowcaseItem: '=', accessToken: '=', hideDate: '=' }, link: function ($scope, element, attrs) { function lowerFirstLetterObjectKeys(input) { if (typeof input !== 'object' || input == null) return input; if (Array.isArray(input)) return input.map(lowerFirstLetterObjectKeys); return Object.keys(input).reduce(function (newObj, key) { let val = input[key]; let newVal = (typeof val === 'object') ? lowerFirstLetterObjectKeys(val) : val; newObj[key.replace(key[0], key[0].toLowerCase())] = newVal; return newObj; }, {}); } function parseResponse(jsonResponse) { //Parse json, restoring properties to PascalCase where needed var parsedResponse = JSON.parse(jsonResponse, function (key, value) { if (key.length < 2 || key[0] === key[0].toUpperCase() || key === "allocatedAssessmentGuid" || key === "publishedResourceId" || key === "responseIdentifier" || key === "usingEmail" || key === "data" || key === "type" || key === "width" || key === "height" || key === "src") { return value; } else { var newKey = key.replace(key[0], key[0].toUpperCase()); this[newKey] = value; return undefined; //removes old key } }); //recursively return result properties to camel case. We can't do this in the reviver function when parsing //because only properties in the result object hierarchy should be changed, and some share names with properties //in other objects parsedResponse.Result = lowerFirstLetterObjectKeys(parsedResponse.Result); //StreamedResource.Type is an exception to the rule that all 'type' properties are lowercase parsedResponse.StreamedResources.forEach(function (resource) { if (resource.Type == undefined && resource.type != undefined) { resource.Type = resource.type; } }); return parsedResponse; } if (typeof $scope.myShowcaseItem.jsonResponse === 'string') $scope.myShowcaseItem.jsonResponse = parseResponse($scope.myShowcaseItem.jsonResponse); if (!$scope.myShowcaseItem.itemId) $scope.myShowcaseItem.itemId = $scope.myShowcaseItem.id; $scope.getLetter = function (index) { if (0 <= index && index <= 25) { return String.fromCharCode(65 + index); } else if (26 <= index <= 51) { return String.fromCharCode(71 + index); } else { return ''; } } $scope.getAssessmentItemResultFromCustomText = function (customText) { var assessmentItemIdentifier = $scope.getAssessmentItemIdentifier(customText); if (assessmentItemIdentifier.length > 0) { var result = $scope.getAssessmentItemResult(assessmentItemIdentifier); return result; } return null; } $scope.getAssessmentItemResult = function (assessmentItemIdentifier) { var resultArray = $scope.myShowcaseItem.jsonResponse.Result.itemResults.filter(function (assessmentItemResult) { return assessmentItemResult.identifier === assessmentItemIdentifier; }) if (resultArray.length > 0) { return resultArray[0]; } else { return null; } } $scope.getAssessmentItemIdentifier = function (customText) { var identifierString = 'identifier:'; if (customText && customText.length > 0 && customText.indexOf(identifierString) > -1) { var startIndex = customText.indexOf(identifierString) + identifierString.length; return customText.substring(startIndex); } return ''; } $scope.isAssessmentItemHidden = function (customText) { if (customText && customText.length > 0) { for (var i = 0; i < $scope.myShowcaseItem.jsonResponse.HiddenAssessmentItemIdentifiers.length; i++) { if (customText.includes($scope.myShowcaseItem.jsonResponse.HiddenAssessmentItemIdentifiers[i])) { return true; } } } return false; } } }; }); })();