From 7312ebe55f58af2b9578ce26ced7810ad66bb19a Mon Sep 17 00:00:00 2001 From: zakhy Date: Mon, 7 Jul 2025 16:17:06 +0700 Subject: [PATCH 1/6] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BD=D0=B5=D1=81?= =?UTF-8?q?=20=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA=D1=83=20=D0=B8=D1=81=D1=85?= =?UTF-8?q?=D0=BE=D0=B4=D1=8F=20=D0=B8=D0=B7=20=D1=82=D1=80=D0=B5=D0=B1?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B9=20=D0=BF=D0=BE=20=D0=B7?= =?UTF-8?q?=D0=B0=D1=8F=D0=B2=D0=BA=D0=B5=203458?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/management/templates/settings.html | 31 +++++++++++++++---------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/apps/management/templates/settings.html b/apps/management/templates/settings.html index 7b146c4..7fc4d5a 100644 --- a/apps/management/templates/settings.html +++ b/apps/management/templates/settings.html @@ -59,10 +59,8 @@
- Изображения -
-
- Опасные зоны + Опасные + зоны
- Управление загрузкой данных + Управление + загрузкой данных
- Настройка отображения + Настройка + отображения +
+ +
+ +
+
Управление загрузкой данных From b905f490223dd1feaf19299d948c61189e6bed1a Mon Sep 17 00:00:00 2001 From: zakhy <=> Date: Tue, 8 Jul 2025 11:23:54 +0700 Subject: [PATCH 3/6] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=20=D0=BF=D0=BE=D0=BB=D0=B5=20=D0=B2=D0=B2?= =?UTF-8?q?=D0=BE=D0=B4=D0=B0=20=D0=B4=D0=B0=D1=82=D1=8B=20=D0=B8=20=D0=B2?= =?UTF-8?q?=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=B8=20=D0=B2=20=D1=82=D0=B0?= =?UTF-8?q?=D0=B9=D0=BC=D0=BB=D0=B0=D0=B9=D0=BD=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit На главной странице добавлена возможность выбирать дату и время с помощью поля ввода (необходимо кликнуть на подчеркнутую текущую дату) --- apps/main/templates/main_index.html | 1 - static/js/ol/map/map-timeline.js | 136 ++++++++++++++++++++++++++-- 2 files changed, 127 insertions(+), 10 deletions(-) diff --git a/apps/main/templates/main_index.html b/apps/main/templates/main_index.html index 028ebf8..03c22a2 100644 --- a/apps/main/templates/main_index.html +++ b/apps/main/templates/main_index.html @@ -286,7 +286,6 @@ if (globalTimeQuery !== "" && prevTimeQuery === globalTimeQuery) return if (globalTimeQuery !== "") { loading = true - console.log(loaderWrapper.classList.contains("d-none")) if (loaderWrapper.classList.contains("d-none")) { loaderWrapper.classList.remove("d-none") } diff --git a/static/js/ol/map/map-timeline.js b/static/js/ol/map/map-timeline.js index 38bb20e..31d8ce8 100644 --- a/static/js/ol/map/map-timeline.js +++ b/static/js/ol/map/map-timeline.js @@ -4,6 +4,8 @@ class TimeLine { this.target = options.target this.updateFunction = options.updateFunction + this.disposePopover = this.disposePopover.bind(this); + this.timeline = this.initTimeLine() this.addTimelineEventListeners() } @@ -25,11 +27,8 @@ class TimeLine { orientation: {axis: "top"}, format: { minorLabels: { - minute: 'HH:mm', - hour: 'HH:mm', - second: 'HH:mm:ss' - }, - majorLabels: function (date) { + minute: 'HH:mm', hour: 'HH:mm', second: 'HH:mm:ss' + }, majorLabels: function (date) { return date.format("DD.MM.YY"); } } @@ -37,6 +36,14 @@ class TimeLine { return new vis.Timeline(this.target, items, options); } + disposePopover(e) { + if (e.target !== this.currentTimeLink && + !this.currentTimeLink.contains(e.target) && + !document.querySelector('.popover')?.contains(e.target)) { + this.popover.hide(); + } + } + addTimelineEventListeners() { this.timeline.on('rangechanged', (props) => { const center = new Date((props.start.getTime() + props.end.getTime()) / 2); @@ -48,14 +55,12 @@ class TimeLine { globalTimeQuery = "?time=" + iso } else { globalTimeQuery = "" - } - document.getElementById("current-time").textContent = "Время на карте: " + center.toLocaleDateString() + " " + center.toLocaleTimeString() + this.updateCurrentTimeDisplay(center); this.updateFunction(globalTimeQuery); }); - setInterval(() => { const newMax = moment().add(12, 'hours').toDate(); this.timeline.setOptions({ @@ -69,4 +74,117 @@ class TimeLine { } }, 3000); } -} + + updateCurrentTimeDisplay(center) { + const currentTime = document.getElementById("current-time"); + + // Очистка currentTime + while (currentTime.firstChild) { + currentTime.removeChild(currentTime.firstChild); + } + + const currentTimeSpan = document.createElement("span"); + currentTimeSpan.textContent = "Время на карте: "; + + const currentTimeLink = document.createElement("a"); + currentTimeLink.textContent = center.toLocaleDateString() + " " + center.toLocaleTimeString(); + currentTimeLink.style.zIndex = "33"; + currentTimeLink.style.textDecoration = "underline"; + currentTimeLink.style.cursor = "pointer"; + currentTimeLink.id = "currentTimeLink" + this.currentTimeLink = currentTimeLink + + // Создаем форму для выбора времени + const form = document.createElement('form'); + form.id = 'timelineDatetimeSelectForm'; + form.className = 'needs-validation'; + form.noValidate = true; + + const formGroup = document.createElement('div'); + formGroup.className = 'mb-3'; + + const label = document.createElement('label'); + label.htmlFor = 'timelineDatetimeInput'; + label.className = 'form-label'; + label.textContent = 'Выбор даты и времени'; + + const input = document.createElement('input'); + input.type = 'datetime-local'; + input.id = 'timelineDatetimeInput'; + input.className = 'form-control'; + + // Устанавливаем текущее значение и максимальную дату + const setInputValues = () => { + const now = new Date(); + const year = now.getFullYear(); + const month = String(now.getMonth() + 1).padStart(2, '0'); + const day = String(now.getDate()).padStart(2, '0'); + const hours = String(now.getHours()).padStart(2, '0'); + const minutes = String(now.getMinutes()).padStart(2, '0'); + const maxDateTime = `${year}-${month}-${day}T${hours}:${minutes}`; + + input.max = maxDateTime; + }; + + const inputContainer = document.createElement('div'); + inputContainer.id = 'datetimeInputContainer'; + inputContainer.appendChild(input); + + const resetBtn = document.createElement('button'); + resetBtn.type = 'reset'; + resetBtn.className = 'btn btn-outline-secondary btn-sm me-2'; + resetBtn.textContent = 'Сбросить'; + + const submitBtn = document.createElement('button'); + submitBtn.type = 'submit'; + submitBtn.className = 'btn btn-primary btn-sm'; + submitBtn.textContent = 'Перейти'; + + formGroup.appendChild(label); + formGroup.appendChild(inputContainer); + form.appendChild(formGroup); + form.appendChild(resetBtn); + form.appendChild(submitBtn); + + form.addEventListener("submit", (e) => { + e.preventDefault(); + const selectedDate = new Date(input.value); + if (isNaN(selectedDate.getTime())) return; + + // Обновляем таймлайн + const duration = this.timeline.getWindow().end - this.timeline.getWindow().start; + const start = new Date(selectedDate.getTime() - duration / 2); + const end = new Date(selectedDate.getTime() + duration / 2); + + this.timeline.setWindow(start, end); + + // Обновляем URL + globalTimeQuery = "?time=" + selectedDate.toISOString(); + this.updateFunction(globalTimeQuery); + + // Закрываем popover + popover.hide(); + }); + + const popover = new bootstrap.Popover(currentTimeLink, { + trigger: 'manual', html: true, content: form, placement: 'top', sanitize: false + }); + this.popover = popover + // Обновляем значения поля ввода при каждом показе popover + currentTimeLink.addEventListener('click', (e) => { + e.preventDefault(); + setInputValues(); + + if (currentTimeLink.getAttribute('aria-describedby')) { + popover.hide(); + } else { + popover.show(); + } + }); + + document.addEventListener('click', (e) => this.disposePopover(e, currentTimeLink, popover)); + + currentTime.appendChild(currentTimeSpan); + currentTime.appendChild(currentTimeLink); + } +} \ No newline at end of file From 1b08a34f41c0d34e58f278a81d6d8da4de731c79 Mon Sep 17 00:00:00 2001 From: zakhy <=> Date: Tue, 8 Jul 2025 16:22:38 +0700 Subject: [PATCH 4/6] =?UTF-8?q?=D0=A2=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BD=D0=BE=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D0=BB=20=D0=B4=D1=83=D0=B1=D0=BB=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20event=20listeners?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/js/ol/map/map-timeline.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/static/js/ol/map/map-timeline.js b/static/js/ol/map/map-timeline.js index 31d8ce8..baba33f 100644 --- a/static/js/ol/map/map-timeline.js +++ b/static/js/ol/map/map-timeline.js @@ -4,8 +4,6 @@ class TimeLine { this.target = options.target this.updateFunction = options.updateFunction - this.disposePopover = this.disposePopover.bind(this); - this.timeline = this.initTimeLine() this.addTimelineEventListeners() } @@ -36,13 +34,6 @@ class TimeLine { return new vis.Timeline(this.target, items, options); } - disposePopover(e) { - if (e.target !== this.currentTimeLink && - !this.currentTimeLink.contains(e.target) && - !document.querySelector('.popover')?.contains(e.target)) { - this.popover.hide(); - } - } addTimelineEventListeners() { this.timeline.on('rangechanged', (props) => { @@ -182,7 +173,16 @@ class TimeLine { } }); - document.addEventListener('click', (e) => this.disposePopover(e, currentTimeLink, popover)); + function disposePopover(e) { + if (e.target !== currentTimeLink && + !currentTimeLink.contains(e.target) && + !document.querySelector('.popover')?.contains(e.target)) { + popover.hide(); + } + } + + document.removeEventListener("click", disposePopover) + document.addEventListener('click', disposePopover); currentTime.appendChild(currentTimeSpan); currentTime.appendChild(currentTimeLink); From 3b83cf256e806857589011c5f6af0d216e637cde Mon Sep 17 00:00:00 2001 From: zakhy <=> Date: Tue, 8 Jul 2025 16:39:17 +0700 Subject: [PATCH 5/6] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=20=D0=BF=D0=BE=20=D0=B4?= =?UTF-8?q?=D0=B0=D1=82=D0=B5=20=D0=BD=D0=B0=20=D0=B2=D1=8B=D0=B1=D0=BE?= =?UTF-8?q?=D1=80=D0=BA=D1=83=20=D0=B8=D1=81=D1=82=D0=BE=D1=80=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Исправлена выборка истории техники и персонала. Теперь не отображаются объекты, которые были давно --- apps/gto/views/views_main.py | 5 ++++- apps/workerslocation/views/views_radiusapi.py | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/gto/views/views_main.py b/apps/gto/views/views_main.py index e6d7539..3148083 100644 --- a/apps/gto/views/views_main.py +++ b/apps/gto/views/views_main.py @@ -40,10 +40,13 @@ def update_object(request): try: time_filter = datetime.fromisoformat( time_filter.rstrip('Z')).replace(tzinfo=utc) + time_filter_minus_week = time_filter - timedelta(days=7) latest_times = ( EquipmentTracking.objects - .filter(equipment__block=False, time__lt=time_filter) + .filter(equipment__block=False, + time__gt=time_filter_minus_week, + time__lt=time_filter) .values('equipment_id') .annotate(latest_time=Max('time')) .values_list('equipment_id', 'latest_time') diff --git a/apps/workerslocation/views/views_radiusapi.py b/apps/workerslocation/views/views_radiusapi.py index 25ee8b9..fdad117 100644 --- a/apps/workerslocation/views/views_radiusapi.py +++ b/apps/workerslocation/views/views_radiusapi.py @@ -98,10 +98,12 @@ def update_object(request, pk=None): elif time_filter: time_filter = datetime.fromisoformat( time_filter.rstrip('Z')).replace(tzinfo=utc) - + time_filter_minus_week = time_filter - timedelta(days=7) latest_times = ( WorkersTracking.objects - .filter(worker__active=True, time__lt=time_filter) + .filter(worker__active=True, + time__gt=time_filter_minus_week, + time__lt=time_filter) .values('worker_id') .annotate(latest_time=Max('time')) .values_list('worker_id', 'latest_time') From e771572df250306a754aa669c4059bfe03535890 Mon Sep 17 00:00:00 2001 From: zakhy <=> Date: Tue, 8 Jul 2025 16:57:56 +0700 Subject: [PATCH 6/6] fix login --- apps/util/eventsmodule.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/util/eventsmodule.py b/apps/util/eventsmodule.py index bff3a32..2f1c2ad 100644 --- a/apps/util/eventsmodule.py +++ b/apps/util/eventsmodule.py @@ -5,7 +5,7 @@ from apps.events.models.model_events import Event from apps.events.models.model_events_system import EventSystem def write_system(**kwargs): - system_user = User.objects.filter(username="system").first() + system_user, _ = User.objects.get_or_create(username="system") IP="127.0.0.1" user = system_user level_event = 0