Страница администрирования
This commit is contained in:
parent
5d3c3d414f
commit
bac3abc1f4
@ -4,7 +4,7 @@ from apps.main.models.scales_control import Position
|
||||
from apps.main.services.scales_control.redis_repository import RedisRepository
|
||||
from apps.util.base_view import base_view
|
||||
from django.http import JsonResponse
|
||||
from sabron.util.sabronmodule import get_settings
|
||||
from sabron.util.sabronmodule import get_settings, set_settings
|
||||
|
||||
|
||||
@base_view
|
||||
@ -52,3 +52,16 @@ def get_kek_and_breed(request):
|
||||
fabric_goal = get_settings('fabric_goal')
|
||||
service = RedisRepository(control_conveyor_month, fabric_goal)
|
||||
return JsonResponse(service.get_kek_and_breed_values())
|
||||
|
||||
|
||||
@base_view
|
||||
def fabric_goal(request):
|
||||
if request.method == 'GET':
|
||||
goal = get_settings('fabric_goal')
|
||||
return JsonResponse({'goal': goal, 'success': True})
|
||||
elif request.method == 'PUT':
|
||||
value = json.loads(request.body)['goal']
|
||||
set_settings('fabric_goal', value)
|
||||
return JsonResponse({'success': True, 'message': 'Данные приняты'})
|
||||
else:
|
||||
return JsonResponse({'message': 'wrong method', 'success': False})
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
from apps.main.services.accident_stops.views import get_accident_stops
|
||||
from apps.main.services.density_sensors.views import get_sensors_list
|
||||
from apps.main.services.scales_control.views import (
|
||||
fabric_goal,
|
||||
get_kek_and_breed,
|
||||
get_positions,
|
||||
get_scales_data,
|
||||
@ -24,9 +25,13 @@ urlpatterns = [
|
||||
),
|
||||
path('worktime/create/', create_worktime, name='create_worktime'),
|
||||
path('status/', get_current_status, name='current_status'),
|
||||
|
||||
path('positions/', get_positions, name='get_positions'),
|
||||
|
||||
path('density_sensors/', get_sensors_list, name='get_sensors_list'),
|
||||
|
||||
path('scales/', get_scales_data, name='scales'),
|
||||
path('scales/kek_and_breed/recieve', set_kek_and_breed, name='receive_kek_and_breed'),
|
||||
path('scales/kek_and_breed', get_kek_and_breed, name='get_kek_and_breed')
|
||||
path('scales/kek_and_breed/recieve/', set_kek_and_breed, name='receive_kek_and_breed'),
|
||||
path('scales/kek_and_breed/', get_kek_and_breed, name='get_kek_and_breed'),
|
||||
path('scales/fabric_goal/', fabric_goal, name='fabric_goal')
|
||||
]
|
||||
|
||||
@ -2,7 +2,8 @@ from apps.main.models.worktime import FabricWorkTime
|
||||
from apps.main.services.worktime.create_worktime_data import create_worktime_data
|
||||
from apps.main.services.worktime.service import FabricWorkTimeService
|
||||
from apps.util.base_view import base_view
|
||||
from django.http import JsonResponse
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
from django.shortcuts import redirect
|
||||
|
||||
|
||||
@base_view
|
||||
@ -19,5 +20,7 @@ def factory_work_time_durations(request):
|
||||
|
||||
@base_view
|
||||
def create_worktime(request):
|
||||
res = create_worktime_data()
|
||||
return JsonResponse({'success': bool(res)}, safe=False)
|
||||
if request.user.is_superuser:
|
||||
create_worktime_data()
|
||||
return redirect('administration')
|
||||
return HttpResponse(status=403)
|
||||
|
||||
145
app/apps/main/templates/administration.html
Normal file
145
app/apps/main/templates/administration.html
Normal file
@ -0,0 +1,145 @@
|
||||
{% extends 'default.html' %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row m-2">
|
||||
<div class="col-lg-4 col-sm-12">
|
||||
<div class="m-portlet m-portlet--mobile m-portlet--body-progress-">
|
||||
<div class="m-portlet__head">
|
||||
<div class="m-portlet__head-caption">
|
||||
<div class="m-portlet__head-title">
|
||||
<h3 class="m-portlet__head-text">
|
||||
Основное
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-portlet__body">
|
||||
<div class="d-flex justify-content-between">
|
||||
<a href="/admin" class="btn btn-primary roboto">Панель администрирования</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-4 col-sm-12">
|
||||
<div class="m-portlet m-portlet--mobile m-portlet--body-progress-">
|
||||
<div class="m-portlet__head">
|
||||
<div class="m-portlet__head-caption">
|
||||
<div class="m-portlet__head-title">
|
||||
<h3 class="m-portlet__head-text">
|
||||
Время работы фабрики
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-portlet__body">
|
||||
<div class="d-flex justify-content-between">
|
||||
<a href="{% url "create_worktime" %}" class="btn btn-outline-primary roboto">Загрузить время
|
||||
работы
|
||||
фабрики</a>
|
||||
<a href="#" class="btn btn-danger roboto">Очистить время работы</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-4 col-sm-12">
|
||||
<div class="m-portlet m-portlet--mobile m-portlet--body-progress-">
|
||||
<div class="m-portlet__head">
|
||||
<div class="m-portlet__head-caption">
|
||||
<div class="m-portlet__head-title">
|
||||
<h3 class="m-portlet__head-text">
|
||||
Весы
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-portlet__body">
|
||||
<div class="d-flex flex-column ">
|
||||
|
||||
<div>
|
||||
<button type="button" class="btn btn-primary roboto mb-4" data-toggle="modal"
|
||||
data-target="#fabricGoalModal" id="launchModalBtn">Изменить значение цели по
|
||||
переработке
|
||||
</button>
|
||||
</div>
|
||||
<div><a href="#" class="btn btn-outline-danger roboto mb-2">Очистить значение кека и породы</a>
|
||||
</div>
|
||||
<div><a href="#" class="btn btn-danger roboto mb-2">Очистить данные весов</a></div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="fabricGoalModal" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
|
||||
aria-hidden="true" style="display: none;">
|
||||
<div class="modal-dialog" role="document">
|
||||
<form class="modal-content" id="dropoutAndConcentrateForm">
|
||||
{% csrf_token %}
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="ModalLabel">Изменение значение цели по переработке</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div id="goalModalAlerts"></div>
|
||||
<div class="m-portlet__body">
|
||||
<div class="form-group m-form__group">
|
||||
<label for="goalInput">Цель по переработке (тонн)</label>
|
||||
<input type="number" class="form-control m-input m-input--square" id="goalInput"
|
||||
placeholder="Введите значение в тоннах">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary roboto" data-dismiss="modal">Закрыть</button>
|
||||
<button type="button" class="btn btn-primary roboto" id="submitBtn">Отправить</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block script_footer %}
|
||||
<script>
|
||||
const input = document.querySelector("#goalInput")
|
||||
const submitBtn = document.querySelector("#submitBtn")
|
||||
const goalModalAlerts = document.querySelector('#goalModalAlerts')
|
||||
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
const goal = await fetch('/main/scales/fabric_goal/').then(response => response.json())
|
||||
input.value = goal.goal
|
||||
})
|
||||
submitBtn.addEventListener('click', async () => {
|
||||
const data = {goal: input.value}
|
||||
const response = await fetch('/main/scales/fabric_goal/', {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charset=utf-8',
|
||||
'X-CSRFToken': window.getCookie('csrftoken')
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
|
||||
const responseJson = await response.json()
|
||||
|
||||
const alert = document.createElement('div')
|
||||
alert.classList.add('alert', 'roboto', 'bold')
|
||||
alert.setAttribute('role', 'alert')
|
||||
alert.textContent = `${responseJson.message}`
|
||||
goalModalAlerts.appendChild(alert)
|
||||
|
||||
if (responseJson.success) {
|
||||
alert.classList.add('alert-success')
|
||||
// Спрятать модальное окно
|
||||
// document.getElementById('fabricGoalModal').classList.remove('show')
|
||||
document.querySelectorAll('.modal-backdrop').forEach(el => el.remove())
|
||||
} else {
|
||||
// Отобразить ошибку
|
||||
alert.classList.add('alert-danger')
|
||||
}
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
@ -1,5 +1,5 @@
|
||||
from apps.main import views_main
|
||||
from apps.main.views_main import aspiration, scales
|
||||
from apps.main.views_main import administration, aspiration, scales
|
||||
from django.urls import include, path
|
||||
|
||||
urlpatterns = [
|
||||
@ -8,5 +8,7 @@ urlpatterns = [
|
||||
path('scada/ajax/', views_main.get_ajax, name='get_ajax'),
|
||||
path('', include('apps.main.services.urls')),
|
||||
path('scale/', scales, name='concentrate_and_dropout'),
|
||||
path('aspiration/', aspiration, name='aspiration')
|
||||
path('aspiration/', aspiration, name='aspiration'),
|
||||
|
||||
path('administration/', administration, name='administration')
|
||||
]
|
||||
|
||||
@ -4,7 +4,7 @@ import traceback
|
||||
import requests
|
||||
from apps.util import generalmodule
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.shortcuts import render
|
||||
from django.shortcuts import redirect, render
|
||||
from django.views.decorators.cache import never_cache
|
||||
from sabron.util import logging
|
||||
|
||||
@ -59,3 +59,11 @@ def scales(request):
|
||||
@never_cache
|
||||
def aspiration(request):
|
||||
return render(request, 'aspiration.html')
|
||||
|
||||
|
||||
@login_required(login_url='/accounts/login/?next=')
|
||||
@never_cache
|
||||
def administration(request):
|
||||
if not request.user.is_superuser or not request.user.is_staff:
|
||||
return redirect('mainindex')
|
||||
return render(request, 'administration.html')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user