Merge pull request #1959 from OpenRefine/issue1943
Show reconciliation previews on hover of reconciliation candidates
This commit is contained in:
commit
79394b9c0e
@ -41,6 +41,23 @@ function DataTableCellUI(dataTableView, cell, rowIndex, cellIndex, td) {
|
|||||||
this._render();
|
this._render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DataTableCellUI.previewMatchedCells = true;
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "command/core/get-preference?" + $.param({
|
||||||
|
name: "cell-ui.previewMatchedCells"
|
||||||
|
}),
|
||||||
|
success: function(data) {
|
||||||
|
if (data.value && data.value == "false") {
|
||||||
|
DataTableCellUI.previewMatchedCells = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dataType: "json",
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
|
||||||
DataTableCellUI.prototype._render = function() {
|
DataTableCellUI.prototype._render = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
var cell = this._cell;
|
var cell = this._cell;
|
||||||
@ -108,6 +125,10 @@ DataTableCellUI.prototype._render = function() {
|
|||||||
a.attr("href", encodeURI(service.view.url.replace("{{id}}", match.id)));
|
a.attr("href", encodeURI(service.view.url.replace("{{id}}", match.id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (DataTableCellUI.previewMatchedCells) {
|
||||||
|
self._previewOnHover(service, match, a, a, false);
|
||||||
|
}
|
||||||
|
|
||||||
$('<span> </span>').appendTo(divContent);
|
$('<span> </span>').appendTo(divContent);
|
||||||
$('<a href="javascript:{}"></a>')
|
$('<a href="javascript:{}"></a>')
|
||||||
.text($.i18n('core-views/choose-match'))
|
.text($.i18n('core-views/choose-match'))
|
||||||
@ -125,18 +146,19 @@ DataTableCellUI.prototype._render = function() {
|
|||||||
var candidates = r.c;
|
var candidates = r.c;
|
||||||
var renderCandidate = function(candidate, index) {
|
var renderCandidate = function(candidate, index) {
|
||||||
var li = $('<div></div>').addClass("data-table-recon-candidate").appendTo(ul);
|
var li = $('<div></div>').addClass("data-table-recon-candidate").appendTo(ul);
|
||||||
|
var liSpan = $('<span></span>').appendTo(li);
|
||||||
|
|
||||||
$('<a href="javascript:{}"> </a>')
|
$('<a href="javascript:{}"> </a>')
|
||||||
.addClass("data-table-recon-match-similar")
|
.addClass("data-table-recon-match-similar")
|
||||||
.attr("title", $.i18n('core-views/match-all-cells'))
|
.attr("title", $.i18n('core-views/match-all-cells'))
|
||||||
.appendTo(li).click(function(evt) {
|
.appendTo(liSpan).click(function(evt) {
|
||||||
self._doMatchTopicToSimilarCells(candidate);
|
self._doMatchTopicToSimilarCells(candidate);
|
||||||
});
|
});
|
||||||
|
|
||||||
$('<a href="javascript:{}"> </a>')
|
$('<a href="javascript:{}"> </a>')
|
||||||
.addClass("data-table-recon-match")
|
.addClass("data-table-recon-match")
|
||||||
.attr("title", $.i18n('core-views/match-this-cell') )
|
.attr("title", $.i18n('core-views/match-this-cell') )
|
||||||
.appendTo(li).click(function(evt) {
|
.appendTo(liSpan).click(function(evt) {
|
||||||
self._doMatchTopicToOneCell(candidate);
|
self._doMatchTopicToOneCell(candidate);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -144,26 +166,13 @@ DataTableCellUI.prototype._render = function() {
|
|||||||
.addClass("data-table-recon-topic")
|
.addClass("data-table-recon-topic")
|
||||||
.attr("target", "_blank")
|
.attr("target", "_blank")
|
||||||
.text(_.unescape(candidate.name)) // TODO: only use of _.unescape - consolidate
|
.text(_.unescape(candidate.name)) // TODO: only use of _.unescape - consolidate
|
||||||
.appendTo(li);
|
.appendTo(liSpan);
|
||||||
|
|
||||||
if ((service) && (service.view) && (service.view.url)) {
|
if ((service) && (service.view) && (service.view.url)) {
|
||||||
a.attr("href", encodeURI(service.view.url.replace("{{id}}", candidate.id)));
|
a.attr("href", encodeURI(service.view.url.replace("{{id}}", candidate.id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
var preview = null;
|
self._previewOnHover(service, candidate, liSpan.parent(), liSpan, true);
|
||||||
if ((service) && (service.preview)) {
|
|
||||||
preview = service.preview;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (preview) {
|
|
||||||
a.click(function(evt) {
|
|
||||||
if (!evt.metaKey && !evt.ctrlKey) {
|
|
||||||
self._previewCandidateTopic(candidate, this, preview);
|
|
||||||
evt.preventDefault();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var score;
|
var score;
|
||||||
if (candidate.score < 1) {
|
if (candidate.score < 1) {
|
||||||
@ -171,7 +180,7 @@ DataTableCellUI.prototype._render = function() {
|
|||||||
} else {
|
} else {
|
||||||
score = Math.round(candidate.score);
|
score = Math.round(candidate.score);
|
||||||
}
|
}
|
||||||
$('<span></span>').addClass("data-table-recon-score").text("(" + score + ")").appendTo(li);
|
$('<span></span>').addClass("data-table-recon-score").text("(" + score + ")").appendTo(liSpan);
|
||||||
};
|
};
|
||||||
|
|
||||||
for (var i = 0; i < candidates.length; i++) {
|
for (var i = 0; i < candidates.length; i++) {
|
||||||
@ -431,24 +440,18 @@ DataTableCellUI.prototype._postProcessSeveralCells = function(command, params, b
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO delete this
|
DataTableCellUI.prototype._previewCandidateTopic = function(candidate, elmt, preview, showActions) {
|
||||||
DataTableCellUI.internalPreview = {
|
|
||||||
srchurl: 'https://www.googleapis.com/freebase/v1/search?filter=(all mid:${id})'
|
|
||||||
+ '&output=(notable:/client/summary (description citation provenance) type)'
|
|
||||||
+ '&key='+CustomSuggest.FREEBASE_API_KEY+'&callback=?',
|
|
||||||
imgurl : 'https://www.googleapis.com/freebase/v1/image${id}?maxwidth=75&errorid=/freebase/no_image_png&key='+CustomSuggest.FREEBASE_API_KEY,
|
|
||||||
width: 430,
|
|
||||||
height: 300
|
|
||||||
};
|
|
||||||
|
|
||||||
DataTableCellUI.prototype._previewCandidateTopic = function(candidate, elmt, preview) {
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var id = candidate.id;
|
var id = candidate.id;
|
||||||
var fakeMenu = MenuSystem.createMenu();
|
var fakeMenu = $('<div></div>')
|
||||||
|
.addClass("menu-container");
|
||||||
fakeMenu
|
fakeMenu
|
||||||
.width(preview.width?preview.width:414)
|
.width(preview.width?preview.width:414)
|
||||||
.addClass('data-table-topic-popup')
|
.addClass('data-table-topic-popup');
|
||||||
.html(DOM.loadHTML("core", "scripts/views/data-table/cell-recon-preview-popup-header.html"));
|
if (showActions) {
|
||||||
|
fakeMenu
|
||||||
|
.html(DOM.loadHTML("core", "scripts/views/data-table/cell-recon-preview-popup-header.html"));
|
||||||
|
}
|
||||||
|
|
||||||
if (preview && preview.url) { // Service has a preview URL associated with it
|
if (preview && preview.url) { // Service has a preview URL associated with it
|
||||||
var url = encodeURI(preview.url.replace("{{id}}", id));
|
var url = encodeURI(preview.url.replace("{{id}}", id));
|
||||||
@ -457,37 +460,63 @@ DataTableCellUI.prototype._previewCandidateTopic = function(candidate, elmt, pre
|
|||||||
.height(preview.height)
|
.height(preview.height)
|
||||||
.attr("src", url)
|
.attr("src", url)
|
||||||
.appendTo(fakeMenu);
|
.appendTo(fakeMenu);
|
||||||
} else { // Otherwise use our internal preview
|
} else {
|
||||||
var url = encodeURI(DataTableCellUI.internalPreview.srchurl.replace("\${id}", id));
|
return; // no preview service available
|
||||||
$.ajax(url,{dataType:"jsonp"}).done(function(searchResponse) {
|
|
||||||
var data = searchResponse.result[0];
|
|
||||||
var html = $.suggest.suggest.create_flyout(data, preview.imgurl);
|
|
||||||
var container = $('<div></div>').css({fontSize:16}); // Suggest assumes this as a base font size
|
|
||||||
container.append(html);
|
|
||||||
fakeMenu.append(container);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuSystem.showMenu(fakeMenu, function(){});
|
|
||||||
MenuSystem.positionMenuLeftRight(fakeMenu, $(elmt));
|
MenuSystem.positionMenuLeftRight(fakeMenu, $(elmt));
|
||||||
|
fakeMenu.appendTo(elmt);
|
||||||
|
|
||||||
var elmts = DOM.bind(fakeMenu);
|
var dismissMenu = function() {
|
||||||
|
fakeMenu.remove();
|
||||||
elmts.matchButton.html($.i18n('core-views/match-cell'));
|
fakeMenu.unbind();
|
||||||
elmts.matchSimilarButton.html($.i18n('core-views/match-identical'));
|
};
|
||||||
elmts.cancelButton.html($.i18n('core-buttons/cancel'));
|
|
||||||
|
if (showActions) {
|
||||||
elmts.matchButton.click(function() {
|
var elmts = DOM.bind(fakeMenu);
|
||||||
self._doMatchTopicToOneCell(candidate);
|
|
||||||
MenuSystem.dismissAll();
|
elmts.matchButton.html($.i18n('core-views/match-cell'));
|
||||||
});
|
elmts.matchSimilarButton.html($.i18n('core-views/match-identical'));
|
||||||
elmts.matchSimilarButton.click(function() {
|
elmts.cancelButton.html($.i18n('core-buttons/cancel'));
|
||||||
self._doMatchTopicToSimilarCells(candidate);
|
|
||||||
MenuSystem.dismissAll();
|
elmts.matchButton.click(function() {
|
||||||
});
|
self._doMatchTopicToOneCell(candidate);
|
||||||
elmts.cancelButton.click(function() {
|
dismissMenu();
|
||||||
MenuSystem.dismissAll();
|
});
|
||||||
});
|
elmts.matchSimilarButton.click(function() {
|
||||||
|
self._doMatchTopicToSimilarCells(candidate);
|
||||||
|
dismissMenu();
|
||||||
|
});
|
||||||
|
elmts.cancelButton.click(function() {
|
||||||
|
dismissMenu();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return dismissMenu;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up a preview widget to appear when hovering the given DOM element.
|
||||||
|
*/
|
||||||
|
DataTableCellUI.prototype._previewOnHover = function(service, candidate, hoverElement, coreElement, showActions) {
|
||||||
|
var self = this;
|
||||||
|
var preview = null;
|
||||||
|
if ((service) && (service.preview)) {
|
||||||
|
preview = service.preview;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preview) {
|
||||||
|
var dismissCallback = null;
|
||||||
|
hoverElement.hover(function(evt) {
|
||||||
|
if (!evt.metaKey && !evt.ctrlKey) {
|
||||||
|
dismissCallback = self._previewCandidateTopic(candidate, coreElement, preview, showActions);
|
||||||
|
evt.preventDefault();
|
||||||
|
}
|
||||||
|
}, function(evt) {
|
||||||
|
if(dismissCallback !== null) {
|
||||||
|
dismissCallback();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
DataTableCellUI.prototype._startEdit = function(elmt) {
|
DataTableCellUI.prototype._startEdit = function(elmt) {
|
||||||
|
@ -298,6 +298,13 @@ a.data-table-flag-off {
|
|||||||
padding: @padding_tight;
|
padding: @padding_tight;
|
||||||
.rounded_corners();
|
.rounded_corners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.data-table-topic-popup {
|
||||||
|
z-index: 1010;
|
||||||
|
position: fixed;
|
||||||
|
line-height: 1;
|
||||||
|
white-space: initial;
|
||||||
|
}
|
||||||
|
|
||||||
.data-table-topic-popup-header {
|
.data-table-topic-popup-header {
|
||||||
padding: 0 0 5px;
|
padding: 0 0 5px;
|
||||||
@ -353,4 +360,4 @@ ul.sorting-dialog-blank-error-positions > li {
|
|||||||
margin: 2px;
|
margin: 2px;
|
||||||
cursor: move;
|
cursor: move;
|
||||||
.rounded_corners(3px);
|
.rounded_corners(3px);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user