Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#800 #801

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.resp;
});
}

self.metadata = angular.isDefined(attachment) ? _.clone(attachment) : {};
self.files = null;
self.error = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,9 @@ <h4 class="modal-title">Add an attachment</h4>
<label for="category" class="col-sm-3 control-label">Category</label>

<div class="col-sm-9">
<select id="category" ng-model="attachmentUploadCtrl.metadata.category" class="form-control">
<select id="category" ng-model="attachmentUploadCtrl.metadata.category"
ng-options="category.key as category.value for category in attachmentUploadCtrl.categories" class="form-control">
<option value="">Select a category</option>
<option value="General">General</option>
<option value="Management">Management</option>
</select>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,11 @@ class OpusController extends OpusBaseController {
}
}

def getCategories() {
def result = profileService.getCategories()
render result as JSON
}

@Secured(role = ROLE_PROFILE_ADMIN)
def saveAttachment() {
if (!params.opusId || !(request instanceof MultipartHttpServletRequest) || !request.getParameter("data")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ class ApiControllerSpec extends Specification implements ControllerUnitTest<ApiC

where:
type | opusId | profileId | imageId | responseCode
'PRIVATE' |'opus1' | '123' | '1.png' | 200
'PRIVATE' | 'opus1' | '123' | '1.png' | 200
}

void "getOpusList should be provided"() {
setup:
Expand All @@ -192,4 +193,4 @@ class ApiControllerSpec extends Specification implements ControllerUnitTest<ApiC
response.status == 200

}
}
}
14 changes: 14 additions & 0 deletions src/test/groovy/au/org/ala/profile/hub/OpusControllerSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,18 @@ class OpusControllerSpec extends Specification implements ControllerUnitTest<Opu
then:
assert response.json == [opus1, opus2, opus3, opus4]
}

def "new categories should return a model with the expected number of elements"() {
setup:
mockProfileService.getCategories() >> [[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")
}
}
Loading