From 0b1e5d31d8d2233ca3aa0f77906f5272f29cfd0e Mon Sep 17 00:00:00 2001 From: Silviu Popa Date: Mon, 25 Mar 2019 13:01:43 +0200 Subject: [PATCH] [ADF-4155] ProcessServiceCloud - show AppList when service is missing (#4462) * [ADF-4155] ProcessServiceCloud - show AppList when service is missing * [ADF-4155] - lint * [ADF-4155] - move docs content * [ADF-4155] - reset unnecesary doc file changes * [ADF-4155] - fix unit tests * [ADF-4155] AppListCloudComponent - Fix unit test * [ADF-4155] - remove calls reset * [ADF-4155] - skip app list test * [ADF-4155] - fix unit test * [ADF-4155] - app- list unit test --- demo-shell/src/app.config.json | 3 +- .../services/process-list-cloud.service.md | 14 ++++- .../app-list-cloud.component.spec.ts | 43 +++++++++++----- .../components/app-list-cloud.component.ts | 6 ++- .../services/app-deployment-cloud.service.ts | 51 +++++++++++++++++++ 5 files changed, 102 insertions(+), 15 deletions(-) create mode 100644 lib/process-services-cloud/src/lib/app/services/app-deployment-cloud.service.ts diff --git a/demo-shell/src/app.config.json b/demo-shell/src/app.config.json index 482415ac8a..ca1bd70946 100644 --- a/demo-shell/src/app.config.json +++ b/demo-shell/src/app.config.json @@ -683,5 +683,6 @@ } ] } - } + }, + "alfresco-deployed-apps": [] } diff --git a/docs/process-services-cloud/services/process-list-cloud.service.md b/docs/process-services-cloud/services/process-list-cloud.service.md index 959879f9c1..c371a7e683 100644 --- a/docs/process-services-cloud/services/process-list-cloud.service.md +++ b/docs/process-services-cloud/services/process-list-cloud.service.md @@ -7,7 +7,7 @@ Last reviewed: 2019-02-06 # [Process List Cloud Service](../../../lib/process-services-cloud/src/lib/process/process-list/services/process-list-cloud.service.ts "Defined in process-list-cloud.service.ts") -Searches processes. +Searches processes. ## Class members @@ -23,3 +23,15 @@ Searches processes. Note that for a call to `getProcessByRequest`, the [`ProcessQueryCloudRequestModel`](../../../lib/process-services-cloud/src/lib/process/process-list/models/process-cloud-query-request.model.ts) object must at minimum have the `appName` property correctly set. + +## Activiti 7 + +If you are generating a project for activiti7 you need to add in the **app.config.json** the list of the apps that you desire to use. + +For example : + +```json + "alfresco-deployed-apps" : [{"name": "simple-app"}] +``` + +For more information about the app list component refer to the [documentation](https://github.com/Alfresco/alfresco-ng2-components/blob/development/docs/process-services-cloud/app-list-cloud.component.md) diff --git a/lib/process-services-cloud/src/lib/app/components/app-list-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/app/components/app-list-cloud.component.spec.ts index d5ca202d6f..55ea187214 100644 --- a/lib/process-services-cloud/src/lib/app/components/app-list-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/app/components/app-list-cloud.component.spec.ts @@ -17,34 +17,53 @@ import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { setupTestBed, CoreModule } from '@alfresco/adf-core'; +import { setupTestBed, CoreModule, AlfrescoApiServiceMock, AlfrescoApiService } from '@alfresco/adf-core'; import { of } from 'rxjs'; import { fakeApplicationInstance } from '../mock/app-model.mock'; import { AppListCloudComponent } from './app-list-cloud.component'; import { AppsProcessCloudService } from '../services/apps-process-cloud.service'; import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module'; -import { ApplicationInstanceModel } from '../models/application-instance.model'; import { AppListCloudModule } from '../app-list-cloud.module'; describe('AppListCloudComponent', () => { let component: AppListCloudComponent; let fixture: ComponentFixture; - let service: AppsProcessCloudService; + let appsProcessCloudService: AppsProcessCloudService; let getAppsSpy: jasmine.Spy; + let alfrescoApiService: AlfrescoApiService; - setupTestBed({ - imports: [CoreModule.forRoot(), ProcessServiceCloudTestingModule, AppListCloudModule], - providers: [AppsProcessCloudService] - }); + const mock = { + oauth2Auth: { + callCustomApi: () => Promise.resolve(fakeApplicationInstance) + } + }; - beforeEach(() => { + beforeEach( async(() => { + TestBed.configureTestingModule({ + imports: [CoreModule.forRoot(), ProcessServiceCloudTestingModule, AppListCloudModule], + providers: [ + AppsProcessCloudService + ] + }) + .overrideComponent(AppListCloudComponent, { + set: { + providers: [ + { provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock } + ] + } + }).compileComponents(); + })); + + beforeEach( () => { fixture = TestBed.createComponent(AppListCloudComponent); component = fixture.componentInstance; + alfrescoApiService = TestBed.get(AlfrescoApiService); + appsProcessCloudService = TestBed.get(AppsProcessCloudService); - service = TestBed.get(AppsProcessCloudService); - getAppsSpy = spyOn(service, 'getDeployedApplicationsByStatus').and.returnValue(of(fakeApplicationInstance)); + spyOn(alfrescoApiService, 'getInstance').and.returnValue(mock); + getAppsSpy = spyOn(appsProcessCloudService, 'getDeployedApplicationsByStatus').and.returnValue(of(fakeApplicationInstance)); }); it('should create AppListCloudComponent ', async(() => { @@ -60,7 +79,7 @@ describe('AppListCloudComponent', () => { it('Should fetch deployed apps', async(() => { fixture.detectChanges(); fixture.whenStable().then(() => { - component.apps$.subscribe((response: ApplicationInstanceModel[]) => { + component.apps$.subscribe((response: any[]) => { expect(response).toBeDefined(); expect(response.length).toEqual(3); expect(response[0].name).toEqual('application-new-1'); @@ -72,8 +91,8 @@ describe('AppListCloudComponent', () => { expect(response[1].icon).toEqual('favorite_border'); expect(response[1].theme).toEqual('theme-2'); }); - expect(getAppsSpy).toHaveBeenCalled(); }); + expect(getAppsSpy).toHaveBeenCalled(); })); it('should display default adf-empty-content template when response empty', () => { diff --git a/lib/process-services-cloud/src/lib/app/components/app-list-cloud.component.ts b/lib/process-services-cloud/src/lib/app/components/app-list-cloud.component.ts index d86f88462e..79302daf4c 100644 --- a/lib/process-services-cloud/src/lib/app/components/app-list-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/app/components/app-list-cloud.component.ts @@ -20,11 +20,15 @@ import { Observable } from 'rxjs'; import { AppsProcessCloudService } from '../services/apps-process-cloud.service'; import { ApplicationInstanceModel } from '../models/application-instance.model'; + import { ApplicationDeploymentCloudService } from '../services/app-deployment-cloud.service'; @Component({ selector: 'adf-cloud-app-list', 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 { diff --git a/lib/process-services-cloud/src/lib/app/services/app-deployment-cloud.service.ts b/lib/process-services-cloud/src/lib/app/services/app-deployment-cloud.service.ts new file mode 100644 index 0000000000..b186326fb9 --- /dev/null +++ b/lib/process-services-cloud/src/lib/app/services/app-deployment-cloud.service.ts @@ -0,0 +1,51 @@ +/*! + * @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 { + return this.hasDeployedApps() ? of(this.deployedApps) : super.getDeployedApplicationsByStatus(status); + } + + hasDeployedApps(): boolean { + return this.deployedApps && this.deployedApps.length > 0; + } + + loadApps() { + const apps = this.appConfig.get('alfresco-deployed-apps', []); + apps.map((app) => { + app.theme = app.theme ? app.theme : 'theme-1'; + app.icon = app.icon ? app.icon : 'favorite'; + }); + this.deployedApps = apps; + } +}