3.7.2. Drag & Drop
Steps to implement the feature
Drag & Drop of an item in a list involves a dragable object (e.g. ‘Subtask’) and a reference to a parent object (e.g. ‘Task’).
In order to implement this feature take the following steps:
Add metadata to the draggable object to mark it orderable within a certain reference (e.g. reference ‘task’ )
1<object name="Subtask"> 2 <metadata> 3 4 <orderable>task</orderable> 5 </metadata> 6 7 <reference name="task" type="Task"> 8 9 </reference> 10</object>
In the <orderable> metadata you need to specify the name of a reference, not the name of an object.
Add an attribute sortOrder to the draggable object (here object Subtask)
1<object name="Subtask"> 2 <metadata> 3 <orderable>task</orderable> 4 </metadata> 5 6 <attribute name="sortOrder" type="Integer" notnull="true"> 7 <metadata> 8 <entity.default.value>Integer.MAX_VALUE</entity.default.value> 9 <list.relation.mgmt>[number]</list.relation.mgmt> 10 </metadata> 11 </attribute> 12 <reference name="task" type="Task"> 13 <metadata> 14 15 </metadata> 16 </reference> 17</object>
Add metadata to the reference to create a finder (e.g. findByTask)
1<object name="Subtask"> 2 <metadata> 3 4 <orderable>task</orderable> 5 </metadata> 6 7 <attribute name="sortOrder" type="Integer" notnull="true"> 8 <metadata> 9 <entity.default.value>Integer.MAX_VALUE</entity.default.value> 10 <list.relation.mgmt>[number]</list.relation.mgmt> 11 </metadata> 12 </attribute> 13 <reference name="task" type="Task"> 14 <metadata> 15 16 <create.finder.method.list>true</create.finder.method.list> 17 </metadata> 18 </reference> 19</object>
Generate the application
Create a changeSet in the Liquibase alters changelog to add the column to the table of the draggable object.
Set a default value of 0 as the sort_order is required and must not be null. On the entity the default value becomes Integer.MAX_VALUE, however this is not supported by SQL. 0 is fine to start with.
1
- <<<<<<< HEAD
<databaseChangeLog >
- <changeSet id=”[id-named-after-jira-issue]” author=”[your-initials]”>
- <addColumn tableName=”subtask”>
- <column name=”sort_order” type=”INT” defaultValueNumeric=”0”>
<constraints nullable=”false” />
</column>
</addColumn>
</changeSet>
</databaseChangeLog>
Read more about Liquibase change sets
Run the application.