From d3e1d2774db92035b610b397ae1bd0240a9bd3bd Mon Sep 17 00:00:00 2001 From: William Welling Date: Wed, 28 Aug 2024 14:35:34 -0500 Subject: [PATCH] Fetch submission when needing to update scope --- .../submission/submissionViewController.js | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/webapp/app/controllers/submission/submissionViewController.js b/src/main/webapp/app/controllers/submission/submissionViewController.js index bd285bf22..0d90f9128 100644 --- a/src/main/webapp/app/controllers/submission/submissionViewController.js +++ b/src/main/webapp/app/controllers/submission/submissionViewController.js @@ -16,11 +16,21 @@ vireo.controller("SubmissionViewController", function ($controller, $q, $scope, var deleteFile = function (fieldValue) { fieldValue.removing = true; - FileUploadService.removeFile($scope.submission, fieldValue).then(function (removed) { + var deleteFilePromise = FileUploadService.removeFile($scope.submission, fieldValue); + + deleteFilePromise.then(function (removed) { delete fieldValue.removing; }); + + return deleteFilePromise; }; + var fetchSubmission = function () { + StudentSubmissionRepo.fetchSubmissionById($routeParams.submissionId).then(function (submission) { + angular.extend($scope.submission, submission); + }); + } + StudentSubmissionRepo.fetchSubmissionById($routeParams.submissionId).then(function (submission) { $scope.loaded = true; $scope.submission = submission; @@ -86,6 +96,7 @@ vireo.controller("SubmissionViewController", function ($controller, $q, $scope, } $q.all(removePromises).then(function () { $scope.removingUploads = false; + fetchSubmission(); }); }; @@ -97,9 +108,13 @@ vireo.controller("SubmissionViewController", function ($controller, $q, $scope, $scope.archiveManuscript = function () { $scope.archivingManuscript = true; - FileUploadService.archiveFile($scope.submission, $scope.submission.primaryDocumentFieldValue, true).then(function () { + FileUploadService.archiveFile($scope.submission, $scope.submission.primaryDocumentFieldValue, true).then(function (removeFieldValue) { $scope.archivingManuscript = false; - $scope.submission.addFieldValue($scope.submission.getPrimaryDocumentFieldProfile().fieldPredicate); + if (removeFieldValue) { + fetchSubmission(); + } else { + console.error('Failed to remove field value. Please refresh the page.'); + } }); }; @@ -171,9 +186,7 @@ vireo.controller("SubmissionViewController", function ($controller, $q, $scope, CustomActionDefinitionRepo.listen(function(apiRes) { if(apiRes.meta.status === 'SUCCESS') { StudentSubmissionRepo.remove($scope.submission); - StudentSubmissionRepo.fetchSubmissionById($routeParams.submissionId).then(function (submission) { - angular.extend($scope.submission, submission); - }); + fetchSubmission(); } });