From a8862d1734a3afd0ba199766fcdefee5cae96f18 Mon Sep 17 00:00:00 2001 From: Jared Cosulich Date: Mon, 13 Mar 2017 17:45:19 -0400 Subject: [PATCH] working on displaying data --- app/assets/stylesheets/school_categories.scss | 155 +++++++++--------- app/controllers/categories_controller.rb | 2 + app/controllers/schools_controller.rb | 2 +- app/models/category.rb | 13 +- app/models/school_category.rb | 2 +- app/views/categories/_breadcrumbs.html.haml | 2 + app/views/categories/show.html.haml | 54 +++--- app/views/layouts/_school_header.html.haml | 10 ++ .../_school_category.html.haml | 8 +- app/views/schools/show.html.haml | 10 +- 10 files changed, 134 insertions(+), 124 deletions(-) create mode 100644 app/views/categories/_breadcrumbs.html.haml create mode 100644 app/views/layouts/_school_header.html.haml diff --git a/app/assets/stylesheets/school_categories.scss b/app/assets/stylesheets/school_categories.scss index 2e5d54a2..bfb69d16 100644 --- a/app/assets/stylesheets/school_categories.scss +++ b/app/assets/stylesheets/school_categories.scss @@ -10,95 +10,104 @@ } } -.indicator { - padding-top: 6px; - height: 90px; - - .indicator-circle { - height: 100%; - position: relative; +.indicator-container { + .indicator { + padding-top: 6px; + height: 90px; - .indicator-zones { - width: 100%; + .indicator-circle { height: 100%; + position: relative; - div { + .indicator-zones { + width: 100%; height: 100%; - width: 20%; - float: left; - } - .zone0 { - background-color: orange; - } - .zone1 { - background-color: yellow; - } - .zone2 { - background-color: lightgreen; + div { + height: 100%; + width: 20%; + float: left; + } + + .zone0 { + background-color: orange; + } + .zone1 { + background-color: yellow; + } + .zone2 { + background-color: lightgreen; + } + .zone3 { + background-color: green; + } + .zone4 { + background: repeating-linear-gradient(45deg, lightgray, green 15px); + } } - .zone3 { - background-color: green; - } - .zone4 { - background: repeating-linear-gradient(45deg, lightgray, green 15px); - } - } - - .average { - position: absolute; - width: 10%; - height: 125%; - top: -3px; - border: 2px dashed black; - font-weight: bold; - font-size: 12px; - span { - text-align: center; + .average { position: absolute; - width: 7.75em; - } - } - } -} - -.indicator { - height: 30px; - - .indicator-circle { - width: 100%; - height: 100%; - - .average { - span { - top: -13px; - left: -2.5em; - font-size: 10px; - border: none; - line-height: 10px; + width: 10%; + height: 107%; + top: -3px; + border: 2px dashed black; + font-weight: bold; + font-size: 14px; + + span { + text-align: center; + position: absolute; + width: 7.75em; + margin-top: -1.5em; + } } } } - &.small { - height: 90px; + &.short { + .indicator { + height: 30px; - .indicator-circle { - width: 90px; - overflow: hidden; + .indicator-circle { + width: 100%; + height: 100%; - .indicator-zones { - width: 900px; - } + .average { + height: 120%; - .average { - border: none; - text-align: center; - width: 100%; - line-height: 90px; + span { + left: -1.5em; + font-size: 10px; + border: none; + line-height: 10px; + } + } } } } - } + +// .indicator { +// +// &.small { +// height: 90px; +// +// .indicator-circle { +// width: 90px; +// overflow: hidden; +// +// .indicator-zones { +// width: 900px; +// } +// +// .average { +// border: none; +// text-align: center; +// width: 100%; +// line-height: 90px; +// } +// } +// } +// +// } diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 940fc4a4..bd0fd5ea 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -11,6 +11,8 @@ class CategoriesController < ApplicationController # GET /categories/1 # GET /categories/1.json def show + @school_category = SchoolCategory.for(@school, @category).first + @child_school_categories = SchoolCategory.for_parent_category(@school, @category) end # GET /categories/new diff --git a/app/controllers/schools_controller.rb b/app/controllers/schools_controller.rb index 1921c5d7..f9df5c68 100644 --- a/app/controllers/schools_controller.rb +++ b/app/controllers/schools_controller.rb @@ -10,7 +10,7 @@ class SchoolsController < ApplicationController # GET /schools/1 # GET /schools/1.json def show - @school_categories = @school.school_categories.for_parent_category(nil).sort + @school_categories = @school.school_categories.for_parent_category(@school, nil).sort end # GET /schools/new diff --git a/app/models/category.rb b/app/models/category.rb index 270c59e7..9c115de5 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -9,12 +9,15 @@ class Category < ApplicationRecord scope :for_parent, -> (category=nil) { where(parent_category_id: category.try(:id)) } - def root_identifier + def path p = self - while p.parent_category.present? - p = p.parent_category - end - p.name.downcase.gsub(/\s/, '-') + items = [p] + items << p while (p = p.try(:parent_category)) + items.uniq.compact.reverse + end + + def root_identifier + path.first.name.downcase.gsub(/\s/, '-') end def root_index diff --git a/app/models/school_category.rb b/app/models/school_category.rb index b8f00148..af65cb20 100644 --- a/app/models/school_category.rb +++ b/app/models/school_category.rb @@ -7,7 +7,7 @@ class SchoolCategory < ApplicationRecord validates_associated :category scope :for, -> (school, category) { where(school: school).where(category: category) } - scope :for_parent_category, -> (category=nil) { joins(:category).merge(Category.for_parent(category)) } + scope :for_parent_category, -> (school, category=nil) { where(school: school).joins(:category).merge(Category.for_parent(category)) } def answer_index_average answer_index_total.to_f / response_count.to_f diff --git a/app/views/categories/_breadcrumbs.html.haml b/app/views/categories/_breadcrumbs.html.haml new file mode 100644 index 00000000..fd0e2645 --- /dev/null +++ b/app/views/categories/_breadcrumbs.html.haml @@ -0,0 +1,2 @@ +%p + = school_category.category.path.map { |c| link_to(c.name, [school_category.school, c]) }.join(' > ').html_safe diff --git a/app/views/categories/show.html.haml b/app/views/categories/show.html.haml index 6ebea540..7280807c 100644 --- a/app/views/categories/show.html.haml +++ b/app/views/categories/show.html.haml @@ -1,38 +1,30 @@ -%p#notice= notice -%p - %strong Name: - = @category.name -%p - %strong Blurb: - = @category.blurb -%p - %strong Description: - = @category.description -%p - %strong External: - = @category.external_id += render 'layouts/school_header' -%p - %strong Parent Category: -   - = render partial: 'categories/full_path', locals: {category: @category} +.row + .col-12 + %p + = render 'categories/breadcrumbs', school_category: @school_category -- if @category.child_categories.present? - %p - %strong Child Categories: - - @category.child_categories.each do |child_category| -   - = link_to child_category.name, child_category +.row + .col-12 + .school_category.p-2 + %h3.title.text-center.pt-3 + = @category.name + %p= @category.description + %p + %b Total Responses: + = number_with_delimiter(@school_category.response_count) -%p - %strong Questions +       -- @category.questions.each do |question| - %p= link_to(question.text, question) + %b Average Response: + = @school_category.answer_index_average.round(1) + (out of 5) + .indicator-container.py-3 + = render 'school_categories/indicator', school_category: @school_category - -= link_to 'Edit', edit_category_path(@category) -| -= link_to 'Back', categories_path +- if @child_school_categories.present? + .row + = render @child_school_categories diff --git a/app/views/layouts/_school_header.html.haml b/app/views/layouts/_school_header.html.haml new file mode 100644 index 00000000..df12dee8 --- /dev/null +++ b/app/views/layouts/_school_header.html.haml @@ -0,0 +1,10 @@ +.row + .col + =# link_to(image_tag(@district.logo), @district) if @district.present? + %h2= link_to @school.name, @school + = simple_format(@school.description) + %p Data for 2015-2016 school year. + - if @school.district.present? + %p + %strong District: + = link_to @school.district.name, @school.district diff --git a/app/views/school_categories/_school_category.html.haml b/app/views/school_categories/_school_category.html.haml index c943d9da..2abf7618 100644 --- a/app/views/school_categories/_school_category.html.haml +++ b/app/views/school_categories/_school_category.html.haml @@ -1,12 +1,12 @@ -.col-4.py-3 - .school_category.p-2 +.col-6.py-3 + .school_category.short.p-2 %h4.title.text-center.pt-3 = link_to(school_category.category.name, [school_category.school, school_category.category]) - .indicator-container + .indicator-container.short = render 'school_categories/indicator', school_category: school_category - .description.px-2.pt-3.pb-2 + .description.px-2.pt-3.pb-2.mt-2 - if false #(measurements = school_category.questions.measurements.for_school(school_measure.school)).present? = render 'measurements/nonlikert', measurement: measurements.first, description: school_measure.measure.description - else diff --git a/app/views/schools/show.html.haml b/app/views/schools/show.html.haml index a34604d7..baa215a1 100644 --- a/app/views/schools/show.html.haml +++ b/app/views/schools/show.html.haml @@ -1,12 +1,4 @@ -.row - .col - %p - %strong Name: - = @school.name - - if @school.district.present? - %p - %strong District: - = link_to @school.district.name, @school.district += render 'layouts/school_header' .row = render @school_categories