116 lines
4.2 KiB
JavaScript
116 lines
4.2 KiB
JavaScript
let USER = {};
|
|
|
|
// Определение ID главного блока
|
|
let app = document.getElementById('app');
|
|
|
|
// Конфигурация роутера
|
|
Router.config({ mode: 'history' });
|
|
|
|
async function appReload() {
|
|
|
|
location.reload();
|
|
|
|
// Router.navigate(window.location.pathname, false).check();
|
|
|
|
// // Закрытие старого соединения WebSocket
|
|
// if (socket) socket.close(1000, "Перезапуск соединения");
|
|
// listEntrances = []
|
|
// listApartment = []
|
|
}
|
|
|
|
const Rotation = async () => {
|
|
const result = confirm(`Ви бажаєте провести ротацію територій між групами?`);
|
|
|
|
if (result) {
|
|
let rotationButton = document.getElementById('rotationButton-title');
|
|
rotationButton.innerText = "Зачекайте";
|
|
|
|
let uuid = localStorage.getItem("uuid");
|
|
|
|
const URL = `${CONFIG.api}rotation`;
|
|
await fetch(URL, {
|
|
method: 'GET',
|
|
headers: {
|
|
"Content-Type": "application/json, text/plain, */*",
|
|
"Authorization": uuid
|
|
}
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
console.log(data);
|
|
rotationButton.innerText = 'Ротація завершилась успішно!';
|
|
|
|
Territory.house.setHTML();
|
|
Territory.homestead.setHTML();
|
|
|
|
setTimeout(() => {
|
|
rotationButton.innerText = "Провести ротацію";
|
|
}, 3000);
|
|
})
|
|
.catch(err => {
|
|
console.log(err);
|
|
rotationButton.innerText = "Помилка ротації!";
|
|
})
|
|
}
|
|
}
|
|
|
|
// Функция загрузки приложения
|
|
window.addEventListener('load', async function () {
|
|
console.log('[OS] ', detectOS());
|
|
if (window.matchMedia('(display-mode: standalone)').matches) {
|
|
if (detectOS() == 'Android') {
|
|
document.getElementById('navigation').dataset.state = '';
|
|
} else if (detectOS() == 'iOS') {
|
|
document.getElementById('navigation').dataset.state = 'ios';
|
|
localStorage.setItem('backToTop', 'false');
|
|
} else if (detectOS() == 'MacOS') {
|
|
document.getElementById('navigation').dataset.state = 'ios';
|
|
localStorage.setItem('backToTop', 'false');
|
|
} else {
|
|
document.getElementById('navigation').dataset.state = '';
|
|
}
|
|
}
|
|
|
|
let userInput = () => {
|
|
let h = prompt("Введіть ваше посилання з UUID:");
|
|
if (h) {
|
|
h = h.replace("https://sheep-service.com/?uuid=", "");
|
|
h = h.replace("https://sheep-service.com?uuid=", "");
|
|
h = h.replace("https://sheep-service.com?/hash=", "");
|
|
h = h.replace("https://sheep-service.com?hash=", "");
|
|
|
|
localStorage.setItem("uuid", h)
|
|
return h;
|
|
}
|
|
};
|
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
if (urlParams.get('uuid')) {
|
|
localStorage.setItem("uuid", urlParams.get('uuid'))
|
|
}
|
|
if (urlParams.get('hash')) {
|
|
localStorage.setItem("uuid", urlParams.get('hash'))
|
|
}
|
|
|
|
let uuid = localStorage.getItem("uuid") ? localStorage.getItem("uuid") : userInput();
|
|
if (uuid) {
|
|
const URL = `${CONFIG.api}auth`;
|
|
USER = await fetch(URL, {
|
|
method: 'GET',
|
|
headers: {
|
|
"Content-Type": "application/json, text/plain, */*",
|
|
"Authorization": uuid
|
|
}
|
|
}).then((response) => response.json());
|
|
|
|
console.log("USER Info: ", USER);
|
|
|
|
|
|
if (USER.administrator.uuid || USER.moderator.uuid) document.getElementById("li-sheeps").style.display = "";
|
|
if (USER.administrator.uuid || (USER.moderator.uuid && USER.moderator.can_add_schedule)) document.getElementById("li-schedule").style.display = "";
|
|
if (USER.administrator.uuid || (USER.moderator.uuid && USER.moderator.can_manager_territory)) document.getElementById("li-territory").style.display = "";
|
|
if (USER.administrator.uuid || USER.can_view_stand) document.getElementById("li-stand").style.display = "";
|
|
}
|
|
|
|
Router.check().listen();
|
|
}); |