diff --git a/extensions/freebase/module/MOD-INF/controller.js b/extensions/freebase/module/MOD-INF/controller.js index 0ab7a0e45..7ea1c7fb1 100644 --- a/extensions/freebase/module/MOD-INF/controller.js +++ b/extensions/freebase/module/MOD-INF/controller.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,89 +29,89 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ function init() { - Packages.com.google.refine.freebase.oauth.FreebaseProvider.register(); - - var RS = Packages.com.google.refine.RefineServlet; - RS.registerClassMapping( - "com.google.refine.model.changes.DataExtensionChange", - "com.google.refine.freebase.model.changes.DataExtensionChange"); - RS.registerClassMapping( - "com.google.refine.operations.SaveProtographOperation$ProtographChange", - "com.google.refine.freebase.operations.SaveProtographOperation$ProtographChange"); - - // TODO(dfhuynh): Temporary hack until we know how the core module can resolve our module's classes - RS.cacheClass(Packages.com.google.refine.freebase.model.changes.DataExtensionChange); - RS.cacheClass(Packages.com.google.refine.freebase.operations.SaveProtographOperation$ProtographChange); - - RS.registerCommand(module, "extend-data", new Packages.com.google.refine.freebase.commands.ExtendDataCommand()); - RS.registerCommand(module, "preview-extend-data", new Packages.com.google.refine.freebase.commands.PreviewExtendDataCommand()); + Packages.com.google.refine.freebase.oauth.FreebaseProvider.register(); - RS.registerCommand(module, "preview-protograph", new Packages.com.google.refine.freebase.commands.PreviewProtographCommand()); - RS.registerCommand(module, "save-protograph", new Packages.com.google.refine.freebase.commands.SaveProtographCommand()); + var RS = Packages.com.google.refine.RefineServlet; + RS.registerClassMapping( + "com.google.refine.model.changes.DataExtensionChange", + "com.google.refine.freebase.model.changes.DataExtensionChange"); + RS.registerClassMapping( + "com.google.refine.operations.SaveProtographOperation$ProtographChange", + "com.google.refine.freebase.operations.SaveProtographOperation$ProtographChange"); - RS.registerCommand(module, "check-authorization", new Packages.com.google.refine.freebase.commands.auth.CheckAuthorizationCommand()); - RS.registerCommand(module, "authorize", new Packages.com.google.refine.freebase.commands.auth.AuthorizeCommand()); - RS.registerCommand(module, "deauthorize", new Packages.com.google.refine.freebase.commands.auth.DeAuthorizeCommand()); - RS.registerCommand(module, "user-badges", new Packages.com.google.refine.freebase.commands.auth.GetUserBadgesCommand()); + // TODO(dfhuynh): Temporary hack until we know how the core module can resolve our module's classes + RS.cacheClass(Packages.com.google.refine.freebase.model.changes.DataExtensionChange); + RS.cacheClass(Packages.com.google.refine.freebase.operations.SaveProtographOperation$ProtographChange); - RS.registerCommand(module, "upload-data", new Packages.com.google.refine.freebase.commands.UploadDataCommand()); - RS.registerCommand(module, "import-qa-data", new Packages.com.google.refine.freebase.commands.ImportQADataCommand()); - RS.registerCommand(module, "mqlread", new Packages.com.google.refine.freebase.commands.MQLReadCommand()); - RS.registerCommand(module, "mqlwrite", new Packages.com.google.refine.freebase.commands.MQLWriteCommand()); + RS.registerCommand(module, "extend-data", new Packages.com.google.refine.freebase.commands.ExtendDataCommand()); + RS.registerCommand(module, "preview-extend-data", new Packages.com.google.refine.freebase.commands.PreviewExtendDataCommand()); - var OR = Packages.com.google.refine.operations.OperationRegistry; - - OR.registerOperation(module, "extend-data", Packages.com.google.refine.freebase.operations.ExtendDataOperation); - OR.registerOperation(module, "import-qa-data", Packages.com.google.refine.freebase.operations.ImportQADataOperation); - OR.registerOperation(module, "save-protograph", Packages.com.google.refine.freebase.operations.SaveProtographOperation); // for backward compatibility - OR.registerOperation(module, "save-schema-alignment-skeleton", Packages.com.google.refine.freebase.operations.SaveProtographOperation); - - var RC = Packages.com.google.refine.model.recon.ReconConfig; - - RC.registerReconConfig(module, "strict", Packages.com.google.refine.freebase.model.recon.StrictReconConfig); - RC.registerReconConfig(module, "extend", Packages.com.google.refine.freebase.model.recon.DataExtensionReconConfig); - - var ER = Packages.com.google.refine.exporters.ExporterRegistry; - - ER.registerExporter("tripleloader", new Packages.com.google.refine.freebase.ProtographTransposeExporter.TripleLoaderExporter()); - ER.registerExporter("mqlwrite", new Packages.com.google.refine.freebase.ProtographTransposeExporter.MqlwriteLikeExporter()); - - var FCR = Packages.com.google.refine.grel.ControlFunctionRegistry; - - FCR.registerFunction("mqlKeyQuote", new Packages.com.google.refine.freebase.expr.MqlKeyQuote()); - FCR.registerFunction("mqlKeyUnquote", new Packages.com.google.refine.freebase.expr.MqlKeyUnquote()); - - Packages.com.google.refine.model.Project. - registerOverlayModel("freebaseProtograph", Packages.com.google.refine.freebase.protograph.Protograph); - - ClientSideResourceManager.addPaths( - "project/scripts", - module, - [ - "scripts/extension.js", - - "scripts/util/sign.js", - "scripts/util/freebase.js", - - "scripts/dialogs/freebase-loading-dialog.js", - "scripts/dialogs/extend-data-preview-dialog.js", - - "scripts/dialogs/schema-alignment/dialog.js", - "scripts/dialogs/schema-alignment/ui-node.js", - "scripts/dialogs/schema-alignment/ui-link.js" - ] - ); - - ClientSideResourceManager.addPaths( - "project/styles", - module, - [ - "styles/dialogs/freebase-loading-dialog.less", - "styles/dialogs/extend-data-preview-dialog.less", - "styles/dialogs/schema-alignment-dialog.less" - ] - ); + RS.registerCommand(module, "preview-protograph", new Packages.com.google.refine.freebase.commands.PreviewProtographCommand()); + RS.registerCommand(module, "save-protograph", new Packages.com.google.refine.freebase.commands.SaveProtographCommand()); + + RS.registerCommand(module, "check-authorization", new Packages.com.google.refine.freebase.commands.auth.CheckAuthorizationCommand()); + RS.registerCommand(module, "authorize", new Packages.com.google.refine.freebase.commands.auth.AuthorizeCommand()); + RS.registerCommand(module, "deauthorize", new Packages.com.google.refine.freebase.commands.auth.DeAuthorizeCommand()); + RS.registerCommand(module, "user-badges", new Packages.com.google.refine.freebase.commands.auth.GetUserBadgesCommand()); + + RS.registerCommand(module, "upload-data", new Packages.com.google.refine.freebase.commands.UploadDataCommand()); + RS.registerCommand(module, "import-qa-data", new Packages.com.google.refine.freebase.commands.ImportQADataCommand()); + RS.registerCommand(module, "mqlread", new Packages.com.google.refine.freebase.commands.MQLReadCommand()); + RS.registerCommand(module, "mqlwrite", new Packages.com.google.refine.freebase.commands.MQLWriteCommand()); + + var OR = Packages.com.google.refine.operations.OperationRegistry; + + OR.registerOperation(module, "extend-data", Packages.com.google.refine.freebase.operations.ExtendDataOperation); + OR.registerOperation(module, "import-qa-data", Packages.com.google.refine.freebase.operations.ImportQADataOperation); + OR.registerOperation(module, "save-protograph", Packages.com.google.refine.freebase.operations.SaveProtographOperation); // for backward compatibility + OR.registerOperation(module, "save-schema-alignment-skeleton", Packages.com.google.refine.freebase.operations.SaveProtographOperation); + + var RC = Packages.com.google.refine.model.recon.ReconConfig; + + RC.registerReconConfig(module, "strict", Packages.com.google.refine.freebase.model.recon.StrictReconConfig); + RC.registerReconConfig(module, "extend", Packages.com.google.refine.freebase.model.recon.DataExtensionReconConfig); + + var ER = Packages.com.google.refine.exporters.ExporterRegistry; + + ER.registerExporter("tripleloader", new Packages.com.google.refine.freebase.ProtographTransposeExporter.TripleLoaderExporter()); + ER.registerExporter("mqlwrite", new Packages.com.google.refine.freebase.ProtographTransposeExporter.MqlwriteLikeExporter()); + + var FCR = Packages.com.google.refine.grel.ControlFunctionRegistry; + + FCR.registerFunction("mqlKeyQuote", new Packages.com.google.refine.freebase.expr.MqlKeyQuote()); + FCR.registerFunction("mqlKeyUnquote", new Packages.com.google.refine.freebase.expr.MqlKeyUnquote()); + + Packages.com.google.refine.model.Project. + registerOverlayModel("freebaseProtograph", Packages.com.google.refine.freebase.protograph.Protograph); + + ClientSideResourceManager.addPaths( + "project/scripts", + module, + [ + "scripts/extension.js", + + "scripts/util/sign.js", + "scripts/util/freebase.js", + + "scripts/dialogs/freebase-loading-dialog.js", + "scripts/dialogs/extend-data-preview-dialog.js", + + "scripts/dialogs/schema-alignment/dialog.js", + "scripts/dialogs/schema-alignment/ui-node.js", + "scripts/dialogs/schema-alignment/ui-link.js" + ] + ); + + ClientSideResourceManager.addPaths( + "project/styles", + module, + [ + "styles/dialogs/freebase-loading-dialog.less", + "styles/dialogs/extend-data-preview-dialog.less", + "styles/dialogs/schema-alignment-dialog.less" + ] + ); } diff --git a/extensions/freebase/module/scripts/dialogs/extend-data-preview-dialog.js b/extensions/freebase/module/scripts/dialogs/extend-data-preview-dialog.js index 03bc8cfb2..838280a84 100644 --- a/extensions/freebase/module/scripts/dialogs/extend-data-preview-dialog.js +++ b/extensions/freebase/module/scripts/dialogs/extend-data-preview-dialog.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,368 +29,368 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ function ExtendDataPreviewDialog(column, columnIndex, rowIndices, onDone) { - this._column = column; - this._columnIndex = columnIndex; - this._rowIndices = rowIndices; - this._onDone = onDone; - this._extension = { properties: [] }; + this._column = column; + this._columnIndex = columnIndex; + this._rowIndices = rowIndices; + this._onDone = onDone; + this._extension = { properties: [] }; - var self = this; - this._dialog = $(DOM.loadHTML("freebase", "scripts/dialogs/extend-data-preview-dialog.html")); - this._elmts = DOM.bind(this._dialog); - this._elmts.dialogHeader.text("Add Columns from Freebase Based on Column " + column.name); - this._elmts.resetButton.click(function() { - self._extension.properties = []; - self._update(); - }); - - this._elmts.okButton.click(function() { - if (self._extension.properties.length === 0) { - alert("Please add some properties first."); - } else { - DialogSystem.dismissUntil(self._level - 1); - self._onDone(self._extension); - } - }); - this._elmts.cancelButton.click(function() { - DialogSystem.dismissUntil(self._level - 1); - }); - - var dismissBusy = DialogSystem.showBusy(); - var type = (column.reconConfig) && (column.reconConfig.type) ? column.reconConfig.type.id : "/common/topic"; - - ExtendDataPreviewDialog.getAllProperties(type, function(properties) { - dismissBusy(); - self._show(properties); - }); + var self = this; + this._dialog = $(DOM.loadHTML("freebase", "scripts/dialogs/extend-data-preview-dialog.html")); + this._elmts = DOM.bind(this._dialog); + this._elmts.dialogHeader.text("Add Columns from Freebase Based on Column " + column.name); + this._elmts.resetButton.click(function() { + self._extension.properties = []; + self._update(); + }); + + this._elmts.okButton.click(function() { + if (self._extension.properties.length === 0) { + alert("Please add some properties first."); + } else { + DialogSystem.dismissUntil(self._level - 1); + self._onDone(self._extension); + } + }); + this._elmts.cancelButton.click(function() { + DialogSystem.dismissUntil(self._level - 1); + }); + + var dismissBusy = DialogSystem.showBusy(); + var type = (column.reconConfig) && (column.reconConfig.type) ? column.reconConfig.type.id : "/common/topic"; + + ExtendDataPreviewDialog.getAllProperties(type, function(properties) { + dismissBusy(); + self._show(properties); + }); } ExtendDataPreviewDialog.getAllProperties = function(typeID, onDone) { - var done = false; - - $.getJSON( - Refine.refineHelperService + "/get_properties_of_type?type=" + typeID + "&callback=?", - null, - function(data) { - if (done) return; - done = true; - - var allProperties = []; - for (var i = 0; i < data.properties.length; i++) { - var property = data.properties[i]; - var property2 = { - id: property.id, - name: property.name - }; - if ("id2" in property) { - property2.expected = property.schema2; - property2.properties = [{ - id: property.id2, - name: property.name2, - expected: property.expects - }]; - } else { - property2.expected = property.expects; - } - allProperties.push(property2); - } - allProperties.sort(function(a, b) { return a.name.localeCompare(b.name); }); - - onDone(allProperties); + var done = false; + + $.getJSON( + Refine.refineHelperService + "/get_properties_of_type?type=" + typeID + "&callback=?", + null, + function(data) { + if (done) return; + done = true; + + var allProperties = []; + for (var i = 0; i < data.properties.length; i++) { + var property = data.properties[i]; + var property2 = { + id: property.id, + name: property.name + }; + if ("id2" in property) { + property2.expected = property.schema2; + property2.properties = [{ + id: property.id2, + name: property.name2, + expected: property.expects + }]; + } else { + property2.expected = property.expects; } - ); - - window.setTimeout(function() { - if (done) return; - - done = true; - onDone([]); - }, 7000); // time to give up? + allProperties.push(property2); + } + allProperties.sort(function(a, b) { return a.name.localeCompare(b.name); }); + + onDone(allProperties); + } + ); + + window.setTimeout(function() { + if (done) return; + + done = true; + onDone([]); + }, 7000); // time to give up? }; ExtendDataPreviewDialog.prototype._show = function(properties) { - this._level = DialogSystem.showDialog(this._dialog); - - var n = this._elmts.suggestedPropertyContainer.offset().top + - this._elmts.suggestedPropertyContainer.outerHeight(true) - - this._elmts.addPropertyInput.offset().top; - - this._elmts.previewContainer.height(Math.floor(n)); - - var self = this; - var container = this._elmts.suggestedPropertyContainer; - var renderSuggestedProperty = function(property) { - var label = ("properties" in property) ? (property.name + " » " + property.properties[0].name) : property.name; - var div = $('