Browse Source

Load either configuration payload or file

Raanan Weber 7 năm trước cách đây
mục cha
commit
1370b12a4f
1 tập tin đã thay đổi với 20 bổ sung13 xóa
  1. 20 13
      Viewer/src/configuration/loader.ts

+ 20 - 13
Viewer/src/configuration/loader.ts

@@ -23,20 +23,27 @@ export class ConfigurationLoader {
         if (loadedConfig.configuration) {
         if (loadedConfig.configuration) {
 
 
             let mapperType = "json";
             let mapperType = "json";
-            let url = loadedConfig.configuration;
-
-            // if configuration is an object
-            if (loadedConfig.configuration.url) {
-                url = loadedConfig.configuration.url;
-                mapperType = loadedConfig.configuration.mapper;
-                if (!mapperType) {
-                    // load mapper type from filename / url
-                    mapperType = loadedConfig.configuration.url.split('.').pop();
+            return Promise.resolve().then(() => {
+                if (typeof loadedConfig.configuration === "string" || loadedConfig.configuration.url) {
+                    // a file to load
+                    let url = loadedConfig.configuration;
+
+                    // if configuration is an object
+                    if (loadedConfig.configuration.url) {
+                        url = loadedConfig.configuration.url;
+                        mapperType = loadedConfig.configuration.mapper;
+                        if (!mapperType) {
+                            // load mapper type from filename / url
+                            mapperType = loadedConfig.configuration.url.split('.').pop();
+                        }
+                    }
+                    return this.loadFile(url);
+                } else {
+                    mapperType = loadedConfig.configuration.mapper || mapperType;
+                    return loadedConfig.configuration.payload || {};
                 }
                 }
-            }
-
-            let mapper = mapperManager.getMapper(mapperType);
-            return this.loadFile(url).then((data: any) => {
+            }).then((data: any) => {
+                let mapper = mapperManager.getMapper(mapperType);
                 let parsed = mapper.map(data);
                 let parsed = mapper.map(data);
                 return deepmerge(loadedConfig, parsed);
                 return deepmerge(loadedConfig, parsed);
             });
             });