2019-09-26 15:08:58 +02:00
|
|
|
import { Component } from '@angular/core';
|
2019-07-26 11:46:59 +02:00
|
|
|
import { Router } from '@angular/router';
|
2019-01-19 21:55:06 +01:00
|
|
|
|
2019-07-26 11:46:59 +02:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
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';
|
2019-07-26 11:46:59 +02:00
|
|
|
import { DataStoreUpgradeService } from './core/core-services/data-store-upgrade.service';
|
2019-02-26 11:38:29 +01:00
|
|
|
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-07-11 14:06:01 +02:00
|
|
|
import { OverlayService } from './core/ui-services/overlay.service';
|
2019-04-15 14:19:40 +02:00
|
|
|
import { PingService } from './core/core-services/ping.service';
|
2019-07-26 11:46:59 +02:00
|
|
|
import { PrioritizeService } from './core/core-services/prioritize.service';
|
|
|
|
import { RoutingStateService } from './core/ui-services/routing-state.service';
|
|
|
|
import { ServertimeService } from './core/core-services/servertime.service';
|
|
|
|
import { ThemeService } from './core/ui-services/theme.service';
|
2018-06-13 18:34:10 +02:00
|
|
|
|
2019-05-09 12:52:10 +02:00
|
|
|
declare global {
|
2019-07-11 14:06:01 +02:00
|
|
|
/**
|
|
|
|
* Enhance array with own functions
|
|
|
|
* TODO: Remove once flatMap made its way into official JS/TS (ES 2019?)
|
|
|
|
*/
|
2019-05-09 12:52:10 +02:00
|
|
|
interface Array<T> {
|
2019-07-26 11:46:59 +02:00
|
|
|
flatMap(o: any): any[];
|
2019-05-09 12:52:10 +02:00
|
|
|
}
|
2019-07-11 14:06:01 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Enhances the number object to calculate real modulo operations.
|
|
|
|
* (not remainder)
|
|
|
|
*/
|
|
|
|
interface Number {
|
|
|
|
modulo(n: number): number;
|
|
|
|
}
|
2019-05-09 12:52: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
|
|
|
servertimeService: ServertimeService,
|
2019-04-08 10:57:43 +02:00
|
|
|
router: Router,
|
2019-09-12 12:35:46 +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-09-12 12:35:46 +02:00
|
|
|
overlayService: OverlayService,
|
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,
|
2019-06-25 10:45:24 +02:00
|
|
|
pingService: PingService,
|
|
|
|
routingState: RoutingStateService
|
2018-08-23 15:28:57 +02:00
|
|
|
) {
|
2018-06-29 17:24:44 +02:00
|
|
|
// manually add the supported languages
|
2019-09-04 09:34:55 +02:00
|
|
|
translate.addLangs(['en', 'de', 'cs', 'ru']);
|
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');
|
2019-08-06 14:37:41 +02:00
|
|
|
|
2018-09-18 18:27:14 +02:00
|
|
|
// change default JS functions
|
|
|
|
this.overloadArrayToString();
|
2019-05-09 12:52:10 +02:00
|
|
|
this.overloadFlatMap();
|
2019-07-11 14:06:01 +02:00
|
|
|
this.overloadModulo();
|
|
|
|
|
2019-09-26 15:08:58 +02:00
|
|
|
servertimeService.startScheduler();
|
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
|
|
|
}
|
2019-05-27 17:58:43 +02:00
|
|
|
|
2019-05-09 12:52:10 +02:00
|
|
|
/**
|
|
|
|
* Adds an implementation of flatMap.
|
|
|
|
* TODO: Remove once flatMap made its way into official JS/TS (ES 2019?)
|
|
|
|
*/
|
|
|
|
private overloadFlatMap(): void {
|
|
|
|
const concat = (x: any, y: any) => x.concat(y);
|
|
|
|
const flatMap = (f: any, xs: any) => xs.map(f).reduce(concat, []);
|
|
|
|
Array.prototype.flatMap = function(f: any): any[] {
|
|
|
|
return flatMap(f, this);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-07-11 14:06:01 +02:00
|
|
|
/**
|
|
|
|
* Enhances the number object with a real modulo operation (not remainder).
|
|
|
|
* TODO: Remove this, if the remainder operation is changed to modulo.
|
|
|
|
*/
|
|
|
|
private overloadModulo(): void {
|
|
|
|
Number.prototype.modulo = function(n: number): number {
|
|
|
|
return ((this % n) + n) % n;
|
|
|
|
};
|
|
|
|
}
|
2018-06-13 18:34:10 +02:00
|
|
|
}
|