mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-04-29 03:55:42 +08:00
将前端 JS 移到插件目录
This commit is contained in:
@@ -52,6 +52,7 @@ exports.get '/', requestAuthenticate, (req, res) ->
|
||||
account.attribute.remaining_time = Math.ceil(billing.calcRemainingTime(account) / 24)
|
||||
|
||||
switch_buttons = []
|
||||
panel_script = []
|
||||
|
||||
async.map account.attribute.services, (service_name, callback) ->
|
||||
service_plugin = plugin.get service_name
|
||||
@@ -59,6 +60,10 @@ exports.get '/', requestAuthenticate, (req, res) ->
|
||||
if service_plugin.switch
|
||||
switch_buttons.push service_name
|
||||
|
||||
if service_plugin.panel_script
|
||||
for item in service_plugin.panel_script
|
||||
panel_script.push "/plugin/#{service_name}#{item}"
|
||||
|
||||
async.parallel
|
||||
widgets: (callback) ->
|
||||
async.map (service_plugin.panel_widgets ? []), (widgetBuilder, callback) ->
|
||||
@@ -87,6 +92,7 @@ exports.get '/', requestAuthenticate, (req, res) ->
|
||||
|
||||
res.render 'panel',
|
||||
switch_buttons: switch_buttons
|
||||
panel_script: panel_script
|
||||
plugin: plugin
|
||||
account: account
|
||||
plans: plans
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
$ ->
|
||||
window.ErrorHandle =
|
||||
addInfo: (type, info) ->
|
||||
$("#page-#{type}").append "<p>#{info}</p>"
|
||||
|
||||
clearInfo: (type) ->
|
||||
$("#page-#{type}").empty()
|
||||
|
||||
showInfo: (type, callback) ->
|
||||
$("#page-#{type}").show 1000, if callback? then callback or null
|
||||
|
||||
|
||||
hideInfo: (type) ->
|
||||
$("#page-#{type}").hide()
|
||||
|
||||
flushInfo: (type, error, callback = null) ->
|
||||
@clearInfo type
|
||||
@addInfo type, error
|
||||
@showInfo type, callback
|
||||
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
$ ->
|
||||
|
||||
$(document).ajaxError (e, reply) ->
|
||||
if reply.status is 400
|
||||
error = reply.responseJSON.error
|
||||
ErrorHandle.flushInfo 'alert', error
|
||||
$.ajaxSetup {
|
||||
contentType: 'application/json; charset=UTF-8'
|
||||
}
|
||||
|
||||
$('nav a').each ->
|
||||
$(this).parent().addClass('active') if $(this).attr('href') is location.pathname
|
||||
|
||||
if $(@).attr('href') == location.pathname
|
||||
$(@).parent().addClass('active')
|
||||
|
||||
$('#logout').on 'click', (e) ->
|
||||
e.preventDefault()
|
||||
$.post '/account/logout/', {}
|
||||
.success ->
|
||||
location.href = '/'
|
||||
location.href = '/'
|
||||
|
||||
@@ -31,138 +31,6 @@ $ ->
|
||||
.success ->
|
||||
location.reload()
|
||||
|
||||
$('#nginx-type-json textarea').on 'change keyup paste', ->
|
||||
try
|
||||
JSON.parse($('#nginx-type-json textarea').val())
|
||||
$('.json-error').parent().addClass 'hide'
|
||||
catch err
|
||||
console.log err
|
||||
$('.json-error').text err.toString()
|
||||
$('.json-error').parent().removeClass 'hide'
|
||||
|
||||
syncToJSON = ->
|
||||
username = $('.nav.navbar-nav.navbar-right li:first a').text()
|
||||
|
||||
try
|
||||
config = JSON.parse($('#nginx-type-json textarea').val())
|
||||
catch e
|
||||
config = {}
|
||||
|
||||
config['is_enable'] = $('.option-is-enable input').prop('checked')
|
||||
config['server_name'] = $('.option-server-name input').val().split ' '
|
||||
|
||||
switch $('.option-type :radio:checked').val()
|
||||
when 'fastcgi'
|
||||
config['root'] = $('.option-root input').val() or $('.option-root input').prop('placeholder')
|
||||
config['location'] ?= {}
|
||||
config['location']['/'] =
|
||||
try_files: ['$uri', '$uri/', '/index.php?$args']
|
||||
config['location']['~ \\.php$'] =
|
||||
fastcgi_pass: "unix:///home/#{username}/phpfpm.sock"
|
||||
include: 'fastcgi_params'
|
||||
|
||||
when 'proxy'
|
||||
config['location'] ?= {}
|
||||
config['location']['/'] =
|
||||
proxy_pass: $('.option-proxy input').val() or $('.option-proxy input').prop('placeholder')
|
||||
proxy_set_header:
|
||||
Host: '$host'
|
||||
|
||||
when 'uwsgi'
|
||||
config['location'] ?= {}
|
||||
config['location']['/'] =
|
||||
uwsgi_pass: $('.option-uwsgi input').val() or $('.option-uwsgi input').prop('placeholder')
|
||||
include: 'uwsgi_params'
|
||||
|
||||
when 'static'
|
||||
config['root'] = $('.option-root input').val() or $('.option-root input').prop('placeholder')
|
||||
|
||||
json = $('#nginx-type-json textarea').val JSON.stringify(config, null, ' ')
|
||||
return json
|
||||
|
||||
$('#nginx-modal ul li a').click ->
|
||||
switch $(@).prop('href').match(/.*#nginx-type-(.*)/)[1]
|
||||
when 'json'
|
||||
syncToJSON()
|
||||
when 'guide'
|
||||
$('.json-error').parent().addClass 'hide'
|
||||
|
||||
try
|
||||
config = JSON.parse($('#nginx-type-json textarea').val())
|
||||
catch e
|
||||
return
|
||||
|
||||
$('.option-is-enable input').prop 'checked', config['is_enable']
|
||||
$('.option-server-name input').val config['server_name']?.join ' '
|
||||
$('.option-root input').val config['root']
|
||||
|
||||
type = do ->
|
||||
unless config['location']['/']
|
||||
return 'static'
|
||||
|
||||
if config['location']['/']['proxy_pass']
|
||||
return 'proxy'
|
||||
|
||||
if config['location']['/']['uwsgi_pass']
|
||||
return 'uwsgi'
|
||||
|
||||
if config['location']['/']?['try_files']
|
||||
for item in config['location']['/']['try_files']
|
||||
if item.match(/\.php/)
|
||||
return 'factcgi'
|
||||
|
||||
return 'static'
|
||||
|
||||
$("#nginx-modal :radio[value=#{type}]").click()
|
||||
|
||||
switch type
|
||||
when 'proxy'
|
||||
$('.option-proxy input').val config['location']['/']['proxy_pass']
|
||||
when 'uwsgi'
|
||||
$('.option-uwsgi input').val config['location']['/']['uwsgi_pass']
|
||||
when 'static', 'fastcgi'
|
||||
$('.option-root input').val config['root']
|
||||
|
||||
$('#nginx-modal .radio input').click ->
|
||||
options = ['root', 'proxy', 'uwsgi']
|
||||
|
||||
mapping_table =
|
||||
fastcgi: ['root']
|
||||
proxy: ['proxy']
|
||||
uwsgi: ['uwsgi']
|
||||
static: ['root']
|
||||
|
||||
options_to_show = mapping_table[$(@).val()]
|
||||
|
||||
for item in options
|
||||
if item in options_to_show
|
||||
$("#nginx-modal .option-#{item}").removeClass 'hide'
|
||||
else
|
||||
$("#nginx-modal .option-#{item}").addClass 'hide'
|
||||
|
||||
$('#nginx-modal .modal-footer button.btn-success').click ->
|
||||
type = $('#nginx-modal ul.config-type').find('.active a').prop('href')['#nginx-type-'.length..]
|
||||
|
||||
if type == 'guide'
|
||||
config = syncToJSON()
|
||||
|
||||
else if type == 'json'
|
||||
try
|
||||
config = JSON.parse($('#nginx-type-json textarea').val())
|
||||
catch e
|
||||
return alert 'Invalid JSON'
|
||||
|
||||
else
|
||||
return alert 'Coming Soon'
|
||||
|
||||
$.post '/plugin/nginx/update_site/', JSON.stringify
|
||||
action: if config.id then 'update' else 'create'
|
||||
id: config.id
|
||||
type: type
|
||||
config: config
|
||||
.success ->
|
||||
location.reload()
|
||||
|
||||
# refactored above
|
||||
|
||||
service = $ '#service'
|
||||
|
||||
@@ -67,6 +67,5 @@ html
|
||||
ga('send', 'pageview');
|
||||
script(src='http://cdn.staticfile.org/jquery/2.0.3/jquery.min.js')
|
||||
script(src='http://cdn.staticfile.org/twitter-bootstrap/3.2.0/js/bootstrap.min.js')
|
||||
script(src='/script/base/ErrorHandle.js')
|
||||
script(src='/script/layout.js')
|
||||
block footer
|
||||
|
||||
@@ -63,3 +63,5 @@ block content
|
||||
|
||||
append footer
|
||||
script(src='/script/panel.js')
|
||||
for path in panel_script
|
||||
script(src= path)
|
||||
|
||||
Reference in New Issue
Block a user