Skip to content

Commit

Permalink
Merge pull request #240 from netgrif/NAE-1957
Browse files Browse the repository at this point in the history
[NAE-1957] Allow filter to caseRef field and variants
  • Loading branch information
machacjozef authored Mar 20, 2024
2 parents a63b813 + ffd83b3 commit f9423c0
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 132 deletions.
Original file line number Diff line number Diff line change
@@ -1,40 +1,27 @@
import {AfterViewInit, Component, Inject, Injector, OnDestroy, 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 {CaseRefField} from '../model/case-ref-field';
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 '../model/case-ref-injection-tokens';
import {Subscription} from 'rxjs';
import {AbstractCaseRefBaseFieldComponent} from '../model/abstract-case-ref-base-field-component';

@Component({
selector: 'ncc-abstract-case-ref-default',
template: ''
})
export abstract class AbstractCaseRefDefaultComponent extends AbstractBaseDataFieldComponent<CaseRefField> implements AfterViewInit, OnDestroy {
export abstract class AbstractCaseRefDefaultComponent extends AbstractCaseRefBaseFieldComponent<CaseRefField> implements AfterViewInit, OnDestroy {

public componentPortal: ComponentPortal<any>;
protected _sub: Subscription;

protected constructor(protected injector: Injector,
protected caseViewType: Type<any>,
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<CaseRefField>) {
super(dataFieldPortalData);
super(injector, caseViewType, dataFieldPortalData);
}

ngAfterViewInit(): void {
this.createFilter();
this.createFilter(this.dataField.value.length > 0 ? this.dataField.value : '');
this._sub = this.dataField.valueChanges().subscribe(() => {
this.createFilter();
this.createFilter(this.dataField.value.length > 0 ? this.dataField.value : '');
});
}

Expand All @@ -43,36 +30,4 @@ export abstract class AbstractCaseRefDefaultComponent extends AbstractBaseDataFi
this._sub.unsubscribe();
}

createFilter() {
let portalInjector;
const filterValue : string | string[] = this.dataField.value.length > 0 ? this.dataField.value : '';
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: NAE_CASE_REF_DATAFIELD,
useValue: this.dataField
},
{ provide: ViewIdService, useClass: ViewIdService }],
parent: this.injector
});
this.componentPortal = new ComponentPortal(this.caseViewType, null, portalInjector);
}

}
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);
}
}

Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
import {AfterViewInit, Component, Inject, Injector, OnDestroy, 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 {NAE_CASE_REF_CREATE_CASE, NAE_CASE_REF_SEARCH} from '../../case-ref-field/model/case-ref-injection-tokens';
import {EnumerationField} from '../models/enumeration-field';
import {Subscription} from 'rxjs';
import {AbstractCaseRefBaseFieldComponent} from '../../case-ref-field/model/abstract-case-ref-base-field-component';

@Component({
selector: 'ncc-abstract-case-ref-default',
template: ''
})
export abstract class AbstractEnumerationCaseRefComponent extends AbstractBaseDataFieldComponent<EnumerationField> implements AfterViewInit, OnDestroy {
export abstract class AbstractEnumerationCaseRefComponent extends AbstractCaseRefBaseFieldComponent<EnumerationField> implements AfterViewInit, OnDestroy {

public componentPortal: ComponentPortal<any>;
protected _sub: Subscription;

protected constructor(protected injector: Injector,
protected caseViewType: Type<any>,
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<EnumerationField>) {
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._sub = this.dataField.updatedChoices.subscribe(() => {
this.createFilter();
this.createFilter(this.dataField.choices.length > 0 ? this.dataField.choices.map(value => value.key) : '');
});
}

Expand All @@ -39,32 +30,4 @@ export abstract class AbstractEnumerationCaseRefComponent extends AbstractBaseDa
this._sub.unsubscribe();
}

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);
}

}
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);
}

}

0 comments on commit f9423c0

Please sign in to comment.