Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.10.1 #1044

Merged
merged 10 commits into from
Dec 29, 2023
4 changes: 4 additions & 0 deletions src/app/elements/asset-tree/asset-tree.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ tr:hover {
color: rgb(204, 204, 204);
width: 20px;
line-height: 30px;
&.fa-square-o {
font-weight: bold;
padding: 0 0 0 6px;
}
}

.tree-banner-icon:hover {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class ElementConnectMethodComponent implements OnInit {
if (this.account && !this.account.has_secret) {
const aliases = ['@USER', '@INPUT'];
// 同名账号、手动输入可以下载RDP文件
if (!aliases.includes(this.account.alias) || (!this.manualAuthInfo.secret || !this.manualAuthInfo.username)) {
if (!aliases.includes(this.account.alias) || (!this.manualAuthInfo.username)) {
return false;
}
}
Expand Down
40 changes: 13 additions & 27 deletions src/app/elements/content/content.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,32 +93,13 @@ export class ElementContentComponent implements OnInit, OnDestroy {
handleKeyDownTabChange() {
this.keyboardSubscription = fromEvent(window, 'keydown').subscribe((event: any) => {
if (event.altKey && (event.key === 'ArrowRight' || event.key === 'ArrowLeft') && this.viewList.length > 1) {
window.onblur = () => {
setTimeout(() => window.focus(), 100);
};
let nextViewId: any = 0;
let nextActiveView = null;
const viewIds = this.viewSrv.viewIds;
const currentViewIndex = viewIds.findIndex(i => i === this.viewSrv.currentView.id);
let key = '';
if (event.key === 'ArrowRight') {
if (currentViewIndex === viewIds.length - 1 && currentViewIndex !== 0) {
nextActiveView = this.viewList.find(i => i.id === viewIds[0]);
} else {
nextViewId = viewIds[currentViewIndex + 1];
nextActiveView = this.viewList.find(i => i.id === nextViewId);
}
}
if (event.key === 'ArrowLeft') {
if (currentViewIndex === 0) {
nextActiveView = this.viewList.find(i => i.id === viewIds[viewIds.length - 1]);
} else {
nextViewId = viewIds[currentViewIndex - 1];
nextActiveView = this.viewList.find(i => i.id === nextViewId);
}
}
if (nextActiveView) {
this.setViewActive(nextActiveView);
key = 'alt+right';
} else if (event.key === 'ArrowLeft') {
key = 'alt+left';
}
this.viewSrv.keyboardSwitchTab(key);
}
});
}
Expand Down Expand Up @@ -198,7 +179,6 @@ export class ElementContentComponent implements OnInit, OnDestroy {
if (list[i].protocol !== 'ssh' || list[i].connected !== true) {
continue;
}
list[i].termComp.sendCommand({'data': cmd});
const subViews = list[i].subViews;
if (subViews.length > 1) {
for (let j = 0; j < subViews.length; j++) {
Expand All @@ -207,6 +187,8 @@ export class ElementContentComponent implements OnInit, OnDestroy {
}
subViews[j].termComp.sendCommand({'data': cmd});
}
} else {
list[i].termComp.sendCommand({'data': cmd});
}
}

Expand Down Expand Up @@ -239,7 +221,9 @@ export class ElementContentComponent implements OnInit, OnDestroy {
title: 'Reconnect',
icon: 'fa-refresh',
callback: () => {
this.viewList[this.rIdx].termComp.reconnect();
const viewId = this.viewIds[this.rIdx];
const currentView = this.viewList.find(i => i.id === viewId);
currentView.termComp.reconnect();
}
},
{
Expand All @@ -258,7 +242,9 @@ export class ElementContentComponent implements OnInit, OnDestroy {
title: 'Close Current Tab',
icon: 'fa-close',
callback: () => {
this.closeView(this.viewList[this.rIdx]);
const viewId = this.viewIds[this.rIdx];
const currentView = this.viewList.find(i => i.id === viewId);
this.closeView(currentView);
}
},
{
Expand Down
10 changes: 8 additions & 2 deletions src/app/elements/iframe/iframe.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {AfterViewInit, Component, ElementRef, EventEmitter, Input, OnDestroy, OnInit, Output, ViewChild} from '@angular/core';
import {View} from '@app/model';
import {ConnectTokenService, HttpService, I18nService, LogService} from '@app/services';
import {ConnectTokenService, HttpService, I18nService, LogService, ViewService} from '@app/services';
import {MatDialog} from '@angular/material';
import {environment} from '@src/environments/environment';

@Component({
selector: 'elements-iframe',
templateUrl: './iframe.component.html',
Expand All @@ -28,6 +27,7 @@ export class ElementIframeComponent implements OnInit, AfterViewInit, OnDestroy
private _connectTokenSvc: ConnectTokenService,
private _http: HttpService,
private _dialog: MatDialog,
public viewSrv: ViewService,
) {
}

Expand Down Expand Up @@ -63,6 +63,12 @@ export class ElementIframeComponent implements OnInit, AfterViewInit, OnDestroy
case 'CLICK':
document.body.click();
break;
case 'KEYEVENT':
window.focus();
setTimeout(() => {
this.viewSrv.keyboardSwitchTab(msg.data);
}, 200);
break;
}
}.bind(this);
}
Expand Down
9 changes: 7 additions & 2 deletions src/app/pages/main/main.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Component, ElementRef, HostListener, OnInit, ViewChild} from '@angular/core';
import {DataStore, User} from '@app/globals';
import {DataStore, DEFAULT_ORG_ID, SYSTEM_ORG_ID, User} from '@app/globals';
import {IOutputData, SplitComponent} from 'angular-split';
import {LogService, SettingService, ViewService} from '@app/services';
import * as _ from 'lodash';
Expand All @@ -19,6 +19,7 @@ export class PageMainComponent implements OnInit {
showIframeHider = false;
showSubMenu: any = false;
menus: Array<object>;
isDirectNavigation: boolean;
settingLayoutSize = {
leftWidth: 20,
rightWidth: 80
Expand Down Expand Up @@ -87,6 +88,9 @@ export class PageMainComponent implements OnInit {

ngOnInit(): void {
console.log('main init');
this._settingSvc.isDirectNavigation$.subscribe((state) => {
this.isDirectNavigation = state;
});
this.menus = [
{
name: 'assets',
Expand Down Expand Up @@ -140,9 +144,10 @@ export class PageMainComponent implements OnInit {

@HostListener('window:beforeunload', ['$event'])
unloadNotification($event: any) {
if (!environment.production) {
if (!environment.production || this.isDirectNavigation) {
return;
}

const notInIframe = window.self === window.top;
const notInReplay = location.pathname.indexOf('/luna/replay') === -1;
const returnValue = !(notInIframe && notInReplay);
Expand Down
29 changes: 26 additions & 3 deletions src/app/services/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as CryptoJS from 'crypto-js';
import {getCookie, setCookie} from '@app/utils/common';
import {OrganizationService} from './organization';
import {I18nService} from '@app/services/i18n';
import {config} from 'rxjs';

declare function unescape(s: string): string;

Expand Down Expand Up @@ -103,6 +104,14 @@ export class AppService {
}, second * 1000);
}

isRenewalExpired(currentTimeStamp, sessionExpireTimestamp, renewalTime: number = 60 * 2) {
if (!sessionExpireTimestamp) {
return false;
}
const timeDifferenceInSeconds = currentTimeStamp - parseInt(sessionExpireTimestamp, 10);
return timeDifferenceInSeconds > renewalTime;
}

checkLogin() {
this._logger.debug('Check user auth');
if (!DataStore.Path) {
Expand All @@ -122,13 +131,27 @@ export class AppService {
const token = this.getQueryString('token');
// Determine whether the user has logged in
const sessionExpire = getCookie('jms_session_expire');
const renewalTime = 120;
if (!sessionExpire && !token) {
setCookie('jms_session_expire', 'close', 120);
setCookie('jms_session_expire', 'close', renewalTime);
gotoLogin();
return;
} else if (sessionExpire === 'close') {
setInterval(() => {
setCookie('jms_session_expire', sessionExpire, 120);
const intervalId = setInterval(() => {
const currentTimeStamp = Math.floor(new Date().getTime() / 1000);
const sessionExpireTimestamp = getCookie('jms_session_expire_timestamp');
if (!this.isRenewalExpired(currentTimeStamp, sessionExpireTimestamp, renewalTime)) {
setCookie('jms_session_expire', sessionExpire, renewalTime);
}
if (currentTimeStamp >= parseInt(sessionExpireTimestamp, 10)) {
confirm(this._i18n.instant('LoginExpireMsg'));
if (!this.newLoginHasOpen) {
this._settingSvc.isDirectNavigation$.next(true);
window.location.href = document.location.origin + '/core/auth/logout/';
this.newLoginHasOpen = true;
}
clearInterval(intervalId);
}
}, 10 * 1000);
}

Expand Down
1 change: 1 addition & 0 deletions src/app/services/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class SettingService {
public isLoadTreeAsync$ = new BehaviorSubject<boolean>(true);
public appletConnectMethod$ = new BehaviorSubject<string>('');
public keyboardLayout$ = new BehaviorSubject<string>('');
public isDirectNavigation$ = new BehaviorSubject<boolean>(false);


constructor(
Expand Down
27 changes: 26 additions & 1 deletion src/app/services/view.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {Injectable} from '@angular/core';
import {View} from '@app/model';


@Injectable()
export class ViewService {
viewList: Array<View> = [];
Expand Down Expand Up @@ -72,4 +71,30 @@ export class ViewService {
break;
}
}

keyboardSwitchTab(key) {
let nextViewId: any = 0;
let nextActiveView = null;
const viewIds = this.viewIds;
const currentViewIndex = viewIds.findIndex(i => i === this.currentView.id);
if (key === 'alt+right') {
if (currentViewIndex === viewIds.length - 1 && currentViewIndex !== 0) {
nextActiveView = this.viewList.find(i => i.id === viewIds[0]);
} else {
nextViewId = viewIds[currentViewIndex + 1];
nextActiveView = this.viewList.find(i => i.id === nextViewId);
}
}
if (key === 'alt+left') {
if (currentViewIndex === 0) {
nextActiveView = this.viewList.find(i => i.id === viewIds[viewIds.length - 1]);
} else {
nextViewId = viewIds[currentViewIndex - 1];
nextActiveView = this.viewList.find(i => i.id === nextViewId);
}
}
if (nextActiveView) {
this.activeView(nextActiveView);
}
}
}