@kigi/components 1.5.10 → 1.5.11
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.
package/package.json
CHANGED
|
@@ -5,157 +5,171 @@ import * as Fuse from 'fuse.js'
|
|
|
5
5
|
import { UtilUID } from '../../helpers/util-uid'
|
|
6
6
|
|
|
7
7
|
export class MbgSelectMultiListController {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
$
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
this
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
})
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
executeFetch() {
|
|
61
|
-
this.$timeout(() => {
|
|
62
|
-
this.fetch({ query: (this.inputValue || '') })
|
|
63
|
-
})
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
afterFetchData(data) {
|
|
67
|
-
this.$timeout(() => {
|
|
68
|
-
this.data = (data || []).filter((row) => this.ngModel.filter((model) => angular.equals(row, model)).length === 0)
|
|
69
|
-
})
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
selectRow(row) {
|
|
73
|
-
const copyRow = JSON.parse(JSON.stringify(row))
|
|
74
|
-
const index = this.findIndexRow(this.data, row)
|
|
75
|
-
if (index !== -1) {
|
|
76
|
-
copyRow._uid = UtilUID.generete()
|
|
77
|
-
this.ngModel.push(copyRow)
|
|
78
|
-
this.dataModel.push(copyRow)
|
|
79
|
-
this.data.splice(index, 1)
|
|
80
|
-
this.$timeout(() => {
|
|
81
|
-
(this.ngModel || []).forEach((model) => {
|
|
82
|
-
delete model._uid
|
|
83
|
-
})
|
|
84
|
-
}, 500)
|
|
8
|
+
private data: Array<any>
|
|
9
|
+
private ngModel: any
|
|
10
|
+
private dataModel: Array<any>
|
|
11
|
+
private fetch: Function
|
|
12
|
+
private label: string
|
|
13
|
+
private isLoading: boolean
|
|
14
|
+
private inputValue: string
|
|
15
|
+
private listRowTransclude: string
|
|
16
|
+
private listHeaderTransclude: string
|
|
17
|
+
private placeholderLeft: string
|
|
18
|
+
private placeholderRight: string
|
|
19
|
+
private inputValueResult: string
|
|
20
|
+
|
|
21
|
+
constructor(
|
|
22
|
+
public $scope,
|
|
23
|
+
public $element,
|
|
24
|
+
public $attrs,
|
|
25
|
+
public $timeout,
|
|
26
|
+
public $compile,
|
|
27
|
+
public $transclude,
|
|
28
|
+
) {}
|
|
29
|
+
|
|
30
|
+
$onInit() {
|
|
31
|
+
this.placeholderLeft = this.placeholderLeft || ''
|
|
32
|
+
this.placeholderRight = this.placeholderRight || ''
|
|
33
|
+
this.$scope.$c = this.$scope.$parent
|
|
34
|
+
this.findTransclude()
|
|
35
|
+
this.findTranscludeHeader()
|
|
36
|
+
this.$scope.$watch(
|
|
37
|
+
'$ctrl.data',
|
|
38
|
+
(data) => {
|
|
39
|
+
this.afterFetchData(data)
|
|
40
|
+
},
|
|
41
|
+
true,
|
|
42
|
+
)
|
|
43
|
+
this.$timeout(() => {
|
|
44
|
+
this.ngModel = this.ngModel || []
|
|
45
|
+
this.dataModel = JSON.parse(JSON.stringify(this.ngModel)) || []
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
findTransclude() {
|
|
50
|
+
this.$transclude(this.$scope, (cloneEl) => {
|
|
51
|
+
angular.forEach(cloneEl, (cl) => {
|
|
52
|
+
let element = angular.element(cl)[0]
|
|
53
|
+
if (element.nodeName && element.nodeName === 'MBG-ROW-CONTENT') {
|
|
54
|
+
this.listRowTransclude = element.innerHTML
|
|
85
55
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
findTranscludeHeader() {
|
|
61
|
+
this.$transclude(this.$scope, (cloneEl) => {
|
|
62
|
+
angular.forEach(cloneEl, (cl) => {
|
|
63
|
+
let element = angular.element(cl)[0]
|
|
64
|
+
if (element.nodeName && element.nodeName === 'MBG-HEADER-CONTENT') {
|
|
65
|
+
this.listHeaderTransclude = element.innerHTML
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
executeFetch() {
|
|
72
|
+
this.$timeout(() => {
|
|
73
|
+
this.fetch({ query: this.inputValue || '' })
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
afterFetchData(data) {
|
|
78
|
+
this.$timeout(() => {
|
|
79
|
+
this.data = (data || []).filter(
|
|
80
|
+
(row) => this.ngModel.filter((model) => angular.equals(row, model)).length === 0,
|
|
81
|
+
)
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
selectRow(row) {
|
|
86
|
+
const copyRow = JSON.parse(JSON.stringify(row))
|
|
87
|
+
const index = this.findIndexRow(this.data, row)
|
|
88
|
+
if (index !== -1) {
|
|
89
|
+
copyRow._uid = UtilUID.generete()
|
|
90
|
+
this.ngModel.push(copyRow)
|
|
91
|
+
this.dataModel.push(copyRow)
|
|
92
|
+
this.data.splice(index, 1)
|
|
93
|
+
this.$timeout(() => {
|
|
94
|
+
;(this.ngModel || []).forEach((model) => {
|
|
95
|
+
delete model._uid
|
|
115
96
|
})
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
findIndexRow(array: Array<any>, row) {
|
|
120
|
-
return array.findIndex((data) => angular.equals(data, row))
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
async addEvent(row) {
|
|
124
|
-
const target: any = angular.element('.result-multi-list-wrapper')
|
|
125
|
-
await target.animate({ scrollTop: this.dataModel.length * 44 }, 500)
|
|
126
|
-
this.$timeout(() => {
|
|
127
|
-
const element = angular.element(`div[id="${row['_uid']}"]`)
|
|
128
|
-
element.addClass('active')
|
|
129
|
-
this.$timeout(() => element.removeClass('active'), 300)
|
|
130
|
-
}, 100)
|
|
97
|
+
}, 500)
|
|
131
98
|
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
removeRow(row) {
|
|
102
|
+
this.$timeout(() => {
|
|
103
|
+
const index = this.findIndexRow(this.ngModel, row)
|
|
104
|
+
const indexData = this.findIndexRow(this.dataModel, row)
|
|
105
|
+
if (index !== -1) {
|
|
106
|
+
this.ngModel.splice(index, 1)
|
|
107
|
+
this.dataModel.splice(indexData, 1)
|
|
108
|
+
this.executeFetch()
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
searchNgModel() {
|
|
114
|
+
this.$timeout(() => {
|
|
115
|
+
const search = (this.label || '').split(',')
|
|
116
|
+
const keys = search.map((word) => word.trim())
|
|
117
|
+
const dataModel = JSON.parse(JSON.stringify(this.ngModel))
|
|
118
|
+
const options = {
|
|
119
|
+
shouldSort: true,
|
|
120
|
+
threshold: 0.3,
|
|
121
|
+
location: 0,
|
|
122
|
+
distance: 100,
|
|
123
|
+
maxPatternLength: 32,
|
|
124
|
+
minMatchCharLength: 1,
|
|
125
|
+
keys,
|
|
126
|
+
}
|
|
127
|
+
const fuse = new Fuse(dataModel, options)
|
|
128
|
+
const result = fuse.search(this.inputValueResult)
|
|
129
|
+
this.dataModel = result.length > 0 ? result : dataModel
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
findIndexRow(array: Array<any>, row) {
|
|
134
|
+
return array.findIndex((data) => angular.equals(data, row))
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async addEvent(row) {
|
|
138
|
+
const target: any = angular.element('.result-multi-list-wrapper')
|
|
139
|
+
await target.animate({ scrollTop: this.dataModel.length * 44 }, 500)
|
|
140
|
+
this.$timeout(() => {
|
|
141
|
+
const element = angular.element(`div[id="${row['_uid']}"]`)
|
|
142
|
+
element.addClass('active')
|
|
143
|
+
this.$timeout(() => element.removeClass('active'), 300)
|
|
144
|
+
}, 100)
|
|
145
|
+
}
|
|
132
146
|
}
|
|
133
147
|
|
|
134
148
|
MbgSelectMultiListController.$inject = [
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
149
|
+
'$scope',
|
|
150
|
+
'$element',
|
|
151
|
+
'$attrs',
|
|
152
|
+
'$timeout',
|
|
153
|
+
'$compile',
|
|
154
|
+
'$transclude',
|
|
141
155
|
]
|
|
142
156
|
|
|
143
157
|
const mbgSelectMultiList = {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
158
|
+
transclude: true,
|
|
159
|
+
bindings: {
|
|
160
|
+
ngModel: '=?',
|
|
161
|
+
fetch: '&?',
|
|
162
|
+
label: '@?',
|
|
163
|
+
count: '=?',
|
|
164
|
+
placeholderLeft: '@?',
|
|
165
|
+
placeholderRight: '@?',
|
|
166
|
+
titleLeft: '@?',
|
|
167
|
+
titleRight: '@?',
|
|
168
|
+
data: '=?',
|
|
169
|
+
isLoading: '=?',
|
|
170
|
+
},
|
|
171
|
+
template,
|
|
172
|
+
controller: MbgSelectMultiListController,
|
|
159
173
|
}
|
|
160
174
|
|
|
161
175
|
export { mbgSelectMultiList }
|