Skip to content

605: Add user origin to school dashboard, fix relationships #556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/admin/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ProjectsController < Admin::ApplicationController
before_action :set_host_for_local_storage

def scoped_resource
resource_class.internal_projects
action_name == 'index' ? resource_class.internal_projects : resource_class.all
end

def destroy_image
Expand Down
61 changes: 61 additions & 0 deletions app/dashboards/class_student_dashboard.rb
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The student and teacher dashboards only show the profile id owing to complications around pulling in user info from profile, this is out of scope of this issue and will need to be expanded in the future...this at least allows things to render, and a dev can look up the user_id if need be.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# frozen_string_literal: true

require 'administrate/base_dashboard'

class ClassStudentDashboard < Administrate::BaseDashboard
# ATTRIBUTE_TYPES
# a hash that describes the type of each of the model's fields.
#
# Each different type represents an Administrate::Field object,
# which determines how the attribute is displayed
# on pages throughout the dashboard.
ATTRIBUTE_TYPES = {
school_class: Field::HasOne,
student_id: Field::String,
created_at: Field::DateTime,
updated_at: Field::DateTime
}.freeze

# COLLECTION_ATTRIBUTES
# an array of attributes that will be displayed on the model's index page.
#
# By default, it's limited to four items to reduce clutter on index pages.
# Feel free to add, remove, or rearrange items.
COLLECTION_ATTRIBUTES = %i[
student_id
created_at
updated_at
].freeze

# SHOW_PAGE_ATTRIBUTES
# an array of attributes that will be displayed on the model's show page.
SHOW_PAGE_ATTRIBUTES = %i[
student_id_changed
created_at
updated_at
].freeze

# FORM_ATTRIBUTES
# an array of attributes that will be displayed
# on the model's form (`new` and `edit`) pages.
FORM_ATTRIBUTES = %i[].freeze

# COLLECTION_FILTERS
# a hash that defines filters that can be used while searching via the search
# field of the dashboard.
#
# For example to add an option to search for open resources by typing "open:"
# in the search field:
#
# COLLECTION_FILTERS = {
# open: ->(resources) { resources.where(open: true) }
# }.freeze
COLLECTION_FILTERS = {}.freeze

# Overwrite this method to customize how school classes are displayed
# across all pages of the admin dashboard.
#
# def display_resource(school_class)
# "SchoolClass ##{school_class.id}"
# end
end
61 changes: 61 additions & 0 deletions app/dashboards/class_teacher_dashboard.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# frozen_string_literal: true

require 'administrate/base_dashboard'

class ClassTeacherDashboard < Administrate::BaseDashboard
# ATTRIBUTE_TYPES
# a hash that describes the type of each of the model's fields.
#
# Each different type represents an Administrate::Field object,
# which determines how the attribute is displayed
# on pages throughout the dashboard.
ATTRIBUTE_TYPES = {
school_class: Field::HasOne,
teacher_id: Field::String,
created_at: Field::DateTime,
updated_at: Field::DateTime
}.freeze

# COLLECTION_ATTRIBUTES
# an array of attributes that will be displayed on the model's index page.
#
# By default, it's limited to four items to reduce clutter on index pages.
# Feel free to add, remove, or rearrange items.
COLLECTION_ATTRIBUTES = %i[
teacher_id
created_at
updated_at
].freeze

# SHOW_PAGE_ATTRIBUTES
# an array of attributes that will be displayed on the model's show page.
SHOW_PAGE_ATTRIBUTES = %i[
teacher_id
created_at
updated_at
].freeze

# FORM_ATTRIBUTES
# an array of attributes that will be displayed
# on the model's form (`new` and `edit`) pages.
FORM_ATTRIBUTES = %i[].freeze

# COLLECTION_FILTERS
# a hash that defines filters that can be used while searching via the search
# field of the dashboard.
#
# For example to add an option to search for open resources by typing "open:"
# in the search field:
#
# COLLECTION_FILTERS = {
# open: ->(resources) { resources.where(open: true) }
# }.freeze
COLLECTION_FILTERS = {}.freeze

# Overwrite this method to customize how school classes are displayed
# across all pages of the admin dashboard.
#
# def display_resource(class_teacher)
# class_teacher.teacher.name
# end
end
28 changes: 7 additions & 21 deletions app/dashboards/lesson_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LessonDashboard < Administrate::BaseDashboard
school_class: Field::BelongsTo,
parent: Field::BelongsTo,
copies: Field::HasMany,
projects: Field::HasMany,
project: Field::HasOne,
id: Field::String,
copied_from_id: Field::String,
user_id: Field::String,
Expand All @@ -33,9 +33,8 @@ class LessonDashboard < Administrate::BaseDashboard
# By default, it's limited to four items to reduce clutter on index pages.
# Feel free to add, remove, or rearrange items.
COLLECTION_ATTRIBUTES = %i[
school
name
school_class
parent
copies
].freeze

