2017-11-04 19:38:50 -04:00
|
|
|
"use strict";
|
|
|
|
|
2017-11-29 23:30:35 -05:00
|
|
|
function reloadApp() {
|
|
|
|
window.location.reload(true);
|
|
|
|
}
|
|
|
|
|
2017-11-26 12:56:07 -05:00
|
|
|
function showMessage(message) {
|
2017-12-18 22:06:24 -05:00
|
|
|
console.log(now(), "message: ", message);
|
2017-11-26 12:56:07 -05:00
|
|
|
|
|
|
|
$.notify({
|
|
|
|
// options
|
|
|
|
message: message
|
|
|
|
},{
|
|
|
|
// settings
|
|
|
|
type: 'success',
|
2017-11-26 17:04:18 -05:00
|
|
|
delay: 3000
|
2017-11-26 12:56:07 -05:00
|
|
|
});
|
2017-08-13 21:42:10 -04:00
|
|
|
}
|
|
|
|
|
2017-12-12 23:47:17 -05:00
|
|
|
function showError(message, delay = 10000) {
|
2017-12-18 22:06:24 -05:00
|
|
|
console.log(now(), "error: ", message);
|
2017-11-26 12:56:07 -05:00
|
|
|
|
|
|
|
$.notify({
|
|
|
|
// options
|
|
|
|
message: message
|
|
|
|
},{
|
|
|
|
// settings
|
|
|
|
type: 'danger',
|
2017-12-12 23:47:17 -05:00
|
|
|
delay: delay
|
2017-11-26 12:56:07 -05:00
|
|
|
});
|
2017-09-06 22:06:43 -04:00
|
|
|
}
|
|
|
|
|
2017-12-06 19:53:23 -05:00
|
|
|
function throwError(message) {
|
2017-12-06 20:11:45 -05:00
|
|
|
messaging.logError(message);
|
|
|
|
|
|
|
|
throw new Error(message);
|
2017-12-06 19:53:23 -05:00
|
|
|
}
|
|
|
|
|
2017-12-10 15:31:43 -05:00
|
|
|
function parseDate(str) {
|
|
|
|
try {
|
|
|
|
return new Date(Date.parse(str));
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
throw new Error("Can't parse date from " + str + ": " + e.stack);
|
|
|
|
}
|
2017-09-30 22:36:14 -04:00
|
|
|
}
|
|
|
|
|
2017-12-14 22:38:38 -05:00
|
|
|
function padNum(num) {
|
|
|
|
return (num <= 9 ? "0" : "") + num;
|
|
|
|
}
|
|
|
|
|
2017-09-30 22:36:14 -04:00
|
|
|
function formatTime(date) {
|
2017-12-14 22:38:38 -05:00
|
|
|
return padNum(date.getHours()) + ":" + padNum(date.getMinutes());
|
2017-09-30 22:36:14 -04:00
|
|
|
}
|
|
|
|
|
2017-12-18 22:06:24 -05:00
|
|
|
function formatTimeWithSeconds(date) {
|
|
|
|
return padNum(date.getHours()) + ":" + padNum(date.getMinutes()) + ":" + padNum(date.getSeconds());
|
|
|
|
}
|
|
|
|
|
2017-09-30 22:36:14 -04:00
|
|
|
function formatDate(date) {
|
2017-12-14 22:38:38 -05:00
|
|
|
return padNum(date.getDate()) + ". " + padNum(date.getMonth() + 1) + ". " + date.getFullYear();
|
2017-09-30 22:36:14 -04:00
|
|
|
}
|
|
|
|
|
2018-01-25 23:22:19 -05:00
|
|
|
function formatDateISO(date) {
|
|
|
|
return date.getFullYear() + "-" + padNum(date.getMonth() + 1) + "-" + padNum(date.getDate());
|
|
|
|
}
|
|
|
|
|
2017-09-30 22:36:14 -04:00
|
|
|
function formatDateTime(date) {
|
|
|
|
return formatDate(date) + " " + formatTime(date);
|
2017-11-30 19:58:00 -05:00
|
|
|
}
|
|
|
|
|
2017-12-18 22:06:24 -05:00
|
|
|
function now() {
|
|
|
|
return formatTimeWithSeconds(new Date());
|
|
|
|
}
|
|
|
|
|
2017-11-30 19:58:00 -05:00
|
|
|
function isElectron() {
|
|
|
|
return window && window.process && window.process.type;
|
2017-12-23 11:02:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function assertArguments() {
|
|
|
|
for (const i in arguments) {
|
2017-12-23 12:19:15 -05:00
|
|
|
if (!arguments[i]) {
|
|
|
|
throwError(`Argument idx#${i} should not be falsy: ${arguments[i]}`);
|
|
|
|
}
|
2017-12-23 11:02:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function assert(expr, message) {
|
|
|
|
if (!expr) {
|
|
|
|
throwError(message);
|
|
|
|
}
|
2017-12-23 12:19:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function isTopLevelNode(node) {
|
|
|
|
return isRootNode(node.getParent());
|
|
|
|
}
|
|
|
|
|
|
|
|
function isRootNode(node) {
|
|
|
|
return node.key === "root_1";
|
2017-12-28 19:00:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function escapeHtml(str) {
|
|
|
|
return $('<div/>').text(str).html();
|
2018-01-22 23:18:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
async function stopWatch(what, func) {
|
|
|
|
const start = new Date();
|
|
|
|
|
|
|
|
const ret = await func();
|
|
|
|
|
|
|
|
const tookMs = new Date().getTime() - start.getTime();
|
|
|
|
|
|
|
|
console.log(`${what} took ${tookMs}ms`);
|
|
|
|
|
|
|
|
return ret;
|
2017-06-11 16:04:07 -04:00
|
|
|
}
|