Skip to content

Commit 17a4271

Browse files
committed
Add GA setting frontend
1 parent 706e405 commit 17a4271

File tree

7 files changed

+146
-1
lines changed

7 files changed

+146
-1
lines changed

app/assets/javascripts/admin/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ define(function(require, exports, module) {
5252
.when('/setting/category', setting.createRoute('./controller/category'))
5353
.when('/setting/password', setting.createRoute('./controller/password'))
5454
.when('/setting/disqus', setting.createRoute('./controller/disqus'))
55+
.when('/setting/ga', setting.createRoute('./controller/ga'))
5556
.when('/setting/attach', setting.createRoute('./controller/attach', {reloadOnSearch: false}))
5657

5758
.when('/dashboard', dashboard.createRoute('./controller/index'))
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* 修改 Disqus 设置
3+
*/
4+
define(function(require, exports, module) {
5+
var angular = require('angularjs');
6+
7+
var Controller = ['$scope', 'GA', 'Attach', 'RelativeUrlFactory', 'ErrorMessage', '$timeout', function($scope, GA, Attach, RelativeUrlFactory, ErrorMessage, $timeout) {
8+
$scope.relativeUrl = RelativeUrlFactory.create(module);
9+
$scope.navClass = 'ga';
10+
$scope.ga = GA.get();
11+
12+
ErrorMessage.extend({
13+
ga: {
14+
api_email: {
15+
required: '请填写 Shortname'
16+
}
17+
}
18+
});
19+
20+
$scope.upload = function(files) {
21+
$scope.ga.secret_file = Attach.create({
22+
originalFile: files[0]
23+
});
24+
};
25+
26+
$scope.save = function() {
27+
$scope.ga.$resolved = false;
28+
if ($scope.form.$valid) {
29+
$scope.ga.$update(function() {
30+
$scope.saveSuccess = true;
31+
$timeout(function() {
32+
$scope.saveSuccess = false;
33+
}, 3000);
34+
}, function(resp) {
35+
$scope.serverError = resp.data.errors;
36+
});
37+
}
38+
};
39+
}];
40+
41+
Controller.title = 'GA 设置';
42+
Controller.nav = 'setting';
43+
44+
module.exports = Controller;
45+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* GA 设置
3+
*/
4+
define(function (require, exports, module) {
5+
6+
module.exports = {
7+
'GA': ['$resource', function ($resource) {
8+
var URL = '/admin/ga';
9+
10+
var GA = $resource(URL, null, {
11+
update: {
12+
method: 'PUT'
13+
}
14+
});
15+
16+
return GA;
17+
}]
18+
};
19+
});

app/assets/javascripts/admin/setting/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ define(function(require, exports, module) {
1111
setting.seajsController(require('./controller/password'));
1212
setting.seajsController(require('./controller/website'));
1313
setting.seajsController(require('./controller/attach'));
14+
setting.seajsController(require('./controller/ga'));
1415

1516
setting.factory(require('./factory/website'));
1617
setting.factory(require('./factory/password'));
1718
setting.factory(require('./factory/disqus'));
19+
setting.factory(require('./factory/ga'));
1820

1921
setting.directive(require('./directive/ng-equal-to'));
2022

app/assets/javascripts/admin/setting/template/disqus.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<div class="intro">
99
<p>
1010
Klog2 不再自己实现评论系统,而采用 <a target="_blank" href="http://disqus.com/">Disqus 评论插件</a> <br/>
11-
您需要先申请一个 Disqus 帐号,然后创建 <a href="http://help.disqus.com/customer/portal/articles/787016-how-to-create-an-api-application">API application</a> ,最后将相应的参数填写到这里
11+
您需要先申请一个 Disqus 帐号,然后创建 <a href="http://help.disqus.com/customer/portal/articles/787016-how-to-create-an-api-application" target="_blank">API application</a> ,最后将相应的参数填写到这里
1212
</p>
1313
<p>
1414
<button class="btn btn-primary" ng-click="enableDisqus(true)" ng-if="!disqus.enable">
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<div class="row full-height setting-wrap">
2+
<div class="col-md-1 nav-wrap">
3+
<div ng-include="relativeUrl('./nav.html')"></div>
4+
</div>
5+
<div class="col-md-11 full-height panel-wrap">
6+
<div class="panel panel-default full-height">
7+
<div class="panel-body full-height">
8+
<div class="intro">
9+
<p>
10+
Klog2 可以嵌入 <a
11+
href="https://developers.google.com/analytics/resources/concepts/gaConceptsAccounts"
12+
target="_blank">Google Analytics</a> 统计,
13+
亦可通过 Google API 显示简单的统计报表 <br/>
14+
Google API 的相关设置参见 <a
15+
href="https://github.com/tpitale/legato/wiki/OAuth2-and-Google#service-accounts"
16+
target="_blank">Legato:Server Account</a>
17+
</p>
18+
</div>
19+
<form class="form-horizontal" name="form" ng-submit="save()" validation="password">
20+
<div class="form-group">
21+
<label class="col-md-1 control-label">GA Account</label>
22+
23+
<div class="col-md-5">
24+
<input type="text" class="form-control" ng-model="ga.account"/>
25+
<span class="help-block">填写以开启 Google Analytics 统计(如 UA-XXXX-Y)</span>
26+
</div>
27+
</div>
28+
<div class="form-group">
29+
<label class="col-md-1 control-label">统计图表</label>
30+
31+
<div class="col-md-5">
32+
<label class="radio-inline">
33+
<input type="radio" ng-value="true" ng-model="ga.chart_enable"/> 显示
34+
</label>
35+
<label class="radio-inline">
36+
<input type="radio" ng-value="false" ng-model="ga.chart_enable"/> 不显示
37+
</label>
38+
</div>
39+
</div>
40+
<div class="form-group">
41+
<label class="col-md-1 control-label">Private Key File</label>
42+
43+
<div class="col-md-5">
44+
<div>{{ ga.secret_file.file_name }}</div>
45+
<button file-input="upload(files)" accept=".p12" ng-disabled="!ga.chart_enable" type="button" class="btn btn-default btn-sm">上传文件</button>
46+
47+
<div error-for="form.new_pw"></div>
48+
</div>
49+
</div>
50+
<div class="form-group">
51+
<label class="col-md-1 control-label">API Email</label>
52+
53+
<div class="col-md-5">
54+
<input type="email" class="form-control" ng-disabled="!ga.chart_enable" name="api_email"
55+
ng-model="ga.api_email" />
56+
57+
<div error-for="form.api_email"></div>
58+
</div>
59+
</div>
60+
<div class="form-group">
61+
<label class="col-md-1 control-label"></label>
62+
63+
<div class="col-md-5">
64+
<button type="submit" class="btn btn-primary btn-lg" loading-btn
65+
loading-cancel="saveSuccess || serverError">保 存
66+
</button>
67+
<span class="save-success" ng-show="saveSuccess"><i
68+
class="fa fa-check-circle"></i> 保存成功</span>
69+
</div>
70+
</div>
71+
</form>
72+
</div>
73+
</div>
74+
</div>
75+
</div>

app/assets/javascripts/admin/setting/template/nav.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
<li ng-class="{active: navClass == 'disqus' }">
1212
<a href="#/setting/disqus">Disqus 设置</a>
1313
</li>
14+
<li ng-class="{active: navClass == 'ga' }">
15+
<a href="#/setting/ga">GA 统计</a>
16+
</li>
1417
<li ng-class="{active: navClass == 'attach' }">
1518
<a href="#/setting/attach">附件管理</a>
1619
</li>

0 commit comments

Comments
 (0)