-
Notifications
You must be signed in to change notification settings - Fork 78
feat(gradebook): add Level contribution to weighted gradebook #8449
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
Open
LWS49
wants to merge
3
commits into
lws49/feat-gradebook-weighted-view
Choose a base branch
from
lws49/feat-gradebook-weighted-view-add-level-contribution
base: lws49/feat-gradebook-weighted-view
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,42 @@ | ||
| # frozen_string_literal: true | ||
| class Course::GradebookComponent < SimpleDelegator | ||
| include Course::ControllerComponentHost::Component | ||
|
|
||
| def self.display_name | ||
| 'Gradebook' | ||
| end | ||
|
|
||
| def sidebar_items | ||
| main_sidebar_items + settings_sidebar_items | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def main_sidebar_items | ||
| return [] unless can?(:read_gradebook, current_course) | ||
|
|
||
| [ | ||
| { | ||
| key: self.class.key, | ||
| icon: :gradebook, | ||
| title: I18n.t('course.gradebook.component.sidebar_title'), | ||
| type: :normal, | ||
| weight: 9, | ||
| path: course_gradebook_path(current_course) | ||
| } | ||
| ] | ||
| end | ||
|
|
||
| def settings_sidebar_items | ||
| return [] unless can?(:manage_gradebook_settings, current_course) | ||
|
|
||
| [ | ||
| { | ||
| key: self.class.key, | ||
| type: :settings, | ||
| weight: 14, | ||
| path: course_admin_gradebook_path(current_course) | ||
| } | ||
| ] | ||
| end | ||
| end |
28 changes: 28 additions & 0 deletions
28
app/controllers/course/admin/gradebook_settings_controller.rb
This file contains hidden or 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,28 @@ | ||
| # frozen_string_literal: true | ||
| class Course::Admin::GradebookSettingsController < Course::Admin::Controller | ||
| def edit | ||
| respond_to(&:json) | ||
| end | ||
|
|
||
| def update | ||
| if @settings.update(gradebook_settings_params) && current_course.save | ||
| render 'edit' | ||
| else | ||
| render json: { errors: @settings.errors }, status: :bad_request | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def gradebook_settings_params | ||
| params.require(:settings_gradebook_component).permit(:weighted_view_enabled) | ||
| end | ||
|
|
||
| def component | ||
| current_component_host[:course_gradebook_component] | ||
| end | ||
|
|
||
| def authorize_admin | ||
| authorize! :manage_gradebook_settings, current_course | ||
| end | ||
| end |
This file contains hidden or 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,134 @@ | ||
| # frozen_string_literal: true | ||
| class Course::GradebookController < Course::ComponentController | ||
| before_action :authorize_read_gradebook! | ||
|
|
||
| def index | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/AbcSize: Assignment Branch Condition size for index is too high. [<11, 18, 3> 21.31/20] |
||
| respond_to do |format| | ||
| format.json do | ||
| @weighted_view_enabled = @settings.weighted_view_enabled | ||
| @published_assessments = fetch_published_assessments | ||
| @categories, @tabs = fetch_categories_and_tabs | ||
| @students = fetch_students | ||
| @course_max_level = [current_course.levels.count - 1, 0].max | ||
| @level_config = current_course.gradebook_level_config if @weighted_view_enabled | ||
| assessment_ids = @published_assessments.pluck(:id) | ||
| load_weighted_view_contributions(assessment_ids) if @weighted_view_enabled | ||
| @assessment_max_grades = Course::Assessment.max_grades(assessment_ids) | ||
| @submissions = Course::Assessment::Submission.grade_summary( | ||
| student_ids: @students.map(&:user_id), | ||
| assessment_ids: assessment_ids | ||
| ) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def update_weights | ||
| authorize! :manage_gradebook_weights, current_course | ||
| updates = (update_weights_params[:weights] || []).map { |entry| parse_weight_entry(entry) } | ||
| Course::Gradebook::Contribution.bulk_update(course: current_course, updates: updates) | ||
| level_config = persist_level_contribution | ||
| response_body = { weights: serialize_weight_updates(updates) } | ||
| response_body[:levelContribution] = serialize_level_contribution(level_config) if level_config | ||
| render json: response_body | ||
| rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotFound => e | ||
| render json: { errors: { base: e.message } }, status: :unprocessable_entity | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def authorize_read_gradebook! | ||
| authorize! :read_gradebook, current_course | ||
| end | ||
|
|
||
| def load_weighted_view_contributions(assessment_ids) | ||
| @tab_contributions = Course::Gradebook::Contribution. | ||
| where(tab_id: @tabs.map(&:id)).index_by(&:tab_id) | ||
| @assessment_contributions = Course::Gradebook::AssessmentContribution. | ||
| where(assessment_id: assessment_ids).index_by(&:assessment_id) | ||
| end | ||
|
|
||
| def parse_weight_entry(entry) | ||
| { | ||
| tab_id: entry[:tabId].to_i, | ||
| weight: entry[:weight].to_f, | ||
| weight_mode: entry[:weightMode] || 'equal', | ||
| excluded_assessment_ids: (entry[:excludedAssessmentIds] || []).map(&:to_i), | ||
| assessment_weights: (entry[:assessmentWeights] || []).map do |aw| | ||
| { assessment_id: aw[:assessmentId].to_i, weight: aw[:weight].to_f } | ||
| end | ||
| } | ||
| end | ||
|
|
||
| def update_weights_params | ||
| params.permit( | ||
| weights: [:tabId, :weight, :weightMode, | ||
| excludedAssessmentIds: [], assessmentWeights: [:assessmentId, :weight]] | ||
| ) | ||
| end | ||
|
|
||
| def persist_level_contribution | ||
| attrs = level_contribution_attrs | ||
| return nil if attrs.nil? | ||
|
|
||
| Course::Gradebook::LevelConfig.upsert_for(course: current_course, attrs: attrs) | ||
| end | ||
|
|
||
| def level_contribution_attrs | ||
| lc = params[:levelContribution] | ||
| return nil if lc.blank? | ||
|
|
||
| permitted = lc.permit(:enabled, :formula, :weight, :show) | ||
| { | ||
| enabled: permitted[:enabled], | ||
| formula: permitted[:formula], | ||
| weight: permitted[:weight], | ||
| show: permitted[:show] | ||
| } | ||
| end | ||
|
|
||
| def serialize_level_contribution(config) | ||
| { | ||
| enabled: config.enabled, | ||
| formula: config.formula, | ||
| weight: config.weight.to_f, | ||
| show: config.show | ||
| } | ||
| end | ||
|
|
||
| def serialize_weight_updates(updates) | ||
| updates.map do |u| | ||
| entry = { tabId: u[:tab_id], weight: u[:weight], weightMode: u[:weight_mode].to_s, | ||
| excludedAssessmentIds: u[:excluded_assessment_ids] } | ||
| if u[:weight_mode].to_s == 'custom' | ||
| entry[:assessmentWeights] = u[:assessment_weights].map do |aw| | ||
| { assessmentId: aw[:assessment_id], weight: aw[:weight] } | ||
| end | ||
| end | ||
| entry | ||
| end | ||
| end | ||
|
|
||
| def component | ||
| current_component_host[:course_gradebook_component] | ||
| end | ||
|
|
||
| def fetch_categories_and_tabs | ||
| tabs = @published_assessments.map(&:tab).uniq(&:id) | ||
| [tabs.map(&:category).uniq(&:id), tabs] | ||
| end | ||
|
|
||
| def fetch_students | ||
| current_course.levels.to_a | ||
| current_course.course_users.students.without_phantom_users. | ||
| calculated(:experience_points).includes(user: :emails).to_a. | ||
| sort_by { |cu| cu.user.name } | ||
| end | ||
|
|
||
| def fetch_published_assessments | ||
| current_course.assessments. | ||
| published. | ||
| includes(tab: :category). | ||
| joins(tab: :category). | ||
| reorder('course_assessment_categories.weight, course_assessment_tabs.weight, course_assessments.id') | ||
| end | ||
| end | ||
This file contains hidden or 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
17 changes: 0 additions & 17 deletions
17
app/jobs/course/statistics/assessments_score_summary_download_job.rb
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
app/models/components/course/gradebook_ability_component.rb
This file contains hidden or 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,11 @@ | ||
| # frozen_string_literal: true | ||
| module Course::GradebookAbilityComponent | ||
| include AbilityHost::Component | ||
|
|
||
| def define_permissions | ||
| can :read_gradebook, Course, id: course.id if course_user&.staff? | ||
| can :manage_gradebook_weights, Course, id: course.id if course_user&.manager_or_owner? | ||
| can :manage_gradebook_settings, Course, id: course.id if course_user&.manager_or_owner? | ||
| super | ||
| end | ||
| end |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/ClassLength: Class has too many lines. [114/100]