@modeltables/fontawesome-vuetify 1.0.1

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.
@@ -0,0 +1,391 @@
1
+ <script lang="ts">
2
+ import { ref } from 'vue'
3
+ import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
4
+ import { faCalendar } from '@fortawesome/free-regular-svg-icons';
5
+ import { faRefresh, faSearch, faHashtag } from '@fortawesome/free-solid-svg-icons';
6
+ import { HeaderModel, PaginatonModel } from '../models/table-models';
7
+ import { change, Id, load, rowClick, search } from '../helpers/resources';
8
+ import Date from '../headerFilters/Date.vue';
9
+ import Text from '../headerFilters/Text.vue';
10
+ import Number from '../headerFilters/Number.vue';
11
+ import SortView from '../sort/SortView.vue';
12
+ import PaginationView from '../pagination/PaginationView.vue';
13
+
14
+ export default {
15
+ props: {
16
+ dataheader: {
17
+ type: Array<HeaderModel>,
18
+ },
19
+ key: {
20
+ type: String,
21
+ required: true,
22
+ default: () => 'Id'
23
+ },
24
+ name: {
25
+ type: String
26
+ },
27
+ dataItems: {
28
+ type: Array as () => any[],
29
+ reactive: true,
30
+ required: true
31
+ },
32
+ currentItem: {
33
+ type: Object,
34
+ reactive: true,
35
+ required: false
36
+
37
+ },
38
+ currentId: {
39
+ type: Number,
40
+ reactive: true,
41
+ required: false
42
+ },
43
+ loading: {
44
+ type: Boolean,
45
+ required: false,
46
+ default: false
47
+ },
48
+ crud: {
49
+ type: Boolean,
50
+ required: false,
51
+ default: false
52
+ },
53
+ showFilters: {
54
+ type: Boolean,
55
+ required: false,
56
+ default: () => false
57
+ },
58
+ dialogWidth: {
59
+ type: Number,
60
+ default: () => 800
61
+ },
62
+ itemsPerPage: {
63
+ type: Number,
64
+ default: () => 10
65
+ },
66
+ pagination: {
67
+ type: PaginatonModel,
68
+ required: false,
69
+ default: () => new PaginatonModel()
70
+ },
71
+ showTime: {
72
+ type: Boolean,
73
+ required: false,
74
+ default: () => false
75
+ }
76
+ },
77
+ components: {
78
+ FontAwesomeIcon: FontAwesomeIcon,
79
+ Date: Date,
80
+ Text: Text,
81
+ Number: Number,
82
+ SortView: SortView,
83
+ PaginationView: PaginationView
84
+ },
85
+ mounted() {
86
+ this.firstChange = true;
87
+ this.load({});
88
+ },
89
+ watch: {
90
+ dataItems(newValue, oldValue) {
91
+ this.dataItems = newValue;
92
+ if(this.firstChange){
93
+ this.initFilters();
94
+ this.firstChange = false;
95
+ }
96
+ },
97
+ pagination(newValue: PaginatonModel, oldValue) {
98
+ this.page = newValue.CurrentPage;
99
+ this.perPage = newValue.PerPage;
100
+ this.pageCount = newValue.PageCount;
101
+ this.totalCount = newValue.TotalCount;
102
+ }
103
+ },
104
+ emits: [change, load, rowClick, search],
105
+ setup(props, params) {
106
+ const modelValue = ref([]);
107
+ return { modelValue };
108
+ },
109
+ data() {
110
+ return {
111
+ dataheader: this.dataheader,
112
+ calendar: faCalendar,
113
+ dataItems: this.dataItems,
114
+ dialog: false,
115
+ new: true,
116
+ key: this.key ?? Id,
117
+ name: this.name,
118
+ currentId: this.currentId,
119
+ currentItem: this.currentItem,
120
+ loading: this.loading,
121
+ faSearch: faSearch,
122
+ reload: faRefresh,
123
+ lastItem: {},
124
+ completes: this.completes,
125
+ filters: { CurrentPage: 1, PerPage: 10, SortColumn: '', SortDirection: 1 } as any,
126
+ showFilters: this.showFilters,
127
+ modelValue: ref([]),
128
+ firstChange: true,
129
+ perPage: this.pagination!.PerPage,
130
+ page: this.pagination!.CurrentPage,
131
+ pageCount: this.pagination!.PageCount,
132
+ totalCount:this.pagination!.TotalCount,
133
+ hashTag: faHashtag,
134
+ showTime: this.showTime,
135
+ };
136
+ },
137
+ methods: {
138
+ rowClick(event: {}){
139
+ this.$emit(rowClick, event);
140
+ },
141
+ load(event: {}){
142
+ if(this.onLoad) this.onLoad(event);
143
+ },
144
+ refresh(){
145
+ this.clear();
146
+ this.search();
147
+ },
148
+ clear(){
149
+ for(let prop of Object.keys(this.filters)){
150
+ this.filters[prop] = null;
151
+ }
152
+ },
153
+ initFilters() {
154
+ let item = this.dataItems[0];
155
+ for(let key of Object.keys(item)){
156
+ this.filters[key] = null;
157
+ }
158
+ this.filters.CurrentPage = 0;
159
+ this.filters.PerPage = 0;
160
+ },
161
+ search(){
162
+ if(this.filters != undefined){
163
+ this.$emit(search, this.filters);
164
+ }
165
+ },
166
+ async updateItem(item: any, event: any){
167
+ event.preventDefault();
168
+ if(!this.crud){
169
+ this.rowClick(item);
170
+ }else{
171
+ this.currentId = item[this.key!];
172
+ this.$emit(change, item);
173
+ }
174
+ },
175
+ filterValue(event: any, dataItem: any){
176
+ let item = dataItem;
177
+ let value = event.target.value;
178
+ if(item != null){
179
+ dataItem = value == '' ? null : value;
180
+ }else{
181
+ dataItem = value;
182
+ }
183
+ },
184
+ filterDate(event: any, dataItem: any){
185
+ let item = dataItem;
186
+ if(item != null){
187
+ dataItem = event == '' ? null : new window.Date(event);
188
+ }else{
189
+ dataItem = new window.Date(event);
190
+ }
191
+ },
192
+ isNumber(n: any) {
193
+ return !isNaN(parseFloat(n)) && !isNaN(n - 0)
194
+ },
195
+ isDateTime(d: any){
196
+ if(/^[\d]{4}-[\d]{2}-[\d]{2}T[\d]{2}:[\d]{2}:[\d]{2}.[\d]+$/.test(d)){
197
+ let datetime = new window.Date(d);
198
+ return datetime instanceof window.Date;
199
+ }
200
+ return false;
201
+ },
202
+ isString(s: any){
203
+ return typeof s === 'string' || s instanceof String;
204
+ },
205
+ toDate(d: any){
206
+ if(this.showTime){
207
+ return (new window.Date(d).toLocaleDateString()) + " " + (new window.Date(d).toLocaleTimeString());
208
+ }
209
+
210
+ return (new window.Date(d).toLocaleDateString());
211
+ },
212
+ options(event: any){
213
+ this.page = event!.page;
214
+ this.filters.CurrentPage = this.page;
215
+ this.search();
216
+ },
217
+ nextPage(event: any){
218
+ if(this.page < this.pageCount){
219
+ this.page = this.page + 1;
220
+ this.filters.CurrentPage = this.page;
221
+ this.search();
222
+ }
223
+ },
224
+ previousPage(event: any){
225
+ if(this.page > 1){
226
+ this.page = this.page - 1;
227
+ this.filters.CurrentPage = this.page;
228
+ this.search();
229
+ }
230
+ },
231
+ firstPage(event: any){
232
+ this.page = 1;
233
+ this.filters.CurrentPage = this.page;
234
+ this.search();
235
+ },
236
+ lastPage(event: any){
237
+ this.page = this.pageCount;
238
+ this.filters.CurrentPage = this.page;
239
+ this.search();
240
+ },
241
+ pageChange(event: any){
242
+ this.page = event;
243
+ this.filters.CurrentPage = this.page;
244
+ this.search();
245
+ },
246
+ pageSize(event: any){
247
+ console.log(event);
248
+ this.perPage = event;
249
+ this.filters.PerPage = this.perPage;
250
+ this.search();
251
+ },
252
+ sort(event: any, prop: any, index: number){
253
+ prop.sort = prop.sort == true ? false : true;
254
+ this.filters.SortColumn = Object.keys(this.dataItems[0])[index];
255
+ this.filters.SortDirection = window.Number(prop.sort);
256
+ console.log(this.filters);
257
+ this.search();
258
+ }
259
+ }
260
+ }
261
+ </script>
262
+
263
+ <template>
264
+ <div>
265
+ <v-container>
266
+ <v-row style="border-bottom: 1px solid #393E46; padding: 10px">
267
+ <v-btn @click="search()" style="margin-right: 10px" color="#1697f6" v-if="showFilters" v-tooltip="'Search'">
268
+ <FontAwesomeIcon :icon="faSearch"></FontAwesomeIcon>
269
+ </v-btn>
270
+ <v-btn @click="refresh()" style="margin-right: 10px" color="#1697f6" v-if="showFilters" v-tooltip="'Refresh'">
271
+ <FontAwesomeIcon :icon="reload"></FontAwesomeIcon>
272
+ </v-btn>
273
+ </v-row>
274
+ <v-row>
275
+ <v-data-table
276
+ :color="'white'"
277
+ :striped="'odd'"
278
+ :v-bind:loading-text="'Loading... Please wait'"
279
+ :loading="loading"
280
+ :v-bind:model-value="modelValue"
281
+ :items="dataItems"
282
+ @update:options="options($event)"
283
+ :items-per-page="perPage"
284
+ :page="page"
285
+ hide-default-header
286
+ hide-default-footer
287
+ multi-sort
288
+ return-object>
289
+ <template v-slot:item="{ item, index }" >
290
+ <tr v-if="index == 0 && showFilters" class="filter-items" >
291
+ <td v-for="(prop, index) in dataheader">
292
+ <SortView
293
+ :prop="prop"
294
+ :index="index"
295
+ @sort="sort($event, prop, index)">
296
+ </SortView>
297
+ </td>
298
+ </tr>
299
+ <tr v-if="index == 0 && showFilters" class="filter-items" >
300
+ <td v-for="(prop, index) in Object.keys(item)">
301
+ <span v-if="prop == key!">
302
+ <FontAwesomeIcon :icon="hashTag"></FontAwesomeIcon>
303
+ </span>
304
+ <span v-else>
305
+ <div v-if="isNumber(item[prop])">
306
+ <Number
307
+ :filter="filters[prop]"
308
+ :prop="prop":data="filters"
309
+ @filterValue="filterValue($event, filters[prop])">
310
+ </Number>
311
+ </div>
312
+ <div v-else-if="isDateTime(item[prop])">
313
+ <Date
314
+ :data="filters"
315
+ :filter="filters[prop]"
316
+ :prop="prop"
317
+ @filterValue="filterDate($event, filters[prop])">
318
+ </Date>
319
+ </div>
320
+ <div v-else-if="isString(item[prop])">
321
+ <Text
322
+ :data="filters"
323
+ :filter="filters[prop]"
324
+ :prop="prop"
325
+ @filterValue="filterValue($event, filters[prop])">
326
+ </Text>
327
+ </div>
328
+ </span>
329
+ </td>
330
+ </tr>
331
+ <tr @dblclick="updateItem(item, $event)">
332
+ <td v-for="(prop) in Object.keys(item)">
333
+ <span v-if="prop == key!">
334
+ {{ index + 1 }}
335
+ </span>
336
+ <span v-else-if="isDateTime(item[prop])">
337
+ {{ toDate(item[prop]) }}
338
+ </span>
339
+ <span v-else>
340
+ {{ item[prop] }}
341
+ </span>
342
+ </td>
343
+ </tr>
344
+ </template>
345
+ </v-data-table>
346
+ </v-row>
347
+ <PaginationView
348
+ :page="page"
349
+ :perPage="perPage"
350
+ :pageCount="pageCount"
351
+ :totalCount="totalCount"
352
+ @pageChange="pageChange($event)"
353
+ @pageSize="pageSize($event)"
354
+ @firstPage="firstPage($event)"
355
+ @previousPage="previousPage($event)"
356
+ @nextPage="nextPage($event)"
357
+ @lastPage="lastPage($event)"/>
358
+ </v-container>
359
+ </div>
360
+ </template>
361
+
362
+ <style>
363
+ @media (min-width: 1024px) {
364
+ .about {
365
+ min-height: 100vh;
366
+ display: flex;
367
+ align-items: center;
368
+ }
369
+ }
370
+
371
+ .filter-items{
372
+ height: 56px;
373
+ }
374
+
375
+ .filter-items .v-input__control{
376
+ height: 56px;
377
+ }
378
+
379
+ .filter-items span{
380
+ height: 56px;
381
+ }
382
+
383
+ .filter-items span div{
384
+ height: 56px;
385
+ }
386
+
387
+ .filter-items span div div{
388
+ height: 56px;
389
+ }
390
+
391
+ </style>