Hypertopic / LaSuli

Social annotation for qualitative analysis
https://hypertopic.org/lasuli
GNU General Public License v3.0
12 stars 4 forks source link

Highlight a text fragment with a given topic #47

Closed benel closed 5 years ago

benel commented 5 years ago

@franck Similarly to what was done in LaSuli v2, it should be done with a contextual menu (in the Web page) enabling to choose either an existing topic (with a color and a name) or a new one.

See the following screencast (from LaSuli v2): https://streamable.com/s/zi4xv/dhelkj

franck-eyraud commented 5 years ago

Web extensions allow to add a context menu for the extension : https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/user_interface/Context_menu_items

We can get an event on a click on a context menu with the when a text is selected, and get the value of the text. But, since this doesn't run in a content script, there is no link to the selected elements, so to get the position in the text. Is this information necessary ?

If yes, any idea how to get it ? Inject some hack in the content script, like adding a custom context menu, or get the selection at the time of the right-click in the page (because I'm not sure how to insert a context menu from a web page) ? How was this done in V2 ?

benel commented 5 years ago

How was this done in V2 ?

I'm afraid the problem is new: the separation between different execution contexts was a security and performance improvement introduced by WebExt (and before by the so called "SDK addons").

Check this resource for a comparison between XUL-XPCOM and WebExt on how to interact with Web content. What I understood is that you have to inject a JavaScript into the page and if you need to communicate directly with other parts of the extension, you have to use messages API.

benel commented 5 years ago

I don't know if you asked it for, but the API used in version 2 was the Selection class:

var selObj = window.getSelection();
var range  = selObj.getRangeAt(0);

However, as can be seen in the code of v2, converting this range to coordinates in the corresponding text is a bit tricky.

franck-eyraud commented 5 years ago

Thank you. Indeed, the old code will help to avoid rewriting things. Fortunately, it seems that everything can be done in the content scripts, including that. Just some communication is needed to fetch information.

I could implement a context menu on text selection (when a viewpoint is selected), and fetch the information for creating an highlight https://github.com/franck-eyraud/LaSuli/tree/highlight, now I need to figure out how to put it in hypertopic. I have a viewpoint (the active one), a topic (selected from the menu), but, I need an item, and there can be more than one I think ?

benel commented 5 years ago

From the page URI, you can get the corresponding item ID with /item/?resource=URI

Do it with the Hypertopic libary (getView method) so that you query all servers.

Notes:

benel commented 5 years ago

Case A: no items were found. Then create one on Argos in a special corpus (the user’s bookmarks).

Case B: at least one were found. With its ID, get the corresponding object at /ID in Argos (hypertopic.get method is onlu on the first server).

Case B1: err 404. You need to create an item with the same ID and corpus.

Case B2: 200 OK. Just update it to add an highlight colored with the right topic and viewpoint IDs.

franck-eyraud commented 5 years ago

Thank you for these hints.

create one on Argos in a special corpus (the user’s bookmarks). Where can I find these bookmarks ? Or is this a special name containing the username ?

Speaking of user, it seems that nothing can be created without being authenticated, is authentication a foreseen feature of the extension ?

Case B1: err 404. You need to create an item with the same ID and corpus. Is there some corpus available if there is no item ?

franck-eyraud commented 5 years ago

I realised that I push the wrong branch previously. I now force-updated the highlight branch with above commits, there is the UI with context menus, and the function to create the highlight, but lack of authentication makes it throw a 401 HTTP error.

benel commented 5 years ago

there is the UI with context menus, and the function to create the highligh

It sounds great. Thanks!

Speaking of user, it seems that nothing can be created without being authenticated, is authentication a foreseen feature of the extension ?

True. One option could for now be that I set up another Argos server with no authentication, another would be that I find time to adapt the "Authenticated" React component I made for Porphyry...

If I create the session directly in the sidebar, do you think it be accessible to your own update methods?

franck-eyraud commented 5 years ago

About the authentication, I did the following : changed argos server to the testing one (argos2.test....) for which I know the authentication, authenticated to it within the same browser through my Porphyry local installation, and as you suggested in another message, this authentication was forwarded by the LasuLi extension to the argos server, so I could test the highlight creation.

So probably, by just adding the adapted Authenticated component, it should do the job.

franck-eyraud commented 5 years ago

Adding to an existing topic is done in this branch Adding to a new topic requires #49, I suppose. Currently, after adding, the whole sidebar refreshes, and turns back to initial state, this is due to the way all data are loaded. Trying to understand what would be the way to do that better...

benel commented 5 years ago

Adding to a new topic requires #49, I suppose.

Contrary to the apparence, there is no error in the roadmap: #49 is about creating a topic in the sidebar (i.e. for a top-down analysis). On the contrary, highlighting a text fragment with a new topic (with a contextual menu) is for bottom-up analysis (i.e. you create a topic when you need it).

franck-eyraud commented 5 years ago

OK, I see. So we should ask for the new topic name though a simple browser's popup (prompt), or not ask a name at all and set a default one ?

benel commented 5 years ago

To mimic what was done in LaSuli v2, it would be a no-name topic which could be later renamed (one day in the future when feature #48 is implemented). Even with just a color, the feature is interesting (it is what scholars do everyday with stabilo highlighters).

franck-eyraud commented 5 years ago

Currently, after adding, the whole sidebar refreshes, and turns back to initial state, this is due to the way all data are loaded. Trying to understand what would be the way to do that better...

This should be now OK after adf15c2

highlighting a text fragment with a new topic

And this with 3841398