Skip to content

Commit

Permalink
Merge branch 'master' into aws-eb-test
Browse files Browse the repository at this point in the history
  • Loading branch information
urbanwide committed Jan 28, 2025
2 parents 2f80233 + b9a0222 commit d053f27
Show file tree
Hide file tree
Showing 35 changed files with 334 additions and 147 deletions.
6 changes: 5 additions & 1 deletion app/controllers/activity_categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ def index
@pupil_categories = ActivityCategory.pupil.by_name
@activity_categories = ActivityCategory.featured.by_name.select { |activity_category| activity_category.activity_types.active.count >= 4 }
@activity_count = ActivityType.active_and_not_custom.count
@programme_types = ProgrammeType.featured
if Flipper.enabled?(:todos, current_user)
@programme_types = ProgrammeType.featured.with_task_type(ActivityType)
else
@programme_types = ProgrammeType.featured
end
end

def show
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/intervention_type_groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ class InterventionTypeGroupsController < ApplicationController

def index
@intervention_type_groups = @intervention_type_groups.by_name
if Flipper.enabled?(:todos, current_user)
@programme_types = ProgrammeType.featured.with_task_type(InterventionType)
end
end

def show
Expand Down
10 changes: 8 additions & 2 deletions app/controllers/programme_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ def index
end

def show
route_not_found unless @programme_type.active
if Flipper.enabled?(:todos)
route_not_found unless @programme_type.active && @programme_type.has_todos?
else
route_not_found unless @programme_type.active
end
end

private

def user_progress
@user_progress = Programmes::UserProgress.new(current_user)
if !Flipper.enabled?(:todos) || Flipper.enabled?(:todos_old)
@user_progress = Programmes::UserProgress.new(current_user)
end
end
end
12 changes: 12 additions & 0 deletions app/models/concerns/todos/assignable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ module Assignable

accepts_nested_attributes_for :activity_type_todos, allow_destroy: true
accepts_nested_attributes_for :intervention_type_todos, allow_destroy: true

scope :with_task_type, ->(task_type) {
where(id: ProgrammeType.joins(:todos).where(todos: { task_type: task_type.name }).distinct)
}
end

def has_todos?
todos.any?
end

def no_todos?
todos.none?
end

# Has the provided school already completed all activity & intervention types this year?
Expand Down
24 changes: 4 additions & 20 deletions app/models/concerns/todos/completable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,24 @@ module Completable
scope :completable, -> { raise NoMethodError, 'Implement completable scope in subclass!' }
end

def assignable_todos
assignable.todos
end

def assignable_todo_ids
assignable_todos.ids
end

def completed_todo_ids
completed_todos.pluck(:todo_id)
end

def has_todos?
assignable_todo_ids.any?
end

def nothing_todo?
assignable_todo_ids.none?
end

def completable?
has_todos? && todos_complete?
assignable.has_todos? && todos_complete?
end

def todos_incomplete?
(assignable_todo_ids - completed_todo_ids).any?
(assignable.todos.ids - completed_todo_ids).any?
end

def todos_complete?
(assignable_todo_ids - completed_todo_ids).empty?
(assignable.todos.ids - completed_todo_ids).empty?
end

def uncompleted_todos
assignable_todos - todos_completed
assignable.todos - todos_completed
end

def uncompleted_tasks
Expand Down
2 changes: 1 addition & 1 deletion app/models/intervention_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class InterventionType < ApplicationRecord
before_save :copy_searchable_attributes

def actions_for_school(school)
observations.for_school(school)
observations.visible.for_school(school)
end

# override default name for this resource in transifex
Expand Down
6 changes: 4 additions & 2 deletions app/models/programme_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class ProgrammeType < ApplicationRecord
translates :document_link, type: :string, fallbacks: { cy: :en }

t_has_one_attached :image

## these two relationships to be removed when todos feature removed
has_many :programme_type_activity_types
has_many :activity_types, through: :programme_type_activity_types

Expand Down Expand Up @@ -98,8 +100,8 @@ def activity_types_and_school_activity(school)
end

def repeatable?(school)
# Does the school have any programmes for this programme type completed before the beginning of this academic year?
school.programmes.where(programme_type: self).completed.where(ended_on: ..school.current_academic_year.start_date).any?
# Only allow a repeat if the school hasn't completed this programe type this academic year
school.programmes.where(programme_type: self).completed.where(ended_on: school.current_academic_year.start_date..).none?
end

# Provide a list of activity types a school has already completed this year for this programme type
Expand Down
7 changes: 7 additions & 0 deletions app/models/school.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,18 @@ class ProcessDataError < StandardError; end
has_many :school_target_events, inverse_of: :school
has_many :audits, inverse_of: :school

