refactor front-end

This commit is contained in:
jysperm
2015-05-26 05:28:54 +08:00
parent 3f48c86117
commit c4c85ae2c9
16 changed files with 72 additions and 41 deletions

15
.npmignore Normal file
View File

@@ -0,0 +1,15 @@
*~
.DS_Store
.idea/
.vagrant/
node_modules/
bower_components/
/package.box
/npm-debug.log
/.remote-sync.json
/session.key
/config.coffee
/coverage-reporter.html

0
app.coffee Executable file → Normal file
View File

View File

@@ -7,7 +7,12 @@
"jquery": "~2.1.2",
"backbone": "~1.1.2",
"moment": "~2.9.0",
"jquery-tmpl": "vBeta1.0.0",
"jquery-tmpl": "git://github.com/jquery/jquery-tmpl.git#b504c8afba",
"q": "~1.2.0"
},
"overrides": {
"jquery-tmpl": {
"main": "jquery.tmpl.js"
}
}
}

View File

@@ -4,7 +4,7 @@ $ ->
CompontentCollection = Backbone.Collection.extend
model: Component
url: '/component/resource/'
url: '/components/'
ListItemView = Backbone.View.extend
tagName: 'tr'

View File

@@ -1,9 +1,4 @@
$ ->
_.templateSettings =
evaluate: /\{%([\s\S]+?)%\}/g,
interpolate: /\{:([\s\S]+?)\}\}/g
escape: /\{\{([\s\S]+?)\}\}/g
_.extend window.RP,
i18n_data: {}

View File

@@ -3,9 +3,17 @@ methods = ['get', 'post', 'delete', 'put', 'patch', 'head', 'options']
window.root =
agent: {}
# Private: (name) -> String
t: (name) ->
return name
# Private: (selector) -> (view_data) -> String
tmpl: (selector) ->
cache = $(selector).template()
return (view_data) ->
return $.tmpl cache, view_data
methods.forEach (method) ->
root.agent[method] = (url, data, options = {}) ->
unless method == 'get'

View File

@@ -1,4 +1,8 @@
$ ->
$.ajaxSetup
headers:
'X-Token': $.cookie 'token'
color_mapping =
closed: 'muted'
open: 'primary'
@@ -12,7 +16,7 @@ $ ->
model: Reply
Ticket = Backbone.Model.extend
urlRoot: '/ticket/rest/'
urlRoot: '/tickets'
idAttribute: '_id'
initialize: ->
@@ -24,7 +28,7 @@ $ ->
TicketCollection = Backbone.Collection.extend
model: Ticket
url: '/ticket/rest/'
url: '/tickets'
CreateView = Backbone.View.extend
el: '#create-view'
@@ -38,14 +42,14 @@ $ ->
content: @$('[name=content]').val()
ticket.save().success (ticket) ->
location.href = "/ticket/view/#{ticket._id}"
location.href = "/tickets/#{ticket._id}/view"
ReplyView = Backbone.View.extend
tagName: 'li'
className: 'list-group-item clearfix'
initialize: ->
@template = RP.tmpl '#reply-template'
@template = root.tmpl '#reply-template'
@model.on 'change', @render.bind @
render: ->
@@ -70,10 +74,10 @@ $ ->
@model.fetch()
@templateContent = RP.tmpl '#content-template'
@templateActions = RP.tmpl '#actions-template'
@templateAccountInfo = RP.tmpl '#account-info-template'
@templateMembers = RP.tmpl '#members-template'
@templateContent = root.tmpl '#content-template'
@templateActions = root.tmpl '#actions-template'
@templateAccountInfo = root.tmpl '#account-info-template'
@templateMembers = root.tmpl '#members-template'
render: ->
view_data = @model.toJSON()
@@ -108,7 +112,7 @@ $ ->
tagName: 'tr'
initialize: ->
@template = RP.tmpl '#list-item-template'
@template = root.tmpl '#list-item-template'
render: ->
view_data = @model.toJSON()
@@ -132,9 +136,9 @@ $ ->
TicketRouter = Backbone.Router.extend
routes:
'ticket/create(/)': 'create'
'ticket/list(/)': 'list'
'ticket/view/:id(/)': 'view'
'tickets/create(/)': 'create'
'tickets/list(/)': 'list'
'tickets/:id/view(/)': 'view'
create: -> new CreateView()
list: -> new ListView()

View File

@@ -16,6 +16,7 @@ router.use requireAuthenticate
###
router.get '/financials', (req, res, next) ->
Q.all([
null
Financials.getDepositLogs req.account, req: req, limit: 10
Financials.getBillingLogs req.account, limit: 10
]).done ([payment_providers, deposit_logs, billing_logs]) ->

