Skip to content

Improved Access List Form #975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions frontend/js/app/nginx/access/form.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@

<!-- Authorization -->
<div class="tab-pane" id="auth">
<p>
Basic Authorization via
<a target="_blank" href="https://nginx.org/en/docs/http/ngx_http_auth_basic_module.html">
Nginx HTTP Basic Authentication
</a>
</p>
<div class="row">
<div class="col-sm-6 col-md-6">
<div class="form-group">
Expand All @@ -60,10 +66,19 @@
</div>

<div class="items"><!-- items --></div>
<div class="btn-list justify-content-end">
<button type="button" class="btn btn-teal auth_add"><%- i18n('access-lists', 'auth-add') %></button>
</div>
</div>

<!-- Access -->
<div class="tab-pane" id="access">
<p>
IP Address Whitelist/Blacklist via
<a target="_blank" href="https://nginx.org/en/docs/http/ngx_http_access_module.html">
Nginx HTTP Access
</a>
</p>
<div class="clients"><!-- clients --></div>
<div class="row">
<div class="col-sm-3 col-md-3">
Expand All @@ -78,6 +93,9 @@
</div>
</div>
<div class="text-muted">Note that the <code>allow</code> and <code>deny</code> directives will be applied in the order they are defined.</div>
<div class="btn-list justify-content-end">
<button type="button" class="btn btn-teal access_add"><%- i18n('access-lists', 'access-add') %></button>
</div>
</div>

</div>
Expand Down
39 changes: 24 additions & 15 deletions frontend/js/app/nginx/access/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ module.exports = Mn.View.extend({
form: 'form',
buttons: '.modal-footer button',
cancel: 'button.cancel',
save: 'button.save'
save: 'button.save',
access_add: 'button.access_add',
auth_add: 'button.auth_add'
},

regions: {
Expand Down Expand Up @@ -105,27 +107,34 @@ module.exports = Mn.View.extend({
alert(err.message);
this.ui.buttons.prop('disabled', false).removeClass('btn-disabled');
});
},
'click @ui.access_add': function (e) {
e.preventDefault();

let clients = this.model.get('clients');
clients.push({});
this.showChildView('clients_region', new ClientsView({
collection: new Backbone.Collection(clients)
}));
},
'click @ui.auth_add': function (e) {
e.preventDefault();

let items = this.model.get('items');
items.push({});
this.showChildView('items_region', new ItemsView({
collection: new Backbone.Collection(items)
}));
}
},

onRender: function () {
let items = this.model.get('items');
let clients = this.model.get('clients');

// Add empty items to the end of the list. This is cheating but hey I don't have the time to do it right
let items_to_add = 5 - items.length;
if (items_to_add) {
for (let i = 0; i < items_to_add; i++) {
items.push({});
}
}

let clients_to_add = 4 - clients.length;
if (clients_to_add) {
for (let i = 0; i < clients_to_add; i++) {
clients.push({});
}
}
// Ensure at least one field is shown initally
if (!items.length) items.push({});
if (!clients.length) clients.push({});

this.showChildView('items_region', new ItemsView({
collection: new Backbone.Collection(items)
Expand Down
2 changes: 1 addition & 1 deletion frontend/js/app/nginx/access/form/client.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
</div>
<div class="col-sm-9 col-md-9">
<div class="form-group">
<input type="text" name="address[]" class="form-control" value="<%- typeof address !== 'undefined' ? address : '' %>" value="">
<input type="text" name="address[]" placeholder="IP / Subnet" class="form-control" value="<%- typeof address !== 'undefined' ? address : '' %>" value="">
</div>
</div>
4 changes: 3 additions & 1 deletion frontend/js/i18n/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@
"access": "Access",
"satisfy": "Satisfy",
"satisfy-any": "Satisfy Any",
"pass-auth": "Pass Auth to Host"
"pass-auth": "Pass Auth to Host",
"access-add": "Add",
"auth-add": "Add"
},
"users": {
"title": "Users",
Expand Down
5 changes: 5 additions & 0 deletions frontend/scss/tabler-extra.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ $pink: #f66d9b;
padding: 0;
}

/* For some reason this class doesn't have 'display: flex' when it should. https://preview.tabler.io/docs/buttons.html#list-of-buttons */
.btn-list {
display: flex;
}

/* Teal Outline Buttons */
.btn-outline-teal {
color: $teal;
Expand Down