Web UI: Avoid unnecessary duplicated api calls

This commit is contained in:
Matthieu Hostache 2019-11-27 12:04:05 +01:00 committed by Traefiker Bot
parent 5b1dc0bfbd
commit 407eda0ba0
2 changed files with 20 additions and 35 deletions

View file

@ -3,15 +3,12 @@ import { APP } from '../_helpers/APP'
const apiBase = '/http' const apiBase = '/http'
function getAllRouters (params) { function getAllRouters (params) {
return APP.api.get(`${apiBase}/routers?search=${params.query}&status=${params.status}`) return APP.api.get(`${apiBase}/routers?search=${params.query}&status=${params.status}&per_page=${params.limit}&page=${params.page}`)
.then(body => { .then(body => {
const total = body.data ? body.data.length : 0 const total = body.data ? body.data.length : 0
return APP.api.get(`${apiBase}/routers?search=${params.query}&status=${params.status}&per_page=${params.limit}&page=${params.page}`) console.log('Success -> HttpService -> getAllRouters', body.data)
.then(body => { // TODO - suggestion: add the total-pages in api response to optimize the query
console.log('Success -> HttpService -> getAllRouters', body.data) return { data: body.data || [], total }
// TODO - suggestion: add the total-pages in api response to optimize the query
return { data: body.data || [], total }
})
}) })
} }
@ -24,15 +21,12 @@ function getRouterByName (name) {
} }
function getAllServices (params) { function getAllServices (params) {
return APP.api.get(`${apiBase}/services?search=${params.query}&status=${params.status}`) return APP.api.get(`${apiBase}/services?search=${params.query}&status=${params.status}&per_page=${params.limit}&page=${params.page}`)
.then(body => { .then(body => {
const total = body.data ? body.data.length : 0 const total = body.data ? body.data.length : 0
return APP.api.get(`${apiBase}/services?search=${params.query}&status=${params.status}&per_page=${params.limit}&page=${params.page}`) console.log('Success -> HttpService -> getAllServices', body.data)
.then(body => { // TODO - suggestion: add the total-pages in api response to optimize the query
console.log('Success -> HttpService -> getAllServices', body.data) return { data: body.data || [], total }
// TODO - suggestion: add the total-pages in api response to optimize the query
return { data: body.data || [], total }
})
}) })
} }
@ -45,15 +39,12 @@ function getServiceByName (name) {
} }
function getAllMiddlewares (params) { function getAllMiddlewares (params) {
return APP.api.get(`${apiBase}/middlewares?search=${params.query}&status=${params.status}`) return APP.api.get(`${apiBase}/middlewares?search=${params.query}&status=${params.status}&per_page=${params.limit}&page=${params.page}`)
.then(body => { .then(body => {
const total = body.data ? body.data.length : 0 const total = body.data ? body.data.length : 0
return APP.api.get(`${apiBase}/middlewares?search=${params.query}&status=${params.status}&per_page=${params.limit}&page=${params.page}`) console.log('Success -> HttpService -> getAllMiddlewares', body.data)
.then(body => { // TODO - suggestion: add the total-pages in api response to optimize the query
console.log('Success -> HttpService -> getAllMiddlewares', body.data) return { data: body.data || [], total }
// TODO - suggestion: add the total-pages in api response to optimize the query
return { data: body.data || [], total }
})
}) })
} }

View file

@ -3,15 +3,12 @@ import { APP } from '../_helpers/APP'
const apiBase = '/tcp' const apiBase = '/tcp'
function getAllRouters (params) { function getAllRouters (params) {
return APP.api.get(`${apiBase}/routers?search=${params.query}&status=${params.status}`) return APP.api.get(`${apiBase}/routers?search=${params.query}&status=${params.status}&per_page=${params.limit}&page=${params.page}`)
.then(body => { .then(body => {
const total = body.data ? body.data.length : 0 const total = body.data ? body.data.length : 0
return APP.api.get(`${apiBase}/routers?search=${params.query}&status=${params.status}&per_page=${params.limit}&page=${params.page}`) console.log('Success -> HttpService -> getAllRouters', body.data)
.then(body => { // TODO - suggestion: add the total-pages in api response to optimize the query
console.log('Success -> HttpService -> getAllRouters', body.data) return { data: body.data || [], total }
// TODO - suggestion: add the total-pages in api response to optimize the query
return { data: body.data || [], total }
})
}) })
} }
@ -24,15 +21,12 @@ function getRouterByName (name) {
} }
function getAllServices (params) { function getAllServices (params) {
return APP.api.get(`${apiBase}/services?search=${params.query}&status=${params.status}`) return APP.api.get(`${apiBase}/services?search=${params.query}&status=${params.status}&per_page=${params.limit}&page=${params.page}`)
.then(body => { .then(body => {
const total = body.data ? body.data.length : 0 const total = body.data ? body.data.length : 0
return APP.api.get(`${apiBase}/services?search=${params.query}&status=${params.status}&per_page=${params.limit}&page=${params.page}`) console.log('Success -> HttpService -> getAllServices', body.data)
.then(body => { // TODO - suggestion: add the total-pages in api response to optimize the query
console.log('Success -> HttpService -> getAllServices', body.data) return { data: body.data || [], total }
// TODO - suggestion: add the total-pages in api response to optimize the query
return { data: body.data || [], total }
})
}) })
} }