Initial commit
This commit is contained in:
19
proxy-ui-app/src/store/index.js
Normal file
19
proxy-ui-app/src/store/index.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import {createStore, createLogger} from 'vuex';
|
||||
import {store as proxy} from '@/store/modules/proxy';
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
let debug = process.env.NODE_ENV !== 'production';
|
||||
debug = false;
|
||||
|
||||
const plugins = debug ? [createLogger({})] : [];
|
||||
|
||||
export const store = createStore({
|
||||
plugins,
|
||||
modules: {
|
||||
proxy
|
||||
},
|
||||
});
|
||||
|
||||
export function useStore() {
|
||||
return store;
|
||||
}
|
||||
65
proxy-ui-app/src/store/modules/proxy/StaticData.js
Normal file
65
proxy-ui-app/src/store/modules/proxy/StaticData.js
Normal file
@@ -0,0 +1,65 @@
|
||||
const config = {
|
||||
id: "id",
|
||||
created_at: "created_at",
|
||||
updated_at: "updated_at",
|
||||
deleted_at: "deleted_at",
|
||||
name: "name",
|
||||
port: "port",
|
||||
proxy_ip: "proxy_ip",
|
||||
internet_uri: "internet_uri",
|
||||
description: "description",
|
||||
is_online: "is_online",
|
||||
site_ip: "device_ip",
|
||||
}
|
||||
|
||||
const configRoutes = {
|
||||
id: "id",
|
||||
created_at: "created_at",
|
||||
updated_at: "updated_at",
|
||||
deleted_at: "deleted_at",
|
||||
server_id: "server_id",
|
||||
path: "path",
|
||||
role: "role",
|
||||
description: "description",
|
||||
order: "order",
|
||||
deepness: "deepness",
|
||||
is_cb_on: "is_cb_on",
|
||||
is_online: "is_online",
|
||||
cb_request_limit: "cb_request_limit",
|
||||
cb_min_requests: "cb_min_requests",
|
||||
cb_error_threshold_percentage: "cb_error_threshold_percentage",
|
||||
cb_interval_duration: "cb_interval_duration",
|
||||
cb_open_state_timeout: "cb_open_state_timeout",
|
||||
site_ip: "device_ip",
|
||||
}
|
||||
|
||||
const routes = [
|
||||
{"path": "/socket.io", "backend": "http://backend:8000", "role": "*", "site": "cdrp"},
|
||||
{"path": "/socket.io", "backend": "http://backend:8000", "role": "*", "site": "cdrp"},
|
||||
{"path": "/socket.io/*", "backend": "http://backend:8000", "role": "*", "site": "cdrp"},
|
||||
{"path": "/api", "backend": "http://backend:8000", "role": "*", "site": "cdrp"},
|
||||
{"path": "/api/*", "backend": "http://backend:8000", "role": "*", "site": "cdrp"},
|
||||
{"path": "/api/*/*", "backend": "http://backend:8000", "role": "*", "site": "cdrp"},
|
||||
{"path": "/api/*/*/*", "backend": "http://backend:8000", "role": "*", "site": "cdrp"},
|
||||
{"path": "/api/*/*/*/*", "backend": "http://backend:8000", "role": "*", "site": "cdrp"},
|
||||
{"path": "/swagger", "backend": "http://backend:8000", "role": "*", "site": "cdrp"},
|
||||
{"path": "/swagger/*", "backend": "http://backend:8000", "role": "*", "site": "cdrp"},
|
||||
{"path": "/swagger/*/*", "backend": "http://backend:8000", "role": "*", "site": "cdrp"},
|
||||
{"path": "/swagger/*/*/*","backend": "http://backend:8000", "role": "*", "site": "cdrp"},
|
||||
{"path": "/", "backend": "http://frontend:8000", "role": "*", "site": "cdrp"},
|
||||
{"path": "/*", "backend": "http://frontend:8000", "role": "*", "site": "cdrp"},
|
||||
{"path": "/*/*", "backend": "http://frontend:8000", "role": "*", "site": "cdrp"},
|
||||
{"path": "/*/*/*", "backend": "http://frontend:8000", "role": "*", "site": "cdrp"},
|
||||
{"path": "/*/*/*/*", "backend": "http://frontend:8000", "role": "*", "site": "cdrp"},
|
||||
{"path": "/*/*/*/*/*", "backend": "http://frontend:8000", "role": "*", "site": "cdrp"}
|
||||
]
|
||||
|
||||
const sites = [
|
||||
{"name": "cdrp"},
|
||||
{"name": "live_monitore"},
|
||||
{"name": "buk"},
|
||||
{"name": "mtso"},
|
||||
{"name": "as_dmps"}
|
||||
]
|
||||
|
||||
export {routes, sites, config, configRoutes}
|
||||
67
proxy-ui-app/src/store/modules/proxy/helpers.js
Normal file
67
proxy-ui-app/src/store/modules/proxy/helpers.js
Normal file
@@ -0,0 +1,67 @@
|
||||
const addedSite = (addedSite, sites) => {
|
||||
return [addedSite,...sites]
|
||||
}
|
||||
|
||||
const updatedSite = (updatedSite, sites) => {
|
||||
if (updatedSite.id) {
|
||||
const editIdx = sites.findIndex(service => service.id === updatedSite.id)
|
||||
const beforeEdit = sites.slice(0, editIdx)
|
||||
const afterEdit = sites.slice(editIdx + 1)
|
||||
const withEdit = [...beforeEdit, updatedSite]
|
||||
return [...withEdit, ...afterEdit]
|
||||
}
|
||||
}
|
||||
|
||||
const removedNewSite = (sites) => {
|
||||
if (sites.length > 0) {
|
||||
const firstSite = sites[0]
|
||||
const isNewSite = firstSite.id === -1
|
||||
sites = isNewSite ? sites.slice(1) : sites
|
||||
return sites
|
||||
}
|
||||
}
|
||||
|
||||
const deletedSite = (deletedSiteId, sites) => {
|
||||
if (deletedSiteId) {
|
||||
const deleteIdx = sites.findIndex(service => service.id === deletedSiteId)
|
||||
return sites.slice(0, deleteIdx).concat(sites.slice(deleteIdx + 1))
|
||||
}
|
||||
}
|
||||
|
||||
const addedNewRoute = (selectedSite, routes) => {
|
||||
let newRoute = routes.find((route) => route.action === 'create')
|
||||
if (newRoute) {
|
||||
newRoute = {...newRoute, server_id: selectedSite.id}
|
||||
const withoutNewRoute = routes.filter(route => route.action !== 'create')
|
||||
return [newRoute, ...withoutNewRoute]
|
||||
}
|
||||
}
|
||||
|
||||
const updatedRoute = (updatedRoute, routes) => {
|
||||
return routes.reduce((acc, cur) => {
|
||||
if (cur.id === updatedRoute.id) {
|
||||
return [...acc, {
|
||||
...updatedRoute,
|
||||
action: updatedRoute.action === "create" ? "create" : "update"
|
||||
}]
|
||||
}
|
||||
return [...acc, cur]
|
||||
}, [])
|
||||
}
|
||||
|
||||
const deletedRoute = (deletedRouteId, routes) => {
|
||||
return routes.reduce((acc, cur) => {
|
||||
if (cur.id !== deletedRouteId) return [...acc, cur]
|
||||
if (cur.action === "create") return acc
|
||||
return [...acc, {
|
||||
...cur,
|
||||
action: "remove"
|
||||
}]
|
||||
}, [])
|
||||
}
|
||||
|
||||
const sortedRoutes = (routes) => {
|
||||
return routes.sort(({updated_at: a}, {updated_at: b}) => new Date(b).valueOf() - new Date(a).valueOf())
|
||||
}
|
||||
|
||||
export { addedSite, updatedSite, removedNewSite, deletedSite, addedNewRoute, updatedRoute, sortedRoutes, deletedRoute }
|
||||
153
proxy-ui-app/src/store/modules/proxy/index.js
Normal file
153
proxy-ui-app/src/store/modules/proxy/index.js
Normal file
@@ -0,0 +1,153 @@
|
||||
import { config, configRoutes } from './StaticData.js';
|
||||
import routeOptions from './routeOptions.json'
|
||||
import Services from '@helpers/Services/Services.js';
|
||||
import {addedSite, updatedSite, removedNewSite, deletedSite, addedNewRoute, updatedRoute, sortedRoutes, deletedRoute} from './helpers.js';
|
||||
import {isEmpty, dissoc} from 'ramda';
|
||||
import RoutesClass from "@helpers/server-routes/Routes.js";
|
||||
|
||||
const routerManager = new RoutesClass(import.meta.env.VITE_API_ADDR, configRoutes)
|
||||
const services = new Services(import.meta.env.VITE_API_ADDR, config)
|
||||
|
||||
const initState = {
|
||||
sites: [],
|
||||
sitesState: "loading",
|
||||
isSaveData: false,
|
||||
selectedSite: null,
|
||||
|
||||
routes: [],
|
||||
routesState: "await",
|
||||
routesLib: {},
|
||||
};
|
||||
|
||||
const state = {
|
||||
...initState
|
||||
};
|
||||
|
||||
const getters = {
|
||||
isSaveData: (state) => state.isSaveData,
|
||||
sites: (state) => state.sites,
|
||||
routes: (state) => state.routes.filter(({action}) => !["remove", "delete"].includes(action)),
|
||||
routesLib: (state) => state.routes.reduce((acc, cur) => ({
|
||||
...acc,
|
||||
[cur.id]: cur
|
||||
}), {}),
|
||||
routesState: (state) => state.routesState,
|
||||
sitesState: (state) => state.sitesState,
|
||||
routeOptions: () => routeOptions,
|
||||
selectedSite: (state) => state.selectedSite,
|
||||
};
|
||||
|
||||
const mutations = {
|
||||
setIsSaveData: (state, payload) => state.isSaveData = payload,
|
||||
setSites: (state, payload) => state.sites = payload,
|
||||
setSitesState: (state, payload) => state.sitesState = payload,
|
||||
setSelectedSite: (state, payload) => state.selectedSite = payload,
|
||||
setRoutes: (state, payload) => state.routes = payload,
|
||||
setRoutesState: (state, payload) => state.routesState = payload,
|
||||
};
|
||||
|
||||
const actions = {
|
||||
addNewSiteLayout: ({commit, getters}) => {
|
||||
const newSite = {"port": "", "name": "", id: -1}
|
||||
commit('setSites', [newSite,...getters.sites])
|
||||
commit('setSelectedSite', newSite)
|
||||
commit('setRoutes', [])
|
||||
commit('setRoutesState', "active")
|
||||
},
|
||||
createNewSite: async ({dispatch, commit, getters, state}, payload) => {
|
||||
commit('setIsSaveData', false)
|
||||
commit('setSelectedSite', null)
|
||||
const newSite = await services.createService(payload)
|
||||
const updatedSites = addedSite(newSite, getters.sites)
|
||||
if (!isEmpty(updatedSites)) {
|
||||
const newSite = updatedSites[0]
|
||||
const updatedRoutes = addedNewRoute(newSite, state.routes)
|
||||
commit('setRoutes', updatedRoutes)
|
||||
dispatch('updateRoutesWithApi', newSite)
|
||||
return commit('setSites', updatedSites)
|
||||
}
|
||||
},
|
||||
breakeAddingSite: ({commit}) => {
|
||||
commit('setSelectedSite', null)
|
||||
},
|
||||
uploadSites: async ({commit}) => {
|
||||
const sites = await services.getServices()
|
||||
commit('setSites', sites)
|
||||
commit('setSitesState', 'active')
|
||||
},
|
||||
editSelectedSite: async ({commit, getters}, payload) => {
|
||||
const selectedSite = getters.selectedSite
|
||||
selectedSite[payload.key] = payload.value
|
||||
commit('setSelectedSite', selectedSite)
|
||||
},
|
||||
saveSite: async ({commit, getters}, payload) => {
|
||||
commit('setIsSaveData', false)
|
||||
commit('setSelectedSite', null)
|
||||
const editedSite = await services.updateService(payload)
|
||||
const updatedSites = !isEmpty(editedSite) ? updatedSite(editedSite, getters.sites) : getters.sites
|
||||
commit('setSites', updatedSites)
|
||||
},
|
||||
breakSavingSite: ({commit}) => {
|
||||
commit('setSelectedSite', null)
|
||||
commit('setRoutesState', "await")
|
||||
},
|
||||
removeSite: async ({commit, getters}, id) => {
|
||||
const deletedSiteId = await services.deleteService(id)
|
||||
const updatedSites = deletedSite(deletedSiteId, getters.sites)
|
||||
if (!isEmpty(updatedSites)) return commit('setSites', updatedSites)
|
||||
},
|
||||
uploadSiteRoutes: async ({commit, getters}, siteProps) => {
|
||||
const sites = removedNewSite(getters.sites)
|
||||
commit('setSites', sites)
|
||||
commit('setSelectedSite', siteProps)
|
||||
commit('setRoutesState', "loading")
|
||||
let routes = await routerManager.getRouterById(siteProps.id)
|
||||
routes = sortedRoutes(routes)
|
||||
commit('setRoutes', routes)
|
||||
commit('setRoutesState', "active")
|
||||
},
|
||||
addNewRouteLayout: ({commit, getters}) => {
|
||||
const newRoute = {
|
||||
"path": null,
|
||||
"role": null,
|
||||
id: Math.random().toString(36).slice(4),
|
||||
action: "create",
|
||||
server_id: getters.selectedSite.id
|
||||
}
|
||||
commit('setRoutes', [newRoute, ...state.routes])
|
||||
},
|
||||
updateRouteRow: ({commit, state}, editRoute) => {
|
||||
const updatedRoutes = updatedRoute(editRoute, state.routes)
|
||||
commit('setRoutes', updatedRoutes)
|
||||
},
|
||||
updateRoutesWithApi: async ({commit, state}, payload) => {
|
||||
commit('setRoutesState', "loading")
|
||||
let updatedRoutes = state.routes.filter(({action}) => action)
|
||||
updatedRoutes = updatedRoutes.map((el) => {
|
||||
if (el.action === "create") return dissoc('id', el)
|
||||
return el
|
||||
})
|
||||
await routerManager.updateGroupRoutes(updatedRoutes)
|
||||
let routes = await routerManager.getRouterById(payload.id)
|
||||
routes = sortedRoutes(routes)
|
||||
commit('setRoutes', routes)
|
||||
commit('setRoutesState', "await")
|
||||
},
|
||||
removeRoute: ({commit, state}, {id}) => {
|
||||
const updatedRoutes = deletedRoute(id, state.routes)
|
||||
commit('setRoutes', updatedRoutes)
|
||||
},
|
||||
resetStore: ({state}) => {
|
||||
Object.entries(initState).forEach(([k,v]) => {
|
||||
state[k] = v
|
||||
})
|
||||
},
|
||||
};
|
||||
|
||||
export const store = {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
mutations,
|
||||
actions,
|
||||
};
|
||||
5
proxy-ui-app/src/store/modules/proxy/routeOptions.json
Normal file
5
proxy-ui-app/src/store/modules/proxy/routeOptions.json
Normal file
@@ -0,0 +1,5 @@
|
||||
[
|
||||
{ "name": 1, "value": 1 },
|
||||
{ "name": 2, "value": 2 },
|
||||
{ "name": 3, "value": 3 }
|
||||
]
|
||||
19
proxy-ui-app/src/store/modules/proxy/routes.json
Executable file
19
proxy-ui-app/src/store/modules/proxy/routes.json
Executable file
@@ -0,0 +1,19 @@
|
||||
[
|
||||
{"description": "The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting", "id": 1,"path": "/socket.io", "backend": "http://backend:8000", "role": "*", "site": "cdrp"},
|
||||
{"description": "The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting", "id": 2,"path": "/socket.io/*", "backend": "http://backend:8000", "role": "*", "site": "cdrp"},
|
||||
{"description": "The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting", "id": 3,"path": "/api", "backend": "http://backend:8000", "role": "*", "site": "cdrp"},
|
||||
{"description": "The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting", "id": 4,"path": "/api/*", "backend": "http://backend:8000", "role": "*", "site": "cdrp"},
|
||||
{"description": "The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting", "id": 5,"path": "/api/*/*", "backend": "http://backend:8000", "role": "*", "site": "cdrp"},
|
||||
{"description": "The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting", "id": 6,"path": "/api/*/*/*", "backend": "http://backend:8000", "role": "*", "site": "cdrp"},
|
||||
{"description": "The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting", "id": 7,"path": "/api/*/*/*/*", "backend": "http://backend:8000", "role": "*", "site": "cdrp"},
|
||||
{"description": "The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting", "id": 8,"path": "/swagger", "backend": "http://backend:8000", "role": "*", "site": "cdrp"},
|
||||
{"description": "The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting", "id": 9,"path": "/swagger/*", "backend": "http://backend:8000", "role": "*", "site": "cdrp"},
|
||||
{"description": "The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting", "id": 10,"path": "/swagger/*/*", "backend": "http://backend:8000", "role": "*", "site": "cdrp"},
|
||||
{"description": "The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting", "id": 11,"path": "/swagger/*/*/*","backend": "http://backend:8000", "role": "*", "site": "cdrp"},
|
||||
{"description": "The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting", "id": 12,"path": "/", "backend": "http://frontend:8000", "role": "*", "site": "cdrp"},
|
||||
{"description": "The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting", "id": 13,"path": "/*", "backend": "http://frontend:8000", "role": "*", "site": "cdrp"},
|
||||
{"description": "The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting", "id": 14,"path": "/*/*", "backend": "http://frontend:8000", "role": "*", "site": "cdrp"},
|
||||
{"description": "The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting", "id": 15,"path": "/*/*/*", "backend": "http://frontend:8000", "role": "*", "site": "cdrp"},
|
||||
{"description": "The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting", "id": 16,"path": "/*/*/*/*", "backend": "http://frontend:8000", "role": "*", "site": "cdrp"},
|
||||
{"description": "The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting", "id": 17,"path": "/*/*/*/*/*", "backend": "http://frontend:8000", "role": "*", "site": "cdrp"}
|
||||
]
|
||||
7
proxy-ui-app/src/store/modules/proxy/sites.json
Executable file
7
proxy-ui-app/src/store/modules/proxy/sites.json
Executable file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
{"description": "The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting", "device_ip": "172.25.78.36", "proxy_ip": "172.25.78.36", "status": "active", "id": 1,"port": "4000", "name": "cdrp"},
|
||||
{"description": "The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting", "device_ip": "172.25.78.36", "proxy_ip": "172.25.78.36", "status": "active", "id": 2,"port": "4000", "name": "live_monitore"},
|
||||
{"description": "The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting", "device_ip": "172.25.78.36", "proxy_ip": "172.25.78.36", "status": "active", "id": 3,"port": "4000", "name": "buk"},
|
||||
{"description": "The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting", "device_ip": "172.25.78.36", "proxy_ip": "172.25.78.36", "status": "active", "id": 4,"port": "4000", "name": "mtso"},
|
||||
{"description": "The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting", "device_ip": "172.25.78.36", "proxy_ip": "172.25.78.36", "status": "active", "id": 5,"port": "4000", "name": "as_dmps"}
|
||||
]
|
||||
Reference in New Issue
Block a user