mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-09-17 14:21:29 +00:00
[ADF-4576] Remove duplicate getDeployedApplicationsByStatus service (#4740)
* * Remove overriding & added appconfig apps support * * Added tests * * Updated docs * [ADF-4576] Made one service private * * Fixed tests * * [ADF-4576] Improved tests
This commit is contained in:
committed by
Eugenio Romano
parent
90617ee3fd
commit
d571480ddd
@@ -16,7 +16,9 @@ Gets details of deployed apps for the current user.
|
|||||||
- **getDeployedApplicationsByStatus**(status: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`ApplicationInstanceModel`](../../../lib/process-services-cloud/src/lib/app/models/application-instance.model.ts)`[]>`<br/>
|
- **getDeployedApplicationsByStatus**(status: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`ApplicationInstanceModel`](../../../lib/process-services-cloud/src/lib/app/models/application-instance.model.ts)`[]>`<br/>
|
||||||
Gets a list of deployed apps for this user by status.
|
Gets a list of deployed apps for this user by status.
|
||||||
- _status:_ `string` - Required status value
|
- _status:_ `string` - Required status value
|
||||||
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`ApplicationInstanceModel`](../../../lib/process-services-cloud/src/lib/app/models/application-instance.model.ts)`[]>` - The list of deployed apps
|
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`ApplicationInstanceModel`](../../../lib/process-services-cloud/src/lib/app/models/application-instance.model.ts)`[]>` - The list of deployed apps.
|
||||||
|
|
||||||
|
You can override the behaviour by defining the required applications in app.config.json against the property `alfresco-deployed-apps`. The service will fetch the deployed apps only when there are no apps defined in the app.config.json
|
||||||
|
|
||||||
## Details
|
## Details
|
||||||
|
|
||||||
|
@@ -20,16 +20,12 @@ import { AfterContentInit, Component, EventEmitter, Input, OnInit, Output, Conte
|
|||||||
import { Observable, of, Subject } from 'rxjs';
|
import { Observable, of, Subject } from 'rxjs';
|
||||||
import { AppsProcessCloudService } from '../services/apps-process-cloud.service';
|
import { AppsProcessCloudService } from '../services/apps-process-cloud.service';
|
||||||
import { ApplicationInstanceModel } from '../models/application-instance.model';
|
import { ApplicationInstanceModel } from '../models/application-instance.model';
|
||||||
import { ApplicationDeploymentCloudService } from '../services/app-deployment-cloud.service';
|
|
||||||
import { catchError } from 'rxjs/operators';
|
import { catchError } from 'rxjs/operators';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'adf-cloud-app-list',
|
selector: 'adf-cloud-app-list',
|
||||||
templateUrl: './app-list-cloud.component.html',
|
templateUrl: './app-list-cloud.component.html',
|
||||||
styleUrls: ['./app-list-cloud.component.scss'],
|
styleUrls: ['./app-list-cloud.component.scss']
|
||||||
providers: [
|
|
||||||
{ provide: AppsProcessCloudService, useClass: ApplicationDeploymentCloudService }
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
export class AppListCloudComponent implements OnInit, AfterContentInit {
|
export class AppListCloudComponent implements OnInit, AfterContentInit {
|
||||||
|
|
||||||
|
@@ -1,51 +0,0 @@
|
|||||||
/*!
|
|
||||||
* @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 { AppConfigService, LogService, AlfrescoApiService } from '@alfresco/adf-core';
|
|
||||||
import { Observable, of } from 'rxjs';
|
|
||||||
import { AppsProcessCloudService } from './apps-process-cloud.service';
|
|
||||||
import { Injectable } from '@angular/core';
|
|
||||||
import { ApplicationInstanceModel } from '../models/application-instance.model';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class ApplicationDeploymentCloudService extends AppsProcessCloudService {
|
|
||||||
|
|
||||||
deployedApps: ApplicationInstanceModel[];
|
|
||||||
|
|
||||||
constructor(apiService: AlfrescoApiService, logService: LogService, private appConfig: AppConfigService) {
|
|
||||||
super(apiService, logService, appConfig);
|
|
||||||
|
|
||||||
this.loadApps();
|
|
||||||
}
|
|
||||||
|
|
||||||
getDeployedApplicationsByStatus(status: string): Observable<ApplicationInstanceModel[]> {
|
|
||||||
return this.hasDeployedApps() ? of(this.deployedApps) : super.getDeployedApplicationsByStatus(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
hasDeployedApps(): boolean {
|
|
||||||
return this.deployedApps && this.deployedApps.length > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
loadApps() {
|
|
||||||
const apps = this.appConfig.get<any>('alfresco-deployed-apps', []);
|
|
||||||
apps.map((app) => {
|
|
||||||
app.theme = app.theme ? app.theme : 'theme-1';
|
|
||||||
app.icon = app.icon ? app.icon : 'favorite';
|
|
||||||
});
|
|
||||||
this.deployedApps = apps;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -16,8 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { TestBed } from '@angular/core/testing';
|
import { TestBed } from '@angular/core/testing';
|
||||||
import { of, throwError } from 'rxjs';
|
import { throwError } from 'rxjs';
|
||||||
import { setupTestBed, CoreModule } from '@alfresco/adf-core';
|
import { setupTestBed, CoreModule, AppConfigService, AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-core';
|
||||||
import { HttpErrorResponse } from '@angular/common/http';
|
import { HttpErrorResponse } from '@angular/common/http';
|
||||||
import { AppsProcessCloudService } from './apps-process-cloud.service';
|
import { AppsProcessCloudService } from './apps-process-cloud.service';
|
||||||
import { fakeApplicationInstance } from '../mock/app-model.mock';
|
import { fakeApplicationInstance } from '../mock/app-model.mock';
|
||||||
@@ -27,27 +27,51 @@ import { ProcessServiceCloudTestingModule } from '../../testing/process-service-
|
|||||||
describe('AppsProcessCloudService', () => {
|
describe('AppsProcessCloudService', () => {
|
||||||
|
|
||||||
let service: AppsProcessCloudService;
|
let service: AppsProcessCloudService;
|
||||||
|
let appConfigService: AppConfigService;
|
||||||
|
let apiService: AlfrescoApiService;
|
||||||
|
|
||||||
|
const apiMock = {
|
||||||
|
oauth2Auth: {
|
||||||
|
callCustomApi: () => Promise.resolve({list : { entries: [ {entry: fakeApplicationInstance[0]}, {entry: fakeApplicationInstance[1]}] }})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
setupTestBed({
|
setupTestBed({
|
||||||
imports: [CoreModule.forRoot(), ProcessServiceCloudTestingModule],
|
imports: [CoreModule.forRoot(), ProcessServiceCloudTestingModule],
|
||||||
providers: [AppsProcessCloudService]
|
providers: [AppsProcessCloudService, AppConfigService,
|
||||||
|
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock } ]
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
service = TestBed.get(AppsProcessCloudService);
|
service = TestBed.get(AppsProcessCloudService);
|
||||||
|
appConfigService = TestBed.get(AppConfigService);
|
||||||
|
apiService = TestBed.get(AlfrescoApiService);
|
||||||
|
spyOn(apiService, 'getInstance').and.returnValue(apiMock);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get the deployed applications ', (done) => {
|
it('should get the deployed applications no apps are specified in app.config', (done) => {
|
||||||
spyOn(service, 'getDeployedApplicationsByStatus').and.returnValue(of(fakeApplicationInstance));
|
spyOn(appConfigService, 'get').and.returnValue([]);
|
||||||
|
service.loadApps();
|
||||||
service.getDeployedApplicationsByStatus('fake').subscribe(
|
service.getDeployedApplicationsByStatus('fake').subscribe(
|
||||||
(res: ApplicationInstanceModel[]) => {
|
(res: ApplicationInstanceModel[]) => {
|
||||||
expect(res).toBeDefined();
|
expect(res).toBeDefined();
|
||||||
expect(res.length).toEqual(3);
|
expect(res.length).toEqual(2);
|
||||||
expect(res).toEqual(fakeApplicationInstance);
|
expect(res[0].name).toEqual('application-new-1');
|
||||||
|
expect(res[1].name).toEqual('application-new-2');
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should get apps from app.config when apps are specified in app.config', (done) => {
|
||||||
|
spyOn(appConfigService, 'get').and.returnValue([fakeApplicationInstance[0]]);
|
||||||
|
service.loadApps();
|
||||||
|
service.getDeployedApplicationsByStatus('fake').subscribe(
|
||||||
|
(res: ApplicationInstanceModel[]) => {
|
||||||
|
expect(res).toBeDefined();
|
||||||
|
expect(res.length).toEqual(1);
|
||||||
expect(res[0]).toEqual(fakeApplicationInstance[0]);
|
expect(res[0]).toEqual(fakeApplicationInstance[0]);
|
||||||
expect(res[0].name).toEqual('application-new-1');
|
expect(res[0].name).toEqual('application-new-1');
|
||||||
expect(res[1]).toEqual(fakeApplicationInstance[1]);
|
|
||||||
expect(res[1].name).toEqual('application-new-2');
|
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@@ -26,10 +26,14 @@ import { ApplicationInstanceModel } from '../models/application-instance.model';
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class AppsProcessCloudService {
|
export class AppsProcessCloudService {
|
||||||
|
|
||||||
|
deployedApps: ApplicationInstanceModel[];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private apiService: AlfrescoApiService,
|
private apiService: AlfrescoApiService,
|
||||||
private logService: LogService,
|
private logService: LogService,
|
||||||
private appConfigService: AppConfigService) {
|
private appConfigService: AppConfigService) {
|
||||||
|
|
||||||
|
this.loadApps();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,6 +42,23 @@ export class AppsProcessCloudService {
|
|||||||
* @returns The list of deployed apps
|
* @returns The list of deployed apps
|
||||||
*/
|
*/
|
||||||
getDeployedApplicationsByStatus(status: string): Observable<ApplicationInstanceModel[]> {
|
getDeployedApplicationsByStatus(status: string): Observable<ApplicationInstanceModel[]> {
|
||||||
|
return this.hasDeployedApps() ? of(this.deployedApps) : this.getApplicationsByStatus(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
hasDeployedApps(): boolean {
|
||||||
|
return this.deployedApps && this.deployedApps.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
loadApps() {
|
||||||
|
const apps = this.appConfigService.get<any>('alfresco-deployed-apps', []);
|
||||||
|
apps.map((app) => {
|
||||||
|
app.theme = app.theme ? app.theme : 'theme-1';
|
||||||
|
app.icon = app.icon ? app.icon : 'favorite';
|
||||||
|
});
|
||||||
|
this.deployedApps = apps;
|
||||||
|
}
|
||||||
|
|
||||||
|
private getApplicationsByStatus(status: string): Observable<ApplicationInstanceModel[]> {
|
||||||
if (status === '') {
|
if (status === '') {
|
||||||
return of([]);
|
return of([]);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user