Suppression de l'input 'refresh' et refactoring
This commit is contained in:
@@ -30,7 +30,7 @@
|
||||
</mat-menu>
|
||||
</mat-card-header>
|
||||
<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>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Component, AfterContentChecked, OnInit, OnDestroy } from '@angular/core';
|
||||
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 { MatCardModule } from '@angular/material/card';
|
||||
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
|
||||
@@ -11,10 +11,8 @@ import { Observable, Subscription } from 'rxjs';
|
||||
import { take } from 'rxjs/operators';
|
||||
|
||||
import { MenuItems, JumpAddDialogComponent, JumpTableComponent } from 'src/app/components/shared';
|
||||
//import { JumpTableComponent } from 'src/app/components/shared/helpers-jump';
|
||||
import { Errors, Jump, JumpAddParams, JumpListConfig, User } from 'src/app/core/models';
|
||||
import { Errors, Jump, JumpListConfig, User } from 'src/app/core/models';
|
||||
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_02.json';
|
||||
|
||||
@@ -41,7 +39,6 @@ export class LogbookComponent implements OnInit, OnDestroy, AfterContentChecked
|
||||
public lastJump: Jump = {} as Jump;
|
||||
public currentUser: User = {} as User;
|
||||
public listConfig: JumpListConfig = { type: 'all', filters: {} };
|
||||
public refresh: boolean = false;
|
||||
public isAuthenticated = false;
|
||||
public isUser = true;
|
||||
public canModify = false;
|
||||
@@ -103,7 +100,6 @@ export class LogbookComponent implements OnInit, OnDestroy, AfterContentChecked
|
||||
try {
|
||||
data.forEach((entry) => {
|
||||
Object.assign(this.jump, entry);
|
||||
//console.log(this.jump);
|
||||
this._jumpsService.save(this.jump)
|
||||
.pipe(take(1))
|
||||
.subscribe({
|
||||
@@ -152,7 +148,6 @@ export class LogbookComponent implements OnInit, OnDestroy, AfterContentChecked
|
||||
}
|
||||
|
||||
private _saveJump(jump: Jump, refresh: boolean) {
|
||||
//console.log(jump);
|
||||
this._jumpsService.save(jump)
|
||||
.pipe(take(1))
|
||||
.subscribe({
|
||||
@@ -162,7 +157,6 @@ export class LogbookComponent implements OnInit, OnDestroy, AfterContentChecked
|
||||
if (refresh) {
|
||||
this.jumpRefresh = !this.jumpRefresh;
|
||||
this._jumpTableService.updateJumpRefresh(this.jumpRefresh);
|
||||
//this.refresh = !this.refresh;
|
||||
this._lastjump$ = this._jumpsService.getLastJump();
|
||||
this._lastjump = this._lastjump$.subscribe((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 { UntypedFormBuilder, UntypedFormGroup, Validators, FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { Router, RouterLink } from '@angular/router';
|
||||
@@ -83,7 +83,6 @@ export class JumpTableComponent implements OnChanges, OnDestroy, AfterContentChe
|
||||
|
||||
@Input() title = '';
|
||||
@Input() limit = 0;
|
||||
@Input() refresh = false;
|
||||
@Input() showAdd = false;
|
||||
@Input() isUser = false;
|
||||
@Input()
|
||||
@@ -102,7 +101,6 @@ export class JumpTableComponent implements OnChanges, OnDestroy, AfterContentChe
|
||||
this.loading = true;
|
||||
this._query = this.config;
|
||||
this.runQuery();
|
||||
//this.refresh = false;
|
||||
console.log('ngOnChanges event in jump-table component');
|
||||
}
|
||||
|
||||
@@ -112,11 +110,6 @@ export class JumpTableComponent implements OnChanges, OnDestroy, AfterContentChe
|
||||
}
|
||||
|
||||
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) {
|
||||
this.jumpRefresh = this._jumpTableService.jumpRefresh;
|
||||
this.runQuery();
|
||||
@@ -148,8 +141,6 @@ export class JumpTableComponent implements OnChanges, OnDestroy, AfterContentChe
|
||||
this.jumps.paginator = this.paginator;
|
||||
this.jumps.sort = this.sort;
|
||||
this._resetErrors();
|
||||
//this.tableRefresh = !this.tableRefresh;
|
||||
//this._jumpTableService.updateJumpRefresh(this.tableRefresh);
|
||||
},
|
||||
error: (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 {
|
||||
const dialogRef = this.dialog.open(JumpDeleteDialogComponent, {
|
||||
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) {
|
||||
this.snackBar.open(content, title, {
|
||||
horizontalPosition: <MatSnackBarHorizontalPosition>'end',
|
||||
|
||||
Reference in New Issue
Block a user