@afeefa/vue-app 0.0.203 → 0.0.205

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- 0.0.203
1
+ 0.0.205
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@afeefa/vue-app",
3
- "version": "0.0.203",
3
+ "version": "0.0.205",
4
4
  "description": "",
5
5
  "author": "Afeefa Kollektiv <kollektiv@afeefa.de>",
6
6
  "license": "MIT",
@@ -20,14 +20,15 @@
20
20
  <hr>
21
21
  </template>
22
22
 
23
- <input
24
- v-if="items.length > 20"
23
+ <a-text-field
24
+ v-if="!nestLevel && numItemsWithChildren > 8"
25
25
  v-model="filterTerm"
26
+ class="mt-1 mb-2"
26
27
  type="text"
27
- class="inputElement inputElement--filter"
28
28
  placeholder="Filtern"
29
- autofocus
30
- >
29
+ focus
30
+ hide-details
31
+ />
31
32
 
32
33
  <div
33
34
  v-for="item in filteredItems"
@@ -57,6 +58,7 @@
57
58
  <popup-menu-list
58
59
  v-if="item.children?.length && selectedItem === item"
59
60
  :parent="canSelectParent && item"
61
+ :parentFilterTerm="filterTerm"
60
62
  :items="item.children"
61
63
  :level="nestLevel + 1"
62
64
  :position="getPosition(item)"
@@ -75,7 +77,7 @@
75
77
  v-if="filteredItems.length === 0"
76
78
  class="noItems"
77
79
  >
78
- Keine Einträge
80
+ Keine Einträge gefunden
79
81
  </p>
80
82
  </a-popup>
81
83
  </template>
@@ -86,7 +88,7 @@ import { Component, Vue } from '@a-vue'
86
88
  import { PositionConfig } from '../../services/PositionService'
87
89
 
88
90
  @Component({
89
- props: ['items', 'parent', 'level', 'position', {canSelectParent: true}],
91
+ props: ['items', 'parent', 'level', 'position', {canSelectParent: true}, 'parentFilterTerm'],
90
92
  name: 'popup-menu-list'
91
93
  })
92
94
  export default class PopupMenuList extends Vue {
@@ -98,15 +100,48 @@ export default class PopupMenuList extends Vue {
98
100
  }
99
101
 
100
102
  get filteredItems () {
101
- if (!this.filterTerm) {
103
+ const filterTerm = this.parentFilterTerm || this.filterTerm
104
+ if (!filterTerm) {
102
105
  return this.items
103
106
  } else {
104
- return this.items.filter(item => {
105
- return item.title.toLowerCase().includes(this.filterTerm.toLowerCase())
107
+ const selectableItems = [] // this list of children is shown instead of the root list in case of max 5 selectable filter results
108
+
109
+ const items = this.items.filter(item => {
110
+ // count parent only if it has no children
111
+ const itemFound = item.title.toLowerCase().includes(filterTerm.toLowerCase())
112
+ if (itemFound && !item.children?.length) {
113
+ selectableItems.push(item)
114
+ return true
115
+ }
116
+
117
+ // find all filtered children
118
+ const filteredChildren = item.children?.filter(item => {
119
+ if (item.title.toLowerCase().includes(filterTerm.toLowerCase())) {
120
+ selectableItems.push(item)
121
+ return true
122
+ }
123
+ return false
124
+ })
125
+
126
+ // count parent only if it has min 1 filtered child
127
+ return filteredChildren?.length || false
106
128
  })
129
+
130
+ // return the list of children instead the root list
131
+ if (selectableItems.length <= 5) {
132
+ return selectableItems
133
+ }
134
+
135
+ return items
107
136
  }
108
137
  }
109
138
 
139
+ get numItemsWithChildren () {
140
+ return this.items.reduce((num, i) => {
141
+ return num + 1 + (i.children?.length || 0)
142
+ }, 0)
143
+ }
144
+
110
145
  click (item) {
111
146
  if (item === this.parent) { // parent item
112
147
  this.$emit('click', item)
@@ -150,18 +185,11 @@ export default class PopupMenuList extends Vue {
150
185
  }
151
186
 
152
187
  .noItems {
153
- font-size: .8rem;
154
- font-weight:bold;
155
- margin: .5em 0;
188
+ font-size: .9rem;
189
+ margin: .2rem;
156
190
  white-space: nowrap;
157
191
  }
158
192
 
159
- .inputElement--filter {
160
- font-size: .8rem;
161
- margin-bottom: .5em;
162
- padding: .5em;
163
- }
164
-
165
193
  .item {
166
194
  display: flex;
167
195
  align-items: center;