mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
Simplify js by including full path in district and school options values
This commit is contained in:
parent
4d6eb4ecf1
commit
f8166aed47
7 changed files with 35 additions and 44 deletions
1
Gemfile
1
Gemfile
|
|
@ -39,7 +39,6 @@ gem 'haml'
|
|||
|
||||
gem 'bootstrap'
|
||||
|
||||
gem 'jquery-ui-rails'
|
||||
gem 'friendly_id', '~> 5.1.0'
|
||||
|
||||
gem 'newrelic_rpm'
|
||||
|
|
|
|||
|
|
@ -100,8 +100,6 @@ GEM
|
|||
rails-dom-testing (>= 1, < 3)
|
||||
railties (>= 4.2.0)
|
||||
thor (>= 0.14, < 2.0)
|
||||
jquery-ui-rails (6.0.1)
|
||||
railties (>= 3.2.16)
|
||||
jwt (1.5.6)
|
||||
launchy (2.5.0)
|
||||
addressable (~> 2.7)
|
||||
|
|
@ -263,7 +261,6 @@ DEPENDENCIES
|
|||
haml
|
||||
jbuilder (~> 2.5)
|
||||
jquery-rails
|
||||
jquery-ui-rails
|
||||
launchy
|
||||
listen (~> 3.0.5)
|
||||
nested_scaffold
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@
|
|||
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
||||
// about supported directives.
|
||||
//
|
||||
//= require jquery
|
||||
//= require jquery_ujs
|
||||
//= require bootstrap
|
||||
//= require turbolinks
|
||||
//= require_tree .
|
||||
|
|
|
|||
|
|
@ -1,34 +1,9 @@
|
|||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const selectSchoolElement = document.querySelector('#select-school');
|
||||
|
||||
selectSchoolElement.addEventListener('change', (event) => {
|
||||
change_school(event);
|
||||
document.querySelector('#select-school').addEventListener('change', (event) => {
|
||||
window.location = event.target.value;
|
||||
});
|
||||
|
||||
const selectDistrictElement = document.querySelector('#select-district');
|
||||
|
||||
selectDistrictElement.addEventListener('change', (event) => {
|
||||
change_district(event);
|
||||
document.querySelector('#select-district').addEventListener('change', (event) => {
|
||||
window.location = event.target.value;
|
||||
});
|
||||
});
|
||||
|
||||
function change_school(event) {
|
||||
const school_slug = event.target.value;
|
||||
|
||||
const district_regex = /districts\/(.+)\/schools/;
|
||||
const district_slug = window.location.pathname.match(district_regex)[1];
|
||||
|
||||
const year_range_regex = /year=(.+)/;
|
||||
const year_range = window.location.search.match(year_range_regex)[1];
|
||||
|
||||
window.location = `/districts/${district_slug}/schools/${school_slug}/dashboard?year=${year_range}`;
|
||||
};
|
||||
|
||||
function change_district(event) {
|
||||
const district_slug = event.target.value;
|
||||
|
||||
const year_range_regex = /year=(.+)/;
|
||||
const year_range = window.location.search.match(year_range_regex)[1];
|
||||
|
||||
window.location = `/districts/${district_slug}/schools/first/dashboard?year=${year_range}`;
|
||||
};
|
||||
|
|
|
|||
25
app/helpers/header_helper.rb
Normal file
25
app/helpers/header_helper.rb
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
module HeaderHelper
|
||||
|
||||
def link_to_dashboard(district:, school:, academic_year:)
|
||||
dashboard_link(district_slug: district.slug, school_slug: school.slug, academic_year_range: academic_year.range)
|
||||
end
|
||||
|
||||
def link_to_browse(district:, school:, academic_year:)
|
||||
"/districts/#{district.slug}/schools/#{school.slug}/browse/teachers-and-leadership?year=#{academic_year.range}"
|
||||
end
|
||||
|
||||
def district_url_for(district:, academic_year:)
|
||||
dashboard_link(district_slug: district.slug, school_slug: district.schools.alphabetic.first.slug, academic_year_range: academic_year.range)
|
||||
end
|
||||
|
||||
def school_url_for(school:, academic_year:)
|
||||
dashboard_link(district_slug: school.district.slug, school_slug: school.slug, academic_year_range: academic_year.range)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def dashboard_link(district_slug:, school_slug:, academic_year_range:)
|
||||
"/districts/#{district_slug}/schools/#{school_slug}/dashboard?year=#{academic_year_range}"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -4,17 +4,17 @@
|
|||
<div class="col d-flex justify-content-start align-items-center">
|
||||
<p class="me-6"><%= link_to image_tag('logo.png', class: 'height-56'), root_path %></p>
|
||||
<p class="me-4">
|
||||
<a class="h3" href="/districts/<%= @district.slug %>/schools/<%= @school.slug %>/dashboard?year=2020-21">Dashboard</a>
|
||||
<a class="h3" href="<%= link_to_dashboard(district: @district, school: @school, academic_year: @academic_year) %>">Dashboard</a>
|
||||
</p>
|
||||
<p>
|
||||
<a class="h3" href="/districts/<%= @district.slug %>/schools/<%= @school.slug %>/browse/teachers-and-leadership?year=2020-21">Browse</a>
|
||||
<a class="h3" href="<%= link_to_browse(district: @district, school: @school, academic_year: @academic_year) %>">Browse</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="col d-flex justify-content-end">
|
||||
<select id="select-district" class="form-select" name="district">
|
||||
<% @districts.each do |district| %>
|
||||
<option class="district-options" value="<%= district.slug %>" <%= @district.slug == district.slug ? "selected" : nil %>>
|
||||
<option class="district-options" value="<%= district_url_for(district: district, academic_year: @academic_year) %>" <%= @district.slug == district.slug ? "selected" : nil %>>
|
||||
<%= district.name %>
|
||||
</option>
|
||||
<% end %>
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
<select id="select-school" class="ms-3 form-select" name="school">
|
||||
<% @schools.each do |school| %>
|
||||
<option class="school-options" value="<%= school.slug %>" <%= @school.slug == school.slug ? "selected" : nil %> >
|
||||
<option class="school-options" value="<%= school_url_for(school: school, academic_year: @academic_year) %>" <%= @school.slug == school.slug ? "selected" : nil %> >
|
||||
<%= school.name %>
|
||||
</option>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -106,11 +106,6 @@ feature 'School dashboard', type: feature do
|
|||
|
||||
end
|
||||
|
||||
# visit photos_path
|
||||
# assert_selector 'h1', text: 'Photos'
|
||||
# assert_equal 1, all('.photo-deletable').count
|
||||
# click_on 'Delete'
|
||||
# page.driver.browser.switch_to.alert.accept
|
||||
scenario 'user sees schools in the same district' do
|
||||
page.driver.browser.basic_authorize(username, password)
|
||||
visit "/districts/#{district.slug}/schools/#{school.slug}/dashboard?year=#{ay_2020_21.range}"
|
||||
|
|
@ -119,6 +114,7 @@ feature 'School dashboard', type: feature do
|
|||
expect(page.all('.school-options').count).to eq expected_num_of_schools
|
||||
expect(page.all('.school-options[selected]').count).to eq 1
|
||||
expect(page.all('.school-options[selected]')[0].text).to eq 'Winchester High School'
|
||||
expect(page.all('.school-options[selected]')[0].value).to eq "/districts/#{district.slug}/schools/#{school.slug}/dashboard?year=#{ay_2020_21.range}"
|
||||
|
||||
school_options = page.all('.school-options')
|
||||
school_options.each_with_index do |school , index|
|
||||
|
|
@ -135,6 +131,7 @@ feature 'School dashboard', type: feature do
|
|||
expect(page.all('.district-options').count).to eq expected_num_of_districts
|
||||
expect(page.all('.district-options[selected]').count).to eq 1
|
||||
expect(page.all('.district-options[selected]')[0].text).to eq 'Winchester'
|
||||
expect(page.all('.district-options[selected]')[0].value).to eq "/districts/#{district.slug}/schools/#{district.schools.alphabetic.first.slug}/dashboard?year=#{ay_2020_21.range}"
|
||||
|
||||
district_options = page.all('.district-options')
|
||||
district_options.each_with_index do |district , index|
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue