From 790ea87f194f02ccd038e0c5d42f0f18e5bf4f91 Mon Sep 17 00:00:00 2001 From: zakhy <=> Date: Thu, 29 May 2025 14:59:13 +0700 Subject: [PATCH 1/9] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=BA=D0=B0=20=D0=BD=D0=B0=20=D0=B3=D0=BB=D0=B0?= =?UTF-8?q?=D0=B2=D0=BD=D0=BE=D0=B9=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=86=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/main/templates/main_index.html | 248 +++++++++++++++++++++------- static/css/main_page.css | 111 ++++++++++--- static/js/ol/layersStyles.js | 18 +- 3 files changed, 289 insertions(+), 88 deletions(-) diff --git a/apps/main/templates/main_index.html b/apps/main/templates/main_index.html index 8baf36e..e81b189 100644 --- a/apps/main/templates/main_index.html +++ b/apps/main/templates/main_index.html @@ -15,14 +15,68 @@ {% block content %}
{% csrf_token %} -
-
-
- +
+
+
+ +
+ {% if show_speed_excess or show_drivers_fatigue or show_seismic_activity %} +
+
+ + {% if show_speed_excess %} + + {% endif %} + + {% if show_drivers_fatigue %} + + {% endif %} + + + {% if show_seismic_activity %} + +
+ {% endif %} +
+ {% endif %} +
+
+
@@ -33,66 +87,20 @@
- - -
+
+
+
+
+
-

Текущая дата: ...

-
- {% if show_speed_excess or show_drivers_fatigue or show_seismic_activity %} -
-
- - {% if show_speed_excess %} - - {% endif %} - - - - {% if show_drivers_fatigue %} - - {% endif %} - - - {% if show_seismic_activity %} - -
- {% endif %} +
+

Текущая дата: ...

- {% endif %} +
+
{% endblock %} @@ -207,6 +215,128 @@ zoom: 12 }); }); + var proxySource = new ol.source.Vector(); + const sourceIcons = new Map([ + [gtoLayer.getSource(), gtoDefaultIcon], + [workerLayer.getSource(), workerDefaultIcon] + ]); + + function syncSources(sources, proxySource) { + proxySource.clear(); // очистим перед полной синхронизацией + sources.forEach(src => { + proxySource.addFeatures(src.getFeatures()); + + // Обновлять при изменениях + src.on('addfeature', function (e) { + proxySource.addFeature(e.feature); + }); + + src.on('removefeature', function (e) { + proxySource.removeFeature(e.feature); + }); + + src.on('clear', function () { + proxySource.clear(); // в реальном проекте можно сделать тоньше, если нужно + sources.forEach(s => proxySource.addFeatures(s.getFeatures())); + }); + }); + } + + function findSourceForFeature(feature) { + for (const [source, icon] of sourceIcons.entries()) { + if (source.hasFeature(feature)) { + return source; + } + } + return null; + } + + function getDefaultIcon(feature) { + const source = findSourceForFeature(feature); + return sourceIcons.get(source) || '/static/img/default.png'; + } + + var highlightLayer = new ol.layer.Vector({ + source: new ol.source.Vector(), + map: mapCore.map, + style: function (feature) { + return new ol.style.Style({ + image: new ol.style.Circle({ + radius: 15, + fill: new ol.style.Fill({color: 'rgba(255,0,0,0.3)'}), + stroke: new ol.style.Stroke({color: 'red', width: 2}) + }) + }); + } + }); + syncSources([gtoLayer.getSource(), workerLayer.getSource()], proxySource); + var search = new ol.control.SearchFeature({ + source: proxySource, + property: $(".options select").val(), + placeholder: "Поиск...", + className: "search-input", + minLength: 3, + sort: function (f1, f2) { + if (search.getSearchString(f1) < search.getSearchString(f2)) return -1; + if (search.getSearchString(f1) > search.getSearchString(f2)) return 1; + return 0; + }, + target: document.getElementById("f-search"), + getTitle: function (feature) { + const iconUrl = feature.get('icon') || getDefaultIcon(feature); + let title = feature.get('name') || 'Без имени'; + if (title.length > 20) { + title = title.substring(0, 20) + "..." + } + const nowDate = Date.now() + const featureDate = Date.parse(feature.get('iso_time')) + const delta = nowDate - featureDate + const deltaInHours = (delta / 1000 / 60 / 60).toFixed(0) + return ` +
+
+ + ${title} +
+
+ ${deltaInHours}ч. +
+
+ `; + } + }); + mapCore.map.on('click', function () { + search.clearHistory(); + }); + mapCore.map.addControl(search); + + search.on('select', function (e) { + search.clearHistory(); + const feature = e.search; + const coord = feature.getGeometry().getFirstCoordinate(); + + mapCore.map.getView().animate({center: coord, duration: 1000, zoom: 16}); + + highlightLayer.getSource().clear(); + + const flashFeature = new ol.Feature(new ol.geom.Point(coord)); + highlightLayer.getSource().addFeature(flashFeature); + + let count = 0; + const interval = setInterval(() => { + const source = highlightLayer.getSource(); + if (source.hasFeature(flashFeature)) { + source.removeFeature(flashFeature); + } else { + source.addFeature(flashFeature); + } + count++; + if (count > 5) { + clearInterval(interval); + source.removeFeature(flashFeature); + } + }, 400); + }); // Функция для обновления маркеров async function updateMarkers() { diff --git a/static/css/main_page.css b/static/css/main_page.css index 939ec0f..99a8c9b 100644 --- a/static/css/main_page.css +++ b/static/css/main_page.css @@ -10,7 +10,7 @@ #slider-date { margin: 5px 0; - font-size: 12px; + font-size: 14px; } #time-slider::-webkit-slider-thumb { @@ -140,12 +140,12 @@ input:checked + .slider:before { } #toStart { - position: absolute; - top: .5em; - left: .5em; - z-index: 999; + /*position: absolute;*/ + /*top: .5em;*/ + /*left: .5em;*/ + /*z-index: 999;*/ background-color: rgba(255, 255, 255, 0.5); - border: 1px solid #e2c4b0 + border: 1px solid rgba(201, 200, 211, 0.5) } #LayerSwitcher { @@ -160,14 +160,15 @@ input:checked + .slider:before { } #slider-container { - position: absolute; - bottom: .5em; - left: 50%; - transform: translateX(-50%); - z-index: 1000; - background: rgba(255, 255, 255, 0.8); - padding: 10px; - border-radius: 5px; + /*position: absolute;*/ + /*bottom: 60px;*/ + /*left: 50%;*/ + /*transform: translateX(-50%);*/ + /*z-index: 1000;*/ + border: 1px solid rgba(201, 200, 211, 0.5); + + /*padding: 10px;*/ + /*border-radius: 5px;*/ } #time-slider { @@ -175,17 +176,24 @@ input:checked + .slider:before { } #coefficients { - position: absolute; - top: .5em; - right: .5em; - z-index: 1000; - background: rgba(255, 255, 255, 0.8); - padding: 10px; + /*position: absolute;*/ + /*top: .5em;*/ + /*right: .5em;*/ + /*z-index: 1000;*/ + border: 1px solid rgba(201, 200, 211, 0.5); + /*padding: 10px;*/ border-radius: 5px; + height: 100%; } -.divider-vertical { - gap: 1em +.divider-vertical > div { + padding-left: 1em; + padding-right: 1em; +} + +.divider-vertical > div:not(:last-child) { + border-right: 1px solid rgba(201, 200, 211, 0.5); + } @@ -212,4 +220,61 @@ input:checked + .slider:before { .badge { font-size: 1em -} \ No newline at end of file +} + +.map-container { + height: calc(100% - 55px - 60px); + position: relative; +} + +.wrap-low-gap { + gap: .5em; +} + +.border-rounded-top { + border-top-left-radius: 10px; + border-top-right-radius: 10px +} + +.search-input { + width: 300px; +} + +input.search { + border: 1px solid rgba(201, 200, 211, 0.5); + border-radius: 5px; + height: 100%; + width: 100%; +} + + +.ol-search input { + margin: 0; + padding: 0; + text-indent: 10px; +} + +.gap-1 { + gap: 1em; +} + +.autocomplete { + position: absolute; + z-index: 999; + width: 100%; + max-height: 200px; +} +.autocomplete > li { + width: 100%; +} +input:focus { + border: 1px solid rgba(201, 200, 211, 0.5) !important; +} + +.search-item { + display: flex; + justify-content: space-between; +} +.search { + outline: none; +} diff --git a/static/js/ol/layersStyles.js b/static/js/ol/layersStyles.js index c3b2d1c..de58d48 100644 --- a/static/js/ol/layersStyles.js +++ b/static/js/ol/layersStyles.js @@ -1,9 +1,15 @@ +const gtoDefaultIcon = '/static/img/belaz.png' +const workerDefaultIcon = '/static/img/worker.png' + const getMarkerText = function (feature) { - const statemum = feature.get('garagenum') - if (statemum) { - return statemum; + let text = feature.get('garagenum') + if (!text) { + text = feature.get('name') } - return feature.get('name') + if (text.length > 20) { + text = text.substring(0, 20) + '...' + } + return text }; const createFeatureTextStyle = function (feature, resolution) { @@ -64,7 +70,7 @@ const createGTOZoneNameTextStyle = function (feature, resolution) { function GTOStyleFunction(feature, resolution) { return new ol.style.Style({ image: new ol.style.Icon({ - src: feature.get('icon') ? feature.get('icon') : "/static/img/belaz.png", + src: feature.get('icon') ? feature.get('icon') : gtoDefaultIcon, width: 30, height: 20 }), @@ -95,7 +101,7 @@ function createHatchPattern() { function VlocationStyleFunction(feature, resolution) { return new ol.style.Style({ image: new ol.style.Icon({ - src: feature.get('icon') ? feature.get('icon') : '/static/img/worker.png', + src: feature.get('icon') ? feature.get('icon') : workerDefaultIcon, width: 25, height: 30 }), From ebb539fd556533de4cd619d2ddb94ad77faa1416 Mon Sep 17 00:00:00 2001 From: zakhy Date: Fri, 30 May 2025 13:22:26 +0700 Subject: [PATCH 2/9] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BD=D0=B5=D1=81?= =?UTF-8?q?=20=D0=B2=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/main/templates/main_index.html | 128 ++--------------------- static/js/ol/map/map-feature-search.js | 139 +++++++++++++++++++++++++ 2 files changed, 147 insertions(+), 120 deletions(-) create mode 100644 static/js/ol/map/map-feature-search.js diff --git a/apps/main/templates/main_index.html b/apps/main/templates/main_index.html index e81b189..72e5e06 100644 --- a/apps/main/templates/main_index.html +++ b/apps/main/templates/main_index.html @@ -114,6 +114,7 @@ + + @@ -115,6 +133,42 @@ + - @@ -377,7 +376,7 @@ - + From 27c1f7f40cc744ed1b1e20d7c42ed99c05cc4ff8 Mon Sep 17 00:00:00 2001 From: zakhy <=> Date: Tue, 3 Jun 2025 15:09:51 +0700 Subject: [PATCH 8/9] =?UTF-8?q?=D0=98=D1=81=D1=82=D0=BE=D1=80=D0=B8=D1=8F?= =?UTF-8?q?=20=D1=81=20=D1=82=D0=B0=D0=B9=D0=BC=D0=BB=D0=B0=D0=B9=D0=BD?= =?UTF-8?q?=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/gto/models/model_equipment.py | 29 +- apps/gto/models/model_tracking.py | 7 +- apps/gto/views/views_main.py | 5 +- apps/main/templates/main_index.html | 154 +- apps/workerslocation/views/views_radiusapi.py | 3 +- static/js/ol/layersStyles.js | 11 +- static/js/ol/map/map-marker-manager.js | 33 +- .../plugins/moment/moment-with-timezone.js | 1582 +++++++++++++++++ 8 files changed, 1735 insertions(+), 89 deletions(-) create mode 100644 static/lte/plugins/moment/moment-with-timezone.js diff --git a/apps/gto/models/model_equipment.py b/apps/gto/models/model_equipment.py index af6f9aa..9b00a19 100644 --- a/apps/gto/models/model_equipment.py +++ b/apps/gto/models/model_equipment.py @@ -1,9 +1,11 @@ # -*- coding: utf-8 -*- +import datetime + +from django.conf import settings from django.db import models -from django.urls import \ - reverse # Used to generate URLs by reversing the URL patterns from apps.gto.models.model_type_icons import ModelTypeIcons +from apps.util.datetime_funcs import get_current_time class Equipment(models.Model): # Оборудование @@ -54,12 +56,14 @@ class Equipment(models.Model): # Оборудование def getLon(self): return str(self.lon).replace(",", ".") - def to_dict(self): + def to_dict(self, time_filter=None): type_g = self.model.strip() icon = "" icon_obj = ModelTypeIcons.objects.filter(model=type_g).first() if icon_obj is not None: icon = icon_obj.icon.url + connection_condition = self.get_condition( + self.time) return { "id": self.id, "name": self.name, @@ -71,8 +75,27 @@ class Equipment(models.Model): # Оборудование "model": self.model, "icon": icon, "garagenum": self.garagenum, + "condition": connection_condition, } + @staticmethod + def get_condition(update_time: datetime.datetime, + calc_from: datetime.datetime = None) -> str: + if calc_from: + now = calc_from + else: + now = get_current_time() + + record_time = update_time.replace(tzinfo=settings.TIME_ZONE_OBJECT) + # Разница во времени в часах между текущем временем и времени координаты + delta = (now - record_time).total_seconds() / 60 / 60 + if delta < 1: + return "ok" + elif delta < 24: + return "warning" + else: + return "danger" + def __str__(self): """ diff --git a/apps/gto/models/model_tracking.py b/apps/gto/models/model_tracking.py index 6000b28..1e69132 100644 --- a/apps/gto/models/model_tracking.py +++ b/apps/gto/models/model_tracking.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +import datetime + from django.db import models from django.urls import \ reverse # Used to generate URLs by reversing the URL patterns @@ -28,12 +30,14 @@ class EquipmentTracking(models.Model): # Передвижение оборуд def getLon(self): return str(self.lon).replace(",", ".") - def to_dict(self): + def to_dict(self, time_filter: datetime.datetime): type_g = self.equipment.model.strip() icon = "" icon_obj = ModelTypeIcons.objects.filter(model=type_g).first() if icon_obj is not None: icon = icon_obj.icon.url + connection_condition = self.equipment.get_condition(self.time, time_filter) + return { "id": self.equipment.id, "name": self.equipment.name, @@ -45,6 +49,7 @@ class EquipmentTracking(models.Model): # Передвижение оборуд "model": self.equipment.model, "icon": icon, "garagenum": self.equipment.garagenum, + "condition": connection_condition } def __str__(self): diff --git a/apps/gto/views/views_main.py b/apps/gto/views/views_main.py index 6b90ab8..0d76b9b 100644 --- a/apps/gto/views/views_main.py +++ b/apps/gto/views/views_main.py @@ -11,6 +11,7 @@ from django.http import HttpResponse, JsonResponse from django.shortcuts import redirect, render from django.utils import timezone from django.views.decorators.cache import never_cache +from pytz import utc from apps.general.views import settingsmodule from apps.gto.models.model_equipment import Equipment @@ -33,7 +34,7 @@ def update_object(request): if time_filter: time_filter = time_filter.rstrip('Z') # удаляет Z в конце - time_filter = datetime.fromisoformat(time_filter) + time_filter = datetime.fromisoformat(time_filter).replace(tzinfo=utc) subquery = EquipmentTracking.objects.filter( equipment=OuterRef('equipment'), @@ -53,7 +54,7 @@ def update_object(request): ).all() res = [] for obj in object_list: - res.append(obj.to_dict()) + res.append(obj.to_dict(time_filter)) return JsonResponse(res, safe=False) except Exception as err: logging.error(traceback.format_exc()) diff --git a/apps/main/templates/main_index.html b/apps/main/templates/main_index.html index 9efed86..5bc831f 100644 --- a/apps/main/templates/main_index.html +++ b/apps/main/templates/main_index.html @@ -16,8 +16,9 @@ position: absolute; top: 0; bottom: 0; + margin-left: 3px; width: 2px; - background-color: red; + background-color: dodgerblue; left: 50%; transform: translateX(-1px); z-index: 10; @@ -111,7 +112,8 @@ {#

Текущая дата: ...

#} {# #} {# #} -
+ +
@@ -134,42 +136,8 @@ -