Jump to:

10931 Posts in 2614 Topics by 1810 members

All other Modules

SilverStripe Forums » All other Modules » New Module: SortWeight - Easy Ordering of DataObjects & Relationships

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 2679 Views
  • brice
    Avatar
    Community Member
    51 Posts

    New Module: SortWeight - Easy Ordering of DataObjects & Relationships Link to this post

    I'd like to announce the availability of the SortWeight module. This extension makes ordering of DataObjects and ComponentSets easy and non-obtrusive. My goal is to get this [or something like it] into the an official silverstripe module -- as ordering is a feature we all want!

    This is the first release & needs testing. A Demo and preliminary TODO are up at the project page:

    http://code.google.com/p/silverstripe-briceburg/

    Main highlights are:

    # Supports ordering of components in has-many and many-many relationships
    # Supports ordering of the base DataObject? outside of relationships (e.g. controls DataObjectSet? item order of Dataobject::get('MyObject?'); calls)
    # Drag and Drop support (as well as buttons to move to top/bottom)
    # Transparently drops in to core Silverstripe -- automatically extends ComplexTableField?
    # Does not rely on DataObjectManager ( I consistently ran into issues when trying to limit sorted sets [http://silverstripe.org/dataobjectmanager-module-forum/show/7010?start=264#post293107])

    Please enjoy && let me know what needs fixing!

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: New Module: SortWeight - Easy Ordering of DataObjects & Relationships Link to this post

    Hey brice, good stuff!

    I've note you're mentioning potential core patches throughout the codebase - any chance you could extract those into tickets on open.silverstripe.org? Specifically providing more data hinting in CTF markup. CTF (and its parent classes) will most likely see an overhaul in 3.0 in the next year, but then again 2.4.x will be around for a while, so smaller improvements are always welcome!

    I see you're doing some pretty heavy query string parsing in augmentSQL() - how about unit testing that with a couple of query permutations?
    How about phpdoc class/method documentation to describe the purpose of your three classes?
    By the way, 2.4.3 has internal/relative URLs for jQuery-UI requirements again, in case you want to adapt your codebase.

  • Fuzz10
    Avatar
    Community Member
    787 Posts

    Re: New Module: SortWeight - Easy Ordering of DataObjects & Relationships Link to this post

    That looks awesome Brice ! Thanks for the hard work !

  • brice
    Avatar
    Community Member
    51 Posts

    Re: New Module: SortWeight - Easy Ordering of DataObjects & Relationships Link to this post

    Ingo,

    Thanks for looking over the module -- it means a lot to me!

    If you think things are looking decent I'll resume work on this and go the extra mile with unit tests and proper ticketed core patches that will optimize and take the "magic" out of the current auto-detection routines.

    Have been on a hiatus since the 21st && am looking forward to getting back in the saddle! I've been following open.silverstripe.org timeline closely during this break && am as ever excited about this project.

    In the next revision I hope to meet the remainder of todos, and have the module enhance DataObjectManager tables out-of-box (as it's quite popular and useful, but the sorting routine has caused much pain in way of bugs [http://silverstripe.org/dataobjectmanager-module-forum/show/7010?start=256#post292909]).

  • brice
    Avatar
    Community Member
    51 Posts

    Re: New Module: SortWeight - Easy Ordering of DataObjects & Relationships Link to this post

    I've drastically simplified this module & released a beta at GitHub.

    This version (0.1+) is safe for testing. Please use in your projects & send any feedback!

    Project Page: https://github.com/briceburg/silverstripe-sortweight

    I hope the re-factorings in this release prove to be worthwhile; as my aim is to bring the code up to a level of being officially supported.

  • Sequoia
    Avatar
    Community Member
    5 Posts

    Re: New Module: SortWeight - Easy Ordering of DataObjects & Relationships Link to this post

    Hi brice! Thanks for the module. Is there a demo of how to set it up or some examples? Iooked at the example in the _config but there's not much there so I may have got it wrong.

    <?php
    //EXAMPLE
    //SortWeightRegistry::decorate('Artist','Albums');
    //mine:
    SortWeightRegistry::decorate('Homepage','Headlines');

    //******************************************************//

    //in the Homepage class:
    static $has_many = array( 'Headlines' => 'Headline' );
    //from Homepage::getCMSFields
             $sng = singleton('Headline');
               $heaadlines = new ComplexTableField(
            $this,
            'Headlines',
            'Headline',
            $sng->stat('summary_fields'),
            'getCMSFields_forPopup'
               );
           $heaadlines->setAddTitle( 'A Headline' );

    I see a table Homepage_HeadlinesWeight in the DB but it's empty, and I'm not seeing anything on the CFT in the admin area. The site is on SS 2.4.1.

    Thanks for your help, I look forward to using this module!
    -Sequoia

  • brice
    Avatar
    Community Member
    51 Posts

    Re: New Module: SortWeight - Easy Ordering of DataObjects & Relationships Link to this post

    Hi Sequoia! Thanks for the report. The latest release of this module uses a shared version of jQuery UI that was added in 2.4.3. I believe this *contributes* to the issue as the JavaScript for sorting is not being called. That said; you should still see a SortWeight column on the ComplexTableField.

    The SortWeight module actually uses the updateSummaryFields() method in DataObjectDecorator to inject the SortWeight column into CTFs -- so if you explicitly pass SummaryFields to the ComplexTableField it will bypass this decoration. Interestingly enough your code is behaving properly and I will need to come up with a workaround for your situation... but for now please change;

    //from Homepage::getCMSFields
    $sng = singleton('Headline');
    $heaadlines = new ComplexTableField(
    $this,
    'Headlines',
    'Headline',
    $sng->stat('summary_fields'),
    'getCMSFields_forPopup'
    );
    $heaadlines->setAddTitle( 'A Headline' );

    TO:

    //from Homepage::getCMSFields
    $heaadlines = new ComplexTableField(
    $this,
    'Headlines',
    'Headline',
    null,
    'getCMSFields_forPopup'
    );
    $heaadlines->setAddTitle( 'A Headline' );

    Does this get you further along?

  • Sequoia
    Avatar
    Community Member
    5 Posts

    Re: New Module: SortWeight - Easy Ordering of DataObjects & Relationships Link to this post

    That did the trick!! Hmm... looks like with $summary_fields I don't need more than three arguments to the ComplexTableField constructor. Good to know! Drag/drop reordering works on 2.4.1.

    Thanks,
    Sequoia

    2679 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.