Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

New Module: SortWeight - Easy Ordering of DataObjects & Relationships


Go to End


12 Posts   5091 Views

Avatar
brice

Community Member, 52 Posts

21 November 2010 at 3:14pm

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!

Avatar
Ingo

Forum Moderator, 801 Posts

16 December 2010 at 10:23pm

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.

Avatar
Fuzz10

Community Member, 791 Posts

17 December 2010 at 12:11am

That looks awesome Brice ! Thanks for the hard work !

Avatar
brice

Community Member, 52 Posts

6 January 2011 at 6:02am

Edited: 06/01/2011 6:04am

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]).

Avatar
brice

Community Member, 52 Posts

15 February 2011 at 5:21pm

Edited: 17/02/2011 6:27am

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.

Avatar
Sequoia

Community Member, 5 Posts

24 February 2011 at 9:09am

Edited: 24/02/2011 9:10am

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

Avatar
brice

Community Member, 52 Posts

24 February 2011 at 4:02pm

Edited: 24/02/2011 4:02pm

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?

Avatar
Sequoia

Community Member, 5 Posts

25 February 2011 at 8:33am

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

Go to Top