0.1.69 • Published 2 years ago

@eqproject/eqp-filters-next v0.1.69

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

Table of contents

Required

  • Angular Material installed and imported
  • @angular-material-components/datetime-picker (v2.0.4)
  • @angular-material-components/moment-adapter
  • Moment.js

Getting started

This package allows the definition of filters to be used on a data list of any type. With eqp-filters you can configure different types of filters (to choose from a predefined set) or create a custom filter to inject into the directive itself.

Notes

The directive does not really apply the filter but dynamically composes the filter to be returned to the user.

Step 1: Install eqp-dynamic-filters:

NPM

npm install --save @eqproject/eqp-filters

Step 2: Import the EqpDashboardModule :

import { EqpFiltersModule } from '@eqproject/eqp-filters';

@NgModule({
  declarations: [AppComponent],
  imports: [EqpFiltersModule],
  bootstrap: [AppComponent]
})
export class AppModule {}

API

Inputs

InputTypeDefaultRequiredDescription
filtersConfigArray<FilterConfig>-yesArray of FilterConfig Objects
resultTypeFilterResultTypeBASICyesIt allows you to define the type of result to be returned to the calling component, when the "Apply Filters" button is pressed. The possible values ​​are, 1-BASIC: returns an object that will contain as many properties as there are filters valued, each property will have a name and value consistent with the filter configuration; 2-ADVANCED: Returns a complex object to use as LinqPredicate
usingModeFilterModeWITH_CARDyesIt allows you to define the method of use and the graphic aspect of the directive. Possible values are, 1-WITH_CARD: an expandable card is rendered and the filters are displayed in the mat-card-content. When you apply filters in the card-header, the applied filters are summarized 2-WITH_BUTTON: a button is rendered (with the same style as the previous card-header). Pressing the button opens a modal containing all the filters. When filters are applied or reset, the modal closes and the applied filters are summarized in the button
filterTitlestringFiltrinoAllows you to define the label to show as a title for the filters
filterAppliedTitlestringFiltri applicati:noAllows you to define the label to show in the header of the card when there are filters applied
applyFilterLabelstringFiltranoAllows you to define the button label to apply filters
resetAllFilterLabelstringResetnoAllows you to define the button label to reset filters
showExpandendbooleanfalsenoWhen using usingMode = WITH_CARD it allows to define the starting state of the card. If TRUE then part open otherwise collapsed
currentCultureSelectedstringit-ITyesIt allows you to define the culture (and the relative language) to be used for the localization of dates
applyOnInitbooleanfalsenoIf TRUE then invokes the filterSelected output event at the init of the component. To be used when you want to give a starting value to some filters
saveFilterbooleanfalsenoIf it assumes the value TRUE then the filter saving function will be active; the user can, after setting the different conditions, click on the 'Save filters' button to store the current filter status. This operation can be done several times in order to memorize more filters with different conditions. If the property is TRUE then it is mandatory to define the saveFilterID input
saveFilterIDstring-noIf saveFilter is TRUE then this input is required and must contain a unique name that identifies the component. This unique value will be used to store the different filters configured by the user.
saveFilterButtonLabelstringSalva filtronoIf saveFilter is TRUE then this input allows you to define the label to show for the save filter button
saveFilterTitlestringInserire il nome per questo filtronoIf saveFilter is TRUE then this input allows you to define the title of the modal for entering the name of the filter to be saved
saveFilterConfirmLabelstringConfermanoIf saveFilter is TRUE then this input allows you to define the label of the confirm button for saving the filters
saveFilterAbortLabelstringAnnullanoIf saveFilter is TRUE then this input allows you to define the label of the cancel button for saving filters
restoreSavedFilterTooltipstringRicarica filtronoIt allows you to define the tooltip to be shown to reload a filter from those previously saved (default value: 'Reload filter'). This input is used only when saveFilter = TRUE
removeSavedFilterTooltipstringElimina filtronoIt allows you to define the tooltip to be displayed to delete a filter from those previously saved (default value: 'Delete filter'). This input is used only when saveFilter = TRUE
savedFilterLabelstringFiltri salvatinoIf saveFilter is TRUE then this input allows you to define the section label that shows all previously saved filters (default value: 'Saved Filters')
useInitialValueOnResetbooleantruenoIf TRUE then when the RESET key is pressed for the filters that had default start values ​​then those values ​​will be reset, otherwise if FALSE all the filters will be deleted
filterPreventRemovalTooltipstringNon è possibile rimuovere questo filtronoAllows you to redefine the label to be shown as a tooltip when you hover the mouse over a filter for which PreventRemoval = TRUE (i.e. when deletion is prevented for a filter)
saveLastFilterbooleanfalsenoIf TRUE saves the last user selected filters and if the parameter applyOnInit is TRUE they will be restored and applied.
savedLastFilterNamestringUltimi filtri usatinoIf saveLastFilter is TRUE then this input allows you to define the name of the last selected filters.
leftCollapseIconbooleantruenoIf TRUE and usingMode == FilterMode.WITH_CARD then shows the arrow to expand/collapse the card on the left side of the header, otherwise shows it on the right side.
showAppliedFiltersIconbooleanfalsenoIf TRUE, usingMode == FilterMode.WITH_CARD and the user selected some filters then shows a filter icon on the left of the header title. To change this icon color you can use its own css class named eqp-filters-applied-filter-icon.

