mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 06:04:11 +08:00
Improve badge grouping UI
Start work on triggers
This commit is contained in:
parent
375f0815b6
commit
b9a7d945c3
|
@ -5,6 +5,10 @@ Discourse.AdminBadgesRoute = Discourse.Route.extend({
|
|||
},
|
||||
|
||||
setupController: function(controller, model) {
|
||||
// TODO build into findAll
|
||||
Discourse.ajax('/admin/badges/groupings').then(function(json) {
|
||||
controller.set('badgeGroupings', json.badge_groupings);
|
||||
});
|
||||
Discourse.ajax('/admin/badges/types').then(function(json) {
|
||||
controller.set('badgeTypes', json.badge_types);
|
||||
});
|
||||
|
|
|
@ -47,6 +47,15 @@
|
|||
disabled=readOnly}}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="badge_grouping_id">{{i18n admin.badges.badge_grouping}}</label>
|
||||
{{view Ember.Select name="badge_grouping_id" value=badge_grouping_id
|
||||
content=controller.badgeGroupings
|
||||
optionValuePath="content.id"
|
||||
optionLabelPath="content.name"
|
||||
disabled=readOnly}}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="description">{{i18n admin.badges.description}}</label>
|
||||
{{#if controller.canEditDescription}}
|
||||
|
|
|
@ -124,7 +124,8 @@ Discourse.Badge = Discourse.Model.extend({
|
|||
multiple_grant: !!this.get('multiple_grant'),
|
||||
listable: !!this.get('listable'),
|
||||
enabled: !!this.get('enabled'),
|
||||
icon: this.get('icon')
|
||||
icon: this.get('icon'),
|
||||
badge_grouping_id: this.get('badge_grouping_id')
|
||||
}
|
||||
}).then(function(json) {
|
||||
self.updateFromJson(json);
|
||||
|
|
|
@ -4,6 +4,11 @@ class Admin::BadgesController < Admin::AdminController
|
|||
render_serialized(badge_types, BadgeTypeSerializer, root: "badge_types")
|
||||
end
|
||||
|
||||
def badge_groupings
|
||||
badge_groupings = BadgeGrouping.all.to_a
|
||||
render_serialized(badge_groupings, BadgeGroupingSerializer, root: "badge_groupings")
|
||||
end
|
||||
|
||||
def create
|
||||
badge = Badge.new
|
||||
update_badge_from_params(badge)
|
||||
|
@ -30,15 +35,13 @@ class Admin::BadgesController < Admin::AdminController
|
|||
end
|
||||
|
||||
def update_badge_from_params(badge)
|
||||
params.permit(:name, :description, :badge_type_id, :allow_title, :multiple_grant, :listable, :enabled)
|
||||
badge.name = params[:name]
|
||||
badge.description = params[:description]
|
||||
badge.badge_type = BadgeType.find(params[:badge_type_id])
|
||||
badge.allow_title = params[:allow_title]
|
||||
badge.multiple_grant = params[:multiple_grant]
|
||||
badge.icon = params[:icon]
|
||||
badge.listable = params[:listable]
|
||||
badge.enabled = params[:enabled]
|
||||
allowed = [:icon, :name, :description, :badge_type_id, :allow_title, :multiple_grant, :listable, :enabled, :badge_grouping_id]
|
||||
params.permit(*allowed)
|
||||
|
||||
allowed.each do |key|
|
||||
badge.send("#{key}=" , params[key]) if params[key]
|
||||
end
|
||||
|
||||
badge
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,6 +17,12 @@ class Badge < ActiveRecord::Base
|
|||
# other consts
|
||||
AutobiographerMinBioLength = 10
|
||||
|
||||
module Triggers
|
||||
PostAction = 1
|
||||
ReadGuidelines = 2
|
||||
PostRevision = 4
|
||||
TrustLevelChange = 8
|
||||
end
|
||||
|
||||
module Queries
|
||||
|
||||
|
|
|
@ -1,13 +1,5 @@
|
|||
class BadgeSerializer < ApplicationSerializer
|
||||
attributes :id, :name, :description, :grant_count, :allow_title, :multiple_grant, :icon, :listable, :enabled, :has_badge
|
||||
attributes :id, :name, :description, :grant_count, :allow_title,
|
||||
:multiple_grant, :icon, :listable, :enabled, :badge_grouping_id
|
||||
has_one :badge_type
|
||||
has_one :badge_grouping
|
||||
|
||||
def include_has_badge?
|
||||
@options[:user_badges]
|
||||
end
|
||||
|
||||
def has_badge
|
||||
@options[:user_badges].include?(object.id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1888,6 +1888,7 @@ en:
|
|||
display_name: Display Name
|
||||
description: Description
|
||||
badge_type: Badge Type
|
||||
badge_grouping: Group
|
||||
granted_by: Granted By
|
||||
granted_at: Granted At
|
||||
save: Save
|
||||
|
|
|
@ -146,6 +146,7 @@ Discourse::Application.routes.draw do
|
|||
resources :badges, constraints: AdminConstraint.new do
|
||||
collection do
|
||||
get "types" => "badges#badge_types"
|
||||
get "groupings" => "badges#badge_groupings"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
5
db/migrate/20140721063820_add_trigger_to_badges.rb
Normal file
5
db/migrate/20140721063820_add_trigger_to_badges.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class AddTriggerToBadges < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :badges, :trigger, :integer
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user