Skip to content

Commit 7427eb9

Browse files
authored
Merge pull request #19 from rumd3x/feature/current-time
Display current server time on dashboard
2 parents dd977f1 + 2d936e7 commit 7427eb9

File tree

9 files changed

+51
-22
lines changed

9 files changed

+51
-22
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ Retrieve information about crontab.
4545
http://your-host/api/info
4646
```
4747

48+
- `GET` Time<br/>
49+
Get current server date and time information.
50+
```
51+
http://your-host/api/time
52+
```
53+
4854
- `GET` Jobs<br/>
4955
Retrieve a list of existing jobs.
5056
```
@@ -106,7 +112,7 @@ http://your-host/api/jobs/{id}
106112
| active | Boolean | If the job is enabled or not. |
107113

108114
## To Do
109-
- Add current container time to web interface
115+
- Have more ideas...
110116

111117
## License
112118

docs/dashboard.png

-17.1 KB
Loading

public/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<!-- Topbar -->
3535
<nav class="navbar navbar-expand navbar-light bg-white topbar mb-4 static-top shadow">
3636
<span class="navbar-brand">Docker Cronjob Manager</span>
37+
<small>Server Time: {{ currentTime }}</small>
3738
</nav>
3839
<!-- End of Topbar -->
3940

@@ -250,7 +251,7 @@ <h5 class="modal-title" id="exampleModalLabel">Job Management</h5>
250251
<input beth-bind="formObject.cron" type="text" class="form-control" id="txtJobSchedule" name="cron" aria-describedby="jobScheduleHelp" placeholder="* * * * *">
251252
<small id="jobScheduleHelp" class="form-text text-muted">The crontab schedule for this job. Click <a href="https://crontab.guru/" target="_blank">here</a> to create a crontab.</small>
252253
</div>
253-
254+
254255
<div class="form-check">
255256
<input beth-bind="formObject.active" type="checkbox" class="form-check-input" id="ckbJobActive" name="active">
256257
<label class="form-check-label" for="ckbJobActive">Enable Job</label>
@@ -290,12 +291,14 @@ <h5 class="modal-title" id="exampleModalLabel">Job Management</h5>
290291
<script src="js/sb-admin-2.js"></script>
291292

292293
<!-- Dashboard -->
294+
<script src="modules/commons.js"></script>
293295
<script src="modules/dashboard/info.js"></script>
294296
<script src="modules/dashboard/find.js"></script>
295297
<script src="modules/dashboard/list.js"></script>
296298
<script src="modules/dashboard/form.js"></script>
297299
<script src="modules/dashboard/logs.js"></script>
298300
<script src="modules/dashboard/delete.js"></script>
301+
<script src="modules/dashboard/time.js"></script>
299302
</body>
300303

301304
</html>

public/js/sb-admin-2.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,3 @@
4747
});
4848

4949
})(jQuery); // End of use strict
50-
51-
const makeToast = (type, message) => {
52-
$.toast({
53-
text: message,
54-
icon: type,
55-
showHideTransition: 'fade',
56-
allowToastClose: false,
57-
hideAfter: 3000,
58-
stack: 50,
59-
position: 'top-right',
60-
textAlign: 'left',
61-
loader: true,
62-
loaderBg: '#FFFFFF',
63-
});
64-
}

public/modules/commons.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const makeToast = (type, message) => {
2+
$.toast({
3+
text: message,
4+
icon: type,
5+
showHideTransition: 'fade',
6+
allowToastClose: false,
7+
hideAfter: 3000,
8+
stack: 50,
9+
position: 'top-right',
10+
textAlign: 'left',
11+
loader: true,
12+
loaderBg: '#FFFFFF',
13+
});
14+
}
15+
16+
const formatDateTimeString = (date) => {
17+
return new Date(Date.parse(date)).toLocaleString();
18+
}
19+
20+
const formatServerTime = (date) => {
21+
return new Date(Date.parse(date)).toLocaleString([], {hour: '2-digit', minute:'2-digit'});
22+
}

public/modules/dashboard/delete.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const deleteJob = (job_id) => {
22
findJobById(job_id, (job) => {
3-
console.log(job);
43
Swal.fire({
54
title: `Deleting job: ${job.name} (id: ${job.id})`,
65
text: "You are about to delete this job.",

public/modules/dashboard/list.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,4 @@ const getJobsList = () => {
1515
});
1616
}
1717

18-
const formatDateTimeString = (date) => {
19-
return new Date(Date.parse(date)).toLocaleString();
20-
}
21-
2218
getJobsList();

public/modules/dashboard/time.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var currentTime = "";
2+
3+
const getCurrentTime = () => {
4+
$.get(`api/time`, (response) => {
5+
currentTime = formatServerTime(response.data);
6+
}).fail((xhr) => {
7+
makeToast('error', xhr.responseJSON.message);
8+
});
9+
10+
setTimeout(getCurrentTime, 60000);
11+
}
12+
13+
getCurrentTime();

routes/routes.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ const register = (app) => {
1818
res.json({message: err.message});
1919
});
2020

21+
app.get("/api/time", async (req, res) => {
22+
res.status(200);
23+
res.json({"data": new Date(), "message": ""});
24+
});
25+
2126
app.get("/api/jobs", async (req, res) => {
2227
let jobs = await jobDao.list();
2328

0 commit comments

Comments
 (0)