v0.0.1
This commit is contained in:
130
web/lib/pages/territory/script.js
Normal file
130
web/lib/pages/territory/script.js
Normal file
@@ -0,0 +1,130 @@
|
||||
const Territory = {
|
||||
init: async () => {
|
||||
let html = await fetch('/lib/pages/territory/index.html').then((response) => response.text());
|
||||
app.innerHTML = html;
|
||||
|
||||
if (USER.administrator.uuid) document.getElementById('rotationButton').style.display = "";
|
||||
if (USER.administrator.uuid || (USER.moderator.uuid && USER.moderator.can_add_territory)) document.getElementById("constructorButton").style.display = "";
|
||||
|
||||
Territory.house.setHTML();
|
||||
Territory.homestead.setHTML();
|
||||
},
|
||||
house: {
|
||||
loadAPI: async function () {
|
||||
let uuid = localStorage.getItem("uuid");
|
||||
|
||||
const URL = `${CONFIG.api}houses/list`;
|
||||
return await fetch(URL, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": uuid
|
||||
}
|
||||
}).then((response) => response.json());
|
||||
},
|
||||
setHTML: async function () {
|
||||
let list = await Territory.house.loadAPI();
|
||||
|
||||
list.sort((a, b) => b.id - a.id);
|
||||
|
||||
console.log(list);
|
||||
let block_house = document.getElementById('list-house')
|
||||
block_house.innerHTML = "";
|
||||
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
const element = list[i];
|
||||
|
||||
let progress = ((element.entrance.working / element.entrance.quantity) * 100);
|
||||
|
||||
let pageURL = () => {
|
||||
if (USER.administrator.uuid || (USER.moderator.uuid && USER.moderator.can_manager_territory)) return `/territory/manager/house/${element.id}`;
|
||||
else return `/territory/card/house/${element.id}`
|
||||
}
|
||||
|
||||
block_house.innerHTML += `
|
||||
<div class="card">
|
||||
<i style="background-image: url(https://sheep-service.com/cards/house/T${element.id}.webp);"></i>
|
||||
<div class="contents">
|
||||
<div class="group" style="background: ${colorGroup(element.group_id)}">
|
||||
<span>Група №${element.group_id}</span>
|
||||
</div>
|
||||
<div class="info">
|
||||
<div>
|
||||
<div class="progress" style="width: ${progress}%"></div>
|
||||
<span>Вільні під'їзди:</span>
|
||||
<p>${element.entrance.quantity - element.entrance.working} / ${element.entrance.quantity}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p>${element.title} ${element.number}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<a href="${pageURL()}" data-route></a>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
},
|
||||
homestead: {
|
||||
loadAPI: async function () {
|
||||
let uuid = localStorage.getItem("uuid");
|
||||
|
||||
const URL = `${CONFIG.api}homestead/list`;
|
||||
return await fetch(URL, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": uuid
|
||||
}
|
||||
}).then((response) => response.json());
|
||||
},
|
||||
setHTML: async function () {
|
||||
let list = await Territory.homestead.loadAPI();
|
||||
|
||||
list.sort((a, b) => b.id - a.id);
|
||||
|
||||
console.log(list);
|
||||
let block_homestead = document.getElementById('list-homestead')
|
||||
block_homestead.innerHTML = "";
|
||||
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
const element = list[i];
|
||||
|
||||
let block_history = () => {
|
||||
if (element.working) {
|
||||
return `
|
||||
<div>
|
||||
<div class="progress" style="width: 100%"></div>
|
||||
<p>${element.history.name}</p>
|
||||
</div>
|
||||
`
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
let pageURL = () => {
|
||||
if (USER.administrator.uuid || (USER.moderator.uuid && USER.moderator.can_manager_territory)) return `/territory/manager/homestead/${element.id}`;
|
||||
else return `/territory/card/homestead/${element.id}`
|
||||
}
|
||||
|
||||
block_homestead.innerHTML += `
|
||||
<div class="card">
|
||||
<i style="background-image: url(https://sheep-service.com/cards/homestead/H${element.id}.webp);"></i>
|
||||
<div class="contents">
|
||||
<div class="group" style="background: ${colorGroup(element.group_id)}">
|
||||
<span>Група №${element.group_id}</span>
|
||||
</div>
|
||||
<div class="info">
|
||||
${block_history()}
|
||||
<div>
|
||||
<p>${element.title} ${element.number}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<a href="${pageURL()}" data-route></a>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user