mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-31 17:38:28 +00:00
[ACA] Dialogs - close on navigation by default (#634)
* close modals on navigation by default * lint * modals effect and action * add to store module * register in module * close modals if auth fails * rename action * change dialog selector
This commit is contained in:
committed by
Denys Vuika
parent
eb97b18f95
commit
2f4048a859
@@ -23,107 +23,125 @@
|
|||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { browser, element, by, ElementFinder, promise, ExpectedConditions as EC } from 'protractor';
|
import {
|
||||||
|
browser,
|
||||||
|
element,
|
||||||
|
by,
|
||||||
|
ElementFinder,
|
||||||
|
promise,
|
||||||
|
ExpectedConditions as EC
|
||||||
|
} from 'protractor';
|
||||||
import { BROWSER_WAIT_TIMEOUT } from './../configs';
|
import { BROWSER_WAIT_TIMEOUT } from './../configs';
|
||||||
|
|
||||||
export abstract class Page {
|
export abstract class Page {
|
||||||
private static USE_HASH_STRATEGY = true;
|
private static USE_HASH_STRATEGY = true;
|
||||||
|
|
||||||
private locators = {
|
private locators = {
|
||||||
app: by.css('app-root'),
|
app: by.css('app-root'),
|
||||||
layout: by.css('app-layout'),
|
layout: by.css('app-layout'),
|
||||||
overlay: by.css('.cdk-overlay-container'),
|
overlay: by.css('.cdk-overlay-container'),
|
||||||
dialogContainer: by.css('.mat-dialog-container[role]'),
|
dialogContainer: by.css('.mat-dialog-container'),
|
||||||
snackBarContainer: '.cdk-overlay-pane .mat-snack-bar-container',
|
snackBarContainer: '.cdk-overlay-pane .mat-snack-bar-container',
|
||||||
snackBar: '.mat-simple-snackbar',
|
snackBar: '.mat-simple-snackbar',
|
||||||
snackBarAction: '.mat-simple-snackbar-action button',
|
snackBarAction: '.mat-simple-snackbar-action button',
|
||||||
|
|
||||||
genericError: 'aca-generic-error',
|
genericError: 'aca-generic-error',
|
||||||
genericErrorIcon: 'aca-generic-error .mat-icon',
|
genericErrorIcon: 'aca-generic-error .mat-icon',
|
||||||
genericErrorTitle: '.generic-error__title'
|
genericErrorTitle: '.generic-error__title'
|
||||||
};
|
};
|
||||||
|
|
||||||
public app: ElementFinder = element(this.locators.app);
|
public app: ElementFinder = element(this.locators.app);
|
||||||
public layout: ElementFinder = element(this.locators.layout);
|
public layout: ElementFinder = element(this.locators.layout);
|
||||||
public overlay: ElementFinder = element(this.locators.overlay);
|
public overlay: ElementFinder = element(this.locators.overlay);
|
||||||
snackBar: ElementFinder = browser.$(this.locators.snackBar);
|
snackBar: ElementFinder = browser.$(this.locators.snackBar);
|
||||||
dialogContainer: ElementFinder = element(this.locators.dialogContainer);
|
dialogContainer: ElementFinder = element(this.locators.dialogContainer);
|
||||||
snackBarContainer: ElementFinder = browser.$(this.locators.snackBarContainer);
|
snackBarContainer: ElementFinder = browser.$(this.locators.snackBarContainer);
|
||||||
snackBarAction: ElementFinder = browser.$(this.locators.snackBarAction);
|
snackBarAction: ElementFinder = browser.$(this.locators.snackBarAction);
|
||||||
|
|
||||||
genericError: ElementFinder = browser.$(this.locators.genericError);
|
genericError: ElementFinder = browser.$(this.locators.genericError);
|
||||||
genericErrorIcon: ElementFinder = browser.$(this.locators.genericErrorIcon);
|
genericErrorIcon: ElementFinder = browser.$(this.locators.genericErrorIcon);
|
||||||
genericErrorTitle: ElementFinder = browser.$(this.locators.genericErrorTitle);
|
genericErrorTitle: ElementFinder = browser.$(this.locators.genericErrorTitle);
|
||||||
|
|
||||||
constructor(public url: string = '') {}
|
constructor(public url: string = '') {}
|
||||||
|
|
||||||
get title(): promise.Promise<string> {
|
get title(): promise.Promise<string> {
|
||||||
return browser.getTitle();
|
return browser.getTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
load(relativeUrl: string = ''): promise.Promise<void> {
|
load(relativeUrl: string = ''): promise.Promise<void> {
|
||||||
const hash = Page.USE_HASH_STRATEGY ? '/#' : '';
|
const hash = Page.USE_HASH_STRATEGY ? '/#' : '';
|
||||||
const path = `${hash}${this.url}${relativeUrl}`;
|
const path = `${hash}${this.url}${relativeUrl}`;
|
||||||
|
|
||||||
return browser.get(path);
|
return browser.get(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
waitForApp() {
|
waitForApp() {
|
||||||
return browser.wait(EC.presenceOf(this.layout), BROWSER_WAIT_TIMEOUT);
|
return browser.wait(EC.presenceOf(this.layout), BROWSER_WAIT_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
waitForSnackBarToAppear() {
|
waitForSnackBarToAppear() {
|
||||||
return browser.wait(EC.visibilityOf(this.snackBarContainer), BROWSER_WAIT_TIMEOUT);
|
return browser.wait(
|
||||||
}
|
EC.visibilityOf(this.snackBarContainer),
|
||||||
|
BROWSER_WAIT_TIMEOUT
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
waitForSnackBarToClose() {
|
waitForSnackBarToClose() {
|
||||||
return browser.wait(EC.not(EC.visibilityOf(this.snackBarContainer)), BROWSER_WAIT_TIMEOUT);
|
return browser.wait(
|
||||||
}
|
EC.not(EC.visibilityOf(this.snackBarContainer)),
|
||||||
|
BROWSER_WAIT_TIMEOUT
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
waitForDialog() {
|
waitForDialog() {
|
||||||
return browser.wait(EC.visibilityOf(this.dialogContainer), BROWSER_WAIT_TIMEOUT);
|
return browser.wait(
|
||||||
}
|
EC.visibilityOf(this.dialogContainer),
|
||||||
|
BROWSER_WAIT_TIMEOUT
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
waitForDialogToClose() {
|
waitForDialogToClose() {
|
||||||
return browser.wait(EC.not(EC.visibilityOf(this.dialogContainer)), BROWSER_WAIT_TIMEOUT);
|
return browser.wait(
|
||||||
}
|
EC.not(EC.visibilityOf(this.dialogContainer)),
|
||||||
|
BROWSER_WAIT_TIMEOUT
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
refresh(): promise.Promise<void> {
|
refresh(): promise.Promise<void> {
|
||||||
return browser.refresh();
|
return browser.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
getDialogActionByLabel(label) {
|
getDialogActionByLabel(label) {
|
||||||
return element(by.cssContainingText('.mat-button-wrapper', label));
|
return element(by.cssContainingText('.mat-button-wrapper', label));
|
||||||
}
|
}
|
||||||
|
|
||||||
isSnackBarDisplayed(): promise.Promise<boolean> {
|
isSnackBarDisplayed(): promise.Promise<boolean> {
|
||||||
return this.snackBar.isDisplayed();
|
return this.snackBar.isDisplayed();
|
||||||
}
|
}
|
||||||
|
|
||||||
getSnackBarMessage(): promise.Promise<string> {
|
getSnackBarMessage(): promise.Promise<string> {
|
||||||
return this.waitForSnackBarToAppear()
|
return this.waitForSnackBarToAppear().then(() =>
|
||||||
.then(() => this.snackBar.getAttribute('innerText'));
|
this.snackBar.getAttribute('innerText')
|
||||||
}
|
);
|
||||||
|
}
|
||||||
|
|
||||||
getSnackBarAction() {
|
getSnackBarAction() {
|
||||||
return this.waitForSnackBarToAppear()
|
return this.waitForSnackBarToAppear().then(() => this.snackBarAction);
|
||||||
.then(() => this.snackBarAction);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
clickSnackBarAction() {
|
clickSnackBarAction() {
|
||||||
return this.waitForSnackBarToAppear()
|
return this.waitForSnackBarToAppear().then(() => {
|
||||||
.then(() => {
|
return browser.executeScript(function(elem) {
|
||||||
return browser.executeScript(function (elem) {
|
elem.click();
|
||||||
elem.click();
|
}, this.snackBarAction);
|
||||||
}, this.snackBarAction);
|
});
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
|
||||||
isGenericErrorDisplayed() {
|
isGenericErrorDisplayed() {
|
||||||
return this.genericError.isDisplayed();
|
return this.genericError.isDisplayed();
|
||||||
}
|
}
|
||||||
|
|
||||||
getGenericErrorTitle() {
|
getGenericErrorTitle() {
|
||||||
return this.genericErrorTitle.getText();
|
return this.genericErrorTitle.getText();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -39,7 +39,8 @@ import {
|
|||||||
SetLanguagePickerAction,
|
SetLanguagePickerAction,
|
||||||
SnackbarErrorAction,
|
SnackbarErrorAction,
|
||||||
SetCurrentUrlAction,
|
SetCurrentUrlAction,
|
||||||
SetInitialStateAction
|
SetInitialStateAction,
|
||||||
|
CloseModalDialogsAction
|
||||||
} from './store/actions';
|
} from './store/actions';
|
||||||
import {
|
import {
|
||||||
AppStore,
|
AppStore,
|
||||||
@@ -47,7 +48,6 @@ import {
|
|||||||
INITIAL_APP_STATE
|
INITIAL_APP_STATE
|
||||||
} from './store/states/app.state';
|
} from './store/states/app.state';
|
||||||
import { filter } from 'rxjs/operators';
|
import { filter } from 'rxjs/operators';
|
||||||
import { MatDialog } from '@angular/material';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
@@ -64,8 +64,7 @@ export class AppComponent implements OnInit {
|
|||||||
private alfrescoApiService: AlfrescoApiService,
|
private alfrescoApiService: AlfrescoApiService,
|
||||||
private authenticationService: AuthenticationService,
|
private authenticationService: AuthenticationService,
|
||||||
private uploadService: UploadService,
|
private uploadService: UploadService,
|
||||||
private extensions: AppExtensionService,
|
private extensions: AppExtensionService
|
||||||
private dialogRef: MatDialog
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
@@ -76,9 +75,9 @@ export class AppComponent implements OnInit {
|
|||||||
provider: 'ECM',
|
provider: 'ECM',
|
||||||
url: this.router.url
|
url: this.router.url
|
||||||
});
|
});
|
||||||
this.router.navigate(['/login']);
|
|
||||||
|
|
||||||
this.dialogRef.closeAll();
|
this.store.dispatch(new CloseModalDialogsAction());
|
||||||
|
this.router.navigate(['/login']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -31,7 +31,8 @@ import {
|
|||||||
MatDialogModule,
|
MatDialogModule,
|
||||||
MatInputModule,
|
MatInputModule,
|
||||||
MatSnackBarModule,
|
MatSnackBarModule,
|
||||||
MatProgressBarModule
|
MatProgressBarModule,
|
||||||
|
MAT_DIALOG_DEFAULT_OPTIONS
|
||||||
} from '@angular/material';
|
} from '@angular/material';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
@@ -52,6 +53,12 @@ import {
|
|||||||
MatInputModule,
|
MatInputModule,
|
||||||
MatSnackBarModule,
|
MatSnackBarModule,
|
||||||
MatProgressBarModule
|
MatProgressBarModule
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: MAT_DIALOG_DEFAULT_OPTIONS,
|
||||||
|
useValue: { closeOnNavigation: true, hasBackdrop: true }
|
||||||
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class MaterialModule {}
|
export class MaterialModule {}
|
||||||
|
@@ -32,3 +32,4 @@ export * from './actions/viewer.actions';
|
|||||||
export * from './actions/search.actions';
|
export * from './actions/search.actions';
|
||||||
export * from './actions/library.actions';
|
export * from './actions/library.actions';
|
||||||
export * from './actions/upload.actions';
|
export * from './actions/upload.actions';
|
||||||
|
export * from './actions/modals.actions';
|
||||||
|
33
src/app/store/actions/modals.actions.ts
Normal file
33
src/app/store/actions/modals.actions.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Alfresco Example Content Application
|
||||||
|
*
|
||||||
|
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||||
|
*
|
||||||
|
* This file is part of the Alfresco Example Content Application.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Action } from '@ngrx/store';
|
||||||
|
|
||||||
|
export const CLOSE_MODAL_DIALOGS = 'CLOSE_MODAL_DIALOGS';
|
||||||
|
|
||||||
|
export class CloseModalDialogsAction implements Action {
|
||||||
|
readonly type = CLOSE_MODAL_DIALOGS;
|
||||||
|
constructor() {}
|
||||||
|
}
|
@@ -40,7 +40,8 @@ import {
|
|||||||
SearchEffects,
|
SearchEffects,
|
||||||
SiteEffects,
|
SiteEffects,
|
||||||
UploadEffects,
|
UploadEffects,
|
||||||
FavoriteEffects
|
FavoriteEffects,
|
||||||
|
ModalsEffects
|
||||||
} from './effects';
|
} from './effects';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
@@ -56,7 +57,8 @@ import {
|
|||||||
SearchEffects,
|
SearchEffects,
|
||||||
SiteEffects,
|
SiteEffects,
|
||||||
UploadEffects,
|
UploadEffects,
|
||||||
FavoriteEffects
|
FavoriteEffects,
|
||||||
|
ModalsEffects
|
||||||
]),
|
]),
|
||||||
!environment.production
|
!environment.production
|
||||||
? StoreDevtoolsModule.instrument({ maxAge: 25 })
|
? StoreDevtoolsModule.instrument({ maxAge: 25 })
|
||||||
|
@@ -32,3 +32,4 @@ export * from './effects/viewer.effects';
|
|||||||
export * from './effects/search.effects';
|
export * from './effects/search.effects';
|
||||||
export * from './effects/library.effects';
|
export * from './effects/library.effects';
|
||||||
export * from './effects/upload.effects';
|
export * from './effects/upload.effects';
|
||||||
|
export * from './effects/modals.effects';
|
||||||
|
41
src/app/store/effects/modals.effects.ts
Normal file
41
src/app/store/effects/modals.effects.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Alfresco Example Content Application
|
||||||
|
*
|
||||||
|
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||||
|
*
|
||||||
|
* This file is part of the Alfresco Example Content Application.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Effect, Actions, ofType } from '@ngrx/effects';
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { map } from 'rxjs/operators';
|
||||||
|
import { CloseModalDialogsAction, CLOSE_MODAL_DIALOGS } from '../actions';
|
||||||
|
import { MatDialog } from '@angular/material';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ModalsEffects {
|
||||||
|
constructor(private actions$: Actions, private matDialog: MatDialog) {}
|
||||||
|
|
||||||
|
@Effect({ dispatch: false })
|
||||||
|
closeAll$ = this.actions$.pipe(
|
||||||
|
ofType<CloseModalDialogsAction>(CLOSE_MODAL_DIALOGS),
|
||||||
|
map(() => this.matDialog.closeAll())
|
||||||
|
);
|
||||||
|
}
|
Reference in New Issue
Block a user