From 8444749a1e3f4567a5aac9e501b154b27031f2b2 Mon Sep 17 00:00:00 2001 From: Jenny Tong Date: Sun, 2 May 2021 21:30:44 -0500 Subject: [PATCH 1/6] Add an age field to the applications index page --- app/models/application.rb | 4 ++++ app/views/members/applications/index.html.haml | 3 +++ 2 files changed, 7 insertions(+) diff --git a/app/models/application.rb b/app/models/application.rb index 1824a8d3..466310eb 100644 --- a/app/models/application.rb +++ b/app/models/application.rb @@ -125,6 +125,10 @@ def sufficient_votes? enough_yes || !few_nos end + def age + Time.now - submitted_at + end + def self.to_approve all.map { |x| x if x.approvable? && x.state == "submitted" }.compact.sort_by { |x| x.submitted_at } end diff --git a/app/views/members/applications/index.html.haml b/app/views/members/applications/index.html.haml index 74fd7dee..14d80f86 100644 --- a/app/views/members/applications/index.html.haml +++ b/app/views/members/applications/index.html.haml @@ -22,6 +22,7 @@ %th Yes %th No %th ? + %th Age %tbody - @applicants_submitted.each do |applicant| - application = applicant.application @@ -48,6 +49,8 @@ %td= application.yes_votes.size %td= application.no_votes.size %td= application.not_voted_count + %td= "#{(application.age/ 1.day).floor} days" + %h3 %a{"data-toggle" => "collapse" , "href" => "#collapseEmails"} Applicant Email Addresses From 16fc9fe40f338397dbbcefbf55335f435c15f1ff Mon Sep 17 00:00:00 2001 From: Jenny Tong Date: Sat, 8 May 2021 16:06:18 -0700 Subject: [PATCH 2/6] WIP-add css class and logic for warning. Logic is still broken. --- app/assets/stylesheets/membership_application.scss | 4 ++++ app/views/members/applications/index.html.haml | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/membership_application.scss b/app/assets/stylesheets/membership_application.scss index 107938dc..0a8b4c3e 100644 --- a/app/assets/stylesheets/membership_application.scss +++ b/app/assets/stylesheets/membership_application.scss @@ -36,3 +36,7 @@ body.applications.show { } } } + +.overdue-highlighted { + background-color: #FFA500; +} diff --git a/app/views/members/applications/index.html.haml b/app/views/members/applications/index.html.haml index 14d80f86..46d10d4a 100644 --- a/app/views/members/applications/index.html.haml +++ b/app/views/members/applications/index.html.haml @@ -49,7 +49,10 @@ %td= application.yes_votes.size %td= application.no_votes.size %td= application.not_voted_count - %td= "#{(application.age/ 1.day).floor} days" + -age_in_days = (application.age/ 1.day).floor + %td= "#{age_in_days} days" + -if age_in_days > 2.months + %td.overdue-highlighted %h3 From fa9d110b1ac22b6f4f9696a880f63c9d95764599 Mon Sep 17 00:00:00 2001 From: Jenny Tong Date: Sat, 8 May 2021 17:26:56 -0700 Subject: [PATCH 3/6] Fix highlighting for age column for 2 months overdue applications --- app/views/members/applications/index.html.haml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/views/members/applications/index.html.haml b/app/views/members/applications/index.html.haml index 46d10d4a..17197caa 100644 --- a/app/views/members/applications/index.html.haml +++ b/app/views/members/applications/index.html.haml @@ -50,9 +50,10 @@ %td= application.no_votes.size %td= application.not_voted_count -age_in_days = (application.age/ 1.day).floor - %td= "#{age_in_days} days" - -if age_in_days > 2.months - %td.overdue-highlighted + %td{:class => ("overdue-highlighted" if application.age > 2.months)} + = "#{age_in_days} days" + + %h3 From e41766f5e788ef7828619cb7559b80095086e509 Mon Sep 17 00:00:00 2001 From: Jenny Tong Date: Mon, 10 May 2021 16:06:46 -0700 Subject: [PATCH 4/6] Add helper for choosing highlight class --- app/assets/stylesheets/membership_application.scss | 4 ++++ app/helpers/membership_application_helper.rb | 10 ++++++++++ app/views/members/applications/index.html.haml | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 app/helpers/membership_application_helper.rb diff --git a/app/assets/stylesheets/membership_application.scss b/app/assets/stylesheets/membership_application.scss index 0a8b4c3e..fb50e4e1 100644 --- a/app/assets/stylesheets/membership_application.scss +++ b/app/assets/stylesheets/membership_application.scss @@ -40,3 +40,7 @@ body.applications.show { .overdue-highlighted { background-color: #FFA500; } + +.almost-due-highlighted { + background-color: yellow; +} \ No newline at end of file diff --git a/app/helpers/membership_application_helper.rb b/app/helpers/membership_application_helper.rb new file mode 100644 index 00000000..e9f155fb --- /dev/null +++ b/app/helpers/membership_application_helper.rb @@ -0,0 +1,10 @@ +module MembershipApplicationHelper + + def choose_highlight_class(age) + if age >= 5.weeks && age < 2.months + "almost-due-highlighted" + elsif age > 2.months + "overdue-highlighted" + end + end +end \ No newline at end of file diff --git a/app/views/members/applications/index.html.haml b/app/views/members/applications/index.html.haml index 17197caa..e969bcdf 100644 --- a/app/views/members/applications/index.html.haml +++ b/app/views/members/applications/index.html.haml @@ -50,7 +50,7 @@ %td= application.no_votes.size %td= application.not_voted_count -age_in_days = (application.age/ 1.day).floor - %td{:class => ("overdue-highlighted" if application.age > 2.months)} + %td{:class => choose_highlight_class(application.age)} = "#{age_in_days} days" From c602f88a08ec08e32d5de6dc3708ff08b7760f1f Mon Sep 17 00:00:00 2001 From: Jenny Tong Date: Mon, 10 May 2021 16:11:59 -0700 Subject: [PATCH 5/6] Change highlight warning number of weeks to the correct number --- app/helpers/membership_application_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/membership_application_helper.rb b/app/helpers/membership_application_helper.rb index e9f155fb..bb6cb6cc 100644 --- a/app/helpers/membership_application_helper.rb +++ b/app/helpers/membership_application_helper.rb @@ -1,7 +1,7 @@ module MembershipApplicationHelper def choose_highlight_class(age) - if age >= 5.weeks && age < 2.months + if age >= 7.weeks && age < 2.months "almost-due-highlighted" elsif age > 2.months "overdue-highlighted" From 69ac98af929516a63f0fccb85c8b68ff061e29ed Mon Sep 17 00:00:00 2001 From: Jenny Tong Date: Sun, 16 May 2021 16:54:07 -0700 Subject: [PATCH 6/6] Add spec, refactor method, and refactor css classes --- .../stylesheets/membership_application.scss | 8 ------ app/helpers/membership_application_helper.rb | 8 ++++-- .../members/applications/index.html.haml | 3 +-- spec/features/application_age_spec.rb | 25 +++++++++++++++++++ 4 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 spec/features/application_age_spec.rb diff --git a/app/assets/stylesheets/membership_application.scss b/app/assets/stylesheets/membership_application.scss index fb50e4e1..bd0c23c4 100644 --- a/app/assets/stylesheets/membership_application.scss +++ b/app/assets/stylesheets/membership_application.scss @@ -35,12 +35,4 @@ body.applications.show { display: block; } } -} - -.overdue-highlighted { - background-color: #FFA500; -} - -.almost-due-highlighted { - background-color: yellow; } \ No newline at end of file diff --git a/app/helpers/membership_application_helper.rb b/app/helpers/membership_application_helper.rb index bb6cb6cc..059e3f30 100644 --- a/app/helpers/membership_application_helper.rb +++ b/app/helpers/membership_application_helper.rb @@ -2,9 +2,13 @@ module MembershipApplicationHelper def choose_highlight_class(age) if age >= 7.weeks && age < 2.months - "almost-due-highlighted" + "bg-info" elsif age > 2.months - "overdue-highlighted" + "bg-danger" end end + + def age_in_days(age) + (age/ 1.day).floor + end end \ No newline at end of file diff --git a/app/views/members/applications/index.html.haml b/app/views/members/applications/index.html.haml index e969bcdf..21645a47 100644 --- a/app/views/members/applications/index.html.haml +++ b/app/views/members/applications/index.html.haml @@ -49,9 +49,8 @@ %td= application.yes_votes.size %td= application.no_votes.size %td= application.not_voted_count - -age_in_days = (application.age/ 1.day).floor %td{:class => choose_highlight_class(application.age)} - = "#{age_in_days} days" + = "#{age_in_days(application.age)} days" diff --git a/spec/features/application_age_spec.rb b/spec/features/application_age_spec.rb new file mode 100644 index 00000000..6880f6c3 --- /dev/null +++ b/spec/features/application_age_spec.rb @@ -0,0 +1,25 @@ +require "spec_helper" + +describe "diplaying age on application" do + + before do + @submitted_application = create(:user, state: :applicant).application + @submitted_application.update_attribute(:state, "submitted") + @submitted_application.update_attribute(:submitted_at, 1.week.ago) + end + + before do + page.set_rack_session(user_id: member.id) + end + + context "when logged in as a voting member" do + let(:member) { create(:voting_member) } + + it "displays the correct application age" do + visit members_applications_path + expect(page).to have_content "Age" + #This spec controls the age of the application so the age can be hardcoded in + expect(page).to have_content "7 days" + end + end +end