forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess-map-layout.js
More file actions
139 lines (126 loc) · 3.9 KB
/
process-map-layout.js
File metadata and controls
139 lines (126 loc) · 3.9 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import moment from "moment";
require("bootstrap");
const { Vue } = window;
if (window.ProcessMaker && window.ProcessMaker.user) {
moment.tz.setDefault(window.ProcessMaker.user.timezone);
moment.defaultFormat = window.ProcessMaker.user.datetime_format;
moment.defaultFormatUtc = window.ProcessMaker.user.datetime_format;
}
if (document.documentElement.lang) {
moment.locale(document.documentElement.lang);
window.ProcessMaker.user.lang = document.documentElement.lang;
}
Vue.prototype.moment = moment;
window.moment = moment;
// Event bus ProcessMaker.
window.ProcessMaker.events = new Vue();
window.ProcessMaker.nodeTypes = [];
window.ProcessMaker.nodeTypes.get = function (id) {
return this.find((node) => node.id === id);
};
window.ProcessMaker.navbar = new Vue({
el: "#navbar",
data() {
return {
alerts: [],
};
},
});
window.ProcessMaker.closeSessionModal = () => {
ProcessMaker.navbar.sessionShow = false;
};
// Set our own specific alert function at the ProcessMaker global object that could
// potentially be overwritten by some custom theme support
window.ProcessMaker.alert = (
msg,
variant,
showValue = 5,
stayNextScreen = false,
showLoader = false,
) => {
let updatedShowValue = showValue;
if (showValue === 0) {
// Just show it indefinitely, no countdown.
updatedShowValue = true;
}
// amount of items allowed in array
if (ProcessMaker.navbar.alerts.length > 5) {
ProcessMaker.navbar.alerts.shift();
}
ProcessMaker.navbar.alerts.push({
alertText: msg,
alertShow: updatedShowValue,
alertVariant: String(variant),
showLoader,
stayNextScreen,
timestamp: Date.now(),
});
};
// flags print forms
window.ProcessMaker.apiClient.requestCount = 0;
window.ProcessMaker.apiClient.requestCountFlag = false;
window.ProcessMaker.apiClient.interceptors.request.use((request) => {
// flags print forms
if (window.ProcessMaker.apiClient.requestCountFlag) {
window.ProcessMaker.apiClient.requestCount += 1;
}
window.ProcessMaker.EventBus.$emit("api-client-loading", request);
return request;
});
window.ProcessMaker.apiClient.interceptors.response.use(
(response) => {
window.ProcessMaker.EventBus.$emit("api-client-done", response);
// flags print forms
if (
window.ProcessMaker.apiClient.requestCountFlag
&& window.ProcessMaker.apiClient.requestCount > 0
) {
window.ProcessMaker.apiClient.requestCount -= 1;
}
return response;
},
(error) => {
window.ProcessMaker.EventBus.$emit("api-client-error", error);
if (
error.response
&& error.response.status
&& error.response.status === 401
) {
// stop 401 error consuming endpoints with data-sources
const { url } = error.config;
if (url.includes("/data_sources/")) {
if (url.includes("requests/") || url.includes("/test")) {
throw error;
}
}
window.location = "/login";
} else if (_.has(error, "config.url") && !error.config.url.match("/debug")) {
window.ProcessMaker.apiClient.post("/debug", {
name: "Javascript ProcessMaker.apiClient Error",
message: JSON.stringify({
message: error.message,
code: error.code,
config: error.config,
}),
});
}
return Promise.reject(error);
},
);
// Display any uncaught promise rejections from axios in the Process Maker alert box
window.addEventListener("unhandledrejection", (event) => {
const error = event.reason;
// eslint-disable-next-line no-underscore-dangle
if (error.config && error.config._defaultErrorShown) {
// Already handeled
event.preventDefault(); // stops the unhandled rejection error
} else if (
error.response
&& error.response.data
&& error.response.data.message
) {
window.ProcessMaker.alert(error.response.data.message, "danger");
} else if (error.message) {
window.ProcessMaker.alert(error.message, "danger");
}
});