Made data table view's All menu extensible. Added more common transforms. Touched up on a few menus.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@1593 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-10-18 01:53:23 +00:00
parent 2090136d74
commit 2fc0374f79
4 changed files with 99 additions and 21 deletions

View File

@ -128,16 +128,17 @@ MenuSystem.createAndShowStandardMenu = function(items, elmt, options) {
menuItem.addClass("menu-expanded"); menuItem.addClass("menu-expanded");
MenuSystem.createAndShowStandardMenu( var options = {
item.submenu, horizontal: true,
this, onDismiss: function() {
{ menuItem.removeClass("menu-expanded");
horizontal: true,
onDismiss: function() {
menuItem.removeClass("menu-expanded");
}
} }
); };
if ("width" in item) {
options.width = item.width;
}
MenuSystem.createAndShowStandardMenu(item.submenu, this, options);
}); });
} else { } else {
menuItem.html(item.label).click(function(evt) { menuItem.html(item.label).click(function(evt) {

View File

@ -9,6 +9,14 @@ function DataTableColumnHeaderUI(dataTableView, column, columnIndex, td) {
DataTableColumnHeaderUI._extenders = []; DataTableColumnHeaderUI._extenders = [];
/*
To extend, call
DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) {
...
MenuSystem.appendTo(menu, path, newItems);
});
*/
DataTableColumnHeaderUI.extendMenu = function(extender) { DataTableColumnHeaderUI.extendMenu = function(extender) {
DataTableColumnHeaderUI._extenders.push(extender); DataTableColumnHeaderUI._extenders.push(extender);
}; };
@ -61,12 +69,14 @@ DataTableColumnHeaderUI.prototype._createMenuForColumnHeader = function(elmt) {
{ {
id: "core/facet", id: "core/facet",
label: "Facet", label: "Facet",
width: "170px",
submenu: [] submenu: []
}, },
{}, {},
{ {
id: "core/edit-cells", id: "core/edit-cells",
label: "Edit Cells", label: "Edit Cells",
width: "170px",
submenu: [] submenu: []
}, },
{ {
@ -145,6 +155,7 @@ DataTableColumnHeaderUI.prototype._createMenuForColumnHeader = function(elmt) {
id: "core/reconcile", id: "core/reconcile",
label: "Reconcile", label: "Reconcile",
tooltip: "Match this column's cells to topics on Freebase", tooltip: "Match this column's cells to topics on Freebase",
width: "170px",
submenu: [] submenu: []
} }
]; ];

View File

@ -10,6 +10,25 @@ function DataTableView(div) {
this._showRows(0); this._showRows(0);
} }
DataTableView._extenders = [];
/*
To extend, do something like this
DataTableView.extendMenu(function(dataTableView, menu) {
...
MenuSystem.appendTo(menu, [ "core/view" ], {
"label": "Test",
"click": function() {
alert("Test");
}
});
});
*/
DataTableView.extendMenu = function(extender) {
DataTableView._extenders.push(extender);
};
DataTableView.prototype.getSorting = function() { DataTableView.prototype.getSorting = function() {
return this._sorting; return this._sorting;
}; };
@ -429,11 +448,14 @@ DataTableView.prototype._addSortingCriterion = function(criterion, alone) {
DataTableView.prototype._createMenuForAllColumns = function(elmt) { DataTableView.prototype._createMenuForAllColumns = function(elmt) {
var self = this; var self = this;
MenuSystem.createAndShowStandardMenu([ var menu = [
{ label: "Facet", { label: "Facet",
id: "core/facets",
width: "200px",
submenu: [ submenu: [
{ {
label: "Facet by Star", label: "Facet by Star",
id: "core/facet-by-star",
click: function() { click: function() {
ui.browsingEngine.addFacet( ui.browsingEngine.addFacet(
"list", "list",
@ -450,6 +472,7 @@ DataTableView.prototype._createMenuForAllColumns = function(elmt) {
}, },
{ {
label: "Facet by Flag", label: "Facet by Flag",
id: "core/facet-by-flag",
click: function() { click: function() {
ui.browsingEngine.addFacet( ui.browsingEngine.addFacet(
"list", "list",
@ -466,16 +489,21 @@ DataTableView.prototype._createMenuForAllColumns = function(elmt) {
} }
] ]
}, },
{},
{ label: "Edit Rows", { label: "Edit Rows",
id: "core/edit-rows",
width: "200px",
submenu: [ submenu: [
{ {
label: "Star Rows", label: "Star Rows",
id: "core/star-rows",
click: function() { click: function() {
Refine.postCoreProcess("annotate-rows", { "starred" : "true" }, null, { rowMetadataChanged: true }); Refine.postCoreProcess("annotate-rows", { "starred" : "true" }, null, { rowMetadataChanged: true });
} }
}, },
{ {
label: "Unstar Rows", label: "Unstar Rows",
id: "core/unstar-rows",
click: function() { click: function() {
Refine.postCoreProcess("annotate-rows", { "starred" : "false" }, null, { rowMetadataChanged: true }); Refine.postCoreProcess("annotate-rows", { "starred" : "false" }, null, { rowMetadataChanged: true });
} }
@ -483,12 +511,14 @@ DataTableView.prototype._createMenuForAllColumns = function(elmt) {
{}, {},
{ {
label: "Flag Rows", label: "Flag Rows",
id: "core/flag-rows",
click: function() { click: function() {
Refine.postCoreProcess("annotate-rows", { "flagged" : "true" }, null, { rowMetadataChanged: true }); Refine.postCoreProcess("annotate-rows", { "flagged" : "true" }, null, { rowMetadataChanged: true });
} }
}, },
{ {
label: "Unflag Rows", label: "Unflag Rows",
id: "core/unflag-rows",
click: function() { click: function() {
Refine.postCoreProcess("annotate-rows", { "flagged" : "false" }, null, { rowMetadataChanged: true }); Refine.postCoreProcess("annotate-rows", { "flagged" : "false" }, null, { rowMetadataChanged: true });
} }
@ -496,6 +526,7 @@ DataTableView.prototype._createMenuForAllColumns = function(elmt) {
{}, {},
{ {
label: "Remove All Matching Rows", label: "Remove All Matching Rows",
id: "core/remove-rows",
click: function() { click: function() {
Refine.postCoreProcess("remove-rows", {}, null, { rowMetadataChanged: true }); Refine.postCoreProcess("remove-rows", {}, null, { rowMetadataChanged: true });
} }
@ -503,19 +534,26 @@ DataTableView.prototype._createMenuForAllColumns = function(elmt) {
] ]
}, },
{ label: "Edit Columns", { label: "Edit Columns",
id: "core/edit-columns",
width: "200px",
submenu: [ submenu: [
{ {
label: "Re-order Columns", label: "Re-order Columns ...",
id: "core/reorder-columns",
click: function() { click: function() {
new ColumnReorderingDialog(); new ColumnReorderingDialog();
} }
} }
] ]
}, },
{},
{ label: "View", { label: "View",
id: "core/view",
width: "200px",
submenu: [ submenu: [
{ {
label: "Collapse All Columns", label: "Collapse All Columns",
id: "core/collapse-all-columns",
click: function() { click: function() {
for (var i = 0; i < theProject.columnModel.columns.length; i++) { for (var i = 0; i < theProject.columnModel.columns.length; i++) {
self._collapsedColumnNames[theProject.columnModel.columns[i].name] = true; self._collapsedColumnNames[theProject.columnModel.columns[i].name] = true;
@ -525,6 +563,7 @@ DataTableView.prototype._createMenuForAllColumns = function(elmt) {
}, },
{ {
label: "Expand All Columns", label: "Expand All Columns",
id: "core/expand-all-columns",
click: function() { click: function() {
self._collapsedColumnNames = []; self._collapsedColumnNames = [];
self.render(); self.render();
@ -532,7 +571,13 @@ DataTableView.prototype._createMenuForAllColumns = function(elmt) {
} }
] ]
} }
], elmt, { width: "120px", horizontal: false }); ];
for (var i = 0; i < DataTableView._extenders.length; i++) {
DataTableView._extenders[i].call(null, this, menu);
}
MenuSystem.createAndShowStandardMenu(menu, elmt, { width: "120px", horizontal: false });
}; };
DataTableView.prototype._createSortingMenu = function(elmt) { DataTableView.prototype._createSortingMenu = function(elmt) {
@ -643,5 +688,3 @@ DataTableView.promptExpressionOnVisibleRows = function(column, title, expression
onDone onDone
); );
}; };

View File

@ -119,16 +119,22 @@ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) {
label: "Common Transforms", label: "Common Transforms",
submenu: [ submenu: [
{ {
id: "core/unescape-html-entities", id: "core/trim-whitespace",
label: "Unescape HTML entities", label: "Trim leading and trailing whitespace",
click: function() { doTextTransform("value.unescape('html')", "store-blank", true, 10); } click: function() { doTextTransform("value.trim()", "store-blank", false, ""); }
}, },
{ {
id: "core/collapse-whitespace", id: "core/collapse-whitespace",
label: "Collapse whitespace", label: "Collapse consecutive whitespace",
click: function() { doTextTransform("value.replace(/\\s+/,' ')", "store-blank", false, ""); } click: function() { doTextTransform("value.replace(/\\s+/,' ')", "store-blank", false, ""); }
}, },
{}, {},
{
id: "core/unescape-html-entities",
label: "Unescape HTML entities",
click: function() { doTextTransform("value.unescape('html')", "store-blank", true, 10); }
},
{},
{ {
id: "core/to-titlecase", id: "core/to-titlecase",
label: "To Titlecase", label: "To Titlecase",
@ -144,9 +150,26 @@ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) {
label: "To Lowercase", label: "To Lowercase",
click: function() { doTextTransform("toLowercase(value)", "store-blank", false, ""); } click: function() { doTextTransform("toLowercase(value)", "store-blank", false, ""); }
}, },
{},
{
id: "core/to-number",
label: "To number",
click: function() { doTextTransform("toNumber(value)", "store-blank", false, ""); }
},
{
id: "core/to-date",
label: "To date",
click: function() { doTextTransform("toDate(value)", "store-blank", false, ""); }
},
{
id: "core/to-text",
label: "To text",
click: function() { doTextTransform("toString(value)", "store-blank", false, ""); }
},
{},
{ {
id: "core/to-blank", id: "core/to-blank",
label: "To Blank", label: "Blank out cells",
click: function() { doTextTransform("null", "store-blank", false, ""); } click: function() { doTextTransform("null", "store-blank", false, ""); }
} }
] ]
@ -278,12 +301,12 @@ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) {
MenuSystem.appendTo(menu, [ "core/transpose" ], [ MenuSystem.appendTo(menu, [ "core/transpose" ], [
{ {
id: "core/transpose-columns-into-rows", id: "core/transpose-columns-into-rows",
label: "Cells Across Columns into Rows", label: "Cells Across Columns into Rows ...",
click: doTransposeColumnsIntoRows click: doTransposeColumnsIntoRows
}, },
{ {
id: "core/transpose-rows-into-columns", id: "core/transpose-rows-into-columns",
label: "Cells in Rows into Columns", label: "Cells in Rows into Columns ...",
click: doTransposeRowsIntoColumns click: doTransposeRowsIntoColumns
} }
]); ]);