круды для радиоканалов

This commit is contained in:
zakhy 2025-06-04 15:00:54 +07:00
parent 2c654dccb8
commit cb392efad6
8 changed files with 491 additions and 3 deletions

View File

@ -0,0 +1,21 @@
from django import forms
from django.forms import ModelForm
from apps.pla.models.model_channel import PlaChannel
class ChannelForm(ModelForm):
class Meta:
model = PlaChannel
fields = ("name", "uid", "active")
labels = {
"name": "Наименование",
}
widgets = {
"name": forms.TextInput(attrs={"class": "form-control",
"placeholder": "Введите наименование"}),
"uid": forms.TextInput(attrs={"class": "form-control",
"placeholder": "Введите идентификатор"}),
}

View File

@ -0,0 +1,207 @@
{% extends "default.html" %}
{% load static %}
{% load mysettings %}
{% block header_link %}
<!-- Select2 -->
<link rel="stylesheet"
href="{% static 'lte/plugins/select2/css/select2.min.css' %}?ver={% settings_value 'APP_VER' %}">
<link rel="stylesheet"
href="{% static 'lte/plugins/select2-bootstrap4-theme/select2-bootstrap4.min.css' %}?ver={% settings_value 'APP_VER' %}">
<!-- iCheck for checkboxes and radio inputs -->
<link rel="stylesheet"
href="{% static 'lte/plugins/icheck-bootstrap/icheck-bootstrap.min.css' %}?ver={% settings_value 'APP_VER' %}">
<style>
.file-upload-label {
cursor: pointer;
border: 1px solid #ced4da;
padding: .375rem .75rem;
border-radius: .25rem;
font-weight: normal !important;
}
.custom-file {
margin-bottom: 1.5em;
}
.file-name {
margin-left: .5em;
font-size: 0.7rem;
}
</style>
{% endblock header_link %}
{% block content %}
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h4>{% if form.instance.pk %}Редактирование{% else %}Добавление{% endif %} канала</h4>
</div>
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a href="{% url 'mainindex' %}">Главная</a></li>
<li class="breadcrumb-item"><a href="{% url 'management:main_index' %}">Параметры системы </a>
</li>
</ol>
</div>
</div>
</div><!-- /.container-fluid -->
</section>
<section class="content">
<form autocomplete="off" method="post" enctype="multipart/form-data" class="form-horizontal" id="form">
{% csrf_token %}
<div class="container-fluid">
<div class="row">
<!-- /.col -->
<div class="col-12">
<div class="card card-outline card-primary">
<div class="card-body">
<div class="form-group row">
<label for="{{ form.name.id_for_label }}" class="col-sm-2 col-form-label">
Наименование
<span class="text-danger">*</span>
</label>
<div class="col-sm-8">
{{ form.name }}
{% if form.name.errors %}
<div class="invalid-feedback d-block">
{% for error in form.name.errors %}
<p>{{ error }}</p>
{% endfor %}
</div>
{% endif %}
</div>
</div>
<div class="form-group row">
<label for="{{ form.name.id_for_label }}" class="col-sm-2 col-form-label">
Идентификатор
<span class="text-danger">*</span>
</label>
<div class="col-sm-8">
{{ form.uid }}
{% if form.uid.errors %}
<div class="invalid-feedback d-block">
{% for error in form.uid.errors %}
<p>{{ error }}</p>
{% endfor %}
</div>
{% endif %}
</div>
</div>
</div>
<div class="card-footer">
<button id="saveButton" type="submit" class="btn bg-gradient-primary">Сохранить</button>
<a href="/management/" type="button" class="btn btn-default float-right">Отмена</a>
</div>
<!-- /.card -->
</div>
<!-- /.nav-tabs-custom -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
</div><!-- /.container-fluid -->
</form>
</section>
{% endblock %}
{% block script_footer %}
<script src="{% static 'js/ol/lib/OpenLayers.js' %}?ver={% settings_value 'APP_VER' %}"></script>
<script src="{% static 'js/ol/ol-ext/ol-ext.min.js' %}?ver={% settings_value 'APP_VER' %}"></script>
<script src="{% static 'js/ol/layersStyles.js' %}?ver={% settings_value 'APP_VER' %}"></script>
<script src="{% static 'js/ol/map/map-core.js' %}?ver={% settings_value 'APP_VER' %}"></script>
<script src="{% static 'js/ol/map/map-layer-switcher.js' %}?ver={% settings_value 'APP_VER' %}"></script>
<script src="{% static 'js/ol/map/map-marker-manager.js' %}?ver={% settings_value 'APP_VER' %}"></script>
<script src="{% static 'js/ol/map/map-created-layer-manager.js' %}?ver={% settings_value 'APP_VER' %}"></script>
<script src="{% static 'js/ol/map/map-time-slider.js' %}?ver={% settings_value 'APP_VER' %}"></script>
<script src="{% static 'js/ol/map/map-coefficients-manager.js' %}?ver={% settings_value 'APP_VER' %}"></script>
<script>
document.getElementById("saveButton").addEventListener("click", (event) => {
$("#saveButtonIcon").hide()
event.target.insertAdjacentHTML('afterbegin', `
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
`);
event.target.disabled = true
document.getElementById("form").submit()
})
</script>
<script>
const inputArr = document.querySelectorAll('.custom-file')
for (let div of inputArr) {
div.querySelector("input").addEventListener('change', function (event) {
const fileNameDisplay = div.querySelector("span.file-name");
const file = event.target.files[0];
if (file) {
fileNameDisplay.style.display = 'block';
fileNameDisplay.innerHTML = `Сейчас выбран: <a href="#" download="${file.name}">${file.name}</a>`;
} else {
fileNameDisplay.style.display = 'none';
}
});
}
</script>
<script>
document.addEventListener("DOMContentLoaded", async () => {
const extent = ol.proj.transformExtent(
[
parseFloat('{{ form.instance.min_lon|safe }}'),
parseFloat('{{ form.instance.min_lat|safe }}'),
parseFloat('{{ form.instance.max_lon|safe }}'),
parseFloat('{{ form.instance.max_lat|safe }}')
],
'EPSG:4326', // Исходная проекция
'EPSG:3857' // Целевая проекция
);
const mapCore = new MapCore('map', {
center: ['{{longitude}}', '{{latitude}}'],
zoom: 12
});
await mapCore.initialize();
const scanLayer = new ol.layer.Tile({
source: new ol.source.XYZ({
url: `{{ form.instance.url }}`,
}),
extent: extent
});
scanLayer.set('title', 'Ортофотоплан')
scanLayer.set('name', 'orto')
mapCore.addLayer(scanLayer)
mapCore.map.getView().fit(extent, {
padding: [20, 20, 20, 20],
duration: 1000,
maxZoom: 15
});
const extentPolygon = ol.geom.Polygon.fromExtent(extent);
const vectorLayer = new ol.layer.Vector({
source: new ol.source.Vector({
features: [
new ol.Feature({
geometry: extentPolygon,
}),
],
}),
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'red',
width: 2,
}),
}),
});
mapCore.addLayer(vectorLayer)
});
</script>
{% endblock script_footer %}