View File

@@ -1,4 +1,4 @@
describe 'account.register', ->
describe 'router.account', ->
agent = createAgent
baseUrl: '/account'

View File

@@ -1,4 +1,4 @@
describe 'tickets.user', ->
describe 'router.tickets', ->
agent = createLoggedAgent
baseUrl: '/tickets'

View File

@@ -18,7 +18,7 @@ block main
th= t('common.amount')
th= t('view.financials.pay_method')
tbody
for item in deposit_log
for item in deposit_logs
tr
td= moment(item.created_at).format('YYYY-MM-DD HH:mm:ss')
td #{item.amount.toFixed(2)} #{t('plan.currency.' + config.billing.currency)}
@@ -36,7 +36,7 @@ block main
th= t('common.details')
th= t('common.amount')
tbody
for item in billing_log
for item in billing_logs
tr
td= moment(item.created_at).format('YYYY-MM-DD HH:mm:ss')
td

View File

@@ -22,6 +22,6 @@ prepend sidebar
append footer
script(id='list-item-template', type='text/x-jquery-tmpl')
td
a(href='/tickets/view/${_id}') ${title}
a(href='/tickets/${_id}/view') ${title}
td
span(class='text-${color}') ${RP.t('ticket_status.' + status)}
span(class='text-${color}') ${root.t('ticket_status.' + status)}

View File

@@ -24,7 +24,7 @@ append footer
script(id='content-template', type='text/x-jquery-tmpl')
header
| ${title}  
span.small(class='text-${color}') ${RP.t('ticket_status.' + status)}
span.small(class='text-${color}') ${root.t('ticket_status.' + status)}
p {{html content_html}}
script(id='reply-template', type='text/x-jquery-tmpl')

View File

@@ -2,6 +2,7 @@ del = require 'del'
gulp = require 'gulp'
less = require 'gulp-less'
shell = require 'gulp-shell'
debug = require 'gulp-debug'
order = require 'gulp-order'
rsync = require 'gulp-rsync'
coffee = require 'gulp-coffee'
@@ -34,7 +35,7 @@ gulp.task 'vendor:scripts', ->
gulp.task 'vendor:fonts', ->
gulp.src bowerFiles()
.pipe filter ['*.eot', '*.svg', '*.ttf', '*.woff']
.pipe filter ['*.eot', '*.svg', '*.ttf', '*.woff', '*.woff2']
.pipe gulp.dest 'public/fonts'
gulp.task 'build:vendor', ->
@@ -51,7 +52,7 @@ gulp.task 'build:styles', ->
gulp.src 'core/public/style/*.less'
.pipe less()
.pipe concat 'core.css'
.pipe minifyCss()
# .pipe minifyCss()
.pipe gulp.dest 'public'
gulp.task 'build:scripts', ->
@@ -59,7 +60,7 @@ gulp.task 'build:scripts', ->
.pipe coffee()
.pipe order ['root.coffee', '*']
.pipe concat 'core.js'
.pipe uglify()
# .pipe uglify()
.pipe gulp.dest 'public'
gulp.task 'watch', ->

View File

@@ -17,8 +17,9 @@
],
"main": "core",
"scripts": {
"prepushlish": "gulp build",
"start": "coffee app.coffee",
"test": "mocha --compilers coffee:coffee-script/register --require test/env -- core/test/*.test.coffee",
"test": "mocha --compilers coffee:coffee-script/register --require test/env --recursive core/test",
"docker-build": "docker build -t=jysperm/rootpanel .",
"docker-create": "docker run --name rootpanel -P -v `pwd`:/rootpanel -i -t jysperm/rootpanel",
"docker-start": "docker start -i -a rootpanel"
@@ -67,6 +68,7 @@
"gulp": "^3.8.11",
"gulp-coffee": "^2.3.1",
"gulp-concat": "^2.5.2",
"gulp-debug": "^2.0.1",
"gulp-filter": "^2.0.2",
"gulp-less": "^3.0.3",
"gulp-minify-css": "^1.1.0",

View File

@@ -101,6 +101,17 @@ createLoggedAgent = (options) ->
return agent
_.extend global, {
utils
ifEnabled
unlessTravis
randomAccount
createAgent
createLoggedAgent
}
printHttpResponse = ({httpVersion, statusCode, statusMessage, headers, body}) ->
message = """
Response:
@@ -119,14 +130,3 @@ printHttpResponse = ({httpVersion, statusCode, statusMessage, headers, body}) ->
message += "\n#{body}"
return message
_.extend global, {
utils
ifEnabled
unlessTravis
randomAccount
createAgent
createLoggedAgent
}