Skip to content

Commit 86ca2ae

Browse files
committed
badge and group links in reward admin UI
1 parent 00a664c commit 86ca2ae

File tree

12 files changed

+66
-26
lines changed

12 files changed

+66
-26
lines changed

admin/assets/javascripts/admin/templates/admin-plugins/show/discourse-kofi-rewards/index.gjs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { fn } from "@ember/helper";
2+
import { LinkTo } from "@ember/routing";
23
import RouteTemplate from "ember-route-template";
34
import { not } from "truth-helpers";
5+
import BadgeButton from "discourse/components/badge-button";
46
import DButton from "discourse/components/d-button";
57
import DPageSubheader from "discourse/components/d-page-subheader";
68
import DropdownMenu from "discourse/components/dropdown-menu";
9+
import GroupLink from "discourse/components/group-link";
710
import icon from "discourse/helpers/d-icon";
811
import { i18n } from "discourse-i18n";
912
import DMenu from "float-kit/components/d-menu";
@@ -63,8 +66,22 @@ export default RouteTemplate(
6366
</td>
6467
<td class="d-admin-row__detail">{{reward.amount}}</td>
6568
<td class="d-admin-row__detail">{{reward.payment_types}}</td>
66-
<td class="d-admin-row__detail">{{reward.badge.name}}</td>
67-
<td class="d-admin-row__detail">{{reward.group.name}}</td>
69+
<td class="d-admin-row__detail">
70+
{{#if reward.badge}}
71+
<LinkTo
72+
@route="adminBadges.show"
73+
@model={{reward.badge.id}}
74+
>
75+
<BadgeButton @badge={{reward.badge}} />
76+
</LinkTo>
77+
{{/if}}</td>
78+
<td class="d-admin-row__detail">
79+
{{#if reward.group}}
80+
<GroupLink
81+
@group={{reward.group}}
82+
>{{reward.group.name}}</GroupLink>
83+
{{/if}}
84+
</td>
6885
<td class="d-admin-row__controls">
6986
<DButton
7087
@icon="pencil"
@@ -156,9 +173,9 @@ export default RouteTemplate(
156173
<td
157174
class="d-admin-row__detail"
158175
>{{subscription.tier_name}}</td>
159-
<td
160-
class="d-admin-row__detail"
161-
>{{subscription.group.name}}</td>
176+
<td class="d-admin-row__detail"><GroupLink
177+
@group={{subscription.group}}
178+
>{{subscription.group.name}}</GroupLink></td>
162179
<td class="d-admin-row__controls">
163180
<DButton
164181
@icon="pencil"

app/serializers/discourse_kofi/admin_payment_serializer.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

3-
require "active_support/json"
4-
53
module ::DiscourseKofi
64
class AdminPaymentSerializer < UserPaymentSerializer
75
attributes :is_first_subscription_payment, :message_id, :url, :anonymized
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
# frozen_string_literal: true
22

3-
require "active_support/json"
4-
53
module ::DiscourseKofi
64
class BaseRewardSerializer < ApplicationSerializer
75
root "reward"
86

97
attributes :id, :enabled, :subscription
108

11-
has_one :group, serializer: IdNameSerializer, embed: :objects
9+
has_one :group, serializer: BasicGroupSerializer, embed: :objects
1210
end
1311
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
module ::DiscourseKofi
4+
class BasicBadgeSerializer < ApplicationSerializer
5+
attributes :id, :name, :enabled, :icon, :image, :badgeTypeClassName
6+
7+
def name
8+
object.display_name
9+
end
10+
11+
def image
12+
object.image_url
13+
end
14+
15+
def badgeTypeClassName
16+
"badge-type-" + object.badge_type.name.downcase
17+
end
18+
end
19+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
module ::DiscourseKofi
4+
class BasicGroupSerializer < ApplicationSerializer
5+
attributes :id, :name, :url
6+
7+
def name
8+
object.full_name || object.name
9+
end
10+
11+
def url
12+
object.full_url
13+
end
14+
end
15+
end

app/serializers/discourse_kofi/id_name_serializer.rb

Lines changed: 0 additions & 7 deletions
This file was deleted.

app/serializers/discourse_kofi/payment_serializer.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

3-
require "active_support/json"
4-
53
module ::DiscourseKofi
64
class PaymentSerializer < ApplicationSerializer
75
root "payment"

app/serializers/discourse_kofi/reward_serializer.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# frozen_string_literal: true
22

3-
require "active_support/json"
4-
53
module ::DiscourseKofi
64
class RewardSerializer < BaseRewardSerializer
75
attributes :payment_types, :amount
86

9-
has_one :badge, serializer: IdNameSerializer, embed: :objects
7+
has_one :badge, serializer: BasicBadgeSerializer, embed: :objects
108

119
def initialize(object, options = {})
1210
if object.subscription

app/serializers/discourse_kofi/subscription_reward_serializer.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

3-
require "active_support/json"
4-
53
module ::DiscourseKofi
64
class SubscriptionRewardSerializer < BaseRewardSerializer
75
attributes :tier_name

app/serializers/discourse_kofi/user_payment_serializer.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

3-
require "active_support/json"
4-
53
module ::DiscourseKofi
64
# User's view on payments
75
class UserPaymentSerializer < PaymentSerializer

0 commit comments

Comments
 (0)