Skip to content

Commit

Permalink
feat() update filter
Browse files Browse the repository at this point in the history
  • Loading branch information
develite98 committed Oct 30, 2023
1 parent 277d45d commit 53e6449
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@
<div class="mix-dbs-table__main-container">
<div
class="h-100 w-100"
[class.d-none]="vm.status !== 'Success' || vm.loadDataError"
[class.d-none]="vm.status === 'Loading' || vm.loadDataError"
>
<div *ngIf="vm.status === 'SilentLoading'" class="mix-progress-bar">
<div class="mix-progress-bar-value"></div>
</div>

<ag-grid-angular
class="ag-theme-alpine"
[animateRows]="true"
Expand Down
1 change: 1 addition & 0 deletions apps/mix-cms/src/app/stores/database-data.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export class DatabaseDataStore extends ComponentStore<DatabaseDataState> {

this.patchState((s) => ({
...s,
status: 'SilentLoading',
loadDataError: false,
request: request,
}));
Expand Down
2 changes: 1 addition & 1 deletion libs/mix-share/src/bases/base-crud.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface BaseState<T> {
data: T[];
request: PaginationRequestModel;
pageInfo: PaginationModel;
status: 'Loading' | 'Error' | 'Pending' | 'Success';
status: 'Loading' | 'Error' | 'Pending' | 'Success' | 'SilentLoading';
}

export const DEFAULT_DATA = {
Expand Down
18 changes: 17 additions & 1 deletion libs/mix-ui/src/dynamic-filter/dynamic-filter.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,27 @@ <h4 class="mb-3">Filter Record(s)</h4>
[columns]="columns"
[filter]="filter"
(filterChange)="onFilterValueChange($event, i)"
(deleteFilter)="deleteFilter(filter, i)"
></mix-filter-item>
</ng-container>

<div class="d-flex align-items-center gap-2" *ngIf="filters.length >= 2">
*Meet

<mix-select
[formControl]="logicalOperateForm"
size="s"
class="filter-dialog__select"
[items]="logicalOperateItems"
></mix-select>

of these conditions
</div>

<div class="filter-dialog__footer">
<mix-button type="outline" (click)="add()">Add condition</mix-button>
<mix-button type="outline" (click)="add()">
<span class="mix-icon">add</span> Add condition</mix-button
>

<mix-button class="ms-auto" type="outline" (click)="ref.close()"
>Close</mix-button
Expand Down
4 changes: 4 additions & 0 deletions libs/mix-ui/src/dynamic-filter/dynamic-filter.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
width: 100%;
gap: 4px;
}

&__select {
width: 100px;
}
}
27 changes: 24 additions & 3 deletions libs/mix-ui/src/dynamic-filter/dynamic-filter.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,33 @@ import {
import { MixColumn, MixFilter } from '@mixcore/lib/model';
import { TrackByProp } from '@mixcore/share/pipe';

import { FormControl, ReactiveFormsModule } from '@angular/forms';
import { MixButtonComponent } from '@mixcore/ui/button';
import { DialogService } from '@ngneat/dialog';
import { TippyDirective } from '@ngneat/helipopper';
import { TuiBadgeModule } from '@taiga-ui/kit';
import { MixSelectComponent } from '../select';
import { FilterItemComponent } from './filter-item/filter-item.component';

export interface DynamicFilterValue {
column?: MixColumn;
}

export enum LogicalOperate {
All = 'All',
AtLeast = 'At least 1',
}

@Component({
selector: 'mix-dynamic-filter',
standalone: true,
imports: [
CommonModule,
MixButtonComponent,
TippyDirective,
MixSelectComponent,
FilterItemComponent,
TrackByProp,
TuiBadgeModule,
ReactiveFormsModule,
],
templateUrl: './dynamic-filter.component.html',
styleUrls: ['./dynamic-filter.component.scss'],
Expand All @@ -46,6 +53,8 @@ export class DynamicFilterComponent {
@Input() public filters: MixFilter[] = [];
@Output() public filtersChange = new EventEmitter<MixFilter[]>();
public validFilterCount = 0;
public logicalOperateItems = [LogicalOperate.All, LogicalOperate.AtLeast];
public logicalOperateForm = new FormControl(LogicalOperate.AtLeast);

public open(tpl: TemplateRef<any>) {
this.dialog.open(tpl, { resizable: true, draggable: true });
Expand All @@ -56,6 +65,7 @@ export class DynamicFilterComponent {
fieldName: this.columns[0].systemName,
value: null,
compareOperator: 'Like',
isRequired: false,
});

this.cdr.detectChanges();
Expand All @@ -66,7 +76,18 @@ export class DynamicFilterComponent {
}

public applyChange() {
this.filters = this.filters
.filter((x) => x.value)
.map((f) => {
f.isRequired = this.logicalOperateForm.value === LogicalOperate.All;
return f;
});

this.validFilterCount = this.filters.length;
this.filtersChange.emit(this.filters);
this.validFilterCount = this.filters.filter((x) => x.value).length;
}

public deleteFilter(value: MixFilter, index: number) {
this.filters.splice(index, 1);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<mix-input *ngIf="inputType === 'Text'" [formControl]="control"></mix-input>
<mix-input
*ngIf="inputType === 'Text'"
[formControl]="control"
[placeHolder]="'Type value'"
></mix-input>

<mix-date-picker
*ngIf="inputType === 'DatePicker'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@
(valueChange)="filterValueChange($event)"
></mix-filter-input>

<mix-button>X</mix-button>
<mix-button [iconBtn]="true" type="icon" (click)="deleteFilter.emit()"
><span class="mix-icon">close</span></mix-button
>
</div>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.filter-item {
display: grid;
grid-template-columns: 120px 150px auto 50px;
grid-template-columns: 120px 150px auto min-content;
grid-gap: 4px;
margin-bottom: 6px;
align-items: center;
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class FilterItemComponent {
});

@Output() public filterChange = new EventEmitter();
@Output() public deleteFilter = new EventEmitter();

ngOnInit() {
this.form.controls.column.patchValue(
Expand Down

0 comments on commit 53e6449

Please sign in to comment.