Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds the service logo to column header and while schema building #6156

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 57 additions & 6 deletions extensions/wikibase/module/scripts/schema-alignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,27 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/

function serviceLogoFromReconConfig(reconConfig){
var serviceUrl = null;
var service = null;
var serviceLogo=null;
if (reconConfig) {
serviceUrl =reconConfig.service;
}
if (serviceUrl) {
service = ReconciliationManager.getServiceFromUrl(serviceUrl);
}
if (service) {
serviceLogo=service.logo;
}
try {
return new URL(serviceLogo);
}
catch {
console.warn("Invalid logo URL supplied by service "+serviceUrl)
}

};
var SchemaAlignment = {
_isSetUp: false
};
Expand Down Expand Up @@ -246,7 +266,7 @@ SchemaAlignment.updateColumns = function() {
// TODO we could potentially ignore any reconciliation to a siteIRI not
// mentioned in the manifest…
var cell = SchemaAlignment._createDraggableColumn(column.name,
reconConfig && column.reconStats ? reconConfig.identifierSpace : null);
reconConfig && column.reconStats ? reconConfig.identifierSpace : null, reconConfig);
this._columnArea.append(cell);
}

Expand Down Expand Up @@ -433,8 +453,19 @@ SchemaAlignment._changesCleared = function() {
.addClass('disabled');
};

