Skip to content

Commit

Permalink
+ Dialogos na submição de análises.
Browse files Browse the repository at this point in the history
+ Mudança da rota de analysis para results.
  • Loading branch information
JamesCodesUFG committed Jan 31, 2025
1 parent 7187816 commit c489205
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p-dialog header="{{ messages[messageCode].title | translate }}" [modal]="true" [(visible)]="visible" [style]="{ width: '25rem' }" appendTo="body">
<span class="p-text-secondary block mb-5"> {{ messages[messageCode].message | translate }} </span>
</p-dialog>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Angular imports.
*/
import { Component } from '@angular/core';
import { LOCALE_ID } from '@angular/core';
import { FormsModule } from '@angular/forms';

/**
* Core imports.
*/
import { LocalizationService } from '@core/internationalization/localization.service';

/**
* PrimeNg imports.
*/
import { DialogModule } from 'primeng/dialog';
import { InputSwitchModule } from 'primeng/inputswitch';

/**
* Translate imports
*/
import { TranslateModule } from '@ngx-translate/core';


@Component({
standalone: true,
selector: 'app-dialog-message',
templateUrl: './dialog-message.component.html',
styleUrls: ['./dialog-message.component.scss'],
imports: [
DialogModule,
InputSwitchModule,
FormsModule,
TranslateModule,
],
providers: [{ provide: LOCALE_ID, useValue: 'pt-BR' }],
})
class DialogMessageComponent {
public visible: boolean = false;

public messageCode: number = 200;

public messages = {
200: {
title: 'dialogs.submition.success.title',
message: 'dialogs.submition.success.message'
},
500: {
title: 'dialogs.submition.error.title',
message: 'dialogs.submition.error.message'
}
};

constructor(public localizationService: LocalizationService) {}

public message(status: number): void {
this.messageCode = status;

this.visible = true;
}
}

export { DialogMessageComponent };
24 changes: 17 additions & 7 deletions client/src/app/@core/services/analysis.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { Observable, throwError } from 'rxjs';
import { Observable, of, throwError } from 'rxjs';
import { catchError, switchMap } from 'rxjs/operators';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { map } from 'rxjs/operators';
Expand Down Expand Up @@ -29,7 +29,7 @@ export class AnalysisService {
public getAnalysisByToken(token: any): Observable<any> {
return this.httpClient
.get<any>(`${environment.TASK_API}/result/${token}`)
.pipe(map((response) => response))
.pipe(map((response) => response));
}

// TODO: Verificação do recaptcha.
Expand Down Expand Up @@ -74,10 +74,20 @@ export class AnalysisService {
formData.append('name', encodeURIComponent(user.name));
formData.append('email', encodeURIComponent(user.email));

return this.httpClient.post<any>(`${this.apiURL}/savefile`, formData).pipe(
map((response: any) => {
console.log(response);
})
);
return this.httpClient
.post<any>(`${this.apiURL}/savefile`, formData)
.pipe(
map((response: any) => {
return {
status: 200,
token: response.token,
};
})
)
.pipe(
catchError((response) => {
return of({ status: response.error.message.status });
})
);
}
}
2 changes: 1 addition & 1 deletion client/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const routes: Routes = [
.then(module => module.ComponentsModule),
},
{
path: 'analysis',
path: 'results',
loadChildren: () => import('./analysis/analysis.module')
.then(module => module.AnalysisModule),
}
Expand Down
2 changes: 2 additions & 0 deletions client/src/app/map-platform/components.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { ComponentsRoutingModule } from './components-routing.module';
import { LayersSidebarComponent } from './components/layers-sidebar/layers-sidebar.component';
import { DrawAreaComponent } from './components/general-map/draw_area/draw_area.component';
import { SwipeComponent } from './components/general-map/swipe/swipe.component';
import { DialogMessageComponent } from '@core/components/dialog-message/dialog-message.component';

import { OlMapsModule } from '../@core/ol-maps/ol-maps.module';
import { GeneralMapComponent } from './components/general-map/general-map.component';
Expand Down Expand Up @@ -96,6 +97,7 @@ registerLocaleData(localePt);
DrawAreaComponent
],
imports: [
DialogMessageComponent,
UserInfoComponent,
SliderModule,
LoadingSpinnerComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class AreaSidebarComponent {
}

public onAnalyseClicked() {
this.router.navigate([`/analysis/${this.userInput}`])
this.router.navigate([`/results/${this.userInput}`])
}

private validationMobile() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
/>
</div>

<app-dialog-message/>

<app-user-info-dialog/>
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Component, Input, Output } from '@angular/core';
import { EventEmitter, ViewChild } from '@angular/core';
import { Component } from '@angular/core';
import { ViewChild } from '@angular/core';
import { trigger, state, style } from '@angular/animations';
import { animate, transition } from '@angular/animations';
import { HttpClient } from '@angular/common/http';
import { Subscription, of } from 'rxjs';
import { LocalizationService } from '@core/internationalization/localization.service';
import { AnalysisService } from '../../../@core/services';
import { ReCaptchaV3Service } from 'ng-recaptcha';
import { UserInfoComponent } from '@core/components/user-info-dialog/user-info-dialog.component';
import { UserInfo } from '@core/interfaces/user_info';
import { DialogMessageComponent } from '@core/components/dialog-message/dialog-message.component';

