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");
MenuSystem.createAndShowStandardMenu(
item.submenu,
this,
{
horizontal: true,
onDismiss: function() {
menuItem.removeClass("menu-expanded");
}
var options = {
horizontal: true,
onDismiss: function() {
menuItem.removeClass("menu-expanded");
}
);
};
if ("width" in item) {
options.width = item.width;
}
MenuSystem.createAndShowStandardMenu(item.submenu, this, options);
});
} else {
menuItem.html(item.label).click(function(evt) {

View File

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

View File

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

View File

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