@benjy2976/pmsg 0.1.0 → 0.1.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.
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/Model.js +12 -9
- package/src/useModelStore.js +29 -3
package/README.md
CHANGED
package/package.json
CHANGED
package/src/Model.js
CHANGED
|
@@ -21,7 +21,9 @@ export default class Model {
|
|
|
21
21
|
selectable : false,// Condicional para definir si el objeto es seleccionable
|
|
22
22
|
default : {},// Valor del objeto por defecto,
|
|
23
23
|
params : { modeljs: true },// Aquí se configuran parámetros adicionales a enviar en los request excepto DELETE
|
|
24
|
-
modelGetters : {}
|
|
24
|
+
modelGetters : {},// Aquí se configuran parámetros adicionales a enviar en los request excepto DELETE
|
|
25
|
+
paginate : false,// Condicional para definir si el modelo tiene paginación
|
|
26
|
+
pagination : {current_page: 1, per_page: 10},// Configuración de paginación
|
|
25
27
|
}
|
|
26
28
|
//config.hasKey=config.hasKey!=undefined?config.hasKey:config.key!=undefined
|
|
27
29
|
defaultValues = Object.assign(defaultValues, config)
|
|
@@ -44,6 +46,8 @@ export default class Model {
|
|
|
44
46
|
this.default = defaultValues.default
|
|
45
47
|
this.params = defaultValues.params
|
|
46
48
|
this.modelGetters = defaultValues.modelGetters
|
|
49
|
+
this.paginate = defaultValues.paginate
|
|
50
|
+
this.pagination = defaultValues.pagination
|
|
47
51
|
this.state = {}
|
|
48
52
|
this.getters = {}
|
|
49
53
|
this.actions = {}
|
|
@@ -52,9 +56,7 @@ export default class Model {
|
|
|
52
56
|
get(url = '', params = {}) {
|
|
53
57
|
params = Object.assign(params, this.params)
|
|
54
58
|
url = this.route + '/' + url
|
|
55
|
-
return this.instance.get(url,
|
|
56
|
-
params : params,
|
|
57
|
-
})
|
|
59
|
+
return this.instance.get(url, params)
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
post(url = '', params = {}) {
|
|
@@ -66,9 +68,7 @@ export default class Model {
|
|
|
66
68
|
// Función para obtener el listado de Objetos de la base de datos
|
|
67
69
|
getAll(params = {}) {
|
|
68
70
|
params = Object.assign(params, this.params)
|
|
69
|
-
return this.instance.get(this.route,
|
|
70
|
-
params : params,
|
|
71
|
-
})
|
|
71
|
+
return this.instance.get(this.route, params)
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
// Función para crear un objeto en la base de datos
|
|
@@ -190,7 +190,9 @@ export default class Model {
|
|
|
190
190
|
|
|
191
191
|
}
|
|
192
192
|
}),
|
|
193
|
-
sync
|
|
193
|
+
sync : this.sync,
|
|
194
|
+
paginate : this.paginate,
|
|
195
|
+
pagination : this.pagination,
|
|
194
196
|
}
|
|
195
197
|
}
|
|
196
198
|
|
|
@@ -214,4 +216,5 @@ export default class Model {
|
|
|
214
216
|
getNameAttribute() {
|
|
215
217
|
return this.name
|
|
216
218
|
}
|
|
217
|
-
}
|
|
219
|
+
}
|
|
220
|
+
|
package/src/useModelStore.js
CHANGED
|
@@ -34,6 +34,8 @@ export default function createModelStore (model, state = {}, getters = {}, actio
|
|
|
34
34
|
maxRelationsResolve : config.maxRelationsResolve,
|
|
35
35
|
relations : config.relations,
|
|
36
36
|
syncStatus : config.sync,
|
|
37
|
+
paginate : config.paginate,
|
|
38
|
+
pagination : config.pagination,
|
|
37
39
|
selectedStatus : false,
|
|
38
40
|
timeOutAsinc : null,
|
|
39
41
|
check : check,
|
|
@@ -128,17 +130,26 @@ export default function createModelStore (model, state = {}, getters = {}, actio
|
|
|
128
130
|
})
|
|
129
131
|
},
|
|
130
132
|
// Action para obtener la lista de objetos de el servidor
|
|
131
|
-
async get (params = {}) {
|
|
133
|
+
async get (params = {}, pagination={}) {
|
|
132
134
|
//var commit = store.commit
|
|
133
135
|
const action = this.syncStatus ? 'sync' : 'setItems';
|
|
134
|
-
|
|
136
|
+
|
|
137
|
+
if (model.paginate) {
|
|
138
|
+
params = {...params, ...Object.assign({
|
|
139
|
+
page : this.pagination.current_page, per_page : this.pagination.per_page
|
|
140
|
+
}, pagination) };
|
|
141
|
+
}
|
|
135
142
|
if (!(await model.saved(params))) {
|
|
136
143
|
return new Promise((resolve, reject) => {
|
|
137
144
|
model.getAll(params).then(response => {
|
|
138
145
|
const data = response.data;
|
|
139
146
|
model.save(data.data);
|
|
140
147
|
this[action](data.data);
|
|
148
|
+
// eslint-disable-next-line no-unused-vars
|
|
149
|
+
const { data: _, ...pagination } = data.meta;
|
|
150
|
+
this.pagination = Object.assign(this.pagination, pagination);
|
|
141
151
|
this.afterGet();
|
|
152
|
+
console.log('get', this)
|
|
142
153
|
resolve(response);
|
|
143
154
|
}).catch(reject);
|
|
144
155
|
})
|
|
@@ -148,6 +159,18 @@ export default function createModelStore (model, state = {}, getters = {}, actio
|
|
|
148
159
|
}
|
|
149
160
|
},
|
|
150
161
|
|
|
162
|
+
async getPage (params = {}, pagination={}) {
|
|
163
|
+
//var commit = store.commit
|
|
164
|
+
if (model.paginate) {
|
|
165
|
+
params = {...params, ...Object.assign({
|
|
166
|
+
page : this.pagination.current_page, per_page : this.pagination.per_page
|
|
167
|
+
}, pagination) };
|
|
168
|
+
}
|
|
169
|
+
//console.log('getPage paginatios', this.pagination)
|
|
170
|
+
//console.log('getPage', params)
|
|
171
|
+
return this.get(params)
|
|
172
|
+
|
|
173
|
+
},
|
|
151
174
|
// Action para obtener la lista de algunos objetos de el servidor sin consultar ni almacenar en el localstorage
|
|
152
175
|
getSome( params = {}){
|
|
153
176
|
//var commit = store.commit
|
|
@@ -297,6 +320,9 @@ export default function createModelStore (model, state = {}, getters = {}, actio
|
|
|
297
320
|
this.items.push(item)
|
|
298
321
|
}
|
|
299
322
|
},
|
|
323
|
+
setPageSize(pageSize){
|
|
324
|
+
this.pagination.per_page = pageSize
|
|
325
|
+
},
|
|
300
326
|
|
|
301
327
|
/********* MUTACIONES COMO ACTIONS */
|
|
302
328
|
// Mutation para setear el listado de objetos
|
|
@@ -322,4 +348,4 @@ export default function createModelStore (model, state = {}, getters = {}, actio
|
|
|
322
348
|
...actions
|
|
323
349
|
}
|
|
324
350
|
};
|
|
325
|
-
}
|
|
351
|
+
}
|