mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-04-23 11:17:54 +08:00
many changes about components
This commit is contained in:
@@ -39,7 +39,7 @@ Account.find
|
||||
async.each _.difference(services, original_services), (service_name, callback) ->
|
||||
console.log "#{account.username} enabled #{service_name}"
|
||||
|
||||
async.each pluggable.selectHooks(account, "service.#{service_name}.enable"), (hook, callback) ->
|
||||
async.each pluggable.applyHooks(account, "service.#{service_name}.enable"), (hook, callback) ->
|
||||
hook.filter account, callback
|
||||
, callback
|
||||
, callback
|
||||
@@ -48,7 +48,7 @@ Account.find
|
||||
async.each _.difference(original_services, services), (service_name, callback) ->
|
||||
console.log "#{account.username} disabled #{service_name}"
|
||||
|
||||
async.each pluggable.selectHooks(account, "service.#{service_name}.disable"), (hook, callback) ->
|
||||
async.each pluggable.applyHooks(account, "service.#{service_name}.disable"), (hook, callback) ->
|
||||
hook.filter account, callback
|
||||
, callback
|
||||
, callback
|
||||
|
||||
@@ -8,6 +8,8 @@ process.nextTick ->
|
||||
{available_plugins} = config.plugin
|
||||
|
||||
module.exports = class Plan
|
||||
join_freely: true
|
||||
|
||||
constructor: (info) ->
|
||||
_.extend @, info
|
||||
|
||||
|
||||
@@ -53,7 +53,9 @@ exports.csrf = ->
|
||||
csrf = app.libs.csrf()
|
||||
|
||||
return (req, res, next) ->
|
||||
if req.path in _.pluck app.pluggable.selectHooks('app.ignore_csrf'), 'path'
|
||||
paths = _.pluck app.pluggable.applyHooks('app.ignore_csrf'), 'path'
|
||||
|
||||
if req.path in paths
|
||||
return next()
|
||||
|
||||
csrf_token = do ->
|
||||
@@ -127,7 +129,10 @@ exports.accountHelpers = (req, res, next) ->
|
||||
t: res.t
|
||||
moment: res.moment
|
||||
|
||||
selectHooks: app.pluggable.selectHooks
|
||||
applyHooks: (name, options) ->
|
||||
app.pluggable.applyHooks name, req.account, _.extend {
|
||||
execute: false
|
||||
}, options
|
||||
|
||||
next()
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ Account.register = (account, callback) ->
|
||||
|
||||
pluggable: {}
|
||||
|
||||
async.each pluggable.selectHooks('account.before_register'), (hook, callback) ->
|
||||
async.each pluggable.applyHooks('account.before_register'), (hook, callback) ->
|
||||
hook.filter account, callback
|
||||
, ->
|
||||
account.save (err) ->
|
||||
|
||||
@@ -70,13 +70,8 @@ pluggable.selectHookPath = (name) ->
|
||||
|
||||
return ref
|
||||
|
||||
pluggable.applyHooks = (name, account, options) ->
|
||||
options = _.extend {
|
||||
op: 'action'
|
||||
execute: true
|
||||
}, options
|
||||
|
||||
{op, execute} = options
|
||||
pluggable.applyHooks = (name, account, options = {}) ->
|
||||
{execute} = options
|
||||
|
||||
result = []
|
||||
|
||||
@@ -93,7 +88,7 @@ pluggable.applyHooks = (name, account, options) ->
|
||||
params.push component if component
|
||||
params.push callback
|
||||
|
||||
hook[op].apply null, params
|
||||
hook[execute].apply null, params
|
||||
|
||||
else
|
||||
result.push _.extend {}, hook, payload
|
||||
|
||||
@@ -9,7 +9,7 @@ exports.use requireAdminAuthenticate
|
||||
|
||||
exports.get '/', (req, res) ->
|
||||
Account.find {}, (err, accounts) ->
|
||||
async.map pluggable.selectHooks('view.admin.sidebars'), (hook, callback) ->
|
||||
async.map pluggable.applyHooks('view.admin.sidebars'), (hook, callback) ->
|
||||
hook.generator req, (html) ->
|
||||
callback null, html
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@ componentParam = (req, res, next, id) ->
|
||||
|
||||
next()
|
||||
|
||||
exports.param 'id', componentParam
|
||||
|
||||
exports.use '/resource', do ->
|
||||
rest = new express.Router mergeParams: true
|
||||
rest.param 'id', componentParam
|
||||
|
||||
@@ -13,7 +13,7 @@ exports.get '/financials', (req, res) ->
|
||||
|
||||
async.parallel
|
||||
payment_methods: (callback) ->
|
||||
async.map pluggable.selectHooks('billing.payment_methods'), (hook, callback) ->
|
||||
async.map pluggable.applyHooks('billing.payment_methods'), (hook, callback) ->
|
||||
hook.widgetGenerator req, (html) ->
|
||||
callback null, html
|
||||
, callback
|
||||
@@ -30,7 +30,7 @@ exports.get '/financials', (req, res) ->
|
||||
async.map deposit_logs, (deposit_log, callback) ->
|
||||
deposit_log = deposit_log.toObject()
|
||||
|
||||
matched_hook = _.find pluggable.selectHooks('billing.payment_methods'), (hook) ->
|
||||
matched_hook = _.find pluggable.applyHooks('billing.payment_methods'), (hook) ->
|
||||
return hook.type == deposit_log.payload.type
|
||||
|
||||
unless matched_hook
|
||||
@@ -55,24 +55,23 @@ exports.get '/financials', (req, res) ->
|
||||
, (err, result) ->
|
||||
res.render 'panel/financials', result
|
||||
|
||||
exports.get '/components', (req, res) ->
|
||||
templates = _.map req.account.getAvailableComponentsTemplates(), (template_name) ->
|
||||
return pluggable.components[template_name]
|
||||
|
||||
res.render 'panel/components',
|
||||
templates: templates
|
||||
|
||||
exports.get '/', (req, res) ->
|
||||
billing.triggerBilling req.account, (err, account) ->
|
||||
return res.error err if err
|
||||
|
||||
view_data =
|
||||
account: account
|
||||
plans: []
|
||||
widgets_html: []
|
||||
async.parallel
|
||||
widgets_html: (callback) ->
|
||||
pluggable.applyHooks('view.panel.widgets', account, execute: 'generator') callback
|
||||
|
||||
for name, info of billing.plans
|
||||
view_data.plans.push _.extend _.clone(info),
|
||||
is_enabled: account.inPlan name
|
||||
|
||||
async.map pluggable.selectHooks('view.panel.widgets'), (hook, callback) ->
|
||||
hook.generator req, (html) ->
|
||||
callback null, html
|
||||
|
||||
, (err, widgets_html) ->
|
||||
view_data.widgets_html = widgets_html
|
||||
|
||||
res.render 'panel', view_data
|
||||
, (err, result) ->
|
||||
res.render 'panel', _.extend result,
|
||||
account: account
|
||||
plans: _.filter billing.plans, (plan) ->
|
||||
return plan.join_freely
|
||||
|
||||
33
core/static/script/components.coffee
Normal file
33
core/static/script/components.coffee
Normal file
@@ -0,0 +1,33 @@
|
||||
$ ->
|
||||
Component = Backbone.Model.extend
|
||||
idAttribute: '_id'
|
||||
|
||||
CompontentCollection = Backbone.Collection.extend
|
||||
model: Component
|
||||
url: '/component/resource/'
|
||||
|
||||
ListItemView = Backbone.View.extend
|
||||
tagName: 'tr'
|
||||
|
||||
initialize: ->
|
||||
@template = RP.tmpl '#list-item-template'
|
||||
|
||||
render: ->
|
||||
@$el.html @template @model.toJSON()
|
||||
return @
|
||||
|
||||
ListView = Backbone.View.extend
|
||||
el: '#list-view'
|
||||
|
||||
components: new CompontentCollection()
|
||||
|
||||
initialize: ->
|
||||
@components.on 'reset', =>
|
||||
@components.each (component) =>
|
||||
view = new ListItemView
|
||||
model: component
|
||||
@$('.table-component tbody').append view.render().el
|
||||
|
||||
@components.fetch reset: true
|
||||
|
||||
new ListView()
|
||||
@@ -15,6 +15,8 @@ block main
|
||||
a(href='#tab-account-list', data-toggle='tab')= t('view.admin.account_list')
|
||||
li
|
||||
a(href='#tab-coupon-code', data-toggle='tab')= t('view.admin.coupon_code')
|
||||
li
|
||||
a(href='#tab-compontents', data-toggle='tab') 元件
|
||||
li
|
||||
a(href='#tab-system-log', data-toggle='tab') 系统日志
|
||||
|
||||
@@ -51,6 +53,15 @@ block main
|
||||
td= account.balance.toFixed(2)
|
||||
td
|
||||
button.btn.btn-info.btn-sm.action-details(type='button')= t('common.details')
|
||||
.btn-group
|
||||
button(type='button', data-toggle='dropdown').btn.btn-warning.btn-sm.dropdown-toggle
|
||||
| 计划
|
||||
span.caret
|
||||
ul.dropdown-menu
|
||||
li
|
||||
a(href='#') 加入套餐 A
|
||||
li
|
||||
a(href='#') 离开套餐 B
|
||||
.btn-group
|
||||
button(type='button', data-toggle='dropdown').btn.btn-primary.btn-sm.dropdown-toggle
|
||||
| #{t('common.actions')}
|
||||
@@ -58,7 +69,7 @@ block main
|
||||
ul.dropdown-menu
|
||||
li
|
||||
a.action-confirm-payment(href='#')= t('view.admin.confirm_payment')
|
||||
if account.balance <= 0 && account.plans.length == 0
|
||||
if account.balance <= 0 && !_.isEmpty(account.plans)
|
||||
li
|
||||
a.action-delete-account(href='#')= t('view.admin.delete_account')
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ html
|
||||
block header
|
||||
link(rel='stylesheet', href='/bower_components/bootstrap/dist/css/bootstrap.min.css')
|
||||
link(rel='stylesheet', href='/style/layout.css')
|
||||
for hook in selectHooks('view.layout.styles')
|
||||
for hook in applyHooks('view.layout.styles')
|
||||
link(rel='stylesheet', href=hook.path)
|
||||
|
||||
body(data-username="#{account ? account.username : ''}", data-locale-version=app.i18n.localeHash(req), data-csrf-token=req.session.csrf_token)
|
||||
@@ -21,7 +21,7 @@ html
|
||||
a.navbar-brand(href='/')= t(config.web.t_name)
|
||||
#navbar-collapse.collapse.navbar-collapse
|
||||
ul.nav.navbar-nav
|
||||
for hook in selectHooks('view.layout.menu_bar')
|
||||
for hook in applyHooks('view.layout.menu_bar')
|
||||
li
|
||||
a(href=hook.href, target=hook.target)= hook.plugin.getTranslator(req)(hook.t_body)
|
||||
ul.nav.navbar-nav.navbar-right
|
||||
@@ -79,11 +79,12 @@ html
|
||||
ga('create', '#{config.web.google_analytics_id}', 'auto');
|
||||
ga('send', 'pageview');
|
||||
script(src='/bower_components/jquery/dist/jquery.min.js')
|
||||
script(src='/bower_components/jquery-tmpl/jquery.tmpl.min.js')
|
||||
script(src='/bower_components/jquery-cookie/jquery.cookie.js')
|
||||
script(src='/bower_components/underscore/underscore-min.js')
|
||||
script(src='/bower_components/backbone/backbone.js')
|
||||
script(src='/bower_components/bootstrap/dist/js/bootstrap.min.js')
|
||||
script(src='/script/layout.js')
|
||||
for hook in selectHooks('view.layout.scripts')
|
||||
for hook in applyHooks('view.layout.scripts')
|
||||
script(src=hook.path)
|
||||
block footer
|
||||
|
||||
@@ -5,7 +5,7 @@ prepend header
|
||||
|
||||
append header
|
||||
link(rel='stylesheet', href='/style/panel.css')
|
||||
for hook in selectHooks('view.panel.styles')
|
||||
for hook in applyHooks('view.panel.styles')
|
||||
link(rel='stylesheet', href=hook.path)
|
||||
|
||||
block main
|
||||
@@ -25,7 +25,7 @@ block main
|
||||
strong= t(plan.t_name)
|
||||
td= t(plan.t_description)
|
||||
td
|
||||
if plan.is_enabled
|
||||
if account.inPlan(plan.name)
|
||||
button.action-leave-plan.btn.btn-danger.btn-sm= t('plan.leave')
|
||||
else
|
||||
button.action-join-plan.btn.btn-success.btn-sm= t('plan.join')
|
||||
@@ -35,6 +35,8 @@ block main
|
||||
|
||||
prepend sidebar
|
||||
.row
|
||||
p
|
||||
a.btn.btn-lg.btn-success(href='/panel/components') 元件详情
|
||||
p
|
||||
a.btn.btn-lg.btn-success(href='/ticket/list/')= t('ticket.')
|
||||
p
|
||||
@@ -42,5 +44,5 @@ prepend sidebar
|
||||
|
||||
append footer
|
||||
script(src='/script/panel.js')
|
||||
for hook in selectHooks('view.panel.scripts')
|
||||
for hook in applyHooks('view.panel.scripts')
|
||||
script(src=hook.path)
|
||||
|
||||
40
core/view/panel/components.jade
Normal file
40
core/view/panel/components.jade
Normal file
@@ -0,0 +1,40 @@
|
||||
extends ../layout
|
||||
|
||||
prepend header
|
||||
title 元件 | #{t(config.web.t_name)}
|
||||
|
||||
block main
|
||||
#list-view
|
||||
header 可用模板
|
||||
|
||||
table.table-template.table.table-hover
|
||||
thead
|
||||
tr
|
||||
th 模板
|
||||
th 限制
|
||||
th 操作
|
||||
tbody
|
||||
for template in templates
|
||||
tr
|
||||
td= template.name
|
||||
td
|
||||
td
|
||||
|
||||
header 拥有元件
|
||||
|
||||
table.table-component.table.table-hover
|
||||
thead
|
||||
tr
|
||||
th 元件模板
|
||||
th 名称
|
||||
th 节点
|
||||
th 状态
|
||||
tbody
|
||||
|
||||
append footer
|
||||
script(src='/script/components.js')
|
||||
script(id='list-item-template', type='text/x-jquery-tmpl')
|
||||
td ${template}
|
||||
td ${name}
|
||||
td ${node_name}
|
||||
td ${status}
|
||||
@@ -5,35 +5,35 @@
|
||||
monitor = require './monitor'
|
||||
|
||||
exports.createUser = (component, callback) ->
|
||||
{account, node_name} = component
|
||||
{account, node} = component
|
||||
|
||||
async.series [
|
||||
(callback) ->
|
||||
node_name.runCommand "sudo useradd -m -s /bin/bash #{account.username}", (err) ->
|
||||
node.runCommand "sudo useradd -m -s /bin/bash #{account.username}", (err) ->
|
||||
logger.warn err if err
|
||||
callback()
|
||||
|
||||
(callback) ->
|
||||
node_name.runCommand "sudo usermod -G #{account.username} -a www-data", callback
|
||||
node.runCommand "sudo usermod -G #{account.username} -a www-data", callback
|
||||
|
||||
], callback
|
||||
|
||||
exports.deleteUser = (component, callback) ->
|
||||
{account, node_name} = component
|
||||
{account, node} = component
|
||||
|
||||
async.series [
|
||||
(callback) ->
|
||||
node_name.runCommand "sudo pkill -u #{account.username}", (err) ->
|
||||
node.runCommand "sudo pkill -u #{account.username}", (err) ->
|
||||
logger.warn err if err
|
||||
callback()
|
||||
|
||||
(callback) ->
|
||||
node_name.runCommand "sudo userdel -rf #{account.username}", (err) ->
|
||||
node.runCommand "sudo userdel -rf #{account.username}", (err) ->
|
||||
logger.warn err if err
|
||||
callback()
|
||||
|
||||
(callback) ->
|
||||
node_name.runCommand "sudo groupdel #{account.username}", (err) ->
|
||||
node.runCommand "sudo groupdel #{account.username}", (err) ->
|
||||
logger.warn err if err
|
||||
callback()
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ module.exports = exports = express.Router()
|
||||
exports.get '/', (req, res) ->
|
||||
pages_by_category = {}
|
||||
|
||||
for page in pluggable.selectHooks 'plugins.wiki.pages'
|
||||
for page in pluggable.applyHooks 'plugins.wiki.pages'
|
||||
pages_by_category[page.category] ?= []
|
||||
pages_by_category[page.category].push page
|
||||
|
||||
@@ -27,7 +27,7 @@ exports.get '/', (req, res) ->
|
||||
res.send html
|
||||
|
||||
exports.get '/:category/:name', (req, res) ->
|
||||
page = _.findWhere pluggable.selectHooks('plugins.wiki.pages'),
|
||||
page = _.findWhere pluggable.applyHooks('plugins.wiki.pages'),
|
||||
category: req.params.category
|
||||
name: req.params.name
|
||||
|
||||
|
||||
Reference in New Issue
Block a user