connexion avec le back (non testé)
This commit is contained in:
parent
22f6d316b4
commit
6b9a6d7c73
14 changed files with 215 additions and 130 deletions
|
|
@ -2,8 +2,7 @@ import {AfterViewInit, Component, ViewChild} from '@angular/core';
|
|||
import {MatTableDataSource} from "@angular/material/table";
|
||||
import {MatSort} from "@angular/material/sort";
|
||||
import {MatPaginator} from "@angular/material/paginator";
|
||||
import {FictitiousDatasService} from "../../common/services/fictitiousDatas/fictitious-datas.service";
|
||||
import {MatDialog} from "@angular/material/dialog";
|
||||
import {MessageService} from "../../common/services/message/message.service";
|
||||
|
||||
|
||||
|
||||
|
|
@ -15,33 +14,41 @@ import {MatDialog} from "@angular/material/dialog";
|
|||
export class PageRegistryComponent implements AfterViewInit
|
||||
{
|
||||
displayedColumns: string[] = [ "nickname", "email", "role" ];
|
||||
dataSource: MatTableDataSource<any>;
|
||||
dataSource: MatTableDataSource<any> = new MatTableDataSource<any>();
|
||||
@ViewChild(MatSort) sort: MatSort;
|
||||
@ViewChild(MatPaginator) paginator: MatPaginator;
|
||||
|
||||
|
||||
constructor( private fictitiousDatasService: FictitiousDatasService,
|
||||
public dialog: MatDialog ) { }
|
||||
constructor( private messageService: MessageService ) { }
|
||||
|
||||
|
||||
ngAfterViewInit(): void
|
||||
{
|
||||
// Faux code
|
||||
let tabPerson = this.fictitiousDatasService.getTabPerson(5);
|
||||
|
||||
// Vrai code ...
|
||||
|
||||
tabPerson = tabPerson.map( person => {
|
||||
if(!person.is_admin) return Object.assign(person, {role: "utilisateur"});
|
||||
else return Object.assign(person, {role: "admin"});
|
||||
});
|
||||
this.dataSource = new MatTableDataSource(tabPerson);
|
||||
this.dataSource.sort = this.sort;
|
||||
this.dataSource.paginator = this.paginator;
|
||||
this.messageService
|
||||
.get('users?order_by=nickname')
|
||||
.subscribe(retour => this.ngAfterViewInitCallback(retour), err => this.ngAfterViewInitCallback(err));
|
||||
}
|
||||
|
||||
|
||||
applyFilter(event: Event)
|
||||
ngAfterViewInitCallback(retour: any): void
|
||||
{
|
||||
if(retour.status !== "success") {
|
||||
console.log(retour);
|
||||
}
|
||||
else {
|
||||
let tabPerson: { id: number, email: string, nickname: string, is_admin: boolean }[] = retour.data;
|
||||
tabPerson = tabPerson.map( person => {
|
||||
if(!person.is_admin) return Object.assign(person, {role: "utilisateur"});
|
||||
else return Object.assign(person, {role: "admin"});
|
||||
});
|
||||
this.dataSource = new MatTableDataSource(tabPerson);
|
||||
this.dataSource.sort = this.sort;
|
||||
this.dataSource.paginator = this.paginator;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
applyFilter(event: Event): void
|
||||
{
|
||||
const filterValue = (event.target as HTMLInputElement).value;
|
||||
this.dataSource.filter = filterValue.trim().toLowerCase();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue