Skip to content

Commit 52fcc90

Browse files
committed
Functional redirection hosts
1 parent c20a462 commit 52fcc90

File tree

7 files changed

+55
-78
lines changed

7 files changed

+55
-78
lines changed
Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
11
<td class="text-center">
2-
<div class="avatar d-block" style="background-image: url(<%- avatar || '/images/default-avatar.jpg' %>)">
3-
<span class="avatar-status <%- is_disabled ? 'bg-red' : 'bg-green' %>"></span>
2+
<div class="avatar d-block" style="background-image: url(<%- owner.avatar || '/images/default-avatar.jpg' %>)" title="Owned by <%- owner.name %>">
3+
<span class="avatar-status <%- owner.is_disabled ? 'bg-red' : 'bg-green' %>"></span>
44
</div>
55
</td>
66
<td>
7-
<div><%- name %></div>
7+
<div>
8+
<% domain_names.map(function(host) {
9+
%>
10+
<span class="tag"><%- host %></span>
11+
<%
12+
});
13+
%>
14+
</div>
815
<div class="small text-muted">
9-
Created: <%- formatDbDate(created_on, 'Do MMMM YYYY') %>
16+
<%- i18n('str', 'created-on', {date: formatDbDate(created_on, 'Do MMMM YYYY')}) %>
1017
</div>
1118
</td>
1219
<td>
13-
<div><%- email %></div>
20+
<div class="text-monospace"><%- forward_domain_name %></div>
1421
</td>
1522
<td>
16-
<div><%- roles.join(', ') %></div>
23+
<div><%- ssl_enabled && ssl_provider ? i18n('ssl', ssl_provider) : i18n('ssl', 'none') %></div>
1724
</td>
25+
<% if (canManage) { %>
1826
<td class="text-center">
1927
<div class="item-action dropdown">
2028
<a href="#" data-toggle="dropdown" class="icon"><i class="fe fe-more-vertical"></i></a>
2129
<div class="dropdown-menu dropdown-menu-right">
22-
<a href="#" class="edit-user dropdown-item"><i class="dropdown-icon fe fe-edit"></i> Edit Details</a>
23-
<a href="#" class="edit-permissions dropdown-item"><i class="dropdown-icon fe fe-shield"></i> Edit Permissions</a>
24-
<a href="#" class="set-password dropdown-item"><i class="dropdown-icon fe fe-lock"></i> Set Password</a>
25-
<% if (!isSelf()) { %>
26-
<a href="#" class="login dropdown-item"><i class="dropdown-icon fe fe-log-in"></i> Sign in as User</a>
30+
<a href="#" class="edit dropdown-item"><i class="dropdown-icon fe fe-edit"></i> <%- i18n('str', 'edit') %></a>
31+
<a href="#" class="logs dropdown-item"><i class="dropdown-icon fe fe-book"></i> <%- i18n('str', 'logs') %></a>
2732
<div class="dropdown-divider"></div>
28-
<a href="#" class="delete-user dropdown-item"><i class="dropdown-icon fe fe-trash-2"></i> Delete User</a>
29-
<% } %>
33+
<a href="#" class="delete dropdown-item"><i class="dropdown-icon fe fe-trash-2"></i> <%- i18n('str', 'delete') %></a>
3034
</div>
3135
</div>
3236
</td>
37+
<% } %>

src/frontend/js/app/nginx/redirection/list/item.js

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,32 @@
11
'use strict';
22

3-
const Mn = require('backbone.marionette');
4-
const Controller = require('../../../controller');
5-
const Api = require('../../../api');
6-
const Cache = require('../../../cache');
7-
const Tokens = require('../../../tokens');
8-
const template = require('./item.ejs');
3+
const Mn = require('backbone.marionette');
4+
const App = require('../../../main');
5+
const template = require('./item.ejs');
96

