[AAE-11695] move version compatibility directive and service (#8038)

* [AAE-11695] move version compatibility directive

* [AAE-11695] remove spare readme section
This commit is contained in:
Kasia Biernat
2022-12-12 11:19:31 +01:00
committed by GitHub
parent 8425831c5d
commit 5edc1186a4
24 changed files with 122 additions and 55 deletions

View File

@@ -17,9 +17,10 @@
import { Component, Input, OnChanges, SimpleChanges, ViewEncapsulation } from '@angular/core';
import { Node } from '@alfresco/js-api';
import { ContentService, AllowableOperationsEnum, VersionCompatibilityService } from '@alfresco/adf-core';
import { ContentService, AllowableOperationsEnum } from '@alfresco/adf-core';
import { NodeAspectService } from '../../../aspect-list/services/node-aspect.service';
import { PresetConfig } from '../../interfaces/content-metadata.interfaces';
import { VersionCompatibilityService } from '../../../version-compatibility/version-compatibility.service';
@Component({
selector: 'adf-content-metadata-card',
templateUrl: './content-metadata-card.component.html',

View File

@@ -17,12 +17,13 @@
import { TestBed } from '@angular/core/testing';
import { ContentTypePropertiesService } from './content-type-property.service';
import { CardViewItem, CardViewSelectItemModel, CardViewTextItemModel, setupTestBed, VersionCompatibilityService } from '@alfresco/adf-core';
import { CardViewItem, CardViewSelectItemModel, CardViewTextItemModel, setupTestBed } from '@alfresco/adf-core';
import { ContentTestingModule } from '../../testing/content.testing.module';
import { TranslateModule } from '@ngx-translate/core';
import { ContentTypeService } from '../../content-type';
import { of } from 'rxjs';
import { Node, TypeEntry } from '@alfresco/js-api';
import { VersionCompatibilityService } from '../../version-compatibility/version-compatibility.service';
describe('ContentTypePropertyService', () => {

View File

@@ -17,7 +17,7 @@
import { Injectable } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { CardViewItem, CardViewSelectItemModel, CardViewSelectItemOption, CardViewTextItemModel, VersionCompatibilityService } from '@alfresco/adf-core';
import { CardViewItem, CardViewSelectItemModel, CardViewSelectItemOption, CardViewTextItemModel } from '@alfresco/adf-core';
import { Observable, of, Subject, zip } from 'rxjs';
import { distinctUntilChanged, map } from 'rxjs/operators';
import { ContentTypeDialogComponent } from '../../content-type/content-type-dialog.component';
@@ -25,6 +25,7 @@ import { ContentTypeDialogComponentData } from '../../content-type/content-type-
import { ContentTypeService } from '../../content-type/content-type.service';
import { Node, Property, TypeEntry } from '@alfresco/js-api';
import { PropertyGroupTranslatorService } from './property-groups-translator.service';
import { VersionCompatibilityService } from '../../version-compatibility/version-compatibility.service';
@Injectable({
providedIn: 'root'

View File

@@ -16,7 +16,7 @@
*/
import { CommonModule } from '@angular/common';
import { NgModule, ModuleWithProviders } from '@angular/core';
import { NgModule, ModuleWithProviders, APP_INITIALIZER } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { CoreModule, TRANSLATION_PROVIDER } from '@alfresco/adf-core';
@@ -41,6 +41,9 @@ import { PermissionManagerModule } from './permission-manager/permission-manager
import { TreeViewModule } from './tree-view/tree-view.module';
import { ContentTypeModule } from './content-type/content-type.module';
import { AspectListModule } from './aspect-list/aspect-list.module';
import { VersionCompatibilityModule } from './version-compatibility/version-compatibility.module';
import { versionCompatibilityFactory } from './version-compatibility/version-compatibility-factory';
import { VersionCompatibilityService } from './version-compatibility/version-compatibility.service';
@NgModule({
imports: [
@@ -67,7 +70,8 @@ import { AspectListModule } from './aspect-list/aspect-list.module';
VersionManagerModule,
TreeViewModule,
ContentTypeModule,
AspectListModule
AspectListModule,
VersionCompatibilityModule
],
providers: [
{
@@ -98,7 +102,8 @@ import { AspectListModule } from './aspect-list/aspect-list.module';
VersionManagerModule,
TreeViewModule,
AspectListModule,
ContentTypeModule
ContentTypeModule,
VersionCompatibilityModule
]
})
export class ContentModule {
@@ -113,6 +118,12 @@ export class ContentModule {
name: 'adf-content-services',
source: 'assets/adf-content-services'
}
},
{
provide: APP_INITIALIZER,
useFactory: versionCompatibilityFactory,
deps: [VersionCompatibilityService],
multi: true
}
]
};

View File

@@ -24,9 +24,10 @@ import {
SitesApi
} from '@alfresco/js-api';
import { BehaviorSubject, from, Observable } from 'rxjs';
import { VersionCompatibilityService, SitesService, AlfrescoApiService } from '@alfresco/adf-core';
import { SitesService, AlfrescoApiService } from '@alfresco/adf-core';
import { LibraryMembershipToggleEvent } from '../interfaces/library-membership-toggle-event.interface';
import { LibraryMembershipErrorEvent} from '../interfaces/library-membership-error-event.interface';
import { VersionCompatibilityService } from '../version-compatibility/version-compatibility.service';
@Directive({
selector: '[adf-library-membership]',

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { NgModule } from '@angular/core';
import { NgModule, APP_INITIALIZER } from '@angular/core';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import {
@@ -31,6 +31,8 @@ import {
} from '@alfresco/adf-core';
import { ContentModule } from '../content.module';
import { TranslateModule } from '@ngx-translate/core';
import { versionCompatibilityFactory } from '../version-compatibility/version-compatibility-factory';
import { VersionCompatibilityService } from '../version-compatibility/version-compatibility.service';
@NgModule({
imports: [
@@ -44,7 +46,13 @@ import { TranslateModule } from '@ngx-translate/core';
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
{ provide: AppConfigService, useClass: AppConfigServiceMock },
{ provide: TranslationService, useClass: TranslationMock },
{ provide: CookieService, useClass: CookieServiceMock }
{ provide: CookieService, useClass: CookieServiceMock },
{
provide: APP_INITIALIZER,
useFactory: versionCompatibilityFactory,
deps: [ VersionCompatibilityService ],
multi: true
}
],
exports: [
NoopAnimationsModule,

View File

@@ -0,0 +1,18 @@
/*!
* @license
* Copyright 2019 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';

View File

@@ -0,0 +1,20 @@
/*!
* @license
* Copyright 2019 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-compatibility.directive';
export * from './version-compatibility.service';
export * from './version-compatibility.module';

View File

@@ -0,0 +1,23 @@
/*!
* @license
* Copyright 2019 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 { VersionCompatibilityService } from './version-compatibility.service';
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
export function versionCompatibilityFactory(versionCompatibilityService: VersionCompatibilityService) {
return () => versionCompatibilityService;
}

View File

@@ -0,0 +1,96 @@
/*!
* @license
* Copyright 2019 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 } from '@angular/core';
import { By } from '@angular/platform-browser';
import { TranslateModule } from '@ngx-translate/core';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { setupTestBed, CoreTestingModule } from '@alfresco/adf-core';
import { VersionCompatibilityService } from './version-compatibility.service';
import { VersionInfo } from '@alfresco/js-api';
import { VersionCompatibilityModule } from './version-compatibility.module';
@Component({
template: `
<div *adf-acs-version="'8'" class="hidden-content-1">
My hidden content 1
</div>
<div *adf-acs-version="'7.1'" class="hidden-content-2">
My hidden content 2
</div>
<div *adf-acs-version="'7.0.2'" class="hidden-content-3">
My hidden content 3
</div>
<div *adf-acs-version="'6.1.5'" class="visible-content-1">
My visible content 1
</div>
<div *adf-acs-version="'6.1'" class="visible-content-2">
My visible content 2
</div>
<div *adf-acs-version="'6'" class="visible-content-3">
My visible content 3
</div>
`
})
class TestComponent { }
describe('VersionCompatibilityDirective', () => {
let fixture: ComponentFixture<TestComponent>;
let versionCompatibilityService: VersionCompatibilityService;
const acsResponceMock = new VersionInfo({
display: '7.0.1',
major: '7',
minor: '0',
patch: '1'
});
setupTestBed({
imports: [
TranslateModule.forRoot(),
CoreTestingModule,
VersionCompatibilityModule
],
declarations: [TestComponent]
});
beforeEach(() => {
fixture = TestBed.createComponent(TestComponent);
versionCompatibilityService = TestBed.inject(VersionCompatibilityService);
spyOn(versionCompatibilityService, 'getAcsVersion').and.returnValue(acsResponceMock);
});
it('should display component when the version is supported', () => {
fixture.detectChanges();
const element1 = fixture.debugElement.query(By.css('[class="visible-content-1"]'));
const element2 = fixture.debugElement.query(By.css('[class="visible-content-2"]'));
const element3 = fixture.debugElement.query(By.css('[class="visible-content-3"]'));
expect(element1).toBeDefined();
expect(element2).toBeDefined();
expect(element3).toBeDefined();
});
it('should hide component when the version is not supported', () => {
fixture.detectChanges();
const element1 = fixture.debugElement.query(By.css('[class="hidden-content-1"]'));
const element2 = fixture.debugElement.query(By.css('[class="hidden-content-2"]'));
const element3 = fixture.debugElement.query(By.css('[class="hidden-content-3"]'));
expect(element1).toBeNull();
expect(element2).toBeNull();
expect(element3).toBeNull();
});
});

View File

@@ -0,0 +1,48 @@
/*!
* @license
* Copyright 2019 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 { Directive, Input, ViewContainerRef, TemplateRef } from '@angular/core';
import { VersionCompatibilityService } from './version-compatibility.service';
import { take } from 'rxjs/operators';
@Directive({
selector: '[adf-acs-version]'
})
export class VersionCompatibilityDirective {
/** Minimum version required for component to work correctly . */
@Input('adf-acs-version')
set version(requiredVersion: string) {
this.validateAcsVersion(requiredVersion);
}
constructor(
private templateRef: TemplateRef<any>,
private viewContainer: ViewContainerRef,
private versionCompatibilityService: VersionCompatibilityService
) {
}
private validateAcsVersion(requiredVersion: string) {
this.versionCompatibilityService.acsVersionInitialized$.pipe(take(1)).subscribe(() => {
this.viewContainer.clear();
if (requiredVersion && this.versionCompatibilityService.isVersionSupported(requiredVersion)) {
this.viewContainer.createEmbeddedView(this.templateRef);
}
});
}
}

View File

@@ -0,0 +1,27 @@
/*!
* @license
* Copyright 2019 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 { VersionCompatibilityDirective } from './version-compatibility.directive';
@NgModule({
imports: [CommonModule],
exports: [VersionCompatibilityDirective],
declarations: [VersionCompatibilityDirective]
})
export class VersionCompatibilityModule {}

View File

@@ -0,0 +1,81 @@
/*!
* @license
* Copyright 2019 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 { CoreTestingModule, DiscoveryApiService, setupTestBed } from '@alfresco/adf-core';
import { RepositoryInfo } from '@alfresco/js-api';
import { TestBed } from '@angular/core/testing';
import { TranslateModule } from '@ngx-translate/core';
import { BehaviorSubject } from 'rxjs';
import { VersionCompatibilityService } from './version-compatibility.service';
describe('VersionCompatibilityService', () => {
let versionCompatibilityService: VersionCompatibilityService;
let discoveryApiService: DiscoveryApiService;
const mockProductInfo = new BehaviorSubject<RepositoryInfo>(null);
const acsResponceMock = {
version: {
display: '7.0.1',
major: '7',
minor: '0',
patch: '1'
}
};
setupTestBed({
imports: [
TranslateModule.forRoot(),
CoreTestingModule
],
providers: [
{
provide: DiscoveryApiService,
useValue: {
ecmProductInfo$: mockProductInfo
}
}
]
});
beforeEach(async () => {
discoveryApiService = TestBed.inject(DiscoveryApiService);
versionCompatibilityService = TestBed.inject(VersionCompatibilityService);
mockProductInfo.next(acsResponceMock as RepositoryInfo);
versionCompatibilityService = new VersionCompatibilityService(discoveryApiService);
});
it('should get ACS running version', () => {
const acsVersion = versionCompatibilityService.getAcsVersion();
expect(acsVersion).toBeDefined();
expect(acsVersion.display).toBe('7.0.1');
});
it('should validate give version', () => {
expect(versionCompatibilityService.getAcsVersion()).toEqual({ display: '7.0.1', major: '7', minor: '0', patch: '1' } as any);
expect(versionCompatibilityService.isVersionSupported('8.0.0')).toBe(false);
expect(versionCompatibilityService.isVersionSupported('7.0.1')).toBe(true);
expect(versionCompatibilityService.isVersionSupported('7.0.0')).toBe(true);
expect(versionCompatibilityService.isVersionSupported('6.0.0')).toBe(true);
});
it('should emit versionCompatibilityInitialized after retrieving acs version', (done) => {
versionCompatibilityService.acsVersionInitialized$.subscribe(() => {
expect(versionCompatibilityService.getAcsVersion()).toEqual({ display: '7.0.1', major: '7', minor: '0', patch: '1' } as any);
done();
});
});
});

View File

@@ -0,0 +1,80 @@
/*!
* @license
* Copyright 2019 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 { Injectable } from '@angular/core';
import { filter } from 'rxjs/operators';
import { ReplaySubject } from 'rxjs';
import { VersionInfo, RepositoryInfo } from '@alfresco/js-api';
import { DiscoveryApiService } from '@alfresco/adf-core';
@Injectable({
providedIn: 'root'
})
export class VersionCompatibilityService {
private acsVersion: VersionInfo;
acsVersionInitialized$ = new ReplaySubject();
constructor(private discoveryApiService: DiscoveryApiService) {
this.discoveryApiService.ecmProductInfo$
.pipe(filter(acsInfo => !!acsInfo))
.subscribe((acsInfo: RepositoryInfo) => this.initializeAcsVersion(acsInfo.version));
}
private initializeAcsVersion(acsVersion: VersionInfo) {
this.acsVersion = acsVersion;
this.acsVersionInitialized$.next();
}
getAcsVersion(): VersionInfo {
return this.acsVersion;
}
isVersionSupported(requiredVersion: string): boolean {
const parsedRequiredVersion = this.parseVersion(requiredVersion);
const currentVersion = this.getAcsVersion();
let versionSupported = false;
if (currentVersion) {
if (+currentVersion.major > +parsedRequiredVersion.major) {
versionSupported = true;
} else if (currentVersion.major === parsedRequiredVersion.major &&
+currentVersion.minor > +parsedRequiredVersion.minor) {
versionSupported = true;
} else if (currentVersion.major === parsedRequiredVersion.major &&
currentVersion.minor === parsedRequiredVersion.minor &&
+currentVersion.patch >= +parsedRequiredVersion.patch) {
versionSupported = true;
}
}
return versionSupported;
}
private parseVersion(version: string): VersionInfo {
const major = version.split('.')[0];
const minor = version.split('.')[1] || '0';
const patch = version.split('.')[2] || '0';
return {
major,
minor,
patch
} as VersionInfo;
}
}

View File

@@ -24,6 +24,7 @@ import { VersionUploadComponent } from './version-upload.component';
import { VersionManagerComponent } from './version-manager.component';
import { VersionListComponent } from './version-list.component';
import { UploadModule } from '../upload/upload.module';
import { VersionCompatibilityModule } from '../version-compatibility/version-compatibility.module';
import { CoreModule } from '@alfresco/adf-core';
import { VersionComparisonComponent } from './version-comparison.component';
@@ -33,6 +34,7 @@ import { VersionComparisonComponent } from './version-comparison.component';
MaterialModule,
CoreModule,
UploadModule,
VersionCompatibilityModule,
FormsModule
],
exports: [

View File

@@ -37,5 +37,6 @@ export * from './lib/aspect-list/index';
export * from './lib/content-type/index';
export * from './lib/new-version-uploader';
export * from './lib/interfaces/index';
export * from './lib/version-compatibility/index';
export * from './lib/content.module';