From 40c5fb8ff1307e71c2b87729fab7626ebafa5464 Mon Sep 17 00:00:00 2001 From: David Huynh Date: Sat, 26 Jun 2010 05:34:54 +0000 Subject: [PATCH] More work on recon refactoring: - services can now be unregistered. - matched topics and candidates now have links formatted by the service that generated them. - recon candidate previews are also based on the recon service. git-svn-id: http://google-refine.googlecode.com/svn/trunk@1040 7d457c2a-affb-35e4-300a-418c747d4874 --- .../scripts/reconciliation/recon-dialog.js | 10 ++ .../scripts/reconciliation/recon-manager.js | 43 ++++- .../reconciliation/standard-service-panel.js | 6 +- .../views/data-table/data-table-cell-ui.js | 149 +++++++++--------- .../styles/reconciliation/recon-dialog.css | 16 ++ 5 files changed, 142 insertions(+), 82 deletions(-) diff --git a/main/webapp/modules/core/scripts/reconciliation/recon-dialog.js b/main/webapp/modules/core/scripts/reconciliation/recon-dialog.js index f5b89a33f..bf1fdfee7 100644 --- a/main/webapp/modules/core/scripts/reconciliation/recon-dialog.js +++ b/main/webapp/modules/core/scripts/reconciliation/recon-dialog.js @@ -76,6 +76,16 @@ ReconDialog.prototype._populateDialog = function() { .click(function() { self._selectService(record); }); + + $('') + .html(" ") + .addClass("recon-dialog-service-selector-remove") + .prependTo(record.selector) + .click(function() { + ReconciliationManager.unregisterService(service, function() { + self._refresh(-1); + }); + }); self._serviceRecords.push(record); }; diff --git a/main/webapp/modules/core/scripts/reconciliation/recon-manager.js b/main/webapp/modules/core/scripts/reconciliation/recon-manager.js index 6c67c3a96..b69dddf17 100644 --- a/main/webapp/modules/core/scripts/reconciliation/recon-manager.js +++ b/main/webapp/modules/core/scripts/reconciliation/recon-manager.js @@ -1,6 +1,25 @@ var ReconciliationManager = { - "customServices" : [], // services registered by core and extensions - "standardServices" : [] // services registered by user + customServices : [], // services registered by core and extensions + standardServices : [], // services registered by user + _urlMap : {} +}; + +ReconciliationManager.isFreebaseId = function(s) { + return s == "http://rdf.freebase.com/ns/type.object.id"; +}; + +ReconciliationManager._rebuildMap = function() { + var map = {}; + $.each(ReconciliationManager.getAllServices(), function(i, service) { + if ("url" in service) { + map[service.url] = service; + } + }); + ReconciliationManager._urlMap = map; +}; + +ReconciliationManager.getServiceFromUrl = function(url) { + return ReconciliationManager._urlMap[url]; }; ReconciliationManager.getAllServices = function() { @@ -9,6 +28,7 @@ ReconciliationManager.getAllServices = function() { ReconciliationManager.registerService = function(service) { ReconciliationManager.customServices.push(service); + ReconciliationManager._rebuildMap(); return ReconciliationManager.customServices.length - 1; }; @@ -25,6 +45,8 @@ ReconciliationManager.registerStandardService = function(url, f) { ReconciliationManager.standardServices.length; ReconciliationManager.standardServices.push(data); + ReconciliationManager._rebuildMap(); + ReconciliationManager.save(); if (f) { @@ -35,6 +57,22 @@ ReconciliationManager.registerStandardService = function(url, f) { }); }; +ReconciliationManager.unregisterService = function(service, f) { + for (var i = 0; i < ReconciliationManager.customServices.length; i++) { + if (ReconciliationManager.customServices[i] === service) { + ReconciliationManager.customServices.splice(i, 1); + break; + } + } + for (var i = 0; i < ReconciliationManager.standardServices.length; i++) { + if (ReconciliationManager.standardServices[i] === service) { + ReconciliationManager.standardServices.splice(i, 1); + break; + } + } + ReconciliationManager.save(f); +}; + ReconciliationManager.save = function(f) { $.ajax({ async: false, @@ -64,6 +102,7 @@ ReconciliationManager.save = function(f) { success: function(data) { if (data.value && data.value != "null") { ReconciliationManager.standardServices = JSON.parse(data.value); + ReconciliationManager._rebuildMap(); } else { ReconciliationManager.registerStandardService( "http://standard-reconcile.dfhuynh.user.dev.freebaseapps.com/reconcile"); diff --git a/main/webapp/modules/core/scripts/reconciliation/standard-service-panel.js b/main/webapp/modules/core/scripts/reconciliation/standard-service-panel.js index ba8303653..9dea64d66 100644 --- a/main/webapp/modules/core/scripts/reconciliation/standard-service-panel.js +++ b/main/webapp/modules/core/scripts/reconciliation/standard-service-panel.js @@ -212,13 +212,11 @@ ReconStandardServicePanel.prototype._rewirePropertySuggests = function(type) { }; ReconStandardServicePanel.prototype._isInFreebaseIdentifierSpace = function() { - return "identifierSpace" in this._service && - this._service.identifierSpace == "http://rdf.freebase.com/ns/type.object.id"; + return ReconciliationManager.isFreebaseId(this._service.identifierSpace); }; ReconStandardServicePanel.prototype._isInFreebaseSchemaSpace = function() { - return "schemaSpace" in this._service && - this._service.schemaSpace == "http://rdf.freebase.com/ns/type.object.id"; + return ReconciliationManager.isFreebaseId(this._service.schemaSpace); }; ReconStandardServicePanel.prototype.start = function() { diff --git a/main/webapp/modules/core/scripts/views/data-table/data-table-cell-ui.js b/main/webapp/modules/core/scripts/views/data-table/data-table-cell-ui.js index 80ee62552..d03d68a0a 100644 --- a/main/webapp/modules/core/scripts/views/data-table/data-table-cell-ui.js +++ b/main/webapp/modules/core/scripts/views/data-table/data-table-cell-ui.js @@ -49,6 +49,8 @@ DataTableCellUI.prototype._render = function() { } } else { var r = cell.r; + var service = (r.service) ? ReconciliationManager.getServiceFromUrl(r.service) : null; + if (r.j == "new") { $('').text(cell.v + " (new topic) ").appendTo(divContent); @@ -60,12 +62,19 @@ DataTableCellUI.prototype._render = function() { }); } else if (r.j == "matched" && "m" in r && r.m !== null) { var match = cell.r.m; - $('') + var a = $('') .text(match.name) - .attr("href", "http://www.freebase.com/view" + match.id) .attr("target", "_blank") .appendTo(divContent); + if (service) { + if ((service.view) && (service.view.url)) { + a.attr("href", service.view.url.replace("{{id}}", match.id)); + } else if (ReconciliationManager.isFreebaseId(service.identifierSpace)) { + a.attr("href", "http://www.freebase.com/view" + match.id); + } + } + $(' ').appendTo(divContent); $('') .text("re\u2011match") @@ -98,19 +107,36 @@ DataTableCellUI.prototype._render = function() { self._doMatchTopicToOneCell(candidate); }); - $('') + var a = $('') .addClass("data-table-recon-topic") - .attr("href", "http://www.freebase.com/view" + candidate.id) .attr("target", "_blank") .text(candidate.name) - .appendTo(li) - .click(function(evt) { - if (!evt.metaKey && !evt.ctrlKey) { - self._previewCandidateTopic(candidate, this); - evt.preventDefault(); - return false; - } - }); + .appendTo(li); + + if (service) { + if ((service.view) && (service.view.url)) { + a.attr("href", service.view.url.replace("{{id}}", candidate.id)); + } else if (ReconciliationManager.isFreebaseId(service.identifierSpace)) { + a.attr("href", "http://www.freebase.com/view" + candidate.id); + } + + var preview = null; + if (service.preview) { + preview = service.preview; + } else if (ReconciliationManager.isFreebaseId(service.identifierSpace)) { + preview = DataTableCellUI.topicBlockPreview; + } + + if (preview) { + a.click(function(evt) { + if (!evt.metaKey && !evt.ctrlKey) { + self._previewCandidateTopic(candidate, this, preview); + evt.preventDefault(); + return false; + } + }); + } + } var score; if (candidate.score < 1) { @@ -322,77 +348,48 @@ DataTableCellUI.prototype._postProcessSeveralCells = function(command, params, c ); }; -DataTableCellUI.topicBlockParams = { - "mode" : "content", - "blocks" : JSON.stringify([ - { - "block" : "full_info" - }, - { - "block" : "article_props" - } - ]) -}; - -DataTableCellUI.topicBlockDimensions = { +DataTableCellUI.topicBlockPreview = { + url: 'http://www.freebase.com/widget/topic{{id}}?mode=content&blocks=[{"block":"full_info"},{"block":"article_props"}]', width: 430, height: 300 }; -DataTableCellUI.prototype._previewCandidateTopic = function(candidate, elmt) { +DataTableCellUI.prototype._previewCandidateTopic = function(candidate, elmt, preview) { var self = this; var id = candidate.id; - - var render = function(id2) { - var url = "http://www.freebase.com/widget/topic" + id2 + '?' + $.param(DataTableCellUI.topicBlockParams); - - var fakeMenu = MenuSystem.createMenu(); - fakeMenu - .width(DataTableCellUI.topicBlockDimensions.width) - .css("background", "none") - .css("border", "none") - .html( - '
' + - ' ' + - '' + - '
' - ); - - var iframe = $('') - .addClass("data-table-topic-popup-iframe") - .width(DataTableCellUI.topicBlockDimensions.width) - .height(DataTableCellUI.topicBlockDimensions.height) - .attr("src", url) - .appendTo(fakeMenu); - - MenuSystem.showMenu(fakeMenu, function(){}); - MenuSystem.positionMenuLeftRight(fakeMenu, $(elmt)); - - var elmts = DOM.bind(fakeMenu); - elmts.matchButton.click(function() { - self._doMatchTopicToOneCell(candidate); - MenuSystem.dismissAll(); - }); - elmts.matchSimilarButton.click(function() { - self._doMatchTopicToSimilarCells(candidate); - MenuSystem.dismissAll(); - }); - }; - - if (id.indexOf("/guid/") !== 0) { - render(id); - } else { - Freebase.mqlread( - { - "guid" : "#" + id.substring(6), - "id" : null - }, - null, - function(o) { - render(o.result.id); - } + var url = preview.url.replace("{{id}}", id); + + var fakeMenu = MenuSystem.createMenu(); + fakeMenu + .width(preview.width) + .css("background", "none") + .css("border", "none") + .html( + '
' + + ' ' + + '' + + '
' ); - } + + var iframe = $('') + .addClass("data-table-topic-popup-iframe") + .width(preview.width) + .height(preview.height) + .attr("src", url) + .appendTo(fakeMenu); + + MenuSystem.showMenu(fakeMenu, function(){}); + MenuSystem.positionMenuLeftRight(fakeMenu, $(elmt)); + + var elmts = DOM.bind(fakeMenu); + elmts.matchButton.click(function() { + self._doMatchTopicToOneCell(candidate); + MenuSystem.dismissAll(); + }); + elmts.matchSimilarButton.click(function() { + self._doMatchTopicToSimilarCells(candidate); + MenuSystem.dismissAll(); + }); }; DataTableCellUI.prototype._startEdit = function(elmt) { diff --git a/main/webapp/modules/core/styles/reconciliation/recon-dialog.css b/main/webapp/modules/core/styles/reconciliation/recon-dialog.css index b5bc3aa72..2578f82dc 100644 --- a/main/webapp/modules/core/styles/reconciliation/recon-dialog.css +++ b/main/webapp/modules/core/styles/reconciliation/recon-dialog.css @@ -26,3 +26,19 @@ a.recon-dialog-service-selector.selected { padding: 50px 0; color: #aaa; } + +a.recon-dialog-service-selector-remove { + float: right; + position: relative; + top: -5px; + left: 5px; + width: 16px; + height: 16px; + text-decoration: none; + background-image: url(../../images/close-map.png); + background-repeat: no-repeat; + background-position: 0px 0px; +} +a.recon-dialog-service-selector-remove:hover { + background-position: -16px 0px; +} \ No newline at end of file