bx-865-apps #1

Merged
ksenia_mikhailova merged 140 commits from bx-865-apps into main 2024-06-27 15:03:27 +03:00
3 changed files with 72 additions and 20 deletions
Showing only changes of commit aee92eddbe - Show all commits

View File

@ -40,7 +40,13 @@ const sampling_data = () => {
})
paths_array.value = res
}
watch(point_array, (newStatus) => {
watch(point_array, () => {
sampling_data()
})
watch(chunk_size, () => {
sampling_data()
})
watch(threshold, () => {
sampling_data()
})
onMounted(() => {
@ -61,7 +67,8 @@ onMounted(() => {
<style scoped>
svg path {
fill: transparent
fill: transparent;
stroke: rgba(70, 70, 0, 0.1);
}
svg path:hover {

View File

@ -6,14 +6,10 @@ import { chunks } from '~/helpers';
const config = useRuntimeConfig()
const point_array = useState('point_array', () => [[]])
const chunk_size = useState('chunk_size', () => 8)
const threshold = useState('chunk_size', () => 20)
const threshold = useState('threshold', () => 20)
const paths_array = ref<{ path: string, unwalkable: boolean, x: number, y: number }[]>()
const loading = ref<boolean>(false)
const canvasElement: Ref<HTMLCanvasElement | undefined> = ref();
const context: Ref<CanvasRenderingContext2D | undefined> = ref();
const grid = ref<Grid>()
const startPoint = ref<number[]>()
const endPoint = ref<number[]>()
@ -26,16 +22,17 @@ const files = ref([])
const cw = 1920
const ch = 800
const nextFrame = () => new Promise(resolve => requestAnimationFrame(resolve));
const title = ref()
const beforeUpload = () => {
loading.value = true
const dataToState = (data: any) => {
point_array.value = data.np_field
title.value = data.title
}
const onUpload = (event: FileUploadUploadEvent) => {
try {
const data = JSON.parse(event.xhr.response)
point_array.value = data.response.np_field
dataToState(data.response)
} catch (error) {
console.log(error)
}
@ -45,12 +42,13 @@ const selectFileEvent = async () => {
try {
const res = await fetch(`${config.public.apiBase}/api/floorplan/${selectFile.value}`)
const data = await res.json()
point_array.value = data.np_field
dataToState(data)
} catch (error) {
console.log(error)
}
loadingFile.value = false
}
const loadFiles = async () => {
try {
loadingFile.value = true
@ -63,17 +61,17 @@ const loadFiles = async () => {
loadingFile.value = false
}
const openBlocks = ref<string[]>([])
const isBlockOpen = (name: string) => {
return openBlocks.value.includes(name)
}
const toggleBlock = (name: string) => {
if (openBlocks.value.includes(name)) {
if (isBlockOpen(name)) {
openBlocks.value.splice(openBlocks.value.indexOf(name), 1)
} else {
openBlocks.value.push(name)
}
}
const isBlockOpen = (name: string) => {
return openBlocks.value.includes(name)
}
const openBlocks = ref<string[]>([])
const fileBtnClick = async () => {
if (isBlockOpen('upload_file')) {
@ -81,6 +79,21 @@ const fileBtnClick = async () => {
}
toggleBlock('upload_file')
}
const updateValues = async () => {
const res = await fetch(`${config.public.apiBase}/api/floorplan/${selectFile.value}`, {
method: 'PATCH',
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
title: title.value,
d_size: chunk_size.value,
d_border: threshold.value,
})
})
const data = await res.json()
}
onMounted(async () => {
await loadFiles()
})
@ -104,12 +117,27 @@ onMounted(async () => {
</Panel>
<Panel header="Загрузка файла" v-if="isBlockOpen('upload_file')">
<FileUpload mode="basic" name="demo" :url="`${config.public.apiBase}/api/floorplan/`" accept="image/*"
:maxFileSize="10000000" @upload="onUpload" @before-upload="beforeUpload" :auto="true"
chooseLabel="Выберите файл" :disabled="loading" />
:maxFileSize="10000000" @upload="onUpload" :auto="true" chooseLabel="Выберите файл"
:disabled="loading" />
</Panel>
<Panel header="Данные для работы">
<div class="flex align-middle items-end gap-2">
<div class="flex flex-col">
<label for="title">Название</label>
<InputText id="title" type="text" v-model="title" />
</div>
<div class="flex flex-col">
<label for="chunk">Значение дискретизации</label>
<InputNumber id="chunk" type="text" showButtons :min="0" :max="50" v-model="chunk_size" />
</div>
<div class="flex flex-col">
<label for="threshold">Пороговое значение</label>
<InputNumber id="threshold" type="text" showButtons :min="0" :max="chunk_size * chunk_size"
v-model="threshold" />
</div>
<Button @click="updateValues">Сохранить данные</Button>
</div>
</Panel>
<Panel :header="loading ? `Идет отрисовка` : `Обработанный план здания`">

View File

@ -78,3 +78,20 @@ class FloorplanView(APIView):
except Exception as e:
logger.error(e)
raise e
def patch(self, request, id):
try:
if id is not None:
item = Floorplan.objects.get(id=id)
serializer = FloorplanSerializer(item, data=request.data, partial=True)
data = serializer.data
if serializer.is_valid():
serializer.save()
return JsonResponse(status=201)
else:
logger.info(serializer.errors)
else:
return JsonResponse("No item", status=400)
except Exception as e:
logger.error(e)
raise e