Skip to content

Commit 9f994d3

Browse files
committed
Get dashboard with rudimentary info for activity. Make user create page - still non-functional but fields are there
1 parent 36c90ca commit 9f994d3

File tree

6 files changed

+177
-5
lines changed

6 files changed

+177
-5
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
const fs = require('fs-extra'),
2+
path = require('path'),
3+
partialPath = path.join(__dirname, '..', '..', '..','views','pages','partials','create');
4+
module.exports = {
5+
friendlyName: 'View users create',
6+
description: 'Display "users create" page.',
7+
exits: {
8+
success: {
9+
viewTemplatePath: 'pages/create'
10+
}
11+
},
12+
fn: async function () {
13+
let req = this.req,
14+
res = this.res,
15+
data = {
16+
model: 'user',
17+
header: 'Create New User',
18+
formItems: {
19+
displayname: {
20+
textarea: false,
21+
text: 'Display Name',
22+
type: 'text',
23+
id: 'displayname',
24+
classes: ['displayname'],
25+
placeholder: 'Supercool Dude'
26+
},
27+
username: {
28+
textarea: false,
29+
text: 'Username',
30+
type: 'text',
31+
id: 'username',
32+
classes: ['username'],
33+
placeholder: 'sdude'
34+
},
35+
emailaddress: {
36+
textarea: false,
37+
text: 'Email Address',
38+
type: 'text',
39+
validations: {
40+
minLength: 5,
41+
regex: /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
42+
},
43+
id: 'emailaddress',
44+
classes: [],
45+
placeholder: 'some@email.org'
46+
},
47+
password: {
48+
textarea: false,
49+
text: 'Password',
50+
type: 'password',
51+
id: 'password',
52+
classes: [],
53+
validations: {
54+
minLength: 8,
55+
regex: /(?=.*){8,}/
56+
},
57+
placeholder: '********'
58+
},
59+
passwordconf: {
60+
textarea: false,
61+
text: 'Password (confirm)',
62+
type: 'password',
63+
id: 'passwordconf',
64+
classes: [],
65+
validations: {
66+
minLength: 8,
67+
regex: /(?=.*){8,}/
68+
},
69+
placeholder: '********'
70+
}
71+
},
72+
formButtons: {
73+
Cancel: {
74+
classes: ['btn-warning','float-left'],
75+
type: 'submit'
76+
},
77+
Create: {
78+
classes: ['btn-success','float-right'],
79+
type: 'submit'
80+
}
81+
},
82+
partialname: false
83+
},
84+
partial = path.join(partialPath, `${data.model}.js`);
85+
data.title = `Create New ${data.model.charAt(0).toUpperCase() + data.model.slice(1)}`,
86+
data.form = await sails.helpers.formGenerator.with({
87+
model: data.model,
88+
method: 'post',
89+
action: `/${data.model}s/create`,
90+
id: `${data.model}-create`,
91+
classes: [`${data.model}-create-form`],
92+
formItems: data.formItems,
93+
formButtons: data.formButtons
94+
});
95+
if (fs.existsSync(partial)) {
96+
data.partialname = partial;
97+
}
98+
return data;
99+
}
100+
};

api/controllers/pages/dashboard.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ module.exports = {
2424
webserver = false,
2525
uptime = await si.time().uptime * 1000,
2626
loadaverage = await si.currentLoad(),
27-
legend = [];
27+
legend = [],
28+
staged=3,
29+
active=6,
30+
avail=(10 - (staged + active));
2831

2932
loadaverage = loadaverage.avgload;
3033
uptime = moment.duration(uptime);
@@ -66,7 +69,10 @@ module.exports = {
6669
legend,
6770
webserver,
6871
loadaverage,
69-
uptime
72+
uptime,
73+
avail: avail,
74+
staged: staged,
75+
active: active
7076
});
7177
});
7278
// Respond with view.

