Show reconciliation previews on hover of reconciliation candidates and matches.

Closes #1943.
This commit is contained in:
Antonin Delpeuch 2019-02-19 16:46:24 +00:00
parent fea1efba41
commit c509dd3847
2 changed files with 55 additions and 43 deletions

View File

@ -108,6 +108,8 @@ 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)));
} }
self._previewOnHover(service, match, a);
$('<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 +127,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:{}">&nbsp;</a>') $('<a href="javascript:{}">&nbsp;</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:{}">&nbsp;</a>') $('<a href="javascript:{}">&nbsp;</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 +147,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);
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 +161,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++) {
@ -428,20 +418,11 @@ DataTableCellUI.prototype._postProcessSeveralCells = function(command, params, b
); );
}; };
// TODO delete this
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) { 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')
@ -454,19 +435,17 @@ 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 dismissMenu = function() {
fakeMenu.remove();
fakeMenu.unbind();
};
var elmts = DOM.bind(fakeMenu); var elmts = DOM.bind(fakeMenu);
@ -476,15 +455,41 @@ DataTableCellUI.prototype._previewCandidateTopic = function(candidate, elmt, pre
elmts.matchButton.click(function() { elmts.matchButton.click(function() {
self._doMatchTopicToOneCell(candidate); self._doMatchTopicToOneCell(candidate);
MenuSystem.dismissAll(); dismissMenu();
}); });
elmts.matchSimilarButton.click(function() { elmts.matchSimilarButton.click(function() {
self._doMatchTopicToSimilarCells(candidate); self._doMatchTopicToSimilarCells(candidate);
MenuSystem.dismissAll(); dismissMenu();
}); });
elmts.cancelButton.click(function() { elmts.cancelButton.click(function() {
MenuSystem.dismissAll(); dismissMenu();
}); });
return dismissMenu;
};
/**
* Sets up a preview widget to appear when hovering the given DOM element.
*/
DataTableCellUI.prototype._previewOnHover = function(service, candidate, element) {
var self = this;
var preview = null;
if ((service) && (service.preview)) {
preview = service.preview;
}
if (preview) {
var dismissCallback = null;
element.hover(function(evt) {
if (!evt.metaKey && !evt.ctrlKey) {
dismissCallback = self._previewCandidateTopic(candidate, this, preview);
evt.preventDefault();
}
}, function(evt) {
if(dismissCallback !== null) {
dismissCallback();
}
});
}
}; };
DataTableCellUI.prototype._startEdit = function(elmt) { DataTableCellUI.prototype._startEdit = function(elmt) {

View File

@ -299,6 +299,13 @@ a.data-table-flag-off {
.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;
} }