diff --git a/lib/content-services/src/lib/i18n/en.json b/lib/content-services/src/lib/i18n/en.json index 54302f2655..9cd2208e0e 100644 --- a/lib/content-services/src/lib/i18n/en.json +++ b/lib/content-services/src/lib/i18n/en.json @@ -8,8 +8,8 @@ "UPLOAD": { "TITLE": "Upload new version", "TOOLTIP": "Restriction: you must upload a file with the same name to create a new version of it", - "MAJOR": "major changes (2.0)", - "MINOR": "minor changes (1.1)", + "MAJOR": "major changes ({{version}})", + "MINOR": "minor changes ({{version}})", "COMMENT": "Leave a comment", "ADD": "Add New Version", "CANCEL": "Cancel" diff --git a/lib/content-services/src/lib/version-manager/version-manager.component.html b/lib/content-services/src/lib/version-manager/version-manager.component.html index 52da70ee43..13406962cc 100644 --- a/lib/content-services/src/lib/version-manager/version-manager.component.html +++ b/lib/content-services/src/lib/version-manager/version-manager.component.html @@ -3,13 +3,14 @@
- +
diff --git a/lib/content-services/src/lib/version-manager/version-upload.component.html b/lib/content-services/src/lib/version-manager/version-upload.component.html index 309430b28e..bffba2fd88 100644 --- a/lib/content-services/src/lib/version-manager/version-upload.component.html +++ b/lib/content-services/src/lib/version-manager/version-upload.component.html @@ -1,12 +1,10 @@
- {{ - 'ADF_VERSION_LIST.ACTIONS.UPLOAD.MINOR' | - translate }} + + {{ 'ADF_VERSION_LIST.ACTIONS.UPLOAD.MINOR' | translate: { version: minorVersion } }} - {{ - 'ADF_VERSION_LIST.ACTIONS.UPLOAD.MAJOR' | - translate }} + + {{ 'ADF_VERSION_LIST.ACTIONS.UPLOAD.MAJOR' | translate: { version: majorVersion } }} diff --git a/lib/content-services/src/lib/version-manager/version-upload.component.spec.ts b/lib/content-services/src/lib/version-manager/version-upload.component.spec.ts index 38c387a452..60a7ede0d0 100644 --- a/lib/content-services/src/lib/version-manager/version-upload.component.spec.ts +++ b/lib/content-services/src/lib/version-manager/version-upload.component.spec.ts @@ -18,7 +18,7 @@ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; import { TranslateModule } from '@ngx-translate/core'; -import { VersionUploadComponent } from 'content-services'; +import { VersionUploadComponent } from './version-upload.component'; import { ContentService, setupTestBed, UploadService } from '@alfresco/adf-core'; import { ContentTestingModule } from '../testing/content.testing.module'; import { Node } from '@alfresco/js-api'; @@ -93,4 +93,17 @@ describe('VersionUploadComponent', () => { fixture.detectChanges(); }); + it('should update next major version', () => { + let majorVersion = component.getNextMajorVersion('1.0'); + expect(majorVersion).toEqual('2.0'); + majorVersion = component.getNextMajorVersion('10.0'); + expect(majorVersion).toEqual('11.0'); + }); + + it('should update next minor version', () => { + let minorVersion = component.getNextMinorVersion('1.0'); + expect(minorVersion).toEqual('1.1'); + minorVersion = component.getNextMinorVersion('1.10'); + expect(minorVersion).toEqual('1.11'); + }); }); diff --git a/lib/content-services/src/lib/version-manager/version-upload.component.ts b/lib/content-services/src/lib/version-manager/version-upload.component.ts index a0261e6749..1ace3a00af 100644 --- a/lib/content-services/src/lib/version-manager/version-upload.component.ts +++ b/lib/content-services/src/lib/version-manager/version-upload.component.ts @@ -15,8 +15,8 @@ * limitations under the License. */ -import { Component, Input, ViewEncapsulation, Output, EventEmitter, OnInit, OnDestroy } from '@angular/core'; -import { Node } from '@alfresco/js-api'; +import { Component, EventEmitter, Input, OnDestroy, OnInit, Output, ViewEncapsulation } from '@angular/core'; +import { Node, Version } from '@alfresco/js-api'; import { ContentService, FileUploadErrorEvent, FileUploadEvent, UploadService } from '@alfresco/adf-core'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; @@ -35,6 +35,8 @@ export class VersionUploadComponent implements OnInit, OnDestroy { uploadVersion: boolean = false; disabled: boolean = false; onDestroy$ = new Subject(); + majorVersion = '2.0'; + minorVersion = '1.1'; /** The target node. */ @Input() @@ -52,6 +54,15 @@ export class VersionUploadComponent implements OnInit, OnDestroy { @Input() showCancelButton: boolean = true; + /** Current version for a target node */ + @Input() + set currentVersion(version: Version) { + if (version) { + this.minorVersion = this.getNextMinorVersion(version.id); + this.majorVersion = this.getNextMajorVersion(version.id); + } + } + /** Emitted when the file is uploaded successfully. */ @Output() success = new EventEmitter(); @@ -124,4 +135,19 @@ export class VersionUploadComponent implements OnInit, OnDestroy { this.onDestroy$.complete(); } + getNextMinorVersion(version: string): string { + const { major, minor } = this.getParsedVersion(version); + return `${major}.${minor + 1}`; + } + + getNextMajorVersion(version: string): string { + const { major} = this.getParsedVersion(version); + return `${major + 1 }.0`; + } + + private getParsedVersion(version: string) { + const minor = version.indexOf('.') !== -1 ? Number(version.substr(version.indexOf('.') + 1)) : 0; + const major = parseInt(version, 10); + return { minor, major }; + } }