Skip to content
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

FEATURE: Add option to lock leaderboard view to default period #179

Merged
merged 1 commit into from
Jan 16, 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
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>
Comment on lines +163 to +170
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a clean way to achieve an inline label with the checkbox without breaking out of form-kit?

Screenshot 2025-01-02 at 9 12 02 PM

Setting the @showTitle argument on the field generates the following, but it lacks the optional tag and does not match the styling of a standard form label. Could I style it myself? Yes! But I wanted to confirm whether this isn’t possible out of the box first.

Screenshot 2025-01-02 at 9 14 08 PM

Copy link
Contributor

Choose a reason for hiding this comment

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

@chapoi what should we do in this case?

<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
Loading