1
0
Fork 0

Web UI: Polling on tables

This commit is contained in:
Matthieu Hostache 2019-12-17 14:52:05 +01:00 committed by Traefiker Bot
parent 7f085df240
commit b3c9a50ead
20 changed files with 2028 additions and 361 deletions

View file

@ -1,5 +1,4 @@
import { Notify } from 'quasar'
import { APP } from './APP'
class Errors {
// Getters
@ -12,7 +11,7 @@ class Errors {
// ------------------------------------------------------------------------
static showError (body) {
body = APP._.isString(body) ? JSON.parse(body) : body
body = typeof body === 'string' ? JSON.parse(body) : body
Notify.create({
color: 'negative',
position: 'top',

View file

@ -1,4 +1,4 @@
import { APP } from './APP'
import { get } from 'dot-prop'
class Helps {
// Getters
@ -11,7 +11,7 @@ class Helps {
// ------------------------------------------------------------------------
static get (obj, prop, def = undefined) {
return APP._.get(obj, prop, def)
return get(obj, prop, def)
}
static hasIn (obj, prop) {

View file

@ -0,0 +1,44 @@
import { set, get } from 'dot-prop'
export const withPagination = (type, opts = {}) => (state, data) => {
const { isSameContext, statePath } = opts
const currentState = get(state, statePath)
let newState
switch (type) {
case 'request':
newState = {
...currentState,
loading: true
}
break
case 'success':
const { body, page } = data
newState = {
...currentState,
items: [
...(isSameContext && currentState.items && page !== 1 ? currentState.items : []),
...(body.data || [])
],
currentPage: page,
total: isSameContext && currentState.items && page !== 1
? body.total + currentState.total
: body.total,
loading: false
}
break
case 'failure':
newState = {
...currentState,
loading: false,
error: data,
endReached: data.message.includes('invalid request: page:')
}
break
}
if (newState) {
set(state, statePath, newState)
}
}