Skip to content

Commit 0de68d8

Browse files
committed
better locations form
1 parent 4dd30b3 commit 0de68d8

File tree

14 files changed

+74
-34
lines changed

14 files changed

+74
-34
lines changed

src/api/groups.service.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,42 @@ import { _adaptParamsToGetQuery } from '@/api/utils.service'
1515
import useAPI from '@/composables/useAPI'
1616
import { ProjectModel } from '@/models/project.model'
1717
import { PeopleGroupModel } from '@/models/invitation.model'
18+
import { LocationModel } from '@/models/location.model'
19+
// import { delay } from 'es-toolkit'
1820

1921
// HIERARCHY
2022

2123
export async function getHierarchyGroups(organizationCode: string, config = {}) {
24+
// await delay(5000)
2225
return await useAPI<PaginationResult<HierarchyGroupModel>>(
2326
`organization/${organizationCode}/people-groups-hierarchy/`,
2427
config
2528
)
2629
}
2730

2831
export async function getPeopleGroupsHierarchy(org_code, params) {
32+
// await delay(5000)
2933
return await useAPI(`organization/${org_code}/people-groups-hierarchy/`, {
3034
..._adaptParamsToGetQuery(params),
3135
}) //.data.value
3236
}
3337

3438
export async function getGroups(org_id) {
39+
// await delay(5000)
3540
return await useAPI(`organization/${org_id}/people-group/`, {}) //.data.value
3641
}
3742

3843
// ALL GROUPS
3944

4045
export async function getPeopleGroups(org_code, params) {
46+
// await delay(5000)
4147
return await useAPI(`organization/${org_code}/people-group/`, {
4248
..._adaptParamsToGetQuery(params),
4349
}) //.data.value
4450
}
4551

4652
export async function postGroup(org: string, groupData: PostGroupData) {
53+
// await delay(5000)
4754
return await useAPI(`organization/${org}/people-group/`, { body: groupData, method: 'POST' })
4855
//.data.value
4956
}
@@ -55,6 +62,7 @@ export async function addParentGroup(
5562
groupId: number,
5663
body: AddParentGroupModelInput
5764
) {
65+
// await delay(5000)
5866
return await useAPI(`organization/${orgId}/people-group/${groupId}/`, { body, method: 'PATCH' }) //.data.value
5967
}
6068

@@ -70,13 +78,15 @@ export async function patchGroup(
7078
groupName: number,
7179
groupData: Partial<PostGroupData>
7280
) {
81+
// await delay(5000)
7382
return await useAPI(`organization/${organizationCode}/people-group/${groupName}/`, {
7483
body: groupData,
7584
method: 'PATCH',
7685
}) //.data.value
7786
}
7887

