Skip to content
Snippets Groups Projects
Commit 84d90b1b authored by Xiao Gui's avatar Xiao Gui
Browse files

bugfix: failing single plugin manifest does not fail all

parent 87157bf6
No related branches found
No related tags found
No related merge requests found
import { Injectable, OnDestroy } from "@angular/core"; import { Injectable, OnDestroy } from "@angular/core";
import { Store, select } from "@ngrx/store"; import { Store } from "@ngrx/store";
import { ViewerStateInterface, FETCHED_TEMPLATE, DataEntry, FETCHED_DATAENTRIES, safeFilter, FETCHED_SPATIAL_DATA, UPDATE_SPATIAL_DATA } from "../services/stateStore.service"; import { ViewerStateInterface, FETCHED_TEMPLATE, FETCHED_SPATIAL_DATA, UPDATE_SPATIAL_DATA } from "../services/stateStore.service";
import { Subscription, combineLatest } from "rxjs"; import { Subscription } from "rxjs";
import { AtlasViewerConstantsServices } from "./atlasViewer.constantService.service"; import { AtlasViewerConstantsServices } from "./atlasViewer.constantService.service";
import { PluginManifest } from "./atlasViewer.pluginService.service";
/**
* TODO move constructor into else where and deprecate ASAP
*/
@Injectable({ @Injectable({
providedIn : 'root' providedIn : 'root'
...@@ -11,36 +14,6 @@ import { PluginManifest } from "./atlasViewer.pluginService.service"; ...@@ -11,36 +14,6 @@ import { PluginManifest } from "./atlasViewer.pluginService.service";
export class AtlasViewerDataService implements OnDestroy{ export class AtlasViewerDataService implements OnDestroy{
private subscriptions : Subscription[] = [] private subscriptions : Subscription[] = []
/**
* TODO ensure
*/
public promiseFetchedPluginManifests : Promise<PluginManifest[]> = new Promise((resolve,reject)=>{
Promise.all([
PLUGINDEV
? fetch(PLUGINDEV).then(res => res.json())
: Promise.resolve([]),
new Promise(resolve => {
fetch(`${this.constantService.backendUrl}plugins`)
.then(res => res.json())
.then(arr => Promise.all(
arr.map(url => fetch(url).then(res => res.json()))
))
.then(resolve)
.catch(e => {
resolve([])
})
}),
Promise.all(
BUNDLEDPLUGINS
.filter(v => typeof v === 'string')
.map(v => fetch(`res/plugin_examples/${v}/manifest.json`).then(res => res.json()))
)
.then(arr => arr.reduce((acc,curr) => acc.concat(curr) ,[]))
])
.then(arr => resolve( [].concat(arr[0]).concat(arr[1]) ))
.catch(reject)
})
constructor( constructor(
private store : Store<ViewerStateInterface>, private store : Store<ViewerStateInterface>,
......
import { Injectable, ViewContainerRef, ComponentFactoryResolver, ComponentFactory } from "@angular/core"; import { Injectable, ViewContainerRef, ComponentFactoryResolver, ComponentFactory } from "@angular/core";
import { AtlasViewerDataService } from "./atlasViewer.dataService.service";
import { PluginInitManifestInterface, ACTION_TYPES } from "src/services/state/pluginState.store"; import { PluginInitManifestInterface, ACTION_TYPES } from "src/services/state/pluginState.store";
import { isDefined } from 'src/services/stateStore.service' import { isDefined } from 'src/services/stateStore.service'
import { AtlasViewerAPIServices } from "./atlasViewer.apiService.service"; import { AtlasViewerAPIServices } from "./atlasViewer.apiService.service";
...@@ -11,6 +10,7 @@ import { interval } from "rxjs"; ...@@ -11,6 +10,7 @@ import { interval } from "rxjs";
import { take, takeUntil } from "rxjs/operators"; import { take, takeUntil } from "rxjs/operators";
import { Store } from "@ngrx/store"; import { Store } from "@ngrx/store";
import { WidgetUnit } from "./widgetUnit/widgetUnit.component"; import { WidgetUnit } from "./widgetUnit/widgetUnit.component";
import { AtlasViewerConstantsServices } from "./atlasViewer.constantService.service";
@Injectable({ @Injectable({
providedIn : 'root' providedIn : 'root'
...@@ -25,7 +25,7 @@ export class PluginServices{ ...@@ -25,7 +25,7 @@ export class PluginServices{
constructor( constructor(
private apiService : AtlasViewerAPIServices, private apiService : AtlasViewerAPIServices,
private atlasDataService : AtlasViewerDataService, private constantService : AtlasViewerConstantsServices,
private widgetService : WidgetServices, private widgetService : WidgetServices,
private cfr : ComponentFactoryResolver, private cfr : ComponentFactoryResolver,
private store : Store<PluginInitManifestInterface> private store : Store<PluginInitManifestInterface>
...@@ -34,8 +34,44 @@ export class PluginServices{ ...@@ -34,8 +34,44 @@ export class PluginServices{
this.pluginUnitFactory = this.cfr.resolveComponentFactory( PluginUnit ) this.pluginUnitFactory = this.cfr.resolveComponentFactory( PluginUnit )
this.apiService.interactiveViewer.uiHandle.launchNewWidget = this.launchNewWidget.bind(this) this.apiService.interactiveViewer.uiHandle.launchNewWidget = this.launchNewWidget.bind(this)
const promiseFetchedPluginManifests : Promise<PluginManifest[]> = new Promise((resolve, reject) => {
this.atlasDataService.promiseFetchedPluginManifests Promise.all([
/**
* PLUGINDEV should return an array of
*/
PLUGINDEV
? fetch(PLUGINDEV).then(res => res.json())
: Promise.resolve([]),
new Promise(resolve => {
fetch(`${this.constantService.backendUrl}plugins`)
.then(res => res.json())
.then(arr => Promise.all(
arr.map(url => new Promise(rs =>
/**
* instead of failing all promises when fetching manifests, only fail those that fails to fetch
*/
fetch(url).then(res => res.json()).then(rs).catch(e => (console.log('fetching manifest error', e), rs(null))))
)
))
.then(manifests => resolve(
manifests.filter(m => !!m)
))
.catch(e => {
resolve([])
})
}),
Promise.all(
BUNDLEDPLUGINS
.filter(v => typeof v === 'string')
.map(v => fetch(`res/plugin_examples/${v}/manifest.json`).then(res => res.json()))
)
.then(arr => arr.reduce((acc,curr) => acc.concat(curr) ,[]))
])
.then(arr => resolve( [].concat(arr[0]).concat(arr[1]) ))
.catch(reject)
})
promiseFetchedPluginManifests
.then(arr=> .then(arr=>
this.fetchedPluginManifests = arr) this.fetchedPluginManifests = arr)
.catch(console.error) .catch(console.error)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment