Repository navigation
Expand file tree
/
Copy pathtasks.js
More file actions
277 lines (225 loc) · 8.63 KB
/
Copy pathtasks.js
File metadata and controls
277 lines (225 loc) · 8.63 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
const form = document.getElementById('sheetDbForm');
form.addEventListener("submit", e => {
e.preventDefault();
fetch(form.action, {
method : "POST",
body: new FormData(form),
}).then(
response => response.json()
).then((html) => {
});
alert('success');
form.reset();
});
//data from the OEE,Availability,Performance and Quality
const toau = {
limit:100,
apiKey: "jaz77Itn89EUTuq096fw_s6yynI4g8DJBQumEBgmN0ttjughI-rUVaIIwsyVlw",
spreadsheetId: "14fsBRp1Mnes7CDHToV5yqvnforSt6kcJHD3JOUEemq0"
};
const link = new URL("https://api.sheetson.com/v2/sheets/WAPQO");
Object.keys(toau).forEach((key) => link.searchParams.append(key, encodeURIComponent(toau[key])));
fetch(link)
.then((response) => response.json())
.then((result) => {
//console.log("Fetched Data:", result);
console.log(result.results);
getDataFromExcel(result.results);
})
function getDataFromExcel(data) {
const dataToBtm = document.querySelector('.btm');
let weekValues = {
"24/14": 14,
"24/15": 15,
"24/16": 16,
"24/17": 17
};
// Define arrays of background colors
let tconBackgroundColors = ["#fee2e2", "#f5d0fe", "#ccfbf1", "#eef2ff"];
let weekkkBackgroundColors = ["#701a75", "#1e40af", "#16a34a", "#f43f5e"];
data.forEach((item, index) => {
console.log(item);
const cont = document.createElement('div');
cont.classList.add('tcon');
cont.style.backgroundColor = tconBackgroundColors[index % tconBackgroundColors.length];
const coap = document.createElement('div');
coap.classList.add('coap');
const couo = document.createElement('div');
couo.classList.add('couo');
const weekValue = item.Week;
const numericWeekValue = weekValues[weekValue];
if (numericWeekValue !== undefined) {
const dataToWeek = document.createElement('div');
dataToWeek.classList.add('weekkk');
dataToWeek.style.backgroundColor = weekkkBackgroundColors[index % weekkkBackgroundColors.length];
dataToWeek.textContent = `${numericWeekValue}`;
cont.appendChild(dataToWeek);
if ('OEE' in item) {
const oee = document.createElement('div');
oee.classList.add('oee');
oee.textContent = `OEE: ${item.OEE}`;
couo.appendChild(oee);
}
if ('Availability' in item) {
const availability = document.createElement('div');
availability.classList.add('ava');
availability.textContent = `AVA: ${item.Availability}`;
coap.appendChild(availability);
}
if ('Performance' in item) {
const per = document.createElement('div');
per.classList.add('per');
per.textContent = `PER: ${item.Performance}`;
coap.appendChild(per);
}
if ('PL' in item) {
const udt = document.createElement('div');
udt.classList.add('udt');
udt.textContent = `PL: ${item.PL}`;
couo.appendChild(udt);
}
cont.appendChild(coap);
cont.appendChild(couo);
dataToBtm.appendChild(cont);
}
});
}
//data from the formdata sheet
const parameter = {
limit:100,
apiKey: "5NMubZFzK7dgCWXPYAMQhXwvBlwNXU8nytnPuvvY9Y1mpq6Nlgcmedd9vQY",
spreadsheetId: "1QVtTbCz_7911dG_Xugp9a9sXGZgqW8rib_X6wPA7KlM"
};
const urll = new URL("https://api.sheetson.com/v2/sheets/from-form");
Object.keys(parameter).forEach((key) => urll.searchParams.append(key, encodeURIComponent(parameter[key])));
fetch(urll)
.then((response) => response.json())
.then((result) => {
console.log("Fetched Data:", result.results);
displayDataInList(result.results);
})
function displayDataInList(data) {
// Assuming there is an HTML element with the id "dataList" where you want to display the data
const dataListElement = document.getElementById("tasks");
// Iterate through the data and create list items
data.forEach((item) => {
const lists = document.createElement('div');
lists.classList.add('un');
Object.entries(item).forEach(([key,value])=>{
if (key.toLowerCase() !== "rowindex"){
if (key.toLowerCase() === "duedate") {
const ti = document.createElement('div');
function updateTimer() {
future = Date.parse(value);
now = new Date();
diff = future - now;
days = Math.floor(diff / (1000 * 60 * 60 * 24));
hours = Math.floor(diff / (1000 * 60 * 60));
mins = Math.floor(diff / (1000 * 60));
secs = Math.floor(diff / 1000);
d = days;
h = hours - days * 24;
m = mins - hours * 60;
s = secs - mins * 60;
ti.innerHTML = d + ' : ' + h + ' : ' + m + ' : ' + s;
lists.appendChild(ti);
}
updateTimer();
setInterval(updateTimer, 1000);
}
const li = document.createElement("div");
li.textContent = value; // You can customize this based on your data structure
lists.appendChild(li);
}
});
// Append the unordered list to the dataListElement
dataListElement.appendChild(lists);
});
//console.log(dataListElement);
}
//data from the majordowntime(tohtml) sheet
const params = {
limit:170,
apiKey: "KRigaOPTxu3xg6U8kWHsuEr71V8FLXrrtLmN69F0r1aMDDBJ5CVmhWmwJKN1AA",
spreadsheetId: "14fsBRp1Mnes7CDHToV5yqvnforSt6kcJHD3JOUEemq0"
};
const url = new URL("https://api.sheetson.com/v2/sheets/table");
Object.keys(params).forEach((key) => url.searchParams.append(key, encodeURIComponent(params[key])));
fetch(url)
.then((response) => response.json())
.then((result) => {
console.log("Fetched Data:", result.results);
if (result && result.results && result.results.length > 0) {
displayDataByWeek(result.results);
} else {
console.error("Error: Data array is empty");
}
})
.catch((error) => console.error("Error:", error));
function displayDataByWeek(data) {
// Container to hold tables for each week
const tablesContainer = document.getElementById("container");
// Group data by week
const groupedData = groupDataByWeek(data);
// console.log(groupedData);
// Create a table for each week
Object.keys(groupedData).forEach((weekNumber) => {
const table = document.createElement("table");
table.classList.add('rwd-table');
// Extracting headers from the first row of data for the current week
const headers = Object.keys(groupedData[weekNumber][0]);
// Exclude 'week' and 'rowIndex' from headers
const filteredHeaders = headers.filter(header => header.toLowerCase() !== 'week' && header.toLowerCase() !== 'rowindex');
// Create table header row
const contain = document.createElement('div');
const headerRow = document.createElement("h3");
// console.log(weekNumber);
headerRow.textContent = "week " + weekNumber;
filteredHeaders.forEach(header => {
const th = document.createElement("th");
th.textContent = header;
table.appendChild(th);
});
contain.appendChild(headerRow);
contain.appendChild(table);
// Create table rows for the current week
groupedData[weekNumber].forEach((rowData) => {
const dataRow = document.createElement("tr");
filteredHeaders.forEach((header) => {
const td = document.createElement("td");
td.textContent = rowData[header];
dataRow.appendChild(td);
});
table.appendChild(dataRow);
});
//console.log(contain);
// Append the table to the container
tablesContainer.appendChild(contain);
});
}
function groupDataByWeek(data) {
// Assuming the data has a 'week' field
const groupedData = {};
// console.log(data);
// Iterate through each item in the data array
data.forEach((item) => {
// Extract the week number from the current item
const weekNumber = item.week;
// Creating an array for each week if not exists
if (!groupedData[weekNumber]) {
groupedData[weekNumber] = [];
}
// Adding data to the corresponding week's array
groupedData[weekNumber].push(item);
});
return reverseObjectKeys(groupedData);
}
function reverseObjectKeys(originalObject) {
const reversedObject = {};
Object.keys(originalObject)
.sort((a, b) => Number(b) - Number(a))
.forEach((key) => {
reversedObject[key] = originalObject[key];
});
return reversedObject;
}