@Component({
selector: 'app-file-upload',
Expand All @@ -23,33 +22,21 @@ import { UserInfo } from '@core/interfaces/user_info';
})
export class FileUploadComponent {
@ViewChild(UserInfoComponent) userInfo!: UserInfoComponent;
@ViewChild(DialogMessageComponent) dialog!: DialogMessageComponent;

@ViewChild('fileUpload') fileUpload!: HTMLInputElement;

public maxSize: number = 15;

private userData: any = {};

public MAX_FILE_SIZE = 5 * 1024 * 1024;

public files: Array<FileUploadModel> = [];

private lang: string;

constructor(
private analysisService: AnalysisService,
private recaptchaV3Service: ReCaptchaV3Service,
private localizationService: LocalizationService
) {
this.lang = localizationService.currentLang();

// TODO: Se não tirar subscrição pode afetar performance.
localizationService.translateService.onLangChange.subscribe({
next: (lang: string) => {
this.lang = lang;
},
});

this.maxSize = this.maxSize * 1024 * 1024;
}

Expand Down Expand Up @@ -90,7 +77,7 @@ export class FileUploadComponent {
.subscribe((recaptcha: string) => {
this.analysisService
.saveFile(file, user, recaptcha).subscribe((response) => {
console.log(response)
this.dialog.message(response.status)
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
</div>
</div>

<p-dialog header="{{ 'dialogs.submition.success' | translate}}" [modal]="true" [(visible)]="dialogVisible" [style]="{ width: '25rem' }" [draggable]="false" [resizable]="false">
{{ 'dialogs.submition.content' | translate }}
</p-dialog>
<app-dialog-message/>

<app-user-info-dialog/>
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { Interaction, Modify, Snap } from 'ol/interaction';
import { UserInfoComponent } from '@core/components/user-info-dialog/user-info-dialog.component';
import { ReCaptchaV3Service } from 'ng-recaptcha';
import { Feature, Overlay } from 'ol';
import { DialogMessageComponent } from '@core/components/dialog-message/dialog-message.component';

const PRIMARY_COLOR = window
.getComputedStyle(document.body)
Expand All @@ -47,8 +48,7 @@ const PRIMARY_COLOR = window
})
export class DrawAreaComponent implements OnInit, OnDestroy {
@ViewChild(UserInfoComponent) userInfo!: UserInfoComponent;

public dialogVisible: boolean = false;
@ViewChild(DialogMessageComponent) dialog!: DialogMessageComponent;

private interaction!: Interaction;
private vector: VectorLayer<any> = new VectorLayer();
Expand Down Expand Up @@ -241,9 +241,8 @@ export class DrawAreaComponent implements OnInit, OnDestroy {
this.analysisService
.saveGeojson(userInfo, geoJson, recaptcha)
.subscribe({
next: (data) => {
// TODO: Avisar pro usuário que o token dele chegara pelo e-mail.
this.dialogVisible = true;
next: (response) => {
this.dialog.message(response.status)
},
});
});
Expand Down
10 changes: 8 additions & 2 deletions client/src/assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@
"cancel": "cancel"
},
"submition": {
"success": "Submition success",
"content": "O token e o link de acesso serão enviados para o seu e-mail assim que o processamento for concluído."
"success": {
"title": "Analysis Submitted Successfully",
"message": "Your analysis has been successfully submitted and is being processed. You will receive an email with an access token once the process is complete."
},
"error": {
"title": "Unable to Process Analysis",
"message": "The submitted analysis could not be processed. Please check the data and try again."
}
}
},
"controls": {
Expand Down
10 changes: 8 additions & 2 deletions client/src/assets/locales/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@
"cancel": "cancelar"
},
"submition": {
"success": "Sucesso no envio",
"content": "O token e o link de acesso serão enviados para o seu e-mail assim que o processamento for concluído."
"success": {
"title": "Análise enviada com sucesso",
"message": "Sua análise foi submetida com sucesso e está sendo processada. Você receberá um e-mail com um token de acesso assim que o processo for concluído."
},
"error": {
"title": "Erro ao Processar a Análise",
"message": "Não foi possível processar a análise submetida. Por favor, verifique os dados e tente novamente."
}
}
},
"controls": {
Expand Down

0 comments on commit c489205

Please sign in to comment.