number filter & datetime filter

This commit is contained in:
Yubing325 2020-06-29 15:29:13 -05:00
parent 1e6e02cf69
commit 9e02901937
13 changed files with 281 additions and 137 deletions

View File

@ -1,24 +1,66 @@
<div class="row"> <ng-template #popTemplate>
<div class="col-xs-12 col-12 col-md-4 form-group"> <div class="container" >
<div class="row">
<div class="form-group">
<input type="text" <input type="text"
placeholder="Datepicker" placeholder="Datepicker"
class="form-control" class="form-control"
bsDatepicker> bsDatepicker [(ngModel)]="filterValue">
</div> </div>
<div class="col-xs-12 col-12 col-md-4 form-group"> </div>
<div class="row">
<input type="text" <input type="text"
placeholder="Daterangepicker" placeholder="Daterangepicker"
class="form-control" class="form-control"
bsDaterangepicker> bsDaterangepicker>
</div> </div>
<div class="row mt-2">
<button class="btn btn-primary mr-1" >Filter</button>
<button type="button" class="btn btn-warning" *ngIf="!isFiltering" (click)="pop.hide()">Hide</button>
<button type="button" class="btn btn-dark" *ngIf="isFiltering">Clear</button>
</div> </div>
</div>
</ng-template>
<!-- <button [popover]="popTemplate" class="btn btn-default" [(isOpen)]="filterPopUpOpened" [outsideClick]="true" #pop="bs-popover">
<div class="row"> <svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
<div class="pr-3 pb-3"> viewBox="0 0 477.875 477.875" style="enable-background:new 0 0 477.875 477.875;" xml:space="preserve" fill-opacity="0.5" [tooltip]="showTooltip()" [tooltipEnable]="!filterPopUpOpened" width="13px" height="13px" [ngStyle]="{'fill': isFiltering ? 'red': 'black', 'fill-opacity': isFiltering ? '1': '0.5'}">
<bs-datepicker-inline [bsValue]="bsInlineValue"></bs-datepicker-inline> <g>
</div> <g>
<div class="pr-3 pb-3"> <path d="M460.804,0H17.071C7.645,0,0.004,7.641,0.004,17.067V102.4c-0.004,4.842,2.05,9.458,5.649,12.698l165.018,148.514V460.8
<bs-daterangepicker-inline [bsValue]="bsInlineRangeValue"></bs-daterangepicker-inline> c-0.004,9.426,7.633,17.07,17.059,17.075c2.651,0.001,5.266-0.615,7.637-1.8l102.4-51.2c5.786-2.891,9.441-8.806,9.438-15.275
</div> V263.612l165.018-148.48c3.608-3.247,5.662-7.878,5.649-12.732V17.067C477.871,7.641,470.23,0,460.804,0z"/>
</div> --> </g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
</svg>
</button>

View File

@ -1,4 +1,5 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit, Input } from '@angular/core';
import { IDataSource, ISimpleFilter } from '@poweredsoft/data';
@Component({ @Component({
selector: 'psbx-datetime-filter', selector: 'psbx-datetime-filter',
@ -7,6 +8,17 @@ import { Component, OnInit } from '@angular/core';
}) })
export class DatetimeFilterComponent { export class DatetimeFilterComponent {
@Input() path: string;
@Input() dataSource : IDataSource<any>;
filterPopUpOpened: boolean = false;
isFiltering: boolean;
filterValue: Date = null;
filterType: string = 'Equal';
filterTypes = [
{key:'equal', value: 'Equal'},
];
bsInlineValue = new Date(); bsInlineValue = new Date();
bsInlineRangeValue: Date[]; bsInlineRangeValue: Date[];
maxDate = new Date(); maxDate = new Date();
@ -15,5 +27,31 @@ export class DatetimeFilterComponent {
this.maxDate.setDate(this.maxDate.getDate() + 7); this.maxDate.setDate(this.maxDate.getDate() + 7);
this.bsInlineRangeValue = [this.bsInlineValue, this.maxDate]; this.bsInlineRangeValue = [this.bsInlineValue, this.maxDate];
} }
showTooltip(){
return "Filter by "+ this.path;
}
applyFilter(){debugger;
this.isFiltering = true;
const filters = this.dataSource.filters;
const existingFilter = filters.find(t => (t as ISimpleFilter).path == this.path) as ISimpleFilter;
if (existingFilter) {
existingFilter.type = this.filterType;
existingFilter.value = this.filterValue.toString()
} else {
filters.push(<ISimpleFilter>{
and: true,
type: this.filterType,
path: this.path,
value: this.filterValue.toString()
})
}
this.dataSource.query({
filters: filters,
page: 1
})
}
} }

