Skip to content
Snippets Groups Projects
Commit f1b5610f authored by Alex ORLUC's avatar Alex ORLUC
Browse files

FEAT #14454 TIME 0:20 save filter baskets admin

parent 521dd557
No related branches found
No related tags found
No related merge requests found
...@@ -12,7 +12,6 @@ import { catchError } from 'rxjs/internal/operators/catchError'; ...@@ -12,7 +12,6 @@ import { catchError } from 'rxjs/internal/operators/catchError';
import { of } from 'rxjs/internal/observable/of'; import { of } from 'rxjs/internal/observable/of';
import { NotificationService } from '../../service/notification/notification.service'; import { NotificationService } from '../../service/notification/notification.service';
import { FormControl } from '@angular/forms'; import { FormControl } from '@angular/forms';
import { debounceTime } from 'rxjs/operators';
@Injectable() @Injectable()
export class AdministrationService { export class AdministrationService {
...@@ -30,6 +29,12 @@ export class AdministrationService { ...@@ -30,6 +29,12 @@ export class AdministrationService {
page: 0, page: 0,
field: '' field: ''
}, },
admin_baskets: {
sort: 'basket_id',
sortDirection: 'asc',
page: 0,
field: ''
},
}; };
dataSource: MatTableDataSource<any>; dataSource: MatTableDataSource<any>;
filterColumns: string[]; filterColumns: string[];
......
...@@ -38,8 +38,7 @@ ...@@ -38,8 +38,7 @@
<div class="row"> <div class="row">
<div class="col-md-6 col-xs-6"> <div class="col-md-6 col-xs-6">
<mat-form-field> <mat-form-field>
<input matInput (keyup)="applyFilter($event.target.value)" <input matInput [formControl]="adminService.getFilterField()" placeholder="{{lang.filterBy}}">
placeholder="{{lang.filterBy}}">
</mat-form-field> </mat-form-field>
</div> </div>
<div class="col-md-6 col-xs-6"> <div class="col-md-6 col-xs-6">
...@@ -47,8 +46,7 @@ ...@@ -47,8 +46,7 @@
</mat-paginator> </mat-paginator>
</div> </div>
</div> </div>
<mat-table #table [dataSource]="dataSource" matSort matSortActive="basket_id" <mat-table #table [dataSource]="adminService.getDataSource()" [matSortActive]="adminService.getFilter('sort')" [matSortDirection]="adminService.getFilter('sortDirection')" matSort>
matSortDirection="asc">
<ng-container matColumnDef="basket_id"> <ng-container matColumnDef="basket_id">
<mat-header-cell *matHeaderCellDef mat-sort-header <mat-header-cell *matHeaderCellDef mat-sort-header
[class.hide-for-mobile]="appService.getViewMode()">{{lang.id}}</mat-header-cell> [class.hide-for-mobile]="appService.getViewMode()">{{lang.id}}</mat-header-cell>
......
...@@ -4,11 +4,13 @@ import { LANG } from '../../translate.component'; ...@@ -4,11 +4,13 @@ import { LANG } from '../../translate.component';
import { MatPaginator } from '@angular/material/paginator'; import { MatPaginator } from '@angular/material/paginator';
import { MatSidenav } from '@angular/material/sidenav'; import { MatSidenav } from '@angular/material/sidenav';
import { MatSort } from '@angular/material/sort'; import { MatSort } from '@angular/material/sort';
import { MatTableDataSource } from '@angular/material/table';
import { NotificationService } from '../../../service/notification/notification.service'; import { NotificationService } from '../../../service/notification/notification.service';
import { HeaderService } from '../../../service/header.service'; import { HeaderService } from '../../../service/header.service';
import { AppService } from '../../../service/app.service'; import { AppService } from '../../../service/app.service';
import { FunctionsService } from '../../../service/functions.service'; import { FunctionsService } from '../../../service/functions.service';
import { AdministrationService } from '../administration.service';
import { catchError, tap, finalize } from 'rxjs/operators';
import { of } from 'rxjs/internal/observable/of';
@Component({ @Component({
templateUrl: 'baskets-administration.component.html' templateUrl: 'baskets-administration.component.html'
...@@ -25,18 +27,10 @@ export class BasketsAdministrationComponent implements OnInit { ...@@ -25,18 +27,10 @@ export class BasketsAdministrationComponent implements OnInit {
basketsOrder: any[] = []; basketsOrder: any[] = [];
displayedColumns = ['basket_id', 'basket_name', 'basket_desc', 'actions']; displayedColumns = ['basket_id', 'basket_name', 'basket_desc', 'actions'];
dataSource: any; filterColumns = ['basket_id', 'basket_name', 'basket_desc'];
@ViewChild(MatPaginator, { static: false }) paginator: MatPaginator; @ViewChild(MatPaginator, { static: false }) paginator: MatPaginator;
@ViewChild(MatSort, { static: false }) sort: MatSort; @ViewChild(MatSort, { static: false }) sort: MatSort;
applyFilter(filterValue: string) {
filterValue = filterValue.trim(); // Remove whitespace
filterValue = filterValue.toLowerCase(); // MatTableDataSource defaults to lowercase matches
this.dataSource.filter = filterValue;
this.dataSource.filterPredicate = (template: any, filter: string) => {
return this.functions.filterUnSensitive(template, filter, ['basket_id', 'basket_name', 'basket_desc']);
};
}
constructor( constructor(
public http: HttpClient, public http: HttpClient,
...@@ -44,6 +38,7 @@ export class BasketsAdministrationComponent implements OnInit { ...@@ -44,6 +38,7 @@ export class BasketsAdministrationComponent implements OnInit {
private headerService: HeaderService, private headerService: HeaderService,
public appService: AppService, public appService: AppService,
public functions: FunctionsService, public functions: FunctionsService,
public adminService: AdministrationService,
private viewContainerRef: ViewContainerRef private viewContainerRef: ViewContainerRef
) { } ) { }
...@@ -53,29 +48,32 @@ export class BasketsAdministrationComponent implements OnInit { ...@@ -53,29 +48,32 @@ export class BasketsAdministrationComponent implements OnInit {
this.loading = true; this.loading = true;
this.getSortedBasket();
this.http.get('../rest/baskets') this.http.get('../rest/baskets')
.subscribe((data: any) => { .subscribe((data: any) => {
this.baskets = data['baskets']; this.baskets = data['baskets'];
this.loading = false; this.loading = false;
setTimeout(() => { setTimeout(() => {
this.http.get('../rest/sortedBaskets') this.adminService.setDataSource('admin_baskets', this.baskets, this.sort, this.paginator, this.filterColumns);
.subscribe((dataSort: any) => {
this.basketsOrder = dataSort['baskets'];
}, (err) => {
this.notify.handleErrors(err);
});
this.dataSource = new MatTableDataSource(this.baskets);
this.dataSource.paginator = this.paginator;
this.dataSource.sortingDataAccessor = this.functions.listSortingDataAccessor;
this.sort.active = 'basket_id';
this.sort.direction = 'asc';
this.dataSource.sort = this.sort;
}, 0); }, 0);
}, (err) => { }, (err) => {
this.notify.handleErrors(err); this.notify.handleErrors(err);
}); });
} }
getSortedBasket() {
this.http.get('../rest/sortedBaskets').pipe(
tap((dataSort: any) => {
this.basketsOrder = dataSort['baskets'];
}),
catchError((err: any) => {
this.notify.handleSoftErrors(err);
return of(false);
})
).subscribe();
}
delete(basket: any) { delete(basket: any) {
const r = confirm(this.lang.confirmAction + ' ' + this.lang.delete + ' « ' + basket['basket_name'] + ' »'); const r = confirm(this.lang.confirmAction + ' ' + this.lang.delete + ' « ' + basket['basket_name'] + ' »');
...@@ -84,15 +82,8 @@ export class BasketsAdministrationComponent implements OnInit { ...@@ -84,15 +82,8 @@ export class BasketsAdministrationComponent implements OnInit {
.subscribe((data: any) => { .subscribe((data: any) => {
this.notify.success(this.lang.basketDeleted); this.notify.success(this.lang.basketDeleted);
this.baskets = data['baskets']; this.baskets = data['baskets'];
this.dataSource = new MatTableDataSource(this.baskets); this.adminService.setDataSource('admin_baskets', this.baskets, this.sort, this.paginator, this.filterColumns);
this.dataSource.paginator = this.paginator; this.getSortedBasket();
this.dataSource.sort = this.sort;
this.http.get('../rest/sortedBaskets')
.subscribe((dataSort: any) => {
this.basketsOrder = dataSort['baskets'];
}, (err) => {
this.notify.handleErrors(err);
});
}, (err: any) => { }, (err: any) => {
this.notify.error(err.error.errors); this.notify.error(err.error.errors);
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment