support metadata edit
This commit is contained in:
parent
249fa4d8d5
commit
6a47482ea4
@ -0,0 +1,52 @@
|
||||
package com.google.refine.commands.project;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONTokener;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.google.refine.ProjectManager;
|
||||
import com.google.refine.ProjectMetadata;
|
||||
import com.google.refine.commands.Command;
|
||||
import com.google.refine.model.Project;
|
||||
|
||||
public class SetProjectMetaDataCommand extends Command {
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
Project project = request.getParameter("project") != null ? getProject(request) : null;
|
||||
String metaName = request.getParameter("name");
|
||||
String valueString = request.getParameter("value");
|
||||
ProjectMetadata meta = null;
|
||||
|
||||
if (project == null) {
|
||||
respond(response, "{ \"code\" : \"error\", \"message\" : \"Project cannot be found\" }");
|
||||
return;
|
||||
}
|
||||
|
||||
meta = project.getMetadata();
|
||||
try {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||
|
||||
Object o = valueString == null ? null : new JSONTokener(valueString).nextValue();
|
||||
|
||||
meta.setAnyField(metaName, valueString);
|
||||
ProjectManager.singleton.saveMetadata(meta, project.id);
|
||||
|
||||
respond(response, "{ \"code\" : \"ok\" }");
|
||||
} catch (JSONException e) {
|
||||
respondException(response, e);
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
|
||||
|
||||
function EditMetadataDialog(metaData) {
|
||||
this._metaDataUIs = [];
|
||||
this._metaData = metaData;
|
||||
|
||||
this._MetaDataUI = function(tr, key, value, project) {
|
||||
var self = this;
|
||||
|
||||
var td0 = tr.insertCell(0);
|
||||
$(td0).text(key);
|
||||
|
||||
var td1 = tr.insertCell(1);
|
||||
$(td1).text((value !== null) ? value : "");
|
||||
|
||||
var td2 = tr.insertCell(2);
|
||||
|
||||
$('<button class="button">').text($.i18n._('core-index')["edit"]).appendTo(td2).click(function() {
|
||||
var newValue = window.prompt($.i18n._('core-index')["change-value"]+" " + key, value);
|
||||
if (newValue !== null) {
|
||||
$(td1).text(newValue);
|
||||
metaData[key] = newValue;
|
||||
$.post(
|
||||
"command/core/set-metaData",
|
||||
{
|
||||
project : project,
|
||||
name : key,
|
||||
value : newValue
|
||||
},
|
||||
function(o) {
|
||||
if (o.code === "error") {
|
||||
alert(o.message);
|
||||
}
|
||||
},
|
||||
"json"
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this._createDialog();
|
||||
}
|
||||
|
||||
EditMetadataDialog.prototype._createDialog = function() {
|
||||
var self = this;
|
||||
|
||||
var frame = $(DOM.loadHTML("core", "scripts/project/edit-metadata-dialog.html"));
|
||||
this._elmts = DOM.bind(frame);
|
||||
|
||||
this._level = DialogSystem.showDialog(frame);
|
||||
this._elmts.closeButton.html($.i18n._('core-buttons')["close"]);
|
||||
this._elmts.closeButton.click(function() { self._dismiss(); });
|
||||
|
||||
var body = $("#metadata-body");
|
||||
|
||||
$('<h1>').text($.i18n._('core-index')["metaDatas"]).appendTo(body);
|
||||
|
||||
var metadataTable = $("<table>")
|
||||
.addClass("list-table")
|
||||
.addClass("preferences")
|
||||
.html('<tr><th>'+$.i18n._('core-index')["key"]+'</th><th>'+$.i18n._('core-index')["value"]+'</th><th></th></tr>')
|
||||
.appendTo(body)[0];
|
||||
|
||||
for (var k in this._metaData) {
|
||||
var tr = metadataTable.insertRow(metadataTable.rows.length);
|
||||
|
||||
if (typeof this._metaData[k] === 'string')
|
||||
v = this._metaData[k].replace(/\"/g, "");
|
||||
else
|
||||
v = JSON.stringify(this._metaData[k]);
|
||||
|
||||
|
||||
this._metaDataUIs.push(new this._MetaDataUI(tr, k, v, this._metaData.id));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
EditMetadataDialog.prototype._dismiss = function() {
|
||||
DialogSystem.dismissUntil(this._level - 1);
|
||||
};
|
||||
|
@ -0,0 +1,11 @@
|
||||
<div class="dialog-frame" style="width: 1600px; height: 700px">
|
||||
<div class="dialog-border">
|
||||
<div class="dialog-header" bind="dialogHeader"></div>
|
||||
<div class="dialog-body" bind="dialogBody">
|
||||
<div id="metadata-body" class="grid-layout layout-normal layout-full"></div>
|
||||
</div>
|
||||
<div class="dialog-footer" bind="dialogFooter">
|
||||
<button class="button" bind="closeButton"></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user