@tripup-company/element-ui-extended 0.0.7 → 0.0.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tripup-company/element-ui-extended",
3
- "version": "0.0.7",
3
+ "version": "0.0.11",
4
4
  "main": "./dist/element-ui-extended.umd.js",
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
package/src/App.vue CHANGED
@@ -1,6 +1,12 @@
1
1
  <template>
2
2
  <div id="app">
3
- <composite-table :fields="fields" :filters="filters" :filters-top="filtersTop" :repository="repository"></composite-table>
3
+ <composite-table
4
+ :storageKey="'Project_name'"
5
+ :fields="fields"
6
+ :filters="filters"
7
+ :top-filter="topFilter"
8
+ :repository="repository"
9
+ ></composite-table>
4
10
  <img alt="Vue logo" src="./assets/logo.png" />
5
11
  </div>
6
12
  </template>
@@ -9,35 +15,39 @@
9
15
  import { Component, Vue } from "vue-property-decorator";
10
16
  import CompositeTable from "@/components/CompositeTable/index.vue";
11
17
  import filters from "./filters";
12
- import filtersTop from "./filters-top";
18
+ import topFilter from "./topFilter";
13
19
  import repository from "./repositories/contacts-repository";
14
20
  @Component({
15
21
  components: { CompositeTable },
16
22
  data: function () {
17
- let repo = new repository('', '/test', null);
23
+ let repo = new repository("", "/test", null);
18
24
  return {
19
25
  filters: filters,
20
- filtersTop: filtersTop,
26
+ topFilter: topFilter,
21
27
  repository: repo,
22
28
  fields: [
23
- {
24
- prop: 'full_name', label: 'Full Name',
25
- formatter: row => {
26
- return row.first_name + ' ' + row.last_name;
29
+ {
30
+ prop: "full_name",
31
+ label: "Full Name",
32
+ formatter: (row) => {
33
+ return row.first_name + " " + row.last_name;
34
+ },
27
35
  },
28
- },
29
- {
30
- prop: 'email', label: 'Email',
31
- },
32
- {
33
- prop: 'phone', label: 'Phone',
34
- },
35
- {
36
- prop: 'created_at', label: 'Created at',
37
- },
38
- ],
39
- }
40
- }
36
+ {
37
+ prop: "email",
38
+ label: "Email",
39
+ },
40
+ {
41
+ prop: "phone",
42
+ label: "Phone",
43
+ },
44
+ {
45
+ prop: "created_at",
46
+ label: "Created at",
47
+ },
48
+ ],
49
+ };
50
+ },
41
51
  })
42
52
  export default class App extends Vue {}
43
53
  </script>
@@ -1,18 +1,17 @@
1
1
  <template>
2
2
  <div v-loading="loading" class="composite-table">
3
3
  <slot>
4
- <slot name="top-filter" v-bind="{ filtersTop, search }">
5
- <generic-top-filter
6
- v-if="filtersTop.length"
7
- :filters="filtersTop"
8
- :search="search"
9
- @apply:filter="handleApplyFilter"
10
- @reset:filter="handleResetFilter"
11
- />
12
- </slot>
13
-
14
4
  <el-row :gutter="20">
15
5
  <el-col :span="18">
6
+ <slot name="quick-search-filter" v-bind="{ topFilter, search }">
7
+ <quick-search-filter
8
+ v-if="topFilter"
9
+ :filter="topFilter"
10
+ :search="topSearch"
11
+ @apply:filter="handleApplyTopFilter"
12
+ @reset:filter="handleResetTopFilter"
13
+ />
14
+ </slot>
16
15
  <slot name="table" v-bind="{ fields, data }">
17
16
  <generic-table
18
17
  :fields="fields"
@@ -58,10 +57,11 @@ import GenericTable from "@/components/GenericTable";
58
57
  import ListQueryService from "@/services/list-query-service";
59
58
  import { LocalStorageService } from "@/services/local-storage-service";
60
59
  import MetaModel from "@/models/meta-model";
