-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New position logic for drag and drop beta version (#716)
* Add new position to story model * Create populate new position task * Create sort stories route * Added ordering stories specs * Added sort stories to redux * Implemented new position logic * Update and fix specs * Update changelog * Remove a console.log * Remove unnecessary PunditContext * Change new route path * Refactored SortStories reducer * Fixed beta stories controller spec * Refactores projectBoard beta model * Change calculatePositions arguments * Default value to calculatePosition arguments * Added logging to populate new position task * Fixed Story model spec * Fixed some CodeClimate issues * Fixed cypress specs
- Loading branch information
1 parent
8398358
commit 8b190c4
Showing
24 changed files
with
330 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class Beta::StoriesController < ApplicationController | ||
before_action :set_project_and_story | ||
def position | ||
authorize Story | ||
stories = Beta::SortStories.new(@story, allowed_params).call | ||
render json: stories | ||
end | ||
|
||
private | ||
|
||
def allowed_params | ||
params.require(:story).permit(:position, :new_position, :id, :state, :project_id) | ||
end | ||
|
||
def set_project_and_story | ||
@project = policy_scope(Project).find(allowed_params[:project_id]) | ||
@story = policy_scope(Story).find(allowed_params[:id]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,10 @@ def sort? | |
update? | ||
end | ||
|
||
def position? | ||
update? | ||
end | ||
|
||
def backlog? | ||
update? | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
class Beta::SortStories | ||
def initialize(story, sort_params) | ||
@story = story | ||
@new_position = sort_params[:new_position] | ||
@new_state = sort_params[:state] | ||
@position = sort_params[:position] | ||
end | ||
|
||
def call | ||
update_current_story | ||
update_stories_positions | ||
stories | ||
end | ||
|
||
private | ||
|
||
def update_current_story | ||
@story.update(new_position: @new_position, state: @new_state, position: @position) | ||
end | ||
|
||
def stories_to_update | ||
stories.where.not(id: @story.id) | ||
end | ||
|
||
def update_stories_positions | ||
stories_to_update.update_all('new_position = new_position + 1') | ||
end | ||
|
||
def stories | ||
case @new_state | ||
when 'started', 'finished', 'delivered' | ||
@story.project.stories.in_progress.where('new_position >= ?', @new_position) | ||
when 'unstarted' | ||
@story.project.stories.backlog.where('new_position >= ?', @new_position) | ||
when 'unscheduled' | ||
@story.project.stories.chilly_bin.where('new_position >= ?', @new_position) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class AddNewPositionToStory < ActiveRecord::Migration[5.2] | ||
def change | ||
add_column :stories, :new_position, :integer, null: true | ||
end | ||
def down | ||
remove_column :stories, :new_position | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.