-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #240 from netgrif/NAE-1957
[NAE-1957] Allow filter to caseRef field and variants
- Loading branch information
Showing
4 changed files
with
81 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...s-core/src/lib/data-fields/case-ref-field/model/abstract-case-ref-base-field-component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import {AbstractBaseDataFieldComponent} from '../../base-component/abstract-base-data-field.component'; | ||
import {CaseRefField} from './case-ref-field'; | ||
import { Inject, Injector, Optional, Type} from '@angular/core'; | ||
import {ComponentPortal} from '@angular/cdk/portal'; | ||
import {DATA_FIELD_PORTAL_DATA, DataFieldPortalData} from '../../models/data-field-portal-data-injection-token'; | ||
import {CaseSearchRequestBody} from '../../../filter/models/case-search-request-body'; | ||
import {NAE_DEFAULT_HEADERS} from '../../../header/models/default-headers-token'; | ||
import {NAE_CASE_REF_CREATE_CASE, NAE_CASE_REF_DATAFIELD, NAE_CASE_REF_SEARCH} from './case-ref-injection-tokens'; | ||
import {NAE_BASE_FILTER} from '../../../search/models/base-filter-injection-token'; | ||
import {SimpleFilter} from '../../../filter/models/simple-filter'; | ||
import {BaseFilter} from '../../../search/models/base-filter'; | ||
import {NAE_VIEW_ID_SEGMENT} from '../../../user/models/view-id-injection-tokens'; | ||
import {ViewIdService} from '../../../user/services/view-id.service'; | ||
import {DataField} from '../../models/abstract-data-field'; | ||
|
||
export abstract class AbstractCaseRefBaseFieldComponent<T extends DataField<unknown>> extends AbstractBaseDataFieldComponent<T> { | ||
|
||
public componentPortal: ComponentPortal<any>; | ||
|
||
protected constructor(protected injector: Injector, | ||
protected caseViewType: Type<any>, | ||
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<T>) { | ||
super(dataFieldPortalData); | ||
} | ||
|
||
createFilter(filterValue: string | string[]) { | ||
let portalInjector; | ||
const filterProperty: boolean = this.dataField?.component?.properties?.filter === 'true'; | ||
let query: CaseSearchRequestBody; | ||
if (filterProperty) { | ||
query = JSON.parse(this.dataField?.component?.properties?.filterQuery) as CaseSearchRequestBody; | ||
} | ||
let providers = [ | ||
{ | ||
provide: NAE_DEFAULT_HEADERS, useValue: this.dataField.component?.properties?.headers.split(',') | ||
}, | ||
{ | ||
provide: NAE_CASE_REF_CREATE_CASE, useValue: this.dataField.component?.properties?.createCase === 'true' | ||
}, | ||
{ | ||
provide: NAE_CASE_REF_SEARCH, useValue: this.dataField.component?.properties?.search === 'true' | ||
}, | ||
{ | ||
provide: NAE_BASE_FILTER, | ||
useValue: { filter: SimpleFilter.fromCaseQuery((filterProperty && query ? query : {stringId: filterValue})) } as BaseFilter | ||
}, | ||
{ | ||
provide: NAE_VIEW_ID_SEGMENT, | ||
useValue: this.dataField.parentCaseId + '_' + this.dataField.parentTaskId + '_' + this.dataField.stringId | ||
}, | ||
{ provide: ViewIdService, useClass: ViewIdService } | ||
]; | ||
if (this.dataField instanceof CaseRefField) { | ||
providers.push({ | ||
provide: NAE_CASE_REF_DATAFIELD, | ||
useValue: this.dataField | ||
}) | ||
} | ||
portalInjector = Injector.create({ | ||
providers, | ||
parent: this.injector | ||
}); | ||
this.componentPortal = new ComponentPortal(this.caseViewType, null, portalInjector); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 5 additions & 40 deletions
45
...ltichoice-field/multichoice-caseref-field/abstract-multichoice-caseref-field.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,28 @@ | ||
import {AfterViewInit, Component, Inject, Injector, Optional, Type} from "@angular/core"; | ||
import {NAE_BASE_FILTER} from "../../../search/models/base-filter-injection-token"; | ||
import {SimpleFilter} from "../../../filter/models/simple-filter"; | ||
import {BaseFilter} from "../../../search/models/base-filter"; | ||
import {NAE_VIEW_ID_SEGMENT} from "../../../user/models/view-id-injection-tokens"; | ||
import {ViewIdService} from "../../../user/services/view-id.service"; | ||
import {AbstractBaseDataFieldComponent} from "../../base-component/abstract-base-data-field.component"; | ||
import {DATA_FIELD_PORTAL_DATA, DataFieldPortalData} from "../../models/data-field-portal-data-injection-token"; | ||
import {ComponentPortal} from "@angular/cdk/portal"; | ||
import {NAE_DEFAULT_HEADERS} from '../../../header/models/default-headers-token'; | ||
import {MultichoiceField} from '../models/multichoice-field'; | ||
import {NAE_CASE_REF_CREATE_CASE, NAE_CASE_REF_SEARCH} from '../../case-ref-field/model/case-ref-injection-tokens'; | ||
import {AbstractCaseRefBaseFieldComponent} from '../../case-ref-field/model/abstract-case-ref-base-field-component'; | ||
|
||
@Component({ | ||
selector: 'ncc-abstract-case-ref-default', | ||
template: '' | ||
}) | ||
export abstract class AbstractMultichoiceCaseRefComponent extends AbstractBaseDataFieldComponent<MultichoiceField> implements AfterViewInit { | ||
export abstract class AbstractMultichoiceCaseRefComponent extends AbstractCaseRefBaseFieldComponent<MultichoiceField> implements AfterViewInit { | ||
|
||
public componentPortal: ComponentPortal<any>; | ||
|
||
protected constructor(protected injector: Injector, | ||
protected caseViewType: Type<any>, | ||
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<MultichoiceField>) { | ||
super(dataFieldPortalData); | ||
super(injector, caseViewType, dataFieldPortalData); | ||
} | ||
|
||
ngAfterViewInit(): void { | ||
this.createFilter(); | ||
this.createFilter(this.dataField.choices.length > 0 ? this.dataField.choices.map(value => value.key) : ''); | ||
this.dataField.updatedChoices.subscribe(() => { | ||
this.createFilter(); | ||
this.createFilter(this.dataField.choices.length > 0 ? this.dataField.choices.map(value => value.key) : ''); | ||
}); | ||
} | ||
|
||
createFilter() { | ||
let portalInjector; | ||
const filterValue : string | string[] = this.dataField.choices.length > 0 ? this.dataField.choices.map(value => value.key) : ''; | ||
portalInjector = Injector.create({ | ||
providers: [ | ||
{ | ||
provide: NAE_DEFAULT_HEADERS, useValue: this.dataField.component?.properties?.headers.split(',') | ||
}, | ||
{ | ||
provide: NAE_CASE_REF_CREATE_CASE, useValue: this.dataField.component?.properties?.createCase === 'true' | ||
}, | ||
{ | ||
provide: NAE_CASE_REF_SEARCH, useValue: this.dataField.component?.properties?.search === 'true' | ||
}, | ||
{ | ||
provide: NAE_BASE_FILTER, | ||
useValue: { filter: SimpleFilter.fromCaseQuery({stringId: filterValue}) } as BaseFilter | ||
}, | ||
{ | ||
provide: NAE_VIEW_ID_SEGMENT, | ||
useValue: this.dataField.parentCaseId + '_' + this.dataField.parentTaskId + '_' + this.dataField.stringId | ||
}, | ||
{ provide: ViewIdService, useClass: ViewIdService }], | ||
parent: this.injector | ||
}); | ||
this.componentPortal = new ComponentPortal(this.caseViewType, null, portalInjector); | ||
} | ||
|
||
} |