Add /badges route that lists all defined badges.
This commit is contained in:
parent
de23caa871
commit
acfcf0b64e
|
@ -164,7 +164,7 @@ Discourse.Badge.reopenClass({
|
||||||
@returns {Promise} a promise that resolves to an array of `Discourse.Badge`
|
@returns {Promise} a promise that resolves to an array of `Discourse.Badge`
|
||||||
**/
|
**/
|
||||||
findAll: function() {
|
findAll: function() {
|
||||||
return Discourse.ajax('/admin/badges').then(function(badgesJson) {
|
return Discourse.ajax('/badges.json').then(function(badgesJson) {
|
||||||
return Discourse.Badge.createFromJson(badgesJson);
|
return Discourse.Badge.createFromJson(badgesJson);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,4 +94,6 @@ Discourse.Route.buildRoutes(function() {
|
||||||
|
|
||||||
this.route('signup', {path: '/signup'});
|
this.route('signup', {path: '/signup'});
|
||||||
this.route('login', {path: '/login'});
|
this.route('login', {path: '/login'});
|
||||||
|
|
||||||
|
this.route('badges');
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
/**
|
||||||
|
Shows a list of all badges.
|
||||||
|
|
||||||
|
@class BadgesRoute
|
||||||
|
@extends Discourse.Route
|
||||||
|
@namespace Discourse
|
||||||
|
@module Discourse
|
||||||
|
**/
|
||||||
|
Discourse.BadgesRoute = Discourse.Route.extend({
|
||||||
|
model: function() {
|
||||||
|
return Discourse.Badge.findAll();
|
||||||
|
}
|
||||||
|
});
|
|
@ -0,0 +1,13 @@
|
||||||
|
<div class='container'>
|
||||||
|
<h1>{{i18n badges.title}}</h1>
|
||||||
|
|
||||||
|
<table class='badges-listing'>
|
||||||
|
{{#each}}
|
||||||
|
<tr>
|
||||||
|
<td class='badge'>{{user-badge badge=this}}</td>
|
||||||
|
<td class='description'>{{description}}</td>
|
||||||
|
<td class='grant-count'>{{i18n badges.awarded count=grant_count}}</td>
|
||||||
|
</tr>
|
||||||
|
{{/each}}
|
||||||
|
</table>
|
||||||
|
</div>
|
|
@ -1,14 +1,16 @@
|
||||||
.user-badge {
|
.user-badge {
|
||||||
padding: 3px 8px;
|
padding: 3px 8px;
|
||||||
border: 1px solid $secondary-border-color;
|
border: 1px solid $secondary-border-color;
|
||||||
font-size: 12px;
|
font-size: $base-font-size * 0.86;
|
||||||
line-height: 16px;
|
line-height: 16px;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
background-color: $primary_background_color;
|
||||||
|
|
||||||
.fa {
|
.fa {
|
||||||
padding-right: 5px;
|
padding-right: 3px;
|
||||||
font-size: 16px;
|
font-size: 1.4em;
|
||||||
|
vertical-align: bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.badge-type-gold .fa {
|
&.badge-type-gold .fa {
|
||||||
|
@ -23,3 +25,29 @@
|
||||||
color: #cd7f32;
|
color: #cd7f32;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table.badges-listing {
|
||||||
|
margin-top: 20px;
|
||||||
|
border-bottom: 1px solid $primary-border-color;
|
||||||
|
|
||||||
|
.user-badge {
|
||||||
|
font-size: $base-font-size;
|
||||||
|
}
|
||||||
|
|
||||||
|
td {
|
||||||
|
padding: 10px 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
td.grant-count {
|
||||||
|
font-size: 0.8em;
|
||||||
|
color: $secondary_text_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
td.badge, td.grant-count {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr {
|
||||||
|
border-top: 1px solid $primary-border-color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
class Admin::BadgesController < Admin::AdminController
|
class Admin::BadgesController < Admin::AdminController
|
||||||
def index
|
|
||||||
badges = Badge.all.to_a
|
|
||||||
render_serialized(badges, BadgeSerializer, root: "badges")
|
|
||||||
end
|
|
||||||
|
|
||||||
def badge_types
|
def badge_types
|
||||||
badge_types = BadgeType.all.to_a
|
badge_types = BadgeType.all.to_a
|
||||||
render_serialized(badge_types, BadgeTypeSerializer, root: "badge_types")
|
render_serialized(badge_types, BadgeTypeSerializer, root: "badge_types")
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
class BadgesController < ApplicationController
|
||||||
|
def index
|
||||||
|
badges = Badge.all.to_a
|
||||||
|
render_serialized(badges, BadgeSerializer, root: "badges")
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,5 +1,5 @@
|
||||||
class BadgeSerializer < ApplicationSerializer
|
class BadgeSerializer < ApplicationSerializer
|
||||||
attributes :id, :name, :description
|
attributes :id, :name, :description, :grant_count
|
||||||
|
|
||||||
has_one :badge_type
|
has_one :badge_type
|
||||||
end
|
end
|
||||||
|
|
|
@ -1768,12 +1768,16 @@ en:
|
||||||
mark_watching: '<b>m</b> then <b>w</b> Mark topic as watching'
|
mark_watching: '<b>m</b> then <b>w</b> Mark topic as watching'
|
||||||
|
|
||||||
badges:
|
badges:
|
||||||
|
title: Badges
|
||||||
badge_count:
|
badge_count:
|
||||||
one: "1 Badge"
|
one: "1 Badge"
|
||||||
other: "%{count} Badges"
|
other: "%{count} Badges"
|
||||||
more_badges:
|
more_badges:
|
||||||
one: "+1 More"
|
one: "+1 More"
|
||||||
other: "+%{count} More"
|
other: "+%{count} More"
|
||||||
|
awarded:
|
||||||
|
one: "1 awarded"
|
||||||
|
other: "%{count} awarded"
|
||||||
example_badge:
|
example_badge:
|
||||||
name: Example Badge
|
name: Example Badge
|
||||||
description: This is a generic example badge.
|
description: This is a generic example badge.
|
||||||
|
|
|
@ -242,6 +242,7 @@ Discourse::Application.routes.draw do
|
||||||
end
|
end
|
||||||
resources :user_actions
|
resources :user_actions
|
||||||
|
|
||||||
|
resources :badges, only: [:index]
|
||||||
resources :user_badges, only: [:index, :create, :destroy]
|
resources :user_badges, only: [:index, :create, :destroy]
|
||||||
|
|
||||||
# We've renamed popular to latest. If people access it we want a permanent redirect.
|
# We've renamed popular to latest. If people access it we want a permanent redirect.
|
||||||
|
|
|
@ -9,18 +9,6 @@ describe Admin::BadgesController do
|
||||||
let!(:user) { log_in(:admin) }
|
let!(:user) { log_in(:admin) }
|
||||||
let!(:badge) { Fabricate(:badge) }
|
let!(:badge) { Fabricate(:badge) }
|
||||||
|
|
||||||
context '.index' do
|
|
||||||
it 'returns success' do
|
|
||||||
xhr :get, :index
|
|
||||||
response.should be_success
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns JSON' do
|
|
||||||
xhr :get, :index
|
|
||||||
::JSON.parse(response.body)["badges"].should be_present
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context '.badge_types' do
|
context '.badge_types' do
|
||||||
it 'returns success' do
|
it 'returns success' do
|
||||||
xhr :get, :badge_types
|
xhr :get, :badge_types
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe BadgesController do
|
||||||
|
let!(:badge) { Fabricate(:badge) }
|
||||||
|
|
||||||
|
context 'index' do
|
||||||
|
it 'should return a list of all badges' do
|
||||||
|
xhr :get, :index
|
||||||
|
|
||||||
|
response.status.should == 200
|
||||||
|
parsed = JSON.parse(response.body)
|
||||||
|
parsed["badges"].length.should == 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue