From c32d6dc7ba8877a84fa2558c1708feeb93d1876a Mon Sep 17 00:00:00 2001 From: Adam Driscoll Date: Tue, 18 Jun 2019 08:28:12 -0600 Subject: [PATCH 1/2] Adding JS plugin support. --- .../Components/index.js | 14 ++++- .../Tests/button.tests.ps1 | 2 + src/client/src/app/App.jsx | 3 + src/client/src/app/services/fetch-service.jsx | 7 +-- .../services/universal-dashboard-service.jsx | 55 +++++++++++++++++++ src/client/src/app/ud-dashboard.jsx | 6 +- 6 files changed, 81 insertions(+), 6 deletions(-) diff --git a/src/UniversalDashboard.Materialize/Components/index.js b/src/UniversalDashboard.Materialize/Components/index.js index afc2888a..1c35f9b9 100644 --- a/src/UniversalDashboard.Materialize/Components/index.js +++ b/src/UniversalDashboard.Materialize/Components/index.js @@ -40,4 +40,16 @@ UniversalDashboard.register("ud-checkbox", UDCheckbox); UniversalDashboard.register("ud-collapsible", UDCollapsible); UniversalDashboard.register("ud-select", UDSelect); UniversalDashboard.register("ud-grid-layout", UDGridLayout); -UniversalDashboard.register("ud-fab", UDFab); \ No newline at end of file +UniversalDashboard.register("ud-fab", UDFab); + +UniversalDashboard.registerPlugin({ + provideDashboardComponents: function(state) { + console.log('provideDashboardComponents'); + }, + provideRoutes: function() { + console.log('provideRoutes'); + }, + invokeMiddleware: function(method, url, history, response) { + console.log('invokeMiddleware'); + } +}) \ No newline at end of file diff --git a/src/UniversalDashboard.Materialize/Tests/button.tests.ps1 b/src/UniversalDashboard.Materialize/Tests/button.tests.ps1 index 4c945b25..ac71132a 100644 --- a/src/UniversalDashboard.Materialize/Tests/button.tests.ps1 +++ b/src/UniversalDashboard.Materialize/Tests/button.tests.ps1 @@ -9,6 +9,8 @@ Describe "New-UDButton" { } } + Wait-Debugger + Context "Floating" { Set-TestDashboard { New-UDButton -Text "Click Me" -Id "button" -Floating 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 From e0d8475400e41bf9ef6028bff5252ad00ad359c5 Mon Sep 17 00:00:00 2001 From: Adam Driscoll Date: Tue, 18 Jun 2019 08:28:32 -0600 Subject: [PATCH 2/2] Undo changes. --- .../Components/index.js | 14 +------------- .../Tests/button.tests.ps1 | 2 -- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/src/UniversalDashboard.Materialize/Components/index.js b/src/UniversalDashboard.Materialize/Components/index.js index 1c35f9b9..afc2888a 100644 --- a/src/UniversalDashboard.Materialize/Components/index.js +++ b/src/UniversalDashboard.Materialize/Components/index.js @@ -40,16 +40,4 @@ UniversalDashboard.register("ud-checkbox", UDCheckbox); UniversalDashboard.register("ud-collapsible", UDCollapsible); UniversalDashboard.register("ud-select", UDSelect); UniversalDashboard.register("ud-grid-layout", UDGridLayout); -UniversalDashboard.register("ud-fab", UDFab); - -UniversalDashboard.registerPlugin({ - provideDashboardComponents: function(state) { - console.log('provideDashboardComponents'); - }, - provideRoutes: function() { - console.log('provideRoutes'); - }, - invokeMiddleware: function(method, url, history, response) { - console.log('invokeMiddleware'); - } -}) \ No newline at end of file +UniversalDashboard.register("ud-fab", UDFab); \ No newline at end of file diff --git a/src/UniversalDashboard.Materialize/Tests/button.tests.ps1 b/src/UniversalDashboard.Materialize/Tests/button.tests.ps1 index ac71132a..4c945b25 100644 --- a/src/UniversalDashboard.Materialize/Tests/button.tests.ps1 +++ b/src/UniversalDashboard.Materialize/Tests/button.tests.ps1 @@ -9,8 +9,6 @@ Describe "New-UDButton" { } } - Wait-Debugger - Context "Floating" { Set-TestDashboard { New-UDButton -Text "Click Me" -Id "button" -Floating