TwelvestoneBack End

Ordering results - theory question


Sign in

  • Waiting for Godot ( 730 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 5.1 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.9 k posts )
    general front end design an...
  • Back End ( 9.7 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
scudsucker
 
2009-07-28

This is a theory question, not really a specific issue.

Lets say i build a gallery for a site. Pics are added by the client. They add them all and then request a different order.

Now I can order easily by date ASC or DESC, or by primary key ASC/DESC, but often this is not what they want, they want to swap pic 7 with pic 4 and move pic 3 to pic 10

There are only two ways I can think of at the moment:

a) Add a column that allows the client to enter the order (1, 2, 3 etc). This is fine, except that every update to this column must update every row (eg, I set pic 7 to order number 4, I'll need to set all of the other columns so that they do not have any duplicate rows), I suppose, using a trigger.

b) Give only a "weighting" - each image can be ranked from 10 to -10 with 10 getting it higher up in the list and -10 pushing it down the list. Obviously this would means a certain amount of jockey-ing for clients who want a specific order.

So what is the best solution for this problem?

DontBogartMe
 
2009-07-28

linked list

scudsucker
 
2009-07-28

Not really - that will make the data entry (which is up to the client to do) complicated.

He'd have to upload pic A, then upload pic B, and set A as B's reference.

He then uploads C, D and E - and then decides that the order should be ACDBE

He'd have to edit all of them to set the reference.

Clients are notoriously stupid - I have to make this really really easy, (preferably for me to code as well!)

Best case I can think of is a linked list/order type scenario with an AJAX interface that allows drag-drop of the images into a specific order, which is saved accordingly.

DontBogartMe
 
2009-07-28

you'd write the code that handles adding things to the linked list. Look up linked lists, I think it's what you need really.

Sorry for cutting it short, not got time to get into this!

scudsucker
 
2009-07-28

I do agree with a linked list as the display mechanism - but that does not make for a simple UI (nor simple storage)

I think I'll have to bite the bullet and do more work on UI.

poliguin
 
2009-07-28

Sort column is easy on the backend, the trick is implementing UI so that it is a) user friendly and b) idiot proof (as it can be)

Having drag drop UI: Eg: img[0] - Sort=1 img[1] - Sort=2 img[2] - Sort=3

drag C above a, UI code knows to change to: img[0] - Sort=2 img[1] - Sort=3 img[2] - Sort=1

And when you click save you do have to save out for all by default, but lets say you have this in your client script:

var imageList = { imageList : [ { id:123, path:"someString", currentSort:1, newSort:0 }, { id:321, path:"somOtherString", currentSort:2, newSort:0 }, { id:555, path:"somOtherString", currentSort:3, newSort:0 } ] }

Loop through the JSON object and build your list, naturally according to sort and when you move an item around update the newSort field (leaving current sort for a check on allowing for "restore")

Now, when you save, that can be simple, transform your object to an xml string that you parse on the backend and only update if your newSort != 0. eg:

test var serializeObject = { toXML : function(obj, nodeName) { var XML = new Array();
XML.push('<' + nodeName + '>'); //Reflect for(var x in obj) { if(!(obj[x] instanceof Function)) { switch(true) { case (obj[x] instanceof Array): if(obj[x].length > 0) { XML.push('<' + x + 's>'); for(var i=0; i'); } else { XML.push('<' + x + 's />'); } break; case (obj[x] instanceof Object) && x.toLowerCase() != 'parent': XML.push(this.toXML(obj[x], x)); break default: switch(true) { case String(obj[x]).length > 0: XML.push('<' + x + '>' + this.HTMLEncode(unescape(obj[x])) + '</' + x + '>') break; default: XML.push('<' + x + ' />'); break; } } } } XML.push('</' + nodeName + '>'); return XML.join(''); }, HTMLEncode : function(s) { var t = s.toString(); var h = new Array("&","\"","<",">"); var e = new Array("&",""","<",">") for(var i = 0; i < h.length; i ++) { t = t.replace(eval('/' + h[i] + '/gi'), e[i]); } return t; }, sendData : function(fieldId, object, rootNodeName) { document.getElementById(fieldId).value = this.toXML(object, rootNodeName); } }; var imageList = { imageList : [ { id:123, path:"someString", currentSort:1, newSort:0 }, { id:321, path:"somOtherString", currentSort:2, newSort:0 }, { id:555, path:"somOtherString", currentSort:3, newSort:0 } ] }

and in the end you have a simple structure to traverse:

123 someString 1 0 321 somOtherString 2 0 555 somOtherString 3 0

DontBogartMe
 
2009-07-28

Originally posted by: scudsucker I do agree with a linked list as the display mechanism - but that does not make for a simple UI (nor simple storage)

just for the record, a linked list has nothing to do with the UI - it's a way of organising your data, the end user never has to look at or click and drag into a linked list.

But you're probably better off with a sorting column anyway, what you said in choice a).

scudsucker
 
2009-07-29

linked list as the display mechanism

Oops, typo - should have read "backend mechanism"

Poliguin - thanks very much, helps me make a start.

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneBack End

Ordering results - theory question