vi-grid-builder 0.0.9 → 1.0.2

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,15 +1,24 @@
1
1
  import ViGridBuilder from "./src/ViGridBuilder.vue"
2
+ import DateSettings from "./src/settings/DateSettings.js"
2
3
  import ViPaginationPlugin from 'vi-pagination'
3
4
  import fieldMixin from "./src/mixins/field-mixin.js"
4
5
  import {useGridActions} from "./src/composables/useGridActions.js"
5
6
  export default {
6
- install(app, options ={pagination:{}, fieldComponents:{}, defaultSlots:{}}) {
7
+ install(app, options ={pagination:{}, fieldComponents:{}, defaultSlots:{}, dateFormats: {}}) {
7
8
 
8
9
  // if (options?.fieldComponents) {
9
10
  // Object.keys(options.fieldComponents).forEach(key => {
10
11
  // ViGridBuilder.components[key] = options.fieldComponents[key]
11
12
  // });
12
13
  // }
14
+ app.provide('ViDateSettings', {
15
+ ...DateSettings,
16
+ format:{
17
+ ...DateSettings.format,
18
+ ...options?.dateFormats
19
+ }
20
+ });
21
+
13
22
  app.use(ViPaginationPlugin, options?.pagination);
14
23
  app.component('ViGridBuilder', {
15
24
  extends:ViGridBuilder,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vi-grid-builder",
3
3
  "main": "ViGridBuilderPlugin",
4
- "version": "0.0.9",
4
+ "version": "1.0.2",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -9,6 +9,7 @@
9
9
  "preview": "vite preview"
10
10
  },
11
11
  "dependencies": {
12
+ "date-fns": "^2.30.0",
12
13
  "vi-pagination": "^0.0.5",
13
14
  "vue": "^3.3.4"
14
15
  },
@@ -17,6 +17,9 @@
17
17
  }
18
18
 
19
19
  tr {
20
+ &.clickable{
21
+ cursor: pointer;
22
+ }
20
23
 
21
24
  th.title {
22
25
  padding-bottom: 40px;
@@ -33,7 +33,7 @@
33
33
  </slot>
34
34
  </td>
35
35
  </tr>
36
- <tr v-for="row in currentVisibleRows" :key="row[rowKey]">
36
+ <tr v-for="row in currentVisibleRows" :key="row[rowKey]" @click="$ev => onRowClicked(row)" :class="{'clickable': clickableRow}">
37
37
 
38
38
  <td v-for="column in columns" :key="column.name">
39
39
  <vi-grid-field
@@ -132,6 +132,10 @@
132
132
  noCellDataLabel: {
133
133
  type: String,
134
134
  default:'/'
135
+ },
136
+ clickableRow:{
137
+ type: Boolean,
138
+ default: false
135
139
  }
136
140
  },
137
141
  data: () => ({search: null, isFetchingData: false}),
@@ -186,6 +190,11 @@
186
190
  if (this.isServerSide) {
187
191
  this.fetchData({pagination: newPagination})
188
192
  }
193
+ },
194
+ onRowClicked(row){
195
+ if (this.clickableRow) {
196
+ this.$emit('rowClicked',row)
197
+ }
189
198
  }
190
199
  },
191
200
  created() {
@@ -3,7 +3,7 @@
3
3
  <component
4
4
  v-if="fieldComponent"
5
5
  v-bind:is="fieldComponent"
6
- :field="field"
6
+ v-bind="field"
7
7
  :value="filedValueFormatted"
8
8
  :original-value="fieldValue"
9
9
  :row="rowValue"
@@ -2,7 +2,7 @@ import {computed } from 'vue';
2
2
 
3
3
  export function useGridActions(props) {
4
4
 
5
- const visibleActions = computed(() => props.field.actions.filter((action ) => {
5
+ const visibleActions = computed(() => props.actions.filter((action ) => {
6
6
  if (action.isVisible === undefined) {
7
7
  return true
8
8
 
@@ -2,7 +2,7 @@
2
2
  <div class="vi-grid-actions">
3
3
 
4
4
  <vi-grid-kebab-menu
5
- v-if="field.kebab"
5
+ v-if="kebab"
6
6
  :actions="visibleActions"
7
7
  @actionClicked="$action => $emit(`action-clicked`, {action:$action, row})"
8
8
  />
@@ -21,18 +21,23 @@
21
21
  import ViGridBuilderActions from "./partials/ViGridBuilderActions.vue";
22
22
 
23
23
  import {useGridActions} from "../composables/useGridActions.js"
24
- import fieldMixin from "../mixins/field-mixin.js"
25
24
 
26
25
  export default {
27
26
  name: "ViGridActions",
28
- mixins: [fieldMixin],
29
27
  components: {ViGridBuilderActions, ViGridKebabMenu},
30
28
  props: {
31
- field: {
32
- type: Object,
33
- required: true
29
+ kebab:{
30
+ type: Boolean,
31
+ default: false,
34
32
  },
35
- row: {}
33
+ row: {},
34
+ actions:{
35
+ type: Array,
36
+ default: function () {
37
+
38
+ return []
39
+ }
40
+ }
36
41
  },
37
42
 
38
43
  setup() {
@@ -10,10 +10,6 @@
10
10
  export default {
11
11
  name: "ViGridBadge",
12
12
  props: {
13
- field: {
14
- type: Object,
15
- required: true
16
- },
17
13
  value: {},
18
14
  },
19
15
  }
@@ -5,33 +5,31 @@
5
5
  </template>
6
6
 
7
7
  <script>
8
+
9
+ import { format, parseISO } from 'date-fns';
10
+
8
11
  export default {
9
12
  name: "ViGridDate",
13
+ inject: ['ViDateSettings'],
10
14
  props: {
11
- field: {
12
- type: Object,
13
- required: true
14
- },
15
15
  value: {},
16
+ mode:{
17
+ type: String,
18
+ validator: function (value) {
19
+
20
+ return ['date','dateTime','time'].includes(value)
21
+ },
22
+ default:'dateTime'
23
+ },
24
+ format:{
25
+ type: String,
26
+ }
16
27
  },
28
+
17
29
  computed: {
18
30
  dateFormatted() {
19
- return this.value;
20
- ///todo format date
21
- // if (!this.value) {
22
- // return this.value;
23
- // }
24
- // switch (this.field.format) {
25
- // case 'date':
26
- // return this.$options.filters.viFormatDate(this.value);
27
- //
28
- // case 'time':
29
- // return this.$options.filters.viFormatTime(this.value);
30
- //
31
- // default:
32
- // return this.$options.filters.viFormatDateTime(this.value);
33
- //
34
- // }
31
+ const formatString = this.format ?? this.ViDateSettings.format[this.mode];
32
+ return format(parseISO(this.value), formatString);
35
33
  }
36
34
  }
37
35
  }
@@ -8,11 +8,6 @@
8
8
  export default {
9
9
  name: "ViGridImage",
10
10
  props: {
11
- field: {
12
- type: Object,
13
- required: true
14
- },
15
-
16
11
  value: {},
17
12
  },
18
13
  }
@@ -1,6 +1,6 @@
1
1
  <template>
2
2
  <div class="vi-grid-link">
3
- <a :href="row[field.link]" target="_blank" v-if="row[field.link]">{{value}}</a>
3
+ <a :href="row[link]" target="_blank" v-if="row[link]">{{value}}</a>
4
4
  <div v-else>{{value}}</div>
5
5
  </div>
6
6
  </template>
@@ -9,8 +9,8 @@
9
9
  export default {
10
10
  name: "ViGridLink",
11
11
  props: {
12
- field: {
13
- type: Object,
12
+ link: {
13
+ type: String,
14
14
  required: true
15
15
  },
16
16
  row: {
@@ -8,10 +8,6 @@
8
8
  export default {
9
9
  name: "ViGridText",
10
10
  props: {
11
- field: {
12
- type: Object,
13
- required: true
14
- },
15
11
  value: {},
16
12
  },
17
13
  }
@@ -0,0 +1,7 @@
1
+ export default {
2
+ format:{
3
+ date:"yyyy-MM-dd",
4
+ dateTime:"yyyy-MM-dd HH:mm:ss",
5
+ time:"HH:mm:ss",
6
+ }
7
+ }