Skip to content

Commit 37cb63b

Browse files
committed
Frontend form and marionette modifications to allow static hosts and locations
1 parent 1c302c6 commit 37cb63b

File tree

8 files changed

+105
-19
lines changed

8 files changed

+105
-19
lines changed

frontend/js/app/nginx/proxy/form.ejs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</div>
3535
<div class="col-sm-3 col-md-3">
3636
<div class="form-group">
37-
<label class="form-label"><%- i18n('proxy-hosts', 'forward-scheme') %><span class="form-required">*</span></label>
37+
<label class="form-label"><%- i18n('proxy-hosts', 'forward-scheme') %></label>
3838
<select name="forward_scheme" class="form-control custom-select" placeholder="http">
3939
<option value="http" <%- forward_scheme === 'http' ? 'selected' : '' %>>http</option>
4040
<option value="https" <%- forward_scheme === 'https' ? 'selected' : '' %>>https</option>
@@ -43,14 +43,26 @@
4343
</div>
4444
<div class="col-sm-5 col-md-5">
4545
<div class="form-group">
46-
<label class="form-label"><%- i18n('proxy-hosts', 'forward-host') %><span class="form-required">*</span></label>
47-
<input type="text" name="forward_host" class="form-control text-monospace" placeholder="" value="<%- forward_host %>" autocomplete="off" maxlength="255" required>
46+
<label class="form-label"><%- i18n('proxy-hosts', 'forward-host') %><% if (!static) { %> <span class="form-required">*</span><% } %></label>
47+
<input type="text" name="forward_host" class="form-control text-monospace" placeholder="" value="<%- forward_host %>" <%- !static ? 'required' : '' %> autocomplete="off" maxlength="255">
4848
</div>
4949
</div>
5050
<div class="col-sm-4 col-md-4">
5151
<div class="form-group">
52-
<label class="form-label"><%- i18n('proxy-hosts', 'forward-port') %> <span class="form-required">*</span></label>
53-
<input name="forward_port" type="number" class="form-control text-monospace" placeholder="80" value="<%- forward_port %>" required>
52+
<label class="form-label"><%- i18n('proxy-hosts', 'forward-port') %><% if (!static) { %> <span class="form-required">*</span><% } %> </label>
53+
<input name="forward_port" type="number" class="form-control text-monospace" placeholder="80" value="<%- forward_port %>" <%- !static ? 'required' : '' %>>
54+
</div>
55+
</div>
56+
<div class="col-sm-5 col-md-5">
57+
<div class="form-group">
58+
<label class="form-label"><%- i18n('proxy-hosts', 'root-dir') %><% if (static) { %> <span class="form-required">*</span><% } %></label>
59+
<input type="text" name="root_dir" class="form-control text-monospace" placeholder="" value="<%- root_dir %>" <%- static ? 'required' : '' %> autocomplete="off" maxlength="255">
60+
</div>
61+
</div>
62+
<div class="col-sm-5 col-md-5">
63+
<div class="form-group">
64+
<label class="form-label"><%- i18n('proxy-hosts', 'index-file') %><% if (static) { %> <span class="form-required">*</span><% } %></label>
65+
<input type="text" name="index_file" class="form-control text-monospace" placeholder="" value="<%- index_file %>" <%- static ? 'required' : '' %> autocomplete="off" maxlength="255">
5466
</div>
5567
</div>
5668
<div class="col-sm-6 col-md-6">
@@ -80,6 +92,15 @@
8092
</label>
8193
</div>
8294
</div>
95+
<div class="col-sm-12 col-md-12">
96+
<div class="form-group">
97+
<label class="custom-switch">
98+
<input type="checkbox" class="custom-switch-input static-checkbox" name="static" value="1"<%- static ? ' checked' : '' %>>
99+
<span class="custom-switch-indicator"></span>
100+
<span class="custom-switch-description"><%- i18n('proxy-hosts', 'static') %></span>
101+
</label>
102+
</div>
103+
</div>
83104

84105
<div class="col-sm-12 col-md-12">
85106
<div class="form-group">

