-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.component.ts
More file actions
188 lines (163 loc) · 6.55 KB
/
app.component.ts
File metadata and controls
188 lines (163 loc) · 6.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import { NavigationService } from "./services/navigation.service";
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, HostListener, inject, OnInit } from "@angular/core";
import AppValues from "./common/app.values";
import { filter, map } from "rxjs/operators";
import { NavigationEnd, Router, RouterEvent } from "@angular/router";
import { DatasetAutocompleteItem, TypeNames } from "./interface/search.interface";
import { ModalService } from "./components/modal/modal.service";
import { BaseComponent } from "./common/base.component";
import ProjectLinks from "./project-links";
import { AccountFragment, AccountType } from "./api/kamu.graphql.interface";
import { MaybeNull } from "./common/app.types";
import _ from "lodash";
import { isMobileView, promiseWithCatch } from "./common/app.helpers";
import { AppConfigService } from "./app-config.service";
import { AppConfigFeatureFlags, LoginMethod } from "./app-config.model";
import { LoginService } from "./auth/login/login.service";
import { loadErrorMessages } from "@apollo/client/dev";
import { isDevMode } from "@angular/core";
import moment from "moment";
import { LoggedUserService } from "./auth/logged-user.service";
import packageFile from "../../package.json";
import { LocalStorageService } from "./services/local-storage.service";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
export const ALL_URLS_WITHOUT_HEADER: string[] = [ProjectLinks.URL_LOGIN, ProjectLinks.URL_GITHUB_CALLBACK];
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AppComponent extends BaseComponent implements OnInit {
public static readonly ANONYMOUS_ACCOUNT_INFO: AccountFragment = {
id: "",
accountName: "",
displayName: AppValues.DEFAULT_USER_DISPLAY_NAME,
accountType: AccountType.User,
isAdmin: false,
};
public static readonly DEFAULT_FEATURE_FLAGS: AppConfigFeatureFlags = {
enableLogout: true,
enableScheduling: true,
enableDatasetEnvVarsManagment: true,
};
public readonly APP_LOGO = `/${AppValues.APP_LOGO}`;
public isMobileView = false;
public isHeaderVisible = true;
public featureFlags: AppConfigFeatureFlags = AppComponent.DEFAULT_FEATURE_FLAGS;
public loggedAccount: AccountFragment = AppComponent.ANONYMOUS_ACCOUNT_INFO;
public loginMethods: LoginMethod[] = [];
@HostListener("window:resize")
public checkWindowSize(): void {
this.checkView();
}
private router = inject(Router);
private loginService = inject(LoginService);
private modalService = inject(ModalService);
private navigationService = inject(NavigationService);
private appConfigService = inject(AppConfigService);
private cdr = inject(ChangeDetectorRef);
private loggedUserService = inject(LoggedUserService);
private localStorageService = inject(LocalStorageService);
public ngOnInit(): void {
if (isDevMode()) {
loadErrorMessages();
}
this.outputAppVersion();
this.setMomentOptions();
this.readConfiguration();
this.checkView();
this.router.events
.pipe(
filter((event) => event instanceof NavigationEnd),
map((event) => event as RouterEvent),
)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((event: RouterEvent) => {
this.isHeaderVisible = this.shouldHeaderBeVisible(event.url);
});
this.loggedUserService.loggedInUserChanges
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((user: MaybeNull<AccountFragment>) => {
this.loggedAccount = user ? _.cloneDeep(user) : AppComponent.ANONYMOUS_ACCOUNT_INFO;
this.cdr.detectChanges();
});
this.initAdminSlideToggle();
}
private initAdminSlideToggle(): void {
const flag = this.localStorageService.adminPriveleges;
this.loggedUserService.emitAdminPrivelegesChanges(Boolean(flag));
}
private setMomentOptions(): void {
moment.relativeTimeThreshold("s", 59);
moment.relativeTimeThreshold("m", 59);
moment.relativeTimeThreshold("h", 23);
}
private readConfiguration(): void {
this.featureFlags = this.appConfigService.featureFlags;
this.loginMethods = this.loginService.loginMethods;
}
private checkView(): void {
this.isMobileView = isMobileView();
}
private shouldHeaderBeVisible(url: string): boolean {
return !ALL_URLS_WITHOUT_HEADER.some((item) => url.toLowerCase().includes(item));
}
private outputAppVersion(): void {
// eslint-disable-next-line no-console
console.info(`%c Kamu UI v${packageFile.version} `, "background-color: rgb(105, 228, 187); font-size: 18px;");
}
public onSelectedDataset(item: DatasetAutocompleteItem): void {
if (item.__typename === TypeNames.datasetType) {
this.navigationService.navigateToDatasetView({
accountName: item.dataset.owner.accountName,
datasetName: item.dataset.name,
});
} else {
this.navigationService.navigateToSearch(item.dataset.id);
}
}
public onOpenUserInfo(): void {
// Not implemented yet
}
public onLogin(): void {
this.localStorageService.setRedirectAfterLoginUrl(this.router.url);
this.navigationService.navigateToLogin();
}
public onLogout(): void {
this.loggedUserService.logout();
}
public onBilling(): void {
promiseWithCatch(
this.modalService.warning({
message: AppValues.UNIMPLEMENTED_MESSAGE,
yesButtonText: "Ok",
}),
);
}
public onAnalytics(): void {
promiseWithCatch(
this.modalService.warning({
message: AppValues.UNIMPLEMENTED_MESSAGE,
yesButtonText: "Ok",
}),
);
}
public onHelp(): void {
promiseWithCatch(
this.modalService.warning({
message: AppValues.UNIMPLEMENTED_MESSAGE,
yesButtonText: "Ok",
}),
);
}
public onDashboard(): void {
promiseWithCatch(
this.modalService.warning({
message: AppValues.UNIMPLEMENTED_MESSAGE,
yesButtonText: "Ok",
}),
);
//TODO: Implement AdminDashBoardComponent
// this.navigationService.navigateToAdminDashBoard();
}
}