View File

@ -0,0 +1,86 @@
{% extends "default.html" %}
{% load static %}
{% load mysettings %}
{% block header_link %}
<!-- Select2 -->
<link rel="stylesheet"
href="{% static 'lte/plugins/select2/css/select2.min.css' %}?ver={% settings_value 'APP_VER' %}">
<link rel="stylesheet"
href="{% static 'lte/plugins/select2-bootstrap4-theme/select2-bootstrap4.min.css' %}?ver={% settings_value 'APP_VER' %}">
<!-- iCheck for checkboxes and radio inputs -->
<link rel="stylesheet"
href="{% static 'lte/plugins/icheck-bootstrap/icheck-bootstrap.min.css' %}?ver={% settings_value 'APP_VER' %}">
{% endblock header_link %}
{% block content %}
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h4>Управление каналами</h4>
</div>
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a href="{% url 'mainindex' %}">Главная</a></li>
<li class="breadcrumb-item"><a href="{% url 'management:main_index' %}">Параметры системы </a>
</li>
</ol>
</div>
</div>
</div><!-- /.container-fluid -->
</section>
<section class="content">
<form autocomplete="off" method="post" enctype="multipart/form-data" class="form-horizontal">
{% csrf_token %}
<div class="container-fluid">
<div class="row">
<!-- /.col -->
<div class="col-12">
<div class="card">
<div class="card-header">
<a href="{% url 'management:add_channel' %}" class="btn btn-primary">Добавить</a>
</div>
<div class="card-body table-responsive p-0">
<table class="table table-bordered table-hover table-head-fixed text-nowrap">
<thead>
<tr role="row">
<th class="col-1"></th>
<th>Наименование</th>
<th>Идентификатор</th>
<th class="col-1"></th>
</tr>
</thead>
<tbody>
{% for channel in catalog %}
<tr>
<td>
{{ channel.id }}
</td>
<td>
<a href="{% url 'management:edit_channel' channel.id %}">{{ channel.name }}</a>
</td>
<td>
{{ channel.uid }}
</td>
<td><a href="{% url 'management:remove_channel' channel.id %}"
class="btn btn-danger btn-block btn-sm"><i class="fa fa-trash"></i>
Удалить</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div> <!-- /.card-body -->
</div>
<!-- /.nav-tabs-custom -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
</div><!-- /.container-fluid -->
</form>
</section>
{% endblock %}

