generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3f2eff
commit 706a698
Showing
31 changed files
with
841 additions
and
1 deletion.
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
68 changes: 68 additions & 0 deletions
68
app/assets/stylesheets/components/timelines/_timeline-stages.scss
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,68 @@ | ||
.timeline-stages__heading-box { | ||
display: flex; | ||
flex-direction: row; | ||
gap: 15px; | ||
} | ||
|
||
.timeline-stages__heading-stage-title { | ||
width: 100%; | ||
height: 45px; | ||
} | ||
|
||
.timeline-stages__heading-stage-title h2 { | ||
line-height: 45px; | ||
padding-left: 1rem; | ||
color: white; | ||
} | ||
|
||
.timeline-stages__heading-stage-indicator { | ||
@extend .govuk-heading-m; | ||
color: white; | ||
border-radius: 50%; | ||
align-items: center; | ||
display: flex; | ||
justify-content: center; | ||
width: 45px; | ||
height: 45px; | ||
flex-shrink: 0; | ||
} | ||
|
||
.timeline-stages__heading-box[data-stage="0"] .timeline-stages__heading-stage-title { | ||
background-color: $stage-0-colour; | ||
} | ||
|
||
.timeline-stages__heading-box[data-stage="0"] .timeline-stages__heading-stage-indicator { | ||
background-color: $stage-0-colour; | ||
} | ||
|
||
.timeline-stages__heading-box[data-stage="1"] .timeline-stages__heading-stage-title { | ||
background-color: $stage-1-colour; | ||
} | ||
|
||
.timeline-stages__heading-box[data-stage="1"] .timeline-stages__heading-stage-indicator { | ||
background-color: $stage-1-colour; | ||
} | ||
|
||
.timeline-stages__heading-box[data-stage="2"] .timeline-stages__heading-stage-title { | ||
background-color: $stage-2-colour; | ||
} | ||
|
||
.timeline-stages__heading-box[data-stage="2"] .timeline-stages__heading-stage-indicator { | ||
background-color: $stage-2-colour; | ||
} | ||
|
||
.timeline-stages__heading-box[data-stage="3"] .timeline-stages__heading-stage-title { | ||
background-color: $stage-3-colour; | ||
} | ||
|
||
.timeline-stages__heading-box[data-stage="3"] .timeline-stages__heading-stage-indicator { | ||
background-color: $stage-3-colour; | ||
} | ||
|
||
.timeline-stages__heading-box[data-stage="4"] .timeline-stages__heading-stage-title { | ||
background-color: $stage-4-colour; | ||
} | ||
|
||
.timeline-stages__heading-box[data-stage="4"] .timeline-stages__heading-stage-indicator { | ||
background-color: $stage-4-colour; | ||
} |
5 changes: 5 additions & 0 deletions
5
app/assets/stylesheets/components/timelines/_timeline-tasks.scss
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,5 @@ | ||
.timeline-tasks__timeframe-tag { | ||
@extend .govuk-tag; | ||
@extend .govuk-tag--grey; | ||
max-width: none; | ||
} |
11 changes: 11 additions & 0 deletions
11
app/assets/stylesheets/components/timelines/_timeline.scss
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,11 @@ | ||
.timeline__date-tag { | ||
@extend .govuk-tag; | ||
@extend .govuk-tag--grey; | ||
max-width: none; | ||
} | ||
|
||
.timeline__end-date-container { | ||
display: flex; | ||
flex-direction: row; | ||
flex-flow: row-reverse; | ||
} |
71 changes: 71 additions & 0 deletions
71
app/controllers/support/cases/timelines/tasks_controller.rb
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,71 @@ | ||
module Support | ||
class Cases::Timelines::TasksController < Cases::ApplicationController | ||
include HasDateParams | ||
|
||
before_action :timeline, :back_url | ||
|
||
def new | ||
@stage = Support::TimelineStage.find(params[:stage]) | ||
@creator = Support::TimelineTask::Creator.new(start_date: 1.business_day.after(@stage.tasks.last.end_date)) | ||
end | ||
|
||
def create | ||
# byebug | ||
@creator = Support::TimelineTask::Creator.new(creator_params.merge(timeline:).merge(stage: Support::TimelineStage.find(creator_params[:stage]))) | ||
if @creator.valid? | ||
@creator.save! | ||
redirect_to edit_support_case_timeline_path(case_id: current_case, id: timeline.id) | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
def edit | ||
@task = Support::TimelineTask.find_by(id: params[:id]) | ||
@editor = @task.editor | ||
end | ||
|
||
def update | ||
@task = Support::TimelineTask.find_by(id: params[:id]) | ||
# byebug | ||
@editor = @task.editor(editor_params) | ||
|
||
if @editor.valid? | ||
@editor.save! | ||
redirect_to edit_support_case_timeline_path(case_id: current_case, id: timeline.id) | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
private | ||
|
||
def creator_params | ||
form_params(:support_timeline_task_creator) | ||
.except("start_date(3i)", "start_date(2i)", "start_date(1i)", "end_date(3i)", "end_date(2i)", "end_date(1i)") | ||
.merge(start_date: date_param(:support_timeline_task_creator, :start_date).compact_blank) | ||
.merge(end_date: date_param(:support_timeline_task_creator, :end_date).compact_blank) | ||
.compact_blank | ||
end | ||
|
||
def editor_params | ||
form_params(:support_timeline_task_editor) | ||
.except("start_date(3i)", "start_date(2i)", "start_date(1i)", "end_date(3i)", "end_date(2i)", "end_date(1i)") | ||
.merge(start_date: date_param(:support_timeline_task_editor, :start_date).compact_blank) | ||
.merge(end_date: date_param(:support_timeline_task_editor, :end_date).compact_blank) | ||
.compact_blank | ||
end | ||
|
||
def form_params(scope) | ||
params.require(scope).permit(:title, :timeframe_type, :start_date, :end_date, :duration, :stage) | ||
end | ||
|
||
def timeline | ||
@timeline = Support::Timeline.find_by(id: params[:timeline_id]) | ||
end | ||
|
||
def back_url | ||
@back_url = support_case_timeline_path(case_id: current_case.id, id: @timeline.id) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module Support | ||
class Cases::TimelinesController < Cases::ApplicationController | ||
before_action :back_url | ||
|
||
def create | ||
timeline = Support::Timeline.create_demo!(case: current_case, start_date: Time.zone.now) | ||
redirect_to support_case_timeline_path(case_id: current_case, id: timeline.id) | ||
end | ||
|
||
def show | ||
@timeline = Support::Timeline.find_by(id: params[:id]) | ||
end | ||
|
||
def edit | ||
@timeline = Support::Timeline.find_by(id: params[:id]) | ||
end | ||
|
||
def versions | ||
@timeline = Support::Timeline.find_by(id: params[:timeline_id]) | ||
@versions = @timeline.versions | ||
@back_url = support_case_timeline_path(case_id: current_case.id, id: @timeline.id) | ||
end | ||
|
||
private | ||
|
||
def back_url | ||
@back_url = support_case_path(@current_case) | ||
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,11 @@ | ||
module Support::Case::Timelineable | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
has_many :timelines, class_name: "Support::Timeline", foreign_key: :support_case_id | ||
end | ||
|
||
def latest_timeline | ||
timelines.last | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module Support | ||
class Timeline < ApplicationRecord | ||
include Adjustable | ||
|
||
# has_paper_trail ignore: %i[id created_at updated_at] | ||
|
||
has_many :stages, class_name: "Support::TimelineStage", foreign_key: :support_timeline_id | ||
has_many :tasks, -> { order start_date: :asc }, class_name: "Support::TimelineTask", through: :stages, source: :tasks | ||
belongs_to :case, class_name: "Support::Case", foreign_key: :support_case_id | ||
|
||
# requires_approval | ||
|
||
# enum :status, { draft: 0, publish: 1 } | ||
|
||
def self.create_demo!(case:, start_date:) | ||
transaction do | ||
timeline = create!(case:, start_date:) | ||
stage_0 = timeline.stages.create!(title: "Initial Stage: Start collaboration", stage: 0) | ||
stage_0.tasks.create!(title: "Task 1", duration: 2.days) | ||
stage_0.tasks.create!(title: "Task 2", duration: 5.days) | ||
stage_1 = timeline.stages.create!(title: "Stage 1: Approach to market", stage: 1) | ||
stage_1.tasks.create!(title: "Task 1", duration: 3.days) | ||
stage_1.tasks.create!(title: "Task 2", duration: 10.days) | ||
stage_2 = timeline.stages.create!(title: "Stage 2: Prepare and go to market", stage: 2) | ||
stage_2.tasks.create!(title: "Task 1", duration: 14.days) | ||
stage_2.tasks.create!(title: "Task 2", duration: 20.days) | ||
timeline | ||
end | ||
end | ||
|
||
def tasks_after(task) | ||
tasks.where("start_date >= ?", task.end_date).order(start_date: :asc) | ||
end | ||
|
||
def tasks_before(task) | ||
tasks.where("end_date <= ?", task.start_date).reorder(end_date: :desc) | ||
end | ||
|
||
def task_after(task) | ||
tasks_after(task).first | ||
end | ||
|
||
def task_before(task) | ||
tasks_before(task).first | ||
end | ||
|
||
def refresh_end_date! | ||
self.end_date = stages.last.complete_by | ||
save! | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Support::Timeline::Adjustable | ||
extend ActiveSupport::Concern | ||
|
||
def adjustor_by_updated_task(task:, new_start_date:, new_end_date:) | ||
Support::Timeline::Adjustor.by_updated_task(timeline: self, task:, new_start_date:, new_end_date:) | ||
end | ||
|
||
def adjustor_by_new_task(task:, new_start_date:, new_end_date:) | ||
Support::Timeline::Adjustor.by_new_task(timeline: self, task:, new_start_date:, new_end_date:) | ||
end | ||
end |
Oops, something went wrong.