1
1
<template >
2
- <div class =" column" >
3
- <div class =" row justify-center" >
4
-
5
- <q-tab-panels v-model =" viewMode" animated style =" width : 100% " >
2
+ <div >
3
+ <div id =" style-manager-header" class =" q-px-md q-mt-md" v-if =" title || (toolbar && toolbar.length)" >
4
+ <div v-if =" title" class =" ellipsis text-h6" >
5
+ {{ $tie(title) }}
6
+ </div >
7
+ <KPanel
8
+ id =" style-manager-toolbar"
9
+ :content =" toolbar"
10
+ v-bind:class =" { 'q-gutter-x-sm' : $q.screen.gt.xs, 'q-gutter-x-xs': $q.screen.lt.sm }"
11
+ />
12
+ <QSeparator inset />
13
+ </div >
14
+ <div id =" style-manager-content" >
15
+ <q-tab-panels v-model =" viewMode" animated >
6
16
<q-tab-panel name =" list" >
7
17
<KGrid
8
- service =" styles"
9
- :append-items =" true"
10
- :base-query =" baseQuery"
11
- :filter-query =" filterQuery"
12
- class =" fit"
13
- :renderer =" {
14
- component: 'collection/KItem',
15
- actions: [
16
- {
17
- id: 'edit-style',
18
- icon: 'las la-edit',
19
- tooltip: 'KStyleManager.EDIT',
20
- scope: 'header',
21
- handler: editStyle
22
- },
23
- {
24
- id: 'delete-style',
25
- icon: 'las la-trash',
26
- tooltip: 'KStyleManager.DELETE',
27
- scope: 'footer',
28
- handler: { name: 'removeItem', params: ['confirm'] }
29
- },
30
- ],
31
- class: 'col-12'
32
- }"
18
+ service =" styles"
19
+ :append-items =" true"
20
+ :base-query =" baseQuery"
21
+ :filter-query =" filterQuery"
22
+ class =" fit"
23
+ :renderer =" {
24
+ component: 'styles/KStylePreviewItem',
25
+ options: {
26
+ avatar: false
27
+ },
28
+ actions: [
29
+ {
30
+ id: 'apply-to-selection',
31
+ icon: 'las la-object-ungroup',
32
+ tooltip: 'KStyleManager.APPLY_TO_SELECTION',
33
+ scope: 'header',
34
+ handler: applyToSelection
35
+ },
36
+ {
37
+ id: 'edit-style',
38
+ icon: 'las la-edit',
39
+ tooltip: 'KStyleManager.EDIT',
40
+ scope: 'header',
41
+ handler: editStyle
42
+ },
43
+ {
44
+ id: 'delete-style',
45
+ icon: 'las la-trash',
46
+ tooltip: 'KStyleManager.DELETE',
47
+ scope: 'footer',
48
+ handler: { name: 'removeItem', params: ['confirm'] }
49
+ },
50
+ ],
51
+ class: 'col-12'
52
+ }"
33
53
/>
34
54
</q-tab-panel >
35
55
<q-tab-panel name =" edit" >
36
- <k- style-editor />
56
+ <KStyleEditor ref = " styleEditor " : style= " style " @cancel = " onCancel " @apply = " onApply " />
37
57
</q-tab-panel >
38
58
</q-tab-panels >
39
-
40
59
</div >
41
60
</div >
42
61
</template >
45
64
import { computed , ref } from ' vue'
46
65
import _ from ' lodash'
47
66
import { KGrid } from ' ../../../../core/client/components'
48
- import { Store } from ' @kalisio/kdk/core.client'
67
+ import { Store , api } from ' @kalisio/kdk/core.client'
49
68
import KStyleEditor from ' ./KStyleEditor.vue'
69
+ import { useCurrentActivity } from ' ../../composables/activity.js'
70
+ import { isLayerStyleEditable } from ' ../../utils/utils.layers.js'
71
+ import { editFeaturesStyle } from ' ../../utils/utils.features.js'
72
+
73
+ // Props
74
+ defineProps ({
75
+ title: {
76
+ type: String ,
77
+ default: ' '
78
+ }
79
+ })
50
80
51
81
// Data
52
82
const filter = Store .get (' filter' )
83
+ const styleEditor = ref (null )
84
+ const style = ref (null )
53
85
const viewMode = ref (' list' )
86
+ const { getSelectedFeaturesByLayer } = useCurrentActivity ()
54
87
55
88
// Computed
56
89
const baseQuery = computed (() => {
@@ -63,10 +96,58 @@ const filterQuery = computed(() => {
63
96
// Filter the objects against the group
64
97
return query
65
98
})
99
+ const toolbar = computed (() => {
100
+ if (viewMode .value === ' edit' ) return []
101
+ return [
102
+ {
103
+ component: ' collection/KSorter' ,
104
+ id: ' style-manager-sorter-options' ,
105
+ tooltip: ' KStyleManager.SORT' ,
106
+ options: [
107
+ { icon: ' las la-sort-alpha-down' , value: { field: ' name' , order: 1 }, default: true },
108
+ { icon: ' las la-sort-alpha-up' , value: { field: ' name' , order: - 1 } },
109
+ { icon: ' kdk:clockwise.png' , value: { field: ' updatedAt' , order: 1 } },
110
+ { icon: ' kdk:anticlockwise.png' , value: { field: ' updatedAt' , order: - 1 } }
111
+ ]
112
+ },
113
+ { component: ' collection/KFilter' , style: ' max-width: 200px;' },
114
+ { component: ' QSpace' },
115
+ {
116
+ id: ' add-layer-category' ,
117
+ icon: ' las la-plus-circle' ,
118
+ tooltip: ' KStyleManager.CREATE_STYLE' ,
119
+ size: ' 1rem' ,
120
+ handler : () => { editStyle () }
121
+ }
122
+ ]
123
+ })
66
124
67
- function editStyle (style ) {
68
- console .log (style)
125
+ // Functions
126
+ function applyToSelection (styleToApply ) {
127
+ const type = { Point : ' point' , LineString: ' line' , Polygon: ' polygon' }
128
+ _ .forEach (getSelectedFeaturesByLayer (), layer => {
129
+ if (isLayerStyleEditable (layer .layer )) {
130
+ _ .forEach (layer .features , f => { f .style = _ .get (styleToApply, [' item' , _ .get (type, f .geometry .type , ' point' )], null ) })
131
+ editFeaturesStyle ({ type: ' FeatureCollection' , features: layer .features }, layer .layer )
132
+ }
133
+ })
134
+ }
135
+ function editStyle (styleToEdit ) {
69
136
viewMode .value = ' edit'
137
+ style .value = _ .get (styleToEdit, ' item' , null )
138
+ }
139
+ function onApply (style ) {
140
+ const service = api .getService (' styles' )
141
+ if (style ._id ) {
142
+ service .patch (style ._id , style)
143
+ } else {
144
+ service .create (style)
145
+ }
146
+ viewMode .value = ' list'
147
+ }
148
+
149
+ function onCancel () {
150
+ viewMode .value = ' list'
70
151
}
71
152
72
153
</script >
0 commit comments