Skip to content

Commit ff2cdb4

Browse files
committed
Add dashboard
1 parent c10d373 commit ff2cdb4

File tree

7 files changed

+132
-0
lines changed

7 files changed

+132
-0
lines changed

app/assets/javascripts/admin/app.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ define(function(require, exports, module) {
3636
var comment = SeajsLazyAngular.createLazyStub(ADMIN_PATH + '/comment/index');
3737
var page = SeajsLazyAngular.createLazyStub(ADMIN_PATH + '/page/index');
3838
var setting = SeajsLazyAngular.createLazyStub(ADMIN_PATH + '/setting/index');
39+
var dashboard = SeajsLazyAngular.createLazyStub(ADMIN_PATH + '/dashboard/index');
3940

4041
$routeProvider
4142
.when('/blog', blog.createRoute('./controller/index'))
@@ -52,6 +53,8 @@ define(function(require, exports, module) {
5253
.when('/setting/password', setting.createRoute('./controller/password'))
5354
.when('/setting/disqus', setting.createRoute('./controller/disqus'))
5455
.when('/setting/attach', setting.createRoute('./controller/attach', {reloadOnSearch: false}))
56+
57+
.when('/dashboard', dashboard.createRoute('./controller/index'))
5558
.otherwise({redirectTo: '/blog'});
5659
}]);
5760

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Dashboard
3+
*/
4+
define(function(require, exports, module) {
5+
6+
var IndexController = ['$scope', '$http', function($scope, $http) {
7+
$http.get('/admin/dashboard').then(function(resp) {
8+
$scope.dashboard = resp.data;
9+
});
10+
11+
$http.get('/admin/dashboard/hot_blogs').then(function(resp) {
12+
$scope.hotBlogs = resp.data;
13+
});
14+
}];
15+
16+
IndexController.title = 'Dashboard';
17+
18+
module.exports = IndexController;
19+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Dashboard HTTP 接口
3+
*/
4+
define(function(require, exports, module) {
5+
6+
module.exports = {
7+
'Dashboard': ['$http', function($http) {
8+
var Dashboard = {
9+
10+
};
11+
12+
return Dashboard;
13+
}]
14+
};
15+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* 设置模块
3+
*/
4+
define(function(require, exports, module) {
5+
var angular = require('angularjs');
6+
7+
var dashboard = angular.module('dashboard', []);
8+
9+
dashboard.seajsController(require('./controller/index'));
10+
11+
dashboard.factory(require('./factory/dashboard'));
12+
13+
14+
module.exports = dashboard;
15+
});
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<div class="row full-height">
2+
<div class="col-md-4">
3+
<div class="panel panel-blue">
4+
<div class="panel-heading clearfix">
5+
<h2>统计</h2>
6+
</div>
7+
<div>
8+
<ul>
9+
<li>
10+
文章 <strong>{{ dashboard.blog.publish }}</strong> 篇,
11+
草稿 <strong>{{ dashboard.blog.draft }}</strong>
12+
</li>
13+
<li>评论 <strong>{{ dashboard.comment }}</strong></li>
14+
<li>分类 <strong>{{ dashboard.category }}</strong></li>
15+
<li>附件 <strong>{{ dashboard.attach.count }}</strong> 个,占用 <strong>{{ dashboard.attach.size
16+
}}</strong></li>
17+
</ul>
18+
</div>
19+
</div>
20+
</div>
21+
22+
<div class="col-md-4">
23+
<div class="panel panel-blue">
24+
<div class="panel-heading clearfix">
25+
<h2>最热 Blog</h2>
26+
</div>
27+
<div>
28+
<ul>
29+
<li ng-repeat="blog in hotBlogs">
30+
<a ng-href="/blog/{{blog.slug}}.html" target="_blank">{{ blog.title }}</a>
31+
<span><i class="fa fa-comments"></i> {{ blog.comment_count}}</span>
32+
</li>
33+
</ul>
34+
</div>
35+
</div>
36+
</div>
37+
</div>
38+
39+
<div class="col-md-4">
40+
<div class="panel panel-blue">
41+
<div class="panel-heading clearfix">
42+
<h2>最热 Blog</h2>
43+
</div>
44+
<div>
45+
<ul>
46+
<li ng-repeat="blog in hotBlogs">
47+
<a ng-href="/blog/{{blog.slug}}.html" target="_blank">{{ blog.title }}</a>
48+
<span><i class="fa fa-comments"></i> {{ blog.comment_count}}</span>
49+
</li>
50+
</ul>
51+
</div>
52+
</div>
53+
</div>
54+
</div>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# 统计
2+
class Admin::DashboardController < Admin::ApplicationController
3+
def show
4+
@blog_publish_count = Blog.with_status(:publish).count
5+
@blog_draft_count = Blog.with_status(:draft).count
6+
@comment_count = Blog.sum(:comment_count)
7+
@category_count = Category.count
8+
@attach_count = Attach.count
9+
@attach_size = Attach.sum('file_size')
10+
11+
render :json => {
12+
:blog => {:publish => @blog_publish_count, :draft => @blog_draft_count},
13+
:comment => @comment_count,
14+
:category => @category_count,
15+
:attach => {:count => @attach_count, :size => view_context.number_to_human_size(@attach_size)},
16+
}
17+
end
18+
19+
def hot_blogs
20+
@hot_blogs = Blog.select(:id, :title, :status, :slug, :comment_count).order('comment_count DESC').limit(5)
21+
22+
render :json => @hot_blogs
23+
end
24+
end

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
namespace :admin do
2424
get '/' => 'home#show'
25+
get '/dashboard' => 'dashboard#show'
26+
get '/dashboard/hot_blogs' => 'dashboard#hot_blogs'
2527

2628
resource :session
2729

0 commit comments

Comments
 (0)