frontend/js/app/nginx/proxy/form.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ module.exports = Mn.View.extend({
2222
form: 'form',
2323
domain_names: 'input[name="domain_names"]',
2424
forward_host: 'input[name="forward_host"]',
25+
root_dir: 'input[name="root_dir"]',
26+
index_file: 'input[name="index_file"]',
27+
static: 'input[type="checkbox"].static-checkbox',
2528
buttons: '.modal-footer button',
2629
cancel: 'button.cancel',
2730
save: 'button.save',
@@ -42,6 +45,20 @@ module.exports = Mn.View.extend({
4245
},
4346

4447
events: {
48+
49+
'click @ui.static': function(e){
50+
51+
const map = {};
52+
53+
let value = e.target.value
54+
if(e.target.type == 'checkbox') value = e.target.checked
55+
map[e.target.name] = value
56+
this.model.set(map);
57+
58+
setTimeout(this.render.bind(this), 300)
59+
60+
},
61+
4562
'change @ui.certificate_select': function () {
4663
let id = this.ui.certificate_select.val();
4764
if (id === 'new') {
@@ -128,7 +145,8 @@ module.exports = Mn.View.extend({
128145
data.hsts_enabled = !!data.hsts_enabled;
129146
data.hsts_subdomains = !!data.hsts_subdomains;
130147
data.ssl_forced = !!data.ssl_forced;
131-
148+
data.static = !!data.static;
149+
132150
if (typeof data.domain_names === 'string' && data.domain_names) {
133151
data.domain_names = data.domain_names.split(',');
134152
}

frontend/js/app/nginx/proxy/list/item.ejs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@
2323
</div>
2424
</td>
2525
<td>
26-
<div class="text-monospace"><%- forward_scheme %>://<%- forward_host %>:<%- forward_port %></div>
26+
<!-- <div> <%- static %> </div> -->
27+
<% if (!static) { %>
28+
<div class="text-monospace"><%- forward_scheme %>://<%- forward_host %>:<%- forward_port %></div>
29+
<% } else { %>
30+
<div class="text-monospace"><%- root_dir %></div>
31+
<div class="text-monospace"><%- index_file %></div>
32+
<% } %>
2733
</td>
2834
<td>
2935
<div><%- certificate && certificate_id ? i18n('ssl', certificate.provider) : i18n('ssl', 'none') %></div>

frontend/js/app/nginx/proxy/___location-item.ejs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<div class="col-auto">
1717
<div class="selectgroup">
1818
<label class="selectgroup-item">
19-
<input type="checkbox" class="selectgroup-input">
19+
<input type="checkbox" class="selectgroup-input settings-checkbox">
2020
<span class="selectgroup-button">
2121
<i class="fe fe-settings"></i>
2222
</span>
@@ -28,7 +28,7 @@
2828
</div>
2929
<div class="col-sm-3 col-md-3">
3030
<div class="form-group">
31-
<label class="form-label"><%- i18n('proxy-hosts', 'forward-scheme') %><span class="form-required">*</span></label>
31+
<label class="form-label"><%- i18n('proxy-hosts', 'forward-scheme') %></label>
3232
<select name="forward_scheme" class="form-control custom-select model" placeholder="http">
3333
<option value="http" <%- forward_scheme === 'http' ? 'selected' : '' %>>http</option>
3434
<option value="https" <%- forward_scheme === 'https' ? 'selected' : '' %>>https</option>
@@ -37,17 +37,38 @@
3737
</div>
3838
<div class="col-sm-5 col-md-5">
3939
<div class="form-group">
40-
<label class="form-label"><%- i18n('proxy-hosts', 'forward-host') %><span class="form-required">*</span></label>
41-
<input type="text" name="forward_host" class="form-control text-monospace model" placeholder="" value="<%- forward_host %>" autocomplete="off" maxlength="200" required>
40+
<label class="form-label"><%- i18n('proxy-hosts', 'forward-host') %> <% if (!static) { %> <span class="form-required">*</span> <% } %> </label>
41+
<input type="text" name="forward_host" class="form-control text-monospace model" placeholder="" value="<%- forward_host %>" <%- !static ? 'checked' : '' %> autocomplete="off" maxlength="200">
4242
<span style="font-size: 9px;"><%- i18n('proxy-hosts', 'custom-forward-host-help') %></span>
4343
</div>
4444
</div>
4545
<div class="col-sm-4 col-md-4">
4646
<div class="form-group">
47-
<label class="form-label"><%- i18n('proxy-hosts', 'forward-port') %> <span class="form-required">*</span></label>
48-
<input name="forward_port" type="number" class="form-control text-monospace model" placeholder="80" value="<%- forward_port %>" required>
47+
<label class="form-label"><%- i18n('proxy-hosts', 'forward-port') %> <% if (!static) { %> <span class="form-required">*</span><% } %> </label>
48+
<input name="forward_port" type="number" class="form-control text-monospace model" placeholder="80" value="<%- forward_port %>" <%- !static ? 'checked' : '' %> >
4949
</div>
5050
</div>
51+
<div class="col-sm-5 col-md-5">
52+
<div class="form-group">
53+
<label class="form-label"><%- i18n('proxy-hosts', 'root-dir') %><% if (static) { %> <span class="form-required">*</span><% } %></label>
54+
<input type="text" name="root_dir" class="form-control text-monospace model" placeholder="" value="<%- root_dir %>" <%- static ? 'required' : '' %> autocomplete="off" maxlength="200">
55+
</div>
56+
</div>
57+
<div class="col-sm-5 col-md-5">
58+
<div class="form-group">
59+
<label class="form-label"><%- i18n('proxy-hosts', 'index-file') %><% if (static) { %> <span class="form-required">*</span><% } %></label>
60+
<input type="text" name="index_file" class="form-control text-monospace model" placeholder="" value="<%- index_file %>" <%- static ? 'required' : false %> autocomplete="off" maxlength="200">
61+
</div>
62+
</div>
63+
<div class="col-sm-12 col-md-12">
64+
<div class="form-group">
65+
<label class="custom-switch">
66+
<input type="checkbox" class="custom-switch-input ___location-static-checkbox model" name="static" value="1"<%- static ? ' checked' : '' %> >
67+
<span class="custom-switch-indicator"></span>
68+
<span class="custom-switch-description"><%- i18n('proxy-hosts', 'static') %></span>
69+
</label>
70+
</div>
71+
</div>
5172
</div>
5273
<div class="row config">
5374
<div class="col-md-12">

frontend/js/app/nginx/proxy/___location.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ const LocationView = Mn.View.extend({
77
className: 'location_block',
88

99
ui: {
10-
toggle: 'input[type="checkbox"]',
10+
settings: 'input[type="checkbox"].settings-checkbox',
11+
static: 'input[type="checkbox"].___location-static-checkbox',
1112
config: '.config',
1213
delete: '.___location-delete'
1314
},
1415

1516
events: {
16-
'change @ui.toggle': function(el) {
17+
18+
'change @ui.settings': function(el) {
1719
if (el.target.checked) {
1820
this.ui.config.show();
1921
} else {
@@ -22,11 +24,20 @@ const LocationView = Mn.View.extend({
2224
},
2325

2426
'change .model': function (e) {
27+
2528
const map = {};
26-
map[e.target.name] = e.target.value;
29+
30+
let value = e.target.value
31+
if(e.target.type == 'checkbox') value = e.target.checked ? 1 : 0
32+
map[e.target.name] = value
2733
this.model.set(map);
34+
35+
setTimeout(this.render.bind(this), 300)
36+
2837
},
2938

39+
// 'click @ui.static': 'render',
40+
3041
'click @ui.delete': function () {
3142
this.model.destroy();
3243
}

frontend/js/i18n/messages.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@
111111
"forward-scheme": "Scheme",
112112
"forward-host": "Forward Hostname / IP",
113113
"forward-port": "Forward Port",
114+
"root-dir": "Root Directory",
115+
"static": "Static File Proxy",
116+
"index-file": "Index File",
114117
"delete": "Delete Proxy Host",
115118
"delete-confirm": "Are you sure you want to delete the Proxy host for: <strong>{domains}</strong>?",
116119
"help-title": "What is a Proxy Host?",

frontend/js/models/proxy-host-___location.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ const model = Backbone.Model.extend({
99
path: '',
1010
advanced_config: '',
1111
forward_scheme: 'http',
12-
forward_host: '',
13-
forward_port: '80'
12+
forward_host: null,
13+
forward_port: '80',
14+
root_dir: null,
15+
static: false,
16+
index_file: 'index.html',
1417
}
1518
},
1619

frontend/js/models/proxy-host.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ const model = Backbone.Model.extend({
1010
modified_on: null,
1111
domain_names: [],
1212
forward_scheme: 'http',
13-
forward_host: '',
13+
forward_host: null,
1414
forward_port: null,
15+
root_dir: null,
16+
static: false,
17+
index_file: 'index.html',
1518
access_list_id: 0,
1619
certificate_id: 0,
1720
ssl_forced: false,

0 commit comments

Comments
 (0)