diff --git a/src/client/src/app/App.jsx b/src/client/src/app/App.jsx index 7edbe5f6..65a91575 100644 --- a/src/client/src/app/App.jsx +++ b/src/client/src/app/App.jsx @@ -53,8 +53,11 @@ export default class App extends React.Component { } + var pluginRoutes = UniversalDashboard.provideRoutes(); + return (
+ {pluginRoutes}
) diff --git a/src/client/src/app/services/fetch-service.jsx b/src/client/src/app/services/fetch-service.jsx index b5c8bb99..a607db32 100644 --- a/src/client/src/app/services/fetch-service.jsx +++ b/src/client/src/app/services/fetch-service.jsx @@ -5,10 +5,9 @@ export const fetchGet = function(url, success, history) { credentials: 'include' }) .then(function(response){ - if (response.status === 401 && history) { - history.push("/login"); - throw new Error('Redirecting to login'); - } else if (response.status === 200) { + UniversalDashboard.invokeMiddleware('GET', url, history, response); + + if (response.status === 200) { response.text().then(text => { try { diff --git a/src/client/src/app/services/universal-dashboard-service.jsx b/src/client/src/app/services/universal-dashboard-service.jsx index 1496cd55..90db0c00 100644 --- a/src/client/src/app/services/universal-dashboard-service.jsx +++ b/src/client/src/app/services/universal-dashboard-service.jsx @@ -7,6 +7,10 @@ import toaster from './toaster'; export const UniversalDashboardService = { components: [], + plugins: [], + registerPlugin: function(plugin) { + this.plugins.push(plugin); + }, register: function(type, component) { var existingComponent = this.components.find(x => x.type === type); if (!existingComponent) this.components.push({ @@ -44,5 +48,56 @@ export const UniversalDashboardService = { } return internalRenderComponent(component, history); + }, + provideDashboardComponents: function(state) { + + var components = []; + + this.plugins.forEach(x => { + try + { + var pluginComponents = x.provideDashboardComponents(state); + + if (pluginComponents == null) { + return; + } + + if (Array.isArray(pluginComponents)) { + components = components.concat(pluginComponents); + } else { + components.push(pluginComponents); + } + } + catch + { + + } + }) + + return components; + }, + provideRoutes: function() { + return this.plugins.forEach(x => { + try + { + return x.provideRoutes(); + } + catch + { + + } + }) + }, + invokeMiddleware: function(method, url, history, response) { + this.plugins.forEach(x => { + try + { + x.invokeMiddleware(method, url, history, response); + } + catch + { + + } + }) } } \ No newline at end of file diff --git a/src/client/src/app/ud-dashboard.jsx b/src/client/src/app/ud-dashboard.jsx index 8428a7e0..003cff3f 100644 --- a/src/client/src/app/ud-dashboard.jsx +++ b/src/client/src/app/ud-dashboard.jsx @@ -325,6 +325,8 @@ export default class UdDashboard extends React.Component { )} /> }) + var pluginComponents = UniversalDashboard.provideDashboardComponents(this.state); + return [
}> - }.bind(this)}/> + }.bind(this)} + />, + pluginComponents ] } } \ No newline at end of file