mirror of
				https://github.com/NginxProxyManager/nginx-proxy-manager.git
				synced 2025-10-31 15:53:33 +00:00 
			
		
		
		
	add basic functionality to front end
This commit is contained in:
		| @@ -3,28 +3,52 @@ | |||||||
|         <h5 class="modal-title"><%- i18n('access-lists', 'form-title', {id: id}) %></h5> |         <h5 class="modal-title"><%- i18n('access-lists', 'form-title', {id: id}) %></h5> | ||||||
|         <button type="button" class="close cancel" aria-label="Close" data-dismiss="modal"> </button> |         <button type="button" class="close cancel" aria-label="Close" data-dismiss="modal"> </button> | ||||||
|     </div> |     </div> | ||||||
|     <div class="modal-body"> |     <div class="modal-body has-tabs"> | ||||||
|         <form> |         <form> | ||||||
|             <div class="row"> |             <ul class="nav nav-tabs" role="tablist"> | ||||||
|                 <div class="col-sm-12 col-md-12"> |                 <li role="presentation" class="nav-item"><a href="#details" aria-controls="tab1" role="tab" data-toggle="tab" class="nav-link active show" aria-selected="true"><i class="fe fe-zap"></i> <%- i18n('access-lists', 'details') %></a></li> | ||||||
|                     <div class="form-group"> |                 <li role="presentation" class="nav-item"><a href="#auth" aria-controls="tab4" role="tab" data-toggle="tab" class="nav-link" aria-selected="false"><i class="fe fe-users"></i> <%- i18n('access-lists', 'authorization') %></a></li> | ||||||
|                         <label class="form-label"><%- i18n('str', 'name') %> <span class="form-required">*</span></label> |                 <li role="presentation" class="nav-item"><a href="#clients" aria-controls="tab2" role="tab" data-toggle="tab" class="nav-link" aria-selected="false"><i class="fe fe-radio"></i> <%- i18n('access-lists', 'clients') %></a></li> | ||||||
|                         <input type="text" name="name" class="form-control" value="<%- name %>" required> |             </ul> | ||||||
|                     </div> |  | ||||||
|                 </div> |  | ||||||
|                 <div class="col-sm-6 col-md-6"> |  | ||||||
|                     <div class="form-group"> |  | ||||||
|                         <label class="form-label"><%- i18n('str', 'username') %></label> |  | ||||||
|                     </div> |  | ||||||
|                 </div> |  | ||||||
|                 <div class="col-sm-6 col-md-6"> |  | ||||||
|                     <div class="form-group"> |  | ||||||
|                         <label class="form-label"><%- i18n('str', 'password') %></label> |  | ||||||
|                     </div> |  | ||||||
|                 </div> |  | ||||||
|             </div> |  | ||||||
|  |  | ||||||
|             <div class="items"><!-- items --></div> |             <div class="tab-content"> | ||||||
|  |                 <!-- Details --> | ||||||
|  |                 <div role="tabpanel" class="tab-pane active show" id="details"> | ||||||
|  |                     <div class="row"> | ||||||
|  |                         <div class="col-sm-12 col-md-12"> | ||||||
|  |                             <div class="form-group"> | ||||||
|  |                                 <label class="form-label"><%- i18n('str', 'name') %> <span class="form-required">*</span></label> | ||||||
|  |                                 <input type="text" name="name" class="form-control" value="<%- name %>" required> | ||||||
|  |                             </div> | ||||||
|  |                         </div> | ||||||
|  |                     </div> | ||||||
|  |                 </div> | ||||||
|  |  | ||||||
|  |                 <!-- Authorization --> | ||||||
|  |                 <div class="tab-pane" id="auth"> | ||||||
|  |                     <div class="row"> | ||||||
|  |                         <div class="col-sm-6 col-md-6"> | ||||||
|  |                             <div class="form-group"> | ||||||
|  |                                 <label class="form-label"><%- i18n('str', 'username') %></label> | ||||||
|  |                             </div> | ||||||
|  |                         </div> | ||||||
|  |                         <div class="col-sm-6 col-md-6"> | ||||||
|  |                             <div class="form-group"> | ||||||
|  |                                 <label class="form-label"><%- i18n('str', 'password') %></label> | ||||||
|  |                             </div> | ||||||
|  |                         </div> | ||||||
|  |                     </div> | ||||||
|  |          | ||||||
|  |                     <div class="items"><!-- items --></div> | ||||||
|  |                 </div> | ||||||
|  |  | ||||||
|  |                 <!-- Clients --> | ||||||
|  |                 <div class="tab-pane" id="clients"> | ||||||
|  |                     <div class="clients"><!-- clients --></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> | ||||||
|  |  | ||||||
|  |             </div> | ||||||
|         </form> |         </form> | ||||||
|     </div> |     </div> | ||||||
|     <div class="modal-footer"> |     <div class="modal-footer"> | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ const App             = require('../../main'); | |||||||
| const AccessListModel = require('../../../models/access-list'); | const AccessListModel = require('../../../models/access-list'); | ||||||
| const template        = require('./form.ejs'); | const template        = require('./form.ejs'); | ||||||
| const ItemView        = require('./form/item'); | const ItemView        = require('./form/item'); | ||||||
|  | const ClientView      = require('./form/client'); | ||||||
|  |  | ||||||
| require('jquery-serializejson'); | require('jquery-serializejson'); | ||||||
|  |  | ||||||
| @@ -10,20 +11,26 @@ const ItemsView = Mn.CollectionView.extend({ | |||||||
|     childView: ItemView |     childView: ItemView | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | const ClientsView = Mn.CollectionView.extend({ | ||||||
|  |     childView: ClientView | ||||||
|  | }); | ||||||
|  |  | ||||||
| module.exports = Mn.View.extend({ | module.exports = Mn.View.extend({ | ||||||
|     template:  template, |     template:  template, | ||||||
|     className: 'modal-dialog', |     className: 'modal-dialog', | ||||||
|  |  | ||||||
|     ui: { |     ui: { | ||||||
|         items_region: '.items', |         items_region:   '.items', | ||||||
|         form:         'form', |         clients_region: '.clients', | ||||||
|         buttons:      '.modal-footer button', |         form:           'form', | ||||||
|         cancel:       'button.cancel', |         buttons:        '.modal-footer button', | ||||||
|         save:         'button.save' |         cancel:         'button.cancel', | ||||||
|  |         save:           'button.save' | ||||||
|     }, |     }, | ||||||
|  |  | ||||||
|     regions: { |     regions: { | ||||||
|         items_region: '@ui.items_region' |         items_region:   '@ui.items_region', | ||||||
|  |         clients_region: '@ui.clients_region' | ||||||
|     }, |     }, | ||||||
|  |  | ||||||
|     events: { |     events: { | ||||||
| @@ -35,9 +42,10 @@ module.exports = Mn.View.extend({ | |||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             let view       = this; |             let view         = this; | ||||||
|             let form_data  = this.ui.form.serializeJSON(); |             let form_data    = this.ui.form.serializeJSON(); | ||||||
|             let items_data = []; |             let items_data   = []; | ||||||
|  |             let clients_data = []; | ||||||
|  |  | ||||||
|             form_data.username.map(function (val, idx) { |             form_data.username.map(function (val, idx) { | ||||||
|                 if (val.trim().length) { |                 if (val.trim().length) { | ||||||
| @@ -48,14 +56,24 @@ module.exports = Mn.View.extend({ | |||||||
|                 } |                 } | ||||||
|             }); |             }); | ||||||
|  |  | ||||||
|  |             form_data.address.map(function (val, idx) { | ||||||
|  |                 if (val.trim().length) { | ||||||
|  |                     clients_data.push({ | ||||||
|  |                         address: val.trim(), | ||||||
|  |                         directive: form_data.directive[idx] | ||||||
|  |                     }) | ||||||
|  |                 } | ||||||
|  |             }); | ||||||
|  |  | ||||||
|             if (!items_data.length) { |             if (!items_data.length) { | ||||||
|                 alert('You must specify at least 1 Username and Password combination'); |                 alert('You must specify at least 1 Username and Password combination'); | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             let data = { |             let data = { | ||||||
|                 name:  form_data.name, |                 name:    form_data.name, | ||||||
|                 items: items_data |                 items:   items_data, | ||||||
|  |                 clients: clients_data | ||||||
|             }; |             }; | ||||||
|  |  | ||||||
|             let method = App.Api.Nginx.AccessLists.create; |             let method = App.Api.Nginx.AccessLists.create; | ||||||
| @@ -88,6 +106,7 @@ module.exports = Mn.View.extend({ | |||||||
|  |  | ||||||
|     onRender: function () { |     onRender: function () { | ||||||
|         let items = this.model.get('items'); |         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 |         // 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; |         let items_to_add = 5 - items.length; | ||||||
| @@ -97,9 +116,20 @@ module.exports = Mn.View.extend({ | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         let clients_to_add = 5 - clients.length; | ||||||
|  |         if (clients_to_add) { | ||||||
|  |             for (let i = 0; i < clients_to_add; i++) { | ||||||
|  |                 clients.push({}); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|         this.showChildView('items_region', new ItemsView({ |         this.showChildView('items_region', new ItemsView({ | ||||||
|             collection: new Backbone.Collection(items) |             collection: new Backbone.Collection(items) | ||||||
|         })); |         })); | ||||||
|  |  | ||||||
|  |         this.showChildView('clients_region', new ClientsView({ | ||||||
|  |             collection: new Backbone.Collection(clients) | ||||||
|  |         })); | ||||||
|     }, |     }, | ||||||
|  |  | ||||||
|     initialize: function (options) { |     initialize: function (options) { | ||||||
|   | |||||||
							
								
								
									
										13
									
								
								frontend/js/app/nginx/access/form/client.ejs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								frontend/js/app/nginx/access/form/client.ejs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | |||||||
|  | <div class="col-sm-3 col-md-3"> | ||||||
|  |     <div class="form-group"> | ||||||
|  |         <select name="directive[]" class="form-control custom-select" placeholder="http"> | ||||||
|  |             <option value="allow" <%- typeof directive == 'undefined' || directive === 'allow' ? 'selected' : '' %>>allow</option> | ||||||
|  |             <option value="deny" <%- typeof directive !== 'undefined' && directive === 'deny' ? 'selected' : '' %>>deny</option> | ||||||
|  |         </select> | ||||||
|  |     </div> | ||||||
|  | </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=""> | ||||||
|  |     </div> | ||||||
|  | </div> | ||||||
							
								
								
									
										7
									
								
								frontend/js/app/nginx/access/form/client.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								frontend/js/app/nginx/access/form/client.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | |||||||
|  | const Mn       = require('backbone.marionette'); | ||||||
|  | const template = require('./client.ejs'); | ||||||
|  |  | ||||||
|  | module.exports = Mn.View.extend({ | ||||||
|  |     template:  template, | ||||||
|  |     className: 'row' | ||||||
|  | }); | ||||||
| @@ -40,7 +40,7 @@ module.exports = Mn.View.extend({ | |||||||
|     onRender: function () { |     onRender: function () { | ||||||
|         let view = this; |         let view = this; | ||||||
|  |  | ||||||
|         App.Api.Nginx.AccessLists.getAll(['owner', 'items']) |         App.Api.Nginx.AccessLists.getAll(['owner', 'items', 'clients']) | ||||||
|             .then(response => { |             .then(response => { | ||||||
|                 if (!view.isDestroyed()) { |                 if (!view.isDestroyed()) { | ||||||
|                     if (response && response.length) { |                     if (response && response.length) { | ||||||
|   | |||||||
| @@ -187,7 +187,10 @@ | |||||||
|       "help-content": "Access Lists provide authentication for the Proxy Hosts via Basic HTTP Authentication.\nYou can configure multiple usernames and passwords for a single Access List and then apply that to a Proxy Host.\nThis is most useful for forwarded web services that do not have authentication mechanisms built in.", |       "help-content": "Access Lists provide authentication for the Proxy Hosts via Basic HTTP Authentication.\nYou can configure multiple usernames and passwords for a single Access List and then apply that to a Proxy Host.\nThis is most useful for forwarded web services that do not have authentication mechanisms built in.", | ||||||
|       "item-count": "{count} {count, select, 1{User} other{Users}}", |       "item-count": "{count} {count, select, 1{User} other{Users}}", | ||||||
|       "proxy-host-count": "{count} {count, select, 1{Proxy Host} other{Proxy Hosts}}", |       "proxy-host-count": "{count} {count, select, 1{Proxy Host} other{Proxy Hosts}}", | ||||||
|       "delete-has-hosts": "This Access List is associated with {count} Proxy Hosts. They will become publicly available upon deletion." |       "delete-has-hosts": "This Access List is associated with {count} Proxy Hosts. They will become publicly available upon deletion.", | ||||||
|  |       "details": "Details", | ||||||
|  |       "authorization": "Authorization", | ||||||
|  |       "clients": "Clients" | ||||||
|     }, |     }, | ||||||
|     "users": { |     "users": { | ||||||
|       "title": "Users", |       "title": "Users", | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ const model = Backbone.Model.extend({ | |||||||
|             modified_on:     null, |             modified_on:     null, | ||||||
|             name:            '', |             name:            '', | ||||||
|             items:           [], |             items:           [], | ||||||
|  |             clients:         [], | ||||||
|             // The following are expansions: |             // The following are expansions: | ||||||
|             owner:           null |             owner:           null | ||||||
|         }; |         }; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user