Text facet's choice count limit is now configurable through preference page. Preference page needs polishing.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@1127 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
965ef20790
commit
762a9f13eb
@ -116,6 +116,7 @@ public class GridworksServlet extends Butterfly {
|
||||
{"mqlwrite", "com.metaweb.gridworks.commands.freebase.MQLWriteCommand"},
|
||||
|
||||
{"get-preference", "com.metaweb.gridworks.commands.GetPreferenceCommand"},
|
||||
{"get-all-preferences", "com.metaweb.gridworks.commands.GetAllPreferencesCommand"},
|
||||
{"set-preference", "com.metaweb.gridworks.commands.SetPreferenceCommand"},
|
||||
};
|
||||
|
||||
|
@ -9,6 +9,7 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.ProjectManager;
|
||||
import com.metaweb.gridworks.browsing.DecoratedValue;
|
||||
import com.metaweb.gridworks.browsing.FilteredRecords;
|
||||
import com.metaweb.gridworks.browsing.FilteredRows;
|
||||
@ -71,7 +72,7 @@ public class ListFacet implements Facet {
|
||||
|
||||
if (_errorMessage != null) {
|
||||
writer.key("error"); writer.value(_errorMessage);
|
||||
} else if (_choices.size() > 2000) {
|
||||
} else if (_choices.size() > getLimit()) {
|
||||
writer.key("error"); writer.value("Too many choices");
|
||||
} else {
|
||||
writer.key("choices"); writer.array();
|
||||
@ -99,6 +100,23 @@ public class ListFacet implements Facet {
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
protected int getLimit() {
|
||||
Object v = ProjectManager.singleton.getPreferenceStore().get("ui.browsing.listFacet.limit");
|
||||
if (v != null) {
|
||||
if (v instanceof Number) {
|
||||
return ((Number) v).intValue();
|
||||
} else {
|
||||
try {
|
||||
int n = Integer.parseInt(v.toString());
|
||||
return n;
|
||||
} catch (NumberFormatException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
return 2000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeFromJSON(Project project, JSONObject o) throws Exception {
|
||||
_name = o.getString("name");
|
||||
|
@ -0,0 +1,48 @@
|
||||
package com.metaweb.gridworks.commands;
|
||||
|
||||
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.JSONWriter;
|
||||
|
||||
import com.metaweb.gridworks.ProjectManager;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.preference.PreferenceStore;
|
||||
|
||||
public class GetAllPreferencesCommand extends Command {
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
Project project = request.getParameter("project") != null ? getProject(request) : null;
|
||||
PreferenceStore ps = project != null ?
|
||||
project.getMetadata().getPreferenceStore() :
|
||||
ProjectManager.singleton.getPreferenceStore();
|
||||
|
||||
try {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||
|
||||
writer.object();
|
||||
|
||||
for (String key : ps.getKeys()) {
|
||||
Object pref = ps.get(key);
|
||||
if (pref == null || pref instanceof String || pref instanceof Number || pref instanceof Boolean) {
|
||||
writer.key(key);
|
||||
writer.value(pref);
|
||||
}
|
||||
}
|
||||
|
||||
writer.endObject();
|
||||
} catch (JSONException e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -27,8 +27,7 @@ public class SetPreferenceCommand extends Command {
|
||||
String valueString = request.getParameter("value");
|
||||
|
||||
try {
|
||||
JSONTokener t = new JSONTokener(valueString);
|
||||
Object o = t.nextValue();
|
||||
Object o = valueString == null ? null : new JSONTokener(valueString).nextValue();
|
||||
|
||||
ps.put(prefName, PreferenceStore.loadObject(o));
|
||||
|
||||
|
@ -5,6 +5,7 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@ -16,13 +17,21 @@ public class PreferenceStore implements Jsonizable {
|
||||
protected Map<String, Object> _prefs = new HashMap<String, Object>();
|
||||
|
||||
public void put(String key, Object value) {
|
||||
_prefs.put(key, value);
|
||||
if (value == null) {
|
||||
_prefs.remove(key);
|
||||
} else {
|
||||
_prefs.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public Object get(String key) {
|
||||
return _prefs.get(key);
|
||||
}
|
||||
|
||||
public Set<String> getKeys() {
|
||||
return _prefs.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(JSONWriter writer, Properties options) throws JSONException {
|
||||
writer.object();
|
||||
@ -58,13 +67,12 @@ public class PreferenceStore implements Jsonizable {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static public Object loadObject(Object o) {
|
||||
if (o instanceof JSONObject) {
|
||||
try {
|
||||
JSONObject obj2 = (JSONObject) o;
|
||||
String className = obj2.getString("class");
|
||||
Class klass = Class.forName(className);
|
||||
Class<?> klass = Class.forName(className);
|
||||
Method method = klass.getMethod("load", JSONObject.class);
|
||||
|
||||
return method.invoke(null, obj2);
|
||||
|
@ -6,7 +6,8 @@ var bundle = true;
|
||||
var templatedFiles = {
|
||||
// Requests with last path segments mentioned here
|
||||
// will get served from .vt files with the same names
|
||||
"project" : true
|
||||
"project" : true,
|
||||
"preferences" : true
|
||||
};
|
||||
|
||||
/*
|
||||
@ -113,6 +114,32 @@ function init() {
|
||||
"styles/protograph/schema-alignment-dialog.css"
|
||||
]
|
||||
);
|
||||
|
||||
ClientSideResourceManager.addPaths(
|
||||
"preferences/scripts",
|
||||
module,
|
||||
[
|
||||
"externals/jquery-1.4.2.min.js",
|
||||
"externals/jquery.cookie.js",
|
||||
"externals/suggest/suggest-1.2.min.js",
|
||||
"externals/jquery-ui/jquery-ui-1.8.custom.min.js",
|
||||
"externals/imgareaselect/jquery.imgareaselect.js",
|
||||
"externals/date.js",
|
||||
"scripts/preferences.js"
|
||||
]
|
||||
);
|
||||
ClientSideResourceManager.addPaths(
|
||||
"preferences/styles",
|
||||
module,
|
||||
[
|
||||
"externals/suggest/css/suggest-1.2.min.css",
|
||||
"externals/jquery-ui/css/ui-lightness/jquery-ui-1.8.custom.css",
|
||||
|
||||
"styles/common.css",
|
||||
"styles/jquery-ui-overrides.css",
|
||||
"styles/preferences.css"
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
|
24
main/webapp/modules/core/preferences.vt
Normal file
24
main/webapp/modules/core/preferences.vt
Normal file
@ -0,0 +1,24 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>Freebase Gridworks - Preferences</title>
|
||||
|
||||
<script type="text/javascript" src="wirings.js"></script>
|
||||
$scriptInjection
|
||||
|
||||
<link rel="icon" type="image/png" href="images/favicon.png" />
|
||||
$styleInjection
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="header">
|
||||
<a id="logo" href="http://www.freebase.com/" title="Freebase"><img alt="Freebase" src="images/freebase-headerlogo.png" /></a>
|
||||
<div id="path"><span class="app-path-section"><a href="./index.html">Gridworks</a></span><span class="app-path-section">Preferences</span></div>
|
||||
</div>
|
||||
|
||||
<div id="body">
|
||||
<div id="loading-message"><img src="images/large-spinner.gif" /> starting up ...</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
109
main/webapp/modules/core/scripts/preferences.js
Normal file
109
main/webapp/modules/core/scripts/preferences.js
Normal file
@ -0,0 +1,109 @@
|
||||
var preferenceUIs = [];
|
||||
|
||||
function onLoad() {
|
||||
$.post(
|
||||
"/command/get-all-preferences",
|
||||
null,
|
||||
populatePreferences,
|
||||
"json"
|
||||
);
|
||||
}
|
||||
|
||||
$(onLoad);
|
||||
|
||||
function populatePreferences(prefs) {
|
||||
var body = $("#body").empty();
|
||||
|
||||
$('<h1>').text("Preferences").appendTo(body);
|
||||
|
||||
var table = $('<table>').addClass("preferences").html('<tr><th>Key</th><th>Value</th><td></td></tr>').appendTo(body)[0];
|
||||
for (var k in prefs) {
|
||||
var tr = table.insertRow(table.rows.length);
|
||||
preferenceUIs.push(new PreferenceUI(tr, k, prefs[k]));
|
||||
}
|
||||
|
||||
var trLast = table.insertRow(table.rows.length);
|
||||
var tdLast0 = trLast.insertCell(0);
|
||||
$('<button>').text("Add Preference").appendTo(tdLast0).click(function() {
|
||||
var key = window.prompt("Preference Key");
|
||||
if (key) {
|
||||
var value = window.prompt("Preference Value");
|
||||
if (value != null) {
|
||||
var tr = table.insertRow(table.rows.length - 1);
|
||||
preferenceUIs.push(new PreferenceUI(tr, key, value));
|
||||
|
||||
$.post(
|
||||
"/command/set-preference",
|
||||
{
|
||||
name : key,
|
||||
value : JSON.stringify(value)
|
||||
},
|
||||
function(o) {
|
||||
if (o.code == "error") {
|
||||
alert(o.message);
|
||||
}
|
||||
},
|
||||
"json"
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function PreferenceUI(tr, key, value) {
|
||||
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>').text("Edit").appendTo(td2).click(function() {
|
||||
var newValue = window.prompt("Value of preference key " + key, value);
|
||||
if (newValue != null) {
|
||||
$(td1).text(newValue);
|
||||
$.post(
|
||||
"/command/set-preference",
|
||||
{
|
||||
name : key,
|
||||
value : JSON.stringify(newValue)
|
||||
},
|
||||
function(o) {
|
||||
if (o.code == "error") {
|
||||
alert(o.message);
|
||||
}
|
||||
},
|
||||
"json"
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
$('<button>').text("Delete").appendTo(td2).click(function() {
|
||||
if (window.confirm("Delete preference key " + key + "?")) {
|
||||
$.post(
|
||||
"/command/set-preference",
|
||||
{
|
||||
name : key
|
||||
},
|
||||
function(o) {
|
||||
if (o.code == "ok") {
|
||||
$(tr).remove();
|
||||
|
||||
for (var i = 0; i < preferenceUIs.length; i++) {
|
||||
if (preferenceUIs[i] === self) {
|
||||
preferenceUIs.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (o.code == "error") {
|
||||
alert(o.message);
|
||||
}
|
||||
},
|
||||
"json"
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
22
main/webapp/modules/core/styles/preferences.css
Normal file
22
main/webapp/modules/core/styles/preferences.css
Normal file
@ -0,0 +1,22 @@
|
||||
#body {
|
||||
padding: 5em;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#loading-message {
|
||||
text-align: center;
|
||||
font-size: 300%;
|
||||
color: #aaa;
|
||||
padding: 1in;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
table.preferences th, table.preferences td {
|
||||
padding: 3px;
|
||||
}
|
||||
table.preferences th {
|
||||
background: #ddd;
|
||||
}
|
||||
table.preferences td {
|
||||
background: #eee;
|
||||
}
|
Loading…
Reference in New Issue
Block a user