Skip to content
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

homepage not in crossover #2426

Closed
wants to merge 11 commits into from
1 change: 1 addition & 0 deletions app/controllers/start_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class StartController < ApplicationController
def index
if current_user
@homepage_presenter = HomepagePresenter.new(current_user)
render "home/index"
end
end
Expand Down
26 changes: 9 additions & 17 deletions app/frontend/styles/_data_box.scss
Original file line number Diff line number Diff line change
@@ -1,44 +1,36 @@
.app-data-box-group {
.app-data-box-section {
@include govuk-font($size: 19);
font-weight: bold;
white-space: nowrap;
}

.app-data-box-group {
@include govuk-responsive-margin(4, "top");
}

@media (min-width: 54.0625em) {
.app-data-box-group-one-third {
.app-data-box-group-row {
display: flex;
justify-content: space-between;
column-gap: govuk-spacing(4);
width: 100%;
min-width: 733.33px;
}
}
@media (min-width: 54.0625em) {
.app-data-box-one-third {
width: 33.3333%;
float: left;
}
}

@media (min-width: 54.0625em) {
.app-data-box__underline {
min-width: 733.33px;
}
}
@media (min-width: 54.0625em) {
.app-data-box-group-one-half {
display: flex;
justify-content: space-between;
column-gap: govuk-spacing(4);
width: 100%;
min-width: 733.33px;
}
}

@media (min-width: 54.0625em) {
.app-data-box-one-half {
width: 50%;
float: left;
}
}

@media (min-width: 54.0625em) {
.app-data-box-one-half__underline {
min-width: 733.33px;
Expand Down
76 changes: 0 additions & 76 deletions app/helpers/home_helper.rb

This file was deleted.

109 changes: 109 additions & 0 deletions app/presenters/homepage_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
class HomepagePresenter
include Rails.application.routes.url_helpers
include CollectionTimeHelper

attr_reader :current_year_in_progress_lettings_data, :current_year_completed_lettings_data, :current_year_in_progress_sales_data, :current_year_completed_sales_data, :last_year_in_progress_lettings_data, :last_year_completed_lettings_data, :last_year_in_progress_sales_data, :last_year_completed_sales_data, :incomplete_schemes_data

def initialize(user)
@user = user
@display_sales = should_display_sales?
@in_crossover_period = FormHandler.instance.in_crossover_period?
@current_year = current_collection_start_year
@current_year_in_progress_lettings_data = data_box_data(:lettings, @current_year, :in_progress)
@current_year_completed_lettings_data = data_box_data(:lettings, @current_year, :completed)
@current_year_in_progress_sales_data = data_box_data(:sales, @current_year, :in_progress) if display_sales?
@current_year_completed_sales_data = data_box_data(:sales, @current_year, :completed) if display_sales?
@last_year = @current_year - 1
@last_year_in_progress_lettings_data = data_box_data(:lettings, @last_year, :in_progress) if in_crossover_period?
@last_year_completed_lettings_data = data_box_data(:lettings, @last_year, :completed)
@last_year_in_progress_sales_data = data_box_data(:sales, @last_year, :in_progress) if in_crossover_period? && display_sales?
@last_year_completed_sales_data = data_box_data(:sales, @last_year, :completed) if display_sales?
if display_schemes?
@incomplete_schemes_data = {
count: @user.schemes.incomplete.count,
text: data_box_text(type: :schemes, status: :incomplete),
path: schemes_path(status: [:incomplete], owning_organisation_select: "all"),
}
end
end

def title_text_for_user
if @user.support?
"Manage all data"
elsif @user.data_coordinator?
"Manage your organisation's logs"
else
"Manage logs assigned to you"
end
end

def display_sales?
@display_sales
end

def in_crossover_period?
false
end

def subheading_for_current_year
subheading_from_year @current_year
end

def subheading_for_last_year
subheading = subheading_from_year @last_year
in_crossover_period? ? subheading : "#{subheading} (Closed collection year)"
end

def display_schemes?
!@user.data_provider?
end

private

def subheading_from_year(year)
"#{year} to #{year + 1} Logs"
end

def data_box_data(type, year, status)
{
count: logs_count(type:, year:, status:),
text: data_box_text(type:, status:),
path: logs_link(type:, year:, status:),
}
end

def data_box_text(type:, status:)
text = [status, type]
text.reverse! if status == :in_progress
text.join(" ").humanize
end

def logs_link(type:, year:, status:)
params = {
status: [status],
years: [year],
assigned_to: @user.data_provider? ? "you" : "all",
owning_organisation_select: "all",
managing_organisation_select: "all",
}
case type
when :lettings then lettings_logs_path(params)
when :sales then sales_logs_path(params)
end
end

def logs_count(type:, year:, status:)
query = case type
when :lettings then @user.lettings_logs
when :sales then @user.sales_logs
end
query = query.where(created_by: @user) if @user.data_provider?
query.filter_by_year(year)
.where(status:)
.count
end

def should_display_sales?
@user.support? || @user.organisation.sales_logs.exists?
end
end
3 changes: 3 additions & 0 deletions app/views/home/_blue_box_link.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="app-data-box__lower">
<%= govuk_link_to text, path, class: "govuk-link--inverse" %>
</div>
7 changes: 2 additions & 5 deletions app/views/home/_data_box.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<div class="app-data-box__upper">
<div class="app-data-box__count">
<%= govuk_link_to data_count(@current_user, type), data_path(@current_user, type), class: "govuk-link--no-visited-state govuk-link--no-underline" %>
<%= govuk_link_to data_box[:count], data_box[:path], class: "govuk-link--no-visited-state govuk-link--no-underline" %>
</div>
<%= govuk_link_to data_subheading(@current_user, type), data_path(@current_user, type), class: "govuk-link--no-visited-state" %>
</div>
<div class="app-data-box__lower">
<%= govuk_link_to view_all_text(type), view_all_path(type), class: "govuk-link--inverse" %>
<%= govuk_link_to data_box[:text], data_box[:path], class: "govuk-link--no-visited-state" %>
</div>
8 changes: 8 additions & 0 deletions app/views/home/_data_box_row_of_two.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="app-data-box-one-half">
<%= render partial: "home/data_box", object: left_data_box %>
</div>
<% if right_data_box %>
<div class="app-data-box-one-half">
<%= render partial: "home/data_box", object: right_data_box %>
</div>
<% end %>
8 changes: 8 additions & 0 deletions app/views/home/_data_box_two_by_two.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="app-data-box-one-half">
<%= render partial: "home/data_box", object: top_left_data_box %>
<%= render partial: "home/data_box", object: bottom_left_data_box %>
</div>
<div class="app-data-box-one-half">
<%= render partial: "home/data_box", object: top_right_data_box %>
<%= render partial: "home/data_box", object: bottom_right_data_box %>
</div>
Loading
Loading