SchemaAlignment._createDraggableColumn = function(name, reconciledSiteIRI) {
SchemaAlignment._createDraggableColumn = function(name, reconciledSiteIRI, reconConfig) {
var logo=serviceLogoFromReconConfig(reconConfig);
var cell = $("<div></div>").addClass('wbs-draggable-column').text(name);
if(logo) {
var img =$("<img>");
if(serviceLogo) {
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if block is probably redundant with the outer one, and seems to refer to an undeclared variable.

var imageUrl = serviceLogo;
img.attr("src", imageUrl);
img.attr("title", service.name);
img.addClass("serviceLogo-for-schema")
}
cell.append(img);
}
cell.data({
'columnName': name,
'reconciledSiteIRI': reconciledSiteIRI
Expand Down Expand Up @@ -1467,13 +1498,26 @@ SchemaAlignment._initField = function(inputContainer, mode, initialValue, change
}

var acceptDraggableColumn = function(column) {
var Logo=serviceLogoFromReconConfig(reconConfig);
var img =$("<img>");
if(Logo ){
var imageUrl = serviceLogo;
img.attr("src", imageUrl);
img.attr("title", service.name);
img.addClass("serviceLogo-for-schema")

};

input.hide();
input.val("");
var columnDiv = $('<div></div>').appendTo(inputContainer);
column.appendTo(columnDiv);
//columnDiv.append(img);
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commented out code can probably be removed, no?


var origText = column.text();
column.text("");
column.append($('<div></div>').addClass('wbs-restricted-column-name').text(origText));
column.append($('<div></div>').addClass('wbs-restricted-column-name').text(origText).append(img));

var deleteButton = SchemaAlignment._makeDeleteButton(true).appendTo(column);
deleteButton.attr('alt', $.i18n('wikibase-schema/remove-column'));
deleteButton.on('click',function (e) {
Expand Down Expand Up @@ -1538,13 +1582,20 @@ SchemaAlignment._initField = function(inputContainer, mode, initialValue, change

// Init with the provided initial value.
if (initialValue) {
var columns = theProject.columnModel.columns;
var reconConfig=null;
for (var i = 0; i < columns.length; i++) {
if(columns[i].name===initialValue.columnName){
reconConfig = columns[i].reconConfig;
}
}
if (initialValue.type === "wbentityidvalueconstant" ||
/* item for backwards-compatibility purposes */
initialValue.type === "wbitemconstant" || initialValue.type === "wbpropconstant") {
input.val(initialValue.label);
input.addClass("wbs-validated-input");
} else if (initialValue.type == "wbentityvariable") {
var cell = SchemaAlignment._createDraggableColumn(initialValue.columnName, true);
var cell = SchemaAlignment._createDraggableColumn(initialValue.columnName, true, reconConfig);
acceptDraggableColumn(cell);
} else if (initialValue.type === "wbstringconstant" ||
initialValue.type === "wbdateconstant" ||
Expand All @@ -1557,7 +1608,7 @@ SchemaAlignment._initField = function(inputContainer, mode, initialValue, change
initialValue.type === "wbdatevariable" ||
initialValue.type === "wblocationvariable" ||
initialValue.type === "wblanguagevariable") {
var cell = SchemaAlignment._createDraggableColumn(initialValue.columnName, false);
var cell = SchemaAlignment._createDraggableColumn(initialValue.columnName, false, reconConfig );
acceptDraggableColumn(cell);
}
inputContainer.data("jsonValue", initialValue);
Expand Down
6 changes: 6 additions & 0 deletions extensions/wikibase/module/styles/schema-alignment.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
max-width: 70em;
}

.serviceLogo-for-schema{
float: left !important;
width:19px;
height:20px;
}

.main-view-panel-tab-header {
margin-top: 9px;
margin-left: 7px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,35 @@ DataTableColumnHeaderUI.prototype._render = function() {
elmts.dropdownMenu.on('click',function() {
self._createMenuForColumnHeader(this);
});


var serviceUrl = null;
var service = null;
var serviceLogo=null;
if (this._column.reconConfig) {
serviceUrl =this._column.reconConfig.service;
}
try {

if (new URL(serviceUrl)) {
service = ReconciliationManager.getServiceFromUrl(serviceUrl);
ayushrai206 marked this conversation as resolved.
Show resolved Hide resolved
}
if(service) {
serviceLogo=service.logo;
}

var img =$("<img>");
if(serviceLogo) {
var imageUrl = serviceLogo;
img.attr("src", imageUrl);
img.attr("title", service.name);
img.addClass("serviceLogo")
img.appendTo(elmts.serviceLogoContainer.show());
}
}
catch {
console.log("The URL is not valid");
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those logging statements could be more useful with a more explicit error message. When you are looking at the code here, it is clear that this logging statement refers to a recon service URL, but imagine what happens when just seeing this message in the console, in the middle of other unrelated statements: the current error message does not give a lot of information, as we have no idea which URL is referred to.

Once the try { } catch { } block is part of the new function suggested above, this logging statement will be about the validity of the logo URL, hence we could instead have something like console.warn("Invalid logo URL supplied by service "+serviceUrl) or something like that.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this problem is still there, no? Or do you see it resolved in another way?

}

if ("reconStats" in this._column) {
var stats = this._column.reconStats;
if (stats.nonBlanks > 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
<div class="column-header-title"><button class="column-header-menu" bind="dropdownMenu"></button><span class="column-header-name" bind="nameContainer"></span></div>
<div style="display:none;" bind="reconStatsContainer"></div>
<div class="container-of-logo-and-statsbar">
<div style="display: none; grid-column:1" bind="serviceLogoContainer" ></div>
<div style="display: none; grid-column:2" bind="reconStatsContainer"></div>
</div>
15 changes: 13 additions & 2 deletions main/webapp/modules/core/styles/views/data-table-view.css
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,25 @@ table.data-table td.column-header, table.data-table th.column-header {
background-position: -17px 0px;
}

.container-of-logo-and-statsbar {
display: grid;
grid-template-columns: max-content auto;
width:100%;
}

.column-header-recon-stats-bar {
margin-top: 10px;
height: 4px;
margin-top:4px;
height: 6px;
background: #ddd;
border: 1px solid #ccc;
position: relative;
width: 100%;
}

.serviceLogo {
width: 19px;
height: 21px;
}

.column-header-recon-stats-matched {
position: absolute;
Expand Down