Skip to content

Commit

Permalink
Merge pull request #891 from ironmansoftware/add-js-plugin
Browse files Browse the repository at this point in the history
Add js plugin
  • Loading branch information
adamdriscoll authored Jun 18, 2019
2 parents 29b5311 + e0d8475 commit a0717dc
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/client/src/app/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ export default class App extends React.Component {
</div>
}

var pluginRoutes = UniversalDashboard.provideRoutes();

return (<Router>
<div className="ud-dashboard">
{pluginRoutes}
<Route path={regex} component={UdDashboard} />
</div>
</Router> )
Expand Down
7 changes: 3 additions & 4 deletions src/client/src/app/services/fetch-service.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
55 changes: 55 additions & 0 deletions src/client/src/app/services/universal-dashboard-service.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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
{

}
})
}
}
6 changes: 5 additions & 1 deletion src/client/src/app/ud-dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ export default class UdDashboard extends React.Component {
)} />
})

var pluginComponents = UniversalDashboard.provideDashboardComponents(this.state);

return [
<header>
<UdNavbar backgroundColor={this.state.dashboard.navBarColor}
Expand Down Expand Up @@ -356,7 +358,9 @@ export default class UdDashboard extends React.Component {
return <Suspense fallback={<div></div>}>
<UdPageCyclerComponent history={x.history} pages={this.state.dashboard.pages} cyclePages={this.state.dashboard.cyclePages && !this.state.pausePageCycle} cyclePagesInterval={this.state.dashboard.cyclePagesInterval} />
</Suspense>
}.bind(this)}/>
}.bind(this)}
/>,
pluginComponents
]
}
}

0 comments on commit a0717dc

Please sign in to comment.