-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix reports group selection, routing, and rendering in print layout
- Loading branch information
Showing
9 changed files
with
226 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class GroupReportsController < HtmlController | ||
skip_after_action :verify_policy_scoped | ||
layout 'print' | ||
def show | ||
@group = Group.includes(:chapter).find params[:id] | ||
authorize @group | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,12 @@ | ||
class ReportsController < HtmlController | ||
skip_after_action :verify_policy_scoped | ||
include Pagy::Backend | ||
has_scope :exclude_deleted, type: :boolean, default: true | ||
has_scope :table_order, type: :hash, default: { key: :created_at, order: :desc } | ||
has_scope :search, only: [:show, :index] | ||
|
||
before_action do | ||
@available_organizations = policy_scope Organization.where(deleted_at: nil).order(:organization_name) | ||
@available_chapters = policy_scope Chapter.where(deleted_at: nil).order(:chapter_name) | ||
@available_groups = policy_scope Group.where(deleted_at: nil).order(:group_name) | ||
def show | ||
@available_organizations = policy_scope Organization.where(deleted_at: nil).order(:organization_name) | ||
@available_chapters = policy_scope Chapter.where(deleted_at: nil).order(:chapter_name) | ||
@available_groups = policy_scope Group.where(deleted_at: nil).order(:group_name) | ||
|
||
@selected_organization_id = params[:organization_id] || @available_organizations.first.id | ||
@selected_chapter_id = params[:chapter_id] | ||
@selected_group_id = params[:group_id] | ||
end | ||
|
||
|
||
def index | ||
authorize Group | ||
@group = Group.new | ||
@pagy, @groups = pagy policy_scope(apply_scopes(GroupSummary.includes(chapter: [:organization])), policy_scope_class: GroupPolicy::Scope) | ||
end | ||
|
||
def show | ||
@group = Group.includes(:chapter).find params[:group_select] | ||
authorize @group | ||
@pagy, @student_rows = pagy apply_scopes(StudentTableRow.where(group_id: @group.id).includes(:tags, :group)) | ||
@student_table_component = TableComponents::Table.new(pagy: @pagy, rows: @student_rows, row_component: TableComponents::StudentRow) | ||
end | ||
end | ||
authorize Group | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Controller } from '@hotwired/stimulus' | ||
|
||
function createOption(label, value) { | ||
const opt = document.createElement('option'); | ||
opt.text = label; | ||
if (value !== undefined) { | ||
opt.value = value; | ||
} | ||
|
||
return opt; | ||
} | ||
export default class extends Controller { | ||
static targets = ['select', 'anchor'] | ||
static values = { | ||
path: String | ||
} | ||
|
||
connect() { | ||
this.updateFilter() | ||
} | ||
|
||
toId(value) { | ||
if (Number.isNaN(Number(value))) { | ||
return '' | ||
} | ||
return value | ||
} | ||
|
||
updateFilter() { | ||
this.updateDropdown(this.selectTargets[0], JSON.parse(this.selectTargets[0].dataset.resources)) | ||
const replaceValue = this.toId(this.selectTargets[this.selectTargets.length - 1].value) | ||
this.anchorTarget.href = this.pathValue.replace("placeholder", replaceValue) | ||
} | ||
|
||
updateDropdown(dropdown, values, parentIds) { | ||
const currentValue = Number(dropdown.value); | ||
dropdown.innerHTML = ''; | ||
const dependents = JSON.parse(dropdown.dataset.dependents || null); | ||
if (dependents) { | ||
dropdown.append(createOption('All', null)); | ||
} | ||
|
||
let valueExists = false; | ||
const filteredIds = values.filter(v => !parentIds || parentIds.includes(v.depend_id)).map((v) => { | ||
if (currentValue === v.id) { | ||
valueExists = true; | ||
} | ||
dropdown.append(createOption(v.label, v.id)); | ||
return v.id; | ||
}); | ||
|
||
if (valueExists) { | ||
dropdown.value = currentValue; | ||
} | ||
|
||
if (dependents) { | ||
dependents.forEach(dependentSelectName => { | ||
const targetSelect = this.selectTargets.find(t => t.dataset.name === dependentSelectName); | ||
this.updateDropdown(targetSelect, JSON.parse(targetSelect.dataset.resources), valueExists ? [currentValue] : filteredIds) | ||
}) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<h1>Lorem ipsum</h1> | ||
|
||
<script> | ||
document.addEventListener('DOMContentLoaded', function () { | ||
window.print(); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html> | ||
<html class="h-full bg-gray-100 overflow-hidden"> | ||
<head> | ||
<title>Tracker<% if content_for? :title %><%= " - #{content_for :title}" %><% end %></title> | ||
<meta name="turbo-cache-control" content="no-preview"> | ||
<meta content="notranslate" name="google" /> | ||
<%= favicon_link_tag 'favicon.ico' %> | ||
<%= stylesheet_link_tag 'tailwind.css', media: 'all' %> | ||
<%= javascript_importmap_tags %> | ||
<%= yield :head_content %> | ||
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet" /> | ||
<% if staging_site? %> | ||
<meta name="robots" content="noindex, nofollow"> | ||
<link rel="canonical" href="https://mindleapstracker.org<%= request.path %>" /> | ||
<% end %> | ||
</head> | ||
<body class="h-full bg-gray-200"> | ||
<div class="h-full flex"> | ||
<div class="flex flex-col w-full overflow-auto"> | ||
<%= yield %> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,22 @@ | ||
<h1>Lorem ipsum</h1> | ||
|
||
<script> | ||
document.addEventListener('DOMContentLoaded', function () { | ||
window.print(); | ||
}); | ||
</script> | ||
<% content_for :title, t(:subject_analytics).capitalize %> | ||
<div class="overflow-x-scroll"> | ||
<div class="p-4 filter-wrap flex items-center flex-1"> | ||
<div class="p-4 filter-wrap flex items-center flex-1" data-controller="reports-filter" data-reports-filter-path-value="<%= reports_group_path(:placeholder) %>"> | ||
<div class="pl-2"> | ||
<%= label_tag :organization_label, "Organization", class: 'block text-sm font-medium text-gray-700' %> | ||
<%= select_tag :organization_select, options_from_collection_for_select(@available_organizations, :id, :organization_name), :class => 'mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md', :prompt => 'All', 'data-reports-filter-target' => 'select', 'data-action' => 'reports-filter#updateFilter', 'data-name' => 'organization_id', 'data-dependents' => ['chapter_id'].to_json, 'data-resources' => @available_organizations.map { |o| { id: o.id, label: o.organization_name} }.to_json %> | ||
</div> | ||
<div class="pl-2"> | ||
<%= label_tag :chapter_label, "Chapter", class: 'block text-sm font-medium text-gray-700' %> | ||
<%= select_tag :chapter_select, options_from_collection_for_select(@available_chapters, :id, :chapter_name), :class => 'mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md', :prompt => 'All', 'data-reports-filter-target' => 'select', 'data-action' => 'reports-filter#updateFilter', 'data-name' => 'chapter_id', 'data-dependents' => ['group_id'].to_json, 'data-resources' => @available_chapters.map { |c| { id: c.id, label: c.chapter_name, depend_id: c.organization_id } }.to_json %> | ||
</div> | ||
<div class="pl-2"> | ||
<%= label_tag :group_label, "Group", class: 'block text-sm font-medium text-gray-700' %> | ||
<%= select_tag :group_select, options_from_collection_for_select(@available_groups, :id, :group_name), :class => 'mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md', 'data-reports-filter-target' => 'select', 'data-action' => 'reports-filter#updateFilter', 'data-name' => 'group_id', 'data-resources' => @available_groups.map { |g| { id: g.id, label: g.group_name, depend_id: g.chapter_id } }.to_json %> | ||
</div> | ||
<div class="pl-2 pt-5"> | ||
<%= render CommonComponents::ButtonComponent.new(label: t(:filter), options: { 'data-reports-filter-target' => 'anchor', 'target' => '_blank' })%> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.