mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
18
lib/content-services/version-manager/index.ts
Normal file
18
lib/content-services/version-manager/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/*!
|
||||
* @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.
|
||||
*/
|
||||
|
||||
export * from './public-api';
|
22
lib/content-services/version-manager/public-api.ts
Normal file
22
lib/content-services/version-manager/public-api.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/*!
|
||||
* @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.
|
||||
*/
|
||||
|
||||
export * from './version-list.component';
|
||||
export * from './version-manager.component';
|
||||
export * from './version-upload.component';
|
||||
|
||||
export * from './version-manager.module';
|
@@ -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>
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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 { MaterialModule } from '../material.module';
|
||||
import { VersionListComponent } from './version-list.component';
|
||||
import { AlfrescoApiService, CoreModule } from '@alfresco/core';
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@@ -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 { AlfrescoApiService } from '@alfresco/core';
|
||||
import { Component, Input, OnChanges, ViewEncapsulation } from '@angular/core';
|
||||
import { VersionsApi } from 'alfresco-js-api';
|
||||
|
||||
@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;
|
||||
});
|
||||
}
|
||||
}
|
@@ -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>
|
@@ -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;
|
||||
}
|
@@ -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;
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
/*!
|
||||
* @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 { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { MaterialModule } from '../material.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
import { VersionUploadComponent } from './version-upload.component';
|
||||
import { VersionManagerComponent } from './version-manager.component';
|
||||
import { VersionListComponent } from './version-list.component';
|
||||
import { UploadModule } from '../upload';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
MaterialModule,
|
||||
TranslateModule,
|
||||
UploadModule
|
||||
],
|
||||
exports: [
|
||||
VersionUploadComponent,
|
||||
VersionManagerComponent,
|
||||
VersionListComponent
|
||||
],
|
||||
declarations: [
|
||||
VersionUploadComponent,
|
||||
VersionManagerComponent,
|
||||
VersionListComponent
|
||||
],
|
||||
providers: []
|
||||
})
|
||||
export class VersionManagerModule {}
|
@@ -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>
|
@@ -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;
|
||||
}
|
Reference in New Issue
Block a user