[ADF-3384] Create automated tests for Version Component (#3631)

* fix version component restore and delete event

* version manager actions

* fix test

* fix unit test

* remove fdescribe

* fix tslint

* fix screenshot rewrite problem

* remove fdescribe

* multi instance try

* remove fdescribe

* try uncomment some test

* error page

* fix user preferences pagiantion

* search page test include

* fix type tslint e2e

* restore code

* default lang momentadapter

* fix test

* [ADF-3384] removed console log from test

* [ADF-3384] adding some fixes for tests and code

* [ADF-3384] fixed some test and code
This commit is contained in:
Eugenio Romano
2018-08-03 18:12:03 +01:00
committed by Eugenio Romano
parent 17074478e2
commit a12662e7e2
101 changed files with 2047 additions and 718 deletions

View File

@@ -27,8 +27,8 @@ import { MAT_DIALOG_DATA } from '@angular/material';
</mat-dialog-content>
<mat-dialog-actions>
<span class="spacer"></span>
<button mat-button [mat-dialog-close]="true">{{ yesLabel | translate }}</button>
<button mat-button color="primary" [mat-dialog-close]="false" cdkFocusInitial>{{ noLabel | translate }}</button>
<button id="adf-confirm-accept" mat-button [mat-dialog-close]="true">{{ yesLabel | translate }}</button>
<button id="adf-confirm-cancel" mat-button color="primary" [mat-dialog-close]="false" cdkFocusInitial>{{ noLabel | translate }}</button>
</mat-dialog-actions>
`,
styles: [`

View File

@@ -1,5 +1,6 @@
<div *ngIf="isDialogActive"
class="upload-dialog"
id="upload-dialog"
[class.upload-dialog--minimized]="isDialogMinimized"
[class.upload-dialog--position-left]="position === 'left'"
[class.upload-dialog--position-right]="position === 'right'">
@@ -45,8 +46,7 @@
</span>
</header>
<section
class="upload-dialog__info"
<section class="upload-dialog__info"
*ngIf="totalErrors">
{{
(totalErrors > 1
@@ -56,8 +56,7 @@
}}
</section>
<section
class="upload-dialog__content"
<section class="upload-dialog__content"
[class.upload-dialog--padding]="isConfirmation">
<adf-file-uploading-list
(error)="onError($event)"
@@ -86,10 +85,10 @@
</div>
</section>
<footer
class="upload-dialog__actions"
[class.upload-dialog--hide]="isConfirmation">
<footer class="upload-dialog__actions"
*ngIf="!isConfirmation">
<button
id="adf-upload-dialog-cancel-all"
color="primary"
mat-button
*ngIf="!uploadList.isUploadCompleted() && !uploadList.isUploadCancelled()"
@@ -98,6 +97,7 @@
</button>
<button
id="adf-upload-dialog-close"
*ngIf="uploadList.isUploadCompleted() || uploadList.isUploadCancelled()"
mat-button
color="primary"
@@ -106,10 +106,10 @@
</button>
</footer>
<footer
class="upload-dialog__actions"
[class.upload-dialog--hide]="!isConfirmation">
<footer class="upload-dialog__actions"
*ngIf="isConfirmation">
<button
id="adf-upload-dialog-cancel"
color="secondary"
mat-button
(click)="cancelAllUploads()">
@@ -117,6 +117,7 @@
</button>
<button
id="adf-upload-dialog-confirm"
mat-button
color="primary"
(click)="toggleConfirmation()">

View File

@@ -1,39 +1,40 @@
<mat-list class="adf-version-list" *ngIf="!isLoading; else loading_template">
<mat-list-item *ngFor="let version of versions; let idx = index">
<mat-icon mat-list-icon>insert_drive_file</mat-icon>
<h4 mat-line class="adf-version-list-item-name">{{version.entry.name}}</h4>
<h4 mat-line class="adf-version-list-item-name" [id]="'adf-version-list-item-name-' + version.entry.id" >{{version.entry.name}}</h4>
<p mat-line>
<span class="adf-version-list-item-version">{{version.entry.id}}</span> -
<span class="adf-version-list-item-date">{{version.entry.modifiedAt | date}}</span>
<span class="adf-version-list-item-version" [id]="'adf-version-list-item-version-' + version.entry.id" >{{version.entry.id}}</span> -
<span class="adf-version-list-item-date" [id]="'adf-version-list-item-date-' + version.entry.id" >{{version.entry.modifiedAt | date}}</span>
</p>
<p mat-line class="adf-version-list-item-comment" *ngIf="showComments">{{version.entry.versionComment}}</p>
<p mat-line [id]="'adf-version-list-item-comment-'+ version.entry.id" class="adf-version-list-item-comment"
*ngIf="showComments">{{version.entry.versionComment}}</p>
<div *ngIf="showActions">
<mat-menu [id]="'adf-version-list-action-menu-'+idx"
<mat-menu [id]="'adf-version-list-action-menu-'+version.entry.id"
#versionMenu="matMenu" yPosition="below" xPosition="before">
<button
[id]="'adf-version-list-action-restore-'+idx"
[id]="'adf-version-list-action-restore-'+version.entry.id"
[disabled]="!canUpdate()"
mat-menu-item
(click)="restore(version.entry.id)">
{{ 'ADF_VERSION_LIST.ACTIONS.RESTORE' | translate }}
</button>
<button *ngIf="allowDownload"
[id]="'adf-version-list-action-download-'+idx"
[id]="'adf-version-list-action-download-'+version.entry.id"
mat-menu-item
(click)="downloadVersion(version.entry.id)">
{{ 'ADF_VERSION_LIST.ACTIONS.DOWNLOAD' | translate }}
</button>
<button
[disabled]="!canDelete()"
[id]="'adf-version-list-action-delete-'+idx"
[id]="'adf-version-list-action-delete-'+version.entry.id"
(click)="deleteVersion(version.entry.id)"
mat-menu-item>
{{ 'ADF_VERSION_LIST.ACTIONS.DELETE' | translate }}
</button>
</mat-menu>
<button mat-icon-button [matMenuTriggerFor]="versionMenu" [id]="'adf-version-list-action-menu-button-'+idx">
<button mat-icon-button [matMenuTriggerFor]="versionMenu" [id]="'adf-version-list-action-menu-button-'+version.entry.id">
<mat-icon>more_vert</mat-icon>
</button>
</div>

View File

@@ -33,6 +33,15 @@ describe('VersionListComponent', () => {
const nodeId = 'test-id';
const versionId = '1.0';
const versionTest = [
{
entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' }
},
{
entry: { name: 'test-file-name-two', id: '1.0', versionComment: 'test-version-comment' }
}
];
setupTestBed({
imports: [
CoreModule.forRoot(),
@@ -64,6 +73,9 @@ describe('VersionListComponent', () => {
});
it('should raise confirmation dialog on delete', () => {
fixture.detectChanges();
component.versions = versionTest;
spyOn(dialog, 'open').and.returnValue({
afterClosed() {
return Observable.of(false);
@@ -76,7 +88,8 @@ describe('VersionListComponent', () => {
});
it('should delete the version if user confirms', () => {
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and.returnValue(Promise.resolve({ list: { entries: [] } }));
fixture.detectChanges();
component.versions = versionTest;
spyOn(dialog, 'open').and.returnValue({
afterClosed() {
return Observable.of(true);
@@ -92,6 +105,8 @@ describe('VersionListComponent', () => {
});
it('should not delete version if user rejects', () => {
component.versions = versionTest;
spyOn(dialog, 'open').and.returnValue({
afterClosed() {
return Observable.of(false);
@@ -106,21 +121,21 @@ describe('VersionListComponent', () => {
expect(alfrescoApiService.versionsApi.deleteVersion).not.toHaveBeenCalled();
});
it('should reload and raise version-deleted DOM event', (done) => {
it('should reload and raise deleted event', (done) => {
spyOn(component, 'loadVersionHistory').and.stub();
fixture.nativeElement.addEventListener('version-deleted', () => {
component.deleted.subscribe(() => {
expect(component.loadVersionHistory).toHaveBeenCalled();
done();
});
fixture.detectChanges();
component.onVersionDeleted();
component.onVersionDeleted({});
});
describe('Version history fetching', () => {
it('should use loading bar', () => {
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and
.callFake(() => Promise.resolve({ list: { entries: [] } }));
.callFake(() => Promise.resolve({ list: { entries: versionTest } }));
let loadingProgressBar = fixture.debugElement.query(By.css('[data-automation-id="version-history-loading-bar"]'));
expect(loadingProgressBar).toBeNull();
@@ -134,7 +149,7 @@ describe('VersionListComponent', () => {
it('should load the versions for a given id', () => {
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and
.callFake(() => Promise.resolve({ list: { entries: [] } }));
.callFake(() => Promise.resolve({ list: { entries: versionTest } }));
component.ngOnChanges();
fixture.detectChanges();
@@ -241,12 +256,12 @@ describe('VersionListComponent', () => {
it('should reload and raise version-restored DOM event', (done) => {
spyOn(component, 'loadVersionHistory').and.stub();
fixture.nativeElement.addEventListener('version-restored', () => {
component.restored.subscribe(() => {
expect(component.loadVersionHistory).toHaveBeenCalled();
done();
});
fixture.detectChanges();
component.onVersionRestored();
component.onVersionRestored({});
});
it('should restore version only when restore allowed', () => {
@@ -258,8 +273,8 @@ describe('VersionListComponent', () => {
it('should load the versions for a given id', () => {
fixture.detectChanges();
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and
.callFake(() => Promise.resolve({ list: { entries: [] } }));
component.versions = versionTest;
const spyOnRevertVersion = spyOn(alfrescoApiService.versionsApi, 'revertVersion').and
.callFake(() => Promise.resolve(
{ entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' } }));
@@ -271,8 +286,10 @@ describe('VersionListComponent', () => {
it('should reload the version list after a version restore', (done) => {
fixture.detectChanges();
component.versions = versionTest;
const spyOnListVersionHistory = spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and
.callFake(() => Promise.resolve({ list: { entries: [] } }));
.callFake(() => Promise.resolve({ list: { entries: versionTest } }));
spyOn(alfrescoApiService.versionsApi, 'revertVersion').and.callFake(() => Promise.resolve());
component.restore(versionId);
@@ -307,12 +324,14 @@ describe('VersionListComponent', () => {
});
it('should show Actions if showActions is true', (done) => {
component.versions = versionTest;
component.showActions = true;
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
let menuButton = fixture.debugElement.query(By.css('#adf-version-list-action-menu-button-0'));
let menuButton = fixture.nativeElement.querySelector('[id="adf-version-list-action-menu-button-1.0"]');
expect(menuButton).not.toBeNull();
done();
@@ -325,7 +344,7 @@ describe('VersionListComponent', () => {
fixture.whenStable().then(() => {
fixture.detectChanges();
let menuButton = fixture.debugElement.query(By.css('#adf-version-list-action-menu-button-0'));
let menuButton = fixture.nativeElement.querySelector('[id="adf-version-list-action-menu-button-1.0"]');
expect(menuButton).toBeNull();
done();
@@ -342,6 +361,9 @@ describe('VersionListComponent', () => {
return Promise.resolve({
list: {
entries: [
{
entry: { name: 'test-file-two', id: '1.1', versionComment: 'test-version-comment' }
},
{
entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' }
}
@@ -356,12 +378,12 @@ describe('VersionListComponent', () => {
it('should disable delete action if is not allowed', (done) => {
fixture.whenStable().then(() => {
fixture.detectChanges();
let menuButton = fixture.debugElement.query(By.css('#adf-version-list-action-menu-button-0'));
menuButton.nativeElement.click();
let menuButton = fixture.nativeElement.querySelector('[id="adf-version-list-action-menu-button-1.1"]');
menuButton.click();
let deleteButton = fixture.debugElement.query(By.css('#adf-version-list-action-delete-0'));
let deleteButton: any = document.querySelector('[id="adf-version-list-action-delete-1.1"]');
expect(deleteButton.nativeElement.disabled).toBe(true);
expect(deleteButton.disabled).toBe(true);
done();
});
});
@@ -369,12 +391,12 @@ describe('VersionListComponent', () => {
it('should disable restore action if is not allowed', (done) => {
fixture.whenStable().then(() => {
fixture.detectChanges();
let menuButton = fixture.debugElement.query(By.css('#adf-version-list-action-menu-button-0'));
menuButton.nativeElement.click();
let menuButton = fixture.nativeElement.querySelector('[id="adf-version-list-action-menu-button-1.1"]');
menuButton.click();
let restoreButton = fixture.debugElement.query(By.css('#adf-version-list-action-restore-0'));
let restoreButton: any = document.querySelector('[id="adf-version-list-action-restore-1.1"]');
expect(restoreButton.nativeElement.disabled).toBe(true);
expect(restoreButton.disabled).toBe(true);
done();
});
});
@@ -389,6 +411,9 @@ describe('VersionListComponent', () => {
return Promise.resolve({
list: {
entries: [
{
entry: { name: 'test-file-name', id: '1.1', versionComment: 'test-version-comment' }
},
{
entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' }
}
@@ -403,12 +428,12 @@ describe('VersionListComponent', () => {
it('should enable delete action if is allowed', (done) => {
fixture.whenStable().then(() => {
fixture.detectChanges();
let menuButton = fixture.debugElement.query(By.css('#adf-version-list-action-menu-button-0'));
menuButton.nativeElement.click();
let menuButton = fixture.nativeElement.querySelector('[id="adf-version-list-action-menu-button-1.1"]');
menuButton.click();
let deleteButton = fixture.debugElement.query(By.css('#adf-version-list-action-delete-0'));
let deleteButton: any = document.querySelector('[id="adf-version-list-action-delete-1.1"]');
expect(deleteButton.nativeElement.disabled).toBe(false);
expect(deleteButton.disabled).toBe(false);
done();
});
});
@@ -416,12 +441,12 @@ describe('VersionListComponent', () => {
it('should enable restore action if is allowed', (done) => {
fixture.whenStable().then(() => {
fixture.detectChanges();
let menuButton = fixture.debugElement.query(By.css('#adf-version-list-action-menu-button-0'));
menuButton.nativeElement.click();
let menuButton = fixture.nativeElement.querySelector('[id="adf-version-list-action-menu-button-1.1"]');
menuButton.click();
let restoreButton = fixture.debugElement.query(By.css('#adf-version-list-action-restore-0'));
let restoreButton: any = document.querySelector('[id="adf-version-list-action-restore-1.1"]');
expect(restoreButton.nativeElement.disabled).toBe(false);
expect(restoreButton.disabled).toBe(false);
done();
});
});

View File

@@ -16,7 +16,7 @@
*/
import { AlfrescoApiService, ContentService } from '@alfresco/adf-core';
import { Component, Input, OnChanges, ViewEncapsulation, ElementRef } from '@angular/core';
import { Component, Input, OnChanges, ViewEncapsulation, EventEmitter, Output } from '@angular/core';
import { VersionsApi, MinimalNodeEntryEntity, VersionEntry } from 'alfresco-js-api';
import { MatDialog } from '@angular/material';
import { ConfirmDialogComponent } from '../dialogs/confirm.dialog';
@@ -56,10 +56,17 @@ export class VersionListComponent implements OnChanges {
@Input()
showActions = true;
/** Emitted when a version is restored */
@Output()
restored: EventEmitter<MinimalNodeEntryEntity> = new EventEmitter<MinimalNodeEntryEntity>();
/** Emitted when a version is deleted */
@Output()
deleted: EventEmitter<MinimalNodeEntryEntity> = new EventEmitter<MinimalNodeEntryEntity>();
constructor(private alfrescoApi: AlfrescoApiService,
private contentService: ContentService,
private dialog: MatDialog,
private el: ElementRef) {
private dialog: MatDialog) {
this.versionsApi = this.alfrescoApi.versionsApi;
}
@@ -68,18 +75,18 @@ export class VersionListComponent implements OnChanges {
}
canUpdate(): boolean {
return this.contentService.hasPermission(this.node, 'update');
return this.contentService.hasPermission(this.node, 'update') && this.versions.length > 1;
}
canDelete(): boolean {
return this.contentService.hasPermission(this.node, 'delete');
return this.contentService.hasPermission(this.node, 'delete') && this.versions.length > 1;
}
restore(versionId) {
if (this.canUpdate()) {
this.versionsApi
.revertVersion(this.node.id, versionId, { majorVersion: true, comment: '' })
.then(() => this.onVersionRestored());
.then(() => this.onVersionRestored(this.node));
}
}
@@ -114,24 +121,20 @@ export class VersionListComponent implements OnChanges {
if (result === true) {
this.alfrescoApi.versionsApi
.deleteVersion(this.node.id, versionId)
.then(() => this.onVersionDeleted());
.then(() => this.onVersionDeleted(this.node));
}
});
}
}
onVersionDeleted() {
onVersionDeleted(node: any) {
this.loadVersionHistory();
const event = new CustomEvent('version-deleted', { bubbles: true });
this.el.nativeElement.dispatchEvent(event);
this.deleted.emit(node);
}
onVersionRestored() {
onVersionRestored(node: any) {
this.loadVersionHistory();
const event = new CustomEvent('version-restored', { bubbles: true });
this.el.nativeElement.dispatchEvent(event);
this.restored.emit(node);
}
private getVersionContentUrl(nodeId: string, versionId: string, attachment?: boolean) {

View File

@@ -1,6 +1,6 @@
<div class="adf-new-version-container">
<div class="adf-new-version-uploader-container" fxLayout="row" fxLayoutAlign="end center" [@uploadToggle]="uploadState">
<table class="adf-version-upload">
<div class="adf-new-version-uploader-container" id="adf-new-version-uploader-container" fxLayout="row" fxLayoutAlign="end center" [@uploadToggle]="uploadState">
<table class="adf-version-upload" *ngIf="uploadState !== 'close'">
<tr>
<td>
<adf-version-upload
@@ -8,7 +8,7 @@
[node]="node"
(success)="onUploadSuccess($event)"
(cancel)="onUploadCancel()"
(error)="uploadError.emit($event)">
(error)="onUploadError($event)">
</adf-version-upload>
</td>
</tr>
@@ -27,11 +27,14 @@
</button>
</div>
<div>
<adf-version-list
#versionList
[node]="node"
[allowDownload]="allowDownload"
[showComments]="showComments">
[showComments]="showComments"
(deleted)="refresh($event)"
(restored)="refresh($event)">
</adf-version-list>
</div>
</div>

View File

@@ -14,7 +14,7 @@
float: left;
position: relative;
visibility: hidden;
display: hidden;
}
.adf-new-version-container {

View File

@@ -102,7 +102,7 @@ describe('VersionManagerComponent', () => {
const emittedData = { value: { entry: node }};
component.uploadSuccess.subscribe(event => {
expect(event).toBe(emittedData);
expect(event).toBe(node);
});
component.onUploadSuccess(emittedData);
}));

View File

@@ -57,11 +57,11 @@ export class VersionManagerComponent {
/** Emitted when a file is uploaded successfully. */
@Output()
uploadSuccess = new EventEmitter();
uploadSuccess: EventEmitter<MinimalNodeEntryEntity> = new EventEmitter<MinimalNodeEntryEntity>();
/** Emitted when an error occurs during upload. */
@Output()
uploadError = new EventEmitter();
uploadError: EventEmitter<MinimalNodeEntryEntity> = new EventEmitter<MinimalNodeEntryEntity>();
@ViewChild('versionList')
versionListComponent: VersionListComponent;
@@ -73,13 +73,24 @@ export class VersionManagerComponent {
private alfrescoApiService: AlfrescoApiService) {
}
onUploadSuccess(event) {
refresh(node: MinimalNodeEntryEntity) {
this.alfrescoApiService.nodeUpdated.next(node);
this.versionListComponent.loadVersionHistory();
this.uploadSuccess.emit(node);
this.uploadState = 'close';
}
onUploadSuccess(event: any) {
this.alfrescoApiService.nodeUpdated.next(event.value.entry);
this.versionListComponent.loadVersionHistory();
this.uploadSuccess.emit(event);
this.uploadSuccess.emit(event.value.entry);
this.uploadState = 'close';
}
onUploadError(event: any) {
this.uploadError.emit(event);
}
onUploadCancel() {
this.uploadState = 'close';
}

View File

@@ -1,16 +1,16 @@
<div class="adf-new-version-max-width">
<mat-radio-group class="adf-new-version-radio-group" [(ngModel)]="semanticVersion">
<mat-radio-button class="adf-new-version-radio-button" [value]="'minor'">{{
<mat-radio-button class="adf-new-version-radio-button" id="adf-new-version-minor"[value]="'minor'">{{
'ADF_VERSION_LIST.ACTIONS.UPLOAD.MINOR' |
translate }}
</mat-radio-button>
<mat-radio-button class="adf-new-version-radio-button" [value]="'major'">{{
<mat-radio-button class="adf-new-version-radio-button" id="adf-new-version-major" [value]="'major'">{{
'ADF_VERSION_LIST.ACTIONS.UPLOAD.MAJOR' |
translate }}
</mat-radio-button>
</mat-radio-group>
<mat-form-field class="adf-new-version-max-width">
<textarea matInput [(ngModel)]="comment" class="adf-new-version-text-area"
<textarea matInput [(ngModel)]="comment" class="adf-new-version-text-area" id="adf-new-version-text-area"
placeholder="{{ 'ADF_VERSION_LIST.ACTIONS.UPLOAD.COMMENT' | translate }}"></textarea>
</mat-form-field>
@@ -29,7 +29,7 @@
(success)="success.emit($event)"
(error)="error.emit($event)">
</adf-upload-version-button>
<button mat-raised-button (click)="cancelUpload()">{{
<button mat-raised-button (click)="cancelUpload()" id="adf-new-version-cancel" >{{
'ADF_VERSION_LIST.ACTIONS.UPLOAD.CANCEL'| translate }}
</button>
</div>

View File

@@ -18,7 +18,7 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { ObjectUtils } from '../utils/object-utils';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Subject } from 'rxjs/Subject';
import { Observable } from 'rxjs/Observable';
export enum AppConfigValues {
@@ -49,11 +49,11 @@ export class AppConfigService {
alfrescoRepositoryName: 'alfresco-1'
};
private onLoadSubject: BehaviorSubject<any>;
private onLoadSubject: Subject<any>;
onLoad: Observable<any>;
constructor(private http: HttpClient) {
this.onLoadSubject = new BehaviorSubject(this.config);
this.onLoadSubject = new Subject();
this.onLoad = this.onLoadSubject.asObservable();
}

View File

@@ -21,6 +21,7 @@ import { Component, HostListener, Input, OnDestroy, OnInit, Renderer2, ViewChild
import { MatMenuTrigger } from '@angular/material';
import { Subscription } from 'rxjs/Subscription';
import { ContextMenuService } from './context-menu.service';
/**
* @deprecated: context-menu-holder is deprecated, use adf-context-menu-holder instead.
*/
@@ -31,9 +32,9 @@ import { ContextMenuService } from './context-menu.service';
<mat-menu #contextMenu="matMenu" class="context-menu">
<ng-container *ngFor="let link of links">
<button *ngIf="link.model?.visible"
mat-menu-item
[disabled]="link.model?.disabled"
(click)="onMenuItemClick($event, link)">
mat-menu-item
[disabled]="link.model?.disabled"
(click)="onMenuItemClick($event, link)">
<mat-icon *ngIf="showIcons && link.model?.icon">{{ link.model.icon }}</mat-icon>
{{ (link.title || link.model?.title) | translate }}
</button>
@@ -44,7 +45,7 @@ import { ContextMenuService } from './context-menu.service';
export class ContextMenuHolderComponent implements OnInit, OnDestroy {
links = [];
private mouseLocation: { left: number, top: number } = {left: 0, top: 0};
private mouseLocation: { left: number, top: number } = { left: 0, top: 0 };
private menuElement = null;
private subscriptions: Subscription[] = [];
private contextMenuListenerFn: () => void;
@@ -70,11 +71,12 @@ export class ContextMenuHolderComponent implements OnInit, OnDestroy {
}
constructor(
private viewport: ViewportRuler,
private overlayContainer: OverlayContainer,
private contextMenuService: ContextMenuService,
private renderer: Renderer2
) {}
private viewport: ViewportRuler,
private overlayContainer: OverlayContainer,
private contextMenuService: ContextMenuService,
private renderer: Renderer2
) {
}
ngOnInit() {
this.subscriptions.push(
@@ -149,20 +151,22 @@ export class ContextMenuHolderComponent implements OnInit, OnDestroy {
private updatePosition() {
setTimeout(() => {
if (this.mdMenuElement.clientWidth + this.mouseLocation.left > this.viewport.getViewportRect().width) {
this.menuTrigger.menu.xPosition = 'before';
this.mdMenuElement.parentElement.style.left = this.mouseLocation.left - this.mdMenuElement.clientWidth + 'px';
} else {
this.menuTrigger.menu.xPosition = 'after';
this.mdMenuElement.parentElement.style.left = this.locationCss().left;
}
if (this.mdMenuElement.parentElement) {
if (this.mdMenuElement.clientWidth + this.mouseLocation.left > this.viewport.getViewportRect().width) {
this.menuTrigger.menu.xPosition = 'before';
this.mdMenuElement.parentElement.style.left = this.mouseLocation.left - this.mdMenuElement.clientWidth + 'px';
} else {
this.menuTrigger.menu.xPosition = 'after';
this.mdMenuElement.parentElement.style.left = this.locationCss().left;
}
if (this.mdMenuElement.clientHeight + this.mouseLocation.top > this.viewport.getViewportRect().height) {
this.menuTrigger.menu.yPosition = 'above';
this.mdMenuElement.parentElement.style.top = this.mouseLocation.top - this.mdMenuElement.clientHeight + 'px';
} else {
this.menuTrigger.menu.yPosition = 'below';
this.mdMenuElement.parentElement.style.top = this.locationCss().top;
if (this.mdMenuElement.clientHeight + this.mouseLocation.top > this.viewport.getViewportRect().height) {
this.menuTrigger.menu.yPosition = 'above';
this.mdMenuElement.parentElement.style.top = this.mouseLocation.top - this.mdMenuElement.clientHeight + 'px';
} else {
this.menuTrigger.menu.yPosition = 'below';
this.mdMenuElement.parentElement.style.top = this.locationCss().top;
}
}
}, 0);
}

View File

@@ -232,6 +232,8 @@ describe('PaginationComponent', () => {
describe('Without pagination input', () => {
it('has defaults', () => {
component.ngOnInit();
const {
current, lastPage, isFirstPage, isLastPage,
next, previous, range, pages

View File

@@ -15,14 +15,17 @@
* limitations under the License.
*/
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation,
ChangeDetectorRef, OnDestroy, HostBinding } from '@angular/core';
import {
ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation,
ChangeDetectorRef, OnDestroy, HostBinding
} from '@angular/core';
import { Pagination } from 'alfresco-js-api';
import { PaginatedComponent } from './paginated-component.interface';
import { PaginationComponentInterface } from './pagination-component.interface';
import { Subscription } from 'rxjs/Subscription';
import { PaginationModel } from '../models/pagination.model';
import { UserPreferencesService } from '../services/user-preferences.service';
@Component({
selector: 'adf-pagination',
@@ -53,11 +56,11 @@ export class PaginationComponent implements OnInit, OnDestroy, PaginationCompone
/** An array of page sizes. */
@Input()
supportedPageSizes: number[] = [5, 25, 50, 100];
supportedPageSizes: number[];
/** Pagination object. */
@Input()
pagination: PaginationModel = PaginationComponent.DEFAULT_PAGINATION;
pagination: PaginationModel;
/** Emitted when pagination changes in any way. */
@Output()
@@ -81,10 +84,20 @@ export class PaginationComponent implements OnInit, OnDestroy, PaginationCompone
private paginationSubscription: Subscription;
constructor(private cdr: ChangeDetectorRef) {
constructor(private cdr: ChangeDetectorRef, private userPreferencesService: UserPreferencesService) {
}
ngOnInit() {
if (!this.pagination) {
let defaultPagination = PaginationComponent.DEFAULT_PAGINATION;
defaultPagination.maxItems = this.userPreferencesService.paginationSize;
this.pagination = defaultPagination;
}
if (!this.supportedPageSizes) {
this.supportedPageSizes = this.userPreferencesService.getDefaultPageSizes();
}
if (this.target) {
this.paginationSubscription = this.target.pagination.subscribe((pagination: PaginationModel) => {

View File

@@ -56,7 +56,7 @@ export class TranslationService {
}
}
userPreference.locale$.subscribe( (locale) => {
userPreference.locale$.subscribe((locale) => {
this.userLang = locale;
this.use(this.userLang);
});
@@ -70,22 +70,18 @@ export class TranslationService {
addTranslationFolder(name: string = '', path: string = '') {
if (!this.customLoader.providerRegistered(name)) {
this.customLoader.registerProvider(name, path);
if (this.userLang !== this.defaultLang) {
this.translate.getTranslation(this.defaultLang).subscribe(() => {
this.translate.getTranslation(this.userLang).subscribe(
() => {
this.translate.use(this.userLang);
this.onTranslationChanged(this.userLang);
}
);
});
} else {
this.translate.getTranslation(this.userLang).subscribe(
() => {
if (this.userLang) {
this.translate.getTranslation(this.userLang).subscribe(() => {
this.translate.use(this.userLang);
this.onTranslationChanged(this.userLang);
}
);
} else {
this.translate.getTranslation(this.defaultLang).subscribe(() => {
this.translate.use(this.defaultLang);
this.onTranslationChanged(this.defaultLang);
}
);
}
}
}
@@ -117,7 +113,7 @@ export class TranslationService {
* @param interpolateParams String(s) to be interpolated into the main message
* @returns Translated text
*/
get(key: string|Array<string>, interpolateParams?: Object): Observable<string|any> {
get(key: string | Array<string>, interpolateParams?: Object): Observable<string | any> {
return this.translate.get(key, interpolateParams);
}

View File

@@ -53,7 +53,7 @@ export class UserPreferencesService {
private appConfig: AppConfigService,
private storage: StorageService) {
this.appConfig.onLoad.subscribe(this.initUserPreferenceStatus.bind(this));
this.localeSubject = new BehaviorSubject(this.userPreferenceStatus[UserPreferenceValues.Locale]);
this.localeSubject = new BehaviorSubject(this.get(UserPreferenceValues.Locale, this.getDefaultLocale()));
this.locale$ = this.localeSubject.asObservable();
this.onChangeSubject = new BehaviorSubject(this.userPreferenceStatus);
this.onChange = this.onChangeSubject.asObservable();
@@ -61,8 +61,7 @@ export class UserPreferencesService {
private initUserPreferenceStatus() {
this.userPreferenceStatus[UserPreferenceValues.Locale] = this.locale || this.getDefaultLocale();
this.userPreferenceStatus[UserPreferenceValues.PaginationSize] = this.paginationSize ?
this.paginationSize : this.appConfig.get('pagination.size', this.defaults.paginationSize);
this.userPreferenceStatus[UserPreferenceValues.PaginationSize] = this.appConfig.get('pagination.size', this.defaults.paginationSize);
this.userPreferenceStatus[UserPreferenceValues.SupportedPageSizes] = this.appConfig.get('pagination.supportedPageSizes', this.defaults.supportedPageSizes);
}
@@ -150,27 +149,27 @@ export class UserPreferencesService {
* @returns Array of page size values
*/
getDefaultPageSizes(): number[] {
return this.defaults.supportedPageSizes;
return this.userPreferenceStatus[UserPreferenceValues.SupportedPageSizes];
}
/** Pagination size. */
set paginationSize(value: number) {
this.set('PAGINATION_SIZE', value);
this.set(UserPreferenceValues.PaginationSize, value);
}
get paginationSize(): number {
return Number(this.get('PAGINATION_SIZE')) || this.defaults.paginationSize;
return Number(this.get(UserPreferenceValues.PaginationSize, this.userPreferenceStatus[UserPreferenceValues.PaginationSize])) || this.defaults.paginationSize;
}
/** Current locale setting. */
get locale(): string {
const locale = this.get('LOCALE');
const locale = this.get(UserPreferenceValues.Locale, this.userPreferenceStatus[UserPreferenceValues.Locale]);
return locale;
}
set locale(value: string) {
this.localeSubject.next(value);
this.set('LOCALE', value);
this.set(UserPreferenceValues.Locale, value);
}
/**

View File

@@ -10,12 +10,12 @@
{{ 'ERROR_CONTENT.' + errorCode + '.DESCRIPTION' | translate }}
</p>
<div class="adf-error-content-buttons">
<a mat-raised-button color="primary"
<a a id="adf-secondary-button" mat-raised-button color="primary"
*ngIf="secondaryButtonText" (click)="onSecondButton()"
class="adf-error-content-description-link">
class="adf-error-content-description-link">
{{ 'ERROR_CONTENT.' + errorCode + '.SECONDARY_BUTTON.TEXT' | translate | uppercase }}
</a>
<a mat-raised-button color="primary" (click)="onReturnButton()">
<a id="adf-return-button" mat-raised-button color="primary" (click)="onReturnButton()">
{{ 'ERROR_CONTENT.' + this.errorCode + '.RETURN_BUTTON.TEXT' | translate | uppercase }}
</a>
</div>

View File

@@ -89,7 +89,8 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
}
clone(date: Moment): Moment {
return date.clone().locale(this.locale);
let locale = this.locale || 'en';
return date.clone().locale(locale);
}
createDate(year: number, month: number, date: number): Moment {
@@ -97,16 +98,18 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
}
today(): Moment {
return moment().locale(this.locale);
let locale = this.locale || 'en';
return moment().locale(locale);
}
parse(value: any, parseFormat: any): Moment {
let locale = this.locale || 'en';
if (value && typeof value === 'string') {
let m = moment(value, parseFormat, this.locale, true);
let m = moment(value, parseFormat, locale, true);
if (!m.isValid()) {
// use strict parsing because Moment's parser is very forgiving, and this can lead to undesired behavior.
m = moment(value, this.overrideDisplyaFormat, this.locale, true);
m = moment(value, this.overrideDisplyaFormat, locale, true);
}
if (m.isValid()) {
// if user omits year, it defaults to 2001, so check for that issue.
@@ -123,7 +126,7 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
return m;
}
return value ? moment(value).locale(this.locale) : null;
return value ? moment(value).locale(locale) : null;
}
format(date: Moment, displayFormat: any): string {
@@ -204,7 +207,8 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
}
fromIso8601(iso8601String: string): Moment | null {
let d = moment(iso8601String, moment.ISO_8601).locale(this.locale);
let locale = this.locale || 'en';
let d = moment(iso8601String, moment.ISO_8601).locale(locale);
return this.isValid(d) ? d : null;
}

View File

@@ -335,8 +335,4 @@ export class ProcessInstanceListComponent extends DataTableSchema implements On
currentPage(skipCount: number, maxItems: number): number {
return (skipCount && maxItems) ? Math.floor(skipCount / maxItems) : 0;
}
get supportedPageSizes(): number[] {
return this.userPreferences.getDefaultPageSizes();
}
}

View File

@@ -377,8 +377,4 @@ export class TaskListComponent extends DataTableSchema implements OnChanges, Aft
currentPage(skipCount: number, maxItems: number): number {
return (skipCount && maxItems) ? Math.floor(skipCount / maxItems) : 0;
}
get supportedPageSizes(): number[] {
return this.userPreferences.getDefaultPageSizes();
}
}