homemanager-fe/src/components/house-planner/PlannerPropertyPanel.vue

149 lines
3.4 KiB
Vue
Raw Permalink Normal View History

2023-01-17 18:32:15 +00:00
<template>
2023-11-07 20:08:56 +00:00
<PlannerSidebar :title="$t('planner.panel.properties.title')">
2023-01-17 18:32:15 +00:00
<div
2023-01-18 17:00:51 +00:00
class="bg-white-50 flex h-full flex-col overflow-auto"
2023-01-17 18:32:15 +00:00
v-if="selectedObject && applicableProperties"
>
2023-01-18 17:00:51 +00:00
<PropertyFormItem
2023-01-17 18:32:15 +00:00
v-for="prop of applicableProperties.properties"
2023-01-18 17:00:51 +00:00
:id="selectedObject.id"
:prop="prop"
:value="selectedObject[prop.key as keyof typeof selectedObject]"
@update="(newValue) => updateProp(prop, newValue)"
/>
2023-01-17 18:32:15 +00:00
</div>
</PlannerSidebar>
</template>
<script setup lang="ts">
import PlannerSidebar from './PlannerSidebar.vue';
import { Layer } from '../../modules/house-planner/interfaces';
import {
ObjectProperties,
ObjectProperty,
} from './interfaces/properties.interfaces';
import { computed } from 'vue';
2023-01-18 17:00:51 +00:00
import PropertyFormItem from './PropertyFormItem.vue';
2023-11-07 20:08:56 +00:00
import { useI18n } from 'vue-i18n';
const { t } = useI18n();
2023-01-17 18:32:15 +00:00
const props = defineProps<{
layers: Layer[];
}>();
const emit = defineEmits<{
(
e: 'update',
layerId: number,
objectId: number,
key: string,
2023-11-07 20:08:56 +00:00
value: unknown,
2023-01-17 18:32:15 +00:00
): void;
}>();
const commonProps: ObjectProperty[] = [
2023-11-07 20:08:56 +00:00
{ key: 'name', title: t('planner.properties.name'), type: 'string' },
{
key: 'visible',
title: t('planner.properties.visible'),
type: 'boolean',
groupable: true,
},
2023-01-17 18:32:15 +00:00
];
const lineProps: ObjectProperty[] = [
...commonProps,
2023-11-07 20:08:56 +00:00
{
key: 'width',
title: t('planner.properties.width'),
type: 'number',
groupable: true,
},
{
key: 'color',
title: t('planner.properties.color'),
type: 'color',
groupable: true,
},
2023-01-17 18:32:15 +00:00
{
key: 'lineCap',
2023-11-07 20:08:56 +00:00
title: t('planner.properties.lineCap'),
2023-01-17 18:32:15 +00:00
type: 'select',
groupable: true,
options: [
{ value: undefined, title: '' },
2023-11-07 20:08:56 +00:00
{ value: 'butt', title: t('planner.properties.butt') },
{ value: 'round', title: t('planner.properties.round') },
{ value: 'square', title: t('planner.properties.square') },
2023-01-17 18:32:15 +00:00
],
},
2023-01-18 17:00:51 +00:00
{
key: 'lineJoin',
2023-11-07 20:08:56 +00:00
title: t('planner.properties.lineJoin'),
2023-01-18 17:00:51 +00:00
type: 'select',
groupable: true,
options: [
{ value: undefined, title: '' },
2023-11-07 20:08:56 +00:00
{ value: 'miter', title: t('planner.properties.miter') },
{ value: 'bevel', title: t('planner.properties.bevel') },
{ value: 'round', title: t('planner.properties.round') },
2023-01-18 17:00:51 +00:00
],
},
2023-11-07 20:08:56 +00:00
{
key: 'closed',
title: t('planner.properties.closed'),
type: 'boolean',
groupable: true,
},
2023-01-17 18:32:15 +00:00
];
const objectTypeProperties: ObjectProperties[] = [
{
type: 'line',
properties: lineProps,
},
{
type: 'curve',
properties: lineProps,
},
{
type: 'room',
properties: lineProps,
},
{
type: 'object',
properties: commonProps,
},
];
const currentLayer = computed(() =>
2023-11-07 20:08:56 +00:00
props.layers.find((layer) => layer.active && layer.visible),
2023-01-17 18:32:15 +00:00
);
// TODO multi edit
const selectedObject = computed(
2023-11-07 20:08:56 +00:00
() => currentLayer.value?.contents?.filter((obj) => obj.selected)[0],
2023-01-17 18:32:15 +00:00
);
const applicableProperties = computed(
() =>
selectedObject.value &&
objectTypeProperties.find(
2023-11-07 20:08:56 +00:00
(prop) => prop.type === selectedObject.value?.type,
),
2023-01-17 18:32:15 +00:00
);
const updateProp = (prop: ObjectProperty, value: unknown) => {
if (!currentLayer.value || !selectedObject.value) return;
if (prop.type === 'number') value = parseFloat(value as string);
emit(
'update',
currentLayer.value!.id,
selectedObject.value!.id,
prop.key,
2023-11-07 20:08:56 +00:00
value,
2023-01-17 18:32:15 +00:00
);
};
</script>