Improve badge grouping UI

Start work on triggers
This commit is contained in:
Sam 2014-07-22 11:11:30 +10:00
parent 375f0815b6
commit b9a7d945c3
9 changed files with 42 additions and 20 deletions

View file

@ -5,6 +5,10 @@ Discourse.AdminBadgesRoute = Discourse.Route.extend({
}, },
setupController: function(controller, model) { 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) { Discourse.ajax('/admin/badges/types').then(function(json) {
controller.set('badgeTypes', json.badge_types); controller.set('badgeTypes', json.badge_types);
}); });

View file

@ -47,6 +47,15 @@
disabled=readOnly}} disabled=readOnly}}
</div> </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> <div>
<label for="description">{{i18n admin.badges.description}}</label> <label for="description">{{i18n admin.badges.description}}</label>
{{#if controller.canEditDescription}} {{#if controller.canEditDescription}}

View file

@ -124,7 +124,8 @@ Discourse.Badge = Discourse.Model.extend({
multiple_grant: !!this.get('multiple_grant'), multiple_grant: !!this.get('multiple_grant'),
listable: !!this.get('listable'), listable: !!this.get('listable'),
enabled: !!this.get('enabled'), enabled: !!this.get('enabled'),
icon: this.get('icon') icon: this.get('icon'),
badge_grouping_id: this.get('badge_grouping_id')
} }
}).then(function(json) { }).then(function(json) {
self.updateFromJson(json); self.updateFromJson(json);

View file

@ -4,6 +4,11 @@ class Admin::BadgesController < Admin::AdminController
render_serialized(badge_types, BadgeTypeSerializer, root: "badge_types") render_serialized(badge_types, BadgeTypeSerializer, root: "badge_types")
end end
def badge_groupings
badge_groupings = BadgeGrouping.all.to_a
render_serialized(badge_groupings, BadgeGroupingSerializer, root: "badge_groupings")
end
def create def create
badge = Badge.new badge = Badge.new
update_badge_from_params(badge) update_badge_from_params(badge)
@ -30,15 +35,13 @@ class Admin::BadgesController < Admin::AdminController
end end
def update_badge_from_params(badge) def update_badge_from_params(badge)
params.permit(:name, :description, :badge_type_id, :allow_title, :multiple_grant, :listable, :enabled) allowed = [:icon, :name, :description, :badge_type_id, :allow_title, :multiple_grant, :listable, :enabled, :badge_grouping_id]
badge.name = params[:name] params.permit(*allowed)
badge.description = params[:description]
badge.badge_type = BadgeType.find(params[:badge_type_id]) allowed.each do |key|
badge.allow_title = params[:allow_title] badge.send("#{key}=" , params[key]) if params[key]
badge.multiple_grant = params[:multiple_grant] end
badge.icon = params[:icon]
badge.listable = params[:listable]
badge.enabled = params[:enabled]
badge badge
end end
end end

View file

@ -17,6 +17,12 @@ class Badge < ActiveRecord::Base
# other consts # other consts
AutobiographerMinBioLength = 10 AutobiographerMinBioLength = 10
module Triggers
PostAction = 1
ReadGuidelines = 2
PostRevision = 4
TrustLevelChange = 8
end
module Queries module Queries

View file

@ -1,13 +1,5 @@
class BadgeSerializer < ApplicationSerializer 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_type
has_one :badge_grouping
def include_has_badge?
@options[:user_badges]
end
def has_badge
@options[:user_badges].include?(object.id)
end
end end

View file

@ -1888,6 +1888,7 @@ en:
display_name: Display Name display_name: Display Name
description: Description description: Description
badge_type: Badge Type badge_type: Badge Type
badge_grouping: Group
granted_by: Granted By granted_by: Granted By
granted_at: Granted At granted_at: Granted At
save: Save save: Save

View file

@ -146,6 +146,7 @@ Discourse::Application.routes.draw do
resources :badges, constraints: AdminConstraint.new do resources :badges, constraints: AdminConstraint.new do
collection do collection do
get "types" => "badges#badge_types" get "types" => "badges#badge_types"
get "groupings" => "badges#badge_groupings"
end end
end end

View file

@ -0,0 +1,5 @@
class AddTriggerToBadges < ActiveRecord::Migration
def change
add_column :badges, :trigger, :integer
end
end