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

add referencePreview feature #140

Merged
merged 8 commits into from
Jan 19, 2018
Merged

add referencePreview feature #140

merged 8 commits into from
Jan 19, 2018

Conversation

Kiailandi
Copy link
Collaborator

This PR will add a new feature to the PST.

The referencePreview feature will enable the user to preview (and to approve or reject) a reference without opening it in another tab.

image

If the reference is fetched from a dataset that makes its corpus available (e.g. StrepHit) the corpus itself will be used to create a preview.

image

If the corpus is not available (e.g. Freebase) a generic scraper will be used to create a "best effort" preview.

image

In the preview the item label, the property label and the value will be highlighted (yellow marker in the previous image) through text search.

- fix a bug where all urls would be concatenated as a common url
- fix a visual bug where the preview button would be cut in case of short urls
- refactor the code used to append the preview button into a general function
@sjoerddebruin
Copy link
Member

Can the button be more subtile? It's quite prominent now for such a feature.

@Kiailandi
Copy link
Collaborator Author

Yes, it can. I will try a different style in the next few days 😃

@marfox
Copy link
Member

marfox commented Dec 4, 2017

@sjoerddebruin , maybe you can give an example of what you mean with subtile ?

@sjoerddebruin
Copy link
Member

A black button seems very off with the rest of the Wikidata user interface.

@Kiailandi
Copy link
Collaborator Author

image

I used white as a background and copied the hex of the other elements as color.

Copy link
Collaborator

@Tpt Tpt left a comment

Choose a reason for hiding this comment

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

Thank you very much for this change. Here are some comments related mostly on how to improve the implementation.

PS: There is also a conflict with the current master version. May you do a rebase?


var async = module.exports;
var ps = mw.ps || {};
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure that having a such global is needed. You could just declare the openNav and closeNav functions inside of the main PrimarySources closure and call them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I initially put the functions in the closure, as you suggested. The problem is that they are called from an onClick of a button, and they are not visible from outside of the closure. If you have any suggestion on how to fix this I could remove the global object.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see. Instead of building the HTML from a string and on* attributes you could maybe build it using jQuery or something similar, allowing you to call functions declared in the closure. Eg.

$('<div>').attr('id', 'myNav').addClass('overlay')
   .append(
             $('<a>').addClass('closebtn).click(closeNav),
             $('<div>').attr('id', "blackboard").addClass("overlay-content")
  );

It's probably even going to make more sense if you use OOjs UI.

type: 'GET',
url: 'https://tools.wmflabs.org/strephit/search?url=' + encodeURI(referenceURL),
success: function(msg) {
$('.loader').remove();
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could use the OOjs UI progress bar to fit more into MediaWiki UI and to avoid to have to write extra code https://doc.wikimedia.org/oojs-ui/master/js/#!/api/OO.ui.ProgressBarWidget

Copy link
Collaborator Author

@Kiailandi Kiailandi Dec 4, 2017

Choose a reason for hiding this comment

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

The loader is pure css and it is not related to "real" progress, it is just used to signal the user that the tool is not blocked but it is waiting for the backend.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok! If you do not set specific progress level OO.ui.ProgressBarWidget is going to be in "indeterminate" state and display a visual motion.

var item = data[index];
if(index != 'url' && item !== null){
if( index == 'other' ) {
while(typeof item == 'string'){
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems quite dangerous (but it's maybe what should be done)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can see your point, but atm I'm not able to provide a better solution for this, as I don't have a consistent format for the data I get from the api.

@@ -34,9 +34,9 @@
*/

$(function() {
'use strict';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you have a good reason to drop the "use strict" option?

Copy link
Collaborator Author

@Kiailandi Kiailandi Dec 4, 2017

Choose a reason for hiding this comment

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

We dropped it in this commit, if you remember, as a temporary fix for the tool. I also think that this is the source of the conflict as it is a duplicate commit.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, thank you! Sorry, for not remembering.

}
}
}
else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This file seems to use the K&R coding style. Example:

if(foo) {
   bar;
} else {
   baz;
}

It's not important but it's better for consistency.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will fix this

ps.openNav = function openNav(itemLabel, propertyLabel, propertyValue, referenceURL, buttons) {
$('#myNav').width('100%');

var blackboard = $('#blackboard');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of building your own window system you could maybe rely on https://doc.wikimedia.org/oojs-ui/master/js/#!/api/OO.ui.ProcessDialog that seems to fit quite well this use case.

PrimarySources is already using it for the PrimarySources list feature and there is already a windowManager created at the end of this file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a great suggestion. I used a simple div as a window system as it seemed the fastest and easiest way to me. I will try to look into the OO.ui library.

@marfox marfox merged commit 40a9666 into Wikidata:master Jan 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants