Skip to content

Commit

Permalink
sc-poc: timeline & dates
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinKruglov committed May 1, 2024
1 parent b3f2eff commit 3044b99
Show file tree
Hide file tree
Showing 31 changed files with 847 additions and 8 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ gem "aws-sdk-s3", require: false
# gem "azure-storage-blob", "~> 2.0", require: false
gem "azure-storage-blob", git: "https://github.com/honeyankit/azure-storage-ruby", ref: "patch-1", require: false
gem "bootsnap", ">= 1.1.0", require: false
gem "business_time"
gem "coffee-rails", "~> 5.0" # TODO: remove coffee-rails, only used for google analytics
gem "contentful", "~> 2.17"
gem "crawler_detect"
gem "cssbundling-rails", "~> 1.1"
gem "draft_punk", git: "https://github.com/groupnews/draftpunk"
gem "dry-struct"
gem "dry-transformer"
gem "dry-validation"
Expand All @@ -26,6 +28,7 @@ gem "flipper-active_record"
gem "flipper-ui"
gem "govuk-components"
gem "govuk_design_system_formbuilder", "~> 5"
gem "holidays"
gem "httparty"
gem "httpclient"
gem "jbuilder", "~> 2.11"
Expand Down
19 changes: 19 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
GIT
remote: https://github.com/groupnews/draftpunk
revision: 003766dc5b80748feb27e3ebee4e69196d196563
specs:
draft_punk (0.4.1)
amoeba (~> 3.1)
differ (< 0.2)
rails (>= 5.0)

GIT
remote: https://github.com/honeyankit/azure-storage-ruby
revision: abae3ba18d5ba169bf83685d372e1be56748d6b4
Expand Down Expand Up @@ -95,6 +104,8 @@ GEM
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
aes_key_wrap (1.1.0)
amoeba (3.3.0)
activerecord (>= 5.2.0)
application_insights (0.5.6)
ar-sequence (0.2.1)
activerecord
Expand Down Expand Up @@ -142,6 +153,9 @@ GEM
bullet (7.1.6)
activesupport (>= 3.0.0)
uniform_notifier (~> 1.11)
business_time (0.13.0)
activesupport (>= 3.2.0)
tzinfo
byebug (11.1.3)
capybara (3.40.0)
addressable
Expand Down Expand Up @@ -183,6 +197,7 @@ GEM
date (3.3.4)
debug_inspector (1.2.0)
diff-lcs (1.5.1)
differ (0.1.2)
docile (1.4.0)
domain_name (0.6.20240107)
dotenv (3.1.0)
Expand Down Expand Up @@ -303,6 +318,7 @@ GEM
hashdiff (1.1.0)
hashie (5.0.0)
highline (3.0.1)
holidays (8.7.1)
html-attributes-utils (1.0.2)
activesupport (>= 6.1.4.4)
http (5.2.0)
Expand Down Expand Up @@ -761,6 +777,7 @@ DEPENDENCIES
bootsnap (>= 1.1.0)
brakeman
bullet
business_time
byebug
capybara (>= 2.15)
climate_control
Expand All @@ -770,6 +787,7 @@ DEPENDENCIES
cssbundling-rails (~> 1.1)
database_cleaner
dotenv-rails
draft_punk!
dry-struct
dry-transformer
dry-validation
Expand All @@ -783,6 +801,7 @@ DEPENDENCIES
govuk-components
govuk_design_system_formbuilder (~> 5)
guard-rspec
holidays
httparty
httpclient
i18n-tasks
Expand Down
3 changes: 3 additions & 0 deletions app/assets/stylesheets/application.sass.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
@import "./components/supported/case-list";
@import "./components/supported/case-files";
@import "./components/draft-email-attachments";
@import "./components/timelines/timeline";
@import "./components/timelines/timeline-stages";
@import "./components/timelines/timeline-tasks";


// Panel overrides
Expand Down
68 changes: 68 additions & 0 deletions app/assets/stylesheets/components/timelines/_timeline-stages.scss
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;
}
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 app/assets/stylesheets/components/timelines/_timeline.scss
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 app/controllers/support/cases/timelines/tasks_controller.rb
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
30 changes: 30 additions & 0 deletions app/controllers/support/cases/timelines_controller.rb
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
1 change: 1 addition & 0 deletions app/models/support/case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Case < ApplicationRecord
include FileUploadable
include Surveyable
include Notifiable
include Timelineable

belongs_to :category, class_name: "Support::Category", optional: true
belongs_to :query, class_name: "Support::Query", optional: true
Expand Down
11 changes: 11 additions & 0 deletions app/models/support/case/timelineable.rb
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
52 changes: 52 additions & 0 deletions app/models/support/timeline.rb
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
11 changes: 11 additions & 0 deletions app/models/support/timeline/adjustable.rb
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

0 comments on commit 3044b99

Please sign in to comment.