-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #242 from NakulManchanda/activity-storage-event
login activity, storage event changes
- Loading branch information
Showing
5 changed files
with
246 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
virtual-desktop/src/app/authentication-manager/idleWarn.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import * as moment from 'moment'; | ||
import { Injectable } from '@angular/core'; | ||
import { ZluxPopupManagerService, ZluxErrorSeverity } from '@zlux/widgets'; | ||
import { TranslationService } from 'angular-l10n'; | ||
import { BaseLogger } from 'virtual-desktop-logger'; | ||
import { Subscription } from 'rxjs/Subscription'; | ||
import { StorageService } from './storage.service'; | ||
|
||
@Injectable() | ||
export class IdleWarnService { | ||
|
||
private report: any; | ||
private readonly logger: ZLUX.ComponentLogger = BaseLogger; | ||
|
||
constructor(private popupManager: ZluxPopupManagerService, | ||
public translation: TranslationService, | ||
private storageService: StorageService | ||
) { | ||
} | ||
|
||
public createRetryErrorReport(renewSession: any, isIdle: any) { | ||
this.removeErrorReport(); | ||
this.report = this.popupManager.createErrorReport( | ||
ZluxErrorSeverity.WARNING, | ||
this.translation.translate('Session Renewal Error'), | ||
this.translation.translate('Session could not be renewed. Logout will occur unless renewed. Click here to retry.'), | ||
{ | ||
blocking: false, | ||
buttons: [this.translation.translate('Retry'), this.translation.translate('Dismiss')] | ||
} | ||
); | ||
|
||
this.report.subscription = new Subscription(); | ||
this.onUserActionSubscribe(renewSession,'Retry'); | ||
this.onActivitySubscribe(renewSession, isIdle); | ||
} | ||
|
||
onUserActionSubscribe(renewSession: any, action: string) { | ||
if(this.report) { | ||
this.report.subscription.add(this.report.subject.subscribe((buttonName:any)=> { | ||
if (buttonName == this.translation.translate(action)) { | ||
renewSession(); | ||
} | ||
})); | ||
} | ||
} | ||
|
||
public createContinueErrorReport(renewSession: any, isIdle: any, expirationInMS: number, desktopSize: any) { | ||
this.removeErrorReport(); | ||
let popupStyle; | ||
|
||
/* According to the size of the desktop, we move the expiration prompt to align with the app bar */ | ||
switch (desktopSize) { | ||
case 3: { | ||
popupStyle = { | ||
'margin-bottom': '70px', | ||
'margin-right': '-5px' | ||
}; | ||
break; | ||
} | ||
case 1: { | ||
popupStyle = { | ||
'margin-bottom': '15px', | ||
'margin-right': '-10px' | ||
}; | ||
break; | ||
} | ||
default: { | ||
popupStyle = { | ||
'margin-bottom': '35px', | ||
'margin-right': '-5px' | ||
}; | ||
break; | ||
} | ||
} | ||
|
||
this.report = this.popupManager.createErrorReport( | ||
ZluxErrorSeverity.WARNING, | ||
this.translation.translate('Session Expiring Soon'), | ||
//TODO: Add translation | ||
//this.translation.translate('You will be logged out at ', { expirationInMS: moment().add(expirationInMS/1000, 'seconds').format('LT') }), | ||
this.translation.translate('You will be logged out at ' + moment().add(expirationInMS/1000, 'seconds').format('LT')), | ||
{ | ||
blocking: false, | ||
buttons: [this.translation.translate('Continue session')], | ||
timestamp: false, | ||
theme: "dark", | ||
style: popupStyle, | ||
callToAction: true | ||
}); | ||
|
||
this.report.subscription = new Subscription(); | ||
this.onUserActionSubscribe(renewSession, 'Continue session'); | ||
this.onActivitySubscribe(renewSession, isIdle); | ||
} | ||
|
||
|
||
onActivitySubscribe(renewSession: any, isIdle: any) { | ||
if(this.report) { | ||
this.report.subscription.add(this.storageService.lastActive.subscribe(()=> { | ||
if (!isIdle()) { | ||
this.logger.info('ZWED5047I', 'renew on activity'); /*this.logger.info('Near session expiration, but renewing session due to activity');*/ | ||
renewSession(); | ||
this.removeErrorReport(); | ||
} | ||
})); | ||
} | ||
} | ||
|
||
removeErrorReport() { | ||
if (this.report) { | ||
this.popupManager.removeReport(this.report.id); | ||
this.report.subscription.unsubscribe(); | ||
this.report = undefined; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
virtual-desktop/src/app/authentication-manager/storage-enum.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
|
||
/* | ||
This program and the accompanying materials are | ||
made available under the terms of the Eclipse Public License v2.0 which accompanies | ||
this distribution, and is available at https://www.eclipse.org/legal/epl-v20.html | ||
SPDX-License-Identifier: EPL-2.0 | ||
Copyright Contributors to the Zowe Project. | ||
*/ | ||
|
||
export const enum StorageKey { | ||
LAST_ACTIVE = 'ZoweZLUX.lastActive', | ||
I18_NEXT_LANG = 'i18nextLng', | ||
USERNAME = 'username' | ||
}; | ||
|
||
|
||
/* | ||
This program and the accompanying materials are | ||
made available under the terms of the Eclipse Public License v2.0 which accompanies | ||
this distribution, and is available at https://www.eclipse.org/legal/epl-v20.html | ||
SPDX-License-Identifier: EPL-2.0 | ||
Copyright Contributors to the Zowe Project. | ||
*/ | ||
|
Oops, something went wrong.