2019-05-09 18:54:39 +12:00
|
|
|
// Init
|
|
|
|
|
2021-05-14 00:37:54 +12:00
|
|
|
window.ls.error = function () {
|
|
|
|
return function (error) {
|
2020-06-04 23:20:30 +12:00
|
|
|
window.console.error(error);
|
2020-06-07 02:04:18 +12:00
|
|
|
|
2021-05-14 00:37:54 +12:00
|
|
|
if (window.location.pathname !== '/console') {
|
2020-06-07 02:04:18 +12:00
|
|
|
window.location = '/console';
|
|
|
|
}
|
2019-09-13 22:47:07 +12:00
|
|
|
};
|
2019-05-09 18:54:39 +12:00
|
|
|
};
|
|
|
|
|
2021-05-14 00:37:54 +12:00
|
|
|
window.addEventListener("error", function (event) {
|
2019-09-13 22:47:07 +12:00
|
|
|
console.error("ERROR-EVENT:", event.error.message, event.error.stack);
|
2019-05-09 18:54:39 +12:00
|
|
|
});
|
|
|
|
|
2021-05-14 00:37:54 +12:00
|
|
|
document.addEventListener("account.deleteSession", function () {
|
2019-09-13 22:47:07 +12:00
|
|
|
window.location = "/auth/signin";
|
2020-02-13 21:04:52 +13:00
|
|
|
});
|
|
|
|
|
2021-05-14 00:37:54 +12:00
|
|
|
document.addEventListener("account.create", function () {
|
2020-02-13 21:04:52 +13:00
|
|
|
let container = window.ls.container;
|
|
|
|
let form = container.get('serviceForm');
|
|
|
|
let sdk = container.get('console');
|
|
|
|
|
|
|
|
let promise = sdk.account.createSession(form.email, form.password);
|
|
|
|
|
2020-02-18 18:25:28 +13:00
|
|
|
container.set("serviceForm", {}, true, true); // Remove sensetive data when not needed
|
2021-08-21 04:37:37 +12:00
|
|
|
|
2020-02-13 21:04:52 +13:00
|
|
|
promise.then(function () {
|
2021-05-14 00:37:54 +12:00
|
|
|
var subscribe = document.getElementById('newsletter').checked;
|
|
|
|
if (subscribe) {
|
2021-05-14 01:16:30 +12:00
|
|
|
let alerts = container.get('alerts');
|
|
|
|
let loaderId = alerts.add({ text: 'Loading...', class: "" }, 0);
|
2021-05-14 00:37:54 +12:00
|
|
|
fetch('https://appwrite.io/v1/newsletter/subscribe', {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
name: form.name,
|
|
|
|
email: form.email,
|
|
|
|
}),
|
|
|
|
}).finally(function () {
|
2021-05-14 01:16:30 +12:00
|
|
|
alerts.remove(loaderId);
|
2021-05-14 00:37:54 +12:00
|
|
|
window.location = '/console';
|
|
|
|
});
|
|
|
|
} else {
|
2020-02-13 21:04:52 +13:00
|
|
|
window.location = '/console';
|
2021-05-14 00:37:54 +12:00
|
|
|
}
|
|
|
|
}, function (error) {
|
|
|
|
window.location = '/auth/signup?failure=1';
|
2020-02-13 21:04:52 +13:00
|
|
|
});
|
2021-06-09 03:27:12 +12:00
|
|
|
});
|
2021-08-26 23:21:41 +12:00
|
|
|
window.addEventListener("load", async () => {
|
2021-08-26 03:56:53 +12:00
|
|
|
const bars = 12;
|
2021-06-09 03:27:12 +12:00
|
|
|
const realtime = window.ls.container.get('realtime');
|
2021-08-26 23:21:41 +12:00
|
|
|
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
2021-08-21 04:37:37 +12:00
|
|
|
let current = {};
|
2021-12-07 01:03:12 +13:00
|
|
|
window.ls.container.get('console').subscribe(['project', 'console'], response => {
|
|
|
|
switch (response.event) {
|
|
|
|
case 'stats.connections':
|
|
|
|
for (let project in response.payload) {
|
|
|
|
current[project] = response.payload[project] ?? 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'database.attributes.create':
|
|
|
|
case 'database.attributes.update':
|
|
|
|
case 'database.attributes.delete':
|
|
|
|
document.dispatchEvent(new CustomEvent('database.createAttribute'));
|
|
|
|
|
|
|
|
break;
|
|
|
|
case 'database.indexes.create':
|
|
|
|
case 'database.indexes.update':
|
|
|
|
case 'database.indexes.delete':
|
|
|
|
document.dispatchEvent(new CustomEvent('database.createIndex'));
|
|
|
|
|
|
|
|
break;
|
2021-08-21 04:37:37 +12:00
|
|
|
}
|
2021-12-07 01:03:12 +13:00
|
|
|
|
2021-06-09 03:27:12 +12:00
|
|
|
});
|
2021-08-26 23:21:41 +12:00
|
|
|
|
|
|
|
while (true) {
|
2021-08-21 04:37:37 +12:00
|
|
|
let newHistory = {};
|
2021-08-26 23:21:41 +12:00
|
|
|
let createdHistory = false;
|
2021-08-21 04:37:37 +12:00
|
|
|
for (const project in current) {
|
|
|
|
let history = realtime?.history ?? {};
|
|
|
|
|
|
|
|
if (!(project in history)) {
|
|
|
|
history[project] = new Array(bars).fill({
|
|
|
|
percentage: 0,
|
|
|
|
value: 0
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
history = history[project];
|
|
|
|
history.push({
|
|
|
|
percentage: 0,
|
|
|
|
value: current[project]
|
|
|
|
});
|
|
|
|
if (history.length >= bars) {
|
|
|
|
history.shift();
|
|
|
|
}
|
|
|
|
|
|
|
|
const highest = history.reduce((prev, curr) => {
|
|
|
|
return (curr.value > prev) ? curr.value : prev;
|
|
|
|
}, 0);
|
|
|
|
|
|
|
|
history = history.map(({ percentage, value }) => {
|
2021-08-26 23:21:41 +12:00
|
|
|
createdHistory = true;
|
2021-08-21 04:37:37 +12:00
|
|
|
percentage = value === 0 ? 0 : ((Math.round((value / highest) * 10) / 10) * 100);
|
|
|
|
if (percentage > 100) percentage = 100;
|
|
|
|
else if (percentage == 0 && value != 0) percentage = 5;
|
|
|
|
|
|
|
|
return {
|
|
|
|
percentage: percentage,
|
|
|
|
value: value
|
|
|
|
};
|
|
|
|
})
|
|
|
|
newHistory[project] = history;
|
|
|
|
}
|
2021-08-26 23:21:41 +12:00
|
|
|
|
2021-08-27 00:33:48 +12:00
|
|
|
let currentSnapshot = { ...current };
|
|
|
|
for (let index = .1; index <= 1; index += .05) {
|
|
|
|
let currentTransition = { ...currentSnapshot };
|
|
|
|
for (const project in current) {
|
|
|
|
if (project in newHistory) {
|
|
|
|
let base = newHistory[project][bars - 2].value;
|
|
|
|
let cur = currentSnapshot[project];
|
|
|
|
let offset = (cur - base) * index;
|
|
|
|
currentTransition[project] = base + Math.floor(offset);
|
2021-08-26 23:21:41 +12:00
|
|
|
}
|
|
|
|
}
|
2021-08-27 00:33:48 +12:00
|
|
|
|
|
|
|
realtime.setCurrent(currentTransition);
|
|
|
|
await sleep(250);
|
2021-08-26 23:21:41 +12:00
|
|
|
}
|
|
|
|
|
2021-08-21 04:37:37 +12:00
|
|
|
realtime.setHistory(newHistory);
|
2021-08-26 23:21:41 +12:00
|
|
|
}
|
2021-06-09 03:27:12 +12:00
|
|
|
});
|
|
|
|
|
2021-10-28 05:55:36 +13:00
|
|
|
window.formValidation = (form, fields) => {
|
2021-12-02 01:05:24 +13:00
|
|
|
const elements = Array.from(form.querySelectorAll('[name]')).reduce((prev, curr) => {
|
|
|
|
if(!curr.name) {
|
|
|
|
return prev;
|
|
|
|
}
|
|
|
|
prev[curr.name] = curr;
|
|
|
|
return prev;
|
|
|
|
}, {});
|
2021-10-28 05:55:36 +13:00
|
|
|
const actionHandler = (action, attribute) => {
|
|
|
|
switch (action) {
|
|
|
|
case "disable":
|
|
|
|
elements[attribute].setAttribute("disabled", true);
|
|
|
|
elements[attribute].dispatchEvent(new Event('change'));
|
|
|
|
break;
|
|
|
|
case "enable":
|
|
|
|
elements[attribute].removeAttribute("disabled");
|
|
|
|
elements[attribute].dispatchEvent(new Event('change'));
|
|
|
|
break;
|
|
|
|
case "unvalue":
|
|
|
|
elements[attribute].value = "";
|
|
|
|
break;
|
|
|
|
case "check":
|
|
|
|
elements[attribute].value = "true";
|
|
|
|
break;
|
|
|
|
case "uncheck":
|
|
|
|
elements[attribute].value = "false";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
for (const field in fields) {
|
|
|
|
for (const attribute in fields[field]) {
|
|
|
|
const attr = fields[field][attribute];
|
|
|
|
if (Array.isArray(attr)) {
|
|
|
|
attr.forEach(action => {
|
|
|
|
if (elements[field].value === "true") {
|
|
|
|
actionHandler(action, attribute);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
const condition = attr.if.some(c => {
|
|
|
|
return elements[c].value === "true";
|
|
|
|
});
|
|
|
|
if (condition) {
|
|
|
|
for (const thenAction in attr.then) {
|
|
|
|
attr.then[thenAction].forEach(action => {
|
|
|
|
actionHandler(action, thenAction);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (const elseAction in attr.else) {
|
|
|
|
attr.else[elseAction].forEach(action => {
|
|
|
|
actionHandler(action, elseAction);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-23 01:49:51 +13:00
|
|
|
form.addEventListener("reset", () => {
|
|
|
|
for (const key in fields) {
|
|
|
|
if (Object.hasOwnProperty.call(fields, key)) {
|
2021-12-02 01:05:24 +13:00
|
|
|
const element = elements[key];
|
2021-11-23 01:49:51 +13:00
|
|
|
element.setAttribute("value", "");
|
|
|
|
element.removeAttribute("disabled");
|
|
|
|
element.dispatchEvent(new Event("change"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2021-10-28 05:55:36 +13:00
|
|
|
};
|