Додана сторінка "Стенд"
Додане повідомлення про оновлення застосунку Оновлен Service Worker Перероблен WebSocket APІ
This commit is contained in:
@@ -15,7 +15,8 @@ db.serialize(() => {
|
|||||||
uuid_manager TEXT,
|
uuid_manager TEXT,
|
||||||
appointment TEXT DEFAULT 'lamb',
|
appointment TEXT DEFAULT 'lamb',
|
||||||
mode INTEGER DEFAULT 0,
|
mode INTEGER DEFAULT 0,
|
||||||
mode_title TEXT DEFAULT 'Користувач'
|
mode_title TEXT DEFAULT 'Користувач',
|
||||||
|
FOREIGN KEY (group_id) REFERENCES groups(group_number)
|
||||||
)
|
)
|
||||||
`);
|
`);
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@ db.serialize(() => {
|
|||||||
db.run(`
|
db.run(`
|
||||||
CREATE TABLE IF NOT EXISTS groups (
|
CREATE TABLE IF NOT EXISTS groups (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
group_number INTEGER,
|
group_number INTEGER UNIQUE,
|
||||||
share_hash TEXT
|
share_hash TEXT
|
||||||
)
|
)
|
||||||
`);
|
`);
|
||||||
@@ -49,7 +50,11 @@ db.serialize(() => {
|
|||||||
CREATE TABLE IF NOT EXISTS subscription (
|
CREATE TABLE IF NOT EXISTS subscription (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
sheep_id INTEGER,
|
sheep_id INTEGER,
|
||||||
token TEXT,
|
endpoint TEXT,
|
||||||
|
keys TEXT,
|
||||||
|
device_name TEXT,
|
||||||
|
device_model TEXT,
|
||||||
|
created_at TIMESTAMP,
|
||||||
FOREIGN KEY (sheep_id) REFERENCES sheeps(id)
|
FOREIGN KEY (sheep_id) REFERENCES sheeps(id)
|
||||||
)
|
)
|
||||||
`);
|
`);
|
||||||
@@ -66,7 +71,6 @@ db.serialize(() => {
|
|||||||
db.run(`
|
db.run(`
|
||||||
CREATE TABLE IF NOT EXISTS house (
|
CREATE TABLE IF NOT EXISTS house (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
group_id INTEGER,
|
|
||||||
title TEXT,
|
title TEXT,
|
||||||
number TEXT,
|
number TEXT,
|
||||||
points TEXT DEFAULT '[]',
|
points TEXT DEFAULT '[]',
|
||||||
@@ -76,8 +80,7 @@ db.serialize(() => {
|
|||||||
settlement TEXT,
|
settlement TEXT,
|
||||||
description TEXT,
|
description TEXT,
|
||||||
created_at TIMESTAMP,
|
created_at TIMESTAMP,
|
||||||
updated_at TIMESTAMP,
|
updated_at TIMESTAMP
|
||||||
FOREIGN KEY (group_id) REFERENCES groups(group_number)
|
|
||||||
)
|
)
|
||||||
`);
|
`);
|
||||||
|
|
||||||
@@ -87,10 +90,6 @@ db.serialize(() => {
|
|||||||
house_id INTEGER,
|
house_id INTEGER,
|
||||||
entrance_number INTEGER,
|
entrance_number INTEGER,
|
||||||
title TEXT,
|
title TEXT,
|
||||||
points TEXT DEFAULT '[]',
|
|
||||||
points_number TEXT DEFAULT '[]',
|
|
||||||
floors_quantity TEXT,
|
|
||||||
apartments_quantity TEXT,
|
|
||||||
description TEXT,
|
description TEXT,
|
||||||
created_at TIMESTAMP,
|
created_at TIMESTAMP,
|
||||||
updated_at TIMESTAMP,
|
updated_at TIMESTAMP,
|
||||||
@@ -106,9 +105,11 @@ db.serialize(() => {
|
|||||||
date_start TIMESTAMP,
|
date_start TIMESTAMP,
|
||||||
date_end TIMESTAMP,
|
date_end TIMESTAMP,
|
||||||
group_id INTEGER,
|
group_id INTEGER,
|
||||||
sheep_id TEXT,
|
sheep_id INTEGER,
|
||||||
working INTEGER DEFAULT 0,
|
working INTEGER DEFAULT 0,
|
||||||
FOREIGN KEY (entrance_id) REFERENCES entrance(id)
|
FOREIGN KEY (entrance_id) REFERENCES entrance(id),
|
||||||
|
FOREIGN KEY (sheep_id) REFERENCES sheeps(id),
|
||||||
|
FOREIGN KEY (group_id) REFERENCES groups(group_number)
|
||||||
)
|
)
|
||||||
`);
|
`);
|
||||||
|
|
||||||
@@ -121,20 +122,22 @@ db.serialize(() => {
|
|||||||
floors_number INTEGER,
|
floors_number INTEGER,
|
||||||
status INTEGER,
|
status INTEGER,
|
||||||
description TEXT,
|
description TEXT,
|
||||||
sheep_id TEXT,
|
sheep_id INTEGER,
|
||||||
updated_at TIMESTAMP,
|
updated_at TIMESTAMP,
|
||||||
FOREIGN KEY (entrance_id) REFERENCES entrance(id)
|
FOREIGN KEY (entrance_id) REFERENCES entrance(id),
|
||||||
|
FOREIGN KEY (sheep_id) REFERENCES sheeps(id)
|
||||||
)
|
)
|
||||||
`);
|
`);
|
||||||
|
|
||||||
db.run(`
|
db.run(`
|
||||||
CREATE TABLE IF NOT EXISTS apartments_history (
|
CREATE TABLE IF NOT EXISTS apartments_history (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
sheep_id TEXT,
|
sheep_id INTEGER,
|
||||||
apartments_id INTEGER,
|
apartments_id INTEGER,
|
||||||
status INTEGER,
|
status INTEGER,
|
||||||
description TEXT,
|
description TEXT,
|
||||||
created_at TIMESTAMP,
|
created_at TIMESTAMP,
|
||||||
|
FOREIGN KEY (sheep_id) REFERENCES sheeps(id),
|
||||||
FOREIGN KEY (apartments_id) REFERENCES apartments(id)
|
FOREIGN KEY (apartments_id) REFERENCES apartments(id)
|
||||||
)
|
)
|
||||||
`);
|
`);
|
||||||
@@ -142,18 +145,16 @@ db.serialize(() => {
|
|||||||
db.run(`
|
db.run(`
|
||||||
CREATE TABLE IF NOT EXISTS homestead (
|
CREATE TABLE IF NOT EXISTS homestead (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
group_id INTEGER,
|
|
||||||
title TEXT,
|
title TEXT,
|
||||||
number TEXT,
|
number TEXT,
|
||||||
points TEXT DEFAULT '[]',
|
points TEXT DEFAULT '[]',
|
||||||
point_icons TEXT DEFAULT '[]',
|
|
||||||
geo TEXT DEFAULT '[]',
|
geo TEXT DEFAULT '[]',
|
||||||
|
zoom INTEGER DEFAULT 18,
|
||||||
osm_id TEXT DEFAULT '[]',
|
osm_id TEXT DEFAULT '[]',
|
||||||
settlement TEXT,
|
settlement TEXT,
|
||||||
description TEXT,
|
description TEXT,
|
||||||
created_at TIMESTAMP,
|
created_at TIMESTAMP,
|
||||||
updated_at TIMESTAMP,
|
updated_at TIMESTAMP
|
||||||
FOREIGN KEY (group_id) REFERENCES groups(group_number)
|
|
||||||
)
|
)
|
||||||
`);
|
`);
|
||||||
|
|
||||||
@@ -165,9 +166,11 @@ db.serialize(() => {
|
|||||||
date_start TIMESTAMP,
|
date_start TIMESTAMP,
|
||||||
date_end TIMESTAMP,
|
date_end TIMESTAMP,
|
||||||
group_id INTEGER,
|
group_id INTEGER,
|
||||||
sheep_id TEXT,
|
sheep_id INTEGER,
|
||||||
working INTEGER DEFAULT 0,
|
working INTEGER DEFAULT 0,
|
||||||
FOREIGN KEY (homestead_id) REFERENCES homestead(id)
|
FOREIGN KEY (homestead_id) REFERENCES homestead(id),
|
||||||
|
FOREIGN KEY (sheep_id) REFERENCES sheeps(id),
|
||||||
|
FOREIGN KEY (group_id) REFERENCES groups(group_number)
|
||||||
)
|
)
|
||||||
`);
|
`);
|
||||||
|
|
||||||
@@ -177,7 +180,7 @@ db.serialize(() => {
|
|||||||
date TIMESTAMP,
|
date TIMESTAMP,
|
||||||
type INTEGER,
|
type INTEGER,
|
||||||
name TEXT,
|
name TEXT,
|
||||||
sheep_id TEXT,
|
sheep_id INTEGER,
|
||||||
title TEXT,
|
title TEXT,
|
||||||
number TEXT,
|
number TEXT,
|
||||||
FOREIGN KEY (sheep_id) REFERENCES sheeps(id)
|
FOREIGN KEY (sheep_id) REFERENCES sheeps(id)
|
||||||
@@ -188,23 +191,38 @@ db.serialize(() => {
|
|||||||
CREATE TABLE IF NOT EXISTS stand_list (
|
CREATE TABLE IF NOT EXISTS stand_list (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
title TEXT,
|
title TEXT,
|
||||||
hour_start INTEGER DEFAULT 10,
|
geo TEXT DEFAULT '[]',
|
||||||
hour_end INTEGER DEFAULT 16,
|
hour_start INTEGER DEFAULT 9,
|
||||||
|
hour_end INTEGER DEFAULT 18,
|
||||||
quantity_sheep INTEGER DEFAULT 2,
|
quantity_sheep INTEGER DEFAULT 2,
|
||||||
week_days TEXT DEFAULT '[0, 1, 2, 3, 4, 5, 6]'
|
week_days TEXT DEFAULT '[0, 1, 2, 3, 4, 5, 6]',
|
||||||
|
processing_time REAL DEFAULT 1,
|
||||||
|
status INTEGER DEFAULT 0,
|
||||||
|
updated_at TIMESTAMP
|
||||||
)
|
)
|
||||||
`);
|
`);
|
||||||
|
|
||||||
db.run(`
|
db.run(`
|
||||||
CREATE TABLE IF NOT EXISTS stand_schedule (
|
CREATE TABLE IF NOT EXISTS stand_schedule (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
stand INTEGER,
|
stand_id INTEGER,
|
||||||
date TIMESTAMP,
|
date TIMESTAMP,
|
||||||
hour INTEGER,
|
hour INTEGER,
|
||||||
sheep_id TEXT,
|
sheep_id INTEGER,
|
||||||
number_sheep TEXT,
|
number_sheep TEXT,
|
||||||
updated_at TIMESTAMP,
|
updated_at TIMESTAMP,
|
||||||
FOREIGN KEY (stand) REFERENCES stand_list(id),
|
FOREIGN KEY (stand_id) REFERENCES stand_list(id),
|
||||||
|
FOREIGN KEY (sheep_id) REFERENCES sheeps(id)
|
||||||
|
)
|
||||||
|
`);
|
||||||
|
|
||||||
|
db.run(`
|
||||||
|
CREATE TABLE IF NOT EXISTS stand_schedule_history (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
stand_schedule_id INTEGER,
|
||||||
|
sheep_id INTEGER,
|
||||||
|
created_at TIMESTAMP,
|
||||||
|
FOREIGN KEY (stand_schedule_id) REFERENCES stand_schedule(id),
|
||||||
FOREIGN KEY (sheep_id) REFERENCES sheeps(id)
|
FOREIGN KEY (sheep_id) REFERENCES sheeps(id)
|
||||||
)
|
)
|
||||||
`);
|
`);
|
||||||
|
|||||||
@@ -2,26 +2,20 @@ const HomesteadsService = require('../services/homesteads.service');
|
|||||||
|
|
||||||
class HomesteadsController {
|
class HomesteadsController {
|
||||||
async getList(req, res) {
|
async getList(req, res) {
|
||||||
const { mode } = req.query;
|
const { mode, sheep_id } = req.query;
|
||||||
|
|
||||||
if (req.possibilities.can_view_territory) {
|
if (req.possibilities.can_view_territory) {
|
||||||
let group_id = 0;
|
let id = null;
|
||||||
let sheepName = false;
|
|
||||||
|
|
||||||
// if (req.mode == 2) {
|
if (mode == "admin" && req.possibilities.can_manager_territory) {
|
||||||
// group_id = 0;
|
id = sheep_id;
|
||||||
// } else if (req.mode == 1) {
|
} else if (mode == "sheep") {
|
||||||
// group_id = req.group_id;
|
id = req.sheepId;
|
||||||
// }
|
} else if (mode == "group") {
|
||||||
|
id = req.group_id;
|
||||||
if (mode == "sheep") {
|
|
||||||
group_id = req.group_id;
|
|
||||||
sheepName = req.sheepName;
|
|
||||||
} else if (mode == "group"){
|
|
||||||
group_id = req.group_id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = await HomesteadsService.getList(group_id, sheepName);
|
let result = await HomesteadsService.getList(mode, id);
|
||||||
if (result) {
|
if (result) {
|
||||||
return res
|
return res
|
||||||
.status(200)
|
.status(200)
|
||||||
|
|||||||
@@ -22,26 +22,20 @@ class HousesController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getList(req, res) {
|
async getList(req, res) {
|
||||||
const { mode } = req.query;
|
const { mode, sheep_id } = req.query;
|
||||||
|
|
||||||
if (req.possibilities.can_view_territory) {
|
if (req.possibilities.can_view_territory) {
|
||||||
let group_id = 0;
|
let id = null;
|
||||||
let sheepName = false;
|
|
||||||
|
|
||||||
// if (req.mode == 2) {
|
if (mode == "admin" && req.possibilities.can_manager_territory) {
|
||||||
// group_id = 0;
|
id = sheep_id;
|
||||||
// } else if (req.mode == 1) {
|
} else if (mode == "sheep") {
|
||||||
// group_id = req.group_id;
|
id = req.sheepId;
|
||||||
// }
|
} else if (mode == "group") {
|
||||||
|
id = req.group_id;
|
||||||
if (mode == "sheep") {
|
|
||||||
group_id = req.group_id;
|
|
||||||
sheepName = req.sheepName;
|
|
||||||
} else if (mode == "group"){
|
|
||||||
group_id = req.group_id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = await HousesService.getList(group_id, sheepName);
|
let result = await HousesService.getList(mode, id);
|
||||||
if (result) {
|
if (result) {
|
||||||
return res
|
return res
|
||||||
.status(200)
|
.status(200)
|
||||||
|
|||||||
@@ -4,7 +4,26 @@ class StandController {
|
|||||||
async getStand(req, res) {
|
async getStand(req, res) {
|
||||||
const { stand_id } = req.params;
|
const { stand_id } = req.params;
|
||||||
|
|
||||||
return res.status(200).send({ stand_id });
|
if (stand_id) {
|
||||||
|
if (req.possibilities.can_view_stand) {
|
||||||
|
const result = await StandService.getStand(stand_id);
|
||||||
|
if (result) {
|
||||||
|
return res.status(200).send(result);
|
||||||
|
} else {
|
||||||
|
return res.status(404).send({
|
||||||
|
message: 'Stand not found.'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return res
|
||||||
|
.status(403)
|
||||||
|
.send({ message: 'The sheep does not have enough rights.' });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return res
|
||||||
|
.status(401)
|
||||||
|
.send({ message: 'Stand not found.' });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getList(req, res) {
|
async getList(req, res) {
|
||||||
@@ -23,7 +42,6 @@ class StandController {
|
|||||||
.status(404)
|
.status(404)
|
||||||
.send({ message: 'The sheep does not have enough rights.' });
|
.send({ message: 'The sheep does not have enough rights.' });
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async createStand(req, res) {
|
async createStand(req, res) {
|
||||||
@@ -130,7 +148,29 @@ class StandController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getScheduleList(req, res) {
|
async getScheduleList(req, res) {
|
||||||
return res.status(200).send({});
|
const { stand_id } = req.params;
|
||||||
|
|
||||||
|
if (stand_id) {
|
||||||
|
if (req.possibilities.can_view_stand) {
|
||||||
|
const result = await StandService.getScheduleList(stand_id);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
return res.status(200).send(result);
|
||||||
|
} else {
|
||||||
|
return res
|
||||||
|
.status(404)
|
||||||
|
.send({ message: 'Schedule not found.' });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return res
|
||||||
|
.status(404)
|
||||||
|
.send({ message: 'The sheep does not have enough rights.' });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return res
|
||||||
|
.status(401)
|
||||||
|
.send({ message: 'Stand id not found.' });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getScheduleHistory(req, res) {
|
async getScheduleHistory(req, res) {
|
||||||
|
|||||||
133
api/package-lock.json
generated
133
api/package-lock.json
generated
@@ -14,6 +14,7 @@
|
|||||||
"exceljs": "^4.4.0",
|
"exceljs": "^4.4.0",
|
||||||
"express": "^4.21.0",
|
"express": "^4.21.0",
|
||||||
"node-telegram-bot-api": "^0.66.0",
|
"node-telegram-bot-api": "^0.66.0",
|
||||||
|
"pg": "^8.16.3",
|
||||||
"puppeteer": "^24.4.0",
|
"puppeteer": "^24.4.0",
|
||||||
"sharp": "^0.33.5",
|
"sharp": "^0.33.5",
|
||||||
"sqlite3": "^5.1.7",
|
"sqlite3": "^5.1.7",
|
||||||
@@ -4251,6 +4252,87 @@
|
|||||||
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
|
||||||
"integrity": "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow=="
|
"integrity": "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow=="
|
||||||
},
|
},
|
||||||
|
"node_modules/pg": {
|
||||||
|
"version": "8.16.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/pg/-/pg-8.16.3.tgz",
|
||||||
|
"integrity": "sha512-enxc1h0jA/aq5oSDMvqyW3q89ra6XIIDZgCX9vkMrnz5DFTw/Ny3Li2lFQ+pt3L6MCgm/5o2o8HW9hiJji+xvw==",
|
||||||
|
"dependencies": {
|
||||||
|
"pg-connection-string": "^2.9.1",
|
||||||
|
"pg-pool": "^3.10.1",
|
||||||
|
"pg-protocol": "^1.10.3",
|
||||||
|
"pg-types": "2.2.0",
|
||||||
|
"pgpass": "1.0.5"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 16.0.0"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"pg-cloudflare": "^1.2.7"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"pg-native": ">=3.0.1"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"pg-native": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/pg-cloudflare": {
|
||||||
|
"version": "1.2.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/pg-cloudflare/-/pg-cloudflare-1.2.7.tgz",
|
||||||
|
"integrity": "sha512-YgCtzMH0ptvZJslLM1ffsY4EuGaU0cx4XSdXLRFae8bPP4dS5xL1tNB3k2o/N64cHJpwU7dxKli/nZ2lUa5fLg==",
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"node_modules/pg-connection-string": {
|
||||||
|
"version": "2.9.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.9.1.tgz",
|
||||||
|
"integrity": "sha512-nkc6NpDcvPVpZXxrreI/FOtX3XemeLl8E0qFr6F2Lrm/I8WOnaWNhIPK2Z7OHpw7gh5XJThi6j6ppgNoaT1w4w=="
|
||||||
|
},
|
||||||
|
"node_modules/pg-int8": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
|
||||||
|
"integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/pg-pool": {
|
||||||
|
"version": "3.10.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.10.1.tgz",
|
||||||
|
"integrity": "sha512-Tu8jMlcX+9d8+QVzKIvM/uJtp07PKr82IUOYEphaWcoBhIYkoHpLXN3qO59nAI11ripznDsEzEv8nUxBVWajGg==",
|
||||||
|
"peerDependencies": {
|
||||||
|
"pg": ">=8.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/pg-protocol": {
|
||||||
|
"version": "1.10.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.10.3.tgz",
|
||||||
|
"integrity": "sha512-6DIBgBQaTKDJyxnXaLiLR8wBpQQcGWuAESkRBX/t6OwA8YsqP+iVSiond2EDy6Y/dsGk8rh/jtax3js5NeV7JQ=="
|
||||||
|
},
|
||||||
|
"node_modules/pg-types": {
|
||||||
|
"version": "2.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz",
|
||||||
|
"integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==",
|
||||||
|
"dependencies": {
|
||||||
|
"pg-int8": "1.0.1",
|
||||||
|
"postgres-array": "~2.0.0",
|
||||||
|
"postgres-bytea": "~1.0.0",
|
||||||
|
"postgres-date": "~1.0.4",
|
||||||
|
"postgres-interval": "^1.1.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/pgpass": {
|
||||||
|
"version": "1.0.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz",
|
||||||
|
"integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==",
|
||||||
|
"dependencies": {
|
||||||
|
"split2": "^4.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/picocolors": {
|
"node_modules/picocolors": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
|
||||||
@@ -4264,6 +4346,41 @@
|
|||||||
"node": ">= 0.4"
|
"node": ">= 0.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/postgres-array": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/postgres-bytea": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/postgres-date": {
|
||||||
|
"version": "1.0.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz",
|
||||||
|
"integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/postgres-interval": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz",
|
||||||
|
"integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"xtend": "^4.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/prebuild-install": {
|
"node_modules/prebuild-install": {
|
||||||
"version": "7.1.3",
|
"version": "7.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-7.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-7.1.3.tgz",
|
||||||
@@ -5228,6 +5345,14 @@
|
|||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/split2": {
|
||||||
|
"version": "4.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz",
|
||||||
|
"integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 10.x"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/sqlite3": {
|
"node_modules/sqlite3": {
|
||||||
"version": "5.1.7",
|
"version": "5.1.7",
|
||||||
"resolved": "https://registry.npmjs.org/sqlite3/-/sqlite3-5.1.7.tgz",
|
"resolved": "https://registry.npmjs.org/sqlite3/-/sqlite3-5.1.7.tgz",
|
||||||
@@ -6007,6 +6132,14 @@
|
|||||||
"resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz",
|
||||||
"integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw=="
|
"integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw=="
|
||||||
},
|
},
|
||||||
|
"node_modules/xtend": {
|
||||||
|
"version": "4.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
|
||||||
|
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/y18n": {
|
"node_modules/y18n": {
|
||||||
"version": "5.0.8",
|
"version": "5.0.8",
|
||||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
|
||||||
|
|||||||
@@ -11,12 +11,12 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^17.2.0",
|
"dotenv": "^17.2.0",
|
||||||
|
"exceljs": "^4.4.0",
|
||||||
"express": "^4.21.0",
|
"express": "^4.21.0",
|
||||||
"node-telegram-bot-api": "^0.66.0",
|
"node-telegram-bot-api": "^0.66.0",
|
||||||
"puppeteer": "^24.4.0",
|
"puppeteer": "^24.4.0",
|
||||||
"sharp": "^0.33.5",
|
"sharp": "^0.33.5",
|
||||||
"sqlite3": "^5.1.7",
|
"sqlite3": "^5.1.7",
|
||||||
"web-push": "^3.6.7",
|
"web-push": "^3.6.7"
|
||||||
"exceljs": "^4.4.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ router
|
|||||||
.delete(authenticate, StandController.deleteStand);
|
.delete(authenticate, StandController.deleteStand);
|
||||||
|
|
||||||
router
|
router
|
||||||
.route('/schedule/list')
|
.route('/schedule/list/:stand_id')
|
||||||
.get(authenticate, StandController.getScheduleList)
|
.get(authenticate, StandController.getScheduleList)
|
||||||
|
|
||||||
router
|
router
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const db = require("../config/db");
|
const db = require("../config/db");
|
||||||
|
|
||||||
class HomesteadsService {
|
class HomesteadsService {
|
||||||
getList(group, sheepName) {
|
getList(mode, id) {
|
||||||
return new Promise((res, rej) => {
|
return new Promise((res, rej) => {
|
||||||
let sql = `
|
let sql = `
|
||||||
SELECT
|
SELECT
|
||||||
@@ -17,7 +17,7 @@ class HomesteadsService {
|
|||||||
homestead
|
homestead
|
||||||
`;
|
`;
|
||||||
|
|
||||||
if (group != "0" && !sheepName) {
|
if (mode == "group") {
|
||||||
sql = `
|
sql = `
|
||||||
SELECT
|
SELECT
|
||||||
homestead.*,
|
homestead.*,
|
||||||
@@ -39,11 +39,9 @@ class HomesteadsService {
|
|||||||
AND
|
AND
|
||||||
homestead_history.name = 'Групова'
|
homestead_history.name = 'Групова'
|
||||||
AND
|
AND
|
||||||
homestead_history.group_id == '${group}'
|
homestead_history.group_id = '${id}'
|
||||||
`;
|
`;
|
||||||
}
|
} else if (mode == "sheep" || mode == "admin") {
|
||||||
|
|
||||||
if (sheepName) {
|
|
||||||
sql = `
|
sql = `
|
||||||
SELECT
|
SELECT
|
||||||
homestead.*,
|
homestead.*,
|
||||||
@@ -63,7 +61,7 @@ class HomesteadsService {
|
|||||||
AND
|
AND
|
||||||
homestead_history.working = 1
|
homestead_history.working = 1
|
||||||
AND
|
AND
|
||||||
homestead_history.name = '${sheepName}';
|
homestead_history.sheep_id = '${id}';
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class HousesService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getList(group, sheepName) {
|
getList(mode, id) {
|
||||||
return new Promise((res, rej) => {
|
return new Promise((res, rej) => {
|
||||||
let sql = `
|
let sql = `
|
||||||
SELECT
|
SELECT
|
||||||
@@ -72,7 +72,7 @@ class HousesService {
|
|||||||
house
|
house
|
||||||
`;
|
`;
|
||||||
|
|
||||||
if (group != "0" && !sheepName) {
|
if (mode == "group") {
|
||||||
sql = `
|
sql = `
|
||||||
SELECT DISTINCT
|
SELECT DISTINCT
|
||||||
house.*,
|
house.*,
|
||||||
@@ -89,11 +89,9 @@ class HousesService {
|
|||||||
AND
|
AND
|
||||||
entrance_history.name = 'Групова'
|
entrance_history.name = 'Групова'
|
||||||
AND
|
AND
|
||||||
entrance_history.group_id == '${group}'
|
entrance_history.group_id = '${id}'
|
||||||
`;
|
`;
|
||||||
}
|
} else if (mode == "sheep" || mode == "admin") {
|
||||||
|
|
||||||
if (sheepName) {
|
|
||||||
sql = `
|
sql = `
|
||||||
SELECT DISTINCT
|
SELECT DISTINCT
|
||||||
house.*,
|
house.*,
|
||||||
@@ -108,7 +106,7 @@ class HousesService {
|
|||||||
WHERE
|
WHERE
|
||||||
entrance_history.working = 1
|
entrance_history.working = 1
|
||||||
AND
|
AND
|
||||||
entrance_history.name = '${sheepName}'
|
entrance_history.sheep_id = '${id}'
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,34 @@ const db = require("../config/db");
|
|||||||
class StandService {
|
class StandService {
|
||||||
getStand(id) {
|
getStand(id) {
|
||||||
return new Promise((res, rej) => {
|
return new Promise((res, rej) => {
|
||||||
return res({ id });
|
const sql = `SELECT * FROM stand_list WHERE id = ?`;
|
||||||
|
|
||||||
|
db.get(sql, [id], (err, row) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err.message);
|
||||||
|
return res(false);
|
||||||
|
}
|
||||||
|
if (!row) {
|
||||||
|
console.log({ error: "id not found" });
|
||||||
|
return res(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let data = {
|
||||||
|
"id": Number(row.id),
|
||||||
|
"title": row.title,
|
||||||
|
"geo": JSON.parse(row.geo),
|
||||||
|
"hour_start": Number(row.hour_start),
|
||||||
|
"hour_end": Number(row.hour_end),
|
||||||
|
"quantity_sheep": Number(row.quantity_sheep),
|
||||||
|
"week_days": JSON.parse(row.week_days),
|
||||||
|
"processing_time": Number(row.processing_time),
|
||||||
|
"status": row.status == 1 ? true : false,
|
||||||
|
"updated_at": Number(row.updated_at)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res(data);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,7 +233,7 @@ class StandService {
|
|||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
return res(false);
|
return res(false);
|
||||||
}
|
}
|
||||||
res({ status: "ok", inserted: list.length });
|
res({ status: "ok", inserted: list.length});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -214,9 +241,45 @@ class StandService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getScheduleList(data) {
|
getScheduleList(stand_id) {
|
||||||
return new Promise((res, rej) => {
|
return new Promise((res, rej) => {
|
||||||
return res({ data });
|
const sql = `
|
||||||
|
SELECT
|
||||||
|
ss.*,
|
||||||
|
s.name AS sheep_name
|
||||||
|
FROM
|
||||||
|
stand_schedule AS ss
|
||||||
|
LEFT JOIN
|
||||||
|
sheeps AS s
|
||||||
|
ON
|
||||||
|
s.id = ss.sheep_id
|
||||||
|
WHERE
|
||||||
|
ss.stand_id = ?
|
||||||
|
ORDER BY
|
||||||
|
ss.id;
|
||||||
|
`;
|
||||||
|
|
||||||
|
db.all(sql, [stand_id], (err, rows) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err.message);
|
||||||
|
return res(false);
|
||||||
|
} else {
|
||||||
|
let data = rows.map((row) => {
|
||||||
|
return {
|
||||||
|
"id": Number(row.id),
|
||||||
|
"stand_id": Number(row.stand_id),
|
||||||
|
"date": Number(row.date),
|
||||||
|
"hour": Number(row.hour),
|
||||||
|
"sheep_id": Number(row.sheep_id),
|
||||||
|
"sheep_name": row.sheep_name,
|
||||||
|
"number_sheep": Number(row.number_sheep),
|
||||||
|
"updated_at": Number(row.updated_at)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return res(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -412,7 +412,7 @@ body.modal-open {
|
|||||||
|
|
||||||
#update_banner .content {
|
#update_banner .content {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
max-width: 300px;
|
max-width: 340px;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
@@ -424,6 +424,8 @@ body.modal-open {
|
|||||||
font-size: var(--FontSize4);
|
font-size: var(--FontSize4);
|
||||||
color: var(--PrimaryColorText);
|
color: var(--PrimaryColorText);
|
||||||
font-family: 'Roboto', sans-serif;
|
font-family: 'Roboto', sans-serif;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
opacity: 0.9;
|
||||||
}
|
}
|
||||||
|
|
||||||
#update_banner .subhead {
|
#update_banner .subhead {
|
||||||
@@ -438,7 +440,7 @@ body.modal-open {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#update_banner[data-state="updateavailable"] {
|
#update_banner[data-state="updateavailable"] {
|
||||||
display: block;
|
display: flex;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
background-color: var(--PrimaryColor);
|
background-color: var(--PrimaryColor);
|
||||||
color: var(--PrimaryColorText);
|
color: var(--PrimaryColorText);
|
||||||
@@ -446,10 +448,10 @@ body.modal-open {
|
|||||||
opacity: 0.95;
|
opacity: 0.95;
|
||||||
z-index: 9999;
|
z-index: 9999;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
width: 300px;
|
width: 350px;
|
||||||
margin: 10px;
|
margin: 10px;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
border-radius: 25px;
|
border-radius: var(--border-radius);
|
||||||
right: 0;
|
right: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,8 @@
|
|||||||
|
|
||||||
<script src="/lib/components/turf.min.js" defer></script>
|
<script src="/lib/components/turf.min.js" defer></script>
|
||||||
|
|
||||||
|
<script src="/lib/components/cloud.js" defer></script>
|
||||||
|
|
||||||
<script src="/lib/components/clipboard.js" defer></script>
|
<script src="/lib/components/clipboard.js" defer></script>
|
||||||
<script src="/lib/components/colorGroup.js" defer></script>
|
<script src="/lib/components/colorGroup.js" defer></script>
|
||||||
<script src="/lib/components/makeid.js" defer></script>
|
<script src="/lib/components/makeid.js" defer></script>
|
||||||
@@ -103,6 +105,9 @@
|
|||||||
<script src="/lib/pages/stand/card/script.js" defer></script>
|
<script src="/lib/pages/stand/card/script.js" defer></script>
|
||||||
<link href="/lib/pages/stand/card/style.css" rel="stylesheet" />
|
<link href="/lib/pages/stand/card/style.css" rel="stylesheet" />
|
||||||
|
|
||||||
|
<script src="/lib/pages/stand/constructor/script.js" defer></script>
|
||||||
|
<link href="/lib/pages/stand/constructor/style.css" rel="stylesheet" />
|
||||||
|
|
||||||
<script src="/lib/pages/schedule/script.js" defer></script>
|
<script src="/lib/pages/schedule/script.js" defer></script>
|
||||||
<link href="/lib/pages/schedule/style.css" rel="stylesheet" />
|
<link href="/lib/pages/schedule/style.css" rel="stylesheet" />
|
||||||
|
|
||||||
@@ -266,7 +271,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<a href="/stand" data-route></a>
|
<a href="/stand" data-route></a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li id="li-options" style="display: none">
|
||||||
<div id="nav-options">
|
<div id="nav-options">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 172 172">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 172 172">
|
||||||
<path
|
<path
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
let USER = {};
|
let USER = {};
|
||||||
|
let swRegistration = null;
|
||||||
|
|
||||||
// Определение ID главного блока
|
// Определение ID главного блока
|
||||||
let app = document.getElementById('app');
|
let app = document.getElementById('app');
|
||||||
@@ -65,12 +66,16 @@ window.addEventListener('load', async function () {
|
|||||||
if (USER.possibilities.can_view_schedule) document.getElementById("li-schedule").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_manager_territory) document.getElementById("li-territory").style.display = "";
|
||||||
if (USER.possibilities.can_view_stand) document.getElementById("li-stand").style.display = "";
|
if (USER.possibilities.can_view_stand) document.getElementById("li-stand").style.display = "";
|
||||||
|
document.getElementById("li-options").style.display = "";
|
||||||
|
|
||||||
if (USER.possibilities.can_view_sheeps) await Sheeps.sheeps_list.loadAPI();
|
if (USER.possibilities.can_view_sheeps) await Sheeps.sheeps_list.loadAPI();
|
||||||
|
|
||||||
editFontStyle();
|
editFontStyle();
|
||||||
|
|
||||||
Router.check().listen().delegateLinks();
|
Router.check().listen().delegateLinks();
|
||||||
|
|
||||||
|
if (Cloud.socket) Cloud.socket.close(1000, "Перезапуск з'єднання");
|
||||||
|
Cloud.start();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -134,10 +139,10 @@ if (detectOS() == 'iOS' && !isInStandaloneMode()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener("beforeinstallprompt", (e) => {
|
window.addEventListener("beforeinstallprompt", (e) => {
|
||||||
|
if (localStorage.getItem('modal') != "false") {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
deferredPrompt = e;
|
deferredPrompt = e;
|
||||||
|
|
||||||
if (localStorage.getItem('modal') != "false") {
|
|
||||||
document.getElementById("blur-backdrop").classList.remove("pwa-hidden");
|
document.getElementById("blur-backdrop").classList.remove("pwa-hidden");
|
||||||
document.getElementById("pwa-install-overlay").classList.remove("pwa-hidden");
|
document.getElementById("pwa-install-overlay").classList.remove("pwa-hidden");
|
||||||
document.body.classList.add("modal-open");
|
document.body.classList.add("modal-open");
|
||||||
@@ -148,7 +153,7 @@ document.getElementById("pwa-install-button").addEventListener("click", async ()
|
|||||||
|
|
||||||
deferredPrompt.prompt();
|
deferredPrompt.prompt();
|
||||||
const { outcome } = await deferredPrompt.userChoice;
|
const { outcome } = await deferredPrompt.userChoice;
|
||||||
console.log(`PWA install result: ${outcome}`);
|
console.log(`Результат встановлення PWA: ${outcome}`);
|
||||||
|
|
||||||
closePopup();
|
closePopup();
|
||||||
});
|
});
|
||||||
@@ -166,10 +171,47 @@ function closePopup() {
|
|||||||
|
|
||||||
|
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
navigator.serviceWorker.register('sw.js')
|
let refreshing = false;
|
||||||
.then(() => {
|
|
||||||
console.log('Service Worker зарегистрирован');
|
const showUpdateBanner = sw => {
|
||||||
webPush.init();
|
const banner = document.getElementById('update_banner');
|
||||||
})
|
if (!banner) return;
|
||||||
.catch(err => console.error('Ошибка регистрации SW:', err));
|
|
||||||
|
banner.dataset.state = 'updateavailable';
|
||||||
|
banner.querySelector('.headline').textContent = 'Доступне оновлення';
|
||||||
|
banner.querySelector('.subhead').textContent = 'Натисніть, щоб оновити додаток до останньої версії!';
|
||||||
|
|
||||||
|
banner.addEventListener('click', () => {
|
||||||
|
banner.querySelector('.headline').textContent = '';
|
||||||
|
banner.querySelector('.subhead').textContent = '';
|
||||||
|
banner.querySelector('#update_banner_icon').style.display = 'block';
|
||||||
|
|
||||||
|
sw.postMessage('skipWaiting'); // активує новий SW
|
||||||
|
sw.postMessage('updateCache'); // оновлює кеш
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
navigator.serviceWorker.register('/sw.js').then(reg => {
|
||||||
|
// якщо є waiting SW, показуємо банер
|
||||||
|
if (reg.waiting) showUpdateBanner(reg.waiting);
|
||||||
|
|
||||||
|
// слідкуємо за новим воркером
|
||||||
|
reg.addEventListener('updatefound', () => {
|
||||||
|
const newWorker = reg.installing;
|
||||||
|
if (!newWorker) return;
|
||||||
|
|
||||||
|
newWorker.addEventListener('statechange', () => {
|
||||||
|
if (newWorker.state === 'installed' && reg.waiting) {
|
||||||
|
showUpdateBanner(reg.waiting); // лише показ банера
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
navigator.serviceWorker.addEventListener('controllerchange', () => {
|
||||||
|
if (refreshing) return;
|
||||||
|
refreshing = true;
|
||||||
|
window.location.reload(); // відбувається ТІЛЬКИ після skipWaiting
|
||||||
|
});
|
||||||
|
|
||||||
|
}).catch(err => console.error('Помилка реєстрації SW:', err));
|
||||||
}
|
}
|
||||||
95
web/lib/components/cloud.js
Normal file
95
web/lib/components/cloud.js
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
const Cloud = {
|
||||||
|
status: null,
|
||||||
|
socket: null,
|
||||||
|
reconnectTimeout: null,
|
||||||
|
reconnectAttempts: 0,
|
||||||
|
reconnecting: false,
|
||||||
|
|
||||||
|
start() {
|
||||||
|
Cloud.status = 'sync';
|
||||||
|
const uuid = localStorage.getItem("uuid");
|
||||||
|
|
||||||
|
if (Cloud.socket && Cloud.socket.readyState <= 1) return;
|
||||||
|
|
||||||
|
const ws = new WebSocket(CONFIG.wss, uuid);
|
||||||
|
Cloud.socket = ws;
|
||||||
|
|
||||||
|
ws.onopen = () => {
|
||||||
|
console.log("[WebSocket] З'єднання встановлено");
|
||||||
|
Cloud.status = 'ok';
|
||||||
|
ws.send(JSON.stringify({
|
||||||
|
event: 'connection',
|
||||||
|
user: {
|
||||||
|
name: USER.name,
|
||||||
|
id: USER.id
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
if(Cloud.reconnecting == true) {
|
||||||
|
Router.navigate(location.pathname);
|
||||||
|
}
|
||||||
|
|
||||||
|
Cloud.reconnecting = true;
|
||||||
|
Cloud.reconnectAttempts = 0;
|
||||||
|
clearTimeout(Cloud.reconnectTimeout);
|
||||||
|
};
|
||||||
|
|
||||||
|
ws.onmessage = (e) => {
|
||||||
|
const data = JSON.parse(e.data);
|
||||||
|
if (data.event === 'user_connected' && data.user.id !== USER.id) {
|
||||||
|
console.log(`Новий користувач: ${data.user.name}`);
|
||||||
|
}
|
||||||
|
if (data.event === 'message') {
|
||||||
|
switch (data.type) {
|
||||||
|
case "apartment":
|
||||||
|
Territory_card.cloud.update(data);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "building":
|
||||||
|
Territory_card.cloud.update(data);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "stand_locking":
|
||||||
|
case "stand_unlocking":
|
||||||
|
case "stand_update":
|
||||||
|
Stand_card.cloud.update(data);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ws.onclose = () => {
|
||||||
|
console.warn("[WebSocket] З'єднання розірвано");
|
||||||
|
Cloud.status = 'err';
|
||||||
|
|
||||||
|
if (!Cloud.reconnecting) return; // защита от дублирования
|
||||||
|
|
||||||
|
if (Cloud.reconnectAttempts < 5) {
|
||||||
|
Cloud.reconnectAttempts++;
|
||||||
|
console.log(`[WebSocket] Спроба перепідключення ${Cloud.reconnectAttempts}/5`);
|
||||||
|
|
||||||
|
Cloud.reconnectTimeout = setTimeout(() => {
|
||||||
|
Cloud.start();
|
||||||
|
}, 1000);
|
||||||
|
} else {
|
||||||
|
Cloud.reconnecting = false;
|
||||||
|
|
||||||
|
if (confirm("З'єднання розірвано! Перепідключитись?")) {
|
||||||
|
Cloud.reconnecting = true;
|
||||||
|
Cloud.reconnectAttempts = 0;
|
||||||
|
Cloud.start();
|
||||||
|
} else {
|
||||||
|
console.warn("[WebSocket] Перепідключення відмінено користувачем");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ws.onerror = (err) => {
|
||||||
|
console.error("[WebSocket] Помилка", err);
|
||||||
|
Cloud.status = 'err';
|
||||||
|
};
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -32,3 +32,11 @@ function getTimeInSeconds(time = Date.now()) {
|
|||||||
|
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formattedDayName(unix_timestamp) {
|
||||||
|
const date = new Date(unix_timestamp);
|
||||||
|
const daysOfWeekUA = ["Неділя", "Понеділок", "Вівторок", "Середа", "Четвер", "П'ятниця", "Субота"];
|
||||||
|
const dayNameUA = daysOfWeekUA[date.getDay()];
|
||||||
|
|
||||||
|
return dayNameUA;
|
||||||
|
}
|
||||||
@@ -2,12 +2,12 @@
|
|||||||
const webPush = {
|
const webPush = {
|
||||||
async init() {
|
async init() {
|
||||||
if (!('serviceWorker' in navigator) || !('PushManager' in window)) {
|
if (!('serviceWorker' in navigator) || !('PushManager' in window)) {
|
||||||
console.error('Push уведомления не поддерживаются');
|
console.error('Push повідомлення не підтримуються');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Получаем публичный ключ VAPID с сервера
|
// Отримуємо публічний ключ VAPID із сервера
|
||||||
const uuid = localStorage.getItem('uuid');
|
const uuid = localStorage.getItem('uuid');
|
||||||
const res = await fetch(`${CONFIG.api}push/key`, {
|
const res = await fetch(`${CONFIG.api}push/key`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@@ -18,7 +18,7 @@ const webPush = {
|
|||||||
});
|
});
|
||||||
const { publicKey } = await res.json();
|
const { publicKey } = await res.json();
|
||||||
|
|
||||||
// Преобразуем ключ
|
// Перетворюємо ключ
|
||||||
function urlBase64ToUint8Array(base64String) {
|
function urlBase64ToUint8Array(base64String) {
|
||||||
const padding = '='.repeat((4 - (base64String.length % 4)) % 4);
|
const padding = '='.repeat((4 - (base64String.length % 4)) % 4);
|
||||||
const base64 = (base64String + padding).replace(/-/g, '+').replace(/_/g, '/');
|
const base64 = (base64String + padding).replace(/-/g, '+').replace(/_/g, '/');
|
||||||
@@ -26,34 +26,34 @@ const webPush = {
|
|||||||
return Uint8Array.from([...raw].map(ch => ch.charCodeAt(0)));
|
return Uint8Array.from([...raw].map(ch => ch.charCodeAt(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Берем уже зарегистрированный Service Worker
|
// Беремо вже зареєстрований Service Worker
|
||||||
const registration = await navigator.serviceWorker.ready;
|
const registration = await navigator.serviceWorker.ready;
|
||||||
|
|
||||||
// Проверяем, есть ли уже подписка
|
// Перевіряємо, чи є підписка
|
||||||
let subscription = await registration.pushManager.getSubscription();
|
let subscription = await registration.pushManager.getSubscription();
|
||||||
|
|
||||||
if (!subscription) {
|
if (!subscription) {
|
||||||
|
|
||||||
// Запрашиваем разрешение
|
// Запитуємо дозвіл
|
||||||
const permission = await Notification.requestPermission();
|
const permission = await Notification.requestPermission();
|
||||||
if (permission !== 'granted') {
|
if (permission !== 'granted') {
|
||||||
console.warn('Пуш уведомления запрещены пользователем');
|
console.warn('Push повідомлення заборонено користувачем');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Подписка на push
|
// Підписка на push
|
||||||
subscription = await registration.pushManager.subscribe({
|
subscription = await registration.pushManager.subscribe({
|
||||||
userVisibleOnly: true,
|
userVisibleOnly: true,
|
||||||
applicationServerKey: urlBase64ToUint8Array(publicKey)
|
applicationServerKey: urlBase64ToUint8Array(publicKey)
|
||||||
});
|
});
|
||||||
|
|
||||||
// данные устройства
|
// дані пристроя
|
||||||
const deviceInfo = {
|
const deviceInfo = {
|
||||||
name: navigator.userAgent,
|
name: navigator.userAgent,
|
||||||
model: navigator.platform || "unknown"
|
model: navigator.platform || "unknown"
|
||||||
};
|
};
|
||||||
|
|
||||||
// Отправка на сервер
|
// Надсилання на сервер
|
||||||
await fetch(`${CONFIG.api}push/subscribe`, {
|
await fetch(`${CONFIG.api}push/subscribe`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -63,15 +63,15 @@ const webPush = {
|
|||||||
body: JSON.stringify({ subscription, device: deviceInfo })
|
body: JSON.stringify({ subscription, device: deviceInfo })
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Push подписка готова:', subscription);
|
console.log('Push підписка готова:', subscription);
|
||||||
|
|
||||||
console.log('Создана новая подписка');
|
console.log('Створено нову підписку');
|
||||||
} else {
|
} else {
|
||||||
console.log('Подписка уже существует');
|
console.log('Підписка вже існує');
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Ошибка инициализации push:', err);
|
console.error('Помилка ініціалізації push:', err);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -81,13 +81,13 @@ const webPush = {
|
|||||||
const subscription = await registration.pushManager.getSubscription();
|
const subscription = await registration.pushManager.getSubscription();
|
||||||
|
|
||||||
if (subscription) {
|
if (subscription) {
|
||||||
// удаляем подписку в браузере
|
// видаляємо підписку у браузері
|
||||||
const success = await subscription.unsubscribe();
|
const success = await subscription.unsubscribe();
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
console.log("Локальная подписка отменена");
|
console.log("Локальна підписка скасована");
|
||||||
|
|
||||||
// уведомляем сервер
|
// повідомляємо сервер
|
||||||
await fetch(`${CONFIG.api}push//unsubscribe`, {
|
await fetch(`${CONFIG.api}push//unsubscribe`, {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -98,7 +98,7 @@ const webPush = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("Подписки нет");
|
console.log("Підписки немає");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,9 @@ const Auth = {
|
|||||||
if (USER.possibilities.can_add_schedule) document.getElementById("li-schedule").style.display = "";
|
if (USER.possibilities.can_add_schedule) document.getElementById("li-schedule").style.display = "";
|
||||||
if (USER.possibilities.can_manager_territory) document.getElementById("li-territory").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 = "";
|
if (USER.possibilities.can_view_stand) document.getElementById("li-stand").style.display = "";
|
||||||
|
document.getElementById("li-options").style.display = "";
|
||||||
|
|
||||||
|
Cloud.start();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,4 +17,6 @@
|
|||||||
<option value="large">Великий</option>
|
<option value="large">Великий</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<button onclick="Options.logout()">Вийти з облікового запису</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
const Options = {
|
const Options = {
|
||||||
init: async () => {
|
async init() {
|
||||||
let html = await fetch('/lib/pages/options/index.html').then((response) => response.text());
|
let html = await fetch('/lib/pages/options/index.html').then((response) => response.text());
|
||||||
app.innerHTML = html;
|
app.innerHTML = html;
|
||||||
|
|
||||||
await Options.optionPush.init();
|
await Options.optionPush.init();
|
||||||
Options.optionFont.init();
|
Options.optionFont.init();
|
||||||
},
|
},
|
||||||
|
|
||||||
optionPush: {
|
optionPush: {
|
||||||
init: async () => {
|
async init() {
|
||||||
const element = document.getElementById("page-options-notifications");
|
const element = document.getElementById("page-options-notifications");
|
||||||
const permission = await Notification.requestPermission();
|
const permission = await Notification.requestPermission();
|
||||||
|
|
||||||
@@ -25,7 +26,8 @@ const Options = {
|
|||||||
element.checked = false;
|
element.checked = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
edit: (state) => {
|
|
||||||
|
edit(state) {
|
||||||
if (state) {
|
if (state) {
|
||||||
webPush.init();
|
webPush.init();
|
||||||
} else {
|
} else {
|
||||||
@@ -33,8 +35,9 @@ const Options = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
optionFont: {
|
optionFont: {
|
||||||
init: () => {
|
init() {
|
||||||
const element = document.getElementById("page-options-fontSize");
|
const element = document.getElementById("page-options-fontSize");
|
||||||
|
|
||||||
let fontSize = localStorage.getItem("fontSize")
|
let fontSize = localStorage.getItem("fontSize")
|
||||||
@@ -43,9 +46,15 @@ const Options = {
|
|||||||
|
|
||||||
element.value = fontSize;
|
element.value = fontSize;
|
||||||
},
|
},
|
||||||
edit: (mode) => {
|
|
||||||
|
edit(mode) {
|
||||||
localStorage.setItem("fontSize", mode);
|
localStorage.setItem("fontSize", mode);
|
||||||
applyFontMode(mode);
|
applyFontMode(mode);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
logout() {
|
||||||
|
localStorage.removeItem("uuid");
|
||||||
|
window.location.reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,3 +54,15 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
margin: 5px 0;
|
margin: 5px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.page-options>button {
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
background: var(--PrimaryColor);
|
||||||
|
color: var(--PrimaryColorText);
|
||||||
|
width: 100%;
|
||||||
|
height: 40px;
|
||||||
|
font-size: var(--FontSize3);
|
||||||
|
font-weight: 400;
|
||||||
|
margin: 20px 0;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
@@ -27,12 +27,11 @@ let Sheeps_icon = [
|
|||||||
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><path d="M 14 12 C 12.896 12 12 12.896 12 14 C 12 15.104 12.896 16 14 16 L 15.492188 16 C 11.397556 20.243092 9 25.992059 9 32 C 9 39.62 12.760547 46.729531 19.060547 51.019531 C 20.970547 52.319531 23.249688 53 25.679688 53 L 38.330078 53 C 40.750078 53 43.039219 52.309766 44.949219 51.009766 C 51.239219 46.719766 55 39.62 55 32 C 55 25.992059 52.602444 20.243092 48.507812 16 L 50 16 C 51.104 16 52 15.104 52 14 C 52 12.896 51.104 12 50 12 L 14 12 z M 21.75 16 L 42.25 16 C 44.971669 17.740083 47.142531 20.078247 48.642578 22.791016 L 46.380859 23.695312 C 42.871859 25.098312 38.961906 25.213578 35.378906 24.017578 L 29.582031 22.085938 C 25.319031 20.664938 20.646828 20.726672 16.423828 22.263672 L 15.460938 22.613281 C 16.956883 19.976859 19.088528 17.701597 21.75 16 z M 23.042969 25.064453 C 24.826219 25.040328 26.612906 25.312359 28.316406 25.880859 L 34.113281 27.8125 C 36.165281 28.4965 38.300547 28.837891 40.435547 28.837891 C 42.961547 28.837891 45.486234 28.358203 47.865234 27.408203 L 50.1875 26.480469 C 50.715092 28.239658 51 30.092368 51 32 C 51 38.29 47.899219 44.170938 42.699219 47.710938 C 41.459219 48.550938 39.950078 49 38.330078 49 L 25.679688 49 C 24.059687 49 22.550547 48.560938 21.310547 47.710938 C 16.110547 44.170938 13 38.3 13 32 C 13 30.484897 13.183421 29.005425 13.519531 27.578125 L 17.791016 26.023438 C 19.480516 25.409438 21.259719 25.088578 23.042969 25.064453 z M 34.5 32 C 31.548188 32 29.139763 33.869393 27.722656 35.292969 L 25.199219 33.400391 C 24.469219 32.852391 23.464953 32.8685 22.751953 33.4375 C 22.039953 34.0065 21.802781 34.986359 22.175781 35.818359 C 22.537781 36.624359 22.900281 37.607 22.988281 38 C 22.901281 38.393 22.537781 39.375641 22.175781 40.181641 C 21.802781 41.013641 22.039953 41.9935 22.751953 42.5625 C 23.116953 42.8545 23.558 43 24 43 C 24.422 43 24.843219 42.866609 25.199219 42.599609 L 27.722656 40.707031 C 29.139763 42.130607 31.548188 44 34.5 44 C 38.979 44 42.258187 39.670734 42.617188 39.177734 C 43.128188 38.475734 43.128188 37.524266 42.617188 36.822266 C 42.258188 36.329266 38.979 32 34.5 32 z M 34.5 36 C 35.908 36 37.346078 37.048 38.330078 38 C 37.345078 38.953 35.908 40 34.5 40 C 33.092 40 31.655922 38.953 30.669922 38 C 31.655922 37.047 33.092 36 34.5 36 z"/></svg>'
|
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><path d="M 14 12 C 12.896 12 12 12.896 12 14 C 12 15.104 12.896 16 14 16 L 15.492188 16 C 11.397556 20.243092 9 25.992059 9 32 C 9 39.62 12.760547 46.729531 19.060547 51.019531 C 20.970547 52.319531 23.249688 53 25.679688 53 L 38.330078 53 C 40.750078 53 43.039219 52.309766 44.949219 51.009766 C 51.239219 46.719766 55 39.62 55 32 C 55 25.992059 52.602444 20.243092 48.507812 16 L 50 16 C 51.104 16 52 15.104 52 14 C 52 12.896 51.104 12 50 12 L 14 12 z M 21.75 16 L 42.25 16 C 44.971669 17.740083 47.142531 20.078247 48.642578 22.791016 L 46.380859 23.695312 C 42.871859 25.098312 38.961906 25.213578 35.378906 24.017578 L 29.582031 22.085938 C 25.319031 20.664938 20.646828 20.726672 16.423828 22.263672 L 15.460938 22.613281 C 16.956883 19.976859 19.088528 17.701597 21.75 16 z M 23.042969 25.064453 C 24.826219 25.040328 26.612906 25.312359 28.316406 25.880859 L 34.113281 27.8125 C 36.165281 28.4965 38.300547 28.837891 40.435547 28.837891 C 42.961547 28.837891 45.486234 28.358203 47.865234 27.408203 L 50.1875 26.480469 C 50.715092 28.239658 51 30.092368 51 32 C 51 38.29 47.899219 44.170938 42.699219 47.710938 C 41.459219 48.550938 39.950078 49 38.330078 49 L 25.679688 49 C 24.059687 49 22.550547 48.560938 21.310547 47.710938 C 16.110547 44.170938 13 38.3 13 32 C 13 30.484897 13.183421 29.005425 13.519531 27.578125 L 17.791016 26.023438 C 19.480516 25.409438 21.259719 25.088578 23.042969 25.064453 z M 34.5 32 C 31.548188 32 29.139763 33.869393 27.722656 35.292969 L 25.199219 33.400391 C 24.469219 32.852391 23.464953 32.8685 22.751953 33.4375 C 22.039953 34.0065 21.802781 34.986359 22.175781 35.818359 C 22.537781 36.624359 22.900281 37.607 22.988281 38 C 22.901281 38.393 22.537781 39.375641 22.175781 40.181641 C 21.802781 41.013641 22.039953 41.9935 22.751953 42.5625 C 23.116953 42.8545 23.558 43 24 43 C 24.422 43 24.843219 42.866609 25.199219 42.599609 L 27.722656 40.707031 C 29.139763 42.130607 31.548188 44 34.5 44 C 38.979 44 42.258187 39.670734 42.617188 39.177734 C 43.128188 38.475734 43.128188 37.524266 42.617188 36.822266 C 42.258188 36.329266 38.979 32 34.5 32 z M 34.5 36 C 35.908 36 37.346078 37.048 38.330078 38 C 37.345078 38.953 35.908 40 34.5 40 C 33.092 40 31.655922 38.953 30.669922 38 C 31.655922 37.047 33.092 36 34.5 36 z"/></svg>'
|
||||||
]
|
]
|
||||||
|
|
||||||
const SheepsEvents = (() => {
|
const SheepsEvents = {
|
||||||
let initialized = false;
|
initialized: false,
|
||||||
|
|
||||||
return {
|
init() {
|
||||||
init: () => {
|
if (this.initialized) return;
|
||||||
if (initialized) return;
|
|
||||||
|
|
||||||
const sheepEditorForm = document.getElementById("sheep-editor");
|
const sheepEditorForm = document.getElementById("sheep-editor");
|
||||||
const sheepEditorButton = document.getElementById('sheep-editor-button');
|
const sheepEditorButton = document.getElementById('sheep-editor-button');
|
||||||
@@ -139,7 +138,7 @@ const SheepsEvents = (() => {
|
|||||||
const randomNumber = Math.floor(Math.random() * Sheeps_icon.length);
|
const randomNumber = Math.floor(Math.random() * Sheeps_icon.length);
|
||||||
|
|
||||||
Sheeps.addeds.close();
|
Sheeps.addeds.close();
|
||||||
await Sheeps.editor.setHTML(data.uuid, randomNumber);
|
await Sheeps.editor.setHTML(data.id, randomNumber);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
sheepAddedsButton.innerText = "Додати";
|
sheepAddedsButton.innerText = "Додати";
|
||||||
@@ -154,17 +153,16 @@ const SheepsEvents = (() => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
initialized = true;
|
this.initialized = true;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
})();
|
|
||||||
|
|
||||||
const Sheeps = {
|
const Sheeps = {
|
||||||
init: async (id) => {
|
init: async (id) => {
|
||||||
let html = await fetch('/lib/pages/sheeps/index.html').then((response) => response.text());
|
let html = await fetch('/lib/pages/sheeps/index.html').then((response) => response.text());
|
||||||
app.innerHTML = html;
|
app.innerHTML = html;
|
||||||
|
|
||||||
Sheeps.sheeps_list.setHTML();
|
await Sheeps.sheeps_list.setHTML();
|
||||||
if (id) Sheeps.editor.setHTML(id);
|
if (id) Sheeps.editor.setHTML(id);
|
||||||
|
|
||||||
SheepsEvents.init();
|
SheepsEvents.init();
|
||||||
@@ -196,6 +194,8 @@ const Sheeps = {
|
|||||||
? Sheeps.sheeps_list.list
|
? Sheeps.sheeps_list.list
|
||||||
: await Sheeps.sheeps_list.loadAPI();
|
: await Sheeps.sheeps_list.loadAPI();
|
||||||
|
|
||||||
|
Sheeps.sheeps_list.list.sort((a, b) => a.group_id - b.group_id);
|
||||||
|
|
||||||
let block_sheeps = document.getElementById('block-sheeps-list');
|
let block_sheeps = document.getElementById('block-sheeps-list');
|
||||||
|
|
||||||
let butt_add = USER.possibilities.can_add_sheeps ? `
|
let butt_add = USER.possibilities.can_add_sheeps ? `
|
||||||
@@ -386,11 +386,13 @@ const Sheeps = {
|
|||||||
sheep_editor_can_view_territory.checked = sheep.possibilities.can_view_territory;
|
sheep_editor_can_view_territory.checked = sheep.possibilities.can_view_territory;
|
||||||
|
|
||||||
if (USER.possibilities.can_manager_territory) {
|
if (USER.possibilities.can_manager_territory) {
|
||||||
document.getElementById('editor-blocks-territory').style.display = "";
|
document.getElementById('editor-blocks-territory').style.display = "none";
|
||||||
|
document.getElementById(`editor-blocks-territory`).innerHTML = "<summary>Території вісника</summary>";
|
||||||
|
Sheeps.territory.house(id);
|
||||||
|
Sheeps.territory.homestead(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (USER.mode == 2) {
|
if (USER.mode == 2) {
|
||||||
document.getElementById('editor-blocks-territory').style.display = "";
|
|
||||||
document.getElementById('sheep-editor-button').style.display = "";
|
document.getElementById('sheep-editor-button').style.display = "";
|
||||||
sheep_editor_mode.disabled = false;
|
sheep_editor_mode.disabled = false;
|
||||||
} else {
|
} else {
|
||||||
@@ -462,5 +464,69 @@ const Sheeps = {
|
|||||||
search_value = value?.trim()?.toLowerCase() || "";
|
search_value = value?.trim()?.toLowerCase() || "";
|
||||||
Sheeps.sheeps_list.setHTML(search_value);
|
Sheeps.sheeps_list.setHTML(search_value);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
territory: {
|
||||||
|
async loadAPI(URL) {
|
||||||
|
const uuid = localStorage.getItem("uuid");
|
||||||
|
const res = await fetch(URL, {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": uuid
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return await res.json();
|
||||||
|
},
|
||||||
|
|
||||||
|
async house(id) {
|
||||||
|
const URL = `${CONFIG.api}house/list?mode=admin&sheep_id=${id}`;
|
||||||
|
const list = await Sheeps.territory.loadAPI(URL);
|
||||||
|
|
||||||
|
if ((USER.possibilities.can_view_territory || USER.mode == 2) && list.length > 0){
|
||||||
|
document.getElementById('editor-blocks-territory').style.display = "";
|
||||||
|
Sheeps.territory.renderCards(list, "house");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async homestead(id) {
|
||||||
|
const URL = `${CONFIG.api}homestead/list?mode=admin&sheep_id=${id}`;
|
||||||
|
const list = await Sheeps.territory.loadAPI(URL);
|
||||||
|
|
||||||
|
if ((USER.possibilities.can_view_territory || USER.mode == 2) && list.length > 0){
|
||||||
|
document.getElementById('editor-blocks-territory').style.display = "";
|
||||||
|
Sheeps.territory.renderCards(list, "homestead");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
renderCards: (list, type) => {
|
||||||
|
const container = document.getElementById(`editor-blocks-territory`);
|
||||||
|
const fragment = document.createDocumentFragment();
|
||||||
|
|
||||||
|
for (const el of list) {
|
||||||
|
const card = document.createElement("div");
|
||||||
|
card.innerHTML = `
|
||||||
|
<div id="title">
|
||||||
|
<h1>${el.title} ${el.number}</h1>
|
||||||
|
|
||||||
|
<a href="/territory/manager/${type}/${el.id}" title="Редактор квартир" data-route>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 30">
|
||||||
|
<path d="M24 2H14c-.55 0-1 .45-1 1v4l3.6 2.7c.25.19.4.49.4.8V14h8V3C25 2.45 24.55 2 24 2zM15.5 7C15.22 7 15 6.78 15 6.5v-2C15 4.22 15.22 4 15.5 4h2C17.78 4 18 4.22 18 4.5v2C18 6.78 17.78 7 17.5 7h-1.17H15.5zM23 4.5v2C23 6.78 22.78 7 22.5 7h-2C20.22 7 20 6.78 20 6.5v-2C20 4.22 20.22 4 20.5 4h2C22.78 4 23 4.22 23 4.5zM22.5 12h-2c-.28 0-.5-.22-.5-.5v-2C20 9.22 20.22 9 20.5 9h2C22.78 9 23 9.22 23 9.5v2C23 11.78 22.78 12 22.5 12zM1 11.51V27c0 .55.45 1 1 1h12c.55 0 1-.45 1-1V11.51c0-.32-.16-.62-.42-.81l-6-4.28C8.41 6.29 8.2 6.23 8 6.23S7.59 6.29 7.42 6.42l-6 4.28C1.16 10.89 1 11.19 1 11.51zM6.5 20h-2C4.22 20 4 19.78 4 19.5v-2C4 17.22 4.22 17 4.5 17h2C6.78 17 7 17.22 7 17.5v2C7 19.78 6.78 20 6.5 20zM7 22.5v2C7 24.78 6.78 25 6.5 25h-2C4.22 25 4 24.78 4 24.5v-2C4 22.22 4.22 22 4.5 22h2C6.78 22 7 22.22 7 22.5zM6.5 15h-2C4.22 15 4 14.78 4 14.5v-2C4 12.22 4.22 12 4.5 12h2C6.78 12 7 12.22 7 12.5v2C7 14.78 6.78 15 6.5 15zM9.5 17h2c.28 0 .5.22.5.5v2c0 .28-.22.5-.5.5h-2C9.22 20 9 19.78 9 19.5v-2C9 17.22 9.22 17 9.5 17zM9 14.5v-2C9 12.22 9.22 12 9.5 12h2c.28 0 .5.22.5.5v2c0 .28-.22.5-.5.5h-2C9.22 15 9 14.78 9 14.5zM9.5 22h2c.28 0 .5.22.5.5v2c0 .28-.22.5-.5.5h-2C9.22 25 9 24.78 9 24.5v-2C9 22.22 9.22 22 9.5 22zM17 17v10c0 .55.45 1 1 1h10c.55 0 1-.45 1-1V17c0-.55-.45-1-1-1H18C17.45 16 17 16.45 17 17zM19.5 18h2c.28 0 .5.22.5.5v2c0 .28-.22.5-.5.5h-2c-.28 0-.5-.22-.5-.5v-2C19 18.22 19.22 18 19.5 18zM27 18.5v2c0 .28-.22.5-.5.5h-2c-.28 0-.5-.22-.5-.5v-2c0-.28.22-.5.5-.5h2C26.78 18 27 18.22 27 18.5zM26.5 26h-2c-.28 0-.5-.22-.5-.5v-2c0-.28.22-.5.5-.5h2c.28 0 .5.22.5.5v2C27 25.78 26.78 26 26.5 26zM19.5 23h2c.28 0 .5.22.5.5v2c0 .28-.22.5-.5.5h-2c-.28 0-.5-.22-.5-.5v-2C19 23.22 19.22 23 19.5 23z"></path>
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<!--
|
||||||
|
<div>
|
||||||
|
<h1>Територія видана:</h1>
|
||||||
|
<h2>02.07.2025</h2>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h1>Варто забрати:</h1>
|
||||||
|
<h2>01.11.2025</h2>
|
||||||
|
</div> -->
|
||||||
|
`;
|
||||||
|
fragment.appendChild(card);
|
||||||
|
}
|
||||||
|
|
||||||
|
container.appendChild(fragment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -552,7 +552,7 @@
|
|||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
margin: 10px;
|
margin: 10px;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
min-height: 100px;
|
min-height: 30px;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
position: relative;
|
position: relative;
|
||||||
border-radius: calc(var(--border-radius) - 5px - 6px);
|
border-radius: calc(var(--border-radius) - 5px - 6px);
|
||||||
@@ -562,7 +562,7 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
height: 30px;
|
height: 30px;
|
||||||
margin-bottom: 10px;
|
/* margin-bottom: 10px; */
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -595,14 +595,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#editor-blocks-territory>div>#title>a>svg {
|
#editor-blocks-territory>div>#title>a>svg {
|
||||||
width: 25px;
|
width: 20px;
|
||||||
height: 25px;
|
height: 20px;
|
||||||
fill: var(--PrimaryColorText);
|
fill: var(--PrimaryColorText);
|
||||||
}
|
}
|
||||||
|
|
||||||
#editor-blocks-territory>div>div {
|
#editor-blocks-territory>div>div {
|
||||||
display: flex;
|
display: flex;
|
||||||
margin-bottom: 10px;
|
/* margin-bottom: 10px; */
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
@@ -6,277 +6,14 @@
|
|||||||
<summary>Інформація про стенд</summary>
|
<summary>Інформація про стенд</summary>
|
||||||
<div>
|
<div>
|
||||||
<span>Розташування:</span>
|
<span>Розташування:</span>
|
||||||
<p id="stand-info-title">Тест</p>
|
<p id="stand-info-title">--</p>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<span>Геолокація:</span>
|
<span>Геолокація:</span>
|
||||||
<p id="stand-info-geo"></p>
|
<a id="stand-info-geo">--</a>
|
||||||
</div>
|
</div>
|
||||||
<img id="stand-info-image" src="" />
|
<img id="stand-info-image" src="" />
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
<div id="stand-schedule">
|
<div id="stand-schedule"></div>
|
||||||
<!-- <div class="block-day" id="day-0">
|
|
||||||
<h3>08.08.2025 • Пʼятниця</h3>
|
|
||||||
<div>
|
|
||||||
<span id="time">09:00-10:00</span>
|
|
||||||
<select id="name_1">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_2">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_3">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<span id="time">10:00-11:00</span>
|
|
||||||
<select id="name_1">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_2">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_3">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<span id="time">11:00-12:00</span>
|
|
||||||
<select id="name_1">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_2">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_3">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<span id="time">12:00-13:00</span>
|
|
||||||
<select id="name_1">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_2">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_3">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<span id="time">14:00-15:00</span>
|
|
||||||
<select id="name_1">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_2">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_3">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<span id="time">15:00-16:00</span>
|
|
||||||
<select id="name_1">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_2">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_3">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<span id="time">16:00-17:00</span>
|
|
||||||
<select id="name_1">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_2">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_3">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<span id="time">17:00-18:00</span>
|
|
||||||
<select id="name_1">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_2">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_3">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="block-day" id="day-1">
|
|
||||||
<h3>11.08.2025 • Понеділок</h3>
|
|
||||||
<div>
|
|
||||||
<span id="time">09:00-10:00</span>
|
|
||||||
<select id="name_1">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_2">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_3">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<span id="time">10:00-11:00</span>
|
|
||||||
<select id="name_1">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_2">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_3">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<span id="time">11:00-12:00</span>
|
|
||||||
<select id="name_1">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_2">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_3">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<span id="time">12:00-13:00</span>
|
|
||||||
<select id="name_1">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_2">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_3">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<span id="time">14:00-15:00</span>
|
|
||||||
<select id="name_1">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_2">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_3">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<span id="time">15:00-16:00</span>
|
|
||||||
<select id="name_1">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_2">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_3">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<span id="time">16:00-17:00</span>
|
|
||||||
<select id="name_1">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_2">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_3">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<span id="time">17:00-18:00</span>
|
|
||||||
<select id="name_1">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_2">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
<select id="name_3">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div> -->
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,123 +1,541 @@
|
|||||||
const Stand_card = {
|
const Stand_card = {
|
||||||
schedule: [],
|
id: null,
|
||||||
init: async (id) => {
|
async init(id) {
|
||||||
let html = await fetch('/lib/pages/stand/card/index.html').then((response) => response.text());
|
let html = await fetch('/lib/pages/stand/card/index.html').then((response) => response.text());
|
||||||
app.innerHTML = html;
|
app.innerHTML = html;
|
||||||
|
|
||||||
let listDate = [1, 4];
|
Stand_card.id = id;
|
||||||
|
|
||||||
function generateAvailableDates() {
|
this.info.setHTML();
|
||||||
let select = document.getElementById("dateSelect");
|
|
||||||
select.innerHTML = "";
|
|
||||||
|
|
||||||
let today = new Date();
|
|
||||||
today.setHours(0, 0, 0, 0);
|
|
||||||
let months = [today.getMonth(), today.getMonth() + 1];
|
|
||||||
let year = today.getFullYear();
|
|
||||||
|
|
||||||
months.forEach(month => {
|
|
||||||
let date = new Date(year, month, 1);
|
|
||||||
while (date.getMonth() === month) {
|
|
||||||
if (date >= today) {
|
|
||||||
let day = date.getDay();
|
|
||||||
if (listDate.includes(day)) {
|
|
||||||
let option = document.createElement("option");
|
|
||||||
option.value = date.toISOString().split("T")[0];
|
|
||||||
option.textContent = date.toLocaleDateString("uk-UA", {
|
|
||||||
weekday: "long", year: "numeric", month: "long", day: "numeric"
|
|
||||||
});
|
|
||||||
select.appendChild(option);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
date.setDate(date.getDate() + 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// generateAvailableDates();
|
|
||||||
Stand_card.generator();
|
|
||||||
},
|
},
|
||||||
generator: () => {
|
|
||||||
let block_schedule = document.getElementById('stand-schedule');
|
|
||||||
|
|
||||||
let html = "";
|
async loadAPI(url) {
|
||||||
|
const uuid = localStorage.getItem("uuid");
|
||||||
|
const response = await fetch(url, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": uuid
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return await response.json();
|
||||||
|
},
|
||||||
|
|
||||||
let stand = {
|
info: {
|
||||||
id: 1,
|
list: [],
|
||||||
title: "Універсам",
|
|
||||||
geo: { lat: 0, lng: 0 },
|
async setHTML() {
|
||||||
hour_start: 9,
|
const url = `${CONFIG.api}stand/${Stand_card.id}`;
|
||||||
hour_end: 14,
|
this.list = await Stand_card.loadAPI(url);
|
||||||
quantity_sheep: 2,
|
|
||||||
week_days: [0, 2, 4, 6],
|
document.getElementById('stand-info-title').innerText = this.list.title;
|
||||||
processing_time: 0.5,
|
document.getElementById('stand-info-geo').innerHTML = 'Відкрити Google Maps';
|
||||||
updated_at: null
|
document.getElementById('stand-info-geo').href = `https://www.google.com/maps?q=${this.list.geo[0]},${this.list.geo[1]}`;
|
||||||
|
document.getElementById('stand-info-image').setAttribute('src', '');
|
||||||
|
|
||||||
|
Stand_card.schedule.setHTML();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Робота з WebSocket
|
||||||
|
cloud: {
|
||||||
|
update(msg) {
|
||||||
|
const { type, data, user } = msg;
|
||||||
|
const el = document.getElementById(`name-${data?.id}`);
|
||||||
|
if (!el) return; // если элемент не найден — выходим
|
||||||
|
|
||||||
|
const isSelf = user.id == USER.id;
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case "stand_locking":
|
||||||
|
if (!isSelf) {
|
||||||
|
el.disabled = true;
|
||||||
|
el.style.border = "2px solid var(--PrimaryColor)";
|
||||||
|
el.style.backgroundColor = "#EAFF0024";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "stand_unlocking":
|
||||||
|
// Разблокируем только если событие от другого пользователя
|
||||||
|
if (!isSelf) {
|
||||||
|
el.style.border = "";
|
||||||
|
el.style.backgroundColor = "";
|
||||||
|
}
|
||||||
|
if ((!isSelf && !el.value) || USER.possibilities.can_manager_stand) {
|
||||||
|
el.removeAttribute("disabled");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "stand_update": {
|
||||||
|
const sid = data.sheep_id;
|
||||||
|
const sname = data.sheep_name ?? "";
|
||||||
|
|
||||||
|
// Менеджеру показываем весь список
|
||||||
|
if (USER.possibilities.can_manager_stand && Array.isArray(Sheeps?.sheeps_list?.list)) {
|
||||||
|
el.innerHTML = "";
|
||||||
|
|
||||||
|
// пустой вариант
|
||||||
|
el.appendChild(Object.assign(document.createElement("option"), {
|
||||||
|
value: "",
|
||||||
|
textContent: " "
|
||||||
|
}));
|
||||||
|
|
||||||
|
// заполняем всех овечек
|
||||||
|
Sheeps.sheeps_list.list.forEach(s => {
|
||||||
|
const opt = document.createElement("option");
|
||||||
|
opt.value = s.id;
|
||||||
|
opt.textContent = s.name;
|
||||||
|
if (s.id == sid) opt.selected = true;
|
||||||
|
el.appendChild(opt);
|
||||||
|
});
|
||||||
|
|
||||||
|
el.removeAttribute("disabled");
|
||||||
|
} else {
|
||||||
|
// Обычное поведение для обычных пользователей
|
||||||
|
if (sid == USER.id) {
|
||||||
|
el.innerHTML = `<option value=""></option><option selected value="${USER.id}">${USER.name}</option>`;
|
||||||
|
el.removeAttribute("disabled");
|
||||||
|
} else if (!sid) {
|
||||||
|
el.innerHTML = `<option value=""></option><option value="${USER.id}">${USER.name}</option>`;
|
||||||
|
el.removeAttribute("disabled");
|
||||||
|
} else {
|
||||||
|
el.innerHTML = `<option value="${sid}">${sname}</option>`;
|
||||||
|
el.disabled = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Stand_card.schedule = [];
|
el.style.border = "";
|
||||||
|
el.style.backgroundColor = "";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Кількість годин служіння
|
default:
|
||||||
let stand_length = (stand.hour_end - stand.hour_start) / stand.processing_time;
|
return;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
for (let z = 0; z < stand.week_days.length; z++) {
|
// update(msg) {
|
||||||
Stand_card.schedule.push([]);
|
// console.log(msg.type, msg.data.id);
|
||||||
|
|
||||||
let date = new Date();
|
// if (msg.type == "stand_locking") {
|
||||||
date.setDate(date.getDate() + stand.week_days[z]);
|
// const id = msg.data.id;
|
||||||
let dayName = date.toLocaleDateString('uk-UA', { weekday: 'long' });
|
// const el = document.getElementById(`name-${id}`);
|
||||||
|
|
||||||
html += `
|
// if (msg.user.id != USER.id) {
|
||||||
<div class="block-day" id="day-${z}">
|
// el.disabled = true;
|
||||||
<h3>${date.toLocaleDateString()} • ${dayName}</h3>
|
// el.style.border = "2px solid var(--PrimaryColor);"
|
||||||
`;
|
// el.style.backgroundColor = "red"
|
||||||
|
// }
|
||||||
|
// } else if (msg.type == "stand_unlocking") {
|
||||||
|
// const id = msg.data.id;
|
||||||
|
// const el = document.getElementById(`name-${id}`);
|
||||||
|
// if (msg.user.id != USER.id || !msg.data.sheep_id) {
|
||||||
|
// el.style.border = "";
|
||||||
|
// el.style.backgroundColor = ""
|
||||||
|
// el.removeAttribute('disabled');
|
||||||
|
// }
|
||||||
|
// } else if (msg.type == "stand_update") {
|
||||||
|
// const id = msg.data.id;
|
||||||
|
// const el = document.getElementById(`name-${id}`);
|
||||||
|
// if (msg.data.sheep_id == USER.id) {
|
||||||
|
// el.innerHTML = `<option value=""></option><option selected value="${USER.id}">${USER.name}</option>`;
|
||||||
|
// el.removeAttribute('disabled');
|
||||||
|
// } else if (msg.data.sheep_id == "" || msg.data.sheep_id == null || msg.data.sheep_id == USER.id) {
|
||||||
|
// el.innerHTML = `<option value=""></option><option value="${USER.id}">${USER.name}</option>`;
|
||||||
|
// el.removeAttribute('disabled');
|
||||||
|
// } else {
|
||||||
|
// el.innerHTML = `<option value="${msg.data.sheep_id}">${msg.data.sheep_name}</option>`;
|
||||||
|
// el.disabled = true;
|
||||||
|
// }
|
||||||
|
// el.style.border = "";
|
||||||
|
// el.style.backgroundColor = ""
|
||||||
|
// } else return;
|
||||||
|
// },
|
||||||
|
|
||||||
let stand_date = 1 + stand.week_days[z];
|
mess: {
|
||||||
|
locking({ id }) {
|
||||||
|
const message = {
|
||||||
|
event: 'message',
|
||||||
|
user: {
|
||||||
|
name: USER.name,
|
||||||
|
id: USER.id
|
||||||
|
},
|
||||||
|
type: "stand_locking",
|
||||||
|
data: {
|
||||||
|
id: id,
|
||||||
|
stand_id: Stand_card.id,
|
||||||
|
sheep_name: null
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
for (let i = 0; i < stand_length; i++) {
|
if (Cloud.socket?.readyState === WebSocket.OPEN) {
|
||||||
let time_now = stand.hour_start + (stand.processing_time * i);
|
Cloud.socket.send(JSON.stringify(message));
|
||||||
let timeFormat = (a) => a > 9 ? a : `0${a}`;
|
} else {
|
||||||
|
if (confirm("З'єднання розірвано! Перепідключитись?")) {
|
||||||
|
Cloud.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
unlocking({ id }) {
|
||||||
|
const message = {
|
||||||
|
event: 'message',
|
||||||
|
user: {
|
||||||
|
name: USER.name,
|
||||||
|
id: USER.id
|
||||||
|
},
|
||||||
|
type: "stand_unlocking",
|
||||||
|
data: {
|
||||||
|
id: id,
|
||||||
|
stand_id: Stand_card.id
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function formatTime(hours) {
|
if (Cloud.socket?.readyState === WebSocket.OPEN) {
|
||||||
|
Cloud.socket.send(JSON.stringify(message));
|
||||||
|
} else {
|
||||||
|
if (confirm("З'єднання розірвано! Перепідключитись?")) {
|
||||||
|
Cloud.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
update({ sheep_id, id }) {
|
||||||
|
const message = {
|
||||||
|
event: 'message',
|
||||||
|
user: {
|
||||||
|
name: USER.name,
|
||||||
|
id: USER.id
|
||||||
|
},
|
||||||
|
type: "stand_update",
|
||||||
|
data: {
|
||||||
|
id: id,
|
||||||
|
stand_id: Stand_card.id,
|
||||||
|
sheep_id: sheep_id,
|
||||||
|
sheep_name: null
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (USER.possibilities.can_manager_stand) {
|
||||||
|
const pos = Sheeps.sheeps_list.list.map(e => e.id).indexOf(Number(sheep_id));
|
||||||
|
if (pos != -1) {
|
||||||
|
let name = Sheeps.sheeps_list.list[pos].name;
|
||||||
|
message.data.sheep_name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Cloud.socket?.readyState === WebSocket.OPEN) {
|
||||||
|
Cloud.socket.send(JSON.stringify(message));
|
||||||
|
} else {
|
||||||
|
if (confirm("З'єднання розірвано! Перепідключитись?")) {
|
||||||
|
Cloud.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
schedule: {
|
||||||
|
list: [],
|
||||||
|
async setHTML() {
|
||||||
|
const block = document.getElementById('stand-schedule');
|
||||||
|
block.innerHTML = '';
|
||||||
|
|
||||||
|
const url = `${CONFIG.api}stand/schedule/list/${Stand_card.id}`;
|
||||||
|
this.list = Stand_card.grouped(await Stand_card.loadAPI(url));
|
||||||
|
|
||||||
|
const fragment = document.createDocumentFragment();
|
||||||
|
|
||||||
|
const createSelect = (sheep) => {
|
||||||
|
const select = document.createElement("select");
|
||||||
|
select.id = `name-${sheep.id}`;
|
||||||
|
|
||||||
|
// пустой option
|
||||||
|
select.appendChild(Object.assign(document.createElement("option"), {
|
||||||
|
value: "",
|
||||||
|
textContent: " "
|
||||||
|
}));
|
||||||
|
|
||||||
|
// если есть права менеджера — добавляем всех пользователей
|
||||||
|
if (USER.possibilities.can_manager_stand && Array.isArray(Sheeps?.sheeps_list?.list)) {
|
||||||
|
Sheeps.sheeps_list.list.sort((a, b) => a.name.localeCompare(b.name, 'uk'));
|
||||||
|
Sheeps.sheeps_list.list.forEach(s => {
|
||||||
|
const option = document.createElement("option");
|
||||||
|
option.value = s.id;
|
||||||
|
option.textContent = s.name;
|
||||||
|
if (s.id === sheep.sheep_id) option.selected = true;
|
||||||
|
select.appendChild(option);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// если есть владелец — показываем его
|
||||||
|
const opt = document.createElement("option");
|
||||||
|
if (sheep.sheep_id) {
|
||||||
|
opt.value = sheep.sheep_id;
|
||||||
|
opt.textContent = sheep.sheep_name ?? USER.name;
|
||||||
|
opt.selected = sheep.sheep_id === USER.id;
|
||||||
|
} else {
|
||||||
|
opt.value = USER.id;
|
||||||
|
opt.textContent = USER.name;
|
||||||
|
}
|
||||||
|
select.appendChild(opt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// если занят другим пользователем — блокируем
|
||||||
|
if (sheep.sheep_id && sheep.sheep_id !== USER.id && !USER.possibilities.can_manager_stand) {
|
||||||
|
select.disabled = true;
|
||||||
|
select.value = sheep.sheep_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- обработчики ---
|
||||||
|
select.addEventListener("mousedown", () => Stand_card.cloud.mess.locking({ id: sheep.id }));
|
||||||
|
select.addEventListener("change", () => Stand_card.cloud.mess.update({ sheep_id: select.value, id: sheep.id }));
|
||||||
|
select.addEventListener("blur", () => Stand_card.cloud.mess.unlocking({ id: sheep.id }));
|
||||||
|
|
||||||
|
return select;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.list.forEach((day, dayIndex) => {
|
||||||
|
const timestamp = day[0][0].date;
|
||||||
|
const dayDiv = Object.assign(document.createElement("div"), {
|
||||||
|
className: "block-day",
|
||||||
|
id: `day-${dayIndex}`
|
||||||
|
});
|
||||||
|
|
||||||
|
dayDiv.appendChild(Object.assign(document.createElement("h3"), {
|
||||||
|
textContent: `${formattedDate(timestamp)} • ${formattedDayName(timestamp)}`
|
||||||
|
}));
|
||||||
|
|
||||||
|
day.forEach((hour, hourIndex) => {
|
||||||
|
const hourDiv = Object.assign(document.createElement("div"), {
|
||||||
|
id: `hour-${dayIndex}-${hourIndex}`
|
||||||
|
});
|
||||||
|
|
||||||
|
hourDiv.appendChild(Object.assign(document.createElement("span"), {
|
||||||
|
className: "time",
|
||||||
|
textContent: `${Stand_card.formatTime(hour[0].hour)}-${Stand_card.formatTime(hour[0].hour + Stand_card.info.list.processing_time)}`
|
||||||
|
}));
|
||||||
|
|
||||||
|
hour.forEach(sheep => hourDiv.appendChild(createSelect(sheep)));
|
||||||
|
dayDiv.appendChild(hourDiv);
|
||||||
|
});
|
||||||
|
|
||||||
|
fragment.appendChild(dayDiv);
|
||||||
|
});
|
||||||
|
|
||||||
|
// кнопка добавления
|
||||||
|
if (USER.possibilities.can_add_stand) {
|
||||||
|
const btn = Object.assign(document.createElement("button"), {
|
||||||
|
id: "stand-new-button",
|
||||||
|
textContent: "Додати стенд(и)",
|
||||||
|
onclick: () => Stand_card.addStand()
|
||||||
|
});
|
||||||
|
fragment.appendChild(btn);
|
||||||
|
}
|
||||||
|
|
||||||
|
block.appendChild(fragment);
|
||||||
|
}
|
||||||
|
// async setHTML() {
|
||||||
|
// const block_schedule = document.getElementById('stand-schedule');
|
||||||
|
// block_schedule.innerHTML = '';
|
||||||
|
|
||||||
|
// const url = `${CONFIG.api}stand/schedule/list/${Stand_card.id}`;
|
||||||
|
// this.list = Stand_card.grouped(await Stand_card.loadAPI(url));
|
||||||
|
|
||||||
|
// let dayIndex = 0;
|
||||||
|
// for (const day of this.list) {
|
||||||
|
// const timestamp = day[0][0].date;
|
||||||
|
|
||||||
|
// const dayDiv = document.createElement("div");
|
||||||
|
// dayDiv.className = "block-day";
|
||||||
|
// dayDiv.id = `day-${dayIndex}`;
|
||||||
|
|
||||||
|
// const header = document.createElement("h3");
|
||||||
|
// header.textContent = `${formattedDate(timestamp)} • ${formattedDayName(timestamp)}`;
|
||||||
|
// dayDiv.appendChild(header);
|
||||||
|
|
||||||
|
// let hourIndex = 0;
|
||||||
|
// for (const hour of day) {
|
||||||
|
// const hourDiv = document.createElement("div");
|
||||||
|
// hourDiv.id = `hour-${dayIndex}-${hourIndex}`;
|
||||||
|
|
||||||
|
// const span = document.createElement("span");
|
||||||
|
// span.className = "time";
|
||||||
|
// span.textContent = `${Stand_card.formatTime(hour[0].hour)}-${Stand_card.formatTime(hour[0].hour + Stand_card.info.list.processing_time)}`;
|
||||||
|
// hourDiv.appendChild(span);
|
||||||
|
|
||||||
|
// for (const sheep of hour) {
|
||||||
|
// const select = document.createElement("select");
|
||||||
|
// select.id = `name-${sheep.id}`;
|
||||||
|
|
||||||
|
// const emptyOption = document.createElement("option");
|
||||||
|
// emptyOption.value = "";
|
||||||
|
// emptyOption.textContent = " ";
|
||||||
|
// select.appendChild(emptyOption);
|
||||||
|
|
||||||
|
// if (sheep.sheep_id && sheep.sheep_id == USER.id) {
|
||||||
|
// const opt = document.createElement("option");
|
||||||
|
// opt.value = USER.id;
|
||||||
|
// opt.textContent = USER.name;
|
||||||
|
// opt.selected = true;
|
||||||
|
// select.appendChild(opt);
|
||||||
|
|
||||||
|
// // --- Обработчики событий ---
|
||||||
|
// select.addEventListener("focus", () => {
|
||||||
|
// // пользователь начал взаимодействие → блокируем
|
||||||
|
// Stand_card.cloud.mess.locking({ id: sheep.id });
|
||||||
|
// });
|
||||||
|
|
||||||
|
// select.addEventListener("blur", () => {
|
||||||
|
// // пользователь ушёл → разблокируем
|
||||||
|
// Stand_card.cloud.mess.unlocking({ id: sheep.id });
|
||||||
|
// });
|
||||||
|
|
||||||
|
// select.addEventListener("change", () => {
|
||||||
|
// // пользователь выбрал что-то → обновляем
|
||||||
|
// Stand_card.cloud.mess.update({ sheep_id: select.value, id: sheep.id });
|
||||||
|
// });
|
||||||
|
// } else if (sheep.sheep_id && sheep.sheep_id != USER.id) {
|
||||||
|
// const opt = document.createElement("option");
|
||||||
|
// opt.value = sheep.sheep_id;
|
||||||
|
// opt.textContent = sheep.sheep_name;
|
||||||
|
// opt.selected = true;
|
||||||
|
// select.appendChild(opt);
|
||||||
|
|
||||||
|
// // --- Обработчики событий ---
|
||||||
|
// select.addEventListener("focus", () => {
|
||||||
|
// // пользователь начал взаимодействие → блокируем
|
||||||
|
// Stand_card.cloud.mess.locking({ id: sheep.id });
|
||||||
|
// });
|
||||||
|
|
||||||
|
// select.addEventListener("blur", () => {
|
||||||
|
// // пользователь ушёл → разблокируем
|
||||||
|
// Stand_card.cloud.mess.unlocking({ id: sheep.id });
|
||||||
|
// });
|
||||||
|
|
||||||
|
// select.addEventListener("change", () => {
|
||||||
|
// // пользователь выбрал что-то → обновляем
|
||||||
|
// Stand_card.cloud.mess.update({ sheep_id: select.value, id: sheep.id });
|
||||||
|
// });
|
||||||
|
|
||||||
|
// select.disabled = true;
|
||||||
|
// } else {
|
||||||
|
// const opt = document.createElement("option");
|
||||||
|
// opt.value = USER.id;
|
||||||
|
// opt.textContent = USER.name;
|
||||||
|
// select.appendChild(opt);
|
||||||
|
|
||||||
|
// // --- Обработчики событий ---
|
||||||
|
// select.addEventListener("focus", () => {
|
||||||
|
// // пользователь начал взаимодействие → блокируем
|
||||||
|
// Stand_card.cloud.mess.locking({ id: sheep.id });
|
||||||
|
// });
|
||||||
|
|
||||||
|
// select.addEventListener("blur", () => {
|
||||||
|
// // пользователь ушёл → разблокируем
|
||||||
|
// Stand_card.cloud.mess.unlocking({ id: sheep.id });
|
||||||
|
// });
|
||||||
|
|
||||||
|
// select.addEventListener("change", () => {
|
||||||
|
// // пользователь выбрал что-то → обновляем
|
||||||
|
// Stand_card.cloud.mess.update({ sheep_id: select.value, id: sheep.id });
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
|
// hourDiv.appendChild(select);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// dayDiv.appendChild(hourDiv);
|
||||||
|
// hourIndex++;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// block_schedule.appendChild(dayDiv);
|
||||||
|
// dayIndex++;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (USER.possibilities.can_add_stand) {
|
||||||
|
// const btn = document.createElement("button");
|
||||||
|
// btn.id = "stand-new-button";
|
||||||
|
// btn.onclick = () => Stand_card.addStand();
|
||||||
|
// btn.textContent = "Додати стенд(и)";
|
||||||
|
// block_schedule.appendChild(btn);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
},
|
||||||
|
|
||||||
|
grouped(list) {
|
||||||
|
const groupedByDate = {};
|
||||||
|
for (const item of list) {
|
||||||
|
if (!groupedByDate[item.date]) groupedByDate[item.date] = [];
|
||||||
|
groupedByDate[item.date].push(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = Object.values(groupedByDate).map(dateGroup => {
|
||||||
|
const groupedByHour = [];
|
||||||
|
let currentGroup = [];
|
||||||
|
let lastHour = null;
|
||||||
|
|
||||||
|
for (const item of dateGroup) {
|
||||||
|
if (item.hour !== lastHour) {
|
||||||
|
if (currentGroup.length > 0) groupedByHour.push(currentGroup);
|
||||||
|
currentGroup = [];
|
||||||
|
lastHour = item.hour;
|
||||||
|
}
|
||||||
|
currentGroup.push(item);
|
||||||
|
}
|
||||||
|
if (currentGroup.length > 0) groupedByHour.push(currentGroup);
|
||||||
|
|
||||||
|
return groupedByHour;
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
|
||||||
|
formatTime(hours) {
|
||||||
let h = Math.floor(hours);
|
let h = Math.floor(hours);
|
||||||
let m = (hours % 1 === 0.5) ? "30" : "00";
|
let m = (hours % 1 === 0.5) ? "30" : "00";
|
||||||
let hh = h.toString().padStart(2, "0");
|
let hh = h.toString().padStart(2, "0");
|
||||||
return `${hh}:${m}`;
|
return `${hh}:${m}`;
|
||||||
|
},
|
||||||
|
|
||||||
|
async addStand() {
|
||||||
|
const button = document.getElementById('stand-new-button');
|
||||||
|
|
||||||
|
const uuid = localStorage.getItem('uuid');
|
||||||
|
const URL = `${CONFIG.api}stand/schedule/${Stand_card.id}`;
|
||||||
|
await fetch(URL, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": uuid
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (response.status == 200) {
|
||||||
|
console.log({ 'setPack': 'ok' });
|
||||||
|
button.innerText = "Стенд(и) додано";
|
||||||
|
|
||||||
html += `
|
return response.json()
|
||||||
<div id="hour-${z}-${i}">
|
} else {
|
||||||
<span class="time">${formatTime(time_now)}-${formatTime(time_now + stand.processing_time)}</span>
|
console.log('err');
|
||||||
`;
|
button.innerText = "Помилка запису";
|
||||||
|
|
||||||
for (let q = 0; q < stand.quantity_sheep; q++) {
|
return
|
||||||
html += `
|
|
||||||
<select id="name">
|
|
||||||
<option value=""></option>
|
|
||||||
<option value="Test">Test</option>
|
|
||||||
</select>
|
|
||||||
`;
|
|
||||||
|
|
||||||
Stand_card.schedule[z].push({
|
|
||||||
id: (i + z) * stand.quantity_sheep + q,
|
|
||||||
hour: stand.hour_start + (stand.processing_time * i),
|
|
||||||
number_sheep: q,
|
|
||||||
date: stand_date,
|
|
||||||
sheep_id: null,
|
|
||||||
stand_id: stand.id,
|
|
||||||
updated_at: Date.now()
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
html += `</div>`; // закриваємо hour
|
Stand_card.schedule.setHTML();
|
||||||
}
|
|
||||||
|
|
||||||
html += `</div>`; // закриваємо day
|
setTimeout(() => {
|
||||||
}
|
button.innerText = "Додати стенд(и)";
|
||||||
|
}, 3000);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
button.innerText = "Помилка запису";
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
document.getElementById('stand-info-title').innerText = Stand_card.title;
|
edit({ sheep_id, stand_id }) {
|
||||||
document.getElementById('stand-info-geo').innerHTML = '';
|
|
||||||
document.getElementById('stand-info-image').setAttribute('src', '');
|
|
||||||
|
|
||||||
block_schedule.innerHTML = html;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@
|
|||||||
|
|
||||||
#stand-schedule {
|
#stand-schedule {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
min-height: calc(100vh - 40px - 50px);
|
/* min-height: calc(100vh - 40px - 50px); */
|
||||||
height: fit-content;
|
height: fit-content;
|
||||||
margin: 0 10px 15px;
|
margin: 0 10px 15px;
|
||||||
border-radius: var(--border-radius);
|
border-radius: var(--border-radius);
|
||||||
@@ -137,6 +137,9 @@
|
|||||||
background-color: var(--ColorThemes0);
|
background-color: var(--ColorThemes0);
|
||||||
color: var(--ColorThemes3);
|
color: var(--ColorThemes3);
|
||||||
}
|
}
|
||||||
|
#stand-schedule>.block-day div select:disabled {
|
||||||
|
opacity: 0.9 !important;
|
||||||
|
}
|
||||||
|
|
||||||
#stand-schedule>.block-day div:nth-child(2n) {
|
#stand-schedule>.block-day div:nth-child(2n) {
|
||||||
background: var(--ColorThemes0);
|
background: var(--ColorThemes0);
|
||||||
@@ -146,3 +149,16 @@
|
|||||||
#stand-schedule>.block-day div:nth-child(2n) select {
|
#stand-schedule>.block-day div:nth-child(2n) select {
|
||||||
background-color: var(--ColorThemes2);
|
background-color: var(--ColorThemes2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#stand-schedule> #stand-new-button{
|
||||||
|
border-radius: 6px;
|
||||||
|
background: var(--PrimaryColor);
|
||||||
|
color: var(--PrimaryColorText);
|
||||||
|
width: calc(100% - 20px);
|
||||||
|
height: 40px;
|
||||||
|
font-size: var(--FontSize3);
|
||||||
|
font-weight: 400;
|
||||||
|
margin: 10px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
115
web/lib/pages/stand/constructor/index.html
Normal file
115
web/lib/pages/stand/constructor/index.html
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
<div class="page-stand-constructor">
|
||||||
|
<form id="stand-constructor-form">
|
||||||
|
<h1>Створення місця розташування стенду</h1>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="info-title">Назва стенду</label>
|
||||||
|
<input type="text" id="info-title" name="title" required />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="info-quantity_sheep"
|
||||||
|
>Кількість вісників, що можуть стояти одночасно</label
|
||||||
|
>
|
||||||
|
<select id="info-quantity_sheep" name="quantity_sheep" required>
|
||||||
|
<option value="2" selected>2 вісника</option>
|
||||||
|
<option value="3">3 вісника</option>
|
||||||
|
<option value="4">4 вісника</option>
|
||||||
|
<option value="5">5 вісників</option>
|
||||||
|
<option value="6">6 вісників</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label>Години початку та кінця служіння</label>
|
||||||
|
<div class="geo-inputs">
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
id="info-hour_start"
|
||||||
|
name="hour_start"
|
||||||
|
required
|
||||||
|
placeholder="10"
|
||||||
|
min="5",
|
||||||
|
step="1"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
id="info-hour_end"
|
||||||
|
name="hour_end"
|
||||||
|
required
|
||||||
|
placeholder="16"
|
||||||
|
max="22",
|
||||||
|
step="1"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label>Локація розташування</label>
|
||||||
|
<div class="geo-inputs">
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
id="info-geo_lat"
|
||||||
|
name="geo_lat"
|
||||||
|
required
|
||||||
|
placeholder="49.5601856455014",
|
||||||
|
step="0.01"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
id="info-geo_lng"
|
||||||
|
name="geo_lng"
|
||||||
|
required
|
||||||
|
placeholder="25.625626212730406",
|
||||||
|
step="0.01"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="info-processing_time">Час тривалості зміни вісників</label>
|
||||||
|
<select id="info-processing_time" name="processing_time" required>
|
||||||
|
<option value="0.5">30 хвилин</option>
|
||||||
|
<option value="1" selected>1 година</option>
|
||||||
|
<option value="2">2 години</option>
|
||||||
|
<option value="3">3 години</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label>Дні встановлення стенду</label>
|
||||||
|
<div class="week-days">
|
||||||
|
<div class="option checkbox">
|
||||||
|
<input class="custom-checkbox" id="day-0" name="day-0" type="checkbox" />
|
||||||
|
<label for="day-0""> Понеділок: </label>
|
||||||
|
</div>
|
||||||
|
<div class="option checkbox">
|
||||||
|
<input class="custom-checkbox" id="day-1" name="day-1" type="checkbox" />
|
||||||
|
<label for="day-1"> Вівторок: </label>
|
||||||
|
</div>
|
||||||
|
<div class="option checkbox">
|
||||||
|
<input class="custom-checkbox" id="day-2" name="day-2" type="checkbox" />
|
||||||
|
<label for="day-2"> Середа: </label>
|
||||||
|
</div>
|
||||||
|
<div class="option checkbox">
|
||||||
|
<input class="custom-checkbox" id="day-3" name="day-3" type="checkbox" />
|
||||||
|
<label for="day-3"> Четвер: </label>
|
||||||
|
</div>
|
||||||
|
<div class="option checkbox">
|
||||||
|
<input class="custom-checkbox" id="day-4" name="day-4" type="checkbox" />
|
||||||
|
<label for="day-4"> Пʼятниця: </label>
|
||||||
|
</div>
|
||||||
|
<div class="option checkbox">
|
||||||
|
<input class="custom-checkbox" id="day-5" name="day-5" type="checkbox" />
|
||||||
|
<label for="day-5"> Субота: </label>
|
||||||
|
</div>
|
||||||
|
<div class="option checkbox">
|
||||||
|
<input class="custom-checkbox" id="day-6" name="day-6" type="checkbox" />
|
||||||
|
<label for="day-6"> Неділя: </label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" id="stand-constructor-button">Зберегти</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
75
web/lib/pages/stand/constructor/script.js
Normal file
75
web/lib/pages/stand/constructor/script.js
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
const Stand_constructor = {
|
||||||
|
init: async () => {
|
||||||
|
let html = await fetch('/lib/pages/stand/constructor/index.html').then((response) => response.text());
|
||||||
|
app.innerHTML = html;
|
||||||
|
|
||||||
|
const form = document.getElementById('stand-constructor-form');
|
||||||
|
|
||||||
|
form.addEventListener('submit', (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
let values = {
|
||||||
|
"title": document.getElementById('info-title').value,
|
||||||
|
"quantity_sheep": Number(document.getElementById('info-quantity_sheep').value),
|
||||||
|
"hour_start": Number(document.getElementById('info-hour_start').value),
|
||||||
|
"hour_end": Number(document.getElementById('info-hour_end').value),
|
||||||
|
"geo": [Number(document.getElementById('info-geo_lat').value), Number(document.getElementById('info-geo_lng').value)],
|
||||||
|
"processing_time": Number(document.getElementById('info-processing_time').value)
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkboxes = form.querySelectorAll('input[type="checkbox"][name^="day-"]');
|
||||||
|
let week_days = () => {
|
||||||
|
let a = [];
|
||||||
|
for (const key in checkboxes) {
|
||||||
|
const element = checkboxes[key];
|
||||||
|
if(element.checked) a.push(Number((element.name).replace("day-", "")))
|
||||||
|
}
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
values.week_days = week_days();
|
||||||
|
|
||||||
|
console.log(values);
|
||||||
|
|
||||||
|
Stand_constructor.save(values);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
async save(values) {
|
||||||
|
const button = document.getElementById('stand-constructor-button');
|
||||||
|
|
||||||
|
const uuid = localStorage.getItem('uuid');
|
||||||
|
const URL = `${CONFIG.api}stand/list`;
|
||||||
|
await fetch(URL, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": uuid
|
||||||
|
},
|
||||||
|
body: JSON.stringify(values)
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (response.status == 200) {
|
||||||
|
console.log({ 'setPack': 'ok' });
|
||||||
|
button.innerText = "Стенд додано";
|
||||||
|
|
||||||
|
return response.json()
|
||||||
|
} else {
|
||||||
|
console.log('err');
|
||||||
|
button.innerText = "Помилка запису";
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
console.log(data);
|
||||||
|
Router.navigate(`/stand/card/${data.id}`);
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
button.innerText = "Зберегти";
|
||||||
|
}, 3000);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
button.innerText = "Помилка запису";
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
120
web/lib/pages/stand/constructor/style.css
Normal file
120
web/lib/pages/stand/constructor/style.css
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
.page-stand-constructor {
|
||||||
|
width: calc(100% - 40px);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
|
margin: 20px 20px 0 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-constructor>form {
|
||||||
|
border-radius: 10px;
|
||||||
|
width: calc(100% - 40px);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
background: var(--ColorThemes1);
|
||||||
|
color: var(--ColorThemes3);
|
||||||
|
border: 1px solid var(--ColorThemes2);
|
||||||
|
box-shadow: var(--shadow-l1);
|
||||||
|
padding: 0 20px;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-constructor>form>h1 {
|
||||||
|
width: calc(100% - 40px);
|
||||||
|
color: var(--ColorThemes3);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
font-size: var(--FontSize5);
|
||||||
|
font-weight: 300;
|
||||||
|
padding: 20px 0;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-constructor>form>div {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
margin: 20px 0;
|
||||||
|
align-items: flex-start;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-constructor>form>div>label {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
flex-direction: column;
|
||||||
|
font-size: var(--FontSize1);
|
||||||
|
font-weight: 500;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-constructor>form>div>select {
|
||||||
|
width: 100%;
|
||||||
|
min-width: 140px;
|
||||||
|
padding: 0 5px;
|
||||||
|
border-radius: calc(var(--border-radius) - 5px - 4px);
|
||||||
|
height: 30px;
|
||||||
|
background-color: var(--ColorThemes0);
|
||||||
|
color: var(--ColorThemes3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-constructor>form>div>input,
|
||||||
|
.page-stand-constructor>form>div>div>input {
|
||||||
|
width: calc(100% - 10px);
|
||||||
|
min-width: 140px;
|
||||||
|
padding: 0 5px;
|
||||||
|
border-radius: 6px;
|
||||||
|
height: 30px;
|
||||||
|
background: var(--ColorThemes0);
|
||||||
|
color: var(--ColorThemes3);
|
||||||
|
font-size: var(--FontSize2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-constructor>form>div>.geo-inputs {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-constructor>form>div>.geo-inputs>input {
|
||||||
|
width: calc(50% - 15px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-constructor>form>div>.week-days {
|
||||||
|
background: var(--ColorThemes0);
|
||||||
|
border-radius: calc(var(--border-radius) - 5px - 4px);
|
||||||
|
width: calc(100% - 15px);
|
||||||
|
padding: 0 5px 0 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-constructor>form>div>.week-days>div {
|
||||||
|
margin: 10px 0;
|
||||||
|
width: 100%;
|
||||||
|
font-size: var(--FontSize3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-constructor>form>div>.week-days>div>.custom-checkbox+label {
|
||||||
|
font-size: var(--FontSize4);
|
||||||
|
font-weight: 400;
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
user-select: none;
|
||||||
|
flex-direction: row-reverse;
|
||||||
|
justify-content: space-between;
|
||||||
|
cursor: pointer;
|
||||||
|
margin: 5px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-constructor>form>button {
|
||||||
|
border-radius: 6px;
|
||||||
|
background: var(--PrimaryColor);
|
||||||
|
color: var(--PrimaryColorText);
|
||||||
|
width: 100%;
|
||||||
|
height: 40px;
|
||||||
|
font-size: var(--FontSize3);
|
||||||
|
font-weight: 400;
|
||||||
|
margin: 20px 0;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
282
web/lib/pages/stand/index.html
Normal file
282
web/lib/pages/stand/index.html
Normal file
@@ -0,0 +1,282 @@
|
|||||||
|
<div class="page-stand">
|
||||||
|
<!-- <label for="dateSelect">Виберіть дату:</label>
|
||||||
|
<select id="dateSelect"></select> -->
|
||||||
|
|
||||||
|
<details id="stand-info">
|
||||||
|
<summary>Інформація про стенд</summary>
|
||||||
|
<div>
|
||||||
|
<span>Розташування:</span>
|
||||||
|
<p id="stand-info-title">Тест</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span>Геолокація:</span>
|
||||||
|
<p id="stand-info-geo"></p>
|
||||||
|
</div>
|
||||||
|
<img id="stand-info-image" src="" />
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<div id="stand-schedule">
|
||||||
|
<!-- <div class="block-day" id="day-0">
|
||||||
|
<h3>08.08.2025 • Пʼятниця</h3>
|
||||||
|
<div>
|
||||||
|
<span id="time">09:00-10:00</span>
|
||||||
|
<select id="name_1">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_2">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_3">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<span id="time">10:00-11:00</span>
|
||||||
|
<select id="name_1">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_2">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_3">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<span id="time">11:00-12:00</span>
|
||||||
|
<select id="name_1">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_2">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_3">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<span id="time">12:00-13:00</span>
|
||||||
|
<select id="name_1">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_2">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_3">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<span id="time">14:00-15:00</span>
|
||||||
|
<select id="name_1">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_2">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_3">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<span id="time">15:00-16:00</span>
|
||||||
|
<select id="name_1">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_2">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_3">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<span id="time">16:00-17:00</span>
|
||||||
|
<select id="name_1">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_2">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_3">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<span id="time">17:00-18:00</span>
|
||||||
|
<select id="name_1">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_2">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_3">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="block-day" id="day-1">
|
||||||
|
<h3>11.08.2025 • Понеділок</h3>
|
||||||
|
<div>
|
||||||
|
<span id="time">09:00-10:00</span>
|
||||||
|
<select id="name_1">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_2">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_3">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<span id="time">10:00-11:00</span>
|
||||||
|
<select id="name_1">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_2">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_3">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<span id="time">11:00-12:00</span>
|
||||||
|
<select id="name_1">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_2">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_3">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<span id="time">12:00-13:00</span>
|
||||||
|
<select id="name_1">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_2">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_3">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<span id="time">14:00-15:00</span>
|
||||||
|
<select id="name_1">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_2">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_3">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<span id="time">15:00-16:00</span>
|
||||||
|
<select id="name_1">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_2">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_3">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<span id="time">16:00-17:00</span>
|
||||||
|
<select id="name_1">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_2">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_3">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<span id="time">17:00-18:00</span>
|
||||||
|
<select id="name_1">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_2">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
<select id="name_3">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div> -->
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -1,3 +1,25 @@
|
|||||||
<div class="page-stand-list">
|
<div class="page-stand-list">
|
||||||
|
<div class="buttons-list" id="buttons-list">
|
||||||
|
<a
|
||||||
|
href="/stand/constructor"
|
||||||
|
data-route
|
||||||
|
id="constructorButton"
|
||||||
|
style="display: none"
|
||||||
|
>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48">
|
||||||
|
<path
|
||||||
|
d="M 14.5 4 C 12.015 4 10 6.015 10 8.5 L 10 39.5 C 10 41.985 12.015 44 14.5 44 L 22.042969 44 C 22.079969 43.749 22.138516 43.502672 22.228516 43.263672 L 22.283203 43.285156 C 22.353203 42.961156 23.236422 40.161109 23.982422 37.787109 C 24.272422 36.865109 24.779891 36.029703 25.462891 35.345703 L 33.904297 27 L 27.5 27 C 26.672 27 26 26.328 26 25.5 L 26 16 L 38 16 L 38 23.054688 C 38.72 22.587688 39.4975 22.254422 40.3125 22.107422 C 40.5365 22.067422 40.769 22.062922 41 22.044922 L 41 14.5 C 41 13.672 40.328 13 39.5 13 L 34 13 L 34 8.5 C 34 6.015 31.985 4 29.5 4 L 14.5 4 z M 30.5 18 A 1.50015 1.50015 0 1 0 30.5 21 L 33.5 21 A 1.50015 1.50015 0 1 0 33.5 18 L 30.5 18 z M 41.498047 24 C 41.224047 24.001 40.946969 24.025172 40.667969 24.076172 C 39.783969 24.235172 38.939563 24.696156 38.226562 25.410156 L 26.427734 37.208984 C 26.070734 37.565984 25.807969 38.011141 25.667969 38.494141 L 24.097656 43.974609 C 24.025656 44.164609 23.993 44.365406 24 44.566406 C 24.013 44.929406 24.155594 45.288406 24.433594 45.566406 C 24.710594 45.843406 25.067688 45.986 25.429688 46 C 25.630688 46.007 25.834391 45.975344 26.025391 45.902344 L 31.505859 44.332031 C 31.988859 44.192031 32.431062 43.930266 32.789062 43.572266 L 44.589844 31.773438 C 45.303844 31.060437 45.764828 30.216031 45.923828 29.332031 C 45.973828 29.053031 45.997047 28.775953 45.998047 28.501953 C 46.001047 27.307953 45.540687 26.179312 44.679688 25.320312 C 43.820687 24.460313 42.692047 23.998 41.498047 24 z M 22 35 C 22.828 35 23.5 35.672 23.5 36.5 C 23.5 37.328 22.828 38 22 38 C 21.172 38 20.5 37.328 20.5 36.5 C 20.5 35.672 21.172 35 22 35 z"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
<span>Конструктор</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<details open>
|
||||||
|
<summary>
|
||||||
|
<span>Доступні стенди</span>
|
||||||
|
</summary>
|
||||||
|
|
||||||
|
<div id="list"></div>
|
||||||
|
</details>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,53 @@
|
|||||||
const Stand_list = {
|
const Stand_list = {
|
||||||
|
list: [],
|
||||||
init: async () => {
|
init: async () => {
|
||||||
let html = await fetch('/lib/pages/stand/list/index.html').then((response) => response.text());
|
let html = await fetch('/lib/pages/stand/list/index.html').then((response) => response.text());
|
||||||
app.innerHTML = html;
|
app.innerHTML = html;
|
||||||
|
|
||||||
|
Stand_list.setHTML();
|
||||||
|
|
||||||
|
if (USER.possibilities.can_add_stand) {
|
||||||
|
document.getElementById("buttons-list").style.display = "flex";
|
||||||
|
document.getElementById("constructorButton").style.display = "";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
loadAPI: async function (url) {
|
||||||
|
const uuid = localStorage.getItem("uuid");
|
||||||
|
const response = await fetch(url, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": uuid
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Stand_list.list = await response.json();
|
||||||
|
return Stand_list.list;
|
||||||
|
},
|
||||||
|
setHTML: async function () {
|
||||||
|
const block_list = document.getElementById('list');
|
||||||
|
|
||||||
|
const url = `${CONFIG.api}stand/list`;
|
||||||
|
let list = this.list.length > 0 ? this.list : await this.loadAPI(url);
|
||||||
|
|
||||||
|
let html = "";
|
||||||
|
for (const element of list) {
|
||||||
|
html += this.renderCard({ element });
|
||||||
|
}
|
||||||
|
|
||||||
|
block_list.innerHTML = html;
|
||||||
|
},
|
||||||
|
renderCard: ({ element }) => {
|
||||||
|
return `
|
||||||
|
<div class="card">
|
||||||
|
<div class="contents">
|
||||||
|
<div class="info">
|
||||||
|
<div>
|
||||||
|
<p>${element.title}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<a href="/stand/card/${element.id}" data-route></a>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,243 @@
|
|||||||
width: calc(100% - 40px);
|
width: calc(100% - 40px);
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: stretch;
|
||||||
margin: 20px 20px 0 20px;
|
margin: 20px 20px 0 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.page-stand-list>.buttons-list {
|
||||||
|
padding: 10px;
|
||||||
|
margin-bottom: 40px;
|
||||||
|
background: var(--ColorThemes1);
|
||||||
|
color: var(--ColorThemes3);
|
||||||
|
border: 1px solid var(--ColorThemes2);
|
||||||
|
box-shadow: var(--shadow-l1);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
overflow: auto;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-list>.buttons-list>button,
|
||||||
|
.page-stand-list>.buttons-list>a {
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: calc(var(--border-radius) - 5px);
|
||||||
|
padding: 0 10px;
|
||||||
|
margin-right: 20px;
|
||||||
|
min-width: fit-content;
|
||||||
|
min-height: 40px;
|
||||||
|
background: var(--PrimaryColor);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-list>.buttons-list>button>span,
|
||||||
|
.page-stand-list>.buttons-list>a>span {
|
||||||
|
color: var(--PrimaryColorText);
|
||||||
|
font-size: var(--FontSize3);
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-list>.buttons-list>button>svg,
|
||||||
|
.page-stand-list>.buttons-list>a>svg {
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
fill: var(--PrimaryColorText);
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-list>.list-controls {
|
||||||
|
padding: 10px;
|
||||||
|
margin: 0px 0 10px 0;
|
||||||
|
background: var(--ColorThemes1);
|
||||||
|
color: var(--ColorThemes3);
|
||||||
|
border: 1px solid var(--ColorThemes2);
|
||||||
|
box-shadow: var(--shadow-l1);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
overflow: auto;
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-list>.list-controls select {
|
||||||
|
min-width: 140px;
|
||||||
|
height: 30px;
|
||||||
|
background-color: var(--ColorThemes2);
|
||||||
|
border: 1px solid var(--ColorThemes0);
|
||||||
|
box-shadow: var(--shadow-l1);
|
||||||
|
color: var(--ColorThemes3);
|
||||||
|
font-size: var(--FontSize1);
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 0 5px;
|
||||||
|
margin-right: 10px;
|
||||||
|
border-radius: calc(var(--border-radius) - 5px - 2px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-list details {
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
background: var(--ColorThemes1);
|
||||||
|
color: var(--ColorThemes3);
|
||||||
|
border: 1px solid var(--ColorThemes2);
|
||||||
|
box-shadow: var(--shadow-l1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-list>details[disabled] summary,
|
||||||
|
.page-stand-list>details.disabled summary {
|
||||||
|
pointer-events: none;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-list>details summary::-webkit-details-marker,
|
||||||
|
.page-stand-list>details summary::marker {
|
||||||
|
display: none;
|
||||||
|
content: "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.page-stand-list summary {
|
||||||
|
width: calc(100% - 40px);
|
||||||
|
cursor: pointer;
|
||||||
|
color: var(--ColorThemes3);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
font-size: var(--FontSize5);
|
||||||
|
font-weight: 300;
|
||||||
|
padding: 20px;
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-list #list {
|
||||||
|
width: 100%;
|
||||||
|
margin: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
flex-direction: row;
|
||||||
|
align-content: flex-start;
|
||||||
|
justify-content: center;
|
||||||
|
overflow-y: auto;
|
||||||
|
align-items: flex-start;
|
||||||
|
transition: .3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-list .card {
|
||||||
|
position: relative;
|
||||||
|
width: 300px;
|
||||||
|
height: 200px;
|
||||||
|
background-color: var(--ColorThemes2);
|
||||||
|
margin: 0px 10px 20px 10px;
|
||||||
|
overflow: hidden;
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: calc(var(--border-radius) - 5px);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 2300px) {
|
||||||
|
.page-stand-list .card {
|
||||||
|
width: calc((100% / 5) - 40px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1960px) {
|
||||||
|
.page-stand-list .card {
|
||||||
|
width: calc((100% / 4) - 40px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1640px) {
|
||||||
|
.page-stand-list .card {
|
||||||
|
width: calc((100% / 3) - 40px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1280px) {
|
||||||
|
.page-stand-list .card {
|
||||||
|
width: calc((100% / 2) - 40px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 650px) {
|
||||||
|
.page-stand-list .card {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media(hover: hover) {
|
||||||
|
.page-stand-list .card:hover {
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-list .card>i {
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
z-index: 1;
|
||||||
|
filter: blur(2px);
|
||||||
|
/* background-repeat: round; */
|
||||||
|
background-size: cover;
|
||||||
|
background-position: center;
|
||||||
|
background-color: var(--PrimaryColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-list .card>a {
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
z-index: 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.page-stand-list .card>.contents {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 2;
|
||||||
|
background: rgb(64 64 64 / 0.7);
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
font-size: 40px;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #fff;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.page-stand-list .card>.contents>.info {
|
||||||
|
margin: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-list .card>.contents>.info>div {
|
||||||
|
width: 100%;
|
||||||
|
height: 35px;
|
||||||
|
display: flex;
|
||||||
|
background: var(--ColorThemes0);
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: var(--FontSize1);
|
||||||
|
color: var(--ColorThemes3);
|
||||||
|
border-radius: calc(var(--border-radius) - 5px - 4px);
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-list .card>.contents>.info>div>span {
|
||||||
|
color: var(--ColorThemes3);
|
||||||
|
font-size: var(--FontSize3);
|
||||||
|
font-weight: 300;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand-list .card>.contents>.info>div>p {
|
||||||
|
color: var(--ColorThemes3);
|
||||||
|
font-size: var(--FontSize3);
|
||||||
|
font-weight: 400;
|
||||||
|
padding: 10px;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
123
web/lib/pages/stand/script.js
Normal file
123
web/lib/pages/stand/script.js
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
const Stand = {
|
||||||
|
schedule: [],
|
||||||
|
init: async () => {
|
||||||
|
let html = await fetch('/lib/pages/stand/index.html').then((response) => response.text());
|
||||||
|
app.innerHTML = html;
|
||||||
|
|
||||||
|
let listDate = [1, 4];
|
||||||
|
|
||||||
|
function generateAvailableDates() {
|
||||||
|
let select = document.getElementById("dateSelect");
|
||||||
|
select.innerHTML = "";
|
||||||
|
|
||||||
|
let today = new Date();
|
||||||
|
today.setHours(0, 0, 0, 0);
|
||||||
|
let months = [today.getMonth(), today.getMonth() + 1];
|
||||||
|
let year = today.getFullYear();
|
||||||
|
|
||||||
|
months.forEach(month => {
|
||||||
|
let date = new Date(year, month, 1);
|
||||||
|
while (date.getMonth() === month) {
|
||||||
|
if (date >= today) {
|
||||||
|
let day = date.getDay();
|
||||||
|
if (listDate.includes(day)) {
|
||||||
|
let option = document.createElement("option");
|
||||||
|
option.value = date.toISOString().split("T")[0];
|
||||||
|
option.textContent = date.toLocaleDateString("uk-UA", {
|
||||||
|
weekday: "long", year: "numeric", month: "long", day: "numeric"
|
||||||
|
});
|
||||||
|
select.appendChild(option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
date.setDate(date.getDate() + 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// generateAvailableDates();
|
||||||
|
Stand.generator();
|
||||||
|
},
|
||||||
|
generator: () => {
|
||||||
|
let block_schedule = document.getElementById('stand-schedule');
|
||||||
|
|
||||||
|
let html = "";
|
||||||
|
|
||||||
|
let stand = {
|
||||||
|
id: 1,
|
||||||
|
title: "Універсам",
|
||||||
|
geo: { lat: 0, lng: 0 },
|
||||||
|
hour_start: 9,
|
||||||
|
hour_end: 14,
|
||||||
|
quantity_sheep: 2,
|
||||||
|
week_days: [0, 2, 4, 6],
|
||||||
|
processing_time: 0.5,
|
||||||
|
updated_at: null
|
||||||
|
}
|
||||||
|
|
||||||
|
Stand.schedule = [];
|
||||||
|
|
||||||
|
// Кількість годин служіння
|
||||||
|
let stand_length = (stand.hour_end - stand.hour_start) / stand.processing_time;
|
||||||
|
|
||||||
|
for (let z = 0; z < stand.week_days.length; z++) {
|
||||||
|
Stand.schedule.push([]);
|
||||||
|
|
||||||
|
let date = new Date();
|
||||||
|
date.setDate(date.getDate() + stand.week_days[z]);
|
||||||
|
let dayName = date.toLocaleDateString('uk-UA', { weekday: 'long' });
|
||||||
|
|
||||||
|
html += `
|
||||||
|
<div class="block-day" id="day-${z}">
|
||||||
|
<h3>${date.toLocaleDateString()} • ${dayName}</h3>
|
||||||
|
`;
|
||||||
|
|
||||||
|
let stand_date = 1 + stand.week_days[z];
|
||||||
|
|
||||||
|
for (let i = 0; i < stand_length; i++) {
|
||||||
|
let time_now = stand.hour_start + (stand.processing_time * i);
|
||||||
|
let timeFormat = (a) => a > 9 ? a : `0${a}`;
|
||||||
|
|
||||||
|
function formatTime(hours) {
|
||||||
|
let h = Math.floor(hours);
|
||||||
|
let m = (hours % 1 === 0.5) ? "30" : "00";
|
||||||
|
let hh = h.toString().padStart(2, "0");
|
||||||
|
return `${hh}:${m}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
html += `
|
||||||
|
<div id="hour-${z}-${i}">
|
||||||
|
<span class="time">${formatTime(time_now)}-${formatTime(time_now + stand.processing_time)}</span>
|
||||||
|
`;
|
||||||
|
|
||||||
|
for (let q = 0; q < stand.quantity_sheep; q++) {
|
||||||
|
html += `
|
||||||
|
<select id="name">
|
||||||
|
<option value=""></option>
|
||||||
|
<option value="Test">Test</option>
|
||||||
|
</select>
|
||||||
|
`;
|
||||||
|
|
||||||
|
Stand.schedule[z].push({
|
||||||
|
id: (i + z) * stand.quantity_sheep + q,
|
||||||
|
hour: stand.hour_start + (stand.processing_time * i),
|
||||||
|
number_sheep: q,
|
||||||
|
date: stand_date,
|
||||||
|
sheep_id: null,
|
||||||
|
stand_id: stand.id,
|
||||||
|
updated_at: Date.now()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
html += `</div>`; // закриваємо hour
|
||||||
|
}
|
||||||
|
|
||||||
|
html += `</div>`; // закриваємо day
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('stand-info-title').innerText = stand.title;
|
||||||
|
document.getElementById('stand-info-geo').innerHTML = '';
|
||||||
|
document.getElementById('stand-info-image').setAttribute('src', '');
|
||||||
|
|
||||||
|
block_schedule.innerHTML = html;
|
||||||
|
}
|
||||||
|
}
|
||||||
148
web/lib/pages/stand/style.css
Normal file
148
web/lib/pages/stand/style.css
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
.page-stand {
|
||||||
|
width: calc(100% - 40px);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
margin: 20px 20px 0 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand details {
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
background: var(--ColorThemes1);
|
||||||
|
color: var(--ColorThemes3);
|
||||||
|
border: 1px solid var(--ColorThemes2);
|
||||||
|
box-shadow: var(--shadow-l1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-stand summary {
|
||||||
|
width: calc(100% - 40px);
|
||||||
|
cursor: pointer;
|
||||||
|
color: var(--ColorThemes3);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
font-size: var(--FontSize5);
|
||||||
|
font-weight: 300;
|
||||||
|
padding: 20px;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
#stand-info div {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
padding: 10px;
|
||||||
|
color: var(--ColorThemes3);
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#stand-info div span {
|
||||||
|
opacity: 0.8;
|
||||||
|
font-weight: 400;
|
||||||
|
font-size: var(--FontSize2);
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#stand-info div p {
|
||||||
|
font-weight: 300;
|
||||||
|
font-size: var(--FontSize4);
|
||||||
|
}
|
||||||
|
|
||||||
|
#stand-info img {
|
||||||
|
position: relative;
|
||||||
|
display: inline-block;
|
||||||
|
width: calc(100% - 20px);
|
||||||
|
border-radius: calc(var(--border-radius) - 8px);
|
||||||
|
margin: 10px;
|
||||||
|
height: auto;
|
||||||
|
aspect-ratio: 16 / 9;
|
||||||
|
background-color: #f2e5c9;
|
||||||
|
}
|
||||||
|
|
||||||
|
#stand-info img::before {
|
||||||
|
content: "Приклад розташування";
|
||||||
|
display: block;
|
||||||
|
color: #555;
|
||||||
|
text-align: center;
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#stand-schedule {
|
||||||
|
width: 100%;
|
||||||
|
min-height: calc(100vh - 40px - 50px);
|
||||||
|
height: fit-content;
|
||||||
|
margin: 0 10px 15px;
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
overflow: hidden;
|
||||||
|
background: var(--ColorThemes1);
|
||||||
|
color: var(--ColorThemes3);
|
||||||
|
border: 1px solid var(--ColorThemes2);
|
||||||
|
box-shadow: var(--shadow-l1);
|
||||||
|
transition: all .2sease 0s;
|
||||||
|
}
|
||||||
|
|
||||||
|
#stand-schedule>.block-day {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
width: calc(100% - 20px);
|
||||||
|
margin: 10px;
|
||||||
|
padding: 10px 0;
|
||||||
|
border: 1px solid var(--PrimaryColor);
|
||||||
|
background-color: var(--ColorThemes2);
|
||||||
|
border: 1px solid var(--ColorThemes0);
|
||||||
|
min-height: 100px;
|
||||||
|
justify-content: center;
|
||||||
|
position: relative;
|
||||||
|
border-radius: calc(var(--border-radius) - 5px);
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
#stand-schedule>.block-day h3 {
|
||||||
|
font-size: 17px;
|
||||||
|
font-weight: 500;
|
||||||
|
padding: 10px;
|
||||||
|
text-transform: capitalize;
|
||||||
|
width: calc(100% - 20px);
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#stand-schedule>.block-day div {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
padding: 5px 0;
|
||||||
|
margin: 0 10px;
|
||||||
|
align-items: center;
|
||||||
|
min-width: calc(100% - 20px);
|
||||||
|
width: fit-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
#stand-schedule>.block-day div span {
|
||||||
|
min-width: 85px;
|
||||||
|
padding: 0 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#stand-schedule>.block-day div select {
|
||||||
|
width: 100%;
|
||||||
|
min-width: 140px;
|
||||||
|
padding: 0 5px;
|
||||||
|
margin: 0 5px;
|
||||||
|
border-radius: calc(var(--border-radius) - 5px - 4px);
|
||||||
|
height: 30px;
|
||||||
|
background-color: var(--ColorThemes0);
|
||||||
|
color: var(--ColorThemes3);
|
||||||
|
}
|
||||||
|
|
||||||
|
#stand-schedule>.block-day div:nth-child(2n) {
|
||||||
|
background: var(--ColorThemes0);
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#stand-schedule>.block-day div:nth-child(2n) select {
|
||||||
|
background-color: var(--ColorThemes2);
|
||||||
|
}
|
||||||
@@ -3,9 +3,6 @@ let map_card;
|
|||||||
const Territory_card = {
|
const Territory_card = {
|
||||||
// Глобальні змінні стану
|
// Глобальні змінні стану
|
||||||
id: null,
|
id: null,
|
||||||
socket: null,
|
|
||||||
reconnectTimeout: null,
|
|
||||||
reconnectAttempts: 0,
|
|
||||||
listEntrances: [],
|
listEntrances: [],
|
||||||
listApartment: [],
|
listApartment: [],
|
||||||
listBuilding: [],
|
listBuilding: [],
|
||||||
@@ -28,11 +25,6 @@ const Territory_card = {
|
|||||||
app.innerHTML = html;
|
app.innerHTML = html;
|
||||||
Territory_card.id = Id;
|
Territory_card.id = Id;
|
||||||
|
|
||||||
// Закриваємо старий WebSocket
|
|
||||||
if (this.socket) this.socket.close(1000, "Перезапуск з'єднання");
|
|
||||||
// this.cloud.start(makeid(6));
|
|
||||||
this.cloud.start()
|
|
||||||
|
|
||||||
// Якщо це сторінка будинку, отримуємо під’їзди та стартуємо WebSocket
|
// Якщо це сторінка будинку, отримуємо під’їзди та стартуємо WebSocket
|
||||||
if (type === "house") {
|
if (type === "house") {
|
||||||
const controls = document.getElementById('page-card-controls');
|
const controls = document.getElementById('page-card-controls');
|
||||||
@@ -45,6 +37,13 @@ const Territory_card = {
|
|||||||
this.getHomestead.map({});
|
this.getHomestead.map({});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ids = ['cloud_1', 'cloud_2', 'cloud_3'];
|
||||||
|
ids.forEach((id, idx) => {
|
||||||
|
const el = document.getElementById(id);
|
||||||
|
if(!el) return;
|
||||||
|
el.setAttribute('data-state', ['sync', 'ok', 'err'].indexOf(Cloud.status) === idx ? 'active' : '');
|
||||||
|
});
|
||||||
|
|
||||||
// Додаємо обробник закриття попапу
|
// Додаємо обробник закриття попапу
|
||||||
const popup = document.getElementById('card-new-date');
|
const popup = document.getElementById('card-new-date');
|
||||||
if (!popup.dataset.listenerAdded) {
|
if (!popup.dataset.listenerAdded) {
|
||||||
@@ -59,71 +58,6 @@ const Territory_card = {
|
|||||||
|
|
||||||
// Робота з WebSocket
|
// Робота з WebSocket
|
||||||
cloud: {
|
cloud: {
|
||||||
start() {
|
|
||||||
const uuid = localStorage.getItem("uuid");
|
|
||||||
const ws = new WebSocket(CONFIG.wss, uuid);
|
|
||||||
Territory_card.socket = ws;
|
|
||||||
|
|
||||||
ws.onopen = () => {
|
|
||||||
console.log("[WebSocket] З'єднання встановлено");
|
|
||||||
Territory_card.cloud.setStatus('ok');
|
|
||||||
ws.send(JSON.stringify({
|
|
||||||
event: 'connection',
|
|
||||||
id: getTimeInSeconds(),
|
|
||||||
date: getTimeInSeconds(),
|
|
||||||
uuid,
|
|
||||||
user: {
|
|
||||||
name: USER.name,
|
|
||||||
id: USER.id
|
|
||||||
},
|
|
||||||
data: {}
|
|
||||||
}));
|
|
||||||
Territory_card.reconnectAttempts = 0;
|
|
||||||
clearTimeout(Territory_card.reconnectTimeout);
|
|
||||||
};
|
|
||||||
|
|
||||||
ws.onmessage = (e) => {
|
|
||||||
const data = JSON.parse(e.data);
|
|
||||||
if (data.event === 'connection' && data.user.id !== USER.id) {
|
|
||||||
console.log(`Новий користувач: ${data.user}`);
|
|
||||||
}
|
|
||||||
if (data.event === 'message') {
|
|
||||||
Territory_card.cloud.update(data);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ws.onclose = () => {
|
|
||||||
console.warn("[WebSocket] З'єднання розірвано");
|
|
||||||
Territory_card.cloud.setStatus('err');
|
|
||||||
Territory_card.reconnectAttempts++;
|
|
||||||
if (Territory_card.reconnectAttempts <= 5) {
|
|
||||||
Territory_card.reconnectTimeout = setTimeout(() => {
|
|
||||||
Territory_card.getEntrances({ update: true });
|
|
||||||
Territory_card.cloud.start();
|
|
||||||
}, 1000);
|
|
||||||
} else {
|
|
||||||
if (confirm("З'єднання розірвано! Перепідключитись?")) {
|
|
||||||
Territory_card.reconnectAttempts = 0;
|
|
||||||
Territory_card.getEntrances({ update: true });
|
|
||||||
Territory_card.cloud.start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ws.onerror = (err) => {
|
|
||||||
console.error("[WebSocket] Помилка", err);
|
|
||||||
Territory_card.cloud.setStatus('err');
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
setStatus(mode) {
|
|
||||||
const ids = ['cloud_1', 'cloud_2', 'cloud_3'];
|
|
||||||
ids.forEach((id, idx) => {
|
|
||||||
const el = document.getElementById(id);
|
|
||||||
el.setAttribute('data-state', ['sync', 'ok', 'err'].indexOf(mode) === idx ? 'active' : '');
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
update(msg) {
|
update(msg) {
|
||||||
if (msg.type !== "apartment" && msg.type !== "building") return;
|
if (msg.type !== "apartment" && msg.type !== "building") return;
|
||||||
|
|
||||||
@@ -189,25 +123,20 @@ const Territory_card = {
|
|||||||
|
|
||||||
const message = {
|
const message = {
|
||||||
event: 'message',
|
event: 'message',
|
||||||
id: getTimeInSeconds(),
|
|
||||||
date: getTimeInSeconds(),
|
|
||||||
user: {
|
user: {
|
||||||
name: USER.name,
|
name: USER.name,
|
||||||
id: USER.id
|
id: USER.id
|
||||||
},
|
},
|
||||||
type: "apartment",
|
type: "apartment",
|
||||||
data: {
|
data: apt
|
||||||
...apt,
|
|
||||||
sheep_id: USER.id
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Territory_card.socket?.readyState === WebSocket.OPEN) {
|
if (Cloud.socket?.readyState === WebSocket.OPEN) {
|
||||||
Territory_card.socket.send(JSON.stringify(message));
|
Cloud.socket.send(JSON.stringify(message));
|
||||||
} else {
|
} else {
|
||||||
if (confirm("З'єднання розірвано! Перепідключитись?")) {
|
if (confirm("З'єднання розірвано! Перепідключитись?")) {
|
||||||
Territory_card.getEntrances({ update: true });
|
Territory_card.getEntrances({ update: true });
|
||||||
Territory_card.cloud.start();
|
Cloud.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -241,21 +170,16 @@ const Territory_card = {
|
|||||||
|
|
||||||
const message = {
|
const message = {
|
||||||
event: 'message',
|
event: 'message',
|
||||||
id: getTimeInSeconds(),
|
|
||||||
date: getTimeInSeconds(),
|
|
||||||
user: {
|
user: {
|
||||||
name: USER.name,
|
name: USER.name,
|
||||||
id: USER.id
|
id: USER.id
|
||||||
},
|
},
|
||||||
type: "building",
|
type: "building",
|
||||||
data: {
|
data: apt
|
||||||
...apt,
|
|
||||||
sheep_id: USER.id
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Territory_card.socket?.readyState === WebSocket.OPEN) {
|
if (Cloud.socket?.readyState === WebSocket.OPEN) {
|
||||||
Territory_card.socket.send(JSON.stringify(message));
|
Cloud.socket.send(JSON.stringify(message));
|
||||||
} else {
|
} else {
|
||||||
if (confirm("З'єднання розірвано! Перепідключитись?")) {
|
if (confirm("З'єднання розірвано! Перепідключитись?")) {
|
||||||
Territory_card.getEntrances({ update: true });
|
Territory_card.getEntrances({ update: true });
|
||||||
@@ -434,9 +358,9 @@ const Territory_card = {
|
|||||||
let lng = data.geo?.lng ?? data.points?.[0]?.[0]?.[0]?.lng ?? 25.6145625;
|
let lng = data.geo?.lng ?? data.points?.[0]?.[0]?.[0]?.lng ?? 25.6145625;
|
||||||
let zoom = 15;
|
let zoom = 15;
|
||||||
|
|
||||||
if (map_card && map_Territory_card.remove) {
|
if (map_card && map_card.remove) {
|
||||||
map_Territory_card.stopLocate();
|
map_card.stopLocate();
|
||||||
map_Territory_card.remove();
|
map_card.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapElement = document.getElementById('map_card');
|
const mapElement = document.getElementById('map_card');
|
||||||
@@ -471,13 +395,13 @@ const Territory_card = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// слежение в реальном времени
|
// слежение в реальном времени
|
||||||
map_Territory_card.locate({ setView: false, watch: true, enableHighAccuracy: true });
|
map_card.locate({ setView: false, watch: true, enableHighAccuracy: true });
|
||||||
map_Territory_card.on('locationfound', (e) => {
|
map_card.on('locationfound', (e) => {
|
||||||
if (!map_Territory_card._userMarker) {
|
if (!map_card._userMarker) {
|
||||||
map_Territory_card._userMarker = L.marker(e.latlng).addTo(map_card)
|
map_card._userMarker = L.marker(e.latlng).addTo(map_card)
|
||||||
.bindPopup("Ви тут!");
|
.bindPopup("Ви тут!");
|
||||||
} else {
|
} else {
|
||||||
map_Territory_card._userMarker.setLatLng(e.latlng);
|
map_card._userMarker.setLatLng(e.latlng);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -489,7 +413,7 @@ const Territory_card = {
|
|||||||
|
|
||||||
let layerControl = L.control.layers(baseMaps, [], { position: 'bottomright' }).addTo(map_card);
|
let layerControl = L.control.layers(baseMaps, [], { position: 'bottomright' }).addTo(map_card);
|
||||||
|
|
||||||
map_Territory_card.pm.setLang("ua");
|
map_card.pm.setLang("ua");
|
||||||
|
|
||||||
const polygonOptions = {
|
const polygonOptions = {
|
||||||
color: "#f2bd53",
|
color: "#f2bd53",
|
||||||
@@ -501,9 +425,9 @@ const Territory_card = {
|
|||||||
|
|
||||||
L.polygon(data.points, polygonOptions).addTo(map_card);
|
L.polygon(data.points, polygonOptions).addTo(map_card);
|
||||||
|
|
||||||
map_Territory_card.setZoom(data.zoom);
|
map_card.setZoom(data.zoom);
|
||||||
|
|
||||||
// map_Territory_card.getZoom()
|
// map_card.getZoom()
|
||||||
|
|
||||||
// console.log(data.zoom);
|
// console.log(data.zoom);
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,10 @@ Router
|
|||||||
pageActive('schedule');
|
pageActive('schedule');
|
||||||
Schedule.init();;
|
Schedule.init();;
|
||||||
})
|
})
|
||||||
|
.add('stand/constructor', function () {
|
||||||
|
pageActive();
|
||||||
|
Stand_constructor.init();;
|
||||||
|
})
|
||||||
.add('stand/card/(.*)', function (id) {
|
.add('stand/card/(.*)', function (id) {
|
||||||
pageActive();
|
pageActive();
|
||||||
Stand_card.init(id);;
|
Stand_card.init(id);;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ app.use(express.static(__dirname));
|
|||||||
|
|
||||||
// Обработка 404 ошибки
|
// Обработка 404 ошибки
|
||||||
app.use((req, res) => {
|
app.use((req, res) => {
|
||||||
res.status(404).sendFile(path.join(__dirname, "index.html"));
|
res.sendFile(path.join(__dirname, "index.html"));
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
|
|||||||
186
web/sw.js
186
web/sw.js
@@ -1,56 +1,158 @@
|
|||||||
self.addEventListener('install', async event => {
|
const STATIC_CACHE_NAME = 'v2.0.1';
|
||||||
|
|
||||||
})
|
const FILES_TO_CACHE = [
|
||||||
|
'/',
|
||||||
|
"/css/main.css",
|
||||||
|
"/config.js",
|
||||||
|
"/lib/router/router.js",
|
||||||
|
"/lib/router/routes.js",
|
||||||
|
|
||||||
self.addEventListener('activate', async event => {
|
"/lib/components/leaflet/leaflet.css",
|
||||||
|
"/lib/components/leaflet/leaflet.js",
|
||||||
|
|
||||||
})
|
"/lib/components/geoman/leaflet-geoman.css",
|
||||||
|
"/lib/components/geoman/leaflet-geoman.min.js",
|
||||||
|
|
||||||
self.addEventListener('fetch', event => {
|
"/lib/components/turf.min.js",
|
||||||
|
|
||||||
})
|
"/lib/components/cloud.js",
|
||||||
|
|
||||||
// Обработка входящих push-сообщений
|
"/lib/components/clipboard.js",
|
||||||
self.addEventListener("push", event => {
|
"/lib/components/colorGroup.js",
|
||||||
let data = {};
|
"/lib/components/makeid.js",
|
||||||
try {
|
"/lib/components/swipeUpdater.js",
|
||||||
data = event.data.json(); // если сервер прислал JSON
|
"/lib/components/detectBrowser.js",
|
||||||
} catch {
|
"/lib/components/detectOS.js",
|
||||||
data = { title: "Уведомление", body: event.data?.text() };
|
"/lib/components/formattedDate.js",
|
||||||
}
|
"/lib/components/setLeafletCursor.js",
|
||||||
|
"/lib/components/webPush.js",
|
||||||
|
|
||||||
console.log(data);
|
"/lib/pages/auth/script.js",
|
||||||
|
"/lib/pages/auth/style.css",
|
||||||
|
|
||||||
|
"/lib/pages/home/script.js",
|
||||||
|
"/lib/pages/home/style.css",
|
||||||
|
|
||||||
const title = data.title || "Уведомление";
|
"/lib/pages/territory/list/script.js",
|
||||||
const options = {
|
"/lib/pages/territory/list/style.css",
|
||||||
body: data.body || "",
|
|
||||||
icon: "/img/icon.png", // иконка уведомления
|
|
||||||
badge: "/img/badge.png", // маленький значок (Android)
|
|
||||||
data: data.url || "/" // можно передать URL
|
|
||||||
};
|
|
||||||
|
|
||||||
|
"/lib/pages/territory/manager/script.js",
|
||||||
|
"/lib/pages/territory/manager/style.css",
|
||||||
|
|
||||||
|
"/lib/pages/territory/history/script.js",
|
||||||
|
"/lib/pages/territory/history/style.css",
|
||||||
|
|
||||||
|
"/lib/pages/territory/constructor/script.js",
|
||||||
|
"/lib/pages/territory/constructor/style.css",
|
||||||
|
|
||||||
|
"/lib/pages/territory/editor/script.js",
|
||||||
|
"/lib/pages/territory/editor/style.css",
|
||||||
|
|
||||||
|
"/lib/pages/territory/card/script.js",
|
||||||
|
"/lib/pages/territory/card/style.css",
|
||||||
|
|
||||||
|
"/lib/pages/options/script.js",
|
||||||
|
"/lib/pages/options/style.css",
|
||||||
|
|
||||||
|
"/lib/pages/sheeps/script.js",
|
||||||
|
"/lib/pages/sheeps/style.css",
|
||||||
|
|
||||||
|
"/lib/pages/stand/list/script.js",
|
||||||
|
"/lib/pages/stand/list/style.css",
|
||||||
|
|
||||||
|
"/lib/pages/stand/card/script.js",
|
||||||
|
"/lib/pages/stand/card/style.css",
|
||||||
|
|
||||||
|
"/lib/pages/stand/constructor/script.js",
|
||||||
|
"/lib/pages/stand/constructor/style.css",
|
||||||
|
|
||||||
|
"/lib/pages/schedule/script.js",
|
||||||
|
"/lib/pages/schedule/style.css",
|
||||||
|
|
||||||
|
"/lib/app.js"
|
||||||
|
];
|
||||||
|
|
||||||
|
// ----------------------- INSTALL -----------------------
|
||||||
|
self.addEventListener('install', event => {
|
||||||
event.waitUntil(
|
event.waitUntil(
|
||||||
self.registration.showNotification(title, options)
|
caches.open(STATIC_CACHE_NAME).then(cache => {
|
||||||
);
|
return Promise.all(FILES_TO_CACHE.map(url =>
|
||||||
});
|
fetch(url).then(res => {
|
||||||
|
if (!res.ok) throw new Error(`${url} not found`);
|
||||||
// Обработка клика по уведомлению
|
return cache.put(url, res);
|
||||||
self.addEventListener("notificationclick", event => {
|
}).catch(err => console.warn(err))
|
||||||
event.notification.close();
|
));
|
||||||
|
|
||||||
event.waitUntil(
|
|
||||||
clients.matchAll({ type: "window", includeUncontrolled: true }).then(clientList => {
|
|
||||||
// если вкладка уже открыта — фокусируем её
|
|
||||||
for (const client of clientList) {
|
|
||||||
if (client.url === event.notification.data && "focus" in client) {
|
|
||||||
return client.focus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// иначе открываем новую вкладку
|
|
||||||
if (clients.openWindow) {
|
|
||||||
return clients.openWindow(event.notification.data);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------- ACTIVATE -----------------------
|
||||||
|
self.addEventListener('activate', event => {
|
||||||
|
event.waitUntil(
|
||||||
|
caches.keys().then(keys => {
|
||||||
|
return Promise.all(keys.map(key => {
|
||||||
|
if (key !== STATIC_CACHE_NAME) return caches.delete(key);
|
||||||
|
}));
|
||||||
|
}).then(() => self.clients.claim())
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ----------------------- FETCH -----------------------
|
||||||
|
self.addEventListener('fetch', event => {
|
||||||
|
event.respondWith(
|
||||||
|
caches.match(event.request).then(cached => cached ?? fetch(event.request))
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ----------------------- PUSH -----------------------
|
||||||
|
self.addEventListener("push", event => {
|
||||||
|
let data = {};
|
||||||
|
try { data = event.data.json(); } catch { data = { title: "Уведомлення", body: event.data?.text() }; }
|
||||||
|
|
||||||
|
const title = data.title || "Уведомлення";
|
||||||
|
const options = {
|
||||||
|
body: data.body || "",
|
||||||
|
icon: "/img/icon.png",
|
||||||
|
badge: "/img/badge.png",
|
||||||
|
data: data.url || "/"
|
||||||
|
};
|
||||||
|
|
||||||
|
event.waitUntil(self.registration.showNotification(title, options));
|
||||||
|
});
|
||||||
|
|
||||||
|
self.addEventListener("notificationclick", event => {
|
||||||
|
event.notification.close();
|
||||||
|
event.waitUntil(
|
||||||
|
clients.matchAll({ type: "window", includeUncontrolled: true }).then(clientList => {
|
||||||
|
for (const client of clientList) {
|
||||||
|
if (client.url === event.notification.data && "focus" in client) return client.focus();
|
||||||
|
}
|
||||||
|
if (clients.openWindow) return clients.openWindow(event.notification.data);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ----------------------- UPDATE CACHE -----------------------
|
||||||
|
self.addEventListener('message', event => {
|
||||||
|
if (event.data === 'skipWaiting') {
|
||||||
|
self.skipWaiting(); // активує новий воркер, але не оновлює кеш автоматично
|
||||||
|
}
|
||||||
|
if (event.data === 'updateCache') {
|
||||||
|
updateALL(); // кеш оновлюється тільки після натискання на банер
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
async function updateALL() {
|
||||||
|
const cacheNames = await caches.keys();
|
||||||
|
await Promise.all(cacheNames.map(name => caches.delete(name)));
|
||||||
|
|
||||||
|
const cache = await caches.open(STATIC_CACHE_NAME);
|
||||||
|
await Promise.all(FILES_TO_CACHE.map(url =>
|
||||||
|
fetch(url).then(res => {
|
||||||
|
if (!res.ok) throw new Error(`${url} not found`);
|
||||||
|
return cache.put(url, res);
|
||||||
|
}).catch(err => console.warn(err))
|
||||||
|
));
|
||||||
|
console.log('All caches updated');
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
const { updateApartment } = require("../services/apartments.service");
|
const { updateApartment } = require("../services/apartments.service");
|
||||||
const { updateBuilding } = require("../services/buildings.service");
|
const { updateBuilding } = require("../services/buildings.service");
|
||||||
const { updateStand } = require("../services/stand.service");
|
const { lockingStand, unlockingStand, updateStand } = require("../services/stand.service");
|
||||||
const { broadcast } = require("../utils/broadcaster");
|
const { broadcast } = require("../utils/broadcaster");
|
||||||
|
|
||||||
module.exports = async (wss, ws, message) => {
|
module.exports = async (wss, ws, message) => {
|
||||||
@@ -12,8 +12,17 @@ module.exports = async (wss, ws, message) => {
|
|||||||
case "building":
|
case "building":
|
||||||
await updateBuilding(ws.user, message.data);
|
await updateBuilding(ws.user, message.data);
|
||||||
break;
|
break;
|
||||||
case "stand":
|
case "stand_locking":
|
||||||
|
await lockingStand(ws.user, message.data);
|
||||||
|
if(!message.data.sheep_name) message.data.sheep_name = ws.user.name;
|
||||||
|
break;
|
||||||
|
case "stand_unlocking":
|
||||||
|
await unlockingStand(ws.user, message.data);
|
||||||
|
if(!message.data.sheep_name) message.data.sheep_name = ws.user.name;
|
||||||
|
break;
|
||||||
|
case "stand_update":
|
||||||
await updateStand(ws.user, message.data);
|
await updateStand(ws.user, message.data);
|
||||||
|
if(!message.data.sheep_name) message.data.sheep_name = ws.user.name;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return ws.send(JSON.stringify({ error: `Unknown message type: ${message.type}` }));
|
return ws.send(JSON.stringify({ error: `Unknown message type: ${message.type}` }));
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ function updateApartment(user, data) {
|
|||||||
SET status = ?, description = ?, sheep_id = ?, updated_at = ?
|
SET status = ?, description = ?, sheep_id = ?, updated_at = ?
|
||||||
WHERE id = ?`;
|
WHERE id = ?`;
|
||||||
|
|
||||||
db.run(sql, [Number(data.status), data.description, data.sheep_id, data.updated_at, data.id], function (err) {
|
db.run(sql, [Number(data.status), data.description, user.id, data.updated_at, data.id], function (err) {
|
||||||
if (err) return reject(err);
|
if (err) return reject(err);
|
||||||
if (this.changes === 0) return reject(new Error("Apartment not found"));
|
if (this.changes === 0) return reject(new Error("Apartment not found"));
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ function updateApartment(user, data) {
|
|||||||
(apartments_id, status, description, sheep_id, created_at)
|
(apartments_id, status, description, sheep_id, created_at)
|
||||||
VALUES (?, ?, ?, ?, ?)`;
|
VALUES (?, ?, ?, ?, ?)`;
|
||||||
|
|
||||||
db.run(insertSql, [Number(data.id), Number(data.status), data.description, data.sheep_id, Date.now()], function (err) {
|
db.run(insertSql, [Number(data.id), Number(data.status), data.description, user.id, Date.now()], function (err) {
|
||||||
if (err) return reject(err);
|
if (err) return reject(err);
|
||||||
resolve({ update: "ok", id: data.id, historyId: this.lastID });
|
resolve({ update: "ok", id: data.id, historyId: this.lastID });
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ function updateBuilding(user, data) {
|
|||||||
SET status = ?, description = ?, sheep_id = ?, updated_at = ?
|
SET status = ?, description = ?, sheep_id = ?, updated_at = ?
|
||||||
WHERE id = ?`;
|
WHERE id = ?`;
|
||||||
|
|
||||||
db.run(sql, [Number(data.status), data.description, data.sheep_id, data.updated_at, data.id], function (err) {
|
db.run(sql, [Number(data.status), data.description, user.id, data.updated_at, data.id], function (err) {
|
||||||
if (err) return reject(err);
|
if (err) return reject(err);
|
||||||
if (this.changes === 0) return reject(new Error("Building not found"));
|
if (this.changes === 0) return reject(new Error("Building not found"));
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ function updateBuilding(user, data) {
|
|||||||
(buildings_id, status, description, sheep_id, created_at)
|
(buildings_id, status, description, sheep_id, created_at)
|
||||||
VALUES (?, ?, ?, ?, ?)`;
|
VALUES (?, ?, ?, ?, ?)`;
|
||||||
|
|
||||||
db.run(insertSql, [Number(data.id), Number(data.status), data.description, data.sheep_id, Date.now()], function (err) {
|
db.run(insertSql, [Number(data.id), Number(data.status), data.description, user.id, Date.now()], function (err) {
|
||||||
if (err) return reject(err);
|
if (err) return reject(err);
|
||||||
resolve({ update: "ok", id: data.id, historyId: this.lastID });
|
resolve({ update: "ok", id: data.id, historyId: this.lastID });
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,26 +1,61 @@
|
|||||||
const db = require("../config/db");
|
const db = require("../config/db");
|
||||||
|
|
||||||
|
function lockingStand(user, data) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const sheepId = Number(data.sheep_id) || null;
|
||||||
|
|
||||||
|
if (!user.possibilities.can_view_stand) {
|
||||||
|
return reject(new Error("Forbidden: no rights to view stand"));
|
||||||
|
}
|
||||||
|
if ((sheepId !== user.id && sheepId !== null) && !user.possibilities.can_manager_stand) {
|
||||||
|
return reject(new Error("Forbidden: no rights to view stand"));
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve({ update: "ok", id: data.id });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function unlockingStand(user, data) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const sheepId = Number(data.sheep_id) || null;
|
||||||
|
|
||||||
|
if (!user.possibilities.can_view_stand) {
|
||||||
|
return reject(new Error("Forbidden: no rights to view stand"));
|
||||||
|
}
|
||||||
|
if ((sheepId !== user.id && sheepId !== null) && !user.possibilities.can_manager_stand) {
|
||||||
|
return reject(new Error("Forbidden: no rights to view stand"));
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve({ update: "ok", id: data.id });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function updateStand(user, data) {
|
function updateStand(user, data) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!user.possibilities.can_manager_territory) {
|
const sheepId = Number(data.sheep_id) || null;
|
||||||
return reject(new Error("Forbidden: no rights to manage territory"));
|
|
||||||
|
if (!user.possibilities.can_view_stand) {
|
||||||
|
return reject(new Error("Forbidden: no rights to view stand"));
|
||||||
|
}
|
||||||
|
if ((sheepId !== user.id && sheepId !== null) && !user.possibilities.can_manager_stand) {
|
||||||
|
return reject(new Error("Forbidden: no rights to view stand"));
|
||||||
}
|
}
|
||||||
|
|
||||||
const sql = `
|
const sql = `
|
||||||
UPDATE buildings
|
UPDATE stand_schedule
|
||||||
SET status = ?, description = ?, sheep_id = ?, updated_at = ?
|
SET sheep_id = ?, updated_at = ?
|
||||||
WHERE id = ?`;
|
WHERE id = ?`;
|
||||||
|
|
||||||
db.run(sql, [Number(data.status), data.description, data.sheep_id, data.updated_at, data.id], function (err) {
|
db.run(sql, [sheepId, Date.now(), data.id], function (err) {
|
||||||
if (err) return reject(err);
|
if (err) return reject(err);
|
||||||
if (this.changes === 0) return reject(new Error("Building not found"));
|
if (this.changes === 0) return reject(new Error("Stand not found"));
|
||||||
|
|
||||||
const insertSql = `
|
const insertSql = `
|
||||||
INSERT INTO buildings_history
|
INSERT INTO stand_schedule_history
|
||||||
(buildings_id, status, description, sheep_id, created_at)
|
(stand_schedule_id, sheep_id, created_at)
|
||||||
VALUES (?, ?, ?, ?, ?)`;
|
VALUES (?, ?, ?)`;
|
||||||
|
|
||||||
db.run(insertSql, [Number(data.id), Number(data.status), data.description, data.sheep_id, Date.now()], function (err) {
|
db.run(insertSql, [Number(data.id), sheepId, Date.now()], function (err) {
|
||||||
if (err) return reject(err);
|
if (err) return reject(err);
|
||||||
resolve({ update: "ok", id: data.id, historyId: this.lastID });
|
resolve({ update: "ok", id: data.id, historyId: this.lastID });
|
||||||
});
|
});
|
||||||
@@ -28,4 +63,4 @@ function updateStand(user, data) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { updateStand };
|
module.exports = { lockingStand, unlockingStand, updateStand };
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
FROM node:20.18
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY package.json package-lock.json ./
|
|
||||||
|
|
||||||
RUN npm install
|
|
||||||
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
EXPOSE 4001
|
|
||||||
|
|
||||||
CMD npm start
|
|
||||||
1644
ws_old/package-lock.json
generated
1644
ws_old/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "WS Sheep Service",
|
|
||||||
"version": "1.0.1",
|
|
||||||
"main": "ws.js",
|
|
||||||
"scripts": {
|
|
||||||
"start": "node ws.js"
|
|
||||||
},
|
|
||||||
"keywords": [],
|
|
||||||
"author": "",
|
|
||||||
"license": "ISC",
|
|
||||||
"description": "",
|
|
||||||
"dependencies": {
|
|
||||||
"sqlite3": "^5.1.7",
|
|
||||||
"url": "^0.11.4",
|
|
||||||
"ws": "^8.18.0",
|
|
||||||
"dotenv": "^17.2.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
260
ws_old/ws.js
260
ws_old/ws.js
@@ -1,260 +0,0 @@
|
|||||||
const WebSocket = require("ws");
|
|
||||||
const { URL } = require('url');
|
|
||||||
const sqlite3 = require('sqlite3');
|
|
||||||
const path = require('path');
|
|
||||||
require("dotenv").config();
|
|
||||||
|
|
||||||
const dbPath = process.env.DATABASE_PATH || '../';
|
|
||||||
const db = new sqlite3.Database(path.join(dbPath, 'database.sqlite'));
|
|
||||||
|
|
||||||
const port = 4004;
|
|
||||||
const api_version = '1.0.0';
|
|
||||||
|
|
||||||
const wss = new WebSocket.Server({
|
|
||||||
port: port
|
|
||||||
}, () => console.log(`Server started on port ${port}`));
|
|
||||||
|
|
||||||
|
|
||||||
wss.on('connection', async (ws, request) => {
|
|
||||||
const url = new URL(request.url, `http://${request.headers.host}`)
|
|
||||||
const params = Object.fromEntries(url.searchParams.entries());
|
|
||||||
const uuid = params.uuid;
|
|
||||||
|
|
||||||
if (!uuid) return
|
|
||||||
|
|
||||||
let check = await checkUUID(uuid);
|
|
||||||
|
|
||||||
console.log(check);
|
|
||||||
|
|
||||||
|
|
||||||
if (!check && check.possibilities.can_view_territory) return
|
|
||||||
|
|
||||||
// Periodic ping to maintain a connection
|
|
||||||
const pingInterval = setInterval(() => {
|
|
||||||
if (ws.readyState === WebSocket.OPEN) {
|
|
||||||
ws.ping('ping');
|
|
||||||
}
|
|
||||||
}, 30000);
|
|
||||||
|
|
||||||
|
|
||||||
ws.send(JSON.stringify({ "connection": "success", "api_version": api_version }));
|
|
||||||
|
|
||||||
ws.on('message', (message) => {
|
|
||||||
message = JSON.parse(message);
|
|
||||||
|
|
||||||
console.log(message.username, check.name);
|
|
||||||
|
|
||||||
switch (message.event) {
|
|
||||||
case "connection":
|
|
||||||
broadcastMessage(message);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "message":
|
|
||||||
updateDatabase(message);
|
|
||||||
broadcastMessage(message);
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
ws.on('pong', (data) => {
|
|
||||||
console.log('PONG received from the client:', data.toString());
|
|
||||||
});
|
|
||||||
|
|
||||||
ws.on('close', () => {
|
|
||||||
console.log('Client close');
|
|
||||||
});
|
|
||||||
|
|
||||||
ws.on('error', (err) => {
|
|
||||||
console.error('ERROR WebSocket:', err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
function broadcastMessage(message) {
|
|
||||||
wss.clients.forEach(client => {
|
|
||||||
if (client.readyState === WebSocket.OPEN) {
|
|
||||||
client.send(JSON.stringify(message));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateDatabase(message) {
|
|
||||||
|
|
||||||
console.log(message.type);
|
|
||||||
|
|
||||||
|
|
||||||
if (message.type === "apartment") {
|
|
||||||
|
|
||||||
let sql = 'UPDATE apartments SET status = ?, description = ?, sheep_id = ?, updated_at = ? WHERE id = ?';
|
|
||||||
|
|
||||||
db.run(sql, [
|
|
||||||
Number(message.data.status),
|
|
||||||
message.data.description,
|
|
||||||
message.data.sheep_id,
|
|
||||||
message.data.updated_at,
|
|
||||||
message.data.id
|
|
||||||
], function (err) {
|
|
||||||
if (err) {
|
|
||||||
console.error(err.message);
|
|
||||||
} else if (this.changes === 0) {
|
|
||||||
console.error('Product not found');
|
|
||||||
} else {
|
|
||||||
console.log({ "update": "ok", "id": message.data.id });
|
|
||||||
|
|
||||||
let sql = `INSERT INTO apartments_history (apartments_id, status, description, sheep_id, created_at) VALUES (?, ?, ?, ?, ?)`;
|
|
||||||
|
|
||||||
db.run(sql, [
|
|
||||||
Number(message.data.id),
|
|
||||||
Number(message.data.status),
|
|
||||||
message.data.description,
|
|
||||||
message.data.sheep_id,
|
|
||||||
Math.floor(Date.now())
|
|
||||||
], function (err) {
|
|
||||||
if (err) {
|
|
||||||
console.error(err.message);
|
|
||||||
} else if (this.changes === 0) {
|
|
||||||
console.error('Apartments not found');
|
|
||||||
} else {
|
|
||||||
console.log({ "insert": "ok", "id": this.lastID });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if(message.type === "building") {
|
|
||||||
let sql = 'UPDATE buildings SET status = ?, description = ?, sheep_id = ?, updated_at = ? WHERE id = ?';
|
|
||||||
|
|
||||||
db.run(sql, [
|
|
||||||
Number(message.data.status),
|
|
||||||
message.data.description,
|
|
||||||
message.data.sheep_id,
|
|
||||||
message.data.updated_at,
|
|
||||||
message.data.id
|
|
||||||
], function (err) {
|
|
||||||
if (err) {
|
|
||||||
console.error(err.message);
|
|
||||||
} else if (this.changes === 0) {
|
|
||||||
console.error('Product not found');
|
|
||||||
} else {
|
|
||||||
console.log({ "update": "ok", "id": message.data.id });
|
|
||||||
|
|
||||||
let sql = `INSERT INTO buildings_history (buildings_id, status, description, sheep_id, created_at) VALUES (?, ?, ?, ?, ?)`;
|
|
||||||
|
|
||||||
db.run(sql, [
|
|
||||||
Number(message.data.id),
|
|
||||||
Number(message.data.status),
|
|
||||||
message.data.description,
|
|
||||||
message.data.sheep_id,
|
|
||||||
Math.floor(Date.now())
|
|
||||||
], function (err) {
|
|
||||||
if (err) {
|
|
||||||
console.error(err.message);
|
|
||||||
} else if (this.changes === 0) {
|
|
||||||
console.error('Apartments not found');
|
|
||||||
} else {
|
|
||||||
console.log({ "insert": "ok", "id": this.lastID });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if(message.type === "stand") {
|
|
||||||
let sql = 'UPDATE stand SET status = ?, sheep_id = ?, updated_at = ? WHERE id = ?';
|
|
||||||
|
|
||||||
db.run(sql, [
|
|
||||||
Number(message.data.status),
|
|
||||||
message.data.sheep_id,
|
|
||||||
message.data.updated_at,
|
|
||||||
message.data.id
|
|
||||||
], function (err) {
|
|
||||||
if (err) {
|
|
||||||
console.error(err.message);
|
|
||||||
} else if (this.changes === 0) {
|
|
||||||
console.error('Product not found');
|
|
||||||
} else {
|
|
||||||
console.log({ "update": "ok", "id": message.data.id });
|
|
||||||
|
|
||||||
let sql = `INSERT INTO stand_history (stand_id, status, sheep_id, created_at) VALUES (?, ?, ?, ?, ?)`;
|
|
||||||
|
|
||||||
db.run(sql, [
|
|
||||||
Number(message.data.id),
|
|
||||||
Number(message.data.status),
|
|
||||||
message.data.sheep_id,
|
|
||||||
Math.floor(Date.now())
|
|
||||||
], function (err) {
|
|
||||||
if (err) {
|
|
||||||
console.error(err.message);
|
|
||||||
} else if (this.changes === 0) {
|
|
||||||
console.error('Stand not found');
|
|
||||||
} else {
|
|
||||||
console.log({ "insert": "ok", "id": this.lastID });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function checkUUID(uuid) {
|
|
||||||
return new Promise((res, rej) => {
|
|
||||||
db.get(`
|
|
||||||
SELECT
|
|
||||||
sheeps.*,
|
|
||||||
possibilities.can_view_territory AS can_view_territory
|
|
||||||
FROM
|
|
||||||
sheeps
|
|
||||||
LEFT JOIN
|
|
||||||
possibilities ON possibilities.sheep_id = sheeps.id
|
|
||||||
WHERE
|
|
||||||
sheeps.uuid_manager = ?`,
|
|
||||||
[uuid],
|
|
||||||
(err, moderator) => {
|
|
||||||
if (moderator) {
|
|
||||||
let data = {
|
|
||||||
id: moderator.sheep_id,
|
|
||||||
group_id: moderator.group_id,
|
|
||||||
name: moderator.name,
|
|
||||||
icon: moderator.icon,
|
|
||||||
uuid: moderator.uuid,
|
|
||||||
appointment: moderator.appointment,
|
|
||||||
sheepRole: moderator.mode_title,
|
|
||||||
possibilities: {
|
|
||||||
can_view_territory: moderator.can_view_territory == 1 ? true : false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
db.get(`
|
|
||||||
SELECT
|
|
||||||
sheeps.*,
|
|
||||||
possibilities.can_view_territory AS can_view_territory
|
|
||||||
FROM
|
|
||||||
sheeps
|
|
||||||
LEFT JOIN
|
|
||||||
possibilities ON possibilities.sheep_id = sheeps.id
|
|
||||||
WHERE
|
|
||||||
sheeps.uuid = ?`,
|
|
||||||
[uuid],
|
|
||||||
(err, sheep) => {
|
|
||||||
if (sheep) {
|
|
||||||
let data = {
|
|
||||||
id: sheep.sheep_id,
|
|
||||||
group_id: sheep.group_id,
|
|
||||||
name: sheep.name,
|
|
||||||
icon: sheep.icon,
|
|
||||||
uuid: sheep.uuid,
|
|
||||||
appointment: sheep.appointment,
|
|
||||||
sheepRole: sheep.mode_title,
|
|
||||||
possibilities: {
|
|
||||||
can_view_territory: sheep.can_view_territory == 1 ? true : false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
return res(false);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user