Skip to content

Commit

Permalink
Merge pull request #368 from wearefuturegov/develop
Browse files Browse the repository at this point in the history
TOP-203 regular schedules
  • Loading branch information
apricot13 authored Sep 5, 2024
2 parents ecab78c + 048344c commit a68b94e
Show file tree
Hide file tree
Showing 23 changed files with 1,943 additions and 148 deletions.
8 changes: 5 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ GEM
listen (3.7.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
logger (1.6.1)
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand Down Expand Up @@ -310,7 +311,7 @@ GEM
actionpack (>= 5.0)
railties (>= 5.0)
retriable (3.1.2)
rexml (3.2.6)
rexml (3.3.7)
rspec-core (3.9.2)
rspec-support (~> 3.9.3)
rspec-expectations (3.9.2)
Expand Down Expand Up @@ -340,8 +341,9 @@ GEM
sprockets (> 3.0)
sprockets-rails
tilt
selenium-webdriver (4.18.0)
selenium-webdriver (4.24.0)
base64 (~> 0.2)
logger (~> 1.4)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
Expand Down Expand Up @@ -412,7 +414,7 @@ GEM
railties (>= 5.2)
semantic_range (>= 2.3.0)
webrick (1.7.0)
websocket (1.2.10)
websocket (1.2.11)
websocket-driver (0.7.3)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand Down
56 changes: 28 additions & 28 deletions app/assets/stylesheets/outpost-design-library/_errors.scss
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
.error {
padding: 25px;
margin-bottom: 40px;
background: transparentize($error, 0.9);
border-left: 5px solid $error;

.error{
padding: 25px;
margin-bottom: 40px;
background: transparentize($error, 0.9);
border-left: 5px solid $error;
@media screen and (min-width: $breakpoint-m) {
margin-bottom: 50px;
}

@media screen and (min-width: $breakpoint-m) {
margin-bottom: 50px;
}

&__title{
margin-top: 0px;
margin-bottom: 20px;
line-height: 1.1;
}
&__title {
margin-top: 0px;
margin-bottom: 0px;
line-height: 1.1;
}

&__list {
list-style: none;
margin-bottom: 0px;
padding-left: 0;
&__list {
list-style: none;
margin-bottom: 0px;
margin-top: 20px;
padding-left: 0;

li{
padding-left: 0;
margin-bottom: 10px;
}
*{
@media screen and (min-width: $breakpoint-m) {
font-size: 1.1rem;
}
}
li {
padding-left: 0;
margin-bottom: 10px;
}
* {
@media screen and (min-width: $breakpoint-m) {
font-size: 1.1rem;
}
}
}
}
}
29 changes: 29 additions & 0 deletions app/assets/stylesheets/outpost-design-library/_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@
color: $error;
}
}

&--error {
.field__input {
border-color: $error;
}
}
}

.field-group {
Expand All @@ -109,6 +115,29 @@
}
}

&--three-cols--or {
@media screen and (min-width: $breakpoint-m) {
display: grid;
grid-template-columns: 1fr minmax(auto, max-content) 1fr;
column-gap: 25px;
align-items: flex-end;
}
}

&--four-cols {
@media screen and (min-width: $breakpoint-m) {
display: grid;
grid-template-columns: auto auto auto auto;
column-gap: 25px;
align-items: flex-end;
}
}

&--flex-cols {
display: flex;
flex-direction: column;
}

