mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-3778] TaskFilterCloud - should render only My Task and Completed task (#4000)
* Change the MyTask with assignee and generate an unique id * save the taskfilter by user * Add taskFilters value on the query params * Fix the unit tests * use js api beta version * Rebase against development * Filter the filters by id name or index * Add the ability to translate and filter by key * make properties optionals * Remove import duplication
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<h2>TASK LIST CLOUD DEMO</h2>
|
<h2>TASK LIST CLOUD DEMO</h2>
|
||||||
<adf-cloud-task-filters
|
<adf-cloud-task-filters
|
||||||
[appName]="'my-app'"
|
[appName]="applicationName"
|
||||||
[showIcons]="true"
|
[showIcons]="true"
|
||||||
(filterClick)="onFilterSelected($event)">
|
(filterClick)="onFilterSelected($event)">
|
||||||
</adf-cloud-task-filters>
|
</adf-cloud-task-filters>
|
||||||
|
@@ -107,8 +107,10 @@ export class TaskListCloudDemoComponent implements OnInit {
|
|||||||
|
|
||||||
onFilterSelected(filter) {
|
onFilterSelected(filter) {
|
||||||
const queryParams = {
|
const queryParams = {
|
||||||
status: filter.query.state,
|
id: filter.id,
|
||||||
filterName: filter.name,
|
filterName: filter.name,
|
||||||
|
status: filter.query.state,
|
||||||
|
assignee: filter.query.assignment,
|
||||||
sort: filter.query.sort,
|
sort: filter.query.sort,
|
||||||
order: filter.query.order
|
order: filter.query.order
|
||||||
};
|
};
|
||||||
|
60
docs/process-services-cloud/task-filters-cloud.component.md
Normal file
60
docs/process-services-cloud/task-filters-cloud.component.md
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
---
|
||||||
|
Added: v3.0.0
|
||||||
|
Status: Active
|
||||||
|
Last reviewed: 2018-20-11
|
||||||
|
---
|
||||||
|
|
||||||
|
# Task Filters Cloud component
|
||||||
|
|
||||||
|
Shows all available filters.
|
||||||
|
|
||||||
|
## Basic Usage
|
||||||
|
|
||||||
|
```html
|
||||||
|
<adf-cloud-task-filters></adf-cloud-task-filters>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Class members
|
||||||
|
|
||||||
|
### Properties
|
||||||
|
|
||||||
|
| Name | Type | Default value | Description |
|
||||||
|
| ---- | ---- | ------------- | ----------- |
|
||||||
|
| appName | `string` | | Display filters available to the current user for the application with the specified name. |
|
||||||
|
| filterParam | [`FilterParamsModel`](../../lib/process-services-cloud/src/lib/task-cloud/models/filter-cloud.model.ts) | | Parameters to use for the task filter cloud. If there is no match then the default filter (the first one the list) is selected. |
|
||||||
|
| showIcon | `boolean` | | Toggles display of the filter's icon. |
|
||||||
|
|
||||||
|
### Events
|
||||||
|
|
||||||
|
| Name | Type | Description |
|
||||||
|
| ---- | ---- | ----------- |
|
||||||
|
| error | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<any>` | Emitted when an error occurs during loading. |
|
||||||
|
| filterClick | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<`[`TaskFilterCloudRepresentationModel`](../../lib/process-services-cloud/src/lib/task-cloud/models/filter-cloud.model.ts)`>` | Emitted when a filter in the list is clicked. |
|
||||||
|
| success | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<any>` | Emitted when the list is loaded. |
|
||||||
|
|
||||||
|
## Details
|
||||||
|
|
||||||
|
### Filtering APS2 task filters
|
||||||
|
|
||||||
|
Use the `filterParam` property to restrict the range of filters that are shown:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<adf-cloud-task-filters
|
||||||
|
[filterParam]="{name:'My tasks'}">
|
||||||
|
</adf-cloud-task-filters>
|
||||||
|
```
|
||||||
|
|
||||||
|
You can use properties from [`FilterParamsModel`](../../lib/process-services-cloud/src/lib/task-cloud/models/filter-cloud.model.ts)
|
||||||
|
as the value of `filterParam` as shown in the table below:
|
||||||
|
|
||||||
|
| Name | Type | Description |
|
||||||
|
| ---- | ---- | ----------- |
|
||||||
|
| id | string | The id of the task filter |
|
||||||
|
| name | string | The name of the task filter, lowercase is checked |
|
||||||
|
| key | string | The key of the task filter |
|
||||||
|
| index | string | The zero-based position of the filter in the array. |
|
||||||
|
|
||||||
|
### How to create an accordion menu with the task filter cloud
|
||||||
|
|
||||||
|
The task filter cloud often works well as an item in an accordion menu. See the
|
||||||
|
[Material Accordion component]((https://material.angular.io/components/expansion/overview#accordion))
|
@@ -1,10 +1,13 @@
|
|||||||
{
|
{
|
||||||
"TEST_KEY": "MY TEST",
|
"ADF_CLOUD_PROCESS_LIST": {
|
||||||
"ADF-PROCESS-LIST-CLOUD": {
|
|
||||||
"MESSAGES": {
|
"MESSAGES": {
|
||||||
"TITLE": "No Processes Found",
|
"TITLE": "No Processes Found",
|
||||||
"SUBTITLE":"Create a new process that you want to easily find later",
|
"SUBTITLE":"Create a new process that you want to easily find later",
|
||||||
"NONE": "No process instance filter selected."
|
"NONE": "No process instance filter selected."
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"ADF_CLOUD_TASK_FILTERS": {
|
||||||
|
"MY_TASKS": "My Tasks",
|
||||||
|
"COMPLETED_TASKS": "Completed Tasks"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
lib/process-services-cloud/src/lib/i18n/it.json
Normal file
13
lib/process-services-cloud/src/lib/i18n/it.json
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"ADF_CLOUD_TASK_PROCESS_LIST": {
|
||||||
|
"MESSAGES": {
|
||||||
|
"TITLE": "Nessun processo trovato",
|
||||||
|
"SUBTITLE":"Crea un nuovo processo",
|
||||||
|
"NONE": "Nessun filtro per processo selezionato."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ADF_CLOUD_TASK_FILTERS": {
|
||||||
|
"MY_TASKS": "Miei compiti",
|
||||||
|
"COMPLETED_TASKS": "Compiti completati"
|
||||||
|
}
|
||||||
|
}
|
@@ -19,8 +19,8 @@
|
|||||||
<ng-template>
|
<ng-template>
|
||||||
<adf-empty-content *ngIf="!emptyCustomContent"
|
<adf-empty-content *ngIf="!emptyCustomContent"
|
||||||
icon="assessment"
|
icon="assessment"
|
||||||
[title]="'ADF-PROCESS-LIST-CLOUD.MESSAGES.TITLE' | translate"
|
[title]="'ADF_CLOUD_TASK_PROCESS_LIST.MESSAGES.TITLE' | translate"
|
||||||
[subtitle]="'ADF-PROCESS-LIST-CLOUD.MESSAGES.SUBTITLE'| translate">
|
[subtitle]="'ADF_CLOUD_TASK_PROCESS_LIST.MESSAGES.SUBTITLE'| translate">
|
||||||
</adf-empty-content>
|
</adf-empty-content>
|
||||||
<ng-content select="adf-empty-custom-content"></ng-content>
|
<ng-content select="adf-empty-custom-content"></ng-content>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
@@ -33,15 +33,19 @@ export class QueryModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export class FilterRepresentationModel {
|
export class TaskFilterCloudRepresentationModel {
|
||||||
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
key: string;
|
||||||
icon: string;
|
icon: string;
|
||||||
query: QueryModel;
|
query: QueryModel;
|
||||||
|
|
||||||
constructor(obj?: any) {
|
constructor(obj?: any) {
|
||||||
if (obj) {
|
if (obj) {
|
||||||
this.name = obj.name || null;
|
this.id = obj.id;
|
||||||
this.icon = obj.icon || null;
|
this.name = obj.name;
|
||||||
|
this.key = obj.key;
|
||||||
|
this.icon = obj.icon;
|
||||||
this.query = new QueryModel(obj.query);
|
this.query = new QueryModel(obj.query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,3 +54,18 @@ export class FilterRepresentationModel {
|
|||||||
return !!this.query;
|
return !!this.query;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
export class FilterParamsModel {
|
||||||
|
id?: string;
|
||||||
|
name?: string;
|
||||||
|
key?: string;
|
||||||
|
index?: number;
|
||||||
|
|
||||||
|
constructor(obj?: any) {
|
||||||
|
if (obj) {
|
||||||
|
this.id = obj.id || null;
|
||||||
|
this.name = obj.name || null;
|
||||||
|
this.key = obj.key || null;
|
||||||
|
this.index = obj.index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -15,16 +15,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { LogService, StorageService } from '@alfresco/adf-core';
|
import { StorageService, JwtHelperService } from '@alfresco/adf-core';
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Observable, forkJoin } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { FilterRepresentationModel, QueryModel } from '../models/filter-cloud.model';
|
import { TaskFilterCloudRepresentationModel, QueryModel } from '../models/filter-cloud.model';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TaskFilterCloudService {
|
export class TaskFilterCloudService {
|
||||||
|
|
||||||
constructor(private logService: LogService,
|
constructor(private storage: StorageService, private jwtService: JwtHelperService) {
|
||||||
private storage: StorageService) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,34 +31,14 @@ export class TaskFilterCloudService {
|
|||||||
* @param appName Name of the target app
|
* @param appName Name of the target app
|
||||||
* @returns Observable of default filters just created
|
* @returns Observable of default filters just created
|
||||||
*/
|
*/
|
||||||
public createDefaultFilters(appName: string): Observable<FilterRepresentationModel[]> {
|
public createDefaultFilters(appName: string): Observable<TaskFilterCloudRepresentationModel[]> {
|
||||||
let involvedTasksFilter = this.getInvolvedTasksFilterInstance(appName);
|
|
||||||
let involvedObservable = this.addFilter(involvedTasksFilter);
|
|
||||||
|
|
||||||
let myTasksFilter = this.getMyTasksFilterInstance(appName);
|
let myTasksFilter = this.getMyTasksFilterInstance(appName);
|
||||||
let myTaskObservable = this.addFilter(myTasksFilter);
|
this.addFilter(myTasksFilter);
|
||||||
|
|
||||||
let queuedTasksFilter = this.getQueuedTasksFilterInstance(appName);
|
|
||||||
let queuedObservable = this.addFilter(queuedTasksFilter);
|
|
||||||
|
|
||||||
let completedTasksFilter = this.getCompletedTasksFilterInstance(appName);
|
let completedTasksFilter = this.getCompletedTasksFilterInstance(appName);
|
||||||
let completeObservable = this.addFilter(completedTasksFilter);
|
this.addFilter(completedTasksFilter);
|
||||||
|
|
||||||
return new Observable((observer) => {
|
return this.getTaskListFilters(appName);
|
||||||
forkJoin(
|
|
||||||
involvedObservable,
|
|
||||||
myTaskObservable,
|
|
||||||
queuedObservable,
|
|
||||||
completeObservable
|
|
||||||
).subscribe(
|
|
||||||
(filters) => {
|
|
||||||
observer.next(filters);
|
|
||||||
observer.complete();
|
|
||||||
},
|
|
||||||
(err: any) => {
|
|
||||||
this.logService.error(err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,8 +46,9 @@ export class TaskFilterCloudService {
|
|||||||
* @param appName Name of the target app
|
* @param appName Name of the target app
|
||||||
* @returns Observable of task filter details
|
* @returns Observable of task filter details
|
||||||
*/
|
*/
|
||||||
getTaskListFilters(appName?: string): Observable<FilterRepresentationModel[]> {
|
getTaskListFilters(appName?: string): Observable<TaskFilterCloudRepresentationModel[]> {
|
||||||
let key = 'task-filters-' + appName;
|
const username = this.getUsername();
|
||||||
|
let key = `task-filters-${appName}-${username}`;
|
||||||
const filters = JSON.parse(this.storage.getItem(key) || '[]');
|
const filters = JSON.parse(this.storage.getItem(key) || '[]');
|
||||||
return new Observable(function(observer) {
|
return new Observable(function(observer) {
|
||||||
observer.next(filters);
|
observer.next(filters);
|
||||||
@@ -81,8 +61,9 @@ export class TaskFilterCloudService {
|
|||||||
* @param filter The new filter to add
|
* @param filter The new filter to add
|
||||||
* @returns Details of task filter just added
|
* @returns Details of task filter just added
|
||||||
*/
|
*/
|
||||||
addFilter(filter: FilterRepresentationModel): Observable<FilterRepresentationModel> {
|
addFilter(filter: TaskFilterCloudRepresentationModel): Observable<TaskFilterCloudRepresentationModel> {
|
||||||
const key = 'task-filters-' + filter.query.appName || '0';
|
const username = this.getUsername();
|
||||||
|
const key = `task-filters-${filter.query.appName}-${username}`;
|
||||||
let filters = JSON.parse(this.storage.getItem(key) || '[]');
|
let filters = JSON.parse(this.storage.getItem(key) || '[]');
|
||||||
|
|
||||||
filters.push(filter);
|
filters.push(filter);
|
||||||
@@ -95,25 +76,18 @@ export class TaskFilterCloudService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
getUsername(): string {
|
||||||
* Creates and returns a filter for "Involved" task instances.
|
return this.getValueFromToken<string>('preferred_username');
|
||||||
* @param appName Name of the target app
|
|
||||||
* @returns The newly created filter
|
|
||||||
*/
|
|
||||||
getInvolvedTasksFilterInstance(appName: string): FilterRepresentationModel {
|
|
||||||
return new FilterRepresentationModel({
|
|
||||||
name: 'Cancelled Tasks',
|
|
||||||
icon: 'view_headline',
|
|
||||||
query: new QueryModel(
|
|
||||||
{
|
|
||||||
appName: appName,
|
|
||||||
sort: 'id',
|
|
||||||
state: 'CANCELLED',
|
|
||||||
assignment: 'involved',
|
|
||||||
order: 'DESC'
|
|
||||||
}
|
}
|
||||||
)
|
|
||||||
});
|
getValueFromToken<T>(key: string): T {
|
||||||
|
let value;
|
||||||
|
const token = localStorage.getItem('access_token');
|
||||||
|
if (token) {
|
||||||
|
const tokenPayload = this.jwtService.decodeToken(token);
|
||||||
|
value = tokenPayload[key];
|
||||||
|
}
|
||||||
|
return <T> value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -121,58 +95,42 @@ export class TaskFilterCloudService {
|
|||||||
* @param appName Name of the target app
|
* @param appName Name of the target app
|
||||||
* @returns The newly created filter
|
* @returns The newly created filter
|
||||||
*/
|
*/
|
||||||
getMyTasksFilterInstance(appName: string): FilterRepresentationModel {
|
getMyTasksFilterInstance(appName: string): TaskFilterCloudRepresentationModel {
|
||||||
return new FilterRepresentationModel({
|
const username = this.getUsername();
|
||||||
name: 'My Tasks',
|
return new TaskFilterCloudRepresentationModel({
|
||||||
|
id: Math.random().toString(36).substr(2, 9),
|
||||||
|
name: 'ADF_CLOUD_TASK_FILTERS.MY_TASKS',
|
||||||
|
key: 'my-tasks',
|
||||||
icon: 'inbox',
|
icon: 'inbox',
|
||||||
query: new QueryModel(
|
query: new QueryModel(
|
||||||
{
|
{
|
||||||
appName: appName,
|
appName: appName,
|
||||||
|
state: 'ASSIGNED',
|
||||||
|
assignment: username,
|
||||||
sort: 'id',
|
sort: 'id',
|
||||||
state: 'CREATED',
|
|
||||||
assignment: 'assignee',
|
|
||||||
order: 'ASC'
|
order: 'ASC'
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and returns a filter for "Queued Tasks" task instances.
|
|
||||||
* @param appName Name of the target app
|
|
||||||
* @returns The newly created filter
|
|
||||||
*/
|
|
||||||
getQueuedTasksFilterInstance(appName: string): FilterRepresentationModel {
|
|
||||||
return new FilterRepresentationModel({
|
|
||||||
name: 'Suspended Tasks',
|
|
||||||
icon: 'adjust',
|
|
||||||
query: new QueryModel(
|
|
||||||
{
|
|
||||||
appName: appName,
|
|
||||||
sort: 'createdDate',
|
|
||||||
state: 'SUSPENDED',
|
|
||||||
assignment: 'candidate',
|
|
||||||
order: 'DESC'
|
|
||||||
}
|
|
||||||
)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates and returns a filter for "Completed" task instances.
|
* Creates and returns a filter for "Completed" task instances.
|
||||||
* @param appName Name of the target app
|
* @param appName Name of the target app
|
||||||
* @returns The newly created filter
|
* @returns The newly created filter
|
||||||
*/
|
*/
|
||||||
getCompletedTasksFilterInstance(appName: string): FilterRepresentationModel {
|
getCompletedTasksFilterInstance(appName: string): TaskFilterCloudRepresentationModel {
|
||||||
return new FilterRepresentationModel({
|
return new TaskFilterCloudRepresentationModel({
|
||||||
name: 'Completed Tasks',
|
id: Math.random().toString(36).substr(2, 9),
|
||||||
|
name: 'ADF_CLOUD_TASK_FILTERS.COMPLETED_TASKS',
|
||||||
|
key: 'completed-tasks',
|
||||||
icon: 'done',
|
icon: 'done',
|
||||||
query: new QueryModel(
|
query: new QueryModel(
|
||||||
{
|
{
|
||||||
appName: appName,
|
appName: appName,
|
||||||
sort: 'createdDate',
|
|
||||||
state: 'COMPLETED',
|
state: 'COMPLETED',
|
||||||
assignment: 'involved',
|
assignment: '',
|
||||||
|
sort: 'id',
|
||||||
order: 'ASC'
|
order: 'ASC'
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
<div class="menu-container">
|
<div class="menu-container">
|
||||||
<mat-list class="adf-menu-list" *ngIf="filters$ | async; else loading">
|
<mat-list class="adf-menu-list" *ngIf="filters$ | async as filterList; else loading">
|
||||||
<mat-list-item (click)="selectFilterAndEmit(filter)" *ngFor="let filter of filters$ | async"
|
<mat-list-item (click)="selectFilterAndEmit({id: filter.id})" *ngFor="let filter of filterList"
|
||||||
class="adf-filters__entry" [class.active]="currentFilter === filter">
|
class="adf-filters__entry" [class.active]="currentFilter === filter">
|
||||||
<mat-icon *ngIf="showIcons && filter.icon" matListIcon class="adf-filters__entry-icon">{{filter.icon}}
|
<mat-icon *ngIf="showIcons && filter.icon" matListIcon class="adf-filters__entry-icon">{{filter.icon}}
|
||||||
</mat-icon>
|
</mat-icon>
|
||||||
<span matLine [attr.data-automation-id]="filter.name + '_filter'">{{filter.name}}</span>
|
<span matLine [attr.data-automation-id]="filter.name + '_filter'">{{filter.name | translate}}</span>
|
||||||
</mat-list-item>
|
</mat-list-item>
|
||||||
</mat-list>
|
</mat-list>
|
||||||
<ng-template #loading>
|
<ng-template #loading>
|
||||||
|
@@ -19,7 +19,7 @@ import { SimpleChange } from '@angular/core';
|
|||||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||||
import { setupTestBed } from '@alfresco/adf-core';
|
import { setupTestBed } from '@alfresco/adf-core';
|
||||||
import { from, Observable } from 'rxjs';
|
import { from, Observable } from 'rxjs';
|
||||||
import { FilterRepresentationModel } from '../models/filter-cloud.model';
|
import { TaskFilterCloudRepresentationModel, FilterParamsModel } from '../models/filter-cloud.model';
|
||||||
import { TaskFilterCloudService } from '../services/task-filter-cloud.service';
|
import { TaskFilterCloudService } from '../services/task-filter-cloud.service';
|
||||||
import { TaskFiltersCloudComponent } from './task-filters-cloud.component';
|
import { TaskFiltersCloudComponent } from './task-filters-cloud.component';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
@@ -31,19 +31,19 @@ describe('TaskFiltersCloudComponent', () => {
|
|||||||
let taskFilterService: TaskFilterCloudService;
|
let taskFilterService: TaskFilterCloudService;
|
||||||
|
|
||||||
let fakeGlobalFilter = [
|
let fakeGlobalFilter = [
|
||||||
new FilterRepresentationModel({
|
new TaskFilterCloudRepresentationModel({
|
||||||
name: 'FakeInvolvedTasks',
|
name: 'FakeInvolvedTasks',
|
||||||
icon: 'adjust',
|
icon: 'adjust',
|
||||||
id: 10,
|
id: 10,
|
||||||
filter: {state: 'open', assignment: 'fake-involved'}
|
filter: {state: 'open', assignment: 'fake-involved'}
|
||||||
}),
|
}),
|
||||||
new FilterRepresentationModel({
|
new TaskFilterCloudRepresentationModel({
|
||||||
name: 'FakeMyTasks1',
|
name: 'FakeMyTasks1',
|
||||||
icon: 'done',
|
icon: 'done',
|
||||||
id: 11,
|
id: 11,
|
||||||
filter: {state: 'open', assignment: 'fake-assignee'}
|
filter: {state: 'open', assignment: 'fake-assignee'}
|
||||||
}),
|
}),
|
||||||
new FilterRepresentationModel({
|
new TaskFilterCloudRepresentationModel({
|
||||||
name: 'FakeMyTasks2',
|
name: 'FakeMyTasks2',
|
||||||
icon: 'inbox',
|
icon: 'inbox',
|
||||||
id: 12,
|
id: 12,
|
||||||
@@ -218,7 +218,7 @@ describe('TaskFiltersCloudComponent', () => {
|
|||||||
it('should select the task filter based on the input by name param', async(() => {
|
it('should select the task filter based on the input by name param', async(() => {
|
||||||
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
|
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
|
||||||
|
|
||||||
component.filterParam = new FilterRepresentationModel({ name: 'FakeMyTasks1' });
|
component.filterParam = new FilterParamsModel({ name: 'FakeMyTasks1' });
|
||||||
const appName = 'my-app-1';
|
const appName = 'my-app-1';
|
||||||
let change = new SimpleChange(null, appName, true);
|
let change = new SimpleChange(null, appName, true);
|
||||||
|
|
||||||
@@ -236,7 +236,7 @@ describe('TaskFiltersCloudComponent', () => {
|
|||||||
it('should select the default task filter if filter input does not exist', async(() => {
|
it('should select the default task filter if filter input does not exist', async(() => {
|
||||||
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
|
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
|
||||||
|
|
||||||
component.filterParam = new FilterRepresentationModel({ name: 'UnexistableFilter' });
|
component.filterParam = new FilterParamsModel({ name: 'UnexistableFilter' });
|
||||||
|
|
||||||
const appName = 'my-app-1';
|
const appName = 'my-app-1';
|
||||||
let change = new SimpleChange(null, appName, true);
|
let change = new SimpleChange(null, appName, true);
|
||||||
@@ -255,7 +255,7 @@ describe('TaskFiltersCloudComponent', () => {
|
|||||||
it('should select the task filter based on the input by index param', async(() => {
|
it('should select the task filter based on the input by index param', async(() => {
|
||||||
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
|
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
|
||||||
|
|
||||||
component.filterParam = new FilterRepresentationModel({ index: 2 });
|
component.filterParam = new FilterParamsModel({ index: 2 });
|
||||||
|
|
||||||
const appName = 'my-app-1';
|
const appName = 'my-app-1';
|
||||||
let change = new SimpleChange(null, appName, true);
|
let change = new SimpleChange(null, appName, true);
|
||||||
@@ -274,7 +274,7 @@ describe('TaskFiltersCloudComponent', () => {
|
|||||||
it('should select the task filter based on the input by id param', async(() => {
|
it('should select the task filter based on the input by id param', async(() => {
|
||||||
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
|
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
|
||||||
|
|
||||||
component.filterParam = new FilterRepresentationModel({ id: 12 });
|
component.filterParam = new FilterParamsModel({ id: 12 });
|
||||||
|
|
||||||
const appName = 'my-app-1';
|
const appName = 'my-app-1';
|
||||||
let change = new SimpleChange(null, appName, true);
|
let change = new SimpleChange(null, appName, true);
|
||||||
@@ -293,7 +293,7 @@ describe('TaskFiltersCloudComponent', () => {
|
|||||||
it('should emit an event when a filter is selected', async(() => {
|
it('should emit an event when a filter is selected', async(() => {
|
||||||
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
|
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
|
||||||
|
|
||||||
component.filterParam = new FilterRepresentationModel({ id: 12 });
|
component.filterParam = new FilterParamsModel({ id: 12 });
|
||||||
|
|
||||||
const appName = 'my-app-1';
|
const appName = 'my-app-1';
|
||||||
let change = new SimpleChange(null, appName, true);
|
let change = new SimpleChange(null, appName, true);
|
||||||
@@ -303,7 +303,7 @@ describe('TaskFiltersCloudComponent', () => {
|
|||||||
spyOn(component, 'selectFilterAndEmit').and.stub();
|
spyOn(component, 'selectFilterAndEmit').and.stub();
|
||||||
let filterButton = fixture.debugElement.nativeElement.querySelector('span[data-automation-id="FakeMyTasks1_filter"]');
|
let filterButton = fixture.debugElement.nativeElement.querySelector('span[data-automation-id="FakeMyTasks1_filter"]');
|
||||||
filterButton.click();
|
filterButton.click();
|
||||||
expect(component.selectFilterAndEmit).toHaveBeenCalledWith(fakeGlobalFilter[1]);
|
expect(component.selectFilterAndEmit).toHaveBeenCalledWith({id: fakeGlobalFilter[1].id});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should reload filters by appName on binding changes', () => {
|
it('should reload filters by appName on binding changes', () => {
|
||||||
@@ -349,11 +349,11 @@ describe('TaskFiltersCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return the current filter after one is selected', () => {
|
it('should return the current filter after one is selected', () => {
|
||||||
let filter = fakeGlobalFilter[1];
|
let filter = new FilterParamsModel({ name: 'FakeInvolvedTasks' });
|
||||||
component.filters = fakeGlobalFilter;
|
component.filters = fakeGlobalFilter;
|
||||||
|
|
||||||
expect(component.currentFilter).toBeUndefined();
|
expect(component.currentFilter).toBeUndefined();
|
||||||
component.selectFilter(filter);
|
component.selectFilter(filter);
|
||||||
expect(component.getCurrentFilter()).toBe(filter);
|
expect(component.getCurrentFilter()).toBe(fakeGlobalFilter[1]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -18,7 +18,8 @@
|
|||||||
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
|
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { TaskFilterCloudService } from '../services/task-filter-cloud.service';
|
import { TaskFilterCloudService } from '../services/task-filter-cloud.service';
|
||||||
import { FilterRepresentationModel } from '../models/filter-cloud.model';
|
import { TaskFilterCloudRepresentationModel, FilterParamsModel } from '../models/filter-cloud.model';
|
||||||
|
import { TranslationService } from '@alfresco/adf-core';
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'adf-cloud-task-filters',
|
selector: 'adf-cloud-task-filters',
|
||||||
templateUrl: './task-filters-cloud.component.html',
|
templateUrl: './task-filters-cloud.component.html',
|
||||||
@@ -30,13 +31,13 @@ export class TaskFiltersCloudComponent implements OnChanges {
|
|||||||
appName: string;
|
appName: string;
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
filterParam: FilterRepresentationModel;
|
filterParam: FilterParamsModel;
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
showIcons: boolean = false;
|
showIcons: boolean = false;
|
||||||
|
|
||||||
@Output()
|
@Output()
|
||||||
filterClick: EventEmitter<FilterRepresentationModel> = new EventEmitter<FilterRepresentationModel>();
|
filterClick: EventEmitter<TaskFilterCloudRepresentationModel> = new EventEmitter<TaskFilterCloudRepresentationModel>();
|
||||||
|
|
||||||
@Output()
|
@Output()
|
||||||
success: EventEmitter<any> = new EventEmitter<any>();
|
success: EventEmitter<any> = new EventEmitter<any>();
|
||||||
@@ -44,19 +45,19 @@ export class TaskFiltersCloudComponent implements OnChanges {
|
|||||||
@Output()
|
@Output()
|
||||||
error: EventEmitter<any> = new EventEmitter<any>();
|
error: EventEmitter<any> = new EventEmitter<any>();
|
||||||
|
|
||||||
filters$: Observable<FilterRepresentationModel[]>;
|
filters$: Observable<TaskFilterCloudRepresentationModel[]>;
|
||||||
|
|
||||||
currentFilter: FilterRepresentationModel;
|
currentFilter: TaskFilterCloudRepresentationModel;
|
||||||
|
|
||||||
filters: FilterRepresentationModel [] = [];
|
filters: TaskFilterCloudRepresentationModel [] = [];
|
||||||
|
|
||||||
constructor(private taskFilterCloudService: TaskFilterCloudService) {
|
constructor(private taskFilterCloudService: TaskFilterCloudService, private translationService: TranslationService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnChanges(changes: SimpleChanges) {
|
ngOnChanges(changes: SimpleChanges) {
|
||||||
const appName = changes['appName'];
|
const appName = changes['appName'];
|
||||||
const filter = changes['filterParam'];
|
const filter = changes['filterParam'];
|
||||||
if (appName && appName.currentValue) {
|
if (appName && appName.currentValue !== appName.previousValue) {
|
||||||
this.getFilters(appName.currentValue);
|
this.getFilters(appName.currentValue);
|
||||||
} else if (filter && filter.currentValue !== filter.previousValue) {
|
} else if (filter && filter.currentValue !== filter.previousValue) {
|
||||||
this.selectFilter(filter.currentValue);
|
this.selectFilter(filter.currentValue);
|
||||||
@@ -70,7 +71,7 @@ export class TaskFiltersCloudComponent implements OnChanges {
|
|||||||
this.filters$ = this.taskFilterCloudService.getTaskListFilters(appName);
|
this.filters$ = this.taskFilterCloudService.getTaskListFilters(appName);
|
||||||
|
|
||||||
this.filters$.subscribe(
|
this.filters$.subscribe(
|
||||||
(res: FilterRepresentationModel[]) => {
|
(res: TaskFilterCloudRepresentationModel[]) => {
|
||||||
if (res.length === 0) {
|
if (res.length === 0) {
|
||||||
this.createFilters(appName);
|
this.createFilters(appName);
|
||||||
} else {
|
} else {
|
||||||
@@ -93,7 +94,7 @@ export class TaskFiltersCloudComponent implements OnChanges {
|
|||||||
this.filters$ = this.taskFilterCloudService.createDefaultFilters(appName);
|
this.filters$ = this.taskFilterCloudService.createDefaultFilters(appName);
|
||||||
|
|
||||||
this.filters$.subscribe(
|
this.filters$.subscribe(
|
||||||
(resDefault: FilterRepresentationModel[]) => {
|
(resDefault: TaskFilterCloudRepresentationModel[]) => {
|
||||||
this.resetFilter();
|
this.resetFilter();
|
||||||
this.filters = resDefault;
|
this.filters = resDefault;
|
||||||
},
|
},
|
||||||
@@ -103,14 +104,14 @@ export class TaskFiltersCloudComponent implements OnChanges {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public selectFilter(newFilter: FilterParamsModel) {
|
||||||
* Pass the selected filter as next
|
|
||||||
*/
|
|
||||||
public selectFilter(newFilter: FilterRepresentationModel) {
|
|
||||||
if (newFilter) {
|
if (newFilter) {
|
||||||
this.currentFilter = this.filters.find((filter) =>
|
this.currentFilter = this.filters.find( (filter: TaskFilterCloudRepresentationModel, index) =>
|
||||||
|
newFilter.index === index ||
|
||||||
|
newFilter.key === filter.key ||
|
||||||
|
newFilter.id === filter.id ||
|
||||||
(newFilter.name &&
|
(newFilter.name &&
|
||||||
(newFilter.name.toLocaleLowerCase() === filter.name.toLocaleLowerCase())
|
(newFilter.name.toLocaleLowerCase() === this.translationService.instant(filter.name).toLocaleLowerCase())
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if (!this.currentFilter) {
|
if (!this.currentFilter) {
|
||||||
@@ -118,7 +119,7 @@ export class TaskFiltersCloudComponent implements OnChanges {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public selectFilterAndEmit(newFilter: FilterRepresentationModel) {
|
public selectFilterAndEmit(newFilter: FilterParamsModel) {
|
||||||
this.selectFilter(newFilter);
|
this.selectFilter(newFilter);
|
||||||
this.filterClick.emit(this.currentFilter);
|
this.filterClick.emit(this.currentFilter);
|
||||||
}
|
}
|
||||||
@@ -135,7 +136,7 @@ export class TaskFiltersCloudComponent implements OnChanges {
|
|||||||
/**
|
/**
|
||||||
* Return the current task
|
* Return the current task
|
||||||
*/
|
*/
|
||||||
getCurrentFilter(): FilterRepresentationModel {
|
getCurrentFilter(): TaskFilterCloudRepresentationModel {
|
||||||
return this.currentFilter;
|
return this.currentFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -80,11 +80,11 @@
|
|||||||
"@mat-datetimepicker/core": "2.0.1-beta.1",
|
"@mat-datetimepicker/core": "2.0.1-beta.1",
|
||||||
"@mat-datetimepicker/moment": "2.0.1-beta.1",
|
"@mat-datetimepicker/moment": "2.0.1-beta.1",
|
||||||
"@ngx-translate/core": "10.0.2",
|
"@ngx-translate/core": "10.0.2",
|
||||||
|
"@nrwl/nx": "6.3.1",
|
||||||
|
"@nrwl/schematics": "6.3.1",
|
||||||
"adf-tslint-rules": "0.0.4",
|
"adf-tslint-rules": "0.0.4",
|
||||||
"alfresco-js-api": "2.7.0-beta5",
|
"alfresco-js-api": "2.7.0-beta5",
|
||||||
"alfresco-js-api-node": "2.7.0-beta5",
|
"alfresco-js-api-node": "2.7.0-beta5",
|
||||||
"@nrwl/schematics": "6.3.1",
|
|
||||||
"@nrwl/nx": "6.3.1",
|
|
||||||
"chart.js": "2.5.0",
|
"chart.js": "2.5.0",
|
||||||
"classlist.js": "1.1.20150312",
|
"classlist.js": "1.1.20150312",
|
||||||
"core-js": "^2.5.4",
|
"core-js": "^2.5.4",
|
||||||
|
Reference in New Issue
Block a user