View File

@ -1,57 +1,62 @@
<ng-template #popTemplate> <ng-template #popTemplate>
<div class="container" >
<div class="row">
<select class="custom-select" title="Choose one of the following..." [(ngModel)]="filterType"> <select class="custom-select" title="Choose one of the following..." [(ngModel)]="filterType">
<option *ngFor="let filter of filterTypes">{{filter}}</option> <option *ngFor="let filter of filterTypes" [value]="filter.value">{{filter.key}}</option>
</select> </select>
</div>
<input type="text" class="form-control" placeholder="column value" aria-label="Username" <div class="row mt-1 mb-1">
<input type="number" class="form-control" placeholder="column value" aria-label="number"
aria-describedby="basic-addon1" [(ngModel)]="filterValue"> aria-describedby="basic-addon1" [(ngModel)]="filterValue">
<button class="btn btn-primary" (click)="applyFilter()">Filter</button> </div>
<button class="btn btn-primary mr-1" (click)="applyFilter()">Filter</button>
<button type="button" class="btn btn-warning" *ngIf="!isFiltering" (click)="pop.hide()">Hide</button>
<button type="button" class="btn btn-dark" *ngIf="isFiltering" (click)="clearFilter()">Clear</button>
</div>
</ng-template> </ng-template>
<button [popover]="popTemplate" class="btn btn-default" [(isOpen)]="filterIsOpenned" [outsideClick]="true" #pop="bs-popover">
<button [popover]="popTemplate" popoverTitle="Template ref content inside" [outsideClick]="true" > <svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" viewBox="0 0 477.875 477.875" style="enable-background:new 0 0 477.875 477.875;" xml:space="preserve" fill-opacity="0.5" [tooltip]="showTooltip()" [tooltipEnable]="!filterIsOpenned" width="13px" height="13px" [ngStyle]="{'fill': isFiltering ? 'red': 'black', 'fill-opacity': isFiltering ? '1': '0.5'}">
y="0px" viewBox="0 0 477.875 477.875" style="enable-background:new 0 0 477.875 477.875;" xml:space="preserve" <g>
width="13px" height="13px">
<g> <g>
<g> <path d="M460.804,0H17.071C7.645,0,0.004,7.641,0.004,17.067V102.4c-0.004,4.842,2.05,9.458,5.649,12.698l165.018,148.514V460.8
<path d="M460.804,0H17.071C7.645,0,0.004,7.641,0.004,17.067V102.4c0.001,4.836,2.054,9.445,5.649,12.681l165.018,148.514V460.8
c-0.004,9.426,7.633,17.07,17.059,17.075c2.651,0.001,5.266-0.615,7.637-1.8l102.4-51.2c5.786-2.891,9.441-8.806,9.438-15.275 c-0.004,9.426,7.633,17.07,17.059,17.075c2.651,0.001,5.266-0.615,7.637-1.8l102.4-51.2c5.786-2.891,9.441-8.806,9.438-15.275
V263.595l165.018-148.48c3.604-3.243,5.658-7.866,5.649-12.715V17.067C477.871,7.641,470.23,0,460.804,0z M443.737,94.805 V263.612l165.018-148.48c3.608-3.247,5.662-7.878,5.649-12.732V17.067C477.871,7.641,470.23,0,460.804,0z"/>
L278.72,243.285c-3.604,3.243-5.657,7.866-5.649,12.715v143.053l-68.267,34.133V256c-0.001-4.836-2.054-9.445-5.649-12.68
L34.137,94.805V34.133h409.6V94.805z" />
</g> </g>
</g> </g>
<g> <g>
</g> </g>
<g> <g>
</g> </g>
<g> <g>
</g> </g>
<g> <g>
</g> </g>
<g> <g>
</g> </g>
<g> <g>
</g> </g>
<g> <g>
</g> </g>
<g> <g>
</g> </g>
<g> <g>
</g> </g>
<g> <g>
</g> </g>
<g> <g>
</g> </g>
<g> <g>
</g> </g>
<g> <g>
</g> </g>
<g> <g>
</g> </g>
<g> <g>
</g> </g>
</svg> </svg>
</button>
</button>{{columnName}}

View File