107
module.exports = Mn.View.extend({
118
template: template,
129
tagName: 'tr',
1310

1411
ui: {
15-
edit: 'a.edit-user',
16-
permissions: 'a.edit-permissions',
17-
password: 'a.set-password',
18-
login: 'a.login',
19-
delete: 'a.delete-user'
12+
edit: 'a.edit',
13+
delete: 'a.delete'
2014
},
2115

2216
events: {
2317
'click @ui.edit': function (e) {
2418
e.preventDefault();
25-
Controller.showUserForm(this.model);
26-
},
27-
28-
'click @ui.permissions': function (e) {
29-
e.preventDefault();
30-
Controller.showUserPermissions(this.model);
31-
},
32-
33-
'click @ui.password': function (e) {
34-
e.preventDefault();
35-
Controller.showUserPasswordForm(this.model);
19+
App.Controller.showNginxRedirectionForm(this.model);
3620
},
3721

3822
'click @ui.delete': function (e) {
3923
e.preventDefault();
40-
Controller.showUserDeleteConfirm(this.model);
41-
},
42-
43-
'click @ui.login': function (e) {
44-
e.preventDefault();
45-
46-
if (Cache.User.get('id') !== this.model.get('id')) {
47-
this.ui.login.prop('disabled', true).addClass('btn-disabled');
48-
49-
Api.Users.loginAs(this.model.get('id'))
50-
.then(res => {
51-
Tokens.addToken(res.token, res.user.nickname || res.user.name);
52-
window.___location = '/';
53-
window.___location.reload();
54-
})
55-
.catch(err => {
56-
alert(err.message);
57-
this.ui.login.prop('disabled', false).removeClass('btn-disabled');
58-
});
59-
}
24+
App.Controller.showNginxRedirectionDeleteConfirm(this.model);
6025
}
6126
},
6227

6328
templateContext: {
64-
isSelf: function () {
65-
return Cache.User.get('id') === this.id;
66-
}
29+
canManage: App.Cache.User.canManage('redirection_hosts')
6730
},
6831

6932
initialize: function () {
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<thead>
2-
<th width="30">&nbsp;</th>
3-
<th>Name</th>
4-
<th>Email</th>
5-
<th>Roles</th>
6-
<th>&nbsp;</th>
2+
<th width="30">&nbsp;</th>
3+
<th><%- i18n('str', 'source') %></th>
4+
<th><%- i18n('str', 'destination') %></th>
5+
<th><%- i18n('str', 'ssl') %></th>
6+
<% if (canManage) { %>
7+
<th>&nbsp;</th>
8+
<% } %>
79
</thead>
810
<tbody>
9-
<!-- items -->
11+
<!-- items -->
1012
</tbody>

src/frontend/js/app/nginx/redirection/list/main.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use strict';
22

3-
const Mn = require('backbone.marionette');
4-
const ItemView = require('./item');
5-
const template = require('./main.ejs');
3+
const Mn = require('backbone.marionette');
4+
const App = require('../../../main');
5+
const ItemView = require('./item');
6+
const template = require('./main.ejs');
67

78
const TableBody = Mn.CollectionView.extend({
89
tagName: 'tbody',
@@ -21,6 +22,10 @@ module.exports = Mn.View.extend({
2122
}
2223
},
2324

25+
templateContext: {
26+
canManage: App.Cache.User.canManage('redirection_hosts')
27+
},
28+
2429
onRender: function () {
2530
this.showChildView('body', new TableBody({
2631
collection: this.collection

src/frontend/js/app/nginx/redirection/main.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = Mn.View.extend({
2525
events: {
2626
'click @ui.add': function (e) {
2727
e.preventDefault();
28-
App.Controller.showNginxProxyForm();
28+
App.Controller.showNginxRedirectionForm();
2929
}
3030
},
3131

@@ -36,24 +36,24 @@ module.exports = Mn.View.extend({
3636
onRender: function () {
3737
let view = this;
3838

39-
App.Api.Nginx.ProxyHosts.getAll(['owner', 'access_list'])
39+
App.Api.Nginx.RedirectionHosts.getAll(['owner'])
4040
.then(response => {
4141
if (!view.isDestroyed()) {
4242
if (response && response.length) {
4343
view.showChildView('list_region', new ListView({
44-
collection: new ProxyHostModel.Collection(response)
44+
collection: new RedirectionHostModel.Collection(response)
4545
}));
4646
} else {
47-
let manage = App.Cache.User.canManage('proxy_hosts');
47+
let manage = App.Cache.User.canManage('redirection_hosts');
4848

4949
view.showChildView('list_region', new EmptyView({
50-
title: App.i18n('proxy-hosts', 'empty'),
50+
title: App.i18n('redirection-hosts', 'empty'),
5151
subtitle: App.i18n('all-hosts', 'empty-subtitle', {manage: manage}),
52-
link: manage ? App.i18n('proxy-hosts', 'add') : null,
53-
btn_color: 'success',
54-
permission: 'proxy_hosts',
52+
link: manage ? App.i18n('redirection-hosts', 'add') : null,
53+
btn_color: 'yellow',
54+
permission: 'redirection_hosts',
5555
action: function () {
56-
App.Controller.showNginxProxyForm();
56+
App.Controller.showNginxRedirectionForm();
5757
}
5858
}));
5959
}
@@ -64,7 +64,7 @@ module.exports = Mn.View.extend({
6464
code: err.code,
6565
message: err.message,
6666
retry: function () {
67-
App.Controller.showNginxProxy();
67+
App.Controller.showNginxRedirection();
6868
}
6969
}));
7070

src/frontend/js/app/user/form.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ module.exports = Mn.View.extend({
6464
}
6565

6666
view.model.set(result);
67-
App.App.UI.closeModal(function () {
67+
App.UI.closeModal(function () {
6868
if (method === App.Api.Users.create) {
6969
// Show permissions dialog immediately
7070
App.Controller.showUserPermissions(view.model);

src/frontend/js/i18n/messages.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@
8585
},
8686
"redirection-hosts": {
8787
"title": "Redirection Hosts",
88+
"empty": "There are no Redirection Hosts",
89+
"add": "Add Redirection Host",
8890
"form-title": "{id, select, undefined{New} other{Edit}} Redirection Host",
8991
"forward-___domain": "Forward Domain",
9092
"preserve-path": "Preserve Path",

0 commit comments

Comments
 (0)