mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
working on question_lists
This commit is contained in:
parent
d731049fc6
commit
cc84c3bbda
26 changed files with 498 additions and 10 deletions
3
app/assets/javascripts/question_lists.coffee
Normal file
3
app/assets/javascripts/question_lists.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/question_lists.scss
Normal file
3
app/assets/stylesheets/question_lists.scss
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the QuestionLists controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
74
app/controllers/question_lists_controller.rb
Normal file
74
app/controllers/question_lists_controller.rb
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
class QuestionListsController < ApplicationController
|
||||
before_action :set_question_list, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
# GET /question_lists
|
||||
# GET /question_lists.json
|
||||
def index
|
||||
@question_lists = QuestionList.all
|
||||
end
|
||||
|
||||
# GET /question_lists/1
|
||||
# GET /question_lists/1.json
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /question_lists/new
|
||||
def new
|
||||
@question_list = QuestionList.new
|
||||
end
|
||||
|
||||
# GET /question_lists/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /question_lists
|
||||
# POST /question_lists.json
|
||||
def create
|
||||
@question_list = QuestionList.new(question_list_params)
|
||||
|
||||
respond_to do |format|
|
||||
if @question_list.save
|
||||
format.html { redirect_to @question_list, notice: 'Question list was successfully created.' }
|
||||
format.json { render :show, status: :created, location: @question_list }
|
||||
else
|
||||
format.html { render :new }
|
||||
format.json { render json: @question_list.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /question_lists/1
|
||||
# PATCH/PUT /question_lists/1.json
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @question_list.update(question_list_params)
|
||||
format.html { redirect_to @question_list, notice: 'Question list was successfully updated.' }
|
||||
format.json { render :show, status: :ok, location: @question_list }
|
||||
else
|
||||
format.html { render :edit }
|
||||
format.json { render json: @question_list.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /question_lists/1
|
||||
# DELETE /question_lists/1.json
|
||||
def destroy
|
||||
@question_list.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to question_lists_url, notice: 'Question list was successfully destroyed.' }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_question_list
|
||||
@question_list = QuestionList.find(params[:id])
|
||||
end
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def question_list_params
|
||||
params.require(:question_list).permit(:name, :description, question_id_array: [])
|
||||
end
|
||||
end
|
||||
2
app/helpers/question_lists_helper.rb
Normal file
2
app/helpers/question_lists_helper.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
module QuestionListsHelper
|
||||
end
|
||||
26
app/models/question_list.rb
Normal file
26
app/models/question_list.rb
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
class QuestionList < ApplicationRecord
|
||||
|
||||
validates :name, presence: true
|
||||
validates :question_ids, presence: true
|
||||
|
||||
attr_accessor :question_id_array
|
||||
before_validation :convert_question_id_array
|
||||
after_initialize :set_question_id_array
|
||||
|
||||
def questions
|
||||
question_id_array.collect { |id| Question.where(id: id).first }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def convert_question_id_array
|
||||
return if question_id_array.blank?
|
||||
self.question_ids = question_id_array.reject { |id| id.to_s.empty? }.join(',')
|
||||
end
|
||||
|
||||
def set_question_id_array
|
||||
return if question_ids.blank?
|
||||
self.question_id_array = question_ids.split(',').map(&:to_i)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
- categories = [category]
|
||||
- categories << category while (category = category.parent_category)
|
||||
- categories << category while (category = category.parent_category).present?
|
||||
= categories.reverse.map { |category| link_to(category.name, category) }.join(' | ').html_safe
|
||||
|
|
|
|||
20
app/views/question_lists/_form.html.haml
Normal file
20
app/views/question_lists/_form.html.haml
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
= form_for(question_list) do |f|
|
||||
- if question_list.errors.any?
|
||||
#error_explanation
|
||||
%h2
|
||||
= pluralize(question_list.errors.count, "error")
|
||||
prohibited this question_list from being saved:
|
||||
%ul
|
||||
- question_list.errors.full_messages.each do |message|
|
||||
%li= message
|
||||
.field
|
||||
= f.label :name
|
||||
= f.text_field :name
|
||||
.field
|
||||
= f.label :description
|
||||
= f.text_area :description
|
||||
.field
|
||||
= f.label :question_ids
|
||||
= f.text_area :question_ids
|
||||
.actions
|
||||
= f.submit
|
||||
5
app/views/question_lists/edit.html.haml
Normal file
5
app/views/question_lists/edit.html.haml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
%h1 Editing Question List
|
||||
= render 'form', question_list: @question_list
|
||||
= link_to 'Show', @question_list
|
||||
|
|
||||
= link_to 'Back', question_lists_path
|
||||
20
app/views/question_lists/index.html.haml
Normal file
20
app/views/question_lists/index.html.haml
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
%p#notice= notice
|
||||
%h1 Question Lists
|
||||
%table
|
||||
%thead
|
||||
%tr
|
||||
%th Name
|
||||
%th Description
|
||||
%th Question ids
|
||||
%th{:colspan => "3"}
|
||||
%tbody
|
||||
- @question_lists.each do |question_list|
|
||||
%tr
|
||||
%td= question_list.name
|
||||
%td= question_list.description
|
||||
%td= question_list.question_ids
|
||||
%td= link_to 'Show', question_list
|
||||
%td= link_to 'Edit', edit_question_list_path(question_list)
|
||||
%td= link_to 'Destroy', question_list, method: :delete, data: { confirm: 'Are you sure?' }
|
||||
%br/
|
||||
= link_to 'New Question List', new_question_list_path
|
||||
4
app/views/question_lists/index.json.jbuilder
Normal file
4
app/views/question_lists/index.json.jbuilder
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
json.array!(@question_lists) do |question_list|
|
||||
json.extract! question_list, :id, :name, :description, :question_ids
|
||||
json.url question_list_url(question_list, format: :json)
|
||||
end
|
||||
3
app/views/question_lists/new.html.haml
Normal file
3
app/views/question_lists/new.html.haml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
%h1 New Question List
|
||||
= render 'form', question_list: @question_list
|
||||
= link_to 'Back', question_lists_path
|
||||
13
app/views/question_lists/show.html.haml
Normal file
13
app/views/question_lists/show.html.haml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
%p#notice= notice
|
||||
%p
|
||||
%strong Name:
|
||||
= @question_list.name
|
||||
%p
|
||||
%strong Description:
|
||||
= @question_list.description
|
||||
%p
|
||||
%strong Question ids:
|
||||
= @question_list.question_ids
|
||||
= link_to 'Edit', edit_question_list_path(@question_list)
|
||||
|
|
||||
= link_to 'Back', question_lists_path
|
||||
1
app/views/question_lists/show.json.jbuilder
Normal file
1
app/views/question_lists/show.json.jbuilder
Normal file
|
|
@ -0,0 +1 @@
|
|||
json.extract! @question_list, :id, :name, :description, :question_ids, :created_at, :updated_at
|
||||
|
|
@ -20,7 +20,10 @@
|
|||
%p
|
||||
%strong Category:
|
||||
|
||||
= render partial: 'categories/full_path', locals: {category: @question.category}
|
||||
- if @question.category.present?
|
||||
= render partial: 'categories/full_path', locals: {category: @question.category}
|
||||
- else
|
||||
No Category
|
||||
|
||||
= link_to 'Edit', edit_question_path(@question)
|
||||
|
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue