# Re sorting and re parenting patch

**URL:** <https://www.ruby-forum.com/t/re-sorting-and-re-parenting-patch/100732>\
**Category:** Radiant CMS\
**Created:** [July 31, 2006, 7:33pm UTC](https://www.ruby-forum.com/t/re-sorting-and-re-parenting-patch/100732 "2006-07-31T19:33:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erik\_BSOrdway](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e274bd/32.png) [@Erik\_BSOrdway](https://www.ruby-forum.com/u/Erik_BSOrdway)\
**Post date:** [July 31, 2006, 7:33pm UTC](https://www.ruby-forum.com/t/re-sorting-and-re-parenting-patch/100732/1 "2006-07-31T19:33:50Z")

</div>

I really wanted to see this functionality but I all saw was talk so I  
scratched my own itch. Code wise it is pretty clean but the UI is  
functional but ugly. All the movements are via the page index page  
with a little ajax for #3 and #4. It works on the “styled blog” test  
site.

[http://dev.radiantcms.org:9007/radiant/ticket/179](http://dev.radiantcms.org:9007/radiant/ticket/179)

This adds five movements to pages:  
Sorts  
#1 Sort up in container  
#2 Sort down in container  
Reparenting  
#3 Become a child of one of my parents siblings  
#4 Become a child of one of my siblings  
#5 Become a sibling of my parent

Sorting is via a sort attribute. On creation each page is assigned a  
sort\_id from a bottomless pool. Changes in the sort are via swaping  
sort\_id’s with the next page in the proper direction. The original  
order of the sort presently used is maintained to some degree as the  
sort attribute is assigned sequentially over time with has the same  
effect of the ASC timestamp sort.

Reparenting is constrained to those movements that make sense. The  
root node can not be preparented. moves that there is no where to  
move to are also blocked at the UI level

Steps needed to use this:

# run migrate to add column and add sort table

# set sort id’s for existing pages " update pages set sort\_id = id;"

wroks on postgresql and maintains the orginal sorting order

# set the sequence used by the sort table to the id after the last

assigned one in the pages table. OR for other DB file the sort table  
to the same point as pages table # put the icons inplace.

Issues/future work  
The icons I used are ugly.  
Does not stop reparenting to virtual pages.  
Moves could be made to display via AJAX without refreshing page.

---

<div class="post-metadata">

**Author:** ![Erik\_BSOrdway](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e274bd/32.png) [@Erik\_BSOrdway](https://www.ruby-forum.com/u/Erik_BSOrdway)\
**Post date:** [July 31, 2006, 11:34pm UTC](https://www.ruby-forum.com/t/re-sorting-and-re-parenting-patch/100732/2 "2006-07-31T23:34:10Z")

</div>

I fixed a few errors. You need to specify a the by=“sort\_id” ala  
\<r:children:each order=“ASC” by=“sort\_id”\> for the display to sort  
correctly. Otherwise it defaults to the normal way.

---

<div class="post-metadata">

**Author:** ![Erik\_BSOrdway](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e274bd/32.png) [@Erik\_BSOrdway](https://www.ruby-forum.com/u/Erik_BSOrdway)\
**Post date:** [July 31, 2006, 11:46pm UTC](https://www.ruby-forum.com/t/re-sorting-and-re-parenting-patch/100732/3 "2006-07-31T23:46:11Z")

</div>

Erik B. Ordway wrote:

> I fixed a few errors. You need to specify a the by=“sort\_id” ala  
> \<r:children:each order=“ASC” by=“sort\_id”\> for the display to sort  
> correctly. Otherwise it defaults to the normal way.

Don’t you think it would be better to make sort\_id the default column?

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)

---

<div class="post-metadata">

**Author:** ![Erik\_BSOrdway](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e274bd/32.png) [@Erik\_BSOrdway](https://www.ruby-forum.com/u/Erik_BSOrdway)\
**Post date:** [August 1, 2006, 2:55am UTC](https://www.ruby-forum.com/t/re-sorting-and-re-parenting-patch/100732/4 "2006-08-01T02:55:14Z")

</div>

Erik B. Ordway wrote:

> I was trying to limit the effect of the change. For the most part  
> everything works like it did before the patch. I agree though that  
> changing the default to sort\_id would make more sense.

Let’s change it.

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)

---

<div class="post-metadata">

**Author:** ![Erik\_BSOrdway](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e274bd/32.png) [@Erik\_BSOrdway](https://www.ruby-forum.com/u/Erik_BSOrdway)\
**Post date:** [August 1, 2006, 12:08am UTC](https://www.ruby-forum.com/t/re-sorting-and-re-parenting-patch/100732/5 "2006-08-01T00:08:02Z")

</div>

I was trying to limit the effect of the change. For the most part  
everything works like it did before the patch. I agree though that  
changing the default to sort\_id would make more sense.

---

<div class="post-metadata">

**Author:** ![Erik\_BSOrdway](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e274bd/32.png) [@Erik\_BSOrdway](https://www.ruby-forum.com/u/Erik_BSOrdway)\
**Post date:** [August 1, 2006, 6:22am UTC](https://www.ruby-forum.com/t/re-sorting-and-re-parenting-patch/100732/6 "2006-08-01T06:22:48Z")

</div>

There is a patch in added to the ticket that should do it.
