inviton-powerduck 0.0.151 → 0.0.153

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,231 +1,231 @@
1
- import type { DropdownOptionGroup } from '../dropdown';
2
- import { Component, Prop } from 'vue-facing-decorator';
3
- import TsxComponent from '../../app/vuetsx';
4
- import { isNullOrEmpty } from '../../common/utils/is-null-or-empty';
5
- import { latinize } from '../../common/utils/latinize-string';
6
- import BootstrapToggle from '../bootstrap-toggle';
7
- import DropdownList from '../dropdown';
8
- import HtmlLiteral from '../html-literal/html-literal';
9
- import TextBox, { TextBoxTextType } from '../input/textbox';
10
- import './css/import-mapper.css';
11
-
12
- export interface ImportMapperMapping {
13
- columnIndex: number;
14
- mappingValue: string;
15
- }
16
-
17
- interface ImportMapperArgs {
18
- cssClass?: string;
19
- subtitleHtml: string;
20
- mappingOptions: DropdownOptionGroup[];
21
- importData: Array<Array<string>>;
22
- firstRowIsHeaderLabel?: string;
23
- defaultMapping?: ImportMapperMapping[];
24
- }
25
-
26
- @Component
27
- export default class ImportMapper extends TsxComponent<ImportMapperArgs> implements ImportMapperArgs {
28
- @Prop() cssClass!: string;
29
- @Prop() subtitleHtml!: string;
30
- @Prop() mappingOptions!: DropdownOptionGroup[];
31
- @Prop() importData!: Array<Array<string>>;
32
- @Prop() defaultMapping!: ImportMapperMapping[];
33
- @Prop() firstRowIsHeaderLabel!: string;
34
- private selectionMap: any = {};
35
- private firstRowHeader: boolean = false;
36
- private wasMatched = [];
37
-
38
- public getData(): any[] {
39
- const retVal = [];
40
-
41
- this.importData.forEach((row, i) => {
42
- if (!this.firstRowHeader || i > 0) {
43
- const newItem = {};
44
- for (const key in this.selectionMap) {
45
- const keyInt = Number(key);
46
- let objVal = row[keyInt];
47
-
48
- if (objVal != null) {
49
- if (typeof objVal === 'string') {
50
- objVal = objVal.trim();
51
- }
52
- }
53
-
54
- newItem[this.selectionMap[key]] = objVal;
55
- }
56
-
57
- retVal.push(newItem);
58
- }
59
- });
60
-
61
- return retVal;
62
- }
63
-
64
- private getDisplayValue(obj: any): string {
65
- if (obj == null) {
66
- return null;
67
- } else if (obj._dte) {
68
- return obj.toDisplayString(true);
69
- }
70
-
71
- return obj;
72
- }
73
-
74
- private getLargestRow(): string[] {
75
- if (isNullOrEmpty(this.importData)) {
76
- return [];
77
- }
78
-
79
- let biggestLength = 0;
80
- this.importData.forEach((rowArr) => {
81
- if (rowArr != null && rowArr.length > biggestLength) {
82
- biggestLength = rowArr.length;
83
- }
84
- });
85
-
86
- const retVal = [];
87
- while (true) {
88
- if (retVal.length < biggestLength) {
89
- retVal.push('x');
90
- } else {
91
- break;
92
- }
93
- }
94
-
95
- return retVal;
96
- }
97
-
98
- private getDropdownSelectedItem(index: number) {
99
- const selection = this.selectionMap[index];
100
-
101
- if (selection == null) {
102
- const match = this.getHeaderItem(index);
103
-
104
- if (!isNullOrEmpty(match) && !this.wasMatched.includes(index)) {
105
- this.wasMatched.push(index);
106
- this.setDropdownSelectedItem(index, match.id);
107
- return match.id;
108
- } else {
109
- return null;
110
- }
111
- }
112
-
113
- if (selection.includes('ncf:')) {
114
- return 'custom';
115
- }
116
-
117
- return this.selectionMap[index];
118
- }
119
-
120
- private setDropdownSelectedItem(index: number, value: any) {
121
- if (value == null || value.id == null) {
122
- if (typeof value === 'string') {
123
- // this.$set(this.selectionMap, index.toString(), value);
124
- this.selectionMap[index.toString()] = value;
125
- } else {
126
- // this.$set(this.selectionMap, index.toString(), null);
127
- this.selectionMap[index.toString()] = null;
128
- }
129
- } else {
130
- // this.$set(this.selectionMap, index.toString(), value.id);
131
- this.selectionMap[index.toString()] = value.id;
132
- }
133
- }
134
-
135
- private getPreviewRows(): Array<string[]> {
136
- if (isNullOrEmpty(this.importData)) {
137
- return [];
138
- }
139
-
140
- let start = 0;
141
- let end = 10;
142
- if (this.firstRowHeader) {
143
- start += 1;
144
- end += 1;
145
- }
146
-
147
- return this.importData.filter((u, i) => i >= start && i < end);
148
- }
149
-
150
- private getHeaderItem(index: number) {
151
- const opts = [];
152
-
153
- this.mappingOptions.forEach((mapOpts) => {
154
- mapOpts.children.forEach((s) => {
155
- opts.push(s);
156
- });
157
- });
158
-
159
- if (this.importData[0][index] != null) {
160
- const indexItem = this.importData[0][index].toString();
161
- const headers = opts.filter(p => latinize(p.text).toLowerCase() == latinize(indexItem).toLowerCase() || latinize(p.id).toLowerCase() == latinize(indexItem).toLowerCase());
162
- if (headers != null && headers.length == 1) {
163
- return headers[0];
164
- }
165
- } else {
166
- return null;
167
- }
168
- }
169
-
170
- private prefillNewCustomFieldName(index: number) {
171
- let retVal = '';
172
- if (this.selectionMap[index].includes('ncf:')) {
173
- retVal = this.selectionMap[index].substring(4);
174
- } else {
175
- retVal = this.importData[0][index];
176
- }
177
-
178
- this.setDropdownSelectedItem(index, `ncf:${retVal}`);
179
- return retVal;
180
- }
181
-
182
- private render(h) {
183
- const largestRow = this.getLargestRow();
184
-
185
- return (
186
- <div class="import-mapper-root">
187
- <p class="import-mapper-subtitle">
188
- <HtmlLiteral innerHTML={this.subtitleHtml} />
189
- </p>
190
-
191
- {this.importData
192
- && (
193
- <div class="import-mapper-table-wrap">
194
- <table class="import-mapper-table">
195
- <thead>
196
- <tr>
197
- {largestRow.map((col, i) => {
198
- return (
199
- <td>
200
- <DropdownList wrap={false} label={null} placeholder="Select value" options={this.mappingOptions} selected={this.getDropdownSelectedItem(i)} changed={(v) => { this.setDropdownSelectedItem(i, v); }} />
201
-
202
- {this.selectionMap[i] != null && (this.selectionMap[i] == 'custom' || this.selectionMap[i].includes('ncf:'))
203
- && <TextBox wrap={false} label="" cssClass="hidden" value={this.prefillNewCustomFieldName(i)} changed={(v) => { this.setDropdownSelectedItem(i, `ncf:${v}`); }} textType={TextBoxTextType.Text} />}
204
- </td>
205
- );
206
- })}
207
- </tr>
208
- </thead>
209
- <tbody>
210
- {this.getPreviewRows().map(row => (
211
- <tr>
212
- {largestRow.map((col, i) => (
213
- <td>
214
- {this.getDisplayValue(row[i])}
215
- </td>
216
- ))}
217
- </tr>
218
- ))}
219
- </tbody>
220
- </table>
221
- </div>
222
- )}
223
-
224
- <div class="import-mapper-settings">
225
- {this.$slots.default}
226
- <BootstrapToggle label={this.firstRowIsHeaderLabel ? this.firstRowIsHeaderLabel : 'First row is header'} value={this.firstRowHeader} changed={(e) => { this.firstRowHeader = e; }} />
227
- </div>
228
- </div>
229
- );
230
- }
231
- }
1
+ import type { DropdownOptionGroup } from '../dropdown';
2
+ import { Component, Prop } from 'vue-facing-decorator';
3
+ import TsxComponent from '../../app/vuetsx';
4
+ import { isNullOrEmpty } from '../../common/utils/is-null-or-empty';
5
+ import { latinize } from '../../common/utils/latinize-string';
6
+ import BootstrapToggle from '../bootstrap-toggle';
7
+ import DropdownList from '../dropdown';
8
+ import HtmlLiteral from '../html-literal/html-literal';
9
+ import TextBox, { TextBoxTextType } from '../input/textbox';
10
+ import './css/import-mapper.css';
11
+
12
+ export interface ImportMapperMapping {
13
+ columnIndex: number;
14
+ mappingValue: string;
15
+ }
16
+
17
+ interface ImportMapperArgs {
18
+ cssClass?: string;
19
+ subtitleHtml: string;
20
+ mappingOptions: DropdownOptionGroup[];
21
+ importData: Array<Array<string>>;
22
+ firstRowIsHeaderLabel?: string;
23
+ defaultMapping?: ImportMapperMapping[];
24
+ }
25
+
26
+ @Component
27
+ export default class ImportMapper extends TsxComponent<ImportMapperArgs> implements ImportMapperArgs {
28
+ @Prop() cssClass!: string;
29
+ @Prop() subtitleHtml!: string;
30
+ @Prop() mappingOptions!: DropdownOptionGroup[];
31
+ @Prop() importData!: Array<Array<string>>;
32
+ @Prop() defaultMapping!: ImportMapperMapping[];
33
+ @Prop() firstRowIsHeaderLabel!: string;
34
+ private selectionMap: any = {};
35
+ private firstRowHeader: boolean = false;
36
+ private wasMatched = [];
37
+
38
+ public getData(): any[] {
39
+ const retVal = [];
40
+
41
+ this.importData.forEach((row, i) => {
42
+ if (!this.firstRowHeader || i > 0) {
43
+ const newItem = {};
44
+ for (const key in this.selectionMap) {
45
+ const keyInt = Number(key);
46
+ let objVal = row[keyInt];
47
+
48
+ if (objVal != null) {
49
+ if (typeof objVal === 'string') {
50
+ objVal = objVal.trim();
51
+ }
52
+ }
53
+
54
+ newItem[this.selectionMap[key]] = objVal;
55
+ }
56
+
57
+ retVal.push(newItem);
58
+ }
59
+ });
60
+
61
+ return retVal;
62
+ }
63
+
64
+ private getDisplayValue(obj: any): string {
65
+ if (obj == null) {
66
+ return null;
67
+ } else if (obj._dte) {
68
+ return obj.toDisplayString(true);
69
+ }
70
+
71
+ return obj;
72
+ }
73
+
74
+ private getLargestRow(): string[] {
75
+ if (isNullOrEmpty(this.importData)) {
76
+ return [];
77
+ }
78
+
79
+ let biggestLength = 0;
80
+ this.importData.forEach((rowArr) => {
81
+ if (rowArr != null && rowArr.length > biggestLength) {
82
+ biggestLength = rowArr.length;
83
+ }
84
+ });
85
+
86
+ const retVal = [];
87
+ while (true) {
88
+ if (retVal.length < biggestLength) {
89
+ retVal.push('x');
90
+ } else {
91
+ break;
92
+ }
93
+ }
94
+
95
+ return retVal;
96
+ }
97
+
98
+ private getDropdownSelectedItem(index: number) {
99
+ const selection = this.selectionMap[index];
100
+
101
+ if (selection == null) {
102
+ const match = this.getHeaderItem(index);
103
+
104
+ if (!isNullOrEmpty(match) && !this.wasMatched.includes(index)) {
105
+ this.wasMatched.push(index);
106
+ this.setDropdownSelectedItem(index, match.id);
107
+ return match.id;
108
+ } else {
109
+ return null;
110
+ }
111
+ }
112
+
113
+ if (selection.includes('ncf:')) {
114
+ return 'custom';
115
+ }
116
+
117
+ return this.selectionMap[index];
118
+ }
119
+
120
+ private setDropdownSelectedItem(index: number, value: any) {
121
+ if (value == null || value.id == null) {
122
+ if (typeof value === 'string') {
123
+ // this.$set(this.selectionMap, index.toString(), value);
124
+ this.selectionMap[index.toString()] = value;
125
+ } else {
126
+ // this.$set(this.selectionMap, index.toString(), null);
127
+ this.selectionMap[index.toString()] = null;
128
+ }
129
+ } else {
130
+ // this.$set(this.selectionMap, index.toString(), value.id);
131
+ this.selectionMap[index.toString()] = value.id;
132
+ }
133
+ }
134
+
135
+ private getPreviewRows(): Array<string[]> {
136
+ if (isNullOrEmpty(this.importData)) {
137
+ return [];
138
+ }
139
+
140
+ let start = 0;
141
+ let end = 10;
142
+ if (this.firstRowHeader) {
143
+ start += 1;
144
+ end += 1;
145
+ }
146
+
147
+ return this.importData.filter((u, i) => i >= start && i < end);
148
+ }
149
+
150
+ private getHeaderItem(index: number) {
151
+ const opts = [];
152
+
153
+ this.mappingOptions.forEach((mapOpts) => {
154
+ mapOpts.children.forEach((s) => {
155
+ opts.push(s);
156
+ });
157
+ });
158
+
159
+ if (this.importData[0][index] != null) {
160
+ const indexItem = this.importData[0][index].toString();
161
+ const headers = opts.filter(p => latinize(p.text).toLowerCase() == latinize(indexItem).toLowerCase() || latinize(p.id).toLowerCase() == latinize(indexItem).toLowerCase());
162
+ if (headers != null && headers.length == 1) {
163
+ return headers[0];
164
+ }
165
+ } else {
166
+ return null;
167
+ }
168
+ }
169
+
170
+ private prefillNewCustomFieldName(index: number) {
171
+ let retVal = '';
172
+ if (this.selectionMap[index].includes('ncf:')) {
173
+ retVal = this.selectionMap[index].substring(4);
174
+ } else {
175
+ retVal = this.importData[0][index];
176
+ }
177
+
178
+ this.setDropdownSelectedItem(index, `ncf:${retVal}`);
179
+ return retVal;
180
+ }
181
+
182
+ private render(h) {
183
+ const largestRow = this.getLargestRow();
184
+
185
+ return (
186
+ <div class="import-mapper-root">
187
+ <p class="import-mapper-subtitle">
188
+ <HtmlLiteral innerHTML={this.subtitleHtml} />
189
+ </p>
190
+
191
+ {this.importData
192
+ && (
193
+ <div class="import-mapper-table-wrap">
194
+ <table class="import-mapper-table">
195
+ <thead>
196
+ <tr>
197
+ {largestRow.map((col, i) => {
198
+ return (
199
+ <td>
200
+ <DropdownList wrap={false} label={null} placeholder="Select value" options={this.mappingOptions} selected={this.getDropdownSelectedItem(i)} changed={(v) => { this.setDropdownSelectedItem(i, v); }} />
201
+
202
+ {this.selectionMap[i] != null && (this.selectionMap[i] == 'custom' || this.selectionMap[i].includes('ncf:'))
203
+ && <TextBox wrap={false} label="" cssClass="hidden" value={this.prefillNewCustomFieldName(i)} changed={(v) => { this.setDropdownSelectedItem(i, `ncf:${v}`); }} textType={TextBoxTextType.Text} />}
204
+ </td>
205
+ );
206
+ })}
207
+ </tr>
208
+ </thead>
209
+ <tbody>
210
+ {this.getPreviewRows().map(row => (
211
+ <tr>
212
+ {largestRow.map((col, i) => (
213
+ <td>
214
+ {this.getDisplayValue(row[i])}
215
+ </td>
216
+ ))}
217
+ </tr>
218
+ ))}
219
+ </tbody>
220
+ </table>
221
+ </div>
222
+ )}
223
+
224
+ <div class="import-mapper-settings">
225
+ {this.$slots.default}
226
+ <BootstrapToggle label={this.firstRowIsHeaderLabel ? this.firstRowIsHeaderLabel : 'First row is header'} value={this.firstRowHeader} changed={(e) => { this.firstRowHeader = e; }} />
227
+ </div>
228
+ </div>
229
+ );
230
+ }
231
+ }