api/helpers/form-generator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ module.exports = {
110110
if (input.placeholder) {
111111
iPlaceholder = ` placeholder="${input.placeholder}"`;
112112
}
113-
if (input.validations || obj.validations) {
113+
if (input.validations || (typeof obj !== 'undefined' && obj.validations)) {
114114
if (input.validations) {
115115
if (input.validations.maxLength) {
116116
iMaxlength = ` maxlength="${input.validations.maxLength}"`;
@@ -122,7 +122,7 @@ module.exports = {
122122
iRegex = ` regex="${input.validations.regex}"`;
123123
}
124124
}
125-
if (obj.validations) {
125+
if (typeof obj !== 'undefined' && obj.validations) {
126126
if (obj.validations.maxLength) {
127127
iMaxlength = ` maxlength="${obj.validations.maxLength}"`;
128128
}

config/routes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ module.exports.routes = {
9595

9696
// User Views
9797
'GET /users': {action: 'pages/list/users'},
98+
'GET /users/create': {action: 'pages/create/users'},
99+
'POST /users/create': {action: 'general/create'},
98100
'GET /user/me': {action: 'user/listme'},
99101

100102
// Workflow Views

views/pages/dashboard.ejs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@
5757
<h3 class="card-title">Activity</h3>
5858
</div>
5959
<div class="card-body">
60+
<div class="chart-responsive">
61+
<input type="hidden" id="avail" value="<%= avail %>">
62+
<input type="hidden" id="staged" value="<%= staged %>">
63+
<input type="hidden" id="active" value="<%= active %>">
64+
<canvas id="activityUsage" class="chartjs-render-monitor"></canvas>
65+
</div>
6066
</div>
6167
</div>
6268
</div>

views/pages/partials/dashboard.js

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,65 @@
22
let free = $('#free').val(),
33
used = $('#used').val(),
44
hFree = $.readableBytes(free),
5-
hUsed = $.readableBytes(used);
5+
hUsed = $.readableBytes(used),
6+
qavail = $('#avail').val(),
7+
qstaged = $('#staged').val(),
8+
qactive = $('#active').val();
9+
// Activity Usage
10+
let activeUsageCanvas = $('#activityUsage').get(0).getContext('2d'),
11+
activeUsageData = {
12+
labels: [
13+
`Available: ${qavail}`,
14+
`Active: ${qactive}`,
15+
`Staged: ${qstaged}`
16+
],
17+
datasets: [
18+
{
19+
data: [
20+
qavail,
21+
qactive,
22+
qstaged
23+
],
24+
backgroundColor: [
25+
'#28a745',
26+
'#dc3545',
27+
'#007bff'
28+
]
29+
}
30+
]
31+
},
32+
activeUsageOpts = {
33+
responsive: true,
34+
plugins: {
35+
labels: {
36+
reder: 'percentage',
37+
precision: 0,
38+
fontColor: '#ffffff',
39+
fontSize: 12
40+
}
41+
},
42+
legend: {
43+
position: 'bottom'
44+
},
45+
tooltips: {
46+
callbacks: {
47+
label: function(tooltipItem, data) {
48+
var dataset = data.datasets[tooltipItem.datasetIndex];
49+
var meta = dataset._meta[Object.keys(dataset._meta)[0]];
50+
var total = meta.total;
51+
var currentValue = dataset.data[tooltipItem.index];
52+
var percentage = parseFloat((currentValue/total*100).toFixed(1));
53+
var hText = $.readableBytes(currentValue);
54+
return `${hText} (${percentage}%)`;
55+
},
56+
}
57+
}
58+
},
59+
activeUsageChart = new Chart(activeUsageCanvas, {
60+
type: 'doughnut',
61+
data: activeUsageData,
62+
options: activeUsageOpts
63+
});
664
// Disk Usage
765
let diskUsageCanvas = $('#diskUsage').get(0).getContext('2d'),
866
diskUsageData = {

0 commit comments

Comments
 (0)