summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Conway <mikeconway@dhcp152-54-6-70.wireless.europa.renci.org>2011-09-07 12:44:11 (GMT)
committer Mike Conway <mikeconway@dhcp152-54-6-70.wireless.europa.renci.org>2011-09-07 12:44:11 (GMT)
commitde4379babb57a5043c8e4b0f034456915d854225 (patch)
tree1459fe81f079b7004a93bfc8fb4458f0366e541f
parent0db4e17389f295aa63d32b9f21a4fa262cf5a9ec (diff)
downloadQCG-Data-de4379babb57a5043c8e4b0f034456915d854225.zip
QCG-Data-de4379babb57a5043c8e4b0f034456915d854225.tar.gz
QCG-Data-de4379babb57a5043c8e4b0f034456915d854225.tar.bz2
[#459] initial functioning add avu dialog
-rw-r--r--idrop-web/grails-app/controllers/org/irods/mydrop/controller/MetadataController.groovy134
-rw-r--r--idrop-web/grails-app/views/metadata/metadataDialog.gsp2
-rw-r--r--idrop-web/web-app/js/mydrop/metadata.js90
3 files changed, 182 insertions, 44 deletions
diff --git a/idrop-web/grails-app/controllers/org/irods/mydrop/controller/MetadataController.groovy b/idrop-web/grails-app/controllers/org/irods/mydrop/controller/MetadataController.groovy
index 1b178ac..85bff41 100644
--- a/idrop-web/grails-app/controllers/org/irods/mydrop/controller/MetadataController.groovy
+++ b/idrop-web/grails-app/controllers/org/irods/mydrop/controller/MetadataController.groovy
@@ -8,8 +8,8 @@ import org.irods.jargon.core.pub.CollectionAO
import org.irods.jargon.core.pub.CollectionAndDataObjectListAndSearchAO
import org.irods.jargon.core.pub.DataObjectAO
import org.irods.jargon.core.pub.IRODSAccessObjectFactory
+import org.irods.jargon.core.pub.domain.AvuData
import org.irods.jargon.core.pub.domain.DataObject
-import org.mockito.Mockito
import org.springframework.security.core.context.SecurityContextHolder
/**
@@ -58,7 +58,7 @@ class MetadataController {
def isDataObject = retObj instanceof DataObject
def metadata;
-
+
if (isDataObject) {
log.debug("retrieving meta data for a data object");
DataObjectAO dataObjectAO = irodsAccessObjectFactory.getDataObjectAO(irodsAccount)
@@ -71,29 +71,111 @@ class MetadataController {
render(view:"metadataDetails", model:[metadata:metadata])
}
-
+
+ /**
+ * Display an metadata dialog for an add or edit
+ */
+ def prepareMetadataDialog = {
+ log.info "prepareMetadataDialog"
+ log.info "params: ${params}"
+
+
+ def absPath = params['absPath']
+ def isCreate = params['create']
+
+
+ if (!absPath) {
+ log.error "no absPath in request for prepareMetadataialog()"
+ throw new JargonException("a path was not supplied")
+ }
+
+
+ render(view:"metadataDialog", model:[absPath:absPath, isCreate:isCreate])
+
+ }
+
/**
- * Display an metadata dialog for an add or edit
- */
- def prepareMetadataDialog = {
- log.info "prepareMetadataDialog"
- log.info "params: ${params}"
-
-
- def absPath = params['absPath']
- def isCreate = params['create']
-
-
- if (!absPath) {
- log.error "no absPath in request for prepareMetadataialog()"
- throw new JargonException("a path was not supplied")
- }
-
-
- render(view:"metadataDialog", model:[absPath:absPath, isCreate:isCreate])
-
- }
-
-
-
+ * Add metadata
+ * FIXME: hacked, fix this up with validation, etc
+ */
+ def addMetadata = {
+
+ log.info "addMetadata"
+ log.info "params: ${params}"
+
+ def absPath = params['absPath']
+ def attribute = params['attribute']
+ def value = params['value']
+ def unit = params['unit']
+
+
+
+ if (!absPath) {
+ response.sendError(500,"no path specified")
+ return
+ }
+
+ if (!attribute) {
+ response.sendError(500,"no attribute specified")
+ return
+ }
+
+ if (!value) {
+ response.sendError(500,"no value specified")
+ return
+ }
+
+ /*
+ if (!unit) {
+ response.sendError(500,"no unit specified")
+ return
+ }*/
+
+
+
+ log.info(" attribute: ${attribute} value: ${value} unit: ${unit}")
+
+ CollectionAndDataObjectListAndSearchAO collectionAndDataObjectListAndSearchAO = irodsAccessObjectFactory.getCollectionAndDataObjectListAndSearchAO(irodsAccount)
+
+ def retObj = collectionAndDataObjectListAndSearchAO.getFullObjectForType(absPath)
+
+ def avuData = AvuData.instance(attribute, value, unit)
+
+ def isDataObject = retObj instanceof DataObject
+
+ if (isDataObject) {
+ log.debug("setting AVU for a data object")
+ DataObjectAO dataObjectAO = irodsAccessObjectFactory.getDataObjectAO(irodsAccount)
+ dataObjectAO.addAVUMetadata(absPath, avuData)
+
+ } else {
+ log.debug("setting AVU for collection")
+ CollectionAO collectionAO = irodsAccessObjectFactory.getCollectionAO(irodsAccount)
+ collectionAO.addAVUMetadata(absPath, avuData)
+
+ }
+
+ log.info("avu set successfully")
+
+ render "OK"
+ }
+
+}
+
+/**
+ * Command for adding metadata from the metadataDialog.gsp form
+ */
+
+/*
+class AddMetadataCommand {
+ String absPath
+ String attribute
+ String value
+ String unit
+ static constraints = {
+ absPath(blank:false),
+ attribute(blank:false),
+ unit(blank:false)
+ }
}
+*/
diff --git a/idrop-web/grails-app/views/metadata/metadataDialog.gsp b/idrop-web/grails-app/views/metadata/metadataDialog.gsp
index 2182061..5498ca5 100644
--- a/idrop-web/grails-app/views/metadata/metadataDialog.gsp
+++ b/idrop-web/grails-app/views/metadata/metadataDialog.gsp
@@ -1,6 +1,6 @@
<div id="metadataDialogDiv" class="roundedContainer">
<div id="metadataDialogMessageArea" style="width:90%;">
- <!-- message area for acl dialogs -->
+ <g:renderErrors bean="${cmd}" />
</div>
<div style="clear: both;">
<g:form controller="metadata" action="addMetadata" method="post"
diff --git a/idrop-web/web-app/js/mydrop/metadata.js b/idrop-web/web-app/js/mydrop/metadata.js
index e27b901..1954477 100644
--- a/idrop-web/web-app/js/mydrop/metadata.js
+++ b/idrop-web/web-app/js/mydrop/metadata.js
@@ -7,14 +7,14 @@
/**
* Global var
*/
-var messageAreaSelector = "#metadataMessageArea";
+var metadataMessageAreaSelector = "#metadataMessageArea";
var metadataUpdateUrl = '/metadata/updateMetadata';
-
+var metadataAddUrl = '/metadata/addMetadata';
/**
* Called by data table upon submit of an acl change
*/
-function metadataUpdate(currentAcl, newAcl, path) {
+function metadataUpdate(avu, newAvu, path) {
lcPrepareForCall();
@@ -22,15 +22,15 @@ function metadataUpdate(currentAcl, newAcl, path) {
throw "No collection or data object selected";
}
- if (!newAcl) {
- throw "No newAcl provided";
+ if (!newAvu) {
+ throw "No newAvu provided";
}
- if (!currentAcl) {
- throw "no currentAcl provided";
+ if (!currentAvu) {
+ throw "no currentAvu provided";
}
- lcShowBusyIconInDiv(messageAreaSelector);
+ lcShowBusyIconInDiv(metadataMessageAreaSelector);
var params = {
absPath : selectedPath,
@@ -42,14 +42,14 @@ function metadataUpdate(currentAcl, newAcl, path) {
newAclUnit : newAcl['unit']
}
- var jqxhr = $.post(context + metadataUpdateUrl, params,
+ var jqxhr = $.post(context + metadataAddUrl, params,
function(data, status, xhr) {
- lcClearDivAndDivClass(messageAreaSelector);
+ lcClearDivAndDivClass(metadataMessageAreaSelector);
}, "html").error(function() {
setMessageInArea(messageAreaSelector, "Error updating metadata");
}).complete(
function() {
- setMessageInArea(messageAreaSelector,
+ setMessageInArea(metadataMessageAreaSelector,
"Metadata update successful");
});
@@ -91,13 +91,69 @@ function showMetadataDialog(data) {
lcPrepareForCall();
$("#metadataDialogArea").html(data).fadeIn('slow');
- /**
- * $("#aclDialogArea").html(data); $("#aclDialogArea").dialog({ "width" :
- * 400, "modal" : true, "buttons" : { "Ok" : function() { submitAclDialog(); },
- * "Cancel" : function() { $(this).dialog("close"); } }, "title" : "Edit
- * Share Permission" });
- */
+}
+
+/**
+ * Handle form submit to add AVU Metadata
+ */
+function submitMetadataDialog() {
+
+ lcPrepareForCall();
+
+ var attribute = $('[name=attribute]').val();
+ var value = $('[name=value]').val();
+ var unit = $('[name=unit]').val();
+
+
+ if (selectedPath == null) {
+ throw "no collection or data object selected";
+ }
+
+ var isCreate = $('[name=isCreate]').val();
+
+ lcShowBusyIconInDiv(metadataMessageAreaSelector);
+
+ var params = {
+ absPath : selectedPath,
+ attribute : attribute,
+ value : value,
+ unit : unit
+ }
+
+ var jqxhr = $.post(context + metadataAddUrl, params,
+ function(data, status, xhr) {
+ lcClearDivAndDivClass(metadataMessageAreaSelector);
+ }, "html").error(function(xhr, status, error) {
+ setMessageInArea(metadataMessageAreaSelector, xhr.responseText);
+ }).success(
+ function() {
+
+ closeMetadataDialog();
+ addRowToMetadataDetailsTable(attribute,value,unit);
+ setMessageInArea(metadataMessageAreaSelector,
+ "Metadata saved successfully");
+ });
+}
+
+function closeMetadataDialog() {
+ $("#metadataDialogArea").hide().fadeOut('slow', new function() {
+ $("#metadataDialogArea").html("")
+ });
+
+}
+
+function addRowToMetadataDetailsTable(attribute, value, unit) {
+
+ var idxs = $("#metaDataDetailsTable")
+ .dataTable()
+ .fnAddData(
+ [
+ "<input id=\"selectedAcl\" type=\"checkbox\" name=\"selectedMetadata\">",
+ attribute, value, unit ], true);
+ var newNode = $("#metaDataDetailsTable").dataTable().fnGetNodes()[idxs[0]];
+ $(newNode).attr("id", selectedPath);
+
}