- Select All and Unselect All buttons in History Extract dialog

- Schema skeleton: support for multiple cells per cell-as nodes, and for conditional links


git-svn-id: http://google-refine.googlecode.com/svn/trunk@1137 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-08-05 20:27:39 +00:00
parent 5cb3f924f6
commit 00c6865d95
7 changed files with 112 additions and 53 deletions

View File

@ -1,5 +1,10 @@
package com.google.gridworks.protograph;
import java.util.Properties;
import org.json.JSONException;
import org.json.JSONWriter;
import com.google.gridworks.model.Column;
import com.google.gridworks.model.Project;
import com.google.gridworks.model.Row;
@ -28,4 +33,10 @@ public class BooleanColumnCondition implements Condition {
return false;
}
@Override
public void write(JSONWriter writer, Properties options) throws JSONException {
writer.object();
writer.key("columnName"); writer.value(columnName);
writer.endObject();
}
}

View File

@ -1,8 +1,9 @@
package com.google.gridworks.protograph;
import com.google.gridworks.Jsonizable;
import com.google.gridworks.model.Project;
import com.google.gridworks.model.Row;
public interface Condition {
public interface Condition extends Jsonizable {
public boolean test(Project project, int rowIndex, Row row);
}

View File

@ -37,6 +37,10 @@ public class Link implements Jsonizable {
writer.key("target");
target.write(writer, options);
}
if (condition != null) {
writer.key("condition");
condition.write(writer, options);
}
writer.endObject();
}

View File