61
- import GenericTopFilter from "@/components/GenericFilters/GenericTopFilter";
60
+ import QuickSearchFilter from "@/components/GenericFilters/QuickSearchFilter";
61
+ import FilterConverter from "../GenericFilters/filter-convertor";
62
62
  export default {
63
63
  components: {
64
- GenericTopFilter,
64
+ QuickSearchFilter,
65
65
  GenericFilter,
66
66
  GenericTable,
67
67
  GenericPaginator,
@@ -82,64 +82,89 @@ export default {
82
82
  default: () => [],
83
83
  type: Array,
84
84
  },
85
- filtersTop: {
86
- default: () => [],
87
- type: Array,
85
+ topFilter: {
86
+ default() {
87
+ return {};
88
+ },
89
+ type: Object,
88
90
  },
89
91
  filters: {
90
92
  default: () => [],
91
93
  type: Array,
92
94
  },
95
+ includes: {
96
+ default: "--",
97
+ type: String,
98
+ },
99
+ storageKey: {
100
+ default: "storage.key",
101
+ type: String,
102
+ },
93
103
  },
94
104
  data: function () {
95
- const localStorage = new LocalStorageService();
105
+ const localStorage = new LocalStorageService(this.storageKey);
96
106
  const listQueryService = new ListQueryService(
97
107
  this.$route ? this.$route.name : "storage.key",
98
108
  localStorage
99
109
  );
110
+ const filterConvertor = new FilterConverter();
100
111
  let search = {};
112
+ let topSearch = {};
101
113
  for (const column of this.filters) {
102
114
  search[column.name] = {
103
115
  operator: "",
104
116
  value: "",
105
117
  };
106
118
  }
107
- for (const column of this.filtersTop) {
108
- search[column.name] = {
109
- position: "top",
119
+ if (this.topFilter) {
120
+ topSearch[this.topFilter.name] = {
110
121
  value: "",
122
+ operator: this.topFilter.operator,
111
123
  };
112
124
  }
125
+
113
126
  search = Object.assign(search, listQueryService.getListQuery().search);
127
+ topSearch = Object.assign(
128
+ topSearch,
129
+ listQueryService.getListQuery().topSearch
130
+ );
114
131
  return {
115
132
  loading: false,
116
133
  filter: {},
117
134
  data: [],
118
135
  search: search,
119
- meta: Object.assign(
120
- new MetaModel(),
121
- listQueryService.getListQuery().meta
122
- ),
136
+ topSearch: topSearch,
137
+ filterConvertor: filterConvertor,
138
+ meta: listQueryService.getListQuery().meta,
139
+ metaModel: new MetaModel(),
123
140
  listQueryService: listQueryService,
124
141
  };
125
142
  },
126
143
  computed: {
144
+ queryFilter() {
145
+ const query = {
146
+ page: this.meta.page,
147
+ limit: this.meta.limit,
148
+ };
149
+ const filter = this.filterConvertor.applyFilter({
150
+ ...this.search,
151
+ ...this.topSearch,
152
+ });
153
+ return { ...query, ...filter };
154
+ },
127
155
  currentPage() {
128
- if (this.data.meta?.pagination) {
129
- return this.data.meta.pagination.current_page;
156
+ if (this.listQueryService.getListQuery().meta) {
157
+ return this.listQueryService.getListQuery().meta.page;
130
158
  }
131
159
  return 0;
132
160
  },
133
161
  total() {
134
- if (this.data.meta?.pagination) {
135
- return this.data.meta.pagination.total;
162
+ if (this.metaModel?.pagination) {
163
+ return this.metaModel.pagination.total;
136
164
  }
137
165
  return 0;
138
166
  },
139
167
  limit() {
140
- if (this.data.meta?.pagination) {
141
- return this.data.meta.pagination.per_page;
142
- }
143
168
  if (this.listQueryService.getListQuery().meta?.limit) {
144
169
  return this.listQueryService.getListQuery().meta?.limit;
145
170
  }
@@ -154,10 +179,11 @@ export default {
154
179
  this.loading = true;
155
180
  try {
156
181
  const response = await this.repository.all(
157
- this.listQueryService.getListQuery()
182
+ this.queryFilter,
183
+ this.includes
158
184
  );
159
185
  this.data = response.data;
160
- Vue.set(this.data, "meta", response.meta);
186
+ Vue.set(this, "metaModel", response.meta);
161
187
  } catch (e) {
162
188
  this.$message.error(e.message);
163
189
  }
@@ -174,7 +200,7 @@ export default {
174
200
  page: this.listQueryService.getListQuery().meta.page,
175
201
  },
176
202
  });
177
- this.meta.pagination.per_page = val;
203
+ Vue.set(this.meta, "limit", val);
178
204
  this.fetch();
179
205
  },
180
206
  handleCurrentChange(val) {
@@ -184,34 +210,39 @@ export default {
184
210
  limit: this.listQueryService.getListQuery().meta.limit,
185
211
  },
186
212
  });
187
- this.meta.pagination.current_page = val;
213
+ Vue.set(this.meta, "page", val);
188
214
  this.fetch();
189
215
  },
190
- handleFilterChange(val) {
191
- this.filter = val;
192
- this.meta.pagination.current_page = 1;
193
- this.fetch();
216
+ handleFilterChange() {
217
+ this.handleCurrentChange(1);
194
218
  },
195
- handleApplyFilter(filters) {
219
+ handleApplyFilter() {
196
220
  this.listQueryService.updateListQuery({ search: this.search });
197
- this.handleFilterChange(filters);
221
+ this.handleFilterChange();
198
222
  },
199
223
  handleResetFilter() {
200
224
  for (const column in this.search) {
201
- if (this.search[column].position === "top") {
202
- this.search[column] = Object.assign(this.search[column], {
203
- value: "",
204
- });
205
- } else {
206
- this.search[column] = Object.assign(this.search[column], {
207
- operator: "",
208
- value: "",
209
- });
210
- }
225
+ this.search[column] = Object.assign(this.search[column], {
226
+ operator: "",
227
+ value: "",
228
+ });
211
229
  }
212
230
  this.listQueryService.updateListQuery({ search: {} });
213
231
  this.handleFilterChange({});
214
232
  },
233
+ handleApplyTopFilter() {
234
+ this.listQueryService.updateListQuery({ topSearch: this.topSearch });
235
+ this.handleFilterChange();
236
+ },
237
+ handleResetTopFilter() {
238
+ for (const column in this.topSearch) {
239
+ this.topSearch[column] = Object.assign(this.topSearch[column], {
240
+ value: "",
241
+ });
242
+ }
243
+ this.listQueryService.updateListQuery({ topSearch: {} });
244
+ this.handleFilterChange({});
245
+ },
215
246
  },
216
247
  };
217
248
  </script>
@@ -0,0 +1,41 @@
1
+ <template>
2
+ <el-row class="m-b-20">
3
+ <el-col v-if="filter">
4
+ <el-input
5
+ v-if="filter.type === 'string'"
6
+ v-model="search[filter.name].value"
7
+ clearable
8
+ @clear="resetFilter"
9
+ @keyup.enter.native="applyFilter"
10
+ />
11
+ </el-col>
12
+ </el-row>
13
+ </template>
14
+
15
+ <script>
16
+ export default {
17
+ name: "QuickSearchFilter",
18
+ props: {
19
+ filter: {
20
+ type: Object,
21
+ default: () => {
22
+ return {};
23
+ },
24
+ },
25
+ search: {
26
+ type: Object,
27
+ default: () => {
28
+ return {};
29
+ },
30
+ },
31
+ },
32
+ methods: {
33
+ applyFilter() {
34
+ this.$emit("apply:filter");
35
+ },
36
+ resetFilter() {
37
+ this.$emit("reset:filter");
38
+ },
39
+ },
40
+ };
41
+ </script>
@@ -42,7 +42,6 @@ export default {
42
42
  },
43
43
  methods: {
44
44
  pageChange (val) {
45
- debugger;
46
45
  this.$emit('page:change', val);
47
46
  },
48
47
  sizeChange(val) {
@@ -3,14 +3,36 @@
3
3
  <el-table :data="data" border @sort-change="sortChange">
4
4
  <template v-for="field in fields">
5
5
  <template v-if="field.callback">
6
- <el-table-column :key="field.prop" v-slot="context" :prop="field.prop" :label="field.label" :width="field.width ? field.width : null" sortable="custom">
7
- <el-link @click="field.callback(field.prop, context.$index, context.row)">
8
- {{ typeof field.formatter === 'function' ? field.formatter(context.row) : context.row[field.prop] }}
6
+ <el-table-column
7
+ :key="field.prop"
8
+ v-slot="context"
9
+ :prop="field.prop"
10
+ :label="field.label"
11
+ :width="field.width ? field.width : null"
12
+ :sortable="field.sortable ? field.sortable : null"
13
+ >
14
+ <el-link
15
+ @click="field.callback(field.prop, context.$index, context.row)"
16
+ >
17
+ {{
18
+ typeof field.formatter === "function"
19
+ ? field.formatter(context.row)
20
+ : context.row[field.prop]
21
+ }}
9
22
  </el-link>
10
23
  </el-table-column>
11
24
  </template>
12
25
  <template v-else>
13
- <el-table-column :formatter="typeof field.formatter === 'function' ? field.formatter : null" :key="field.prop" :prop="field.prop" :label="field.label" :width="field.width ? field.width : null" sortable="custom" />
26
+ <el-table-column
27
+ :formatter="
28
+ typeof field.formatter === 'function' ? field.formatter : null
29
+ "
30
+ :key="field.prop"
31
+ :prop="field.prop"
32
+ :label="field.label"
33
+ :width="field.width ? field.width : null"
34
+ :sortable="field.sortable ? field.sortable : null"
35
+ />
14
36
  </template>
15
37
  </template>
16
38
  </el-table>
@@ -18,7 +40,6 @@
18
40
  </template>
19
41
 
20
42
  <script>
21
-
22
43
  export default {
23
44
  name: "GenericTable",
24
45
  props: {
@@ -44,8 +65,8 @@ export default {
44
65
  },
45
66
  methods: {
46
67
  sortChange(data) {
47
- this.$emit('sort:change', data);
48
- }
49
- }
68
+ this.$emit("sort:change", data);
69
+ },
70
+ },
50
71
  };
51
72
  </script>
package/src/lang/index.js CHANGED
@@ -1,11 +1,7 @@
1
1
  import Vue from 'vue';
2
2
  import VueI18n from 'vue-i18n';
3
3
  import elementEnLocale from 'element-ui/lib/locale/lang/en'; // element-ui lang
4
- import elementZhLocale from 'element-ui/lib/locale/lang/zh-CN';// element-ui lang
5
- import elementViLocale from 'element-ui/lib/locale/lang/vi';// element-ui lang
6
4
  import enLocale from './en';
7
- import zhLocale from './zh';
8
- import viLocale from './vi';
9
5
 
10
6
  Vue.use(VueI18n);
11
7
 
@@ -14,14 +10,6 @@ const messages = {
14
10
  ...enLocale,
15
11
  ...elementEnLocale,
16
12
  },
17
- zh: {
18
- ...zhLocale,
19
- ...elementZhLocale,
20
- },
21
- vi: {
22
- ...viLocale,
23
- ...elementViLocale,
24
- },
25
13
  };
26
14
 
27
15
  const i18n = new VueI18n({
@@ -1,83 +0,0 @@
1
- <template>
2
- <el-col v-if="column" :span="18" class="m-b-20">
3
- <el-col v-if="column.type !== 'checkbox'" class="m-b-5 p-l-0">
4
- <label>{{ column.label }}</label>
5
- </el-col>
6
- <el-input v-if="column.type==='string'" v-model="search.value" />
7
- </el-col>
8
- </template>
9
- <script>
10
- export default {
11
- props: {
12
- column: {
13
- type: Object,
14
- default() {
15
- return {};
16
- },
17
- },
18
- search: {
19
- type: Object,
20
- default() {
21
- return {};
22
- },
23
- },
24
- },
25
- data() {
26
- return {
27
- loading: false,
28
- selectKey: this.column.selectKey ?? 'key',
29
- selectLabel: this.column.selectLabel ?? 'label',
30
- selectValue: this.column.selectValue ?? 'key',
31
- filterable: this.column.filterable ?? false,
32
- remote: this.column.remote ?? false,
33
- remoteMethod: this.column.remoteMethod ?? null,
34
- selectListLocal: this.search.selectList ? this.search.selectList : (this.column.type === 'enum' ? this.column.values : this.boolValues),
35
- };
36
- },
37
- computed: {
38
- isMultiple() {
39
- return this.column.is_multiple ? this.column.is_multiple : false;
40
- },
41
- remoteMethodHandler: {
42
- get() {
43
- if (this.remoteMethod !== null) {
44
- return this.remoteCall;
45
- }
46
- return null;
47
- },
48
- },
49
- },
50
- watch: {
51
- search() {
52
- if (this.search.operator === '') {
53
- this.showFilter = false;
54
- }
55
- },
56
- },
57
- mounted() {
58
- if (this.column.operator) {
59
- this.search.operator = this.column.operator;
60
- }
61
- },
62
- methods: {
63
- async remoteCall(query) {
64
- this.loading = true;
65
- const response = await this.remoteMethod.all({ search: this.selectLabel + ':' + query, searchFields: this.selectLabel + ':like' });
66
- this.selectListLocal = response.data;
67
- this.search['selectList'] = response.data;
68
- this.loading = false;
69
- },
70
- updateSearch(key) {
71
- if (key && this.remote) {
72
- const obj = { [this.selectKey]: key };
73
- for (const item of this.selectListLocal) {
74
- if (item[this.selectKey] === key) {
75
- obj[this.selectLabel] = item[this.selectLabel];
76
- this.search.selectList = [obj];
77
- }
78
- }
79
- }
80
- },
81
- },
82
- };
83
- </script>
@@ -1,54 +0,0 @@
1
- <template>
2
- <el-row>
3
- <filter-top-row
4
- v-for="column in filters"
5
- :key="column.name"
6
- :column="column"
7
- :search="search[column.name]"
8
- />
9
- <el-col :span="6" class="m-t-20">
10
- <el-button @click="applyFilter">Filter</el-button>
11
- <el-button @click="resetFilter">Reset filter</el-button>
12
- </el-col>
13
- </el-row>
14
- </template>
15
-
16
- <script>
17
- import FilterConverter from "./filter-convertor.ts";
18
- import FilterTopRow from "./FilterTopRow";
19
- export default {
20
- name: "GenericTopFilter",
21
- props: {
22
- filters: {
23
- type: Array,
24
- default: () => {
25
- return {};
26
- },
27
- },
28
- search: {
29
- type: Object,
30
- default: () => {
31
- return {};
32
- },
33
- },
34
- },
35
- components: { FilterTopRow },
36
- data() {
37
- const filterConvertor = new FilterConverter();
38
- return {
39
- filterConvertor: filterConvertor,
40
- };
41
- },
42
- methods: {
43
- getFilter() {
44
- return this.filterConvertor.applyFilter(this.search);
45
- },
46
- applyFilter() {
47
- this.$emit("apply:filter", this.filterConvertor.applyFilter(this.search));
48
- },
49
- resetFilter() {
50
- this.$emit("reset:filter", {});
51
- },
52
- },
53
- };
54
- </script>
@@ -1,8 +0,0 @@
1
- export default [
2
- {
3
- name: 'first_name,last_name,email,phone,mobile,position,street,city,state,second_email,department',
4
- label: 'Search',
5
- type: 'string',
6
- operator: 'like_fields',
7
- },
8
- ]