Web UI: Polling on tables
This commit is contained in:
parent
7f085df240
commit
b3c9a50ead
20 changed files with 2028 additions and 361 deletions
|
@ -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',
|
||||
|
|
|
@ -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) {
|
||||
|
|
44
webui/src/_helpers/Mutations.js
Normal file
44
webui/src/_helpers/Mutations.js
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue