Skip to content

Commit

Permalink
[AAE-7243] fix process services eslint warnings (#7498)
Browse files Browse the repository at this point in the history
* fix process services eslint warnings

* fix constants

* revert type changes
  • Loading branch information
DenysVuika committed Feb 17, 2022
1 parent 1a6746f commit e017423
Show file tree
Hide file tree
Showing 91 changed files with 1,815 additions and 1,872 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ import {
ProcessInstanceDetailsComponent,
ProcessInstanceListComponent,
StartProcessInstanceComponent,
AppsListComponent,
FilterRepresentationModel,
TaskDetailsComponent,
TaskDetailsEvent,
TaskFiltersComponent,
TaskListComponent,
ProcessFormRenderingService
ProcessFormRenderingService,
APP_LIST_LAYOUT_LIST
} from '@alfresco/adf-process-services';
import { Subject } from 'rxjs';
import { /*CustomEditorComponent*/ CustomStencil01 } from './custom-editor/custom-editor.component';
Expand Down Expand Up @@ -270,7 +270,7 @@ export class ProcessServiceComponent implements AfterViewInit, OnDestroy, OnInit
this.processFilter = null;
this.currentProcessInstanceId = null;
});
this.layoutType = AppsListComponent.LAYOUT_GRID;
this.layoutType = APP_LIST_LAYOUT_LIST;
}

