-
Notifications
You must be signed in to change notification settings - Fork 227
Add move to list option to Methodology cards #1580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 22 commits
941aa68
abf51e4
d67902a
7b8fab7
e682e68
4b709e4
746bb51
c9e6ed0
92acb8e
14aebeb
fa11864
8c59b71
b4264cb
87511f2
1b2ed24
12944aa
ef8960f
17cc212
eb91548
458f24e
651c2c9
0c1187a
77992f9
42135fd
f782d5b
73e3e33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| class Cards::PositionController < AuthenticatedController | ||
| include EventPublisher | ||
| include ProjectScoped | ||
| include ValidateMove | ||
|
|
||
| before_action :set_current_board_and_list | ||
| before_action :set_card | ||
| before_action :require_list_change, if: :append_to_list? | ||
| before_action :set_prev_item_and_next_item | ||
| before_action :validate_move_params | ||
|
|
||
| def create | ||
| Card.transaction do | ||
| List.move(@card, prev_item: @prev_item, next_item: @next_item) | ||
|
|
||
| if new_list | ||
| @card.list = new_list | ||
| @card.save! | ||
| end | ||
| end | ||
|
|
||
| publish_event('card.updated', @card.to_event_payload) | ||
| @card.reload | ||
|
|
||
| respond_to do |format| | ||
| format.html do | ||
| redirect_to project_board_list_card_path(current_project, @board, @card.list, @card), | ||
| notice: 'Task moved.' | ||
| end | ||
|
|
||
| format.json do | ||
| render json: { | ||
| is_card: true, | ||
| id: @card.id, | ||
| link: polymorphic_path([current_project, @board, @card.list, @card]), | ||
| moveLink: project_board_list_card_position_path(current_project, @board, @card.list, @card) | ||
| } | ||
| end | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| # A request with a new_list_id but no explicit position appends the card to | ||
| # the end of the target list (e.g. the 'move to list' dropdown). | ||
| def append_to_list? | ||
| move_params[:new_list_id].present? && | ||
| move_params[:prev_id].blank? && | ||
| move_params[:next_id].blank? | ||
| end | ||
|
|
||
| # Override EventPublisher#event_action_payload: the RESTful action is | ||
| # 'create', but moving a card is semantically an update. | ||
| # | ||
| # FIXME: Replace with ActivityService action registration once | ||
| # convention-over-configuration approach is implemented. | ||
| def event_action_payload | ||
| super.merge(action: 'update') | ||
| end | ||
|
|
||
| def move_params | ||
| params.permit(:card_id, :project_id, :board_id, :list_id, :next_id, :prev_id, :new_list_id) | ||
| end | ||
|
|
||
| def moveable_item_name | ||
| 'card' | ||
| end | ||
|
|
||
| def moveable_items | ||
| @board.cards | ||
| end | ||
|
|
||
| def moveable_parent | ||
| new_list || @list | ||
| end | ||
|
|
||
| def new_list | ||
| return if move_params[:new_list_id].blank? | ||
|
|
||
| @new_list ||= @board.lists.find(move_params[:new_list_id]) | ||
| end | ||
|
|
||
| def require_list_change | ||
| return if new_list.id != @card.list_id | ||
|
|
||
| redirect_to project_board_list_card_path(current_project, @board, @list, @card), | ||
| alert: 'Task is already in that list.' | ||
| end | ||
|
|
||
| def set_card | ||
| @card = @board.cards.find(params[:card_id]) | ||
| end | ||
|
|
||
| def set_current_board_and_list | ||
| @board = current_project.boards.includes(:lists).find(params[:board_id]) | ||
| @list = @board.lists.includes(:cards).find(params[:list_id]) | ||
| end | ||
|
|
||
| def set_prev_item_and_next_item | ||
| if append_to_list? | ||
| @prev_item = new_list.last_card | ||
| @next_item = nil | ||
| else | ||
| super | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| class Card < ApplicationRecord | ||
| include Commentable | ||
| include Eventable | ||
| include HasFields | ||
| include RevisionTracking | ||
| include Subscribable | ||
|
|
@@ -84,9 +85,19 @@ def to_xml(xml_builder, includes: [], version: 3) | |
| end | ||
| end | ||
|
|
||
| def local_event_payload | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're adding this for cards but are we actually using it? Either we keep this and use eventpublisher for cards, or leave this out for now.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed for now.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aapomm please go ahead and add it. We probably need to include list information in the payload (and even a before/after in the particular Position one).
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why was this resolved @aapomm ? I think that someone paying attention to this event would like List / Board? |
||
| { | ||
| name: name, | ||
| project: { | ||
| id: project.id, | ||
| name: project.name | ||
| } | ||
| } | ||
| end | ||
|
|
||
| def local_fields | ||
| { | ||
| 'List' => list.name.parameterize(preserve_case: true, separator: '_'), | ||
| 'List' => list.name.parameterize(preserve_case: true, separator: '_'), | ||
| 'Title' => name | ||
| } | ||
| end | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.