# relationships to be removed when :todos removed
has_many :audit_activity_types, -> { distinct }, through: :audits, source: :activity_types
has_many :audit_intervention_types, -> { distinct }, through: :audits, source: :intervention_types

has_many :audit_todos, through: :audits, source: :todos
has_many :audit_activity_type_tasks, through: :audit_todos, source: :task, source_type: 'ActivityType'
has_many :audit_intervention_type_tasks, through: :audit_todos, source: :task, source_type: 'InterventionType'

has_many :programmes, inverse_of: :school
has_many :programme_types, through: :programmes

# relationships to be removed when :todos removed
has_many :programme_activity_types, through: :programmes, source: :activity_types

has_many :alerts, inverse_of: :school
Expand Down
4 changes: 2 additions & 2 deletions app/models/todo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def complete_for?(completable:)
end

def latest_recording_for(completable:)
recordings_for(school: completable.school).in_academic_year_for(completable.school, Time.zone.now).by_date(:desc).first
recordings_for(school: completable.school).in_academic_year_for(completable.school, Time.zone.now).by_date(:asc).order(id: :asc).last
end

private
Expand All @@ -59,7 +59,7 @@ def recordings_for(school:)
when 'ActivityType'
school.activities.where(activity_type: task)
when 'InterventionType'
school.observations.intervention.where(intervention_type: task)
school.observations.intervention.visible.where(intervention_type: task)
else
raise StandardError, 'Unsupported task type'
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/completables/progress.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def uncompleted_scores
end

def available_count
completable.assignable_todos.count
completable.assignable.todos.count
end

def completed_count
Expand Down
3 changes: 3 additions & 0 deletions app/services/observation_removal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ def process
@observation.destroy
else
@observation.update_attribute(:visible, false)
if Flipper.enabled?(:todos)
CompletedTodo.where(recording: @observation).destroy_all if @observation.intervention?
end
end
end
end
6 changes: 5 additions & 1 deletion app/services/recommendations/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ def alert_tasks(alert)
end

def audit_tasks
school.audit_intervention_types
if Flipper.enabled?(:todos)
school.audit_intervention_type_tasks
else
school.audit_intervention_types
end
end

def task_tasks(task)
Expand Down
6 changes: 5 additions & 1 deletion app/services/recommendations/activities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ def alert_tasks(alert)
end

def audit_tasks
with_key_stage(school.audit_activity_types)
if Flipper.enabled?(:todos)
with_key_stage(school.audit_activity_type_tasks)
else
with_key_stage(school.audit_activity_types)
end
end

def task_tasks(task)
Expand Down
14 changes: 0 additions & 14 deletions app/views/activity_categories/_programme_types.html.erb

This file was deleted.

16 changes: 1 addition & 15 deletions app/views/activity_categories/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,7 @@
<%= render 'pupil_categories', activity_categories: @pupil_categories.first(4) %>
<% end %>

<% if !@programme_types.blank? %>
<div class="row mt-3 bg-light">
<div class="col">
<div class="d-flex justify-content-between align-items-center">
<h4><%= t('activity_categories.our_programmes.title') %></h4>
<div>
<%= link_to t('activity_categories.view_all_programmes'), programme_types_path,
class: 'btn btn-default' %>
</div>
</div>
<p><%= t('activity_categories.our_programmes.introduction') %></p>
</div>
</div>
<%= render 'programme_types', programme_types: @programme_types.first(4) %>
<% end %>
<%= render 'shared/tasks/programme_types', programme_types: @programme_types %>

<% @activity_categories.each do |activity_category| %>
<div class="row mt-3">
Expand Down
4 changes: 4 additions & 0 deletions app/views/intervention_type_groups/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@

<%= render 'schools/prompt_recommended', scope: :adult %>

<% if Flipper.enabled?(:todos, current_user) %>
<%= render 'shared/tasks/programme_types', programme_types: @programme_types %>
<% end %>

<% @intervention_type_groups.each do |intervention_type_group| %>
<div class="row mt-3">
<div class="col">
Expand Down
7 changes: 7 additions & 0 deletions app/views/programme_types/_intention.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% if programme_type.activity_type_todos.none? %>
<%= render IconComponent.new(name: 'people-group') %> <%= t('programme_types.intention.adults') %>
<% elsif programme_type.intervention_type_todos.none? %>
<%= render IconComponent.new(name: 'book-open-reader') %> <%= t('programme_types.intention.pupils') %>
<% else %>
<%= render IconComponent.new(name: 'school') %> <%= t('programme_types.intention.all') %>
<% end %>
45 changes: 45 additions & 0 deletions app/views/programme_types/_programme_type.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<% programme = programme_type.programme_for_school(current_user_school) if current_user_school %>

