Working on the port of taxonomy manager for Drupal 8, I realized that the module has the potential to be an excellent example (case study) to show how an "old" technical problem can be handled better with modern tools of today.
Taxonomy manager is a handy tool to do 2 things at the same time:
1) manage hierarchy between taxonomy terms
2) update taxonomy term items on the fly, in the same page
This is a handy way to manage hierarchy in general, because it's centralized and one can stay on 1 page to do everything necessary regarding a given taxonomy vocabulary. Having the terms on the left and their forms on the right seems to solve hierarchy management well in terms of UI. I base on this discussion.
However, I see also 2 important aspects that need to be improved:
- Lack of drag and drop.
- Hard to use with touch devices.
Maybe these are not so bad?
My personal feeling is that the power of taxonomy manager is in its interface as such. It deserves to be better, no?
The world of JavaScript has evolved from what we knew it when the initial version of the module was released. There are hundreds (maybe thousands) of JavaScript libraries, frameworks, etc. today. Also, the way people use the browser has changed: touch with drag and drop interaction is a standard, not just a cool thing.
So I'd like to present the idea of choosing a good library to handle these improvements as a next step in the evolution of the project. Taxonomy manager can be kick-ass with the new architecture of Drupal 8.
There are several important updates in core of Drupal 8, bringing new opportunities:
- OOP
- Easy way to implement 3rd party libraries
- REST API
- New jQuery and JS libraries in general
Having OOP means that instead of having 2 files with all functions, there are separate files with clear separation of logic, which could be independant from the data being managed. (MVC word could be mentioned)
Easier inclusion of 3rd parties. This can be done either by Libraries API, composer, bower, etc. - sharing and reusing JavaScript should be something normal, not something special today.
REST API in core means that all the methods which apply CRUD over taxonomy terms, could be actually handled on a higher level via services. SOA with REST over HTTP is easier to manage, because it's testable easier compared to simpletest (and it's faster btw). Rewriting older code is safer with TDD. Not to say it's obligatory, but could be super-awesome example of how Drupal is evolving to modern web too and it will be technically solid too in the long run.
So here are some first-off ideas for libraries which look good:
- https://github.com/mar10/fancytree
- https://www.jstree.com/
- http://www.igniteui.com/tree/drag-and-drop-single-tree
The perfect choice will be one with good documentation and API, active community and examples. And also, Drupal implementations if any. For example, I found this humble beginning of fancytree implementation in a Drupal 7 module: https://github.com/kehh/fancytree
I will be happy to hear opinions - feedback is really welcome!
Comment | File | Size | Author |
---|---|---|---|
#10 | tm add modal.png | 250.78 KB | mh86 |
Comments
Comment #2
kalinchernev CreditAttribution: kalinchernev as a volunteer commentedComment #3
mh86 CreditAttribution: mh86 at jobiqo - job board technology commentedI absolutely agree we should replace the custom javascript tree implementation with an external library. The current code originates from Drupal 5 (year 2007!) and hasn't changed that much till Drupal 7....
For choosing the right library I have some requirements in addition to API quality, active community, support and documentation:
Currently I don't have any favourite, from what I can see all your examples fulfil most requirements.
In the meanwhile I started to play a little bit with fancytree and will let you know about my findings.
Comment #4
mh86 CreditAttribution: mh86 at jobiqo - job board technology commentedI just pushed a commit to the 8.x branch that does 2 things:
When you now open the taxonomy manager for a certain vocabulary, you should get a dynamic tree with nested child terms (they are not loaded via ajax yet).
The form element should allows us to do further testing with the fancytree and other libraries.
Comment #5
mh86 CreditAttribution: mh86 as a volunteer and at jobiqo - job board technology commentedI've pushed another commit that test the lazy loading functionality via a JSON callback, works fine so far!
Comment #6
kalinchernev CreditAttribution: kalinchernev as a volunteer commentedIt's a great progress, @mh86! It's exactly what I meant!
I'll get acquainted with the updates, on first sight it seems to me that you have prepared the most important base!
Comment #7
mh86 CreditAttribution: mh86 as a volunteer and at jobiqo - job board technology commentedThanks :)
I've pushed some more updates:
The current implementation is mostly independent of the fancy tree library. I think it would be easy to test other libraries as well, most of them just differ in the JSON structure (also I was thinking about to just use JSON for generating the tree, instead of HTML lists at the beginning, and then the JSON callback for child terms - would make some code obsolete)
So far the fancy tree library has worked well, but this doesn't mean I made any decision on a library yet. Happy to hear your input on this topic.
Comment #8
kalinchernev CreditAttribution: kalinchernev as a volunteer commentedNice! :)
What do you think could be good next steps into testing this particular implementation? I.e. term operations, specific methods in the library, or something else?
Comment #9
mh86 CreditAttribution: mh86 as a volunteer and at jobiqo - job board technology commentedHi Kalin,
I've pushed another feature for the tree element that allows to expand the tree to a certain child term ('#terms_to_expand' property).
I think the tree element now has all features we need. Regarding the fancytree library, I suggest to stick to it as long as we find a good reason to not use it.
Regarding the next possible steps, in my opinion:
What do you think?
Comment #10
mh86 CreditAttribution: mh86 as a volunteer and at jobiqo - job board technology commentedHi Kalin,
I continued working on the add / delete operation. I used the new modal dialog AJAX API and I think it fits well for the operations.
Attached a screenshot on how it looks like.
Comment #11
kalinchernev CreditAttribution: kalinchernev as a volunteer commentedHi Matthias,
Sorry for not being able to follow up more frequently recently.
Yes, I briefly looked at the fancytree and seemed there a enough amount of methods to handle the CRUD. I think the way you have organized the communication via JSON-s will mean that the JS events from fancytree will be mapped to controller methods in Drupal with CRUD on a given term as you have already started a controller for the main tree. Maybe the move will be more specific, but the existing implementation of helpers in the module with the recursives in the weight and depth could be reused to make it simple.
Indeed, this seems to be "collapsible" element known today in many frameworks. Maybe the core will have some helper classes, I can check the back-end of the core to see some examples.
The modal looks great! :)
However, I've mis-migrated the function which takes care of second and deeper level terms. Only 1st level terms get correctly inserted. So there's need to improve this a bit.
Agree, the DND is nice to have, yet the update functionality is with priority.
This is another feature I'd research in core or symfony libraries. I wouldn't be surprised if we can reuse something new for this too. But it's also that composer is there, so theoretically 3-rd party helpers should be possible maybe.
I created a ticket for myself here https://www.drupal.org/node/2621210 so I will branch out from latest and try to help you with that.
Definitely.
Thanks so much for adopting the idea and progressing so well!
Comment #12
mh86 CreditAttribution: mh86 as a volunteer and at jobiqo - job board technology commentedHi Kalin,
thanks for the response :)
Would be great if we find some time on the DrupalCamp Vienna on Friday or Saturday to discuss/coordinate further tasks.
In the meanwhile I did some further cleanup and fixed the add operation (to assign the right parents). Maybe I also find some time to port the move operation and put it into a modal.
Comment #13
mh86 CreditAttribution: mh86 as a volunteer and at jobiqo - job board technology commentedMarking this issue as fixed, the fancytree library has been integrated. With the rest we'll continue at #2624396: [Meta] Drupal 8.0+ Roadmap and #2220299: Port to Drupal 8