Add drag and drop to change column positions
This commit is contained in:
64
app/Model/Column.php
Normal file
64
app/Model/Column.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Model;
|
||||
|
||||
/**
|
||||
* Column Model
|
||||
*
|
||||
* @package model
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Column extends Base
|
||||
{
|
||||
/**
|
||||
* SQL table name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const TABLE = 'columns';
|
||||
|
||||
/**
|
||||
* Get all columns sorted by position for a given project
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id Project id
|
||||
* @return array
|
||||
*/
|
||||
public function getAll($project_id)
|
||||
{
|
||||
return $this->db->table(self::TABLE)->eq('project_id', $project_id)->asc('position')->findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change column position
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id
|
||||
* @param integer $column_id
|
||||
* @param integer $position
|
||||
* @return boolean
|
||||
*/
|
||||
public function changePosition($project_id, $column_id, $position)
|
||||
{
|
||||
if ($position < 1 || $position > $this->db->table(self::TABLE)->eq('project_id', $project_id)->count()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$column_ids = $this->db->table(self::TABLE)->eq('project_id', $project_id)->neq('id', $column_id)->asc('position')->findAllByColumn('id');
|
||||
$offset = 1;
|
||||
$results = array();
|
||||
|
||||
foreach ($column_ids as $current_column_id) {
|
||||
if ($offset == $position) {
|
||||
$offset++;
|
||||
}
|
||||
|
||||
$results[] = $this->db->table(self::TABLE)->eq('id', $current_column_id)->update(array('position' => $offset));
|
||||
$offset++;
|
||||
}
|
||||
|
||||
$results[] = $this->db->table(self::TABLE)->eq('id', $column_id)->update(array('position' => $position));
|
||||
|
||||
return !in_array(false, $results, true);
|
||||
}
|
||||
}
|
||||
@@ -262,27 +262,6 @@ class Subtask extends Base
|
||||
return $this->db->table(self::TABLE)->eq('task_id', $task_id)->update(array('status' => self::STATUS_DONE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get subtasks with consecutive positions
|
||||
*
|
||||
* If you remove a subtask, the positions are not anymore consecutives
|
||||
*
|
||||
* @access public
|
||||
* @param integer $task_id
|
||||
* @return array
|
||||
*/
|
||||
public function getNormalizedPositions($task_id)
|
||||
{
|
||||
$subtasks = $this->db->hashtable(self::TABLE)->eq('task_id', $task_id)->asc('position')->getAll('id', 'position');
|
||||
$position = 1;
|
||||
|
||||
foreach ($subtasks as $subtask_id => $subtask_position) {
|
||||
$subtasks[$subtask_id] = $position++;
|
||||
}
|
||||
|
||||
return $subtasks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save subtask position
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user