[PATCH 2 of 3 saem_ref v3] Use JQTree to display Concepts in ConceptScheme tab view

Frank Bessou frank.bessou at logilab.fr
Wed Oct 3 14:56:37 CEST 2018




On 02/10/2018 09:47, Denis Laxalde wrote:
> Frank Bessou a écrit :
>>
>> On 28/09/2018 18:16, Denis Laxalde wrote:
>>> Frank Bessou a écrit :
>>>> # HG changeset patch
>>>> # User Frank Bessou <frank.bessou at logilab.fr>
>>>> # Date 1538042688 -7200
>>>> #      Thu Sep 27 12:04:48 2018 +0200
>>>> # Node ID f38adb440019343932d45288aeaa7d90d5cdb428
>>>> # Parent  72e97e0e43537623076c7d8c6b24a98a68f7724c
>>>> # Available At http://hg.logilab.org/review/cubes/saem_ref
>>>> #              hg pull http://hg.logilab.org/review/cubes/saem_ref -r
>>>> f38adb440019
>>>> Use JQTree to display Concepts in ConceptScheme tab view
>>>>
>>>> We extend the ConceptSchemeConceptsTab to use the jqtree.tree view and
>>>> we disable the base class.
>>>>
>>>> The render_tree method is added in an unreleased version of
>>>> cubicweb-skos.
>>>>
>>>> diff --git a/cubicweb_saem_ref/views/__init__.py
>>>> b/cubicweb_saem_ref/views/__init__.py
>>>> --- a/cubicweb_saem_ref/views/__init__.py
>>>> +++ b/cubicweb_saem_ref/views/__init__.py
>>>> @@ -41,6 +41,7 @@ from cubicweb.web.views import (
>>>>      from cubes.squareui.views.basetemplates import basetemplates
>>>>    from cubicweb_seda.views import dropdown_button, has_rel_perm,
>>>> widgets as sedawidgets
>>>> +import cubicweb_skos.views as skos_views
>>>>      from .. import cwuri_url
>>>>    @@ -475,6 +476,16 @@ class RestPathEvaluator(urlpublishing.Re
>>>>            return super(RestPathEvaluator, self).set_vid_for_rset(req,
>>>> cls, rset)
>>>>      +class
>>>> ConceptSchemeConceptsTab(skos_views.ConceptSchemeConceptsTab):
>>>> +    """display a SKOS concept scheme tree"""
>>>> +    __regid__ = 'skos_top_concepts_tab'  # don't use '.' in tab's regid
>>>> +    __select__ = is_instance('ConceptScheme')
>>>> +
>>>> +    def render_tree(self, entity, children_rset):
>>>> +        self._cw.add_js('cubes.saem_ref.js')
>>>
>>> The add_js does not work because, as far as I understand, the page is
>>> already loaded where this statement is executed (i.e. when the tab is
>>> selected). Not sure this is the actual problem, but this does not work
>>> for me...
>>>
>>
>> The js is actually executed when the tab is loaded. This is handled in
>> cubicweb.ajax.js . I don't know why this isn't working on your instance
>> but I will send a new version which move this code to skos.py.
> 
> I don't understand your answer. I'm saying that there is no <script> tag
> with "cubes.saem_ref.js" file on my side, hence the code from this file
> ("canMoveTo" function) fails to execute (I get a TypeError in browser
> console).
> 
> My explanation (I might be wrong) is that the headers list is generated
> and outputted in HTML page *before* tab's code is executed, hence
> self._cw.add_js() call is a no-op.
> 


In the _call_view method of AjaxController, tags that would normally be
serialized in head section are serialized this way:

extresources = self._cw.html_headers.getvalue(skiphead=True)
if extresources:
     stream.write(u'<div class="ajaxHtmlHead">\n') # XXX use a widget?
     stream.write(extresources)
     stream.write(u'</div>\n')

The skiphead argument to the getvalue method makes the script tags
serialized as a 'cubicweb:script' tag:

if skiphead:
     # Don't insert <script> tags directly as they would be
     # interpreted directly by some browsers (e.g. IE).
     # Use <cubicweb:script> tags instead and let
     # `loadAjaxHtmlHead` handle the script insertion / execution.
     w(u'<cubicweb:script src="%s"></cubicweb:script>\n' %
       xml_escape(jsfile))

These tags are then handled in cubicweb/web/data/cubicweb.ajax.js in
_loadAjaxScripts which use $.ajax({..., script:true}) to load the script
and execute it.

>>
>>> Also, can you move this class in skos.py file? >
>>>> +        entity.view('jqtree.treeview', w=self.w)
>>>> +
>>>> +
>>>>    def registration_callback(vreg):
>>>>        from cubicweb.web.views import actions, cwuser, tableview,
>>>> undohistory
>>>>        vreg.register_all(globals().values(), __name__, (
>>>> @@ -482,11 +493,13 @@ def registration_callback(vreg):
>>>>            SAEMHTMLPageFooter,
>>>>            SAEMNoResultView,
>>>>            URLAttributeView,
>>>> +        ConceptSchemeConceptsTab,
>>>>        ))
>>>>        vreg.register_and_replace(RestPathEvaluator,
>>>> urlpublishing.RestPathEvaluator)
>>>>        vreg.register_and_replace(URLAttributeView,
>>>> primary.URLAttributeView)
>>>>        vreg.register_and_replace(SAEMHTMLPageFooter,
>>>> basetemplates.HTMLPageFooter)
>>>>        vreg.register_and_replace(SAEMNoResultView,
>>>> baseviews.NoResultView)
>>>> +    vreg.register_and_replace(ConceptSchemeConceptsTab,
>>>> skos_views.ConceptSchemeConceptsTab)
>>>>        vreg.unregister(tableview.TableView)
>>>>        vreg.unregister(undohistory.UndoHistoryView)
>>>>        vreg.unregister(basecomponents.ApplicationName)
>>>> diff --git a/dev-requirements.txt b/dev-requirements.txt
>>>
>>
> 

-- 
Frank Bessou
Logilab         https://www.logilab.fr



More information about the saem-devel mailing list