View File

@ -0,0 +1,87 @@
{% extends "default.html" %}
{% load static %}
{% load mysettings %}
{% block header_link %}
<!-- Select2 -->
<link rel="stylesheet"
href="{% static 'lte/plugins/select2/css/select2.min.css' %}?ver={% settings_value 'APP_VER' %}">
<link rel="stylesheet"
href="{% static 'lte/plugins/select2-bootstrap4-theme/select2-bootstrap4.min.css' %}?ver={% settings_value 'APP_VER' %}">
<!-- iCheck for checkboxes and radio inputs -->
<link rel="stylesheet"
href="{% static 'lte/plugins/icheck-bootstrap/icheck-bootstrap.min.css' %}?ver={% settings_value 'APP_VER' %}">
<style>
.file-upload-label {
cursor: pointer;
border: 1px solid #ced4da;
padding: .375rem .75rem;
border-radius: .25rem;
font-weight: normal !important;
}
</style>
{% endblock header_link %}
{% block content %}
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h4>Удаление ортофотоплана</h4>
</div>
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a href="/management/">Главная</a></li>
<li class="breadcrumb-item"><a href="/management/">Параметры системы</a></li>
</ol>
</div>
</div>
</div><!-- /.container-fluid -->
</section>
<section class="content">
<form autocomplete="off" method="post" class="form-horizontal">
{% csrf_token %}
<div class="container-fluid">
<div class="row">
<!-- /.col -->
<div class="col-12">
<div class="card">
<div class="card-header">Удаление канала</div>
<div class="card-body">
<p>Вы уверены, что хотите удалить канал: {{ object.name }}?</p>
</div><!-- /.card-body -->
<div class="card-footer">
<button id="btnok" type="submit" class="btn bg-gradient-danger">Удалить</button>
<a href="/management/" type="button" class="btn btn-default float-right">Отмена</a>
</div>
</div>
<!-- /.nav-tabs-custom -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
</div><!-- /.container-fluid -->
</form>
</section>
{% endblock %}
{% block script_footer %}
<script>
const inputArr = document.querySelectorAll('.show-name')
for (let arr of inputArr) {
arr.addEventListener('change', function (event) {
const fileNameDisplay = document.getElementById('file-name');
const file = event.target.files[0];
if (file) {
fileNameDisplay.style.display = 'block';
fileNameDisplay.innerHTML = `Сейчас выбран: <a href="#" download="${file.name}">${file.name}</a>`;
} else {
fileNameDisplay.style.display = 'none';
}
});
}
</script>
{% endblock script_footer %}

View File

@ -27,7 +27,7 @@
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h4>Удаление ортофотоплана</h4>
<h4>Удаление изображения</h4>
</div>
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
@ -47,7 +47,7 @@
<!-- /.col -->
<div class="col-12">
<div class="card">
<div class="card-header">Удаление ортофотоплана</div>
<div class="card-header">Удаление изображения</div>
<div class="card-body">
<p>Вы уверены, что хотите удалить изображение: {{ object.name }}?</p>
</div><!-- /.card-body -->

View File

