-
-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathcontextual-menu.component.ts
More file actions
181 lines (152 loc) · 7.06 KB
/
Copy pathcontextual-menu.component.ts
File metadata and controls
181 lines (152 loc) · 7.06 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
import { Component, OnDestroy, OnInit, ViewChild } from "@angular/core";
import { Session } from "@noovolari/leapp-core/models/session";
import { AppService } from "../../services/app.service";
import { MatMenuTrigger } from "@angular/material/menu";
import { AppProviderService } from "../../services/app-provider.service";
import { SessionSelectionState } from "@noovolari/leapp-core/models/session-selection-state";
import { SessionType } from "@noovolari/leapp-core/models/session-type";
import { SessionStatus } from "@noovolari/leapp-core/models/session-status";
import { constants } from "@noovolari/leapp-core/models/constants";
import { OptionsService } from "../../services/options.service";
import { AwsCredentialsPlugin } from "@noovolari/leapp-core/plugin-sdk/aws-credentials-plugin";
import { SelectedSessionActionsService } from "../../services/selected-session-actions.service";
import { ExtensionWebsocketService, FetchingState } from "../../services/extension-websocket.service";
import { Subscription } from "rxjs";
import { AnalyticsService } from "../../services/analytics.service";
import { AwsSsoRoleSession } from "@noovolari/leapp-core/models/aws/aws-sso-role-session";
import { Role } from "../../services/team-service";
@Component({
selector: "app-contextual-menu",
templateUrl: "./contextual-menu.component.html",
styleUrls: ["./contextual-menu.component.scss"],
})
export class ContextualMenuComponent implements OnInit, OnDestroy {
@ViewChild("menuTrigger", { static: false })
public trigger!: MatMenuTrigger;
public eConstants = constants;
public eSessionStatus = SessionStatus;
public eSessionType = SessionType;
public selectedSession: Session;
public menuX: number;
public menuY: number;
public isWebConsoleFetching: boolean;
private sessionSelectionsSubscription: Subscription;
private fetchingSubscription: Subscription;
constructor(
public appService: AppService,
public optionsService: OptionsService,
public appProviderService: AppProviderService,
private selectedSessionActionsService: SelectedSessionActionsService,
private extensionWebsocketService: ExtensionWebsocketService,
private readonly analyticsService: AnalyticsService
) {}
get isLeappTeamUser(): boolean {
const localWorkspace = this.appProviderService.teamService.workspacesState
.getValue()
.find((workspace) => workspace.name === constants.localWorkspaceName);
return (
(this.appProviderService.teamService.signedInUserState?.getValue()?.role === Role.manager ||
this.appProviderService.teamService.signedInUserState?.getValue()?.role === Role.user) &&
localWorkspace.selected === false
);
}
ngOnInit(): void {
this.sessionSelectionsSubscription = this.appProviderService.behaviouralSubjectService.sessionSelections$.subscribe(
(sessionSelections: SessionSelectionState[]) => {
if (sessionSelections.length === 0) {
return;
}
this.appService.closeAllMenuTriggers();
this.selectedSession = this.appProviderService.repository.getSessionById(sessionSelections[0].sessionId);
this.menuY = sessionSelections[0].menuY;
this.menuX = sessionSelections[0].menuX;
if (sessionSelections[0].isContextualMenuOpen) {
setTimeout(() => {
if (this.trigger) {
this.trigger.openMenu();
this.appService.setMenuTrigger(this.trigger);
}
}, 100);
}
}
);
this.fetchingSubscription = this.extensionWebsocketService.fetching$.subscribe((value) => {
this.isWebConsoleFetching = value !== FetchingState.notFetching;
});
}
ngOnDestroy(): void {
this.sessionSelectionsSubscription?.unsubscribe();
this.fetchingSubscription?.unsubscribe();
}
async startSession(): Promise<void> {
const integrationId = (this.selectedSession as AwsSsoRoleSession).awsSsoConfigurationId;
const integration = this.appProviderService.awsSsoIntegrationService.getIntegration(integrationId);
await this.selectedSessionActionsService.startSession(this.selectedSession);
if (this.selectedSession.type === SessionType.awsSsoRole && this.selectedSession.status === SessionStatus.active && !integration.isOnline) {
await this.analyticsService.captureEvent("Integration Login", {
integrationId: (this.selectedSession as AwsSsoRoleSession).awsSsoConfigurationId,
integrationType: "AWS SSO",
startedAt: new Date().toISOString(),
});
}
}
async stopSession(): Promise<void> {
await this.selectedSessionActionsService.stopSession(this.selectedSession);
}
logoutFromFederatedSession(): void {
this.selectedSessionActionsService.logoutFromFederatedSession(this.selectedSession);
}
createAChainedSessionFromSelectedOne(): void {
this.selectedSessionActionsService.createAChainedSessionFromSelectedOne(this.selectedSession);
}
async ssmModalOpen(): Promise<void> {
await this.selectedSessionActionsService.ssmModalOpen(this.selectedSession);
}
async openAwsWebConsole(): Promise<void> {
if (this.optionsService.extensionEnabled) {
await this.extensionWebsocketService.openWebConsoleWithExtension(this.selectedSession);
} else {
await this.selectedSessionActionsService.openAwsWebConsole(this.selectedSession);
}
await this.analyticsService.captureEvent("Web Console opened", {
withExtension: this.optionsService.extensionEnabled,
sessionType: this.selectedSession.type,
sessionId: this.selectedSession.sessionId,
startedAt: new Date().toISOString(),
});
}
async editSession(): Promise<void> {
await this.selectedSessionActionsService.editCurrentSession(this.selectedSession);
}
async pinSession(): Promise<void> {
await this.selectedSessionActionsService.pinSession(this.selectedSession);
}
async unpinSession(): Promise<void> {
await this.selectedSessionActionsService.unpinSession(this.selectedSession);
}
async deleteSession(): Promise<void> {
await this.selectedSessionActionsService.deleteSession(this.selectedSession);
}
async changeRegionModalOpen(): Promise<void> {
await this.selectedSessionActionsService.changeRegionModalOpen(this.selectedSession);
}
async changeProfileModalOpen(): Promise<void> {
await this.selectedSessionActionsService.changeProfileModalOpen(this.selectedSession);
}
async changeColorModalOpen(): Promise<void> {
await this.selectedSessionActionsService.changeColorModalOpen(this.selectedSession);
}
async copyCredentials(type: number): Promise<void> {
await this.selectedSessionActionsService.copyCredentials(this.selectedSession, type);
}
async copyAwsWebConsoleUrl(): Promise<void> {
await this.selectedSessionActionsService.copyAwsWebConsoleUrl(this.selectedSession);
}
async applyPluginAction(plugin: AwsCredentialsPlugin): Promise<void> {
await this.selectedSessionActionsService.applyPluginAction(this.selectedSession, plugin);
await this.analyticsService.captureEvent("Plugin started", {
pluginName: plugin.metadata.uniqueName,
startedAt: new Date().toISOString(),
});
}
}