From f083c1df3c6b6715da7e41d96924cc4afd53efed Mon Sep 17 00:00:00 2001 From: Kseninia Mikhaylova Date: Wed, 22 May 2024 15:37:33 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=82=D0=BE=D1=87=D0=B5=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/PythonImportHelper-v2-Completion.json | 94 ++++++++++++++++++- admin_front/pages/plan/index.vue | 21 ++++- back/api/models.py | 7 +- back/api/serializers.py | 19 +++- back/api/views.py | 19 +++- back/back/urls.py | 1 + 6 files changed, 148 insertions(+), 13 deletions(-) diff --git a/.vscode/PythonImportHelper-v2-Completion.json b/.vscode/PythonImportHelper-v2-Completion.json index f0c3668..1cea0db 100644 --- a/.vscode/PythonImportHelper-v2-Completion.json +++ b/.vscode/PythonImportHelper-v2-Completion.json @@ -1581,6 +1581,14 @@ "detail": "django.db", "documentation": {} }, + { + "label": "migrations", + "importPath": "django.db", + "description": "django.db", + "isExtraImport": true, + "detail": "django.db", + "documentation": {} + }, { "label": "models", "importPath": "django.db", @@ -1589,6 +1597,39 @@ "detail": "django.db", "documentation": {} }, + { + "label": "migrations", + "importPath": "django.db", + "description": "django.db", + "isExtraImport": true, + "detail": "django.db", + "documentation": {} + }, + { + "label": "models", + "importPath": "django.db", + "description": "django.db", + "isExtraImport": true, + "detail": "django.db", + "documentation": {} + }, + { + "label": "models", + "importPath": "django.db", + "description": "django.db", + "isExtraImport": true, + "detail": "django.db", + "documentation": {} + }, + { + "label": "django.db.models.deletion", + "kind": 6, + "isExtraImport": true, + "importPath": "django.db.models.deletion", + "description": "django.db.models.deletion", + "detail": "django.db.models.deletion", + "documentation": {} + }, { "label": "admin", "importPath": "django.contrib", @@ -8317,6 +8358,24 @@ "detail": "back.api.migrations.0004_alter_floorplan_d_border_alter_floorplan_d_size", "documentation": {} }, + { + "label": "Migration", + "kind": 6, + "importPath": "back.api.migrations.0005_floorplanpoints", + "description": "back.api.migrations.0005_floorplanpoints", + "peekOfCode": "class Migration(migrations.Migration):\n dependencies = [\n ('api', '0004_alter_floorplan_d_border_alter_floorplan_d_size'),\n ]\n operations = [\n migrations.CreateModel(\n name='FloorplanPoints',\n fields=[\n ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),\n ('points', models.JSONField()),", + "detail": "back.api.migrations.0005_floorplanpoints", + "documentation": {} + }, + { + "label": "Migration", + "kind": 6, + "importPath": "back.api.migrations.0006_remove_floorplanpoints_id_alter_floorplanpoints_plan", + "description": "back.api.migrations.0006_remove_floorplanpoints_id_alter_floorplanpoints_plan", + "peekOfCode": "class Migration(migrations.Migration):\n dependencies = [\n ('api', '0005_floorplanpoints'),\n ]\n operations = [\n migrations.RemoveField(\n model_name='floorplanpoints',\n name='id',\n ),\n migrations.AlterField(", + "detail": "back.api.migrations.0006_remove_floorplanpoints_id_alter_floorplanpoints_plan", + "documentation": {} + }, { "label": "ApiConfig", "kind": 6, @@ -8340,7 +8399,16 @@ "kind": 6, "importPath": "back.api.models", "description": "back.api.models", - "peekOfCode": "class Floorplan(models.Model):\n title = models.CharField(max_length=200)\n np_field = models.TextField()\n d_size = models.IntegerField(null=True, blank=True)\n d_border = models.IntegerField(null=True, blank=True)\n paths = models.TextField()", + "peekOfCode": "class Floorplan(models.Model):\n title = models.CharField(max_length=200)\n np_field = models.TextField()\n d_size = models.IntegerField(null=True, blank=True)\n d_border = models.IntegerField(null=True, blank=True)\n paths = models.TextField()\nclass FloorplanPoints(models.Model):\n plan = models.OneToOneField(Floorplan, on_delete=models.CASCADE, primary_key=True)\n points = models.JSONField()", + "detail": "back.api.models", + "documentation": {} + }, + { + "label": "FloorplanPoints", + "kind": 6, + "importPath": "back.api.models", + "description": "back.api.models", + "peekOfCode": "class FloorplanPoints(models.Model):\n plan = models.OneToOneField(Floorplan, on_delete=models.CASCADE, primary_key=True)\n points = models.JSONField()", "detail": "back.api.models", "documentation": {} }, @@ -8358,7 +8426,7 @@ "kind": 6, "importPath": "back.api.serializers", "description": "back.api.serializers", - "peekOfCode": "class FloorplanSerializer(serializers.ModelSerializer):\n class Meta:\n model = Floorplan\n fields = [\n \"id\",\n \"title\",\n \"np_field\",\n \"d_border\",\n \"d_size\",\n \"paths\"", + "peekOfCode": "class FloorplanSerializer(serializers.ModelSerializer):\n class Meta:\n model = Floorplan\n fields = [\n \"id\",\n \"title\",\n \"np_field\",\n \"d_border\",\n \"d_size\",\n \"paths\",", "detail": "back.api.serializers", "documentation": {} }, @@ -8367,7 +8435,16 @@ "kind": 6, "importPath": "back.api.serializers", "description": "back.api.serializers", - "peekOfCode": "class FloorplanListSerializer(serializers.ModelSerializer):\n class Meta:\n model = Floorplan\n fields = [\n \"id\",\n \"title\",\n ]", + "peekOfCode": "class FloorplanListSerializer(serializers.ModelSerializer):\n class Meta:\n model = Floorplan\n fields = [\n \"id\",\n \"title\",\n ]\nclass FloorplanPointsSerializer(serializers.ModelSerializer):\n class Meta:\n model = FloorplanPoints", + "detail": "back.api.serializers", + "documentation": {} + }, + { + "label": "FloorplanPointsSerializer", + "kind": 6, + "importPath": "back.api.serializers", + "description": "back.api.serializers", + "peekOfCode": "class FloorplanPointsSerializer(serializers.ModelSerializer):\n class Meta:\n model = FloorplanPoints\n fields = [\n \"points\",\n \"plan\",\n ]", "detail": "back.api.serializers", "documentation": {} }, @@ -8434,6 +8511,15 @@ "detail": "back.api.views", "documentation": {} }, + { + "label": "FloorplanPointsView", + "kind": 6, + "importPath": "back.api.views", + "description": "back.api.views", + "peekOfCode": "class FloorplanPointsView(APIView):\n def get(self, request, id):\n points = FloorplanPoints.objects.get(plan=id)\n serializer = FloorplanPointsSerializer(points, many=False)\n return JsonResponse(serializer.data, safe=False)\n def post(self, request, id):\n data = JSONParser().parse(request)\n data[\"plan\"] = id\n serializer = FloorplanPointsSerializer(data=data)\n if serializer.is_valid():", + "detail": "back.api.views", + "documentation": {} + }, { "label": "logger", "kind": 5, @@ -8646,7 +8732,7 @@ "kind": 5, "importPath": "back.back.urls", "description": "back.back.urls", - "peekOfCode": "urlpatterns = [\n path(\"admin/\", admin.site.urls),\n path(\"api/products\", csrf_exempt(views.Products.as_view())),\n path(\"api/floorplan/\", csrf_exempt(views.FloorplanView.as_view())),\n path(\"api/floorplan/\", csrf_exempt(views.FloorplanView.as_view())),\n] + static('/files', document_root='files')", + "peekOfCode": "urlpatterns = [\n path(\"admin/\", admin.site.urls),\n path(\"api/products\", csrf_exempt(views.Products.as_view())),\n path(\"api/floorplan/\", csrf_exempt(views.FloorplanView.as_view())),\n path(\"api/floorplan/\", csrf_exempt(views.FloorplanView.as_view())),\n path(\"api/floorplan//points\", csrf_exempt(views.FloorplanPointsView.as_view())),\n] + static('/files', document_root='files')", "detail": "back.back.urls", "documentation": {} }, diff --git a/admin_front/pages/plan/index.vue b/admin_front/pages/plan/index.vue index 2e1074d..70e16b7 100644 --- a/admin_front/pages/plan/index.vue +++ b/admin_front/pages/plan/index.vue @@ -101,10 +101,24 @@ const updateValues = async () => { } const target_array = ref<{ type: string, title: string, points?: { x: number, y: number } }[]>([]) -const target_type = ref() +const target_type = ref('') const addTargetType = (name: string) => { target_type.value = name } + +const savePoints = async ()=>{ + const res = await fetch(`${config.public.apiBase}/api/floorplan/${selectFile.value}/points`, { + method: 'POST', + headers: { + 'Accept': 'application/json', + "Content-Type": "application/json", + }, + body: JSON.stringify({ + points: target_array.value + }) + }) + const data = await res.json() +} onMounted(async () => { await loadFiles() }) @@ -117,7 +131,7 @@ watch(active_point, () => { const t_index = target_array.value.findIndex(el => el.type == target_type.value) if (t_index !== -1) target_array.value.splice(t_index, 1) - const t = ({ type: target_type.value, title: 'home', points: active_point.value }) + const t = ({ type: target_type.value, title: target_type.value, points: active_point.value }) const t_state_index = target_points.value.findIndex(el => el.type == target_type.value) if (t_state_index !== -1) target_points.value.splice(t_state_index, 1) @@ -196,6 +210,9 @@ watch(active_point, () => { {{ item.points }} + diff --git a/back/api/models.py b/back/api/models.py index cb2edb7..76a78cd 100644 --- a/back/api/models.py +++ b/back/api/models.py @@ -20,4 +20,9 @@ class Floorplan(models.Model): np_field = models.TextField() d_size = models.IntegerField(null=True, blank=True) d_border = models.IntegerField(null=True, blank=True) - paths = models.TextField() \ No newline at end of file + paths = models.TextField() + + +class FloorplanPoints(models.Model): + plan = models.OneToOneField(Floorplan, on_delete=models.CASCADE, primary_key=True) + points = models.JSONField() diff --git a/back/api/serializers.py b/back/api/serializers.py index c8f5c17..1fc807c 100644 --- a/back/api/serializers.py +++ b/back/api/serializers.py @@ -1,9 +1,10 @@ from rest_framework import routers, serializers, viewsets -from .models import Product, Floorplan +from .models import Floorplan, FloorplanPoints, Product import logging logger = logging.getLogger("root") + class ProductSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Product @@ -17,7 +18,7 @@ class ProductSerializer(serializers.HyperlinkedModelSerializer): "image3", ] - + class FloorplanSerializer(serializers.ModelSerializer): class Meta: model = Floorplan @@ -27,13 +28,23 @@ class FloorplanSerializer(serializers.ModelSerializer): "np_field", "d_border", "d_size", - "paths" + "paths", ] + class FloorplanListSerializer(serializers.ModelSerializer): class Meta: model = Floorplan fields = [ "id", "title", - ] \ No newline at end of file + ] + + +class FloorplanPointsSerializer(serializers.ModelSerializer): + class Meta: + model = FloorplanPoints + fields = [ + "points", + "plan", + ] diff --git a/back/api/views.py b/back/api/views.py index b727473..6a939a6 100644 --- a/back/api/views.py +++ b/back/api/views.py @@ -4,8 +4,9 @@ from rest_framework.views import APIView from django.http import JsonResponse from api.tracer import parse_image, read_image, numpy_zip_str_to_arr -from .serializers import FloorplanSerializer, FloorplanListSerializer, ProductSerializer -from .models import Floorplan, Product +from .serializers import (FloorplanListSerializer, FloorplanPointsSerializer, FloorplanSerializer, + ProductSerializer) +from .models import Floorplan, FloorplanPoints, Product import logging @@ -97,3 +98,17 @@ class FloorplanView(APIView): except Exception as e: logger.error(e) raise e + +class FloorplanPointsView(APIView): + def get(self, request, id): + points = FloorplanPoints.objects.get(plan=id) + serializer = FloorplanPointsSerializer(points, many=False) + return JsonResponse(serializer.data, safe=False) + + def post(self, request, id): + data = JSONParser().parse(request) + data["plan"] = id + serializer = FloorplanPointsSerializer(data=data) + if serializer.is_valid(): + serializer.save() + return JsonResponse(serializer.data, status=201) \ No newline at end of file diff --git a/back/back/urls.py b/back/back/urls.py index 834f599..bf713bf 100644 --- a/back/back/urls.py +++ b/back/back/urls.py @@ -25,4 +25,5 @@ urlpatterns = [ path("api/products", csrf_exempt(views.Products.as_view())), path("api/floorplan/", csrf_exempt(views.FloorplanView.as_view())), path("api/floorplan/", csrf_exempt(views.FloorplanView.as_view())), + path("api/floorplan//points", csrf_exempt(views.FloorplanPointsView.as_view())), ] + static('/files', document_root='files')