| @@ -86,21 +86,15 @@ | ||
| 86 | 86 | $this->save(); |
| 87 | 87 | return $this; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - $newPosition = ($prevTask->position + $nextItem->position) / 2; | |
| 91 | - | |
| 92 | - // check if new position is already taken | |
| 93 | - $exist = $stageQuery | |
| 94 | - ->where('position', $newPosition) | |
| 95 | - ->where('id', '!=', $this->id) | |
| 96 | - ->first(); | |
| 97 | - | |
| 98 | - if ($exist) { | |
| 90 | + if ($nextItem->position - $prevTask->position < 0.02) { | |
| 99 | 91 | self::reIndexStagesPositions($this->toArray()); |
| 100 | 92 | return $this->moveToNewPosition($newIndex); |
| 101 | 93 | } |
| 102 | 94 | |
| 95 | + $newPosition = ($prevTask->position + $nextItem->position)/ 2; | |
| 96 | + | |
| 103 | 97 | $this->position = $newPosition; |
| 104 | 98 | $this->save(); |
| 105 | 99 | return $this; |
| 106 | 100 | } |
| @@ -112,7 +106,12 @@ | ||
| 112 | 106 | foreach ($allStages as $index => $stage) { |
| 113 | 107 | $stage->position = $index + 1; |
| 114 | 108 | $stage->save(); |
| 115 | 109 | } |
| 110 | + } | |
| 111 | + | |
| 112 | + public function tasks() | |
| 113 | + { | |
| 114 | + return $this->hasMany(Task::class, 'stage_id'); | |
| 116 | 115 | } |
| 117 | 116 | |
| 118 | 117 | } |