This commit is contained in:
2025-09-09 00:10:53 +03:00
parent 38f2a05107
commit 204fc092d7
239 changed files with 22447 additions and 9536 deletions

View File

@@ -3,93 +3,142 @@ const Home = {
let html = await fetch('/lib/pages/home/index.html').then((response) => response.text());
app.innerHTML = html;
Home.house.setHTML();
Home.homestead.setHTML();
if (USER.possibilities.can_view_territory) {
Home.personal.house.setHTML();
Home.personal.homestead.setHTML();
Home.group.house.setHTML();
Home.group.homestead.setHTML();
}
},
house: {
loadAPI: async function () {
let uuid = localStorage.getItem("uuid");
personal: {
house: {
list: [],
loadAPI: async () => {
const uuid = localStorage.getItem("uuid");
const URL = `${CONFIG.api}houses/list?mode=sheep`;
const res = await fetch(URL, {
headers: {
"Content-Type": "application/json",
"Authorization": uuid
}
});
Home.personal.house.list = await res.json();
return Home.personal.house.list;
},
setHTML: async () => {
const list = Home.personal.house.list.length > 0
? Home.personal.house.list
: await Home.personal.house.loadAPI();
const URL = `${CONFIG.api}houses/list?mode=sheep`;
return await fetch(URL, {
method: 'GET',
headers: {
"Content-Type": "application/json",
"Authorization": uuid
}
}).then((response) => response.json());
},
setHTML: async function () {
let list = await Home.house.loadAPI();
if (USER.possibilities.can_view_territory && list.length)
document.getElementById('details-personal-territory').style.display = "";
list.sort((a, b) => b.id - a.id);
list.sort((a, b) => b.id - a.id);
Home.renderCards(list, "house", "personal");
}
},
homestead: {
list: [],
loadAPI: async () => {
const uuid = localStorage.getItem("uuid");
const URL = `${CONFIG.api}homestead/list?mode=sheep`;
const res = await fetch(URL, {
headers: {
"Content-Type": "application/json",
"Authorization": uuid
}
});
Home.personal.homestead.list = await res.json();
return Home.personal.homestead.list;
},
setHTML: async () => {
const list = Home.personal.homestead.list.length > 0
? Home.personal.homestead.list
: await Home.personal.homestead.loadAPI();
console.log(list);
let block_house = document.getElementById('home-personal-territory-list')
if (USER.possibilities.can_view_territory && list.length)
document.getElementById('details-personal-territory').style.display = "";
for (let i = 0; i < list.length; i++) {
const element = list[i];
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>
<p>${element.title} ${element.number}</p>
</div>
</div>
</div>
<a href="/territory/card/house/${element.id}" data-route></a>
</div>
`;
list.sort((a, b) => b.id - a.id);
Home.renderCards(list, "homestead", "personal");
}
}
},
homestead: {
loadAPI: async function () {
let uuid = localStorage.getItem("uuid");
group: {
house: {
list: [],
loadAPI: async () => {
const uuid = localStorage.getItem("uuid");
const URL = `${CONFIG.api}house/list?mode=group`;
const res = await fetch(URL, {
headers: {
"Content-Type": "application/json",
"Authorization": uuid
}
});
Home.group.house.list = await res.json();
return Home.group.house.list;
},
setHTML: async () => {
const list = Home.group.house.list.length > 0
? Home.group.house.list
: await Home.group.house.loadAPI();
const URL = `${CONFIG.api}homestead/list?mode=sheep`;
return await fetch(URL, {
method: 'GET',
headers: {
"Content-Type": "application/json",
"Authorization": uuid
}
}).then((response) => response.json());
},
setHTML: async function () {
let list = await Home.homestead.loadAPI();
if (USER.possibilities.can_view_territory && list.length)
document.getElementById('details-group-territory').style.display = "";
list.sort((a, b) => b.id - a.id);
list.sort((a, b) => b.id - a.id);
Home.renderCards(list, "house", "group");
}
},
homestead: {
list: [],
loadAPI: async () => {
const uuid = localStorage.getItem("uuid");
const URL = `${CONFIG.api}homestead/list?mode=group`;
const res = await fetch(URL, {
headers: {
"Content-Type": "application/json",
"Authorization": uuid
}
});
Home.group.homestead.list = await res.json();
return Home.group.homestead.list;
},
setHTML: async () => {
const list = Home.group.homestead.list.length > 0
? Home.group.homestead.list
: await Home.group.homestead.loadAPI();
console.log(list);
let block_homestead = document.getElementById('home-personal-territory-list')
if (USER.possibilities.can_view_territory && list.length)
document.getElementById('details-group-territory').style.display = "";
for (let i = 0; i < list.length; i++) {
const element = list[i];
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">
<div>
<p>${element.title} ${element.number}</p>
</div>
</div>
</div>
<a href="/territory/card/homestead/${element.id}" data-route></a>
</div>
`;
list.sort((a, b) => b.id - a.id);
Home.renderCards(list, "homestead", "group");
}
}
},
renderCards: (list, type, block) => {
const container = document.getElementById(`home-${block}-territory-list`);
const fragment = document.createDocumentFragment();
for (const el of list) {
const card = document.createElement("div");
card.className = "card";
card.innerHTML = `
<i style="background-image: url(https://sheep-service.com/cards/${type}/${type === "house" ? "T" : "H"}${el.id}.webp);"></i>
<div class="contents">
<div class="info">
<div><p>${el.title} ${el.number}</p></div>
</div>
</div>
<a href="/territory/card/${type}/${el.id}" data-route></a>
`;
fragment.appendChild(card);
}
container.appendChild(fragment);
}
}