7988
export async function deleteGroup(organizationCode: string, groupName: string) {
89+
// await delay(5000)
8090
return await useAPI(`organization/${organizationCode}/people-group/${groupName}/`, {
8191
method: 'DELETE',
8292
}) //.data.value
@@ -85,6 +95,7 @@ export async function deleteGroup(organizationCode: string, groupName: string) {
8595
// GROUP MEMBERS
8696

8797
export async function getGroupMember(organizationCode: string, groupId: number, config = {}) {
98+
// await delay(5000)
8899
return await useAPI<PaginationResult<GroupMember>>(
89100
`organization/${organizationCode}/people-group/${groupId}/member/`,
90101
config
@@ -96,6 +107,7 @@ export async function postGroupMembers(
96107
groupId: number,
97108
membersData: AddGroupMembers
98109
) {
110+
// await delay(5000)
99111
return await useAPI(`organization/${organizationCode}/people-group/${groupId}/member/add/`, {
100112
body: membersData,
101113
method: 'POST',
@@ -107,6 +119,7 @@ export async function removeGroupMember(
107119
groupId: number,
108120
membersData: RemoveGroupMember
109121
) {
122+
// await delay(5000)
110123
return await useAPI(`organization/${organizationCode}/people-group/${groupId}/member/remove/`, {
111124
body: membersData,
112125
method: 'POST',
@@ -116,6 +129,7 @@ export async function removeGroupMember(
116129
// GROUP PROJECTS
117130

118131
export async function getGroupProject(organizationCode: string, groupId: number, config = {}) {
132+
// await delay(5000)
119133
return await useAPI<PaginationResult<ProjectModel>>(
120134
`organization/${organizationCode}/people-group/${groupId}/project/`,
121135
config
@@ -127,6 +141,7 @@ export async function postGroupProjects(
127141
group_id: number,
128142
projectsData: PostGroupProjects
129143
) {
144+
// await delay(5000)
130145
return await useAPI(`organization/${org}/people-group/${group_id}/project/add/`, {
131146
body: projectsData,
132147
method: 'POST',
@@ -138,6 +153,7 @@ export async function removeGroupProject(
138153
group_id: number,
139154
projectsData: PostGroupProjects
140155
) {
156+
// await delay(5000)
141157
return await useAPI(`organization/${org}/people-group/${group_id}/project/remove/`, {
142158
body: projectsData,
143159
method: 'POST',
@@ -147,20 +163,23 @@ export async function removeGroupProject(
147163
// GROUP HEADER
148164

149165
export async function postGroupHeader(org: string, group_id: number, headerData: FormData) {
166+
// await delay(5000)
150167
return await useAPI(`organization/${org}/people-group/${group_id}/header/`, {
151168
body: headerData,
152169
method: 'POST',
153170
}) //.data.value
154171
}
155172

156173
export async function patchGroupHeader(org: string, group_id: number, headerData: FormData) {
174+
// await delay(5000)
157175
return await useAPI(`organization/${org}/people-group/${group_id}/header/`, {
158176
body: headerData,
159177
method: 'PATCH',
160178
}) //.data.value
161179
}
162180

163181
export async function getGroupSimilar(organizationCode: string, groupId: number, config = {}) {
182+
// await delay(5000)
164183
return await useAPI<PaginationResult<PeopleGroupModel>>(
165184
`organization/${organizationCode}/people-group/${groupId}/similars/`,
166185
config
@@ -169,14 +188,16 @@ export async function getGroupSimilar(organizationCode: string, groupId: number,
169188

170189
export async function getSubGroup(organizationCode: string, groupId: number, config = {}) {
171190
// await delay(2000)
191+
// await delay(5000)
172192
return await useAPI<PaginationResult<PeopleGroupModel>>(
173193
`organization/${organizationCode}/people-group/${groupId}/subgroups/`,
174194
config
175195
)
176196
}
177197

178198
export async function getGroupLocation(organizationCode: string, groupId: number, config = {}) {
179-
return await useAPI<PaginationResult<PeopleGroupModel>>(
199+
// await delay(2000)
200+
return await useAPI<PaginationResult<LocationModel>>(
180201
`organization/${organizationCode}/people-group/${groupId}/locations/`,
181202
config
182203
)

src/components/group/Modules/Locations/GroupLocationBase.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
<FetchLoader :status="status" skeleton only-error>
33
<MapRecap :locations="locations" expand :editable="isEdit" @expand="opened = true">
44
<template #tooltip="{ location }">
5-
<ProjectLocationTooltip :location="location" :project="location.project" />
5+
<ProjectLocationTooltip
6+
:location="location as TranslatedLocation"
7+
:project="location.project"
8+
/>
69
</template>
710
</MapRecap>
811
<LocationDrawer
@@ -20,6 +23,7 @@ import LocationDrawer from '@/components/map/LocationDrawer.vue'
2023
import MapRecap from '@/components/map/MapRecap.vue'
2124
import ProjectLocationTooltip from '@/components/project/map/ProjectLocationTooltip.vue'
2225
import { TranslatedPeopleGroupModel } from '@/models/invitation.model'
26+
import { TranslatedLocation } from '@/models/location.model'
2327
2428
const props = withDefaults(
2529
defineProps<{

src/components/map/LocationForm.vue

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
</template>
1313

1414
<template #body>
15+
<div class="location-map-ctn">
16+
<!-- form not have it, so ignore typescript -->
17+
<MapRecap :locations="[form as any]" :expand="false" />
18+
</div>
19+
1520
<div class="location-type-ctn">
1621
<div class="location-type-label">
1722
{{ $t('location.location-type-label') }}
@@ -48,6 +53,7 @@ import LpiButton from '@/components/base/button/LpiButton.vue'
4853
import { LocationForm } from '@/models/location.model'
4954
import { useLocationForm } from '@/form/location'
5055
import { LocationType } from '@/models/types'
56+
import MapRecap from '@/components/map/MapRecap.vue'
5157
5258
const props = withDefaults(
5359
defineProps<{
@@ -62,10 +68,6 @@ const props = withDefaults(
6268
defineEmits(['submit', 'close', 'delete'])
6369
const { t } = useNuxtI18n()
6470
65-
const model = defineModel<LocationForm>()
66-
const { form, isValid, errors } = useLocationForm({ model })
67-
const isExist = computed(() => !!form.value.id)
68-
6971
const locationTypeOptions = computed(() => {
7072
const arr: { value: LocationType; label: string }[] = [
7173
{
@@ -86,6 +88,20 @@ const locationTypeOptions = computed(() => {
8688
}
8789
return arr
8890
})
91+
92+
const model = defineModel<LocationForm>()
93+
94+
const { form, isValid, errors } = useLocationForm({ model })
95+
96+
// safe guard for not locationsType exists
97+
watch(locationTypeOptions, () => {
98+
const values = locationTypeOptions.value.map(({ value }) => value)
99+
if (form.value.type && !values.includes(form.value.type)) {
100+
form.value.type = values[0]
101+
}
102+
})
103+
104+
const isExist = computed(() => !!form.value.id)
89105
</script>
90106

91107
<style lang="scss" scoped>
@@ -116,3 +132,9 @@ const locationTypeOptions = computed(() => {
116132
background: $salmon;
117133
}
118134
</style>
135+
136+
<style>
137+
.location-map-ctn .map-recap {
138+
height: 250px;
139+
}
140+
</style>

src/components/map/LocationTooltip.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="location-tooltip" :class="location.type" @scroll="console.log">
2+
<div class="location-tooltip" :class="location.type">
33
<div class="location-tooltip-header">
44
<LocationType :location="location" />
55
<LpiButton

src/components/map/MapRecap.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
>
1818
<slot name="tooltip" :location="location">
1919
<LocationTooltip
20-
v-if="location.$t.title || location.$t.description"
20+
v-if="location.title || location.description"
2121
:location="location"
2222
/>
2323
</slot>
@@ -44,12 +44,12 @@
4444
import ContextActionButton from '@/components/base/button/ContextActionButton.vue'
4545
import MapPointer from '@/components/map/MapPointer.vue'
4646
import BaseMap from '@/components/map/BaseMap.vue'
47-
import { TranslatedLocation } from '@/models/location.model'
47+
import { AnyTranslatedLocation } from '@/models/location.model'
4848
import LocationTooltip from '@/components/map/LocationTooltip.vue'
4949
5050
const props = withDefaults(
5151
defineProps<{
52-
locations?: TranslatedLocation[]
52+
locations?: AnyTranslatedLocation[]
5353
expand?: boolean
5454
editable?: boolean
5555
}>(),
@@ -63,7 +63,7 @@ const props = withDefaults(
6363
defineEmits<{
6464
'map-moved': []
6565
expand: []
66-
edit: [TranslatedLocation]
66+
edit: [AnyTranslatedLocation]
6767
}>()
6868
6969
const summaryMapRef = useTemplateRef('summary-map')

src/form/location.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { required, minLength } from '@vuelidate/validators'
1+
import { required, maxLength } from '@vuelidate/validators'
22
import useForm from '@/composables/useForm'
33
import { clone } from 'es-toolkit'
44
import { LocationForm } from '@/models/location.model'
@@ -13,13 +13,9 @@ const DEFAULT_FORM: LocationForm = {
1313

1414
const RULES = {
1515
title: {
16-
required,
17-
minLengthValue: minLength(1),
18-
},
19-
description: {
20-
required,
21-
minLengthValue: minLength(1),
16+
maxLengthValue: maxLength(255),
2217
},
18+
description: {},
2319
lat: { required },
2420
lng: { required },
2521
type: { required },

src/i18n/locales/ca.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,8 @@
10051005
"label": "Editor",
10061006
"help": "Editor"
10071007
}
1008-
}
1008+
},
1009+
"view": "Visualitza el grup"
10091010
},
10101011
"header": {
10111012
"private": "Privat: només visible per als membres de l' equip",

src/i18n/locales/de.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,8 @@
10051005
"label": "Herausgeber",
10061006
"help": "Teammitglieder"
10071007
}
1008-
}
1008+
},
1009+
"view": "Gruppe anzeigen"
10091010
},
10101011
"header": {
10111012
"private": "Private: nur für Teammitglieder sichtbar",

src/i18n/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,7 @@
925925
"news": "Announcements",
926926
"more": "More",
927927
"less": "Less",
928+
"view": "View group",
928929
"see-more": "See more",
929930
"see-less": "See less",
930931
"subgroups": "SUBGROUPS",

src/i18n/locales/es.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,8 @@
10051005
"label": "Editor",
10061006
"help": "Editor"
10071007
}
1008-
}
1008+
},
1009+
"view": "Ver grupo"
10091010
},
10101011
"header": {
10111012
"private": "Privada: visible sólo a los miembros del equipo",

0 commit comments

Comments
 (0)