@ -49,7 +49,9 @@ SchemaAlignmentDialog.UILink = function(dialog, link, table, options, parentUINo
SchemaAlignmentDialog.UILink.prototype._renderMain = function() {
$(this._tdMain).empty();
var label = this._link.property !== null ? this._link.property.id : "property?";
var label = this._link.property !== null ?
(this._link.property.id + ((this._link.condition) ? " [?]" : "")) :
"property?";
var self = this;
@ -98,7 +100,7 @@ SchemaAlignmentDialog.UILink.prototype._startEditProperty = function(elmt) {
var sourceTypeID = this._parentUINode.getExpectedType();
var targetNode = this._targetUI._node;
var targetTypeID = "type" in targetNode && targetNode.type !== null ? targetNode.type.id : null;
var targetTypeName = "columnName" in targetNode ? targetNode.columnName : null;
var targetTypeName = "columnNames" in targetNode ? targetNode.columnNames[0] : null;
if (sourceTypeID !== null) {
var self = this;
@ -191,13 +193,46 @@ SchemaAlignmentDialog.UILink.prototype._showPropertySuggestPopup = function(elmt
name: p.name
};
}
var conditionColumnName = conditionalSelect[0].value;
if (conditionColumnName != "") {
self._link.condition = { columnName: conditionColumnName };
} else {
delete self._link.condition;
}
self._configureTarget();
};
var divSearch;
var divConditional = $('<div>')
.addClass("schema-alignment-link-menu-section")
.html("Assert link when 'true' is found in column<br/>").appendTo(menu);
var conditionalSelect = $('<select>').appendTo(divConditional);
$('<option>')
.text("(always assert)")
.attr("value", "")
.attr("name", "schema-alignment-link-menu-condition")
.appendTo(conditionalSelect);
for (var c = 0; c < theProject.columnModel.columns.length; c++) {
var column = theProject.columnModel.columns[c];
var option = $('<option>')
.text(column.name)
.attr("value", column.name)
.attr("name", "schema-alignment-link-menu-condition")
.appendTo(conditionalSelect);
if ((self._link.condition) && column.name == self._link.condition.columnName) {
option.attr("selected", "true");
}
}
var divSearch;
if (suggestions.length > 0) {
divSearch = $('<div>').addClass("schema-alignment-link-menu-type-search2").html('<div>Search for a property or pick one below</div>').appendTo(menu);
divSearch = $('<div>')
.addClass("schema-alignment-link-menu-section")
.html('<div>Search for a property or pick one below</div>').appendTo(menu);
var createSuggestion = function(suggestion) {
var menuItem = MenuSystem.createMenuItem().appendTo(menu);
@ -225,7 +260,9 @@ SchemaAlignmentDialog.UILink.prototype._showPropertySuggestPopup = function(elmt
createSuggestion(suggestions[i]);
}
} else {
divSearch = $('<div>').addClass("schema-alignment-link-menu-type-search").html('<div>Search for a property</div>').appendTo(menu);
divSearch = $('<div>')
.addClass("schema-alignment-link-menu-section-last")
.html('<div>Search for a property</div>').appendTo(menu);
}
var input = $('<input />').appendTo($('<div>').appendTo(divSearch));
@ -235,19 +272,9 @@ SchemaAlignmentDialog.UILink.prototype._showPropertySuggestPopup = function(elmt
var suggestOptions = {
type : '/type/property'
};
if (this._link.target !== null && "type" in this._link.target && this._link.target.type !== null) {
/*
suggestOptions.mql_filter = [{
"/type/property/expected_type" : {
id: this._link.target.type.id
}
}];
*/
} else {
var sourceTypeID = this._parentUINode.getExpectedType();
if (sourceTypeID !== null) {
suggestOptions.ac_param = { schema: sourceTypeID };
}
var sourceTypeID = this._parentUINode.getExpectedType();
if (sourceTypeID !== null) {
suggestOptions.ac_param = { schema: sourceTypeID };
}
input.suggestP(suggestOptions).bind("fb-select", function(e, data) { commitProperty(data); });
@ -260,10 +287,14 @@ SchemaAlignmentDialog.UILink.prototype.getJSON = function() {
var targetJSON = this._targetUI.getJSON();
if (targetJSON !== null) {
return {
var json = {
property: cloneDeep(this._link.property),
target: targetJSON
};
if (this._link.condition) {
json.condition = cloneDeep(this._link.condition);
}
return json;
}
}
return null;

View File

@ -0,0 +1,21 @@
<div class="dialog-frame" style="width: 800px;">
<div class="dialog-header" bind="dialogHeader">Extract Operations</div>
<div class="dialog-body" bind="dialogBody"><div class="grid-layout layout-normal layout-full"><table>
<tr><td colspan="2">
The following JSON code encodes the operations you have done that can be abstracted.
You can copy and save it in order to apply the same operations in the future.
</td></tr>
<tr>
<td width="50%" style="vertical-align: top">
<div class="extract-operation-dialog-entries"><table cellspacing="5" bind="entryTable"></table></div>
</td>
<td width="50%" style="vertical-align: top">
<div class="input-container"><textarea wrap="off" class="history-operation-json" bind="textarea" /></div>
</td>
</tr>
</table></div></div>
<div class="dialog-footer" bind="dialogFooter"><div class="grid-layout layout-normal layout-full"><table><tr>
<td align="left"><button bind="selectAllButton">Select All</button> <button bind="unselectAllButton">Unselect All</button></td>
<td align="left"><button bind="closeButton">Close</button></td>
</tr></table></div></div>
</div>

View File

@ -124,32 +124,9 @@ HistoryWidget.prototype._extractOperations = function() {
HistoryWidget.prototype._showExtractOperationsDialog = function(json) {
var self = this;
var frame = DialogSystem.createDialog();
frame.width("800px");
var frame = $(DOM.loadHTML("core", "scripts/widgets/history-extract-dialog.html"));
var elmts = DOM.bind(frame);
var header = $('<div></div>').addClass("dialog-header").text("Extract Operations").appendTo(frame);
var body = $('<div></div>').addClass("dialog-body").appendTo(frame);
var footer = $('<div></div>').addClass("dialog-footer").appendTo(frame);
var html = $(
'<div class="grid-layout layout-normal layout-full"><table>' +
'<tr><td colspan="2">' +
'The following JSON code encodes the operations you have done that can be abstracted. ' +
'You can copy and save it in order to apply the same operations in the future.' +
'</td></tr>' +
'<tr>' +
'<td width="50%" style="vertical-align: top">' +
'<div class="extract-operation-dialog-entries"><table cellspacing="5" bind="entryTable"></table></div>' +
'</td>' +
'<td width="50%" style="vertical-align: top">' +
'<div class="input-container"><textarea wrap="off" class="history-operation-json" bind="textarea" /></div>' +
'</td>' +
'</tr>' +
'</table></div>'
).appendTo(body);
var elmts = DOM.bind(html);
var entryTable = elmts.entryTable[0];
var createEntry = function(entry) {
var tr = entryTable.insertRow(entryTable.rows.length);
@ -186,9 +163,23 @@ HistoryWidget.prototype._showExtractOperationsDialog = function(json) {
};
updateJson();
$('<button></button>').text("Close").click(function() {
DialogSystem.dismissUntil(level - 1);
}).appendTo(footer);
elmts.closeButton.click(function() { DialogSystem.dismissUntil(level - 1); });
elmts.selectAllButton.click(function() {
for (var i = 0; i < json.entries.length; i++) {
json.entries[i].selected = true;
}
frame.find('input[type="checkbox"]').attr("checked", "true");
updateJson();
});
elmts.unselectAllButton.click(function() {
for (var i = 0; i < json.entries.length; i++) {
json.entries[i].selected = false;
}
frame.find('input[type="checkbox"]').removeAttr("checked");
updateJson();
});
var level = DialogSystem.showDialog(frame);

View File

@ -101,12 +101,12 @@ div.schema-alignment-dialog-preview {
*--------------------------------------------------
*/
.schema-alignment-link-menu-type-search {
padding: 8px;
}
.schema-alignment-link-menu-type-search2 {
.schema-alignment-link-menu-section {
padding: 8px;
border-bottom: 1px solid #ddd;
margin-bottom: 3px;
}
.schema-alignment-link-menu-section-last {
padding: 8px;
}