Skip to content

Commit

Permalink
Use timeout to reset scope with select field profile binding
Browse files Browse the repository at this point in the history
  • Loading branch information
wwelling committed Aug 29, 2024
1 parent eb3114b commit 567786a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
vireo.controller("SubmissionViewController", function ($controller, $q, $scope, $routeParams, CustomActionDefinitionRepo, EmbargoRepo, FieldPredicateRepo, FileUploadService, StudentSubmissionRepo, SubmissionStates) {
vireo.controller("SubmissionViewController", function ($controller, $q, $routeParams, $scope, $timeout, CustomActionDefinitionRepo, EmbargoRepo, FieldPredicateRepo, FileUploadService, StudentSubmissionRepo, SubmissionStates) {

angular.extend(this, $controller('AbstractController', {
$scope: $scope
Expand All @@ -12,6 +12,9 @@ vireo.controller("SubmissionViewController", function ($controller, $q, $scope,

$scope.actionLogDelay = 2000;

$scope.fieldProfile = undefined;
$scope.fieldPredicate = undefined;

FieldPredicateRepo.ready().then(function() {

var deleteFile = function (fieldValue) {
Expand All @@ -31,6 +34,11 @@ vireo.controller("SubmissionViewController", function ($controller, $q, $scope,
StudentSubmissionRepo.fetchSubmissionById($routeParams.submissionId).then(function (submission) {
if (refreshScope) {
$scope.submission = submission;

$scope.fieldProfile = undefined;
$timeout(function () {
$scope.onSelectDocumentType($scope.fieldPredicate);
});
} else {
angular.extend($scope.submission, submission);
}
Expand All @@ -49,6 +57,13 @@ vireo.controller("SubmissionViewController", function ($controller, $q, $scope,

$scope.archivingManuscript = false;

$scope.onSelectDocumentType = function (fieldPredicate) {
if (!!fieldPredicate && !!fieldPredicate.id) {
$scope.fieldPredicate = fieldPredicate;
$scope.fieldProfile = $scope.submission.getFieldProfileByPredicate(fieldPredicate);
}
};

$scope.addMessage = function () {
$scope.messaging = true;
$scope.submission.addMessage($scope.message).then(function () {
Expand Down Expand Up @@ -99,7 +114,7 @@ vireo.controller("SubmissionViewController", function ($controller, $q, $scope,
}
$q.all(removePromises).then(function (removeFiles) {
if (removeFiles.every(Boolean)) {
fetchSubmission();
fetchSubmission(true);
} else {
console.error('Failed to remove additional files. Please refresh the page.');
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/app/views/submission/submissionView.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ <h3>Upload/Remove Files</h3>
<select
class="form-control"
ng-model="fieldPredicate"
ng-selected="fieldProfile = fieldPredicate.id ? submission.getFieldProfileByPredicate(fieldPredicate) : undefined"
ng-change="onSelectDocumentType(fieldPredicate)"
ng-options="documentFieldPredicate as getFileType(documentFieldPredicate) for documentFieldPredicate in filteredFieldPredicates = (fieldPredicates | filter:uploadableFieldPredicates) track by documentFieldPredicate.value">
<option value="">-- select document type --</option>
</select>
Expand Down

0 comments on commit 567786a

Please sign in to comment.