Expand All @@ -44,9 +43,9 @@ class LessonDashboard < Administrate::BaseDashboard
SHOW_PAGE_ATTRIBUTES = %i[
school
school_class
project
parent
copies
projects
id
copied_from_id
user_id
Expand All @@ -62,20 +61,7 @@ class LessonDashboard < Administrate::BaseDashboard
# FORM_ATTRIBUTES
# an array of attributes that will be displayed
# on the model's form (`new` and `edit`) pages.
FORM_ATTRIBUTES = %i[
school
school_class
parent
copies
projects
copied_from_id
user_id
name
description
visibility
due_date
archived_at
].freeze
FORM_ATTRIBUTES = %i[].freeze

# COLLECTION_FILTERS
# a hash that defines filters that can be used while searching via the search
Expand All @@ -92,7 +78,7 @@ class LessonDashboard < Administrate::BaseDashboard
# Overwrite this method to customize how lessons are displayed
# across all pages of the admin dashboard.
#
# def display_resource(lesson)
# "Lesson ##{lesson.id}"
# end
def display_resource(lesson)
lesson.name
end
end
26 changes: 10 additions & 16 deletions app/dashboards/school_class_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class SchoolClassDashboard < Administrate::BaseDashboard
# on pages throughout the dashboard.
ATTRIBUTE_TYPES = {
school: Field::BelongsTo,
members: Field::HasMany,
teachers: Field::HasMany,
students: Field::HasMany,
lessons: Field::HasMany,
id: Field::String,
teacher_id: Field::String,
name: Field::String,
created_at: Field::DateTime,
updated_at: Field::DateTime
Expand All @@ -26,33 +26,27 @@ class SchoolClassDashboard < Administrate::BaseDashboard
# By default, it's limited to four items to reduce clutter on index pages.
# Feel free to add, remove, or rearrange items.
COLLECTION_ATTRIBUTES = %i[
school
members
name
lessons
id
].freeze

# SHOW_PAGE_ATTRIBUTES
# an array of attributes that will be displayed on the model's show page.
SHOW_PAGE_ATTRIBUTES = %i[
school
members
lessons
id
teacher_id
teachers
students
name
id
created_at
updated_at
].freeze

# FORM_ATTRIBUTES
# an array of attributes that will be displayed
# on the model's form (`new` and `edit`) pages.
FORM_ATTRIBUTES = %i[
school
teacher_id
name
].freeze
FORM_ATTRIBUTES = %i[].freeze

# COLLECTION_FILTERS
# a hash that defines filters that can be used while searching via the search
Expand All @@ -69,7 +63,7 @@ class SchoolClassDashboard < Administrate::BaseDashboard
# Overwrite this method to customize how school classes are displayed
# across all pages of the admin dashboard.
#
# def display_resource(school_class)
# "SchoolClass ##{school_class.id}"
# end
def display_resource(school_class)
school_class.name
end
end
5 changes: 4 additions & 1 deletion app/dashboards/school_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class SchoolDashboard < Administrate::BaseDashboard
verified_at: Field::DateTime,
rejected_at: Field::DateTime,
created_at: Field::DateTime,
updated_at: Field::DateTime
updated_at: Field::DateTime,
user_origin: EnumField
}.freeze

# COLLECTION_ATTRIBUTES
Expand All @@ -39,6 +40,7 @@ class SchoolDashboard < Administrate::BaseDashboard
# Feel free to add, remove, or rearrange items.
COLLECTION_ATTRIBUTES = %i[
name
user_origin
reference
country_code
created_at
Expand All @@ -50,6 +52,7 @@ class SchoolDashboard < Administrate::BaseDashboard
# an array of attributes that will be displayed on the model's show page.
SHOW_PAGE_ATTRIBUTES = %i[
name
user_origin
creator
creator_role
creator_department
Expand Down
13 changes: 13 additions & 0 deletions app/fields/enum_field.rb
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, administrate tries to treat enums as select fields and will error, since the data is not in the expected format

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

class EnumField < Administrate::Field::Select
def to_s
# Use Rails' i18n for enums
return if data.blank?

I18n.t(
"activerecord.attributes.#{resource.class.model_name.i18n_key}.#{attribute}_values.#{data}",
default: data.humanize
)
end
end
6 changes: 6 additions & 0 deletions app/views/fields/enum_field/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="field-unit__label">
<%= f.label field.attribute %>
</div>
<div class="field-unit__field">
<%= f.text_field field.attribute %>
</div>
1 change: 1 addition & 0 deletions app/views/fields/enum_field/_index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= field.to_s %>
1 change: 1 addition & 0 deletions app/views/fields/enum_field/_show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= field.to_s %>
6 changes: 6 additions & 0 deletions config/locales/admin/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ en:
reopen_school:
success: "Successfully reopened."
error: "There was an error reopening the school"
activerecord:
attributes:
school:
user_origin_values:
for_education: "Code Editor for Education"
experience_cs: "Experience CS"