Skip to content

Commit

Permalink
Bugfix & code optimization.
Browse files Browse the repository at this point in the history
  • Loading branch information
aNd1coder committed Jan 20, 2016
1 parent ebdb29c commit 2b46774
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 18 deletions.
3 changes: 2 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ app.locals.PROJECT = {
app.locals.FILETYPE = {
html: 'HTML',
css: 'CSS',
js: 'JS'
js: 'JS',
other: '其他'
};

app.locals.MODULETYPE = {
Expand Down
2 changes: 1 addition & 1 deletion helper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
count = Math.ceil(total / limit);
prev = page <= 1 ? false : page - 1;
next = page >= count ? false : page + 1;
url = url.replace(/&page=\d+/, '').replace(/\?page=\d+/, '');
url = url.replace(/[?|&]page=\d+/, '');
p = (url.indexOf('?') != -1 ? '&' : '?') + 'page=';
prev = prev ? url + p + prev : false;
next = next ? url + p + next : false;
Expand Down
7 changes: 7 additions & 0 deletions routes/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ router.post('/save', function (req, res) {

model.title = (model.title || '').trim();
model.content = (model.content || '').trim();

if (model.filetype == 'html') {
model.content = model.content.replace(/>(\s+)|(\s+)</gim, function (s) {
return s.replace(/\s+/, '');
});
}

model.template = (model.template || '').trim();
model.templateData = (model.templateData || '').trim();

Expand Down
4 changes: 3 additions & 1 deletion routes/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ router.post('/save', function (req, res) {
console.log(err);
} else {
if (published) {
// merge template & page content
// merge template and page content,keep content in one line
model.content = template.content.replace(/{{(\w+)}}/gi, function (m, p) {
return model[p];
}).replace(/>(\s+)|(\s+)</gim, function (s) {
return s.replace(/\s+/, '');
});

// push to page server
Expand Down
1 change: 0 additions & 1 deletion views/component/form.jade
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
- var modules = model && model.module && model.module.length > 0 ? model.module: [['','','','','','']]
.form-group
label.control-label 项目
select.form-control(name="project")
Expand Down
17 changes: 3 additions & 14 deletions views/component/gridview.jade
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- var ENVLABELMAP = {'dev':'default','test':'info','pre':'primary'}
form.form.form-inline.well(method="get",action="/#{controllerName}/")
.form-group
label.control-label 项目
Expand Down Expand Up @@ -56,20 +57,8 @@ table.table.table-striped.table-hover
td= moment(new Date(m.createdAt)).format('YYYY-MM-DD HH:MM:SS')
td= moment(new Date(m.updatedAt)).format('YYYY-MM-DD HH:MM:SS')
td
if ENVIRONMENT[m.environment]
if m.environment == 'dev'
span.label.label-default= ENVIRONMENT[m.environment]
else if m.environment == 'test'
span.label.label-info= ENVIRONMENT[m.environment]
else if m.environment == 'pre'
span.label.label-primary= ENVIRONMENT[m.environment]
else
span.label.label-success= ENVIRONMENT[m.environment]

if m.published == 1
span.label.label-success 已发布
else
span.label.label-danger 草稿
span(class="label label-#{ENVLABELMAP[m.environment] || 'success'}")= ENVIRONMENT[m.environment]
span(class="label label-#{m.published == 1 ? 'success' : 'danger'}")= m.published == 1 ? '已发布' : '草稿'
td
if(user.isSuperAdmin)
a.btn.btn-default.btn-delete(href="/#{controllerName}/delete/#{m._id}") 删除
Expand Down
1 change: 1 addition & 0 deletions views/component/module.jade
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- var modules = model && model.module && model.module.length > 0 ? model.module: [['','','','','','']]
each m in modules
.form-group
.input-group
Expand Down

0 comments on commit 2b46774

Please sign in to comment.