&--no-top-margin {
margin-top: 0px;
}
Expand Down
75 changes: 40 additions & 35 deletions app/assets/stylesheets/outpost-design-library/_repeaters.scss
Original file line number Diff line number Diff line change
@@ -1,43 +1,48 @@
.repeater{
.repeater {
&__panels {
list-style: none;
padding-left: 0px;
margin-top: 0;
}

&__panels{
list-style: none;
padding-left: 0px;
margin-top: 0;
}
&__panel {
background: $pale;
border: 1px solid $grey4;
position: relative;
padding: 35px 25px;

&__panel{
background: $pale;
border: 1px solid $grey4;
position: relative;
padding: 35px 25px;
&[hidden] {
display: none;
}

&[hidden]{
display: none;
}
&--error {
border-color: $error;
// border-width: 5px;
// background: transparentize($error, 0.9);
}
}

&__closer{
cursor: pointer;
font-size: 0;
position: absolute;
top: 0;
right: 0;
height: 37px;
width: 37px;
border: none;
background: none;
background-image: url(asset_path("clear.svg"));
background-size: 32px;
background-position: center;
background-repeat: no-repeat;
&__closer {
cursor: pointer;
font-size: 0;
position: absolute;
top: 0;
right: 0;
height: 37px;
width: 37px;
border: none;
background: none;
background-image: url(asset_path("clear.svg"));
background-size: 32px;
background-position: center;
background-repeat: no-repeat;

&:hover{
background-color: $grey4;
}
&:hover {
background-color: $grey4;
}

&:focus{
outline: 3px solid $focus;
}
&:focus {
outline: 3px solid $focus;
}
}
}
}
14 changes: 12 additions & 2 deletions app/controllers/admin/services_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Admin::ServicesController < Admin::BaseController
include ServicePreprocessing
before_action :set_service, only: [:update, :destroy]
before_action :load_custom_field_sections, only: [:show, :update, :destroy, :new, :create]
skip_before_action :set_counts, only: :show
Expand Down Expand Up @@ -92,7 +93,9 @@ def load_custom_field_sections
end

def service_params
result_params = params.require(:service).permit(

preprocessed_params = preprocess_regular_schedules(params)
result_params = preprocessed_params.require(:service).permit(
:name,
:organisation_id,
:description,
Expand Down Expand Up @@ -146,9 +149,16 @@ def service_params
regular_schedules_attributes: [
:id,
:service_at_location_id,
:weekday,
:opens_at,
:closes_at,
:weekday,
:dtstart,
:interval,
:freq,
:byday,
:bymonthday,
:until,
:count,
:_destroy,
],
contacts_attributes: [
Expand Down
69 changes: 69 additions & 0 deletions app/controllers/concerns/service_preprocessing.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
module ServicePreprocessing
extend ActiveSupport::Concern

private

# we do a lot of form processing this method is used to clean up the params hash before saving
def preprocess_regular_schedules(params)

if params['service']['regular_schedules_attributes']
params['service']['regular_schedules_attributes'].each do |key, schedule|
if schedule['time_type'] == 'event_time'

# if dtstart is present, use event_opens_at as opens_at and event_closes_at as closes_at
if schedule['dtstart'].present?
schedule['opens_at'] = schedule['event_opens_at'] if schedule['event_opens_at'].present?
schedule['closes_at'] = schedule['event_closes_at'] if schedule['event_closes_at'].present?
end

# if its a repeated event, make sure the correct repeated event fields are present and formatted right
if schedule['repeats']
# puts "Repeats #{schedule['repeats']}, #{schedule['freq']}"
if schedule['freq'] == 'week'
# uses byday only, joins byday array into a string
schedule['byday'] = schedule['byday'].to_unsafe_h.values.reject(&:blank?).join(',') if schedule['byday'].present?
%w[bymonthday byday_month].each do |key|
schedule[key] = nil
end
elsif schedule['freq'] == 'month'
# uses bymonthday, byday, byday_month and weekofmonth
# form validation takes care of both being set
schedule['byday'] = nil
# set byday to the correct format
if schedule['byday_month'].present?
schedule['byday'] = schedule['byday_month'].map { |entry| "#{entry['occurrence']}#{entry['byday']}" }.join(',')
end

end
end

elsif schedule['time_type'] == 'opening_time'
# if its an opening time we dont want dtstart, until or count coming through
%w[dtstart until count repeats].each do |key|
schedule[key] = nil
end

end


# if its not a repeated event make sure the repeated event fields are empty
if !schedule['repeats']
%w[interval freq byday bymonthday byday_month until count].each do |key|
schedule[key] = nil
end
end

# remove unpermitted fields
%w[time_type event_opens_at event_closes_at repeats byday_month].each do |key|
schedule.delete(key)
end
end
end

params
end




end
21 changes: 18 additions & 3 deletions app/controllers/services_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class ServicesController < ApplicationController
include ServicePreprocessing

before_action :no_admins
before_action :set_service, except: [:new, :create]

Expand Down Expand Up @@ -66,7 +68,8 @@ def set_service


def service_params
result_params = params.require(:service).permit(
preprocessed_params = preprocess_regular_schedules(params)
result_params = preprocessed_params.require(:service).permit(
:name,
:description,
:url,
Expand Down Expand Up @@ -113,9 +116,16 @@ def service_params
regular_schedules_attributes: [
:id,
:service_at_location_id,
:weekday,
:opens_at,
:closes_at,
:weekday,
:dtstart,
:interval,
:freq,
:byday,
:bymonthday,
:until,
:count,
:_destroy,
],
contacts_attributes: [
Expand Down Expand Up @@ -156,7 +166,12 @@ def service_params
result_params['local_offer_attributes']['survey_answers'] =
result_params['local_offer_attributes']['survey_answers'].to_h.map{|k,v| { id: k.to_i, answer: v['answer']}}
end

result_params
end

end


end


Loading

0 comments on commit a68b94e

Please sign in to comment.