<div class="row mt-4">
<div class="col-sm-2">
<%= link_to programme_type_path(programme_type) do %>
<%= render 'programme_types/image', programme_type: programme_type, css_class: 'activity-card-img' %>
<% end %>
</div>
<div class="col-sm-8">
<h4><strong>
<%= link_to programme_type.title, programme_type_path(programme_type), style: 'text-decoration: none;' %>
</strong></h4>
<% if programme&.completed? %>
<p>
<span class="h4 check">
<%= fa_icon('flag-checkered text-success') %>
</span>
<%= t('programme_types.cards.you_have_already_completed_this_programme') %>
</p>
<% elsif programme&.started? %>
<p>
<span class="h4 check">
<%= far_icon('check-circle text-success') %>
</span>
<%= t('programme_types.cards.you_have_already_started_this_programme') %>
</p>
<% end %>
<p>
<%= programme_type.short_description %>
</p>
<p>
<%= render 'intention', programme_type: %>
</p>
<p><%= t('programme_types.cards.bonus_points_html',
bonus_score: tag.span(programme_type.bonus_score, class: 'badge badge-success')) %></p>
</div>
<div class="col-sm-2 align-self-center">
<% if programme&.started? %>
<%= link_to t('programme_types.cards.continue'), programme_type_path(programme_type),
class: 'btn btn-primary btn-lg' %>
<% else %>
<%= link_to t('programme_types.cards.view'), programme_type_path(programme_type), class: 'btn btn-primary btn-lg' %>
<% end %>
</div>
</div>
8 changes: 7 additions & 1 deletion app/views/programme_types/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@
</div>
</div>

<%= render "cards", programme_types: @programme_types, user_progress: @user_progress %>
<% if Flipper.enabled?(:todos, current_user) %>
<% @programme_types.each do |programme_type| %>
<%= render('programme_type', programme_type:) if programme_type.has_todos? %>
<% end %>
<% else %>
<%= render 'cards', programme_types: @programme_types, user_progress: @user_progress %>
<% end %>
5 changes: 4 additions & 1 deletion app/views/programme_types/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<div class="col-md-6">
<h2><%= @programme_type.title %></h2>
<p><%= @programme_type.short_description %></p>
<% if Flipper.enabled?(:todos) %>
<p><%= render 'intention', programme_type: @programme_type %></p>
<% end %>
<p><%= t('programme_types.cards.bonus_points_html',
bonus_score: tag.span(@programme_type.bonus_score, class: 'badge badge-success')) %></p>
</div>
Expand Down Expand Up @@ -43,7 +46,7 @@
<%= render 'programme_types/prompts/prompt', programme_type: @programme_type, school: current_user_school %>
<% elsif programme&.completed? %>
<%= render 'programme_types/prompts/completed', programme: programme %>
<% elsif programme %>
<% elsif programme&.started? %>
<%= render 'programme_types/prompts/started', programme: programme %>
<% end %>

Expand Down
2 changes: 1 addition & 1 deletion app/views/schools/audits/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<% if Flipper.enabled?(:todos, current_user) %>
<% if @audit.has_todos? %>
<p>
<%= t('schools.audits.show.completing_all_of_these_activities_will_award_you') %>
<%= t('schools.audits.show.completed_points') %>
<span class="badge badge-success"><%= SiteSettings.current&.audit_activities_bonus_points %></span>
<%= t('schools.audits.show.points', count: SiteSettings.current&.audit_activities_bonus_points) %>
</p>
Expand Down
33 changes: 33 additions & 0 deletions app/views/shared/tasks/_programme_types.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<% if programme_types&.any? && programme_types.count >= 4 %>
<div class="row mt-3 bg-light">
<div class="col">
<div class="d-flex justify-content-between align-items-center">
<h4><%= t('activity_categories.our_programmes.title') %></h4>
<div>
<%= link_to t('activity_categories.view_all_programmes'), programme_types_path,
class: 'btn btn-default' %>
</div>
</div>
<% if Flipper.enabled?(:todos, current_user) %>
<p><%= t('activity_categories.our_programmes.introduction') %></p>
<% else %>
<p><%= t('activity_categories.our_programmes.introduction_activities') %></p>
<% end %>
</div>
</div>

<div class="card-deck justify-content-center bg-light pb-4 activities-deck" id="programme-types">
<% programme_types.first(4).each do |programme_type| %>
<div class="card col-sm-3">
<%= link_to programme_type_path(programme_type) do %>
<%= render 'programme_types/image', programme_type: programme_type, css_class: '' %>
<% end %>
<div class="card-body">
<p class="card-text">
<%= programme_type.title %>
</p>
</div>
</div>
<% end %>
</div>
<% end %>
Loading

0 comments on commit d053f27

Please sign in to comment.