forked from Netsyms/PackageHelper
Add event timeline (close #35)
parent
e063875712
commit
9a86653fda
@ -0,0 +1,108 @@
|
|||||||
|
/*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
function appendActivityLog(title, subtitle, content, icon, timestamp) {
|
||||||
|
if (typeof timestamp == "undefined") {
|
||||||
|
timestamp = time();
|
||||||
|
}
|
||||||
|
let entry = {
|
||||||
|
title: title,
|
||||||
|
subtitle: subtitle,
|
||||||
|
content: content,
|
||||||
|
icon: icon,
|
||||||
|
timestamp: timestamp
|
||||||
|
};
|
||||||
|
|
||||||
|
let log = getStorage("activitylog");
|
||||||
|
if (log == null) {
|
||||||
|
log = [];
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
log = JSON.parse(log);
|
||||||
|
} catch (ex) {
|
||||||
|
log = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let pushed = false;
|
||||||
|
let datestr = formatTimestamp("Y-m-d", timestamp);
|
||||||
|
for (var i = 0; i < log.length; i++) {
|
||||||
|
if (formatTimestamp("Y-m-d", log[i].date) == datestr) {
|
||||||
|
log[i].entries.push(entry);
|
||||||
|
pushed = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!pushed) {
|
||||||
|
log.push({
|
||||||
|
date: timestamp,
|
||||||
|
entries: [
|
||||||
|
entry
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Added activity log entry", entry);
|
||||||
|
console.log(log);
|
||||||
|
|
||||||
|
setStorage("activitylog", JSON.stringify(log));
|
||||||
|
|
||||||
|
// Trim the log soon but don't block for it
|
||||||
|
setTimeout(trimActivityLog, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearActivityLog() {
|
||||||
|
setStorage("activitylog", "[]");
|
||||||
|
}
|
||||||
|
|
||||||
|
function trimActivityLog() {
|
||||||
|
let log = JSON.parse(getStorage("activitylog"));
|
||||||
|
|
||||||
|
log.sort(function (x, y) {
|
||||||
|
if (x.date < y.date) {
|
||||||
|
return 1;
|
||||||
|
} else if (x.date > y.date) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
let entries = 0;
|
||||||
|
let allowed = SETTINGS.activitylog_maxlength;
|
||||||
|
|
||||||
|
let newlog = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < log.length; i++) {
|
||||||
|
let logdate = {
|
||||||
|
date: log[i].date,
|
||||||
|
entries: []
|
||||||
|
};
|
||||||
|
for (var j = 0; j < log[i].entries.length; j++) {
|
||||||
|
if (entries < allowed) {
|
||||||
|
logdate.entries.push(log[i].entries[j]);
|
||||||
|
}
|
||||||
|
entries++;
|
||||||
|
}
|
||||||
|
if (logdate.entries.length > 0) {
|
||||||
|
newlog.push(logdate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entries - allowed > 0) {
|
||||||
|
newlog[newlog.length - 1].entries.push({
|
||||||
|
title: "Log Trimmed",
|
||||||
|
subtitle: "",
|
||||||
|
content: (entries - allowed) + " older " + ((entries - allowed) == 1 ? "entry was" : "entries were") + " removed from the log.",
|
||||||
|
icon: "fas fa-cut",
|
||||||
|
timestamp: newlog[newlog.length - 1].date
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(log);
|
||||||
|
console.log(newlog);
|
||||||
|
setStorage("activitylog", JSON.stringify(newlog));
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
function confirmDeleteActivityLog() {
|
||||||
|
app.dialog.confirm(
|
||||||
|
"Really delete all log entries?",
|
||||||
|
"Clear Log",
|
||||||
|
function () {
|
||||||
|
// clear
|
||||||
|
clearActivityLog();
|
||||||
|
router.refreshPage();
|
||||||
|
},
|
||||||
|
function () {
|
||||||
|
// cancel
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||||
|
|
||||||
|
<div class="page" data-name="log">
|
||||||
|
|
||||||
|
<div class="navbar">
|
||||||
|
<div class="navbar-bg"></div>
|
||||||
|
<div class="navbar-inner">
|
||||||
|
<div class="left">
|
||||||
|
<a href="#" class="link icon-only back">
|
||||||
|
<i class="icon icon-back"></i>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="title">Activity Log</div>
|
||||||
|
<div class="right">
|
||||||
|
<a class="link text-color-red" onclick="confirmDeleteActivityLog()">
|
||||||
|
<i class="icon material-icons">delete</i>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="page-content">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-100 medium-60 large-50 xlarge-40 elevation-tablet margin-top-tablet">
|
||||||
|
{{#if events}}
|
||||||
|
<div class="timeline medium-sides">
|
||||||
|
{{#each events}}
|
||||||
|
<div class="timeline-item">
|
||||||
|
<div class="timeline-item-date">{{date}} <small>{{addldate}}</small></div>
|
||||||
|
<div class="timeline-item-divider"></div>
|
||||||
|
<div class="timeline-item-content">
|
||||||
|
{{#each entries}}
|
||||||
|
<div class="timeline-item-inner">
|
||||||
|
<div class="timeline-item-time">{{time}}</div>
|
||||||
|
<div class="timeline-item-title"><i class="{{icon}}"></i> {{title}}</div>
|
||||||
|
<div class="timeline-item-subtitle">{{subtitle}}</div>
|
||||||
|
<div class="timeline-item-text">{{content}}</div>
|
||||||
|
</div>
|
||||||
|
{{/each}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/each}}
|
||||||
|
</div>
|
||||||
|
{{else}}
|
||||||
|
<div class="block text-align-center">
|
||||||
|
<img style="width: 60%; max-width: 300px; max-height: 40vh;" src="assets/images/history-dashed.svg" class="margin-vertical" />
|
||||||
|
<div class="margin-top">Log empty! When you mark packages as delivered, add notes, and more, this log will automatically gain entries.</div>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="assets/js/toolbox_log.js"></script>
|
||||||
|
</div>
|
Loading…
Reference in New Issue