@ -1,4 +1,4 @@
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; import { Component, OnInit, Input, Output, EventEmitter, ElementRef, ViewChild } from '@angular/core';
import { IDataSource,IFilter } from '@poweredsoft/data'; import { IDataSource,IFilter } from '@poweredsoft/data';
import { ISimpleFilter } from '../../models/IFilter'; import { ISimpleFilter } from '../../models/IFilter';
@ -9,29 +9,62 @@ import { ISimpleFilter } from '../../models/IFilter';
}) })
export class NumberFilterComponent implements OnInit { export class NumberFilterComponent implements OnInit {
@Input() dataSource : IDataSource<any>; @Input() dataSource : IDataSource<any>;
@Output() onFilter: EventEmitter<IFilter> = new EventEmitter(); @Input() path:string;
@Input() columnName:string;
filterType: string = 'Contains'; filterType: string = 'Equals';
filterValue: string = null; filterValue: number = 0;
isFiltering: boolean;
get filterTypes(){ filterTypes = [
return ["contains","equals","startsWith","GreaterThan","LessThan"] {key:'Equals', value: 'Equal'},
} {key:'Greater Than', value: 'GreaterThan'},
{key:'Less Than', value: 'LessThan'},
{key:'Greater Than Equal', value: 'GreaterThanOrEqual'},
{key:'Less Than Equal', value: 'LessThanOrEqual'},
];
filterIsOpenned: boolean = false;
constructor() { } constructor() { }
ngOnInit(): void { ngOnInit(): void {
}
clearFilter() {
this.isFiltering = false;
const existingFilter = this.dataSource.filters.find(t => (t as ISimpleFilter).path == this.path) as ISimpleFilter;
if (existingFilter) {
this.dataSource.query({
page: 1,
filters: this.dataSource.filters.filter(t => t != existingFilter)
})
}
} }
applyFilter(){ applyFilter(){
this.onFilter.emit(<ISimpleFilter>{ this.isFiltering = true;
path: this.columnName, const filters = this.dataSource.filters;
value: this.filterValue, const existingFilter = filters.find(t => (t as ISimpleFilter).path == this.path) as ISimpleFilter;
if (existingFilter) {
existingFilter.type = this.filterType;
existingFilter.value =this.filterValue.toString();
} else {
filters.push(<ISimpleFilter>{
and: true,
type: this.filterType, type: this.filterType,
and: true path: this.path,
}); value: this.filterValue.toString()
})
}
this.dataSource.query({
filters: filters,
page: 1
})
}
showTooltip(){
return "Filter by "+ this.path;
} }
} }

View File

@ -2,7 +2,7 @@
<div class="container" > <div class="container" >
<div class="row"> <div class="row">
<select class="custom-select" title="Choose one of the following..." [(ngModel)]="filterType"> <select class="custom-select" title="Choose one of the following..." [(ngModel)]="filterType">
<option *ngFor="let filter of filterTypes">{{filter.value}}</option> <option *ngFor="let filter of filterTypes" [value]="filter.value">{{filter.key}}</option>
</select> </select>
</div> </div>

View File

@ -17,10 +17,10 @@ export class TextFilterComponent implements OnInit {
filterValue: string = null; filterValue: string = null;
isFiltering: boolean; isFiltering: boolean;
filterTypes = [ filterTypes = [
{key:'contains', value: 'Contains'}, {key:'Contains', value: 'Contains'},
{key:'equal', value: 'Equal'}, {key:'Equals', value: 'Equal'},
{key:'startsWith', value: 'Starts With'}, {key:'Starts With', value: 'startsWith'},
{key:'endsWith', value: 'Ends With'} {key:'Ends With', value: 'endsWith'}
]; ];
filterIsOpenned: boolean = false; filterIsOpenned: boolean = false;

View File

@ -1,3 +1,3 @@
<span> <span>
<span class="caret dropdown-toggle" [class.not-sorting-state]="!isSorting" [class.sort-desc]="!isAscending" (click)="ascending()"></span> <span class="caret dropdown-toggle" [class.not-sorting-state]="!isSorting" [class.sort-desc]="!isAscending" (click)="sorting()"></span>
</span> </span>

View File

@ -17,10 +17,9 @@ export class GridSortingComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
} }
ascending(){ sorting(){
this.isSorting = !this.isSorting; this.isSorting = true;
this.isAscending = !this.isAscending; this.isAscending = !this.isAscending;
console.log("ascending result...")
const existingSort = this.dataSource.sorts.find(t => t.path == this.path); const existingSort = this.dataSource.sorts.find(t => t.path == this.path);
if (existingSort){ if (existingSort){
existingSort.ascending = (this.isAscending)? true : false; existingSort.ascending = (this.isAscending)? true : false;

View File

@ -1,11 +1,13 @@
export interface IChangeMerchantNameCommand { export interface IChangeMerchantCommand {
id: string; id: string;
name: string; name: string;
address: string; address: string;
ordering: number;
} }
export interface IAddMerchantCommand { export interface IAddMerchantCommand {
name: string; name: string;
address: string; address: string;
ordering: number;
} }
export interface IRemoveMerchantCommand { export interface IRemoveMerchantCommand {

View File

@ -2,4 +2,6 @@ export interface IMerchant {
id: string; id: string;
name: string; name: string;
address: string; address: string;
ordering:number;
openDate: Date;
} }

View File

@ -4,7 +4,7 @@ import { IDataSource, DataSource } from '@poweredsoft/data';
import { Apollo } from 'apollo-angular'; import { Apollo } from 'apollo-angular';
import gql from 'graphql-tag'; import gql from 'graphql-tag';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { IChangeMerchantNameCommand, IAddMerchantCommand, IRemoveMerchantCommand } from './IChangeMerchantNameCommand'; import { IChangeMerchantCommand as IChangeMerchantCommand, IAddMerchantCommand, IRemoveMerchantCommand } from './IChangeMerchantCommand';
import { IMerchant } from './IMerchant'; import { IMerchant } from './IMerchant';
@Injectable({ @Injectable({
@ -23,7 +23,7 @@ export class MerchantService {
>( >(
'merchants', 'merchants',
'GraphQLAdvanceQueryOfMerchantInput', 'GraphQLAdvanceQueryOfMerchantInput',
'id, name, address', 'id, name, address, ordering, openDate',
(model) => model.id, (model) => model.id,
{ {
page: 1, page: 1,
@ -32,7 +32,7 @@ export class MerchantService {
true true
); );
builder.addMutation<IChangeMerchantNameCommand, string>( builder.addMutation<IChangeMerchantCommand, string>(
'changeMerchant', //<-- command name 'changeMerchant', //<-- command name
'changeMerchant', //<-- graph ql mutation name 'changeMerchant', //<-- graph ql mutation name
@ -51,10 +51,11 @@ export class MerchantService {
}, },
// viewModel -> transform to the form model for that command -> IChangeMerchantName // viewModel -> transform to the form model for that command -> IChangeMerchantName
e => of(<IChangeMerchantNameCommand>{ e => of(<IChangeMerchantCommand>{
id: e.model.id, id: e.model.id,
name: e.model.name, name: e.model.name,
address: e.model.address address: e.model.address,
ordering:e.model.ordering,
}) })
); );
@ -80,7 +81,8 @@ export class MerchantService {
// viewModel -> transform to the form model for that command -> IChangeMerchantName // viewModel -> transform to the form model for that command -> IChangeMerchantName
e => of(<IAddMerchantCommand>{ e => of(<IAddMerchantCommand>{
name: 'A New merchant', name: 'A New merchant',
address: '' address: '',
ordering: 11
}) })
); );

View File

@ -1,6 +1,4 @@
<h2>grid-filter-demo works!</h2> <h2>grid-filter-demo works!</h2>
<psbx-datetime-filter></psbx-datetime-filter>
<ps-data-grid [dataSource]="merchantDataSource" [(columns)]="columns" <ps-data-grid [dataSource]="merchantDataSource" [(columns)]="columns"
tableClasses="table table-sm table-striped table-bordered"> tableClasses="table table-sm table-striped table-bordered">
@ -42,16 +40,36 @@
<ng-container psDataGridCol="address"> <ng-container psDataGridCol="address">
<div *psDataGridColHeader>Address</div> <div *psDataGridColHeader>Address</div>
<div *psDataGridCell="let model">{{model.address}}</div> <div *psDataGridCell="let model">{{model.address}}</div>
<psbx-ds-text-filter *psDataGridCellFilter [dataSource]="merchantDataSource" path="address"></psbx-ds-text-filter> <psbx-ds-text-filter *psDataGridCellFilter [dataSource]="merchantDataSource" path="address">
</psbx-ds-text-filter>
<psbx-grid-sorting *psDataGridColSort [dataSource]="merchantDataSource" path="address"></psbx-grid-sorting> <psbx-grid-sorting *psDataGridColSort [dataSource]="merchantDataSource" path="address"></psbx-grid-sorting>
</ng-container> </ng-container>
<ng-container psDataGridCol="ordering">
<div *psDataGridColHeader>Priority</div>
<div *psDataGridCell="let model">{{model.ordering}}</div>
<psbx-number-filter *psDataGridCellFilter [dataSource]="merchantDataSource" path="ordering">
</psbx-number-filter>
<psbx-grid-sorting *psDataGridColSort [dataSource]="merchantDataSource" path="ordering"></psbx-grid-sorting>
</ng-container>
<ng-container psDataGridCol="openDate">
<div *psDataGridColHeader>Open Date</div>
<div *psDataGridCell="let model">{{model.openDate}}</div>
<psbx-datetime-filter *psDataGridCellFilter [dataSource]="merchantDataSource" path="openDate">
</psbx-datetime-filter>
<psbx-grid-sorting *psDataGridColSort [dataSource]="merchantDataSource" path="openDate"></psbx-grid-sorting>
</ng-container>
<ng-container psDataGridCol="commands"> <ng-container psDataGridCol="commands">
<ng-container *psDataGridColHeader>Actions</ng-container> <ng-container *psDataGridColHeader>Actions</ng-container>
<ng-container *psDataGridCell="let model"> <ng-container *psDataGridCell="let model">
<button class="btn-info btn" psbxCommandModal [commandTitle]="'Change ' + model.name + ' name'" commandText="Update" <button class="btn-info btn" psbxCommandModal [commandTitle]="'Change ' + model.name + ' name'"
[dataSource]="merchantDataSource" command="changeMerchant" [model]="model" [template]="theModal">Change</button> commandText="Update" [dataSource]="merchantDataSource" command="changeMerchant" [model]="model"
<button class="btn-danger btn" psbxConfirmModal [commandTitle]="'Are you sure you wnat to remove ' + model.name + '?'" commandText="Remove" [template]="theModal">Change</button>
[dataSource]="merchantDataSource" command="removeMerchant" [model]="model" >Remove</button> <button class="btn-danger btn" psbxConfirmModal
[commandTitle]="'Are you sure you wnat to remove ' + model.name + '?'" commandText="Remove"
[dataSource]="merchantDataSource" command="removeMerchant" [model]="model">Remove</button>
</ng-container> </ng-container>
</ng-container> </ng-container>
<ng-container *psDataGridFooter> <ng-container *psDataGridFooter>
@ -60,24 +78,27 @@
</ps-data-grid> </ps-data-grid>
<ng-template #theModal let-command let-loading="loading">
<label for="name">Name</label>
<input type="text" required [(ngModel)]="command.name" placeholder="Enter a merchant name"
class="form-control">
<label for="address">Address</label>
<input type="text" required [(ngModel)]="command.address"
placeholder="Enter the merchant's address" class="form-control">
<label for="address">Priority</label>
<input type="number" required [(ngModel)]="command.ordering"
placeholder="Enter the merchant's Priority" class="form-control">
<label for="address">Priority</label>
<input type="date" required [(ngModel)]="command.openDate"
placeholder="Enter the merchant's Priority" class="form-control">
</ng-template>
<ng-template #confirm> <ng-template #confirm>
<div class="modal-body text-center"> <div class="modal-body text-center">
<p>Do you want to confirm?</p> <p>Do you want to confirm?</p>
<button type="button" class="btn btn-default" >Yes</button> <button type="button" class="btn btn-default">Yes</button>
<button type="button" class="btn btn-primary" >No</button> <button type="button" class="btn btn-primary">No</button>
</div> </div>
</ng-template>
<ng-template #theModal let-command let-loading="loading">
<label for="name">Name</label>
<input type="text" required [attr.disabled]="loading" [(ngModel)]="command.name" placeholder="Enter a merchant name"
class="form-control" >
<label for="address">Address</label>
<input type="text" required [attr.disabled]="loading" [(ngModel)]="command.address" placeholder="Enter the merchant's address"
class="form-control" >
</ng-template> </ng-template>

View File

@ -11,7 +11,7 @@ import { ConfirmModalService } from '@poweredsoft/ngx-bootstrap';
}) })
export class GridFilterDemoComponent implements OnInit { export class GridFilterDemoComponent implements OnInit {
columns = ['id','name', 'address','commands'] columns = ['id','name', 'address', 'ordering','openDate', 'commands']
merchantDataSource: IDataSource<IMerchant>; merchantDataSource: IDataSource<IMerchant>;
constructor(private merchantService: MerchantService){ constructor(private merchantService: MerchantService){
this.merchantDataSource = this.createDataSource(); this.merchantDataSource = this.createDataSource();