mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
working on categories and questions
This commit is contained in:
parent
9558aa05ec
commit
4bad7d013c
6 changed files with 35 additions and 11 deletions
6
app/controllers/admin_controller.rb
Normal file
6
app/controllers/admin_controller.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
class AdminController < ApplicationController
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
class Category < ApplicationRecord
|
||||
has_many :questions
|
||||
|
||||
has_many :questions
|
||||
belongs_to :parent_categories, class_name: 'Category', foreign_key: :parent_category_id
|
||||
has_many :child_categories, class_name: 'Category', foreign_key: :parent_category_id
|
||||
|
||||
validates :name, presence: true
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
class Question < ApplicationRecord
|
||||
belongs_to :category
|
||||
|
||||
validates :text, presence: true
|
||||
validates :option1, presence: true
|
||||
|
|
|
|||
3
app/views/admin/index.html.haml
Normal file
3
app/views/admin/index.html.haml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
%p= link_to 'Categories', categories_path
|
||||
|
||||
%p= link_to 'Questions', questions_path
|
||||
|
|
@ -16,7 +16,7 @@ Rails.application.routes.draw do
|
|||
devise_for :users
|
||||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
||||
|
||||
|
||||
get '/admin', to: 'admin#index', as: 'admin'
|
||||
|
||||
root to: "welcome#index"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,22 +3,22 @@ require 'csv'
|
|||
namespace :data do
|
||||
desc "Load in all data"
|
||||
task load: :environment do
|
||||
return if School.count > 0
|
||||
Rake::Task["db:seed"].invoke
|
||||
Rake::Task["data:load_measurements"].invoke
|
||||
# return if School.count > 0
|
||||
# Rake::Task["db:seed"].invoke
|
||||
Rake::Task["data:load_categories"].invoke
|
||||
Rake::Task["data:load_questions"].invoke
|
||||
# Rake::Task["data:load_student_responses"].invoke
|
||||
end
|
||||
|
||||
desc 'Load in measurement data'
|
||||
task load_measurements: :environment do
|
||||
desc 'Load in category data'
|
||||
task load_categories: :environment do
|
||||
measures = JSON.parse(File.read(File.expand_path('../../../data/measures.json', __FILE__)))
|
||||
measures.each_with_index do |measure, index|
|
||||
category = Category.create(
|
||||
name: measure['title'],
|
||||
blurb: measure['blurb'],
|
||||
description: measure['text'],
|
||||
external_id: index
|
||||
external_id: index + 1
|
||||
)
|
||||
|
||||
measure['sub'].keys.sort.each do |key|
|
||||
|
|
@ -86,9 +86,13 @@ namespace :data do
|
|||
questions.each do |question|
|
||||
category = nil
|
||||
question['category'].split('-').each do |external_id|
|
||||
categories = Category
|
||||
categories = category.child_categories if category.present?
|
||||
categories = category.present? ? category.child_categories : Category
|
||||
category = categories.where(external_id: external_id).first
|
||||
if category.nil?
|
||||
puts 'NOTHING'
|
||||
puts external_id
|
||||
puts categories.inspect
|
||||
end
|
||||
end
|
||||
question_text = question['text'].gsub(/[[:space:]]/, ' ').strip
|
||||
if question_text.index('*').nil?
|
||||
|
|
@ -102,7 +106,14 @@ namespace :data do
|
|||
)
|
||||
else
|
||||
variations.each do |variation|
|
||||
measure.questions.create(text: question_text.gsub('.*', variation), answers: question['answers'].to_yaml)
|
||||
category.questions.create(
|
||||
text: question_text.gsub('.*', variation),
|
||||
option1: question['answers'][0],
|
||||
option2: question['answers'][1],
|
||||
option3: question['answers'][2],
|
||||
option4: question['answers'][3],
|
||||
option5: question['answers'][4]
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue