Skip to content

Commit

Permalink
add setting/widget page
Browse files Browse the repository at this point in the history
  • Loading branch information
lizheming committed Dec 20, 2015
1 parent b51136a commit 1e62aa2
Show file tree
Hide file tree
Showing 12 changed files with 2,529 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/common/config/locale/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default {
'snapshot-warning': 'It\'s a snaphot of %s in datetime %s, It has nothing to do with the author of this page. change to',
'login': 'Login',
'logout': 'Logout',
'setting': 'Setting',
'delete': 'Delete',
'edit': 'Edit',
'generating': 'Generating...',
Expand All @@ -32,6 +33,7 @@ export default {
'pagination-total': 'Totoal %s records, total %s pages',
'prev-page': 'Prev',
'next-page': 'Next',
'widget-more': 'More...',
'token-not-valid': 'Token not valid!',
'TOKEN_INVALID': [1000, 'token invalid!'],
'NEED_LOGIN': [1001, 'need login!'],
Expand Down
2 changes: 2 additions & 0 deletions src/common/config/locale/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default {
'snapshot-warning': '下面是原始网页 在 %s 的快照。%s 与该网页作者无关,不对其内容负责。切换到',
'login': '登录',
'logout': '注销',
'setting': '设置',
'delete': '删除',
'edit': '修改',
'generating': '生成中...',
Expand All @@ -32,6 +33,7 @@ export default {
'pagination-total': '共有 %s 条记录,共 %s 页',
'prev-page': '上一页',
'next-page': '下一页',
'widget-more': '更多收藏',
'TOKEN_INVALID': [1000, '密码错误'],
'NEED_LOGIN': [1001, '需要登陆'],
'SAVE_FAIL': [1002, '保存失败'],
Expand Down
12 changes: 12 additions & 0 deletions src/home/controller/setting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';
import Base from './base.js';

export default class extends Base {
/**
* index action
* @return {Promise} []
*/
indexAction(){
return this.display();
}
}
16 changes: 16 additions & 0 deletions src/home/controller/widget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

import Base from './base.js';

export default class extends Base {
/**
* index action
* @return {Promise} []
*/
async indexAction(){
let data = await this.model('article').order('id DESC').limit(5).select();
this.assign('articleList', data);
this.type('application/javascript');
return this.display();
}
}
16 changes: 16 additions & 0 deletions src/home/logic/setting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';
/**
* logic
* @param {} []
* @return {} []
*/
export default class extends think.logic.base {
/**
* index action logic
*/
indexAction() {
if( this.cookie('token') !== this.config('token') ) {
return this.redirect('/');
}
}
}
1 change: 1 addition & 0 deletions view/home/article_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ <h2>
{% block footer %}
{% if isLogin %}
<a title="{{ _('drag-to-bookmark-bar') }}" href='{{bookmarks}}' onClick="return false;">{{ _('add-to-bookmarks') }}</a> |
<a href="/setting">{{_('setting')}}</a> |
<a href="/user/logout">{{ _('logout') }}</a>
{% else %}
<a href="/user/login">{{ _('login') }}</a>
Expand Down
1 change: 1 addition & 0 deletions view/home/inc/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
}

</style>
{% block head %}{% endblock %}
</head>
<body role="document">
<div class="container theme-showcase" role="main">
Expand Down
29 changes: 29 additions & 0 deletions view/home/setting_index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% extends './inc/base.html' %}

{% block head %}
<script src="/static/module/jquery/jquery-2.1.4.js"></script>
<script src="/static/module/bootstrap/js/bootstrap.min.js"></script>
{% endblock %}

{% block body %}
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#widget" aria-controls="widget" data-toggle="tab">挂件</a></li>
</ul>
<div class="tab-content">
<div role="tabpanel" id="widget" class="tab-pane active">
<div class="row" style="margin-top: 20px;">
<div class="col-md-6">
<p>复制以下代码到你的网站中:</p>
<textarea style="width:100%;height:200px;resize:none;"><div id="cicada-widget"></div><script src="{{config.protocol}}://{{http.host}}/widget"></script></textarea>
</div>
<div class="col-md-6">
<div id="cicada-widget"></div>
<script src="{{config.protocol}}://{{http.host}}/widget"></script>
</div>
</div>
</div>
<div role="tabpanel" id="password" class="tab-pane">
test
</div>
</div>
{% endblock %}
67 changes: 67 additions & 0 deletions view/home/widget_index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{%- set classname = 'cicada-widget-'+config.port -%}
{%- set url = config.protocol + '://' + http.host -%}
(function() {
var d = document, s = d.createElement('style');
var i = '<div class="{{classname}}"><div class="title">{{config.website_title | escape}}</div><ul>
{%- for article in articleList -%}
<li><a href="{{article.url}}" target="cicada">{{article.title | escape}}</a><datetime>{{article.create_time}}</datetime></li>
{%- endfor -%}
</ul><div class="footer"> <a href="{{url}}" target="_blank">{{_('widget-more')}}</a> <span>power by <a href="https://github.com/thinkjs-team/cicada">cicada</a></div></div>';
s.innerHTML = '.{{classname}} {\
background: #A4D4E8;\
padding: 5px 10px;\
width: 100%;\
}\
.{{classname}} .title {\
font-size: 18px;\
font-weight: bold;\
margin-bottom: 5px;\
color: #265778;\
}\
.{{classname}} ul {\
list-style: none;\
margin: 0;\
padding: 0;\
}\
.{{classname}} ul li {\
padding: 5px 10px;\
background: #E1F2FA;\
border-radius: 2px;\
}\
.{{classname}} ul li + li {\
margin-top: 5px;\
}\
.{{classname}} ul li > a,\
.{{classname}} ul li > a:hover,\
.{{classname}} ul li > a:visited,\
.{{classname}} ul li:focus {\
color: #4c4c4c;\
}\
.{{classname}} ul li > a:before {\
content: \'\';\
width: 5px;\
height: 5px;\
border-radius: 5px;\
display: inline-block;\
background: #A4D4E8;\
border: 1px solid #4c4c4c;\
margin-right: 5px;\
}\
.{{classname}} ul li > datetime {\
display: block;\
font-size: 12px;\
color: #ccc;\
font-family: Georgia, serif;\
}\
.{{classname}} .footer {\
color: #265778;\
font-size: 12px;\
padding: 10px 0 5px\
}\
.{{classname}} .footer span {\
font-style: italic;\
float: right;\
}';
d.head.appendChild(s);
d.getElementById('cicada-widget').innerHTML = i;
})();
Loading

0 comments on commit 1e62aa2

Please sign in to comment.