From c3c6319e731e0bb263ea0dc57fd95de10c945698 Mon Sep 17 00:00:00 2001 From: steven choi Date: Tue, 31 Oct 2023 11:40:26 +1100 Subject: [PATCH 1/3] #800 Add new categories to attachments --- .../profileEditor/controllers/AttachmentController.js | 6 ++++++ .../javascripts/profileEditor/services/ProfileService.js | 5 +++++ .../profileEditor/templates/attachmentUpload.tpl.htm | 5 ++--- .../au/org/ala/profile/hub/OpusController.groovy | 5 +++++ .../controllers/au/org/ala/profile/hub/UrlMappings.groovy | 1 + .../services/au/org/ala/profile/hub/ProfileService.groovy | 4 ++++ 6 files changed, 23 insertions(+), 3 deletions(-) diff --git a/grails-app/assets/javascripts/profileEditor/controllers/AttachmentController.js b/grails-app/assets/javascripts/profileEditor/controllers/AttachmentController.js index 61795fec..71c55894 100644 --- a/grails-app/assets/javascripts/profileEditor/controllers/AttachmentController.js +++ b/grails-app/assets/javascripts/profileEditor/controllers/AttachmentController.js @@ -91,6 +91,12 @@ profileEditor.controller("AttachmentUploadController", function (profileService, var pdfType = {key: "PDF", title: "PDF Document"}; self.types = [pdfType, urlType]; + if (self.categories == null) { + profileService.getCategories().then(function (data) { + self.categories = data; + }); + } + self.metadata = angular.isDefined(attachment) ? _.clone(attachment) : {}; self.files = null; self.error = null; diff --git a/grails-app/assets/javascripts/profileEditor/services/ProfileService.js b/grails-app/assets/javascripts/profileEditor/services/ProfileService.js index a90a57ac..3e5dd931 100644 --- a/grails-app/assets/javascripts/profileEditor/services/ProfileService.js +++ b/grails-app/assets/javascripts/profileEditor/services/ProfileService.js @@ -1094,6 +1094,11 @@ profileEditor.service('profileService', function ($http, util, $cacheFactory, co return util.toStandardPromise(future); }, + getCategories: function () { + var future = $http.get(util.contextRoot() + "/attachment/categories", {cache: true}); + return util.toStandardPromise(future); + }, + getLicences: function () { var future = $http.get(util.contextRoot() + "/licences", {cache: true}); return util.toStandardPromise(future); diff --git a/grails-app/assets/javascripts/profileEditor/templates/attachmentUpload.tpl.htm b/grails-app/assets/javascripts/profileEditor/templates/attachmentUpload.tpl.htm index 6fd1d553..6eaf22e1 100644 --- a/grails-app/assets/javascripts/profileEditor/templates/attachmentUpload.tpl.htm +++ b/grails-app/assets/javascripts/profileEditor/templates/attachmentUpload.tpl.htm @@ -82,10 +82,9 @@
- - -
diff --git a/grails-app/controllers/au/org/ala/profile/hub/OpusController.groovy b/grails-app/controllers/au/org/ala/profile/hub/OpusController.groovy index c5119a20..2dd9fda9 100644 --- a/grails-app/controllers/au/org/ala/profile/hub/OpusController.groovy +++ b/grails-app/controllers/au/org/ala/profile/hub/OpusController.groovy @@ -359,6 +359,11 @@ class OpusController extends OpusBaseController { } } + def getCategories() { + def result = profileService.getCategories() + handle result + } + @Secured(role = ROLE_PROFILE_ADMIN) def saveAttachment() { if (!params.opusId || !(request instanceof MultipartHttpServletRequest) || !request.getParameter("data")) { diff --git a/grails-app/controllers/au/org/ala/profile/hub/UrlMappings.groovy b/grails-app/controllers/au/org/ala/profile/hub/UrlMappings.groovy index c3f0986a..aa65e764 100644 --- a/grails-app/controllers/au/org/ala/profile/hub/UrlMappings.groovy +++ b/grails-app/controllers/au/org/ala/profile/hub/UrlMappings.groovy @@ -112,6 +112,7 @@ class UrlMappings { "/opus/$opusId/attachment/$attachmentId" controller: "opus", action: [GET: "getAttachmentMetadata", DELETE: "deleteAttachment"] "/opus/$opusId/attachment/$attachmentId/download" controller: "opus", action: [GET: "proxyAttachmentDownload"] "/opus/$opusId/attachment/" controller: "opus", action: [GET: "getAttachmentMetadata", POST: "saveAttachment"] + "/attachment/categories/" controller: "opus", action: [GET: "getCategories"] "/opus/$opusId/florulaList" controller: "opus", action: [POST: "updateFlorulaList"] "/opus/$opusId/users/update" controller: "opus", action: [POST: "updateUsers"] diff --git a/grails-app/services/au/org/ala/profile/hub/ProfileService.groovy b/grails-app/services/au/org/ala/profile/hub/ProfileService.groovy index 05af8a67..0cfa02c5 100644 --- a/grails-app/services/au/org/ala/profile/hub/ProfileService.groovy +++ b/grails-app/services/au/org/ala/profile/hub/ProfileService.groovy @@ -220,6 +220,10 @@ class ProfileService { } } + def getCategories() { + webServiceWrapperService.get("${grailsApplication.config.profile.service.url}/attachment/categories", [:], ContentType.APPLICATION_JSON, true, false, getCustomHeaderWithUserId()) + } + def deleteAttachment(String opusId, String profileId, String attachmentId) { if (profileId) { webService.delete("${grailsApplication.config.profile.service.url}/opus/${encPath(opusId)}/profile/${encPath(profileId)}/attachment/${encPath(attachmentId)}?latest=true", [:], ContentType.APPLICATION_JSON, true, false, getCustomHeaderWithUserId()) From 01475b09e86b7d7dc81ae6e3c99fcf5493358de6 Mon Sep 17 00:00:00 2001 From: steven choi Date: Tue, 31 Oct 2023 14:41:32 +1100 Subject: [PATCH 2/3] #800 add test case --- .../controllers/AttachmentController.js | 2 +- .../au/org/ala/profile/hub/OpusController.groovy | 2 +- .../org/ala/profile/api/ApiControllerSpec.groovy | 5 +++-- .../org/ala/profile/hub/OpusControllerSpec.groovy | 14 ++++++++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/grails-app/assets/javascripts/profileEditor/controllers/AttachmentController.js b/grails-app/assets/javascripts/profileEditor/controllers/AttachmentController.js index 71c55894..5ab2a83a 100644 --- a/grails-app/assets/javascripts/profileEditor/controllers/AttachmentController.js +++ b/grails-app/assets/javascripts/profileEditor/controllers/AttachmentController.js @@ -93,7 +93,7 @@ profileEditor.controller("AttachmentUploadController", function (profileService, if (self.categories == null) { profileService.getCategories().then(function (data) { - self.categories = data; + self.categories = data.resp; }); } diff --git a/grails-app/controllers/au/org/ala/profile/hub/OpusController.groovy b/grails-app/controllers/au/org/ala/profile/hub/OpusController.groovy index 2dd9fda9..025b35a0 100644 --- a/grails-app/controllers/au/org/ala/profile/hub/OpusController.groovy +++ b/grails-app/controllers/au/org/ala/profile/hub/OpusController.groovy @@ -361,7 +361,7 @@ class OpusController extends OpusBaseController { def getCategories() { def result = profileService.getCategories() - handle result + render result as JSON } @Secured(role = ROLE_PROFILE_ADMIN) diff --git a/src/test/groovy/au/org/ala/profile/api/ApiControllerSpec.groovy b/src/test/groovy/au/org/ala/profile/api/ApiControllerSpec.groovy index 86d17a98..13784a1a 100644 --- a/src/test/groovy/au/org/ala/profile/api/ApiControllerSpec.groovy +++ b/src/test/groovy/au/org/ala/profile/api/ApiControllerSpec.groovy @@ -179,7 +179,8 @@ class ApiControllerSpec extends Specification implements ControllerUnitTest> [[key: 'key1', title: 'title1'],[key: 'key2', title: 'title2'],[key: 'key3', title: 'title3']] + + when: + controller.getCategories() + + then: + assert response.json.size() == 3 + assert response.json.toString().contains("key1") + assert response.json.toString().contains("key2") + assert response.json.toString().contains("key3") + } } From 796356c14d13fafe2cef89614f1cae0da55e0c8f Mon Sep 17 00:00:00 2001 From: steven choi Date: Wed, 1 Nov 2023 11:19:35 +1100 Subject: [PATCH 3/3] #800 change value name --- .../profileEditor/templates/attachmentUpload.tpl.htm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grails-app/assets/javascripts/profileEditor/templates/attachmentUpload.tpl.htm b/grails-app/assets/javascripts/profileEditor/templates/attachmentUpload.tpl.htm index 6eaf22e1..2bda87b4 100644 --- a/grails-app/assets/javascripts/profileEditor/templates/attachmentUpload.tpl.htm +++ b/grails-app/assets/javascripts/profileEditor/templates/attachmentUpload.tpl.htm @@ -83,7 +83,7 @@