mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-09 07:28:41 -07:00
working on schedules
This commit is contained in:
parent
72418edd7c
commit
2fb55a7443
26 changed files with 726 additions and 1 deletions
3
app/assets/javascripts/schedules.coffee
Normal file
3
app/assets/javascripts/schedules.coffee
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||
3
app/assets/stylesheets/schedules.scss
Normal file
3
app/assets/stylesheets/schedules.scss
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the schedules controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
64
app/controllers/schedules_controller.rb
Normal file
64
app/controllers/schedules_controller.rb
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
class SchedulesController < ApplicationController
|
||||
before_action :set_school
|
||||
before_action :set_schedule, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
# GET schools/1/schedules
|
||||
def index
|
||||
@schedules = @school.schedules
|
||||
end
|
||||
|
||||
# GET schools/1/schedules/1
|
||||
def show
|
||||
end
|
||||
|
||||
# GET schools/1/schedules/new
|
||||
def new
|
||||
@schedule = @school.schedules.build
|
||||
end
|
||||
|
||||
# GET schools/1/schedules/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST schools/1/schedules
|
||||
def create
|
||||
@schedule = @school.schedules.build(schedule_params)
|
||||
|
||||
if @schedule.save
|
||||
redirect_to([@schedule.school, @schedule], notice: 'Schedule was successfully created.')
|
||||
else
|
||||
render action: 'new'
|
||||
end
|
||||
end
|
||||
|
||||
# PUT schools/1/schedules/1
|
||||
def update
|
||||
if @schedule.update_attributes(schedule_params)
|
||||
redirect_to([@schedule.school, @schedule], notice: 'Schedule was successfully updated.')
|
||||
else
|
||||
render action: 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE schools/1/schedules/1
|
||||
def destroy
|
||||
@schedule.destroy
|
||||
|
||||
redirect_to @school
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_school
|
||||
@school = School.find(params[:school_id])
|
||||
end
|
||||
|
||||
def set_schedule
|
||||
@schedule = @school.schedules.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a trusted parameter "white list" through.
|
||||
def schedule_params
|
||||
params.require(:schedule).permit(:name, :description, :school_id, :frequency_hours, :start_date, :end_date, :active, :random, :recipient_list_id, :question_list_id)
|
||||
end
|
||||
end
|
||||
2
app/helpers/schedules_helper.rb
Normal file
2
app/helpers/schedules_helper.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
module SchedulesHelper
|
||||
end
|
||||
11
app/models/schedule.rb
Normal file
11
app/models/schedule.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
class Schedule < ApplicationRecord
|
||||
belongs_to :school
|
||||
belongs_to :recipient_list
|
||||
belongs_to :question_list
|
||||
|
||||
validates :name, presence: true
|
||||
validates :recipient_list, presence: true
|
||||
validates :question_list, presence: true
|
||||
|
||||
|
||||
end
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
class School < ApplicationRecord
|
||||
has_many :schedules
|
||||
has_many :recipient_lists
|
||||
belongs_to :district
|
||||
has_many :recipients
|
||||
|
|
|
|||
51
app/views/schedules/_form.html.haml
Normal file
51
app/views/schedules/_form.html.haml
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
= form_for([@schedule.school, @schedule]) do |f|
|
||||
- if @schedule.errors.any?
|
||||
#error_explanation
|
||||
%h2
|
||||
= pluralize(@schedule.errors.count, "error")
|
||||
prohibited this schedule from being saved:
|
||||
%ul
|
||||
- @schedule.errors.full_messages.each do |msg|
|
||||
%li= msg
|
||||
.field
|
||||
= f.label :name
|
||||
%br/
|
||||
= f.text_field :name
|
||||
.field
|
||||
= f.label :description
|
||||
%br/
|
||||
= f.text_area :description
|
||||
.field
|
||||
= f.label :school_id
|
||||
%br/
|
||||
= f.number_field :school_id
|
||||
.field
|
||||
= f.label :frequency_hours
|
||||
%br/
|
||||
= f.number_field :frequency_hours
|
||||
.field
|
||||
= f.label :start_date
|
||||
%br/
|
||||
= f.date_select :start_date
|
||||
.field
|
||||
= f.label :end_date
|
||||
%br/
|
||||
= f.date_select :end_date
|
||||
.field
|
||||
= f.label :active
|
||||
%br/
|
||||
= f.check_box :active
|
||||
.field
|
||||
= f.label :random
|
||||
%br/
|
||||
= f.check_box :random
|
||||
.field
|
||||
= f.label :recipient_list_id
|
||||
%br/
|
||||
= f.number_field :recipient_list_id
|
||||
.field
|
||||
= f.label :question_list_id
|
||||
%br/
|
||||
= f.number_field :question_list_id
|
||||
.actions
|
||||
= f.submit
|
||||
5
app/views/schedules/edit.html.haml
Normal file
5
app/views/schedules/edit.html.haml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
%h1 Editing schedule
|
||||
= render 'form'
|
||||
= link_to 'Show', [@schedule.school, @schedule]
|
||||
|
|
||||
= link_to 'Back', school_schedules_path(@schedule.school)
|
||||
33
app/views/schedules/index.html.haml
Normal file
33
app/views/schedules/index.html.haml
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
%h1 Listing schedules
|
||||
%table
|
||||
%tr
|
||||
%th Name
|
||||
%th Description
|
||||
%th School
|
||||
%th Frequency hours
|
||||
%th Start date
|
||||
%th End date
|
||||
%th Active
|
||||
%th Random
|
||||
%th Recipient list
|
||||
%th Question list
|
||||
%th
|
||||
%th
|
||||
%th
|
||||
- @schedules.each do |schedule|
|
||||
%tr
|
||||
%td= schedule.name
|
||||
%td= schedule.description
|
||||
%td= schedule.school.name
|
||||
%td= schedule.frequency_hours
|
||||
%td= schedule.start_date
|
||||
%td= schedule.end_date
|
||||
%td= schedule.active
|
||||
%td= schedule.random
|
||||
%td= schedule.recipient_list.name
|
||||
%td= schedule.question_list.name
|
||||
%td= link_to 'Show', [schedule.school, schedule]
|
||||
%td= link_to 'Edit', edit_school_schedule_path(schedule.school, schedule)
|
||||
%td= link_to 'Destroy', [schedule.school, schedule], :confirm => 'Are you sure?', :method => :delete
|
||||
%br/
|
||||
= link_to 'New Schedule', new_school_schedule_path(@school)
|
||||
3
app/views/schedules/new.html.haml
Normal file
3
app/views/schedules/new.html.haml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
%h1 New schedule
|
||||
= render 'form'
|
||||
= link_to 'Back', school_schedules_path(@schedule.school)
|
||||
34
app/views/schedules/show.html.haml
Normal file
34
app/views/schedules/show.html.haml
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
%p#notice= notice
|
||||
%p
|
||||
%b Name:
|
||||
= @schedule.name
|
||||
%p
|
||||
%b Description:
|
||||
= @schedule.description
|
||||
%p
|
||||
%b School:
|
||||
= @schedule.school.name
|
||||
%p
|
||||
%b Frequency hours:
|
||||
= @schedule.frequency_hours
|
||||
%p
|
||||
%b Start date:
|
||||
= @schedule.start_date
|
||||
%p
|
||||
%b End date:
|
||||
= @schedule.end_date
|
||||
%p
|
||||
%b Active:
|
||||
= @schedule.active
|
||||
%p
|
||||
%b Random:
|
||||
= @schedule.random
|
||||
%p
|
||||
%b Recipient list:
|
||||
= @schedule.recipient_list.name
|
||||
%p
|
||||
%b Question list:
|
||||
= @schedule.question_list.name
|
||||
= link_to 'Edit', edit_school_schedule_path(@schedule.school, @schedule)
|
||||
|
|
||||
= link_to 'Back', school_schedules_path(@schedule.school)
|
||||
4
app/views/school/schedules/index.json.jbuilder
Normal file
4
app/views/school/schedules/index.json.jbuilder
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
json.array!(@school_schedules) do |school_schedule|
|
||||
json.extract! school_schedule, :id, :name, :description, :school_id, :frequency_hours, :start_date, :end_date, :active, :random, :recipient_list_id, :question_list_id
|
||||
json.url school_schedule_url(school_schedule, format: :json)
|
||||
end
|
||||
1
app/views/school/schedules/show.json.jbuilder
Normal file
1
app/views/school/schedules/show.json.jbuilder
Normal file
|
|
@ -0,0 +1 @@
|
|||
json.extract! @school_schedule, :id, :name, :description, :school_id, :frequency_hours, :start_date, :end_date, :active, :random, :recipient_list_id, :question_list_id, :created_at, :updated_at
|
||||
Loading…
Add table
Add a link
Reference in a new issue