49 lines
1.7 KiB
JavaScript
49 lines
1.7 KiB
JavaScript
|
import {module} from './module';
|
||
|
import splitingRegister from './splitingRegister';
|
||
|
|
||
|
factory.$inject = ['$translatePartialLoader', '$http', '$window', '$ocLazyLoad', '$q', '$translate'];
|
||
|
export function factory($translatePartialLoader, $http, $window, $ocLazyLoad, $q, $translate) {
|
||
|
class ModuleLoader {
|
||
|
constructor() {
|
||
|
this._loadedModules = {};
|
||
|
}
|
||
|
load(moduleName) {
|
||
|
if(this._loadedModules[moduleName])
|
||
|
return;
|
||
|
|
||
|
this._loadedModules[moduleName] = true;
|
||
|
|
||
|
let deps = splitingRegister.getDependencies(moduleName);
|
||
|
let modules = splitingRegister.modules;
|
||
|
let promises = [];
|
||
|
|
||
|
for(let dep of deps) {
|
||
|
this._loadedModules[dep] = true;
|
||
|
promises.push(modules[dep]());
|
||
|
promises.push(new Promise(resolve => {
|
||
|
$http.get(`/${dep}/validations`).then((json) => {
|
||
|
Object.assign($window.validations, json.data);
|
||
|
resolve();
|
||
|
});
|
||
|
}));
|
||
|
|
||
|
$translatePartialLoader.addPart(dep);
|
||
|
// FIXME: https://github.com/angular-translate/angular-translate/pull/1674
|
||
|
//promises.push($translate.refresh());
|
||
|
setTimeout (() => $translate.refresh(), 500);
|
||
|
}
|
||
|
|
||
|
let ocDeps = deps.map(item => { return { name: item } });
|
||
|
|
||
|
return new Promise (resolve => {
|
||
|
Promise.all(promises).then(
|
||
|
() => resolve($ocLazyLoad.load(ocDeps))
|
||
|
)
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return new ModuleLoader();
|
||
|
};
|
||
|
module.factory('vnModuleLoader', factory);
|