@ -16,6 +16,7 @@
border-radius: .25rem;
font-weight: normal !important;
}
.gap-3 {
gap: .3em;
}
@ -53,7 +54,8 @@
<div class="form-group row">
<div class="d-flex gap-3">
<a href="{% url 'management:manage_orthomosaic' %}" class="btn bg-gradient-primary">Ортофотопланы</a>
<a href="{% url 'management:manage_map' %}" class="btn bg-gradient-primary">Карты</a>
<a href="{% url 'management:manage_map' %}"
class="btn bg-gradient-primary">Карты</a>
</div>
</div>
<div class="form-group row">
@ -571,6 +573,9 @@
autofocus="" id="id_wtoken">{{ platoken }}</textarea>
</div>
</div>
<div class="form-group row">
<a href="{% url 'management:manage_channel' %}" class="btn bg-gradient-primary">Управление каналами</a>
</div>
{% elif plasystem == "Asterisk" %}
<div class="form-group row">
<label for="id_outgoing" class="col-sm-1 col-form-label">Каталог исходящих сообщений

View File

@ -14,6 +14,7 @@ from apps.management.views.views_settings import (
add_icon,
edit_icon,
remove_icon, remove_map, edit_map, add_map, manage_map,
manage_channels, remove_channel, edit_channel, add_channel,
)
app_name = "management"
@ -38,6 +39,11 @@ urlpatterns = [
path("icons/<int:pk>/edit/", edit_icon, name="edit_icon"),
path("icons/<int:pk>/remove/", remove_icon, name="remove_icon"),
path("channels/", manage_channels, name="manage_channel"),
path("channels/create/", add_channel, name="add_channel"),
path("channels/<int:pk>/edit/", edit_channel, name="edit_channel"),
path("channels/<int:pk>/remove/", remove_channel, name="remove_channel"),
path("user/add/", views_user.user_add, name="user_add"),
path("user/", views_user.user_edit, name="user_edit"),
path("user/password/", views_user.user_password_edit, name="user_password_edit"),

View File

@ -14,6 +14,7 @@ from apps.gto.models.model_type_icons import ModelTypeIcons
from apps.main.models.model_icons import Icons
from apps.main.models.model_static_layer import StaticLayer
from apps.management.forms.base_map import BaseMapForm
from apps.management.forms.channel import ChannelForm
from apps.management.forms.gto_icon import ModelTypeIconsForm
from apps.management.forms.icon import IconForm
from apps.management.forms.orthomosaic import OrthomosaicForm
@ -23,6 +24,7 @@ from apps.management.views.util import (save_tif,
extract_zip_ignoring_parent,
calculate_extent_from_tms,
detect_tile_extension)
from apps.pla.models.model_channel import PlaChannel
from apps.util import generalmodule
from sabron.util import logging
@ -448,3 +450,77 @@ def remove_map(request, pk):
except Exception:
logging.error(traceback.format_exc())
return redirect("management:manage_map")
@login_required(login_url="/")
@never_cache
def manage_channels(request):
try:
context = generalmodule.get_context_template()
channels = PlaChannel.objects.all()
context["catalog"] = channels
return render(request, "channel/manage_channel.html", context)
except Exception:
logging.error(traceback.format_exc())
@login_required(login_url="/")
@never_cache
def add_channel(request):
try:
context = generalmodule.get_context_template()
if request.method == "GET":
form = ChannelForm()
context["form"] = form
return render(request, "channel/form_channel.html",
context)
if request.method == "POST":
form = ChannelForm(request.POST)
if form.is_valid():
form.save()
return redirect("management:manage_channel")
else:
context["form"] = form
return render(request,
"channel/form_channel.html",
context)
except Exception:
logging.error(traceback.format_exc())
@login_required(login_url="/")
@never_cache
def edit_channel(request, pk):
try:
if request.method == "GET":
obj = get_object_or_404(PlaChannel, id=pk)
context = generalmodule.get_context_template()
form = ChannelForm(instance=obj)
context["form"] = form
return render(request, "channel/form_channel.html", context)
if request.method == "POST":
obj = get_object_or_404(PlaChannel, id=pk)
form = ChannelForm(request.POST, instance=obj)
if form.is_valid():
form.save()
return redirect("management:manage_channel")
except Exception:
logging.error(traceback.format_exc())
@login_required(login_url="/")
@never_cache
def remove_channel(request, pk):
try:
if request.method == "GET":
obj = get_object_or_404(PlaChannel, id=pk)
context = generalmodule.get_context_template()
context["object"] = obj
return render(request, "channel/remove_channel.html", context)
if request.method == "POST":
obj = get_object_or_404(PlaChannel, id=pk)
obj.delete()
return redirect("management:manage_channel")
except Exception:
logging.error(traceback.format_exc())
return redirect("management:manage_channel")