3.7.2. Drag & Drop

Internal use

Internal M This topic is intended for MetaFactory developers only

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:

  1. Add metadata to the draggable object to mark it orderable within a certain reference (e.g. reference ‘task’ )

    Listing 3.11 model.xml
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    <object name="Subtask">
            <metadata>
                    ...
                    <orderable>task</orderable>
            </metadata>
            ...
            <reference name="task" type="Task">
                    ...
            </reference>
    </object>
    

    Exclam M In the <orderable> metadata you need to specify the name of a reference, not the name of an object.

  2. Add an attribute sortOrder to the draggable object (here object Subtask)

    Listing 3.12 model.xml
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    <object name="Subtask">
            <metadata>
                    <orderable>task</orderable>
            </metadata>
            ...
            <attribute name="sortOrder" type="Integer" notnull="true">
                    <metadata>
                            <entity.default.value>Integer.MAX_VALUE</entity.default.value>
                            <list.relation.mgmt>[number]</list.relation.mgmt>
                    </metadata>
            </attribute>
            <reference name="task" type="Task">
                    <metadata>
                            ...
                    </metadata>
            </reference>
    </object>
    
  3. Add metadata to the reference to create a finder (e.g. findByTask)

    Listing 3.13 model.xml
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    <object name="Subtask">
            <metadata>
                    ...
                    <orderable>task</orderable>
            </metadata>
            ...
            <attribute name="sortOrder" type="Integer" notnull="true">
                    <metadata>
                            <entity.default.value>Integer.MAX_VALUE</entity.default.value>
                            <list.relation.mgmt>[number]</list.relation.mgmt>
                    </metadata>
            </attribute>
            <reference name="task" type="Task">
                    <metadata>
                            ...
                            <create.finder.method.list>true</create.finder.method.list>
                    </metadata>
            </reference>
    </object>
    
  4. Generate the application

  5. 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.

    Listing 3.14 [projectdir]\[backenddir]\src\main\resources\config\liquibase\liquibase-alters-changeLog.xml
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    <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>
    

    Glasses M Read more about Liquibase change sets

  6. Run the application.