From 249fa4d8d54e12a56a576de695c41f33a9728297 Mon Sep 17 00:00:00 2001 From: Jacky Date: Thu, 26 Oct 2017 15:45:58 -0400 Subject: [PATCH] support metadata edit --- .../src/com/google/refine/ProjectManager.java | 2 +- .../com/google/refine/ProjectMetadata.java | 29 +++++++++++++++-- .../GetAllProjectMetadataCommand.java | 9 ++++++ .../google/refine/io/FileProjectManager.java | 2 +- .../webapp/modules/core/MOD-INF/controller.js | 7 +++-- .../modules/core/langs/translation-en.json | 6 ++++ .../modules/core/langs/translation-nb_NO.json | 1 - .../core/scripts/index/open-project-ui.js | 31 ++++++++++++++++++- .../core/styles/index/open-project-ui.less | 3 ++ 9 files changed, 81 insertions(+), 9 deletions(-) delete mode 100644 main/webapp/modules/core/langs/translation-nb_NO.json diff --git a/main/src/com/google/refine/ProjectManager.java b/main/src/com/google/refine/ProjectManager.java index 187899e66..48de19144 100644 --- a/main/src/com/google/refine/ProjectManager.java +++ b/main/src/com/google/refine/ProjectManager.java @@ -193,7 +193,7 @@ public abstract class ProjectManager { * @param projectId * @throws Exception */ - protected abstract void saveMetadata(ProjectMetadata metadata, long projectId) throws Exception; + public abstract void saveMetadata(ProjectMetadata metadata, long projectId) throws Exception; /** * Save project to the data store diff --git a/main/src/com/google/refine/ProjectMetadata.java b/main/src/com/google/refine/ProjectMetadata.java index a63867622..0e747fd8a 100644 --- a/main/src/com/google/refine/ProjectMetadata.java +++ b/main/src/com/google/refine/ProjectMetadata.java @@ -34,6 +34,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine; import java.io.Serializable; +import java.lang.reflect.Field; import java.util.Date; import java.util.HashMap; import java.util.Iterator; @@ -114,13 +115,13 @@ public class ProjectMetadata implements Jsonizable { } writer.endObject(); - // write JSONArray to file directly + // write JSONArray directly if (_importOptionMetaData.length() > 0 ) { writer.key("importOptionMetaData"); writer.value(_importOptionMetaData); } - if ("save".equals(options.getProperty("mode"))) { + if (isSaveMode(options)) { writer.key("password"); writer.value(_password); writer.key("encoding"); writer.value(_encoding); @@ -131,10 +132,20 @@ public class ProjectMetadata implements Jsonizable { writer.endObject(); - if ("save".equals(options.getProperty("mode"))) { + if (isSaveMode(options)) { written = new Date(); } } + + public void writeWithoutOption(JSONWriter writer) + throws JSONException { + write(writer, + new Properties()); + } + + private boolean isSaveMode(Properties options) { + return "save".equals(options.getProperty("mode")); + } public boolean isDirty() { return written == null || _modified.after(written); @@ -369,5 +380,17 @@ public class ProjectMetadata implements Jsonizable { this._rowNumber = rowNumber; updateModified(); } + + public void setAnyField(String metaName, String valueString) { + Class metaClass = this.getClass(); + try { + Field metaField = metaClass.getDeclaredField("_" + metaName); + + metaField.set(this, valueString); + } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { + // do nothing + e.printStackTrace(); + } + } } diff --git a/main/src/com/google/refine/commands/workspace/GetAllProjectMetadataCommand.java b/main/src/com/google/refine/commands/workspace/GetAllProjectMetadataCommand.java index 2d76b0055..c2f40128e 100644 --- a/main/src/com/google/refine/commands/workspace/GetAllProjectMetadataCommand.java +++ b/main/src/com/google/refine/commands/workspace/GetAllProjectMetadataCommand.java @@ -42,7 +42,9 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.json.JSONArray; import org.json.JSONException; +import org.json.JSONObject; import org.json.JSONWriter; import com.google.refine.ProjectManager; @@ -62,6 +64,7 @@ public class GetAllProjectMetadataCommand extends Command { Properties options = new Properties(); writer.object(); + writer.key("projects"); writer.object(); Map m = ProjectManager.singleton.getAllProjectMetadata(); @@ -73,6 +76,12 @@ public class GetAllProjectMetadataCommand extends Command { } } writer.endObject(); + + writer.key("customMetaDataColumns"); + JSONArray customMetaDataColumns = new JSONArray( + (String)ProjectManager.singleton.getPreferenceStore().get("userMetaData")); + writer.value(customMetaDataColumns); + writer.endObject(); } catch (JSONException e) { respondException(response, e); diff --git a/main/src/com/google/refine/io/FileProjectManager.java b/main/src/com/google/refine/io/FileProjectManager.java index 2fa42fc27..e1cac2ede 100644 --- a/main/src/com/google/refine/io/FileProjectManager.java +++ b/main/src/com/google/refine/io/FileProjectManager.java @@ -215,7 +215,7 @@ public class FileProjectManager extends ProjectManager { } @Override - protected void saveMetadata(ProjectMetadata metadata, long projectId) throws Exception { + public void saveMetadata(ProjectMetadata metadata, long projectId) throws Exception { File projectDir = getProjectDir(projectId); ProjectMetadataUtilities.save(metadata, projectDir); } diff --git a/main/webapp/modules/core/MOD-INF/controller.js b/main/webapp/modules/core/MOD-INF/controller.js index f8d4649c6..960981300 100644 --- a/main/webapp/modules/core/MOD-INF/controller.js +++ b/main/webapp/modules/core/MOD-INF/controller.js @@ -34,7 +34,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. var html = "text/html"; var encoding = "UTF-8"; var ClientSideResourceManager = Packages.com.google.refine.ClientSideResourceManager; -var bundle = true; +var bundle = false; var templatedFiles = { // Requests with last path segments mentioned here @@ -68,9 +68,11 @@ function registerCommands() { RS.registerCommand(module, "get-project-metadata", new Packages.com.google.refine.commands.project.GetProjectMetadataCommand()); RS.registerCommand(module, "get-all-project-metadata", new Packages.com.google.refine.commands.workspace.GetAllProjectMetadataCommand()); + RS.registerCommand(module, "set-metaData", new Packages.com.google.refine.commands.project.SetProjectMetaDataCommand()); RS.registerCommand(module, "delete-project", new Packages.com.google.refine.commands.project.DeleteProjectCommand()); RS.registerCommand(module, "rename-project", new Packages.com.google.refine.commands.project.RenameProjectCommand()); + RS.registerCommand(module, "set-project-metadata", new Packages.com.google.refine.commands.project.SetProjectMetaDataCommand()); RS.registerCommand(module, "get-models", new Packages.com.google.refine.commands.project.GetModelsCommand()); RS.registerCommand(module, "get-rows", new Packages.com.google.refine.commands.row.GetRowsCommand()); @@ -350,7 +352,8 @@ function init() { "scripts/index/parser-interfaces/rdf-triples-parser-ui.js", "scripts/index/parser-interfaces/wikitext-parser-ui.js", - "scripts/reconciliation/recon-manager.js" // so that reconciliation functions are available to importers + "scripts/reconciliation/recon-manager.js", // so that reconciliation functions are available to importers + "scripts/index/edit-metadata-dialog.js" ] ); diff --git a/main/webapp/modules/core/langs/translation-en.json b/main/webapp/modules/core/langs/translation-en.json index c62863a34..19623f8e4 100644 --- a/main/webapp/modules/core/langs/translation-en.json +++ b/main/webapp/modules/core/langs/translation-en.json @@ -87,6 +87,12 @@ "open-proj": "Open Project", "name": "Name", "rename": "rename", + "edit-meta-data": "Edit meta data", + "creator": "Creator", + "contributors": "Contributors", + "subject": "Subject", + "description": "Description", + "row-number": "Row Number", "last-mod": "Last modified", "del-title": "Delete this project", "del-body": "Are you sure you want to delete project \"", diff --git a/main/webapp/modules/core/langs/translation-nb_NO.json b/main/webapp/modules/core/langs/translation-nb_NO.json deleted file mode 100644 index 0967ef424..000000000 --- a/main/webapp/modules/core/langs/translation-nb_NO.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/main/webapp/modules/core/scripts/index/open-project-ui.js b/main/webapp/modules/core/scripts/index/open-project-ui.js index 5d9d7004e..c01828abd 100644 --- a/main/webapp/modules/core/scripts/index/open-project-ui.js +++ b/main/webapp/modules/core/scripts/index/open-project-ui.js @@ -123,8 +123,23 @@ Refine.OpenProjectUI.prototype._renderProjects = function(data) { '' + '' + '' + + '' + '' + '' + + '' + + '' + + '' + + '' + + (function() { + var htmlDisplay = ""; + for (var n in data.customMetaDataColumns) { + if (data.customMetaDataColumns[n].display) { + htmlDisplay += ''; + } + } + + return htmlDisplay; + })() + '
'+$.i18n._('core-index-open')["last-mod"]+''+$.i18n._('core-index-open')["name"]+''+$.i18n._('core-index-open')["creator"]+''+$.i18n._('core-index-open')["subject"]+''+$.i18n._('core-index-open')["description"]+''+$.i18n._('core-index-open')["row-number"]+''+ data.customMetaDataColumns[n].name + '
' ).appendTo(container)[0]; @@ -189,7 +204,19 @@ Refine.OpenProjectUI.prototype._renderProjects = function(data) { }).appendTo( $(tr.insertCell(tr.cells.length)).css('width', '1%') ); - + + var editMetaDataLink = $('') + .text($.i18n._('core-index-open')["edit-meta-data"]) + .addClass("secondary") + .attr("href", "javascript:{}") + .css("visibility", "hidden") + .click(function() { + new EditMetadataDialog(project); + }) + .appendTo( + $(tr.insertCell(tr.cells.length)).css('width', '6%') + ); + $('
') .html(formatRelativeDate(project.date)) .addClass("last-modified") @@ -205,9 +232,11 @@ Refine.OpenProjectUI.prototype._renderProjects = function(data) { $(tr).mouseenter(function() { renameLink.css("visibility", "visible"); deleteLink.css("visibility", "visible"); + editMetaDataLink.css("visibility", "visible"); }).mouseleave(function() { renameLink.css("visibility", "hidden"); deleteLink.css("visibility", "hidden"); + editMetaDataLink.css("visibility", "hidden"); }); }; diff --git a/main/webapp/modules/core/styles/index/open-project-ui.less b/main/webapp/modules/core/styles/index/open-project-ui.less index 4a0e8796f..d2662207f 100644 --- a/main/webapp/modules/core/styles/index/open-project-ui.less +++ b/main/webapp/modules/core/styles/index/open-project-ui.less @@ -87,3 +87,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. opacity: 0.2; } +#metadata-body tr:nth-child(even) {background: #CCC} +#metadata-body tr:nth-child(odd) {background: #FFF} +