2018-09-20 13:03:51 +02:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { plugins } from '../../../plugins';
|
|
|
|
import { CommonAppConfig } from '../../site/common/common.config';
|
2018-11-07 08:43:48 +01:00
|
|
|
import { AppConfig, SearchableModelEntry, ModelEntry } from '../../site/base/app-config';
|
2018-09-20 13:03:51 +02:00
|
|
|
import { CollectionStringModelMapperService } from './collectionStringModelMapper.service';
|
|
|
|
import { MediafileAppConfig } from '../../site/mediafiles/mediafile.config';
|
|
|
|
import { MotionsAppConfig } from '../../site/motions/motions.config';
|
2018-09-18 15:51:57 +02:00
|
|
|
import { ConfigAppConfig } from '../../site/config/config.config';
|
2018-09-20 13:03:51 +02:00
|
|
|
import { AgendaAppConfig } from '../../site/agenda/agenda.config';
|
|
|
|
import { AssignmentsAppConfig } from '../../site/assignments/assignments.config';
|
|
|
|
import { UsersAppConfig } from '../../site/users/users.config';
|
2018-10-15 10:12:47 +02:00
|
|
|
import { TagAppConfig } from '../../site/tags/tag.config';
|
2018-09-20 13:03:51 +02:00
|
|
|
import { MainMenuService } from './main-menu.service';
|
2018-11-09 13:44:39 +01:00
|
|
|
import { HistoryAppConfig } from 'app/site/history/history.config';
|
2018-11-07 08:43:48 +01:00
|
|
|
import { SearchService } from './search.service';
|
|
|
|
import { isSearchable } from '../../shared/models/base/searchable';
|
2018-09-20 13:03:51 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A list of all app configurations of all delivered apps.
|
|
|
|
*/
|
|
|
|
const appConfigs: AppConfig[] = [
|
|
|
|
CommonAppConfig,
|
2018-09-18 15:51:57 +02:00
|
|
|
ConfigAppConfig,
|
2018-09-20 13:03:51 +02:00
|
|
|
AgendaAppConfig,
|
|
|
|
AssignmentsAppConfig,
|
|
|
|
MotionsAppConfig,
|
|
|
|
MediafileAppConfig,
|
2018-10-15 10:12:47 +02:00
|
|
|
TagAppConfig,
|
2018-11-09 13:44:39 +01:00
|
|
|
UsersAppConfig,
|
|
|
|
HistoryAppConfig
|
2018-09-20 13:03:51 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
2018-11-07 08:43:48 +01:00
|
|
|
* Handles loading of all apps during the bootup process.
|
2018-09-20 13:03:51 +02:00
|
|
|
*/
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class AppLoadService {
|
2018-11-07 08:43:48 +01:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
* @param modelMapper
|
|
|
|
* @param mainMenuService
|
|
|
|
* @param searchService
|
|
|
|
*/
|
2018-09-20 13:03:51 +02:00
|
|
|
public constructor(
|
|
|
|
private modelMapper: CollectionStringModelMapperService,
|
2018-11-07 08:43:48 +01:00
|
|
|
private mainMenuService: MainMenuService,
|
|
|
|
private searchService: SearchService
|
2018-09-20 13:03:51 +02:00
|
|
|
) {}
|
|
|
|
|
|
|
|
public async loadApps(): Promise<void> {
|
|
|
|
if (plugins.length) {
|
|
|
|
console.log('plugins: ', plugins);
|
|
|
|
}
|
|
|
|
/*for (const pluginName of plugins) {
|
|
|
|
const plugin = await import('../../../../../plugins/' + pluginName + '/' + pluginName);
|
|
|
|
plugin.main();
|
|
|
|
}*/
|
|
|
|
appConfigs.forEach((config: AppConfig) => {
|
|
|
|
if (config.models) {
|
|
|
|
config.models.forEach(entry => {
|
|
|
|
this.modelMapper.registerCollectionElement(entry.collectionString, entry.model);
|
2018-11-07 08:43:48 +01:00
|
|
|
if (this.isSearchableModelEntry(entry)) {
|
|
|
|
this.searchService.registerModel(entry.collectionString, entry.model, entry.searchOrder);
|
|
|
|
}
|
2018-09-20 13:03:51 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
if (config.mainMenuEntries) {
|
|
|
|
this.mainMenuService.registerEntries(config.mainMenuEntries);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-11-07 08:43:48 +01:00
|
|
|
|
|
|
|
private isSearchableModelEntry(entry: ModelEntry | SearchableModelEntry): entry is SearchableModelEntry {
|
|
|
|
if ((<SearchableModelEntry>entry).searchOrder !== undefined) {
|
|
|
|
// We need to double check, because Typescipt cannot check contructors. If typescript could differentiate
|
|
|
|
// between (ModelConstructor<BaseModel>) and (new (...args: any[]) => (BaseModel & Searchable)), we would not have
|
|
|
|
// to check if the result of the contructor (the model instance) is really a searchable.
|
|
|
|
if (!isSearchable(new entry.model())) {
|
2019-01-10 12:54:48 +01:00
|
|
|
throw Error(
|
|
|
|
`Wrong configuration for ${
|
|
|
|
entry.collectionString
|
|
|
|
}: you gave a searchOrder, but the model is not searchable.`
|
|
|
|
);
|
2018-11-07 08:43:48 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-20 13:03:51 +02:00
|
|
|
}
|