v1.0.0
This commit is contained in:
189
web/lib/app.js
189
web/lib/app.js
@@ -18,42 +18,6 @@ async function appReload() {
|
||||
// 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());
|
||||
@@ -71,29 +35,14 @@ window.addEventListener('load', async function () {
|
||||
}
|
||||
}
|
||||
|
||||
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'))
|
||||
if (Router.getParams().uuid) {
|
||||
localStorage.setItem("uuid", Router.getParams().uuid)
|
||||
}
|
||||
|
||||
let uuid = localStorage.getItem("uuid") ? localStorage.getItem("uuid") : userInput();
|
||||
if (uuid) {
|
||||
let uuid = localStorage.getItem("uuid");
|
||||
if (!uuid) {
|
||||
Router.navigate(`/auth`).check().listen().delegateLinks();
|
||||
} else {
|
||||
const URL = `${CONFIG.api}auth`;
|
||||
USER = await fetch(URL, {
|
||||
method: 'GET',
|
||||
@@ -101,16 +50,126 @@ window.addEventListener('load', async function () {
|
||||
"Content-Type": "application/json, text/plain, */*",
|
||||
"Authorization": uuid
|
||||
}
|
||||
}).then((response) => response.json());
|
||||
}).then(response => {
|
||||
if (response.status === 401) {
|
||||
localStorage.removeItem("uuid");
|
||||
Router.navigate(`/auth`);
|
||||
}
|
||||
return 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 = "";
|
||||
}
|
||||
if (USER.possibilities.can_view_sheeps) document.getElementById("li-sheeps").style.display = "";
|
||||
if (USER.possibilities.can_view_schedule) document.getElementById("li-schedule").style.display = "";
|
||||
if (USER.possibilities.can_manager_territory) document.getElementById("li-territory").style.display = "";
|
||||
if (USER.possibilities.can_view_stand) document.getElementById("li-stand").style.display = "";
|
||||
|
||||
Router.check().listen();
|
||||
});
|
||||
if (USER.possibilities.can_view_sheeps) await Sheeps.sheeps_list.loadAPI();
|
||||
|
||||
editFontStyle();
|
||||
|
||||
Router.check().listen().delegateLinks();
|
||||
}
|
||||
});
|
||||
|
||||
function editFontStyle() {
|
||||
let fontSize = localStorage.getItem("fontSize")
|
||||
? localStorage.getItem("fontSize")
|
||||
: 'medium';
|
||||
|
||||
applyFontMode(fontSize);
|
||||
}
|
||||
|
||||
function applyFontMode(mode) {
|
||||
const options = {
|
||||
"small": {
|
||||
"--FontSize1": "10px",
|
||||
"--FontSize2": "11px",
|
||||
"--FontSize3": "12px",
|
||||
"--FontSize4": "13px",
|
||||
"--FontSize5": "14px"
|
||||
},
|
||||
"medium": {
|
||||
"--FontSize1": "12px",
|
||||
"--FontSize2": "13px",
|
||||
"--FontSize3": "14px",
|
||||
"--FontSize4": "15px",
|
||||
"--FontSize5": "16px"
|
||||
},
|
||||
"large": {
|
||||
"--FontSize1": "15px",
|
||||
"--FontSize2": "16px",
|
||||
"--FontSize3": "17px",
|
||||
"--FontSize4": "18px",
|
||||
"--FontSize5": "19px"
|
||||
}
|
||||
};
|
||||
|
||||
const root = document.documentElement;
|
||||
const config = options[mode];
|
||||
|
||||
if (!config) return;
|
||||
|
||||
Object.keys(config).forEach(key => {
|
||||
if (key.startsWith("--")) {
|
||||
root.style.setProperty(key, config[key]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Банер з прохання встановлення PWA
|
||||
let deferredPrompt;
|
||||
const isInStandaloneMode = () =>
|
||||
('standalone' in window.navigator && window.navigator.standalone === true);
|
||||
|
||||
if (detectOS() == 'iOS' && !isInStandaloneMode()) {
|
||||
setTimeout(() => {
|
||||
document.getElementById('blur-backdrop').classList.remove('pwa-hidden');
|
||||
document.getElementById('pwa-ios-overlay').classList.remove('pwa-hidden');
|
||||
document.body.classList.add('modal-open');
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
window.addEventListener("beforeinstallprompt", (e) => {
|
||||
e.preventDefault();
|
||||
deferredPrompt = e;
|
||||
|
||||
if (localStorage.getItem('modal') != "false") {
|
||||
document.getElementById("blur-backdrop").classList.remove("pwa-hidden");
|
||||
document.getElementById("pwa-install-overlay").classList.remove("pwa-hidden");
|
||||
document.body.classList.add("modal-open");
|
||||
}
|
||||
});
|
||||
document.getElementById("pwa-install-button").addEventListener("click", async () => {
|
||||
if (!deferredPrompt) return;
|
||||
|
||||
deferredPrompt.prompt();
|
||||
const { outcome } = await deferredPrompt.userChoice;
|
||||
console.log(`PWA install result: ${outcome}`);
|
||||
|
||||
closePopup();
|
||||
});
|
||||
document.getElementById("pwa-close-button").addEventListener("click", closePopup);
|
||||
document.getElementById('pwa-ios-close-button').addEventListener('click', closePopup);
|
||||
|
||||
function closePopup() {
|
||||
document.getElementById("pwa-install-overlay").classList.add("pwa-hidden");
|
||||
document.getElementById("blur-backdrop").classList.add("pwa-hidden");
|
||||
document.getElementById('pwa-ios-overlay').classList.add('pwa-hidden');
|
||||
document.body.classList.remove("modal-open");
|
||||
deferredPrompt = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.register('sw.js')
|
||||
.then(() => {
|
||||
console.log('Service Worker зарегистрирован');
|
||||
webPush.init();
|
||||
})
|
||||
.catch(err => console.error('Ошибка регистрации SW:', err));
|
||||
}
|
||||
Reference in New Issue
Block a user