@afeefa/vue-app 0.0.204 → 0.0.206

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- 0.0.204
1
+ 0.0.206
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@afeefa/vue-app",
3
- "version": "0.0.204",
3
+ "version": "0.0.206",
4
4
  "description": "",
5
5
  "author": "Afeefa Kollektiv <kollektiv@afeefa.de>",
6
6
  "license": "MIT",
@@ -0,0 +1,112 @@
1
+ <template>
2
+ <div>
3
+ <v-label v-if="$attrs.label">
4
+ {{ $attrs.label }}
5
+ </v-label>
6
+
7
+ <a-row
8
+ :vertical="vertical"
9
+ :gap="vertical ? 0 : 4"
10
+ >
11
+ <a-checkbox
12
+ v-for="option in options_"
13
+ :key="option.itemValue"
14
+ :label="option.itemText"
15
+ :value="isChecked(option.itemValue)"
16
+ hide-details
17
+ @input="checked(option.itemValue, $event)"
18
+ >
19
+ <template #label>
20
+ <div v-html="option.itemText" />
21
+ </template>
22
+ </a-checkbox>
23
+ </a-row>
24
+
25
+ <div
26
+ v-if="errorMessages.length"
27
+ class="mt-1 error--text v-messages"
28
+ >
29
+ {{ errorMessages[0] }}
30
+ </div>
31
+ </div>
32
+ </template>
33
+
34
+
35
+ <script>
36
+ import { Component, Vue, Watch, Inject } from '@a-vue'
37
+
38
+ @Component({
39
+ props: ['value', 'options', 'validator', {vertical: false}]
40
+ })
41
+ export default class ACheckboxGroup extends Vue {
42
+ value_ = []
43
+ options_ = []
44
+ errorMessages = []
45
+ hasError = false
46
+
47
+ @Inject({ from: 'form', default: null }) form
48
+
49
+ created () {
50
+ this.form && this.form.register(this)
51
+ this.value_ = this.value || []
52
+ this.init()
53
+ }
54
+
55
+ checked (key, value) {
56
+ if (value) {
57
+ if (!this.isChecked(key)) {
58
+ this.value_.push(key)
59
+ }
60
+ } else {
61
+ this.value_ = this.value_.filter(v => v !== key)
62
+ }
63
+ this.$emit('input', this.value_)
64
+ this.validate()
65
+ }
66
+
67
+ isChecked (key) {
68
+ return this.value_.includes(key)
69
+ }
70
+
71
+ @Watch('options')
72
+ optionsChanged () {
73
+ this.init()
74
+ }
75
+
76
+ @Watch('value')
77
+ valueChanged (value) {
78
+ this.value_ = value || []
79
+ }
80
+
81
+ async init () {
82
+ const options = typeof this.options === 'function' ? this.options() : this.options
83
+
84
+ if (options instanceof Promise) {
85
+ this.options_ = await options
86
+ } else {
87
+ this.options_ = options
88
+ }
89
+
90
+ this.$nextTick(() => {
91
+ this.validate()
92
+ })
93
+ }
94
+
95
+ validate () {
96
+ this.errorMessages = []
97
+ if (this.validator) {
98
+ const rules = this.validator.getRules(this.$attrs.label)
99
+ for (const rule of rules) {
100
+ const message = rule(this.value_)
101
+ if (typeof message === 'string') {
102
+ this.errorMessages.push(message)
103
+ break
104
+ }
105
+ }
106
+ }
107
+
108
+ this.hasError = !!this.errorMessages.length // VForm will watch the hasError prop
109
+ return !this.errorMessages.length
110
+ }
111
+ }
112
+ </script>
@@ -0,0 +1,30 @@
1
+ <template>
2
+ <a-checkbox-group
3
+ v-model="model[name]"
4
+ :label="label || name"
5
+ :options="_options"
6
+ :validator="validator"
7
+ v-bind="$attrs"
8
+ v-on="$listeners"
9
+ />
10
+ </template>
11
+
12
+ <script>
13
+ import { Component, Mixins } from '@a-vue'
14
+ import { FormFieldMixin } from '../FormFieldMixin'
15
+
16
+ @Component
17
+ export default class FormFieldCheckboxGroup extends Mixins(FormFieldMixin) {
18
+ options = null
19
+
20
+ created () {
21
+ if (this.fieldHasOptionsRequest() || this.fieldHasOptions()) {
22
+ this.options = this.getSelectOptions()
23
+ }
24
+ }
25
+
26
+ get _options () {
27
+ return this.$attrs.options || this.options || []
28
+ }
29
+ }
30
+ </script>
@@ -4,6 +4,7 @@ import EditForm from './form/EditForm'
4
4
  import EditModal from './form/EditModal'
5
5
  import FormFieldCategory from './form/fields/FormFieldCategory'
6
6
  import FormFieldCheckbox from './form/fields/FormFieldCheckbox'
7
+ import FormFieldCheckboxGroup from './form/fields/FormFieldCheckboxGroup'
7
8
  import FormFieldDate from './form/fields/FormFieldDate'
8
9
  import FormFieldRadioGroup from './form/fields/FormFieldRadioGroup'
9
10
  import FormFieldRichTextArea from './form/fields/FormFieldRichTextArea'
@@ -26,6 +27,7 @@ Vue.component('FormFieldText', FormFieldText)
26
27
  Vue.component('FormFieldTextArea', FormFieldTextArea)
27
28
  Vue.component('FormFieldRichTextArea', FormFieldRichTextArea)
28
29
  Vue.component('FormFieldRadioGroup', FormFieldRadioGroup)
30
+ Vue.component('FormFieldCheckboxGroup', FormFieldCheckboxGroup)
29
31
  Vue.component('FormFieldCategory', FormFieldCategory)
30
32
  Vue.component('FormFieldCheckbox', FormFieldCheckbox)
31
33
  Vue.component('FormFieldDate', FormFieldDate)
@@ -104,19 +104,35 @@ export default class PopupMenuList extends Vue {
104
104
  if (!filterTerm) {
105
105
  return this.items
106
106
  } else {
107
- return this.items.filter(item => {
108
- // find parent only if it has no children
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
109
111
  const itemFound = item.title.toLowerCase().includes(filterTerm.toLowerCase())
110
112
  if (itemFound && !item.children?.length) {
113
+ selectableItems.push(item)
111
114
  return true
112
115
  }
113
116
 
114
- // find a child
115
- const childFound = item.children?.some(item => {
116
- return item.title.toLowerCase().includes(filterTerm.toLowerCase())
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
117
124
  })
118
- return childFound
125
+
126
+ // count parent only if it has min 1 filtered child
127
+ return filteredChildren?.length || false
119
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
120
136
  }
121
137
  }
122
138
 
@@ -52,9 +52,12 @@
52
52
  </template>
53
53
 
54
54
  <div v-else>
55
- <div v-if="labelEmpty">
55
+ <a-row
56
+ v-if="labelEmpty"
57
+ gap="1"
58
+ >
56
59
  <x-icon :color="xColorEmpty" /> {{ labelEmpty }}
57
- </div>
60
+ </a-row>
58
61
 
59
62
  <a-icon-button
60
63
  v-if="buttonCreate"