Skip to content

Commit

Permalink
FEATURE: Add option to lock leaderboard view to default period
Browse files Browse the repository at this point in the history
For some leaderboards, filtering by time period might be unsuitable. This change
introduces the option to disable the period chooser in the UI.
  • Loading branch information
s3lase committed Jan 2, 2025
1 parent 03ea20d commit 17cd9db
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default class AdminEditLeaderboard extends Component {
excluded_groups_ids: this.args.leaderboard.excludedGroupsIds,
visible_to_groups_ids: this.args.leaderboard.visibleToGroupsIds,
default_period: this.args.leaderboard.defaultPeriod,
period_filter_disabled: this.args.leaderboard.periodFilterDisabled,
};
}

Expand Down Expand Up @@ -159,6 +160,14 @@ export default class AdminEditLeaderboard extends Component {
</field.Custom>
</form.Field>

<form.Field
@name="period_filter_disabled"
@title={{i18n "gamification.leaderboard.period_filter_disabled"}}
@showTitle={{false}}
as |field|
>
<field.Checkbox @value={{field.value}} />
</form.Field>
<form.Submit />
</Form>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def update
excluded_groups_ids: params[:excluded_groups_ids] || [],
visible_to_groups_ids: params[:visible_to_groups_ids] || [],
default_period: params[:default_period],
period_filter_disabled: params[:period_filter_disabled] || false,
)

if leaderboard.save
Expand Down
25 changes: 13 additions & 12 deletions app/models/discourse_gamification/gamification_leaderboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,19 @@ def self.scores_for(leaderboard_id, page: 0, for_user_id: false, period: nil, us
#
# Table name: gamification_leaderboards
#
# id :bigint not null, primary key
# name :string not null
# from_date :date
# to_date :date
# for_category_id :integer
# created_by_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# visible_to_groups_ids :integer default([]), not null, is an Array
# included_groups_ids :integer default([]), not null, is an Array
# excluded_groups_ids :integer default([]), not null, is an Array
# default_period :integer default(0)
# id :bigint not null, primary key
# name :string not null
# from_date :date
# to_date :date
# for_category_id :integer
# created_by_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# visible_to_groups_ids :integer default([]), not null, is an Array
# included_groups_ids :integer default([]), not null, is an Array
# excluded_groups_ids :integer default([]), not null, is an Array
# default_period :integer default(0)
# period_filter_disabled :boolean default(FALSE), not null
#
# Indexes
#
Expand Down
3 changes: 2 additions & 1 deletion app/serializers/leaderboard_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ class LeaderboardSerializer < ApplicationSerializer
:included_groups_ids,
:excluded_groups_ids,
:default_period,
:updated_at
:updated_at,
:period_filter_disabled
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@period={{this.period}}
@action={{action "changePeriod"}}
@fullDay={{false}}
@options={{hash disabled=this.model.leaderboard.period_filter_disabled}}
class="leaderboard__period-chooser"
/>
{{#if this.currentUser.staff}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class GamificationLeaderboard {
@tracked toDate;
@tracked name;
@tracked period;
@tracked periodFilterDisabled;

constructor(args = {}) {
this.id = args.id;
Expand All @@ -33,6 +34,7 @@ export default class GamificationLeaderboard {
this.toDate = args.to_date;
this.name = args.name;
this.period = args.period;
this.periodFilterDisabled = args.period_filter_disabled;

if (Number.isInteger(args.default_period)) {
this.defaultPeriod = I18n.t(
Expand Down
1 change: 1 addition & 0 deletions config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ en:
excluded_groups_help: "Remove users on those groups from being included in the leaderboard. Leave empty to list everyone."
default_period: "Default period"
default_period_help: "Set the default time period to display for this leaderboard."
period_filter_disabled: "Disable time period filter"
period:
all_time: "All Time"
yearly: "Yearly"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class AddPeriodFilterDisabledToLeaderboards < ActiveRecord::Migration[7.2]
def change
add_column :gamification_leaderboards,
:period_filter_disabled,
:boolean,
default: false,
null: false
end
end

0 comments on commit 17cd9db

Please sign in to comment.