-
Notifications
You must be signed in to change notification settings - Fork 374
Expand file tree
/
Copy pathutils.js
More file actions
83 lines (70 loc) · 2.16 KB
/
Copy pathutils.js
File metadata and controls
83 lines (70 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import $ from "jquery";
import moment from "moment-timezone";
// var p = {foo: [1,2,3], bar: 42};
// setting traditional to true generates
// foo=1&foo=2&foo=3&bar=42
$.ajaxSettings.traditional = true;
export const genieJobsUrl = url => {
const [ignored, path] = url.split("/api/v3/jobs", 2);
return `/output${path}`;
};
export const fileUrl = url => {
const [ignored, path] = url.split("/api/v3/jobs", 2);
return `/file${path}`;
};
export const stripHateoasTemplateUrl = url => url.replace("{?status}", "");
export const activeClusterUrl = url => url.replace("{?status}", "?status=UP");
export const activeCommandUrl = url =>
url.replace("{?status}", "?status=ACTIVE");
export const fetch = (
url,
data = null,
type = "GET",
headers = "application/hal+json"
) => $.ajax({ global: false, type, headers: { Accept: headers }, url, data });
export const hasChanged = (o1, o2) => {
// check if query params have changed or not
// this logic determines if need a full page reload
let changed = false;
for (const key of Object.keys(o1)) {
if (
(key === "src" && o1[key] === "btn") ||
(key !== "showDetails" && (!o2 || o1[key] !== o2[key]))
) {
changed = true;
break;
}
}
if (!changed) {
for (const key of Object.keys(o2)) {
if (key !== "showDetails" && (!o1 || o1[key] !== o2[key])) {
changed = true;
break;
}
}
}
return changed;
};
export const nowUtc = () => moment().utc();
// stringify moment object
export const milliSeconds = momentObj => `${momentObj}`;
export const momentFormat = (
dateStr,
tz = "UTC",
format = "MM/DD/YYYY, H:mm:ss"
) => {
// only UTC & PST are supported timezones
// default is UTC
if (tz === "PST") {
return dateStr
? moment.tz(dateStr, "America/Los_Angeles").format(format)
: "";
} else {
let utcDate = dateStr ? moment.utc(dateStr).format(format) : "";
return utcDate;
}
};
// https://github.com/moment/moment/issues/1048
export const momentDurationFormat = (durationStr, format = ":mm:ss") =>
Math.floor(moment.duration(durationStr).asHours()) +
moment.utc(moment.duration(durationStr).asMilliseconds()).format(format);