Skip to content

Commit

Permalink
BXC-4061 get js working
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharon Luong committed Oct 18, 2023
1 parent 7f96faa commit 0aa0f24
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
11 changes: 11 additions & 0 deletions static/js/admin/src/action/AssignAsThumbnailAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,20 @@ define('AssignAsThumbnailAction', [ 'jquery', 'AjaxCallbackAction'], function($,
action : 'RefreshResult',
target : this.context.target
});
this.context.actionHandler.addEvent({
action : 'RefreshResult',
target : this.context.resultTable.resultObjectList.getResultObject(this.oldThumbnailId)
});
this.alertHandler.alertHandler("success", "Assignment of object \"" + this.context.target.metadata.title + "\" as the assigned thumbnail has completed.");
this.context.target.enable();
};

AssignAsThumbnailAction.prototype.workDone = function(data) {
this.completeTimestamp = data.timestamp;
this.oldThumbnailId = data.oldThumbnailId;
this.newThumbnailId = data.newThumbnailId;
return true;
};

return AssignAsThumbnailAction;
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import edu.unc.lib.boxc.model.api.ids.PID;
import edu.unc.lib.boxc.model.api.objects.FileObject;
import edu.unc.lib.boxc.model.api.objects.RepositoryObjectLoader;
import edu.unc.lib.boxc.model.api.objects.WorkObject;
import edu.unc.lib.boxc.model.fcrepo.ids.PIDs;
import edu.unc.lib.boxc.operations.jms.thumbnails.ThumbnailRequest;
import edu.unc.lib.boxc.operations.jms.thumbnails.ThumbnailRequestSender;
Expand Down Expand Up @@ -100,6 +101,8 @@ ResponseEntity<Object> importThumbnail(@PathVariable("pid") String pid,
@ResponseBody
public ResponseEntity<Object> assignThumbnail(@PathVariable("pidString") String pidString) {
PID pid = PIDs.get(pidString);
Map<String, Object> result = new HashMap<>();
result.put("action", "assignThumbnail");

AccessGroupSet principals = getAgentPrincipals().getPrincipals();
aclService.assertHasAccess("Insufficient permissions to assign thumbnail for " + pidString,
Expand All @@ -111,6 +114,12 @@ public ResponseEntity<Object> assignThumbnail(@PathVariable("pidString") String
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}

var workObject = (WorkObject) object.getParent();
var oldThumbnail = workObject.getThumbnailObject();
if (oldThumbnail != null) {
result.put("oldThumbnailId", oldThumbnail.getPid().getId());
}

var agent = AgentPrincipalsImpl.createFromThread();
var request = new ThumbnailRequest();
request.setAgent(agent);
Expand All @@ -123,13 +132,17 @@ public ResponseEntity<Object> assignThumbnail(@PathVariable("pidString") String
log.error("Error assigning file {} as thumbnail", request.getFilePidString(), e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
return new ResponseEntity<>(HttpStatus.OK);
result.put("timestamp", System.currentTimeMillis());
result.put("newThumbnailId", object.getPid().getId());
return new ResponseEntity<>(result, HttpStatus.OK);
}

@DeleteMapping(value = "/edit/deleteThumbnail/{pidString}")
@ResponseBody
public ResponseEntity<Object> deleteThumbnail(@PathVariable("pidString") String pidString) {
PID pid = PIDs.get(pidString);
Map<String, Object> result = new HashMap<>();
result.put("action", "deleteThumbnail");

AccessGroupSet principals = getAgentPrincipals().getPrincipals();
aclService.assertHasAccess("Insufficient permissions to assign thumbnail for " + pidString,
Expand All @@ -153,6 +166,8 @@ public ResponseEntity<Object> deleteThumbnail(@PathVariable("pidString") String
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}

return new ResponseEntity<>(HttpStatus.OK);
result.put("timestamp", System.currentTimeMillis());
result.put("oldThumbnailId", object.getPid().getId());
return new ResponseEntity<>(result, HttpStatus.OK);
}
}

0 comments on commit 0aa0f24

Please sign in to comment.