ngOnDestroy() {
Expand Down
4 changes: 2 additions & 2 deletions lib/process-services/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/consistent-type-assertions": "warn",
"@typescript-eslint/prefer-for-of": "warn",
"no-underscore-dangle": "warn",
"no-underscore-dangle": ["error", { "allowAfterThis": true }],
"no-shadow": "warn",
"quote-props": "warn",
"object-shorthand": "warn",
"prefer-const": "warn",
"arrow-body-style": "warn",
"@angular-eslint/no-output-native": "warn",
"@angular-eslint/no-output-native": "off",
"space-before-function-paren": "warn",

"@angular-eslint/component-selector": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { AppsProcessService, setupTestBed } from '@alfresco/adf-core';
import { of, throwError } from 'rxjs';

import { defaultApp, deployedApps, nonDeployedApps } from '../mock/apps-list.mock';
import { AppsListComponent } from './apps-list.component';
import { AppsListComponent, APP_LIST_LAYOUT_GRID, APP_LIST_LAYOUT_LIST } from './apps-list.component';
import { ProcessTestingModule } from '../testing/process.testing.module';
import { TranslateModule } from '@ngx-translate/core';

Expand Down Expand Up @@ -181,14 +181,14 @@ describe('AppsListComponent', () => {
});

it('should display a grid when configured to', () => {
component.layoutType = AppsListComponent.LAYOUT_GRID;
component.layoutType = APP_LIST_LAYOUT_GRID;
fixture.detectChanges();
expect(component.isGrid()).toBe(true);
expect(component.isList()).toBe(false);
});

it('should display a list when configured to', () => {
component.layoutType = AppsListComponent.LAYOUT_LIST;
component.layoutType = APP_LIST_LAYOUT_LIST;
fixture.detectChanges();
expect(component.isGrid()).toBe(false);
expect(component.isList()).toBe(true);
Expand Down
131 changes: 65 additions & 66 deletions lib/process-services/src/lib/app-list/apps-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ import { AppDefinitionRepresentationModel } from '../task-list';
import { IconModel } from './icon.model';
import { share, takeUntil, finalize } from 'rxjs/operators';

const DEFAULT_TASKS_APP: string = 'tasks';
const DEFAULT_TASKS_APP_NAME: string = 'ADF_TASK_LIST.APPS.TASK_APP_NAME';
const DEFAULT_TASKS_APP_THEME: string = 'theme-2';
const DEFAULT_TASKS_APP_ICON: string = 'glyphicon-asterisk';

export const APP_LIST_LAYOUT_LIST: string = 'LIST';
export const APP_LIST_LAYOUT_GRID: string = 'GRID';

@Component({
selector: 'adf-apps',
templateUrl: './apps-list.component.html',
Expand All @@ -31,45 +39,35 @@ import { share, takeUntil, finalize } from 'rxjs/operators';
})
export class AppsListComponent implements OnInit, AfterContentInit, OnDestroy {

public static LAYOUT_LIST: string = 'LIST';
public static LAYOUT_GRID: string = 'GRID';
public static DEFAULT_TASKS_APP: string = 'tasks';
public static DEFAULT_TASKS_APP_NAME: string = 'ADF_TASK_LIST.APPS.TASK_APP_NAME';
public static DEFAULT_TASKS_APP_THEME: string = 'theme-2';
public static DEFAULT_TASKS_APP_ICON: string = 'glyphicon-asterisk';
public static DEFAULT_TASKS_APP_MATERIAL_ICON: string = 'favorite_border';

@ContentChild(CustomEmptyContentTemplateDirective)
emptyCustomContent: CustomEmptyContentTemplateDirective;

/** (**required**) Defines the layout of the apps. There are two possible
* values, "GRID" and "LIST".
*/
@Input()
layoutType: string = AppsListComponent.LAYOUT_GRID;
layoutType: string = APP_LIST_LAYOUT_GRID;

/** Provides a way to filter the apps to show. */
@Input()
filtersAppId: any[];

/** Emitted when an app entry is clicked. */
@Output()
appClick: EventEmitter<AppDefinitionRepresentationModel> = new EventEmitter<AppDefinitionRepresentationModel>();
appClick = new EventEmitter<AppDefinitionRepresentationModel>();

/** Emitted when an error occurs. */
@Output()
error: EventEmitter<any> = new EventEmitter<any>();
error = new EventEmitter<any>();

private appsObserver: Observer<AppDefinitionRepresentationModel>;
apps$: Observable<AppDefinitionRepresentationModel>;
currentApp: AppDefinitionRepresentationModel;
appList: AppDefinitionRepresentationModel [] = [];

private iconsMDL: IconModel;

loading: boolean = false;
hasEmptyCustomContentTemplate: boolean = false;

private appsObserver: Observer<AppDefinitionRepresentationModel>;
private iconsMDL: IconModel;
private onDestroy$ = new Subject<boolean>();

constructor(
Expand Down Expand Up @@ -103,103 +101,61 @@ export class AppsListComponent implements OnInit, AfterContentInit, OnDestroy {
}
}

private load() {
this.loading = true;
this.appsProcessService
.getDeployedApplications()
.pipe(finalize(() => this.loading = false))
.subscribe(
(res: AppDefinitionRepresentationModel[]) => {
this.filterApps(res).forEach((app) => {
if (this.isDefaultApp(app)) {
app.theme = AppsListComponent.DEFAULT_TASKS_APP_THEME;
app.icon = AppsListComponent.DEFAULT_TASKS_APP_ICON;
this.appsObserver.next(app);
} else if (app.deploymentId) {
this.appsObserver.next(app);
}
});
},
(err) => {
this.error.emit(err);
}
);
}

isDefaultApp(app) {
return app.defaultAppId === AppsListComponent.DEFAULT_TASKS_APP;
return app.defaultAppId === DEFAULT_TASKS_APP;
}

getAppName(app) {
return this.isDefaultApp(app)
? this.translationService.get(AppsListComponent.DEFAULT_TASKS_APP_NAME)
? this.translationService.get(DEFAULT_TASKS_APP_NAME)
: of(app.name);
}

/**
* Pass the selected app as next
*
* @param app
*/
public selectApp(app: AppDefinitionRepresentationModel) {
selectApp(app: AppDefinitionRepresentationModel) {
this.currentApp = app;
this.appClick.emit(app);
}

/**
* Return true if the appId is the current app
*
* @param appId
*/
isSelected(appId: number): boolean {
return (this.currentApp !== undefined && appId === this.currentApp.id);
}

private filterApps(apps: AppDefinitionRepresentationModel []): AppDefinitionRepresentationModel[] {
const filteredApps: AppDefinitionRepresentationModel[] = [];
if (this.filtersAppId) {
apps.filter((app: AppDefinitionRepresentationModel) => {
this.filtersAppId.forEach((filter) => {
if (app.defaultAppId === filter.defaultAppId ||
app.deploymentId === filter.deploymentId ||
app.name === filter.name ||
app.id === filter.id ||
app.modelId === filter.modelId ||
app.tenantId === filter.tenantId) {
filteredApps.push(app);
}
});
});
} else {
return apps;
}
return filteredApps;
}

/**
* Check if the value of the layoutType property is an allowed value
*/
isValidType(): boolean {
return this.layoutType && (this.layoutType === AppsListComponent.LAYOUT_LIST || this.layoutType === AppsListComponent.LAYOUT_GRID);
return this.layoutType && (this.layoutType === APP_LIST_LAYOUT_LIST || this.layoutType === APP_LIST_LAYOUT_GRID);
}

/**
* Assign the default value to LayoutType
*/
setDefaultLayoutType(): void {
this.layoutType = AppsListComponent.LAYOUT_GRID;
this.layoutType = APP_LIST_LAYOUT_GRID;
}

/**
* Return true if the layout type is LIST
*/
isList(): boolean {
return this.layoutType === AppsListComponent.LAYOUT_LIST;
return this.layoutType === APP_LIST_LAYOUT_LIST;
}

/**
* Return true if the layout type is GRID
*/
isGrid(): boolean {
return this.layoutType === AppsListComponent.LAYOUT_GRID;
return this.layoutType === APP_LIST_LAYOUT_GRID;
}

isEmpty(): boolean {
Expand All @@ -218,4 +174,47 @@ export class AppsListComponent implements OnInit, AfterContentInit, OnDestroy {
return this.iconsMDL.mapGlyphiconToMaterialDesignIcons(app.icon);
}

private load() {
this.loading = true;
this.appsProcessService
.getDeployedApplications()
.pipe(finalize(() => this.loading = false))
.subscribe(
(res: AppDefinitionRepresentationModel[]) => {
this.filterApps(res).forEach((app) => {
if (this.isDefaultApp(app)) {
app.theme = DEFAULT_TASKS_APP_THEME;
app.icon = DEFAULT_TASKS_APP_ICON;
this.appsObserver.next(app);
} else if (app.deploymentId) {
this.appsObserver.next(app);
}
});
},
(err) => {
this.error.emit(err);
}
);
}

private filterApps(apps: AppDefinitionRepresentationModel []): AppDefinitionRepresentationModel[] {
const filteredApps: AppDefinitionRepresentationModel[] = [];
if (this.filtersAppId) {
apps.filter((app: AppDefinitionRepresentationModel) => {
this.filtersAppId.forEach((filter) => {
if (app.defaultAppId === filter.defaultAppId ||
app.deploymentId === filter.deploymentId ||
app.name === filter.name ||
app.id === filter.id ||
app.modelId === filter.modelId ||
app.tenantId === filter.tenantId) {
filteredApps.push(app);
}
});
});
} else {
return apps;
}
return filteredApps;
}
}

0 comments on commit e017423

Please sign in to comment.