Commit abd4d7d1 authored by RenanMontenegro3's avatar RenanMontenegro3

feat(components): ajustes nas páginas de aceites e navios (edição, adição, listagem e visualização)

parent b31d0e30
...@@ -120,7 +120,7 @@ ...@@ -120,7 +120,7 @@
</div> </div>
<div class="row"> <div class="row">
<mat-form-field class="field full-width" appearance="outline"> <mat-form-field class="field full-width" appearance="outline">
<mat-label>Observação</mat-label> <mat-label>Observação do Solicitante</mat-label>
<input matInput type="text" formControlName="obs"> <input matInput type="text" formControlName="obs">
<mat-error *ngIf="empForm.get('obs')?.invalid">{{ getErrorMessage('obs') }}</mat-error> <mat-error *ngIf="empForm.get('obs')?.invalid">{{ getErrorMessage('obs') }}</mat-error>
</mat-form-field> </mat-form-field>
......
...@@ -117,7 +117,7 @@ ...@@ -117,7 +117,7 @@
<div class="row"> <div class="row">
<mat-form-field class="field full-width" appearance="outline"> <mat-form-field class="field full-width" appearance="outline">
<mat-label>Observação</mat-label> <mat-label>Observação do Solicitante</mat-label>
<input matInput type="text" formControlName="obs"> <input matInput type="text" formControlName="obs">
<mat-error *ngIf="empForm.get('obs')?.invalid">{{ getErrorMessage('obs') }}</mat-error> <mat-error *ngIf="empForm.get('obs')?.invalid">{{ getErrorMessage('obs') }}</mat-error>
</mat-form-field> </mat-form-field>
...@@ -136,35 +136,24 @@ ...@@ -136,35 +136,24 @@
</mat-form-field> </mat-form-field>
</div> </div>
<div *ngIf="empForm.get('status')?.value === 'Y' || empForm.get('status')?.value === 'NE'" class="field large"> <div *ngIf="empForm.get('status')?.value === 'Y' || empForm.get('status')?.value === 'NE'" class="field large">
<mat-form-field class="field large" appearance="outline"> <mat-form-field class="field large" appearance="outline" style="width: 100%;">
<mat-label>Comentários sobre o aceite:</mat-label> <mat-label>Comentários sobre o aceite:</mat-label>
<input matInput type="text" formControlName="restricoes"> <textarea matInput formControlName="restricoes" rows="4"
placeholder="Adicione observações ou comentários detalhados..."></textarea>
<mat-error *ngIf="empForm.get('restricoes')?.invalid"> <mat-error *ngIf="empForm.get('restricoes')?.invalid">
{{ getErrorMessage('restricoes') }} {{ getErrorMessage('restricoes') }}
</mat-error> </mat-error>
</mat-form-field> </mat-form-field>
<div class="row file-upload-container">
<mat-label style="color:cadetblue">Adicione o documente Q88 da embarcação</mat-label>
<input type="file" class="file-input" (change)="onFileSelected($event)" #fileUpload style="display: none" />
<div class="file-upload-content">
<div class="file-info">
<span>{{ fileName || "No file uploaded yet." }}</span>
</div>
<div class="upload-button-wrapper"> <div class="row file-upload-container">
<button mat-mini-fab color="primary" class="upload-btn" (click)="fileUpload.click()" type="button"> <ng-container *ngIf="data?.path">
<mat-icon>attach_file</mat-icon> <mat-card-actions>
</button> <button mat-flat-button color="primary" (click)="downloadNavioFunction()">
</div> <mat-icon>download</mat-icon>
</div> Download Documento Q88
<div class="uploaded-image-container" *ngIf="imageUrl">
<img [src]="imageUrl" alt="Uploaded Image" class="uploaded-image" />
<button mat-mini-fab color="warn" class="remove-image-btn" (click)="removeImage()" type="button">
<mat-icon>close</mat-icon>
</button> </button>
</div> </mat-card-actions>
</ng-container>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -23,7 +23,9 @@ import { NgxCurrencyDirective } from 'ngx-currency'; ...@@ -23,7 +23,9 @@ import { NgxCurrencyDirective } from 'ngx-currency';
import { BercosService } from '../../../services/bercos/bercos.service'; import { BercosService } from '../../../services/bercos/bercos.service';
import { PageEvent } from '@angular/material/paginator'; import { PageEvent } from '@angular/material/paginator';
import { throwError } from 'rxjs'; import { throwError } from 'rxjs';
import { MatCardActions } from '@angular/material/card';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../../../environments/.env';
@Component({ @Component({
selector: 'app-aceite-edit', selector: 'app-aceite-edit',
standalone: true, standalone: true,
...@@ -39,7 +41,7 @@ import { throwError } from 'rxjs'; ...@@ -39,7 +41,7 @@ import { throwError } from 'rxjs';
MatSelectModule, MatSelectModule,
MatRadioModule, MatRadioModule,
MatIconModule, // Corrigido MatIconModule, // Corrigido
MatSnackBarModule, NgxCurrencyDirective MatSnackBarModule, NgxCurrencyDirective, MatCardActions
], ],
templateUrl: './aceite-edit.component.html', templateUrl: './aceite-edit.component.html',
styleUrl: './aceite-edit.component.scss' styleUrl: './aceite-edit.component.scss'
...@@ -65,6 +67,8 @@ export class AceiteEditComponent implements OnInit { ...@@ -65,6 +67,8 @@ export class AceiteEditComponent implements OnInit {
private toastService: ToastrService, private toastService: ToastrService,
private _bercoService: BercosService, private _bercoService: BercosService,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,
private httpClient: HttpClient,
) { ) {
this.empForm = this._fb.group({ this.empForm = this._fb.group({
...@@ -80,7 +84,7 @@ export class AceiteEditComponent implements OnInit { ...@@ -80,7 +84,7 @@ export class AceiteEditComponent implements OnInit {
mfold_quilha: ['',], mfold_quilha: ['',],
categoria: [Number(this.data?.categoria) || '', Validators.required], categoria: [Number(this.data?.categoria) || '', Validators.required],
flag: ['', Validators.required], flag: ['', Validators.required],
obs: ['', Validators.required], obs: [''],
calado_entrada: ['', Validators.required], calado_entrada: ['', Validators.required],
calado_saida: ['', Validators.required], calado_saida: ['', Validators.required],
restricoes: [''] restricoes: ['']
...@@ -101,6 +105,29 @@ export class AceiteEditComponent implements OnInit { ...@@ -101,6 +105,29 @@ export class AceiteEditComponent implements OnInit {
} }
selectedCategoriaNome: string = ''; selectedCategoriaNome: string = '';
downloadNavioFunction() {
this.httpClient
.get(`${environment.API_URL}/api/download-file`, {
params: { filename: this.data.path },
responseType: 'blob' // Adiciona 'blob' para lidar com arquivos binários
}).subscribe({
next: (response) => {
// Criação de um URL temporário para o arquivo
const blob = new Blob([response]);
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = this.data.path || 'download'; // Define o nome do arquivo
link.click();
// Libera o objeto URL após o download
window.URL.revokeObjectURL(link.href);
console.log('Download iniciado:', this.data.path);
},
error: (error) => {
console.error('Erro ao baixar o arquivo:', error);
}
});}
onCategoriaChange(catId: any) { onCategoriaChange(catId: any) {
const cat = this.categoria.find((c: any) => c.id === catId); const cat = this.categoria.find((c: any) => c.id === catId);
this.selectedCategoriaNome = cat ? cat.nome : ''; this.selectedCategoriaNome = cat ? cat.nome : '';
......
...@@ -83,14 +83,15 @@ ...@@ -83,14 +83,15 @@
getErrorMessage("mfold_quilha") getErrorMessage("mfold_quilha")
}}</mat-error> }}</mat-error>
</mat-form-field> </mat-form-field>
<div class="row"> <div class="row">
<mat-form-field class="field medium" appearance="outline"> <mat-form-field class="field medium" appearance="outline">
<mat-label>Calado Máximo</mat-label> <mat-label>Calado Máximo</mat-label>
<input matInput type="text" formControlName="calado_max" [currencyMask]="{ prefix: '', thousands: '.', decimal: ',' }"> <input matInput type="text" formControlName="calado_max"
[currencyMask]="{ prefix: '', thousands: '.', decimal: ',' }">
<mat-error *ngIf="empForm.get('calado_max')?.invalid"> <mat-error *ngIf="empForm.get('calado_max')?.invalid">
{{ getErrorMessage('calado_max') }} {{ getErrorMessage('calado_max') }}
</mat-error> </mat-error>
</mat-form-field> </mat-form-field>
</div> </div>
<mat-form-field class="field medium" appearance="outline"> <mat-form-field class="field medium" appearance="outline">
<mat-label>Categoria</mat-label> <mat-label>Categoria</mat-label>
...@@ -105,28 +106,14 @@ ...@@ -105,28 +106,14 @@
<mat-label>Flag</mat-label> <mat-label>Flag</mat-label>
<mat-select formControlName="flag"> <mat-select formControlName="flag">
<mat-select-trigger> <mat-select-trigger>
<img <img *ngIf="selectedCountry" [src]="selectedCountry.flagUrl" width="20" height="15"
*ngIf="selectedCountry" alt="{{ selectedCountry.name }} flag" style="margin-right: 8px" />
[src]="selectedCountry.flagUrl"
width="20"
height="15"
alt="{{ selectedCountry.name }} flag"
style="margin-right: 8px"
/>
{{ selectedCountry?.name }} {{ selectedCountry?.name }}
</mat-select-trigger> </mat-select-trigger>
<mat-option <mat-option *ngFor="let country of countries" [value]="country.id"
*ngFor="let country of countries" (onSelectionChange)="onCountrySelected(country)">
[value]="country.id" <img [src]="country.flagUrl" width="20" height="15" alt="{{ country.name }} flag"
(onSelectionChange)="onCountrySelected(country)" style="margin-right: 8px" />
>
<img
[src]="country.flagUrl"
width="20"
height="15"
alt="{{ country.name }} flag"
style="margin-right: 8px"
/>
{{ country.name }} {{ country.name }}
</mat-option> </mat-option>
</mat-select> </mat-select>
...@@ -144,30 +131,14 @@ ...@@ -144,30 +131,14 @@
}}</mat-error> }}</mat-error>
</mat-form-field> </mat-form-field>
</div> </div>
<div class="row file-upload-container"> <ng-container *ngIf="data?.path">
<mat-label style="color:cadetblue">Adicione o documente Q88 da embarcação</mat-label> <mat-card-actions>
<input type="file" class="file-input" (change)="onFileSelected($event)" #fileUpload style="display: none" /> <button mat-flat-button color="primary" (click)="downloadNavioFunction()">
<mat-icon>download</mat-icon>
<div class="file-upload-content"> Download Documento Q88
<div class="file-info">
<span>{{ fileName || "No file uploaded yet." }}</span>
</div>
<div class="upload-button-wrapper">
<button mat-mini-fab color="primary" class="upload-btn" (click)="fileUpload.click()" type="button">
<mat-icon>attach_file</mat-icon>
</button>
</div>
</div>
<div class="uploaded-image-container" *ngIf="imageUrl">
<img [src]="imageUrl" alt="Uploaded Image" class="uploaded-image" />
<button mat-mini-fab color="warn" class="remove-image-btn" (click)="removeImage()">
<mat-icon>close</mat-icon>
</button> </button>
</div> </mat-card-actions>
</div> </ng-container>
</div> </div>
<div mat-dialog-actions class="action"> <div mat-dialog-actions class="action">
<button mat-raised-button type="button" color="warn" [mat-dialog-close]="false"> <button mat-raised-button type="button" color="warn" [mat-dialog-close]="false">
......
...@@ -17,6 +17,10 @@ import { MatDialogModule } from '@angular/material/dialog'; ...@@ -17,6 +17,10 @@ import { MatDialogModule } from '@angular/material/dialog';
import { NaviosComponent } from '../navios/navios.component'; import { NaviosComponent } from '../navios/navios.component';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { NgxCurrencyDirective } from 'ngx-currency'; import { NgxCurrencyDirective } from 'ngx-currency';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../../../environments/.env';
import { MatCardModule } from '@angular/material/card';
@Component({ @Component({
selector: 'app-navio-edit', selector: 'app-navio-edit',
standalone: true, standalone: true,
...@@ -35,6 +39,7 @@ import { NgxCurrencyDirective } from 'ngx-currency'; ...@@ -35,6 +39,7 @@ import { NgxCurrencyDirective } from 'ngx-currency';
MatSnackBarModule, MatSnackBarModule,
NaviosComponent, NaviosComponent,
NgxCurrencyDirective, NgxCurrencyDirective,
MatCardModule,
], ],
templateUrl: './navio-edit.component.html', templateUrl: './navio-edit.component.html',
styleUrl: './navio-edit.component.scss', styleUrl: './navio-edit.component.scss',
...@@ -57,7 +62,9 @@ export class NavioEditComponent implements OnInit { ...@@ -57,7 +62,9 @@ export class NavioEditComponent implements OnInit {
private _dialogRef: MatDialogRef<NavioService>, private _dialogRef: MatDialogRef<NavioService>,
@Inject(MAT_DIALOG_DATA) public data: any, @Inject(MAT_DIALOG_DATA) public data: any,
private _coreService: CoreService, private _coreService: CoreService,
private toastService: ToastrService private toastService: ToastrService,
private httpClient: HttpClient ,// Adicione isto
) { ) {
this.empForm = this._fb.group({ this.empForm = this._fb.group({
imo: [this.data?.imo || '', Validators.required], imo: [this.data?.imo || '', Validators.required],
...@@ -90,6 +97,30 @@ this.empForm.get('categoria')?.valueChanges.subscribe(catId => { ...@@ -90,6 +97,30 @@ this.empForm.get('categoria')?.valueChanges.subscribe(catId => {
const cat = this.categoria.find((c: any) => c.id === catId); const cat = this.categoria.find((c: any) => c.id === catId);
this.selectedCategoriaNome = cat ? cat.nome : ''; this.selectedCategoriaNome = cat ? cat.nome : '';
} }
downloadNavioFunction() {
this.httpClient
.get(`${environment.API_URL}/api/download-file`, {
params: { filename: this.data.path },
responseType: 'blob', // Adiciona 'blob' para lidar com arquivos binários
})
.subscribe({
next: (response) => {
// Criação de um URL temporário para o arquivo
const blob = new Blob([response]);
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = this.data.path || 'download'; // Define o nome do arquivo
link.click();
// Libera o objeto URL após o download
window.URL.revokeObjectURL(link.href);
console.log('Download iniciado:', this.data.path);
},
error: (error) => {
console.error('Erro ao baixar o arquivo:', error);
},
});
}
countries = [ countries = [
{ id: 1, name: 'Afeganistão', flagUrl: 'https://flagcdn.com/w20/af.png' }, { id: 1, name: 'Afeganistão', flagUrl: 'https://flagcdn.com/w20/af.png' },
{ id: 2, name: 'África do Sul', flagUrl: 'https://flagcdn.com/w20/za.png' }, { id: 2, name: 'África do Sul', flagUrl: 'https://flagcdn.com/w20/za.png' },
......
<app-add-search <app-add-search [title]="'Navios'" [primaryButtonText]="'Adicionar Navio'" [primaryButtonColor]="'primary'"
[title]="'Navios'" [primaryButtonAction]="openAddEmpForm.bind(this)" [secondaryButtonText]="'Buscar Navio'"
[primaryButtonText]="'Adicionar Navio'" [secondaryButtonColor]="'accent'" [secondaryButtonAction]="openAddEmpFormSearch.bind(this)">
[primaryButtonColor]="'primary'"
[primaryButtonAction]="openAddEmpForm.bind(this)"
[secondaryButtonText]="'Buscar Navio'"
[secondaryButtonColor]="'accent'"
[secondaryButtonAction]="openAddEmpFormSearch.bind(this)"
>
</app-add-search> </app-add-search>
<div class="main-body"> <div class="main-body">
<button mat-raised-button color="primary" style="background-color: #43a047; color: #fff; margin: 12px 0;" (click)="saveDataInCSV('aceites')"> <button mat-raised-button color="primary" style="background-color: #43a047; color: #fff; margin: 12px 0;"
(click)="saveDataInCSV('aceites')">
<mat-icon>download</mat-icon> <mat-icon>download</mat-icon>
Exportar Excel Exportar Excel
</button> </button>
<div class="table-container" style="overflow-x: auto"> <div class="table-container" style="overflow-x: auto">
<table mat-table [dataSource]="dataSource" matSort> <table mat-table [dataSource]="dataSource" matSort>
<!-- ID Column --> <!-- ID Column -->
...@@ -52,22 +47,21 @@ ...@@ -52,22 +47,21 @@
<ng-container matColumnDef="flag"> <ng-container matColumnDef="flag">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Flag</th> <th mat-header-cell *matHeaderCellDef mat-sort-header>Flag</th>
<td mat-cell *matCellDef="let row"> <td mat-cell *matCellDef="let row">
<ng-container *ngIf="row.flag; else noFlag"> <ng-container *ngIf="getCountryById(row.flag) as country; else noFlag">
<div style="display: inline-flex; align-items: center;"> <div style="display: inline-flex; align-items: center;">
<img <img [src]="country.flagUrl" width="20" height="15" alt="{{ country.name }} flag"
[src]="countries[row.flag]?.flagUrl" style="margin-right: 8px;" />
width="20" <span>{{ country.name }}</span>
height="15"
alt="{{ countries[row.flag]?.name }} flag"
style="margin-right: 8px"
/>
<span>{{ countries[row.flag]?.name }}</span>
</div> </div>
</ng-container> </ng-container>
<ng-template #noFlag>Não Informado</ng-template> <ng-template #noFlag>
<span>Não informado</span>
</ng-template>
</td> </td>
</ng-container> </ng-container>
<!-- Action Column --> <!-- Action Column -->
<ng-container matColumnDef="action"> <ng-container matColumnDef="action">
<th mat-header-cell *matHeaderCellDef>Action</th> <th mat-header-cell *matHeaderCellDef>Action</th>
...@@ -81,12 +75,7 @@ ...@@ -81,12 +75,7 @@
<button mat-icon-button color="warn" (click)="deleteEmployee(row.id)" *ngIf="user.role === 'COMPANY'"> <button mat-icon-button color="warn" (click)="deleteEmployee(row.id)" *ngIf="user.role === 'COMPANY'">
<mat-icon>delete</mat-icon> <mat-icon>delete</mat-icon>
</button> </button>
<button <button *ngIf="user.role === 'COMPANY'" mat-icon-button color="accent" (click)="addBlackList(row)">
*ngIf="user.role === 'COMPANY'"
mat-icon-button
color="accent"
(click)="addBlackList(row)"
>
<mat-icon>block</mat-icon> <mat-icon>block</mat-icon>
</button> </button>
</td> </td>
...@@ -98,28 +87,16 @@ ...@@ -98,28 +87,16 @@
</div> </div>
<!-- Add paginator reference #paginator="matPaginator" --> <!-- Add paginator reference #paginator="matPaginator" -->
<mat-paginator <mat-paginator #paginator [length]="totalItems" [pageSize]="pageSize" (page)="loadData($event)">
#paginator
[length]="totalItems"
[pageSize]="pageSize"
(page)="loadData($event)"
>
</mat-paginator> </mat-paginator>
<!-- Buttons for navigating to the first and last page --> <!-- Buttons for navigating to the first and last page -->
<button <button mat-button (click)="paginator.firstPage()" [disabled]="paginator.pageIndex === 0">
mat-button
(click)="paginator.firstPage()"
[disabled]="paginator.pageIndex === 0"
>
Primeira Página Primeira Página
</button> </button>
<button <button mat-button (click)="paginator.lastPage()"
mat-button [disabled]="paginator.pageIndex === paginator.getNumberOfPages() - 1">
(click)="paginator.lastPage()"
[disabled]="paginator.pageIndex === paginator.getNumberOfPages() - 1"
>
Última Página Última Página
</button> </button>
</div> </div>
...@@ -134,6 +134,9 @@ export class NaviosComponent implements OnInit { ...@@ -134,6 +134,9 @@ export class NaviosComponent implements OnInit {
}); });
} }
loadData(event?: PageEvent): void { loadData(event?: PageEvent): void {
const pageIndex = event ? event.pageIndex + 1 : this.currentPage - 1; const pageIndex = event ? event.pageIndex + 1 : this.currentPage - 1;
...@@ -185,6 +188,25 @@ export class NaviosComponent implements OnInit { ...@@ -185,6 +188,25 @@ export class NaviosComponent implements OnInit {
}, },
}); });
} }
getCountryById(flag: any) {
if (flag == null || flag === '') return null;
// Converte flag para número
const id = parseInt(flag, 10);
// Se o backend envia id = 26 (Brasil), está tudo certo
// Se ele envia índice (0-based), adiciona +1
const byId = this.countries.find(c => c.id === id);
if (byId) return byId;
// fallback: tenta índice
const idx = id - 1;
if (idx >= 0 && idx < this.countries.length) {
return this.countries[idx];
}
return null;
}
applyFilter(event: Event) { applyFilter(event: Event) {
const filterValue = (event.target as HTMLInputElement).value; const filterValue = (event.target as HTMLInputElement).value;
...@@ -676,7 +698,7 @@ export class NaviosComponent implements OnInit { ...@@ -676,7 +698,7 @@ export class NaviosComponent implements OnInit {
console.error(err); console.error(err);
} }
}); });
} }
} }
...@@ -50,8 +50,8 @@ ...@@ -50,8 +50,8 @@
<div class="column" style="flex: 1 1 30%; margin-bottom: 10px;"> <div class="column" style="flex: 1 1 30%; margin-bottom: 10px;">
<p><strong>Flag:</strong> <p><strong>Flag:</strong>
<ng-container *ngIf="data.flag; else flagNotAvailable"> <ng-container *ngIf="data.flag; else flagNotAvailable">
<img [src]="countries[data.flag].flagUrl" width="20" height="15" alt="{{ countries[data.flag].name }} flag" style="margin-right: 8px" /> <img [src]="countries[data.flag- 1].flagUrl" width="20" height="15" alt="{{ countries[data.flag].name }} flag" style="margin-right: 8px" />
<p>{{ countries[data.flag]?.name }}</p> <p>{{ countries[data.flag - 1 ]?.name }}</p>
</ng-container> </ng-container>
<ng-template #flagNotAvailable>Não informado</ng-template> <ng-template #flagNotAvailable>Não informado</ng-template>
</p> </p>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment