Suppression de l'input 'refresh' et refactoring

This commit is contained in:
Julien Gautier
2023-10-03 14:55:24 +02:00
parent 4a9f650483
commit 340228e698
3 changed files with 4 additions and 54 deletions
@@ -30,7 +30,7 @@
</mat-menu> </mat-menu>
</mat-card-header> </mat-card-header>
<mat-card-content class="my-4"> <mat-card-content class="my-4">
<huapp-jump-table #jumpTable [refresh]="refresh" [config]="listConfig" [isUser]="isUser" [showAdd]="canModify" [title]="title"> <huapp-jump-table #jumpTable [config]="listConfig" [isUser]="isUser" [showAdd]="canModify" [title]="title">
</huapp-jump-table> </huapp-jump-table>
</mat-card-content> </mat-card-content>
</mat-card> </mat-card>
@@ -1,6 +1,6 @@
import { Component, AfterContentChecked, OnInit, OnDestroy } from '@angular/core'; import { Component, AfterContentChecked, OnInit, OnDestroy } from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { ActivatedRoute, Router, RouterLink, RouterModule } from '@angular/router'; import { ActivatedRoute, Router, RouterModule } from '@angular/router';
import { MatButtonModule } from '@angular/material/button'; import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card'; import { MatCardModule } from '@angular/material/card';
import { MatDialog, MatDialogModule } from '@angular/material/dialog'; import { MatDialog, MatDialogModule } from '@angular/material/dialog';
@@ -11,10 +11,8 @@ import { Observable, Subscription } from 'rxjs';
import { take } from 'rxjs/operators'; import { take } from 'rxjs/operators';
import { MenuItems, JumpAddDialogComponent, JumpTableComponent } from 'src/app/components/shared'; import { MenuItems, JumpAddDialogComponent, JumpTableComponent } from 'src/app/components/shared';
//import { JumpTableComponent } from 'src/app/components/shared/helpers-jump'; import { Errors, Jump, JumpListConfig, User } from 'src/app/core/models';
import { Errors, Jump, JumpAddParams, JumpListConfig, User } from 'src/app/core/models';
import { JumpsService, JumpTableService, UserService } from 'src/app/core/services'; import { JumpsService, JumpTableService, UserService } from 'src/app/core/services';
import { environment } from 'src/environments/environment';
import data from 'src/jumps.json'; import data from 'src/jumps.json';
//import data from 'src/jumps_02.json'; //import data from 'src/jumps_02.json';
@@ -41,7 +39,6 @@ export class LogbookComponent implements OnInit, OnDestroy, AfterContentChecked
public lastJump: Jump = {} as Jump; public lastJump: Jump = {} as Jump;
public currentUser: User = {} as User; public currentUser: User = {} as User;
public listConfig: JumpListConfig = { type: 'all', filters: {} }; public listConfig: JumpListConfig = { type: 'all', filters: {} };
public refresh: boolean = false;
public isAuthenticated = false; public isAuthenticated = false;
public isUser = true; public isUser = true;
public canModify = false; public canModify = false;
@@ -103,7 +100,6 @@ export class LogbookComponent implements OnInit, OnDestroy, AfterContentChecked
try { try {
data.forEach((entry) => { data.forEach((entry) => {
Object.assign(this.jump, entry); Object.assign(this.jump, entry);
//console.log(this.jump);
this._jumpsService.save(this.jump) this._jumpsService.save(this.jump)
.pipe(take(1)) .pipe(take(1))
.subscribe({ .subscribe({
@@ -152,7 +148,6 @@ export class LogbookComponent implements OnInit, OnDestroy, AfterContentChecked
} }
private _saveJump(jump: Jump, refresh: boolean) { private _saveJump(jump: Jump, refresh: boolean) {
//console.log(jump);
this._jumpsService.save(jump) this._jumpsService.save(jump)
.pipe(take(1)) .pipe(take(1))
.subscribe({ .subscribe({
@@ -162,7 +157,6 @@ export class LogbookComponent implements OnInit, OnDestroy, AfterContentChecked
if (refresh) { if (refresh) {
this.jumpRefresh = !this.jumpRefresh; this.jumpRefresh = !this.jumpRefresh;
this._jumpTableService.updateJumpRefresh(this.jumpRefresh); this._jumpTableService.updateJumpRefresh(this.jumpRefresh);
//this.refresh = !this.refresh;
this._lastjump$ = this._jumpsService.getLastJump(); this._lastjump$ = this._jumpsService.getLastJump();
this._lastjump = this._lastjump$.subscribe((jump) => { this._lastjump = this._lastjump$.subscribe((jump) => {
this.lastJump = jump; this.lastJump = jump;
@@ -1,4 +1,4 @@
import { Component, AfterContentChecked, Input, ViewChild, OnChanges, OnDestroy, computed, Signal, WritableSignal } from '@angular/core'; import { Component, AfterContentChecked, Input, ViewChild, OnChanges, OnDestroy } from '@angular/core';
import { CommonModule, DecimalPipe, DatePipe } from '@angular/common'; import { CommonModule, DecimalPipe, DatePipe } from '@angular/common';
import { UntypedFormBuilder, UntypedFormGroup, Validators, FormsModule, ReactiveFormsModule } from '@angular/forms'; import { UntypedFormBuilder, UntypedFormGroup, Validators, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { Router, RouterLink } from '@angular/router'; import { Router, RouterLink } from '@angular/router';
@@ -83,7 +83,6 @@ export class JumpTableComponent implements OnChanges, OnDestroy, AfterContentChe
@Input() title = ''; @Input() title = '';
@Input() limit = 0; @Input() limit = 0;
@Input() refresh = false;
@Input() showAdd = false; @Input() showAdd = false;
@Input() isUser = false; @Input() isUser = false;
@Input() @Input()
@@ -102,7 +101,6 @@ export class JumpTableComponent implements OnChanges, OnDestroy, AfterContentChe
this.loading = true; this.loading = true;
this._query = this.config; this._query = this.config;
this.runQuery(); this.runQuery();
//this.refresh = false;
console.log('ngOnChanges event in jump-table component'); console.log('ngOnChanges event in jump-table component');
} }
@@ -112,11 +110,6 @@ export class JumpTableComponent implements OnChanges, OnDestroy, AfterContentChe
} }
ngAfterContentChecked() { ngAfterContentChecked() {
//console.log('jump-table ngAfterContentChecked', this.tableRefresh, this._jumpTableService.tableRefresh);
/*if (this.tableRefresh != this._jumpTableService.tableRefresh) {
this.tableRefresh = this._jumpTableService.tableRefresh;
console.log('refresh table', this.tableRefresh, this._jumpTableService.tableRefresh);
}*/
if (this.jumpRefresh != this._jumpTableService.jumpRefresh) { if (this.jumpRefresh != this._jumpTableService.jumpRefresh) {
this.jumpRefresh = this._jumpTableService.jumpRefresh; this.jumpRefresh = this._jumpTableService.jumpRefresh;
this.runQuery(); this.runQuery();
@@ -148,8 +141,6 @@ export class JumpTableComponent implements OnChanges, OnDestroy, AfterContentChe
this.jumps.paginator = this.paginator; this.jumps.paginator = this.paginator;
this.jumps.sort = this.sort; this.jumps.sort = this.sort;
this._resetErrors(); this._resetErrors();
//this.tableRefresh = !this.tableRefresh;
//this._jumpTableService.updateJumpRefresh(this.tableRefresh);
}, },
error: (err) => { error: (err) => {
this.errors = err; this.errors = err;
@@ -165,19 +156,6 @@ export class JumpTableComponent implements OnChanges, OnDestroy, AfterContentChe
}); });
} }
openAddDialog(): void {
const dialogRef = this.dialog.open(JumpAddDialogComponent, {
width: '70vw',
data: this.jump
});
dialogRef.afterClosed().pipe(take(1))
.subscribe(result => {
if (result != undefined) {
this._onEntry(result);
}
});
}
openDeleteDialog(jump: Jump): void { openDeleteDialog(jump: Jump): void {
const dialogRef = this.dialog.open(JumpDeleteDialogComponent, { const dialogRef = this.dialog.open(JumpDeleteDialogComponent, {
width: '60vw', width: '60vw',
@@ -265,28 +243,6 @@ export class JumpTableComponent implements OnChanges, OnDestroy, AfterContentChe
} }
} }
private _onEntry(entry: NonNullable<unknown>): void {
try {
this.isSubmitting = true;
Object.assign(this.jump, entry);
this._jumpsService.save(this.jump)
.pipe(take(1))
.subscribe({
next: (jump) => {
this._openSnackBar(`Le saut n°${jump.numero} a été ajouté !`, 'OK');
this._resetErrors();
this.runQuery();
},
error: (err) => {
this.errors = err;
this.isSubmitting = false;
}
});
} catch (error) {
console.error(error);
}
}
private _openSnackBar(content: string, title: string) { private _openSnackBar(content: string, title: string) {
this.snackBar.open(content, title, { this.snackBar.open(content, title, {
horizontalPosition: <MatSnackBarHorizontalPosition>'end', horizontalPosition: <MatSnackBarHorizontalPosition>'end',