[ADF-1751] Version manager POC (#2551)

* First try

* Upload new versions

* Add versionComment

* Permission handling for sidebar also

* Add tests

* Fix rebase

* Add documentation
This commit is contained in:
Popovics András
2017-10-26 14:22:34 +01:00
committed by Eugenio Romano
parent e7e2007c93
commit 2588bbda7d
26 changed files with 753 additions and 225 deletions

View File

@@ -18,7 +18,8 @@
import { Injectable } from '@angular/core';
import {
AlfrescoApi, ContentApi, FavoritesApi, NodesApi,
PeopleApi, RenditionsApi, SharedlinksApi, SitesApi
PeopleApi, RenditionsApi, SharedlinksApi, SitesApi,
VersionsApi
} from 'alfresco-js-api';
import * as alfrescoApi from 'alfresco-js-api';
import { AppConfigService } from './app-config.service';
@@ -65,6 +66,10 @@ export class AlfrescoApiService {
return this.getInstance().search.searchApi;
}
get versionsApi(): VersionsApi {
return this.getInstance().core.versionsApi;
}
constructor(private appConfig: AppConfigService,
private storage: StorageService) {

View File

@@ -16,8 +16,10 @@
*/
import { NgModule } from '@angular/core';
import { FlexLayoutModule } from '@angular/flex-layout';
import { CoreModule, TRANSLATION_PROVIDER } from 'ng2-alfresco-core';
import { DataTableModule } from 'ng2-alfresco-datatable';
import { UploadModule } from 'ng2-alfresco-upload';
import { BreadcrumbComponent } from './src/components/breadcrumb/breadcrumb.component';
import { DropdownBreadcrumbComponent } from './src/components/breadcrumb/dropdown-breadcrumb.component';
@@ -29,6 +31,9 @@ import { ContentNodeSelectorComponent } from './src/components/content-node-sele
import { DocumentListComponent } from './src/components/document-list.component';
import { EmptyFolderContentDirective } from './src/components/empty-folder/empty-folder-content.directive';
import { DropdownSitesComponent } from './src/components/site-dropdown/sites-dropdown.component';
import { VersionListComponent } from './src/components/version-manager/version-list.component';
import { VersionManagerComponent } from './src/components/version-manager/version-manager.component';
import { VersionUploadComponent } from './src/components/version-manager/version-upload.component';
import { MaterialModule } from './src/material.module';
import { ContentNodeSelectorService } from './src/components/content-node-selector/content-node-selector.service';
@@ -75,7 +80,10 @@ export const DOCUMENT_LIST_DIRECTIVES: any[] = [
BreadcrumbComponent,
DropdownSitesComponent,
DropdownBreadcrumbComponent,
ContentNodeSelectorComponent
ContentNodeSelectorComponent,
VersionListComponent,
VersionUploadComponent,
VersionManagerComponent
];
export const DOCUMENT_LIST_PROVIDERS: any[] = [
@@ -89,8 +97,10 @@ export const DOCUMENT_LIST_PROVIDERS: any[] = [
@NgModule({
imports: [
CoreModule,
UploadModule,
DataTableModule,
MaterialModule
MaterialModule,
FlexLayoutModule
],
declarations: [
...DOCUMENT_LIST_DIRECTIVES

View File

@@ -47,6 +47,7 @@
"@angular/common": "4.4.5",
"@angular/compiler": "4.4.5",
"@angular/core": "4.4.5",
"@angular/flex-layout": "2.0.0-beta.9",
"@angular/forms": "4.4.5",
"@angular/http": "4.4.5",
"@angular/material": "2.0.0-beta.12",

View File

@@ -35,7 +35,6 @@ import { NodeMinimal, NodeMinimalEntry, NodePaging } from '../models/document-li
import { ImageResolver } from './../data/image-resolver.model';
import { RowFilter } from './../data/row-filter.model';
import { DocumentListService } from './../services/document-list.service';
import { DocumentListComponent } from './document-list.component';

View File

@@ -0,0 +1,23 @@
<mat-list class="adf-version-list" *ngIf="!isLoading; else loading_template">
<mat-list-item *ngFor="let version of versions">
<mat-icon mat-list-icon>insert_drive_file</mat-icon>
<h4 mat-line class="adf-version-list-item-name">{{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>
</p>
<p mat-line class="adf-version-list-item-comment">{{version.entry.versionComment}}</p>
<mat-menu #versionMenu="matMenu" yPosition="below" xPosition="before">
<button mat-menu-item (click)="restore(version.entry.id)"> Restore </button>
</mat-menu>
<button mat-icon-button [matMenuTriggerFor]="versionMenu">
<mat-icon>more_vert</mat-icon>
</button>
</mat-list-item>
</mat-list>
<ng-template #loading_template>
<mat-progress-bar data-automation-id="version-history-loading-bar" mode="indeterminate" color="accent"></mat-progress-bar>
</ng-template>

View File

@@ -0,0 +1,17 @@
.adf-version-list {
.mat-list-item {
border-bottom:1px solid #d8d8d8;
}
&-item-version {
font-weight: bold;
}
&-item-date {
opacity: 0.6;
}
&-item-comment {
opacity: 0.5;
}
}

View File

@@ -0,0 +1,135 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { CUSTOM_ELEMENTS_SCHEMA, DebugElement } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { AlfrescoApiService, CoreModule } from 'ng2-alfresco-core';
import { MaterialModule } from '../../material.module';
import { VersionListComponent } from './version-list.component';
describe('VersionListComponent', () => {
let component: VersionListComponent;
let fixture: ComponentFixture<VersionListComponent>;
let element: DebugElement;
const nodeId = 'test-id';
const versionId = '1.0';
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
CoreModule,
MaterialModule
],
declarations: [
VersionListComponent
],
providers: [
AlfrescoApiService
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
}).compileComponents();
}));
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
beforeEach(() => {
fixture = TestBed.createComponent(VersionListComponent);
element = fixture.debugElement;
component = fixture.componentInstance;
component.id = nodeId;
});
describe('Version history fetching', () => {
it('should use loading bar', () => {
let loadingProgressBar = fixture.debugElement.query(By.css('[data-automation-id="version-history-loading-bar"]'));
expect(loadingProgressBar).toBeNull();
component.ngOnChanges();
fixture.detectChanges();
loadingProgressBar = fixture.debugElement.query(By.css('[data-automation-id="version-history-loading-bar"]'));
expect(loadingProgressBar).not.toBeNull();
});
it('should load the versions for a given id', () => {
const alfrescoApiService = TestBed.get(AlfrescoApiService);
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and.callThrough();
component.ngOnChanges();
fixture.detectChanges();
expect(alfrescoApiService.versionsApi.listVersionHistory).toHaveBeenCalledWith(nodeId);
});
it('should show the versions after loading', () => {
fixture.detectChanges();
const alfrescoApiService = TestBed.get(AlfrescoApiService);
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and.callFake(() => {
return Promise.resolve([
{
entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' }
}
]);
});
component.ngOnChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
let versionFileName = fixture.debugElement.query(By.css('.adf-version-list-item-name')).nativeElement.innerText;
let versionIdText = fixture.debugElement.query(By.css('.adf-version-list-item-version')).nativeElement.innerText;
let versionComment = fixture.debugElement.query(By.css('.adf-version-list-item-comment')).nativeElement.innerText;
expect(versionFileName).toBe('test-file-name');
expect(versionIdText).toBe('1.0');
expect(versionComment).toBe('test-version-comment');
});
});
});
describe('Version restoring', () => {
it('should load the versions for a given id', () => {
fixture.detectChanges();
const alfrescoApiService = TestBed.get(AlfrescoApiService);
spyOn(alfrescoApiService.versionsApi, 'revertVersion').and.callThrough();
component.restore(versionId);
expect(alfrescoApiService.versionsApi.revertVersion).toHaveBeenCalledWith(nodeId, versionId, { majorVersion: true, comment: ''});
});
it('should reload the version list after a version restore', () => {
fixture.detectChanges();
const alfrescoApiService = TestBed.get(AlfrescoApiService);
spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and.callThrough();
spyOn(alfrescoApiService.versionsApi, 'revertVersion').and.callFake(() => Promise.resolve());
component.restore(versionId);
fixture.whenStable().then(() => {
expect(alfrescoApiService.versionsApi.listVersionHistory).toHaveBeenCalledTimes(1);
});
});
});
});

View File

@@ -0,0 +1,61 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component, Input, OnChanges, ViewEncapsulation } from '@angular/core';
import { VersionsApi } from 'alfresco-js-api';
import { AlfrescoApiService } from 'ng2-alfresco-core';
@Component({
selector: 'adf-version-list',
templateUrl: './version-list.component.html',
styleUrls: ['./version-list.component.scss'],
encapsulation: ViewEncapsulation.None,
host: {
'class': 'adf-version-list'
}
})
export class VersionListComponent implements OnChanges {
private versionsApi: VersionsApi;
versions: any = [];
isLoading: boolean = true;
@Input()
id: string;
constructor(private alfrescoApi: AlfrescoApiService) {
this.versionsApi = this.alfrescoApi.versionsApi;
}
ngOnChanges() {
this.loadVersionHistory();
}
restore(versionId) {
this.versionsApi
.revertVersion(this.id, versionId, { majorVersion: true, comment: ''})
.then(this.loadVersionHistory.bind(this));
}
private loadVersionHistory() {
this.isLoading = true;
this.versionsApi.listVersionHistory(this.id).then((data) => {
this.versions = data.list.entries;
this.isLoading = false;
});
}
}

View File

@@ -0,0 +1,6 @@
<div class="adf-new-version-uploader-container" fxLayout="row" fxLayoutAlign="end center">
<adf-version-upload [node]="node"></adf-version-upload>
</div>
<div class="adf-version-list-container">
<adf-version-list [id]="node.id"></adf-version-list>
</div>

View File

@@ -0,0 +1,8 @@
.adf-button.upload-new-version {
box-shadow: none;
}
.adf-new-version-uploader-container {
border-bottom:1px solid #d8d8d8;
padding: 16px 0;
}

View File

@@ -0,0 +1,31 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component, Input, ViewEncapsulation } from '@angular/core';
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
@Component({
selector: 'adf-version-manager',
templateUrl: './version-manager.component.html',
styleUrls: ['./version-manager.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class VersionManagerComponent {
@Input()
node: MinimalNodeEntryEntity;
}

View File

@@ -0,0 +1,8 @@
<adf-upload-button
data-automation-id="adf-new-version-file-upload"
class="adf-new-version-file-upload"
staticTitle="Upload new version"
[rootFolderId]="node.parentId"
tooltip="Restriction: upload file with the same name to create a new version of it"
[versioning]="true">
</adf-upload-button>

View File

@@ -0,0 +1,33 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component, Input, ViewEncapsulation } from '@angular/core';
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
@Component({
selector: 'adf-version-upload',
templateUrl: './version-upload.component.html',
encapsulation: ViewEncapsulation.None,
host: {
'class': 'adf-version-upload'
}
})
export class VersionUploadComponent {
@Input()
node: MinimalNodeEntryEntity;
}

View File

@@ -20,8 +20,8 @@ import { CoreModule } from 'ng2-alfresco-core';
import { DataColumn, DataRow, DataSorting } from 'ng2-alfresco-datatable';
import { FileNode, FolderNode } from './../assets/document-library.model.mock';
import { DocumentListService } from './../services/document-list.service';
import { ShareDataTableAdapter } from './share-datatable-adapter';
import { ShareDataRow } from './share-data-row.model';
import { ShareDataTableAdapter } from './share-datatable-adapter';
describe('ShareDataTableAdapter', () => {

View File

@@ -21,6 +21,7 @@ import {
MatDialogModule,
MatIconModule,
MatInputModule,
MatListModule,
MatMenuModule,
MatOptionModule,
MatProgressSpinnerModule,
@@ -34,6 +35,7 @@ export function modules() {
MatDialogModule,
MatButtonModule,
MatIconModule,
MatListModule,
MatInputModule,
MatProgressSpinnerModule,
MatSelectModule,

View File

@@ -18,9 +18,15 @@
import { NgModule } from '@angular/core';
import {
MatCheckboxModule,
MatDialogModule,
MatIconModule,
MatInputModule,
MatProgressSpinnerModule
MatListModule,
MatProgressBarModule,
MatProgressSpinnerModule,
MatSelectModule,
MatSidenavModule,
MatSlideToggleModule
} from '@angular/material';
export function modules() {
@@ -28,7 +34,14 @@ export function modules() {
MatCheckboxModule,
MatIconModule,
MatInputModule,
MatProgressSpinnerModule
MatProgressSpinnerModule,
MatSlideToggleModule,
MatInputModule,
MatSelectModule,
MatListModule,
MatDialogModule,
MatSidenavModule,
MatProgressBarModule
];
}