2019-03-06 07:38:43 +01:00
|
|
|
import { Component, ApplicationRef } from '@angular/core';
|
2018-06-29 17:24:44 +02:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2019-01-19 21:55:06 +01:00
|
|
|
|
2019-04-08 10:57:43 +02:00
|
|
|
import { take, filter, auditTime } from 'rxjs/operators';
|
2019-03-06 07:38:43 +01:00
|
|
|
|
2019-01-31 13:40:27 +01:00
|
|
|
import { ConfigService } from './core/ui-services/config.service';
|
2019-04-15 13:30:18 +02:00
|
|
|
import { ConstantsService } from './core/core-services/constants.service';
|
2019-02-26 11:38:29 +01:00
|
|
|
import { CountUsersService } from './core/ui-services/count-users.service';
|
|
|
|
import { LoadFontService } from './core/ui-services/load-font.service';
|
|
|
|
import { LoginDataService } from './core/ui-services/login-data.service';
|
|
|
|
import { OperatorService } from './core/core-services/operator.service';
|
2019-01-31 13:40:27 +01:00
|
|
|
import { ServertimeService } from './core/core-services/servertime.service';
|
|
|
|
import { ThemeService } from './core/ui-services/theme.service';
|
2019-04-15 13:30:18 +02:00
|
|
|
import { DataStoreUpgradeService } from './core/core-services/data-store-upgrade.service';
|
2019-04-15 14:19:40 +02:00
|
|
|
import { PrioritizeService } from './core/core-services/prioritize.service';
|
|
|
|
import { PingService } from './core/core-services/ping.service';
|
2019-04-08 10:57:43 +02:00
|
|
|
import { SpinnerService } from './core/ui-services/spinner.service';
|
|
|
|
import { Router } from '@angular/router';
|
2018-06-13 18:34:10 +02:00
|
|
|
|
2018-07-12 14:11:31 +02:00
|
|
|
/**
|
|
|
|
* Angular's global App Component
|
|
|
|
*/
|
2018-06-13 18:34:10 +02:00
|
|
|
@Component({
|
2018-09-03 17:57:20 +02:00
|
|
|
selector: 'os-root',
|
2018-06-19 16:55:50 +02:00
|
|
|
templateUrl: './app.component.html',
|
2018-08-28 09:33:50 +02:00
|
|
|
styleUrls: ['./app.component.scss']
|
2018-06-13 18:34:10 +02:00
|
|
|
})
|
2018-07-06 09:38:25 +02:00
|
|
|
export class AppComponent {
|
2018-08-28 11:07:10 +02:00
|
|
|
/**
|
2018-09-18 18:27:14 +02:00
|
|
|
* Master-component of all apps.
|
|
|
|
*
|
|
|
|
* Inits the translation service, the operator, the login data and the constants.
|
|
|
|
*
|
|
|
|
* Handles the altering of Array.toString()
|
|
|
|
*
|
2019-02-26 11:38:29 +01:00
|
|
|
* @param translate To set the default language
|
|
|
|
* @param operator To call the constructor of the OperatorService
|
|
|
|
* @param loginDataService to call the constructor of the LoginDataService
|
|
|
|
* @param constantService to call the constructor of the ConstantService
|
|
|
|
* @param servertimeService executes the scheduler early on
|
2019-01-29 15:20:00 +01:00
|
|
|
* @param themeService used to listen to theme-changes
|
2019-02-26 11:38:29 +01:00
|
|
|
* @param countUsersService to call the constructor of the CountUserService
|
|
|
|
* @param configService to call the constructor of the ConfigService
|
|
|
|
* @param loadFontService to call the constructor of the LoadFontService
|
2019-05-03 17:39:48 +02:00
|
|
|
* @param dataStoreUpgradeService
|
2018-07-12 14:11:31 +02:00
|
|
|
*/
|
2018-08-29 13:21:25 +02:00
|
|
|
public constructor(
|
|
|
|
translate: TranslateService,
|
2019-03-04 14:40:02 +01:00
|
|
|
appRef: ApplicationRef,
|
|
|
|
servertimeService: ServertimeService,
|
2019-04-08 10:57:43 +02:00
|
|
|
router: Router,
|
2018-09-13 14:40:04 +02:00
|
|
|
operator: OperatorService,
|
2018-09-10 08:15:31 +02:00
|
|
|
loginDataService: LoginDataService,
|
2019-01-24 16:25:50 +01:00
|
|
|
constantsService: ConstantsService, // Needs to be started, so it can register itself to the WebsocketService
|
2019-01-19 21:55:06 +01:00
|
|
|
themeService: ThemeService,
|
2019-04-08 10:57:43 +02:00
|
|
|
spinnerService: SpinnerService,
|
2019-02-26 11:38:29 +01:00
|
|
|
countUsersService: CountUsersService, // Needed to register itself.
|
|
|
|
configService: ConfigService,
|
2019-04-15 13:30:18 +02:00
|
|
|
loadFontService: LoadFontService,
|
2019-05-03 17:39:48 +02:00
|
|
|
dataStoreUpgradeService: DataStoreUpgradeService, // to start it.
|
2019-04-15 14:19:40 +02:00
|
|
|
prioritizeService: PrioritizeService,
|
|
|
|
pingService: PingService
|
2018-08-23 15:28:57 +02:00
|
|
|
) {
|
2018-06-29 17:24:44 +02:00
|
|
|
// manually add the supported languages
|
2018-11-06 16:57:36 +01:00
|
|
|
translate.addLangs(['en', 'de', 'cs']);
|
2018-06-29 17:24:44 +02:00
|
|
|
// this language will be used as a fallback when a translation isn't found in the current language
|
|
|
|
translate.setDefaultLang('en');
|
|
|
|
// get the browsers default language
|
|
|
|
const browserLang = translate.getBrowserLang();
|
|
|
|
// try to use the browser language if it is available. If not, uses english.
|
|
|
|
translate.use(translate.getLangs().includes(browserLang) ? browserLang : 'en');
|
2018-09-18 18:27:14 +02:00
|
|
|
// change default JS functions
|
|
|
|
this.overloadArrayToString();
|
2019-04-08 10:57:43 +02:00
|
|
|
// Show the spinner initial
|
|
|
|
spinnerService.setVisibility(true, translate.instant('Loading data. Please wait...'));
|
2019-03-06 07:38:43 +01:00
|
|
|
|
|
|
|
appRef.isStable
|
|
|
|
.pipe(
|
2019-04-08 10:57:43 +02:00
|
|
|
// take only the stable state
|
2019-03-06 07:38:43 +01:00
|
|
|
filter(s => s),
|
|
|
|
take(1)
|
|
|
|
)
|
2019-03-04 14:40:02 +01:00
|
|
|
.subscribe(() => servertimeService.startScheduler());
|
2019-04-08 10:57:43 +02:00
|
|
|
|
|
|
|
// Subscribe to hide the spinner if the application has changed.
|
|
|
|
appRef.isStable
|
|
|
|
.pipe(
|
|
|
|
filter(s => s),
|
|
|
|
auditTime(1000)
|
|
|
|
)
|
|
|
|
.pipe(take(2))
|
|
|
|
.subscribe(() => {
|
|
|
|
spinnerService.setVisibility(false);
|
|
|
|
});
|
2018-09-18 18:27:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to alter the normal Array.toString - function
|
|
|
|
*
|
|
|
|
* Will add a whitespace after a comma and shorten the output to
|
|
|
|
* three strings.
|
|
|
|
*
|
|
|
|
* TODO: There might be a better place for overloading functions than app.component
|
|
|
|
* TODO: Overloading can be extended to more functions.
|
|
|
|
*/
|
|
|
|
private overloadArrayToString(): void {
|
|
|
|
Array.prototype.toString = function(): string {
|
|
|
|
let string = '';
|
|
|
|
const iterations = Math.min(this.length, 3);
|
|
|
|
|
|
|
|
for (let i = 0; i <= iterations; i++) {
|
|
|
|
if (i < iterations) {
|
|
|
|
string += this[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i < iterations - 1) {
|
|
|
|
string += ', ';
|
|
|
|
} else if (i === iterations && this.length > iterations) {
|
|
|
|
string += ', ...';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return string;
|
|
|
|
};
|
2018-06-29 17:24:44 +02:00
|
|
|
}
|
2018-06-13 18:34:10 +02:00
|
|
|
}
|