-
Notifications
You must be signed in to change notification settings - Fork 195
Expand file tree
/
Copy pathsetting.component.ts
More file actions
149 lines (134 loc) · 4.55 KB
/
Copy pathsetting.component.ts
File metadata and controls
149 lines (134 loc) · 4.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
import _ from 'lodash-es';
import xtermTheme from 'xterm-theme';
import { Subscription } from 'rxjs';
import { I18nService } from '@app/services/i18n';
import { GlobalSetting, Setting } from '@app/model';
import { NZ_MODAL_DATA } from 'ng-zorro-antd/modal';
import { NzMessageService } from 'ng-zorro-antd/message';
import { HttpService, IframeCommunicationService, SettingService } from '@app/services';
import { Component, Inject, OnInit, OnDestroy, ViewChild } from '@angular/core';
import { NzSelectComponent } from 'ng-zorro-antd/select';
import { withSitePrefix } from '@app/utils/path';
interface terminalThemeMap {
label: string;
value: string;
}
@Component({
standalone: false,
selector: 'elements-setting',
templateUrl: 'setting.component.html',
styleUrls: ['setting.component.scss']
})
export class ElementSettingComponent implements OnInit, OnDestroy {
@ViewChild('nzSel', { static: false }) nzSel!: NzSelectComponent;
public boolChoices: any[];
public name: string;
public type: string = 'general';
keyboardLayoutOptions: any[];
resolutionsOptions: any[];
rdpSmartSizeOptions: any[];
colorQualityOptions: any[];
setting: Setting = new Setting();
globalSetting: GlobalSetting;
rdpClientConfig = {
full_screen: false,
multi_screen: false,
drives_redirect: false,
remote_microphone: false
};
currentTheme = '';
terminalThemeMap: terminalThemeMap[] = [];
messageSubscription: Subscription;
constructor(
@Inject(NZ_MODAL_DATA) public data: any,
private _i18n: I18nService,
private _http: HttpService,
private settingSrv: SettingService,
private _message: NzMessageService,
private _iframeSvc: IframeCommunicationService
) {
this.boolChoices = [
{ name: _i18n.instant('Yes'), value: true },
{ name: _i18n.instant('No'), value: false }
];
this.name = data.name || this.name;
this.type = data.type || this.type;
}
hasLicense() {
return this.settingSrv.globalSetting.XPACK_LICENSE_IS_VALID;
}
async ngOnInit() {
this.generateTerminalThemeMap();
await this.getSettingOptions();
this.setting = this.settingSrv.setting;
this.getRdpClientConfig();
this.globalSetting = this.settingSrv.globalSetting;
this.currentTheme = this.setting.command_line.terminal_theme_name;
}
ngOnDestroy() {
if (this.messageSubscription) {
this.messageSubscription.unsubscribe();
}
}
generateTerminalThemeMap() {
this.terminalThemeMap = [
{ label: 'Default', value: 'Default' },
...Object.keys(xtermTheme).map(item => ({ label: item, value: item }))
];
}
async getSettingOptions() {
const url = withSitePrefix('/api/v1/users/preference/?category=luna');
const res: any = await this._http.options(url).toPromise();
const graphics = res.actions.GET.graphics.children;
this.resolutionsOptions = graphics.rdp_resolution.choices;
this.rdpSmartSizeOptions = graphics.rdp_smart_size.choices;
this.colorQualityOptions = graphics.rdp_color_quality.choices;
this.keyboardLayoutOptions = graphics.keyboard_layout.choices;
}
getRdpClientConfig() {
const rdpClientConfig = this.setting.graphics.rdp_client_option || [];
for (const i of rdpClientConfig) {
this.rdpClientConfig[i] = true;
}
}
setRdpClientConfig() {
let rdpClientConfig = this.setting.graphics.rdp_client_option || [];
for (const i in this.rdpClientConfig) {
if (this.rdpClientConfig[i]) {
rdpClientConfig.push(i);
} else {
rdpClientConfig = _.pull(rdpClientConfig, i);
}
}
this.setting.graphics.rdp_client_option = _.uniq(rdpClientConfig);
}
onSubmit() {
this.setRdpClientConfig();
this.settingSrv.save();
}
onThemePreview(event: KeyboardEvent) {
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
// 延迟一个 tick,等待内部 overlay 弹出并高亮变更
setTimeout(() => {
const activatedValue = (this.nzSel as any).activatedValue;
this.onThemeChange(activatedValue);
}, 100);
}
}
onThemeChange(theme: string) {
this.currentTheme = theme;
this.setting.command_line.terminal_theme_name = theme;
this.changeTheme(theme);
this._http.setTerminalPreference({ command_line: { terminal_theme_name: theme } }).subscribe({
next: _res => {
console.log('Theme saved successfully:', theme);
},
error: error => {
console.error('Failed to set theme preference:', error);
}
});
}
changeTheme(theme: string) {
this._iframeSvc.sendMessage({ name: 'TERMINAL_THEME_CHANGE', theme });
}
}