Outputs

OutputEvent ArgumentsRequiredDescription
filtersSelectedEventEmitter<any>yesInvoked when buttons are pressed to apply or reset filters. Returns as a parameter the object (in case of resultType = BASIC) or the array of complex objects (if resultType = ADVANCED) with the results of the applied filters.
customFiltersSavedValueLoadedEventEmitter<any>yesOutput event fired when filters are reloaded from localstorage and the current filter expects an external template. This event is invoked only if the filter has an external template and only if the storage of the filters has been requested for eqp-filters. The complete filter configuration is passed as an event parameter.

Models used

FilterConfig Model: class for configure each individual filter

PropertyDescriptionTypeExamples
FilterIDUnique Filter ID stringstring-
FilterClassSet the dimension of the filter controlFilterSizeClassSMALL;MEDIUM;LARGE;CUSTOM
CustomFilterClassesIf FilterClass == FilterSizeClass.CUSTOM sets the custom defined classes on the filter controlstring-
LabelSet the label for the filterstring-
PropertyNameProperty name of the array objects on which the filter is to be appliedstringName
PropertyObjectProperty value of the array objects on which the filter is to be applied (default null)any-
InputTypeEnum that define the type of the filter control to showInputTypeThe possible values are: Text, Number, Date, Datetime, CvlEnum, Cvl, Boolean, BooleanCvl, CustomTemplate
WherePartTypeIt defines, in the case of resultType = ADVANCED, the type of logical comparison operator to be madeWherePartTypeA value to be chosen between Equal, NotEqual, StringContains, StringNotContains, GreaterThan, GreaterThanOrEqual, LessThan, LessThanOrEqual, ContainsElement, NotContainsElement
CvlConfigSet the configuration for type CVL filter (it's mandatory when InputType = CvlEnum or InputType = Cvl or InputType = BooleanCvl)FilterCvlConfig-
ExternaltemplateDefines an external template to pass to the directive and which contains a custom filter (defined by the user who uses the directive)TemplateRef<any>-
CustomWherePartFunctionAllows you to define an external custom function to be invoked for the current filter when the APPLY FILTERS or RESET buttons are pressedFunction-
CustomAppliedFilterInfoFunctionIt allows you to define the custom function to return the value of the applied filter, to be shown in the header of the cardFunction-
ChildElementPropertyNameFor filters of type ContainsElement and NotContainsElement that rely on applying a where part with the operator ANY of LINQ then this property allows you to define the name of the property of the child objects on which to apply the where part. In this case, the name of the property containing the child list will go into PropertyName.string-
PreventRemovalAllows you to disable the cancellation of the filter for the user. By default it assumes the value FALSE (if true then the X button will not be shown in the summary of the applied filters)boolean-
Enums description
EnumTypeDescriptionNotes
FilterClassAllow the define the dimensione of the filterSMALL apply the col-4 bootstrap class, MEDIUM apply the col-8 bootstrap class and LARGE apply the col-12 bootstrap class
InputTypeAllow the define the type of the input control to show for the filterText: show an input text; Number:show an input number; Date: show a material datepicker; CvlEnum: show an eqp-select for the enumData type defined on the CvlConfig for the filter; Cvl: show an eqp-select for the arrayData defined on the CvlConfig for the filter; Boolean: show a material slide; BooleanCvl: show an eqp-select for the arrayData defined on the CvlConfig for the boolean filter value with states(NULL,TRUE, FALSE); CustomTemplate: show an external ng-template passed to the directive
WherePartTypeIt defines, in the case of resultType = ADVANCED, the type of logical comparison operator to be made-
FilterResultTypeDefines the type of the object to return when the apply filters button is pressed-
FilterModeDefines how the directive is to be usedWITH_CARD (default value): show a mat-card with expandable content. In the mat-card-content the filters are showed; WITH_BUTTON: show a button. When the button is pressed, a mat-dialog window are open with all the configured filters
Static exposed functions
NameReturned TypeParametersExamples
CreateStandardFilterConfigFilterConfigfilterID: string, label: string, propertyName: string, type: InputType, wherePartType: WherePartType, filterClass?: FilterSizeClass, filterCvlConfig?: FilterCvlConfig, externaltemplate?: TemplateRef<any>, customWherePartFunction? : Function, childElementPropertyName?: string-

FilterCvlConfig Model: class for configure the eqp-select for the filter of types: Cvl, CvlEnum or BooleanCvl

PropertyDescriptionTypeExamples
EnumDataSe la CVL si basa su un enumeratore allora in questa proprietà va definito il type dell'enumeratore da usare. In questo modo la sorgente dati della CVL sarà l'insieme dei valori definiti per l'enumeratoreany-
ArrayDataIf the CVL is based on an array then in this property the array to be shown as the data source of the CVL must be definedany[]-
ArrayKeyPropertyIn the case of ArrayData defined it allows to indicate the property of the objects of the array to bind to the filterstring-
ArrayValuePropertyIn the case of ArrayData defined, it allows you to indicate the property of the objects to be displayed in the filterstring-
IsSearchableIf TRUE then it shows the search field within the CVLboolean-
ShowCancelButtonIf TRUE then it shows the button to clear the CVL selectionboolean-
SearchTextAllows you to define the label for the search fieldstring-
IsMultiSelectIt allows you to define the multi-selection of CVL valuesboolean-
BindFullObjectIt allows to define if in the CVL the binding must consider the whole object or only the property defined inside ArrayKeyPropertyboolean-
Static exposed functions
NameReturned TypeParametersExamples
CreateFilterCVLConfigFilterCvlConfigenumData?: any, arrayData?: any, arrayKeyProperty?: any, arrayValueProperty?: any, isMultiSelect?: boolean, isSearchable?: boolean, showCancelButton?: boolean, searchText?: string, bindFullObject?: boolean-

Use cases

Use Example in class :

Define selector in html

<eqp-dynamic-filters [filtersConfig]="filters" (filtersSelected)="filtersSelected($event)"></eqp-dashboard>

CASE 1:Text type filter configuration

    filters: FilterConfig[];
    
    let textFilter: FilterConfig = FilterConfig.CreateStandardFilterConfig("TEXT_FILTER", "Name", "Name", InputType.Text, WherePartType.Equal);
    this.filters.push(textFilter);

CASE 2: Number type filter configuration

    filters: FilterConfig[];
    
    let numberFilter: FilterConfig = FilterConfig.CreateStandardFilterConfig("NUMBER_FILTER", "Counter", "Filtro Numero", InputType.Number, WherePartType.Equal);
    this.filters.push(numberFilter);

CASE 3: Boolean type filter configuration

    filters: FilterConfig[];
    
    let booleanFilter: FilterConfig = FilterConfig.CreateStandardFilterConfig("BOOLEAN_FILTER","Bool Filter", "IsValid", InputType.Boolean, WherePartType.Equal);
     this.filters.push(booleanFilter);

CASE 4: CVL Enum type filter configuration

    filters: FilterConfig[];
    
    //Assuming you define a GenderEnum type enumerator with the values MALE and FEMALE
    
    let enumCvlConfig: FilterCvlConfig = FilterCvlConfig.CreateFilterCVLConfig(GenderEnum, null, null, null, false, true, true);
    let enumFilter: FilterConfig = FilterConfig.CreateStandardFilterConfig("CVL_ENUM_FILTER", "Gender", "Gender", InputType.CvlEnum, WherePartType.Equal, null, enumCvlConfig);
    this.filters.push(enumFilter);

CASE 5: Date type filter configuration

    filters: FilterConfig[];
    
    let filterDateStart: FilterConfig = FilterConfig.CreateStandardFilterConfig("DATE_FILTER", "Start date","StartDate", InputType.Date, WherePartType.GreaterThanOrEqual, FilterSizeClass.SMALL);
    this.filters.push(filterDateStart);

CASE 6: Datetime type filter configuration

    filters: FilterConfig[];
    
    let filterDateStart: FilterConfig = FilterConfig.CreateStandardFilterConfig("DATETIME_FILTER", "Start datetime","StartDatetime", InputType.Datetime, WherePartType.GreaterThanOrEqual, FilterSizeClass.SMALL);
    this.filters.push(filterDateStart);

CASE 7: CVL type filter configuration

    filters: FilterConfig[];
    
    let cvlConfig: FilterCvlConfig = FilterCvlConfig.CreateFilterCVLConfig(null, [{ key: 1, value: "Value 1"}, { key: 2, value: "Value 2"}, { key: 3, value: "Value 3"}], "key", "value", false, true, true, null, true);
    let cvlFilter: FilterConfig = FilterConfig.CreateStandardFilterConfig("CVL_FILTER", "Cvl", "CvlValue", InputType.Cvl, WherePartType.Equal, null, cvlConfig);
    this.filters.push(cvlFilter);

CASE 8: Boolean CVL type filter configuration (this is the typical case of a non-mandatory Boolean)

    filters: FilterConfig[];
    
    let booleanCvlConfig: FilterCvlConfig = FilterCvlConfig.CreateFilterCVLConfig(null, [{ key: true, value: "Yes"}, { key: false, value: "No"}], "key", "value", false, true, true, null, false);
    let booleanCvlFilter: FilterConfig = FilterConfig.CreateStandardFilterConfig("CVL_BOOLEAN_FILTER", "Boolean Cvl", "BooleanCvlValue", InputType.BooleanCvl, WherePartType.Equal, null, booleanCvlConfig);
    this.filters.push(booleanCvlFilter);

CASE 9: Custom Template type filter configuration (this is the typical case of a non-mandatory Boolean)

    <ng-template #externalFilter let-filter="filter">
        <mat-form-field>
            <mat-label>{{ filter.Label }}</mat-label>
            <input matInput [(ngModel)]="filter.PropertyObject">
      </mat-form-field>
    </ng-template>
    
    //Define this ViewChild on ts
    @ViewChild('externalFilter', { static: true }) externalFilter: TemplateRef<any>;
    
    //Define this function on ts
    createCustomFilterValue(filterConfig, context) {
        let result = {};

        result[filterConfig.PropertyName] = filterConfig.PropertyObject;
        return result;
    }
    
    //On the filter configuring method
    filters: FilterConfig[];
    
    let filterExternal: FilterConfig = FilterConfig.CreateStandardFilterConfig("PROVA_TEMPLATE_ESTERNO","Template esterno","Surname", InputType.CustomTemplate, WherePartType.Equal, FilterSizeClass.SMALL);
    filterExternal.Externaltemplate = this.externalFilter;
    filterExternal.CustomWherePartFunction = (config, context) => this.createCustomFilterValue(config, this);

    this.filters.push(filterExternal);
    

CASE 10: eqp-filters with active save functionality

    <eqp-dynamic-filters [filtersConfig]="filters" [saveFilter]="true" [saveFilterID]="'testFiltri'"                            [saveFilterID]="'provaFiltri'" (filtersSelected)="filtersSelected($event)"                     (customFiltersSavedValueLoaded)="customFiltersSavedValueLoaded($event)" [usingMode]="2" [resultType]="2" [applyOnInit]="true" ></eqp-dynamic-filters>
    
    //On the filter configuring method
    filters: FilterConfig[];
    
    let textFilter: FilterConfig = FilterConfig.CreateStandardFilterConfig("PROVA_TEXT_ID", "Nome", "Name", InputType.Text, WherePartType.Equal);
    this.filters.push(textFilter);

    
    customFiltersSavedValueLoaded(filterConfig:FilterConfig) {
    if(!filterConfig)
      return;

    //If the current filter has an external template (with custom function defined) then 
    //here the value of the PropertyObject property of filterConfig must be forced with the value of the properties 
    //used inside the external template. In this way eqp-filters will be able to retrieve the value to be saved also 
    //for custom filters
    //For example: filterConfig.PropertyObject = context.customFilterPropertyValue;
  }
    

Credits

This library has been developed by EqProject SRL, for more info contact: info@eqproject.it

0.1.69

2 years ago

0.1.68

2 years ago

0.1.66

2 years ago

0.1.65

2 years ago

0.1.64

2 years ago

0.1.63

2 years ago

0.1.62

2 years ago

0.1.61

2 years ago

0.1.60

2 years ago

0.1.56

2 years ago

0.1.55

2 years ago

0.1.54

2 years ago

0.1.52

2 years ago

0.1.51

2 years ago

0.1.50

2 years ago

0.1.47

2 years ago

0.1.46

2 years ago

0.1.45

2 years ago

0.1.44

2 years ago

0.1.43

2 years ago

0.1.42

2 years ago

0.1.40

2 years ago

0.1.39

2 years ago

0.1.37

2 years ago

0.1.35

2 years ago

0.1.33

2 years ago

0.1.27

2 years ago

0.1.26

2 years ago

0.1.25

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.26

2 years ago

0.0.25

2 years ago

0.0.24

2 years ago

0.0.23

2 years ago

0.0.22

2 years ago

0.0.21

2 years ago

0.0.20

2 years ago

0.0.19

2 years ago

0.0.18

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago