From 4f75da5c6fdf49aa85d7a36fef21e98c408c6647 Mon Sep 17 00:00:00 2001 From: Krzysztof Rudnicki Date: Sat, 9 Mar 2024 18:07:28 +0100 Subject: [PATCH] feat: started cost view and mediators list --- arai-frontend/angular.json | 3 +- arai-frontend/pnpm-lock.yaml | 21 ----------- arai-frontend/src/app/app.component.html | 2 +- arai-frontend/src/app/app.component.ts | 4 +-- arai-frontend/src/app/app.routes.ts | 21 ++++++++++- arai-frontend/src/app/backend.service.ts | 32 ++++++++++------- .../app/case-input/case-input.component.html | 14 ++++---- .../app/case-input/case-input.component.ts | 27 +++++--------- .../app/cost-view/cost-view.component.html | 6 +++- .../src/app/cost-view/cost-view.component.ts | 35 +++++++++++++++++-- .../mediators-list.component.html | 33 ++++++++++++++++- 11 files changed, 130 insertions(+), 68 deletions(-) diff --git a/arai-frontend/angular.json b/arai-frontend/angular.json index 4874f33..e26c62f 100644 --- a/arai-frontend/angular.json +++ b/arai-frontend/angular.json @@ -30,8 +30,7 @@ "src/assets" ], "styles": [ - "@angular/material/prebuilt-themes/indigo-pink.css", - "src/styles.scss" + "@angular/material/prebuilt-themes/indigo-pink.css" ], "scripts": [], "server": "src/main.server.ts", diff --git a/arai-frontend/pnpm-lock.yaml b/arai-frontend/pnpm-lock.yaml index 312cd19..671e8d9 100644 --- a/arai-frontend/pnpm-lock.yaml +++ b/arai-frontend/pnpm-lock.yaml @@ -26,9 +26,6 @@ dependencies: '@angular/forms': specifier: ^17.0.0 version: 17.2.4(@angular/common@17.2.4)(@angular/core@17.2.4)(@angular/platform-browser@17.2.4)(rxjs@7.8.1) - '@angular/http': - specifier: ^7.2.16 - version: 7.2.16(@angular/core@17.2.4)(@angular/platform-browser@17.2.4)(rxjs@7.8.1) '@angular/material': specifier: ^17.2.2 version: 17.2.2(@angular/animations@17.2.4)(@angular/cdk@17.2.2)(@angular/common@17.2.4)(@angular/core@17.2.4)(@angular/forms@17.2.4)(@angular/platform-browser@17.2.4)(rxjs@7.8.1) @@ -459,20 +456,6 @@ packages: tslib: 2.6.2 dev: false - /@angular/http@7.2.16(@angular/core@17.2.4)(@angular/platform-browser@17.2.4)(rxjs@7.8.1): - resolution: {integrity: sha512-yvjbNyzFSmmz4UTjCdy5M8mk0cZqf9TvSf8yN5UVIwtw4joyuUdlgJCuin0qSbQOKIf/JjHoofpO2JkPCGSNww==} - deprecated: Package no longer supported. Use @angular/common instead, see https://angular.io/guide/deprecations#angularhttp - peerDependencies: - '@angular/core': 7.2.16 - '@angular/platform-browser': 7.2.16 - rxjs: ^6.0.0 - dependencies: - '@angular/core': 17.2.4(rxjs@7.8.1)(zone.js@0.14.4) - '@angular/platform-browser': 17.2.4(@angular/animations@17.2.4)(@angular/common@17.2.4)(@angular/core@17.2.4) - rxjs: 7.8.1 - tslib: 1.14.1 - dev: false - /@angular/material@17.2.2(@angular/animations@17.2.4)(@angular/cdk@17.2.2)(@angular/common@17.2.4)(@angular/core@17.2.4)(@angular/forms@17.2.4)(@angular/platform-browser@17.2.4)(rxjs@7.8.1): resolution: {integrity: sha512-ToUp8gARTvdze9L7jhEuKqdos221jUCMRD6qzhl07XZRlxVbf/5VXUq2Nn7ei9uN11Ii1UY5pC0GS2XtlyHp4A==} peerDependencies: @@ -7720,10 +7703,6 @@ packages: hasBin: true dev: true - /tslib@1.14.1: - resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==} - dev: false - /tslib@2.6.2: resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} diff --git a/arai-frontend/src/app/app.component.html b/arai-frontend/src/app/app.component.html index bade52e..90c6b64 100644 --- a/arai-frontend/src/app/app.component.html +++ b/arai-frontend/src/app/app.component.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/arai-frontend/src/app/app.component.ts b/arai-frontend/src/app/app.component.ts index 346fdbf..b0e68b3 100644 --- a/arai-frontend/src/app/app.component.ts +++ b/arai-frontend/src/app/app.component.ts @@ -1,5 +1,5 @@ import { Component } from '@angular/core'; -import { RouterOutlet } from '@angular/router'; +import { RouterModule, RouterOutlet } from '@angular/router'; import { CaseInputComponent } from './case-input/case-input.component'; import { FlexLayoutModule } from '@angular/flex-layout'; import { HttpClientModule } from '@angular/common/http'; @@ -8,7 +8,7 @@ import { BackendService } from './backend.service'; @Component({ selector: 'app-root', standalone: true, - imports: [RouterOutlet, CaseInputComponent, FlexLayoutModule, HttpClientModule], + imports: [RouterOutlet, CaseInputComponent, FlexLayoutModule, HttpClientModule, RouterModule], providers: [BackendService], templateUrl: './app.component.html', styleUrl: './app.component.scss' diff --git a/arai-frontend/src/app/app.routes.ts b/arai-frontend/src/app/app.routes.ts index dc39edb..4e83f41 100644 --- a/arai-frontend/src/app/app.routes.ts +++ b/arai-frontend/src/app/app.routes.ts @@ -1,3 +1,22 @@ import { Routes } from '@angular/router'; +import { CaseInputComponent } from './case-input/case-input.component'; +import { CostViewComponent } from './cost-view/cost-view.component'; +import { MediatorsListComponent } from './mediators-list/mediators-list.component'; -export const routes: Routes = []; +export const routes: Routes = [ + { + path: '', // Explicit root path configuration + redirectTo: '/input', // Redirect to '/input' as a default route + pathMatch: 'full' // Ensures full match of the path + }, + { + path: '', // Base path for children + children: [ + {path: 'input', component: CaseInputComponent}, + {path: 'koszt', component: CostViewComponent}, + {path: 'mediatorzy', component: MediatorsListComponent}, + {path: '**', component: CaseInputComponent} // Wildcard route for unmatched paths + ] + } + ]; + diff --git a/arai-frontend/src/app/backend.service.ts b/arai-frontend/src/app/backend.service.ts index f6cdce8..e8a46b1 100644 --- a/arai-frontend/src/app/backend.service.ts +++ b/arai-frontend/src/app/backend.service.ts @@ -32,17 +32,25 @@ export class BackendService { } } - public sendMessage(message: GenericRequest): void { - if(message.request_type === "user_input") { - this.userInputArray.push(message as UserInputRequest); - } - const headers = new HttpHeaders().set( - "Content-Type", - "application/json" - ); - console.log(`request: `, JSON.stringify(message)); - this.http.post(this.address, JSON.stringify(message), {headers}).subscribe((response) => { - console.log(`response: `, response); - }) + public sendMessage(message: GenericRequest): Promise { + return new Promise((resolve, reject) => { + if (message.request_type === "user_input") { + this.userInputArray.push(message as UserInputRequest); + } + const headers = new HttpHeaders().set("Content-Type", "application/json"); + + console.log(`request: `, JSON.stringify(message)); + + this.http.post(this.address, JSON.stringify(message), { headers }).subscribe({ + next: (response) => { + console.log(`response: `, response); + resolve(response); + }, + error: (error) => { + console.error(`backendService, sendMessage, error: `, error); + reject(error); + } + }); + }); } } diff --git a/arai-frontend/src/app/case-input/case-input.component.html b/arai-frontend/src/app/case-input/case-input.component.html index 07b754f..fa8e8a1 100644 --- a/arai-frontend/src/app/case-input/case-input.component.html +++ b/arai-frontend/src/app/case-input/case-input.component.html @@ -1,24 +1,24 @@
- Generic Input - + Opis Sprawy + - Trial Value + Wartość Przedmiotu Sporu - Location + Lokacja
- Experts Called - Witnesses Called + Powołani Biegli + Powołani Świadkowie
- +
\ No newline at end of file diff --git a/arai-frontend/src/app/case-input/case-input.component.ts b/arai-frontend/src/app/case-input/case-input.component.ts index 2ef2c91..136fbbb 100644 --- a/arai-frontend/src/app/case-input/case-input.component.ts +++ b/arai-frontend/src/app/case-input/case-input.component.ts @@ -33,24 +33,15 @@ export class CaseInputComponent { }); } - ngOnInit() { - const data: userInput = { - "generic_input": "Rozwodzę się z żoną i chcę uczciwie podzielić majątek", - "trial_cost": 1000, - "location": "Katowice", - "experts_called": true, - "witnesses_called": true - } - const newRequest = new UserInputRequest(data); - this.backendService.sendMessage(newRequest); - } - - onSubmit(): void { + async onSubmit() { + this.userInput = this.userInputForm.value; if(this.userInput !== null) { - this.backendService.sendMessage(new UserInputRequest(this.userInput)); - } else { - console.error(`caseInputComponent, onSubmit, userInput is null!`) - } + const newRequest = new UserInputRequest(this.userInput); + this.backendService.sendMessage(newRequest); + const result = await this.backendService.sendMessage(new UserInputRequest(this.userInput)); + console.log(`result: `, result); + } else { + console.error(`caseInputComponent, onSubmit, userInput is null!`) } - +} } diff --git a/arai-frontend/src/app/cost-view/cost-view.component.html b/arai-frontend/src/app/cost-view/cost-view.component.html index cbdd498..aadef5b 100644 --- a/arai-frontend/src/app/cost-view/cost-view.component.html +++ b/arai-frontend/src/app/cost-view/cost-view.component.html @@ -1 +1,5 @@ -

cost-view works!

+Przewidywalne minimalne koszta: +@if(costData !== null) { + Koszta: {{costData.cost_of_trial}} zł
+ Przewidywalny czas: {{costData.time_of_trial | date:'L'}} miesiące +} \ No newline at end of file diff --git a/arai-frontend/src/app/cost-view/cost-view.component.ts b/arai-frontend/src/app/cost-view/cost-view.component.ts index 957a3ee..d1f240c 100644 --- a/arai-frontend/src/app/cost-view/cost-view.component.ts +++ b/arai-frontend/src/app/cost-view/cost-view.component.ts @@ -1,12 +1,43 @@ -import { Component } from '@angular/core'; +import { Component, Input } from '@angular/core'; +import { StatisticsOutputInterface } from '../requests-responses'; +import { DatePipe } from '@angular/common'; @Component({ selector: 'app-cost-view', standalone: true, - imports: [], + imports: [DatePipe], templateUrl: './cost-view.component.html', styleUrl: './cost-view.component.scss' }) export class CostViewComponent { +@Input() costData: StatisticsOutputInterface | null = { + cost_of_trial: 2137, + time_of_trial: Date.UTC(0, 6, 0, 0, 0, 0, 0) +}; + +public calculateTimeDifference(utcDateNumber: number): string { + const currentDate = new Date(); + const targetDate = new Date(utcDateNumber); + const differenceInMilliseconds = targetDate.getTime() - currentDate.getTime(); + + // Convert milliseconds to days + const differenceInDays = differenceInMilliseconds / (1000 * 60 * 60 * 24); + + // Check if the difference is greater than or equal to 30 to approximate months + if (differenceInDays >= 30) { + const months = Math.floor(differenceInDays / 30); + const years = Math.floor(differenceInDays/365); + if(years > 0) { + return `Twoja sprawa zajmie około ${years} lat` + } + if(months === 1) { + return `Twoja sprawa zajmie około 1 miesiąc`; + } else { + return `Twoja sprawa zajmie około ${months} miesięcy`; + } + } else { + return `Twoja sprawa zajmie około ${Math.ceil(differenceInDays)} dni`; + } +} } diff --git a/arai-frontend/src/app/mediators-list/mediators-list.component.html b/arai-frontend/src/app/mediators-list/mediators-list.component.html index dbd6505..a90591c 100644 --- a/arai-frontend/src/app/mediators-list/mediators-list.component.html +++ b/arai-frontend/src/app/mediators-list/mediators-list.component.html @@ -1 +1,32 @@ -

mediators-list works!

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
No. {{element.position}} Name {{element.name}} Weight {{element.weight}} Symbol {{element.symbol}}
\ No newline at end of file