Last active
September 30, 2024 06:13
-
-
Save prfraser/05ce66d420bdedd47f216ea5299a7763 to your computer and use it in GitHub Desktop.
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
| class WorkforceReport::Base | |
| # ... existing code ... | |
| sig { returns(T::Boolean) } | |
| def sortable_columns? | |
| is_a?(WorkforceReport::Concerns::Sortable) | |
| end | |
| # Remove the reports_with_sortable_columns method | |
| 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
| class WorkforceReport::Shift < WorkforceReport::Components::Published | |
| include WorkforceReport::Concerns::Sortable | |
| self.sort_column_label_map = { | |
| "name" => { model_name: "users", model_field: "name" }, | |
| "date" => { model_name: "shifts", model_field: "date" }, | |
| "shift_start" => { model_name: "shifts", model_field: "start" }, | |
| "shift_end" => { model_name: "shifts", model_field: "end" }, | |
| "shift_length" => { model_name: "shifts", model_field: "shift_length" }, | |
| "clocked_start" => { model_name: "shifts", model_field: "clocked_start" }, | |
| "clocked_end" => { model_name: "shifts", model_field: "clocked_end" }, | |
| "shift_status" => { model_name: "shifts", model_field: "status" }, | |
| "timesheet_start" => { model_name: "timesheets", model_field: "start" }, | |
| "timesheet_end" => { model_name: "timesheets", model_field: "end" } | |
| } | |
| # ... existing code ... | |
| sig { returns Shift::RelationType } | |
| def shifts | |
| # ... existing filtering logic ... | |
| apply_sorting(shifts) | |
| end | |
| # Remove the existing sort, apply_sorting, and sortable_columns methods | |
| 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
| class WorkforceReport::ShiftAcceptAcknowledge < WorkforceReport::Components::Published | |
| include WorkforceReport::Concerns::Sortable | |
| self.sort_column_label_map = { | |
| "name" => { model_name: "users", model_field: "name" }, | |
| "accepted" => { model_name: "users", model_field: "accepted_schedules_count" }, | |
| "declined" => { model_name: "users", model_field: "declined_schedules_count" }, | |
| "no_response" => { model_name: "users", model_field: "not_accepted_count" } | |
| } | |
| # ... existing code ... | |
| sig { returns User::RelationType } | |
| def selected_users | |
| users = @org.users.accessible(@current_user) | |
| # ... existing filtering logic ... | |
| apply_sorting(users.distinct) | |
| end | |
| # Remove the existing sort, apply_sorting, and sortable_columns methods | |
| 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
| # typed: strict | |
| # frozen_string_literal: true | |
| module WorkforceReport | |
| module Concerns | |
| module Sortable | |
| extend T::Sig | |
| extend T::Helpers | |
| extend ActiveSupport::Concern | |
| included do | |
| class_attribute :sort_column_label_map, default: {} | |
| end | |
| sig { params(query: ActiveRecord::Relation).returns(ActiveRecord::Relation) } | |
| def apply_sorting(query) | |
| if sort_column.present? && sort_direction.present? | |
| sort(query) | |
| else | |
| query.order(self.class.sort_column_label_map["name"][:model_field]) | |
| end | |
| end | |
| private | |
| sig { params(query: ActiveRecord::Relation).returns(ActiveRecord::Relation) } | |
| def sort(query) | |
| model_name = self.class.sort_column_label_map[sort_column][:model_name] | |
| model_field = self.class.sort_column_label_map[sort_column][:model_field] | |
| query.order("#{model_name}.#{model_field} #{sort_direction}") | |
| end | |
| sig { returns(T::Array[Symbol]) } | |
| def sortable_columns | |
| self.class.sort_column_label_map.keys.map(&:to_sym) | |
| end | |
| end | |
| 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
| class WorkforceReport::User < WorkforceReport::Components::Published | |
| include WorkforceReport::Concerns::Sortable | |
| self.sort_column_label_map = { | |
| "name" => { model_name: "users", model_field: "name" }, | |
| "legal_first_name" => { model_name: "users", model_field: "legal_first_name" }, | |
| "legal_middle_names" => { model_name: "users", model_field: "legal_middle_names" }, | |
| "legal_last_name" => { model_name: "users", model_field: "legal_last_name" }, | |
| "date_of_birth" => { model_name: "users", model_field: "date_of_birth" }, | |
| "passcode" => { model_name: "users", model_field: "passcode" }, | |
| "email" => { model_name: "users", model_field: "email" }, | |
| "phone" => { model_name: "users", model_field: "phone" }, | |
| "signed_into_mobile_app" => { model_name: "users", model_field: "signed_into_mobile_app" }, | |
| "employment_start_date" => { model_name: "users", model_field: "employment_start_date" }, | |
| "employment_end_date" => { model_name: "users", model_field: "employment_end_date" } | |
| } | |
| # ... existing code ... | |
| sig { returns User::RelationType } | |
| def selected_users | |
| users = @org.users.accessible(@current_user).preload(preloads) | |
| # ... existing filtering logic ... | |
| apply_sorting(users.distinct) | |
| end | |
| # Remove the existing apply_sorting and sortable_columns methods | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment