demo checking
This commit is contained in:
-2
@@ -111,9 +111,7 @@ export class MultiSelectComponent implements OnInit {
|
||||
}
|
||||
|
||||
get selectedModel() {
|
||||
|
||||
return this.selectComponent.selectedItems.map(t => t.value);
|
||||
//return this.selectComponent.hasValue ? this.selectComponent.selectedItems[0].value : null;
|
||||
}
|
||||
|
||||
refreshDataSource(searchTerm:any = null, page:number = null, pageSize:number = null){
|
||||
|
||||
+2
-2
@@ -37,9 +37,9 @@ export class FormGroupCommandModalComponent implements OnInit {
|
||||
|
||||
ngOnInit(): void {
|
||||
this.errorMessage = null;
|
||||
// this._notifyMessage = this.dataSource.notifyMessage$.subscribe(message => {
|
||||
this._notifyMessage = this.dataSource.notifyMessage$.subscribe(message => {
|
||||
|
||||
// });
|
||||
});
|
||||
|
||||
this._validationError = this.dataSource.validationError$.subscribe(validatorErrors => {
|
||||
let validationSummary = '';
|
||||
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
<p>Select multiple elements</p>
|
||||
|
||||
<ng-select
|
||||
[items]="data$ | async"
|
||||
[multiple]="true"
|
||||
[closeOnSelect]="false"
|
||||
[searchable]="true"
|
||||
[bindLabel]="bindLabel"
|
||||
[typeahead] = "searchInput$"
|
||||
placeholder="Select people"
|
||||
[(ngModel)]="selectedId">
|
||||
</ng-select>
|
||||
|
||||
<div class="mt-3">
|
||||
Selected value: <br/>
|
||||
<ul>
|
||||
<li *ngFor="let item of selectedId">{{item.name}}</li>
|
||||
</ul>
|
||||
<button (click)="clearModel()" class="btn btn-secondary btn-sm">Clear model</button>
|
||||
<button (click)="changeModel()" class="btn btn-secondary btn-sm">Change model</button>
|
||||
</div>
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { NgMultiSelectComponent } from './ng-multi-select.component';
|
||||
|
||||
describe('NgMultiSelectComponent', () => {
|
||||
let component: NgMultiSelectComponent;
|
||||
let fixture: ComponentFixture<NgMultiSelectComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ NgMultiSelectComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(NgMultiSelectComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
-97
@@ -1,97 +0,0 @@
|
||||
import { Component, OnInit, Input, ChangeDetectorRef, OnDestroy } from '@angular/core';
|
||||
import { Observable, Subscription, Subject } from 'rxjs';
|
||||
import { IDataSource, ISimpleFilter } from '@poweredsoft/data';
|
||||
import { map, distinctUntilChanged, debounceTime } from 'rxjs/operators';
|
||||
|
||||
@Component({
|
||||
selector: 'ps-ng-multi-select',
|
||||
templateUrl: './ng-multi-select.component.html',
|
||||
styleUrls: ['./ng-multi-select.component.scss']
|
||||
})
|
||||
export class NgMultiSelectComponent implements OnInit, OnDestroy {
|
||||
|
||||
@Input() dataSource: IDataSource<any>;
|
||||
@Input() searchPath: string;
|
||||
@Input() searchType: string = "Contains";
|
||||
@Input() sortingPath: string;
|
||||
@Input() disableServer:boolean = false;
|
||||
@Input() bindLabel:string;
|
||||
|
||||
data$ : Observable<any[]>;
|
||||
selectedId:any[];
|
||||
isLoading:boolean = false;
|
||||
searchInput$ = new Subject<string>();
|
||||
private _dataSubscription: Subscription;
|
||||
|
||||
constructor(private cdr: ChangeDetectorRef) {
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this._dataSubscription.unsubscribe();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.dataFetching();
|
||||
this.detectLoading();
|
||||
if(!this.disableServer){
|
||||
this.searchOnServer();
|
||||
}else{
|
||||
this.refreshDataSource();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dataFetching(){
|
||||
this.data$ = this.dataSource.data$.pipe(
|
||||
map(t => {
|
||||
if (t == null)
|
||||
return [];
|
||||
return t.data;
|
||||
})
|
||||
);
|
||||
this._dataSubscription = this.dataSource.data$.subscribe();
|
||||
}
|
||||
|
||||
detectLoading(){
|
||||
this.dataSource.loading$.subscribe(loading => {
|
||||
this.isLoading = loading;
|
||||
this.cdr.detectChanges();
|
||||
});
|
||||
}
|
||||
|
||||
searchOnServer(){
|
||||
this.searchInput$.pipe(
|
||||
distinctUntilChanged(), // emit the difference from previous input
|
||||
debounceTime(500) // this is for delaying searching speed
|
||||
).subscribe(searchTerm => this.refreshDataSource(searchTerm, 1, 50)); // page: 1, pageSize: 100
|
||||
|
||||
this.refreshDataSource(); //send the query to server to sorting & filtering by default
|
||||
}
|
||||
|
||||
refreshDataSource(searchTerm:any = null, page:number=null, pageSize:number=null){
|
||||
let searchfilters:ISimpleFilter[] = null;
|
||||
if(searchTerm){
|
||||
searchfilters = [<ISimpleFilter>{
|
||||
path: this.searchPath,
|
||||
type: this.searchType, // Default: Contains
|
||||
value: searchTerm
|
||||
}]
|
||||
}
|
||||
this.dataSource.query({
|
||||
page: page,
|
||||
pageSize: pageSize,
|
||||
filters:searchfilters,
|
||||
sorts:[
|
||||
{path: this.sortingPath, ascending: true}
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
clearModel() {
|
||||
this.selectedId = [];
|
||||
}
|
||||
|
||||
changeModel() {
|
||||
this.selectedId = [{ name: 'New person' }];
|
||||
}
|
||||
}
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { NgSelectComponent } from './ng-select.component';
|
||||
|
||||
describe('NgSelectComponent', () => {
|
||||
let component: NgSelectComponent;
|
||||
let fixture: ComponentFixture<NgSelectComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ NgSelectComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(NgSelectComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
-143
@@ -1,143 +0,0 @@
|
||||
import { Component, OnInit, Input, ChangeDetectorRef, OnDestroy, ContentChild, QueryList, ContentChildren, ViewChild, forwardRef, EventEmitter, Output } from '@angular/core';
|
||||
import { IDataSource, ISimpleFilter } from '@poweredsoft/data';
|
||||
import { Observable, Subject, Subscription } from 'rxjs';
|
||||
import { distinctUntilChanged, debounceTime, map } from 'rxjs/operators';
|
||||
import { SelectOptionTemplateDirective } from '../select-option-template.directive';
|
||||
import { NgSelectComponent as SelectComponent } from '@ng-select/ng-select';
|
||||
import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';
|
||||
|
||||
@Component({
|
||||
selector: 'ps-ng-select',
|
||||
templateUrl: './ng-select.component.html',
|
||||
providers: [{
|
||||
provide: NG_VALUE_ACCESSOR,
|
||||
useExisting: forwardRef(() => NgSelectComponent),
|
||||
multi: true
|
||||
}],
|
||||
styleUrls: ['./ng-select.component.scss']
|
||||
})
|
||||
export class NgSelectComponent implements OnInit, OnDestroy, ControlValueAccessor {
|
||||
|
||||
@ContentChild(SelectOptionTemplateDirective) selectTemplate: SelectOptionTemplateDirective;
|
||||
@ViewChild(SelectComponent, { static: true }) selectComponent: SelectComponent;
|
||||
@Input() dataSource: IDataSource<any>;
|
||||
@Input() searchPath: string;
|
||||
@Input() searchType: string;
|
||||
@Input() sortingPath: string;
|
||||
@Input() serverFiltering:boolean;
|
||||
@Input() bindLabel:string;
|
||||
@Input() bindValue: string;
|
||||
|
||||
@Output('change') changeEvent = new EventEmitter();
|
||||
|
||||
trackFn: (item: any) => any;
|
||||
data$ : Observable<any[]>;
|
||||
isLoading:boolean = false;
|
||||
searchInput$ = new Subject<string>();
|
||||
|
||||
private _loadingSubscription: Subscription;
|
||||
|
||||
constructor(private cdr: ChangeDetectorRef) {
|
||||
this.trackFn = this.trackBy.bind(this);
|
||||
|
||||
}
|
||||
|
||||
valueChanged(event) {
|
||||
this.changeEvent.emit(event);
|
||||
}
|
||||
|
||||
writeValue(obj: any): void {
|
||||
this.selectComponent.writeValue(obj);
|
||||
}
|
||||
registerOnChange(fn: any): void {
|
||||
this.selectComponent.registerOnChange(fn);
|
||||
}
|
||||
registerOnTouched(fn: any): void {
|
||||
this.selectComponent.registerOnTouched(fn);
|
||||
}
|
||||
setDisabledState?(isDisabled: boolean): void {
|
||||
if (this.selectComponent.setDisabledState)
|
||||
this.selectComponent.setDisabledState(isDisabled);
|
||||
}
|
||||
|
||||
trackBy(item: any) {
|
||||
return this.dataSource.resolveIdField(item);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this._loadingSubscription.unsubscribe();
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.dataFetching();
|
||||
this.detectLoading();
|
||||
|
||||
console.log(this.serverFiltering);
|
||||
|
||||
if(this.serverFiltering){
|
||||
this.searchOnServer();
|
||||
}else{
|
||||
this.refreshDataSource();
|
||||
}
|
||||
}
|
||||
|
||||
dataFetching(){
|
||||
this.data$ = this.dataSource.data$.pipe(
|
||||
map(t => {
|
||||
if (t == null)
|
||||
return [];
|
||||
return t.data;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
detectLoading(){
|
||||
this._loadingSubscription = this.dataSource.loading$.subscribe(loading => {
|
||||
this.isLoading = loading;
|
||||
this.cdr.detectChanges();
|
||||
});
|
||||
}
|
||||
|
||||
searchOnServer(){
|
||||
this.searchInput$.pipe(
|
||||
distinctUntilChanged(), // emit the difference from previous input
|
||||
debounceTime(500) // this is for delaying searching speed
|
||||
).subscribe(searchTerm => this.refreshDataSource(searchTerm, 1, 100)); // page: 1, pageSize: 50
|
||||
|
||||
this.refreshDataSource(); //send the query to server to sorting & filtering by default
|
||||
}
|
||||
|
||||
get selectedModel() {
|
||||
return this.selectComponent.hasValue ? this.selectComponent.selectedItems[0].value : null;
|
||||
}
|
||||
|
||||
refreshDataSource(searchTerm:any = null, page:number = null, pageSize:number = null){
|
||||
let searchfilters:ISimpleFilter[] = null;
|
||||
if(searchTerm){
|
||||
searchfilters = [<ISimpleFilter>{
|
||||
path: this.searchPath || this.bindLabel,
|
||||
type: this.searchType || 'Contains', // Default: Contains
|
||||
value: searchTerm
|
||||
}]
|
||||
}
|
||||
this.dataSource.query({
|
||||
page: page,
|
||||
pageSize: pageSize,
|
||||
filters:searchfilters,
|
||||
sorts:[
|
||||
{path: this.sortingPath || this.bindLabel, ascending: true}
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
get hasOptionTemplate() {
|
||||
return this.selectTemplate ? true : false;
|
||||
}
|
||||
|
||||
get selectOptionTemplate(){
|
||||
if (this.selectTemplate)
|
||||
return this.selectTemplate.template;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgSelectComponent } from './ng-select/ng-select.component';
|
||||
import { NgMultiSelectComponent } from './ng-multi-select/ng-multi-select.component';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { NgSelectModule } from '@ng-select/ng-select';
|
||||
|
||||
|
||||
|
||||
|
||||
@NgModule({
|
||||
declarations: [NgSelectComponent, NgMultiSelectComponent ],
|
||||
imports: [
|
||||
CommonModule,
|
||||
FormsModule,
|
||||
NgSelectModule,
|
||||
],
|
||||
exports:[NgSelectComponent,NgMultiSelectComponent]
|
||||
})
|
||||
export class PsSelectorsModule { }
|
||||
@@ -13,7 +13,3 @@ export * from './lib/data-grid/directives/data-grid-loader.directive';
|
||||
export * from './lib/data-grid/directives/data-grid-cell-filter.directive';
|
||||
export * from './lib/data-grid/directives/data-grid-col-sort.directive';
|
||||
|
||||
//ng selects
|
||||
export * from './lib/ps-selectors/ps-selectors.module';
|
||||
export * from './lib/ps-selectors/ng-select/ng-select.component';
|
||||
export * from './lib/ps-selectors/ng-multi-select/ng-multi-select.component';
|
||||
|
||||
Reference in New Issue
Block a user