From 37cb63b2d4cd72a11ea5d7fa134172a92904ef84 Mon Sep 17 00:00:00 2001 From: Nikolaj Frey Date: Fri, 14 Aug 2020 15:01:09 +1000 Subject: [PATCH] Frontend form and marionette modifications to allow static hosts and locations --- frontend/js/app/nginx/proxy/form.ejs | 31 ++++++++++++++--- frontend/js/app/nginx/proxy/form.js | 20 ++++++++++- frontend/js/app/nginx/proxy/list/item.ejs | 8 ++++- frontend/js/app/nginx/proxy/location-item.ejs | 33 +++++++++++++++---- frontend/js/app/nginx/proxy/location.js | 17 ++++++++-- frontend/js/i18n/messages.json | 3 ++ frontend/js/models/proxy-host-location.js | 7 ++-- frontend/js/models/proxy-host.js | 5 ++- 8 files changed, 105 insertions(+), 19 deletions(-) diff --git a/frontend/js/app/nginx/proxy/form.ejs b/frontend/js/app/nginx/proxy/form.ejs index 0cc0d543..705e05d4 100644 --- a/frontend/js/app/nginx/proxy/form.ejs +++ b/frontend/js/app/nginx/proxy/form.ejs @@ -34,7 +34,7 @@
- + + + autocomplete="off" maxlength="255">
- - + + > +
+
+
+
+ + autocomplete="off" maxlength="255"> +
+
+
+
+ + autocomplete="off" maxlength="255">
@@ -80,6 +92,15 @@
+
+
+ +
+
diff --git a/frontend/js/app/nginx/proxy/form.js b/frontend/js/app/nginx/proxy/form.js index eb93bc8f..a19d203e 100644 --- a/frontend/js/app/nginx/proxy/form.js +++ b/frontend/js/app/nginx/proxy/form.js @@ -22,6 +22,9 @@ module.exports = Mn.View.extend({ form: 'form', domain_names: 'input[name="domain_names"]', forward_host: 'input[name="forward_host"]', + root_dir: 'input[name="root_dir"]', + index_file: 'input[name="index_file"]', + static: 'input[type="checkbox"].static-checkbox', buttons: '.modal-footer button', cancel: 'button.cancel', save: 'button.save', @@ -42,6 +45,20 @@ module.exports = Mn.View.extend({ }, events: { + + 'click @ui.static': function(e){ + + const map = {}; + + let value = e.target.value + if(e.target.type == 'checkbox') value = e.target.checked + map[e.target.name] = value + this.model.set(map); + + setTimeout(this.render.bind(this), 300) + + }, + 'change @ui.certificate_select': function () { let id = this.ui.certificate_select.val(); if (id === 'new') { @@ -128,7 +145,8 @@ module.exports = Mn.View.extend({ data.hsts_enabled = !!data.hsts_enabled; data.hsts_subdomains = !!data.hsts_subdomains; data.ssl_forced = !!data.ssl_forced; - + data.static = !!data.static; + if (typeof data.domain_names === 'string' && data.domain_names) { data.domain_names = data.domain_names.split(','); } diff --git a/frontend/js/app/nginx/proxy/list/item.ejs b/frontend/js/app/nginx/proxy/list/item.ejs index d90ace4c..88aa265e 100644 --- a/frontend/js/app/nginx/proxy/list/item.ejs +++ b/frontend/js/app/nginx/proxy/list/item.ejs @@ -23,7 +23,13 @@
-
<%- forward_scheme %>://<%- forward_host %>:<%- forward_port %>
+ + <% if (!static) { %> +
<%- forward_scheme %>://<%- forward_host %>:<%- forward_port %>
+ <% } else { %> +
<%- root_dir %>
+
<%- index_file %>
+ <% } %>
<%- certificate && certificate_id ? i18n('ssl', certificate.provider) : i18n('ssl', 'none') %>
diff --git a/frontend/js/app/nginx/proxy/location-item.ejs b/frontend/js/app/nginx/proxy/location-item.ejs index 39445f7b..4673a0f0 100644 --- a/frontend/js/app/nginx/proxy/location-item.ejs +++ b/frontend/js/app/nginx/proxy/location-item.ejs @@ -16,7 +16,7 @@
- + + + autocomplete="off" maxlength="200"> <%- i18n('proxy-hosts', 'custom-forward-host-help') %>
- - + + >
+
+
+ + autocomplete="off" maxlength="200"> +
+
+
+
+ + autocomplete="off" maxlength="200"> +
+
+
+
+ +
+
diff --git a/frontend/js/app/nginx/proxy/location.js b/frontend/js/app/nginx/proxy/location.js index e9513a48..b12b621a 100644 --- a/frontend/js/app/nginx/proxy/location.js +++ b/frontend/js/app/nginx/proxy/location.js @@ -7,13 +7,15 @@ const LocationView = Mn.View.extend({ className: 'location_block', ui: { - toggle: 'input[type="checkbox"]', + settings: 'input[type="checkbox"].settings-checkbox', + static: 'input[type="checkbox"].location-static-checkbox', config: '.config', delete: '.location-delete' }, events: { - 'change @ui.toggle': function(el) { + + 'change @ui.settings': function(el) { if (el.target.checked) { this.ui.config.show(); } else { @@ -22,11 +24,20 @@ const LocationView = Mn.View.extend({ }, 'change .model': function (e) { + const map = {}; - map[e.target.name] = e.target.value; + + let value = e.target.value + if(e.target.type == 'checkbox') value = e.target.checked ? 1 : 0 + map[e.target.name] = value this.model.set(map); + + setTimeout(this.render.bind(this), 300) + }, + // 'click @ui.static': 'render', + 'click @ui.delete': function () { this.model.destroy(); } diff --git a/frontend/js/i18n/messages.json b/frontend/js/i18n/messages.json index 7b5205ab..7ff477d5 100644 --- a/frontend/js/i18n/messages.json +++ b/frontend/js/i18n/messages.json @@ -111,6 +111,9 @@ "forward-scheme": "Scheme", "forward-host": "Forward Hostname / IP", "forward-port": "Forward Port", + "root-dir": "Root Directory", + "static": "Static File Proxy", + "index-file": "Index File", "delete": "Delete Proxy Host", "delete-confirm": "Are you sure you want to delete the Proxy host for: {domains}?", "help-title": "What is a Proxy Host?", diff --git a/frontend/js/models/proxy-host-location.js b/frontend/js/models/proxy-host-location.js index 2a35059f..9ce641d2 100644 --- a/frontend/js/models/proxy-host-location.js +++ b/frontend/js/models/proxy-host-location.js @@ -9,8 +9,11 @@ const model = Backbone.Model.extend({ path: '', advanced_config: '', forward_scheme: 'http', - forward_host: '', - forward_port: '80' + forward_host: null, + forward_port: '80', + root_dir: null, + static: false, + index_file: 'index.html', } }, diff --git a/frontend/js/models/proxy-host.js b/frontend/js/models/proxy-host.js index b82d09fe..fca51b2c 100644 --- a/frontend/js/models/proxy-host.js +++ b/frontend/js/models/proxy-host.js @@ -10,8 +10,11 @@ const model = Backbone.Model.extend({ modified_on: null, domain_names: [], forward_scheme: 'http', - forward_host: '', + forward_host: null, forward_port: null, + root_dir: null, + static: false, + index_file: 'index.html', access_list_id: 0, certificate_id: 0, ssl_forced: false,