Skip to content

Commit 18b3331

Browse files
committed
#272 - clean up and MVP
1 parent 97bf26f commit 18b3331

12 files changed

Lines changed: 100 additions & 97 deletions

File tree

angular-client/src/app/app-nav-bar/app-nav-bar.component.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,8 @@
5353
font-size: 20px;
5454
margin-right: 0.5rem;
5555
}
56+
57+
:host {
58+
--p-dialog-background: #2c2c2c;
59+
--p-dialog-border-color: #2c2c2c;
60+
}

angular-client/src/app/app-nav-bar/app-nav-bar.component.html

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,19 @@
3030
</div>
3131

3232
<div style="display: flex; align-items: center">
33-
<toast-button
34-
[onClick]="this.onStartNewRun"
35-
buttonLabel="Start New Run"
36-
popUpSeverity="success"
37-
popUpTitle="New Run Started"
38-
popUpDetails="Your new run has started successfully."
39-
additionalStyles="height: 35px"
40-
/>
41-
<toast-button [onClick]="this.openRunForm" buttonLabel="Edit Currrent Run" />
33+
<hstack>
34+
<toast-button
35+
[onClick]="this.onStartNewRun"
36+
buttonLabel="Start New Run"
37+
popUpSeverity="success"
38+
popUpTitle="New Run Started"
39+
popUpDetails="Your new run has started successfully."
40+
additionalStyles="height: 35px"
41+
/>
42+
<toast-button [onClick]="this.openRunForm" buttonLabel="Edit Currrent Run" additionalStyles="height: 35px" />
43+
<current-run-display [navBarStyle]="true"></current-run-display>
44+
</hstack>
45+
4246
<typography variant="large-header" content="{{ time$ | async | date: 'HH:mm:ss' }}" style="margin-left: 20px" />
4347
</div>
4448
</nav>
Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Component, OnInit, inject } from '@angular/core';
2+
import { getLatestRun } from 'src/api/run.api';
3+
import APIService from 'src/services/api.service';
24
import Storage from 'src/services/storage.service';
3-
import { DataTypeEnum } from 'src/data-type.enum';
5+
import { Run } from 'src/utils/types.utils';
46

57
@Component({
68
selector: 'driver-component',
@@ -10,11 +12,29 @@ import { DataTypeEnum } from 'src/data-type.enum';
1012
export class DriverComponent implements OnInit {
1113
private storage = inject(Storage);
1214
driver: string = 'No Driver';
15+
apiService = inject(APIService);
1316

1417
ngOnInit() {
15-
this.storage.get(DataTypeEnum.DRIVER).subscribe((value) => {
16-
[this.driver] = value.values || ['No Driver'];
17-
});
18+
setTimeout(() => {
19+
const latestRunQuery = this.apiService.query<Run>(() => getLatestRun());
20+
latestRunQuery.isLoading.subscribe((loading: boolean) => {
21+
if (loading) {
22+
// TODO
23+
}
24+
});
25+
latestRunQuery.error.subscribe((error) => {
26+
if (error) {
27+
// TODO
28+
}
29+
});
30+
latestRunQuery.data.subscribe((data) => {
31+
const latestRun = data;
32+
if (latestRun) {
33+
this.driver =
34+
latestRun.driverName !== undefined || latestRun.driverName === '' ? latestRun.driverName : 'No Driver';
35+
}
36+
});
37+
}, 10000);
1838
console.log(this.driver);
1939
}
2040
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
21
.required:after {
3-
content: "*";
2+
content: '*';
43
color: red;
54
margin-left: 6px;
65
}
@@ -11,4 +10,3 @@
1110
font-size: 12px;
1211
font-weight: 500;
1312
}
14-

angular-client/src/components/form-template/form-template.component.html

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
<!-- dynamic-form.component.html -->
2-
<form class="flex flex-column gap-4 dynamic-form" [formGroup]="form">
2+
<form class="form" [formGroup]="form">
33
@for (field of fields(); track field) {
44
<div class="flex flex-column gap-1">
55
@if (field.label) {
66
<label class="text-sm font-semibold mb-1 required">{{ field.label }}</label>
77
}
8-
9-
<!-- Text Input -->
10-
@if (true) {
11-
<input
12-
[attr.placeholder]="field.placeholder"
13-
[formControlName]="field.name"
14-
[type]="field.type"
15-
[value]="'boston'"
16-
pInputText
17-
class="form-control w-full"
18-
[ngClass]="{
19-
'ng-invalid ng-dirty':
20-
form.get(field.name)?.invalid && (form.get(field.name)?.dirty || form.get(field.name)?.touched)
21-
}"
22-
/>
23-
}
8+
<input
9+
[attr.placeholder]="field.placeholder"
10+
[formControlName]="field.name"
11+
[type]="field.type"
12+
[value]="'boston'"
13+
pInputText
14+
class="form-control w-full"
15+
[ngClass]="{
16+
'ng-invalid ng-dirty':
17+
form.get(field.name)?.invalid && (form.get(field.name)?.dirty || form.get(field.name)?.touched)
18+
}"
19+
/>
2420

2521
<!-- Error Message -->
2622
<div

angular-client/src/components/form-template/form-template.component.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
import { Component, EventEmitter, inject, input, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
2+
import { Component, EventEmitter, inject, input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
33
import { FormBuilder, FormGroup, ValidatorFn, Validators } from '@angular/forms';
44
import { DynamicDialogConfig, DynamicDialogRef } from 'primeng/dynamicdialog';
55

@@ -33,7 +33,7 @@ export class FormTemplateComponent implements OnInit, OnChanges {
3333

3434
public ref = inject(DynamicDialogRef);
3535

36-
@Input() formData: Map<string, anyType> = new Map();
36+
formData = input<Map<string, anyType>>(new Map());
3737
@Output() submitForm: EventEmitter<FormGroup> = new EventEmitter();
3838

3939
form: FormGroup = this.fb.group({});
@@ -57,7 +57,7 @@ export class FormTemplateComponent implements OnInit, OnChanges {
5757

5858
this.fields().forEach((field) => {
5959
const control = this.fb.control({
60-
value: this.formData ? this.formData.get(field.name) : '',
60+
value: this.formData() ? this.formData().get(field.name) : '',
6161
disabled: field.disabled
6262
});
6363

@@ -69,6 +69,10 @@ export class FormTemplateComponent implements OnInit, OnChanges {
6969
if (field.minLength) validations.push(Validators.minLength(field.minLength));
7070

7171
control.setValidators(validations);
72+
if (field.optionValue !== undefined) {
73+
control.setValue(field.optionValue);
74+
}
75+
7276
group[field.name] = control;
7377
});
7478

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
<form-template [fields]="this.inputFields" />
1+
@if (!this.templateReady) {
2+
<loading-page />
3+
} @else {
4+
<info-background>
5+
<form-template [fields]="this.inputFields" />
6+
</info-background>
7+
}

angular-client/src/components/run-form/run-form.component.ts

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DynamicFormField } from '../form-template/form-template.component';
33
import { inject } from '@angular/core';
44
import { Run } from 'src/utils/types.utils';
55
import { getLatestRun } from 'src/api/run.api';
6-
import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
6+
import { DynamicDialogRef } from 'primeng/dynamicdialog';
77
import APIService from 'src/services/api.service';
88
import { MessageService } from 'primeng/api';
99
import { FormGroup } from '@angular/forms';
@@ -15,27 +15,16 @@ import { updateRun } from 'src/api/run.api';
1515
styleUrl: './run-form.component.css'
1616
})
1717
export class RunFormComponent {
18-
private dialogService = inject(DialogService);
19-
public serverService = inject(APIService);
18+
public apiService = inject(APIService);
2019
private messageService = inject(MessageService);
2120
private ref = inject(DynamicDialogRef);
22-
23-
runId: DynamicFormField = {
24-
name: 'runId',
25-
label: 'Run ID',
26-
type: 'number',
27-
placeholder: 'Run ID',
28-
optionValue: 'Boston',
29-
required: true,
30-
disabled: false
31-
};
32-
21+
templateReady = true;
22+
selectRunId: number | undefined = undefined;
3323
locationName: DynamicFormField = {
3424
name: 'locationName',
3525
label: 'Location Name',
3626
type: 'text',
3727
placeholder: 'Enter Location Name',
38-
optionValue: 'Boston',
3928
required: true,
4029
minLength: 3,
4130
maxLength: 50,
@@ -70,66 +59,45 @@ export class RunFormComponent {
7059
disabled: false
7160
};
7261

73-
inputFields: DynamicFormField[] = [
74-
this.runId,
75-
this.locationName,
76-
this.driverName,
77-
this.notes
78-
79-
// example field
80-
// {
81-
// name: 'full name',
82-
// label: 'Full Name',
83-
// type: 'text',
84-
// placeholder: 'Enter Full Name',
85-
// required: true,
86-
// minLength: 3,
87-
// maxLength: 40,
88-
// disabled: false
89-
// },
90-
];
62+
inputFields: DynamicFormField[] = [this.locationName, this.driverName, this.notes];
9163

9264
constructor() {
9365
this.renderTemplate();
9466

9567
this.ref.onClose.subscribe((form: FormGroup) => {
96-
console.log('form template closed');
97-
68+
if (this.selectRunId === undefined) {
69+
this.messageService.add({ severity: 'error', summary: 'Error', detail: 'No run selected' });
70+
return;
71+
}
9872
updateRun(
99-
form.controls['runId'].value,
73+
this.selectRunId,
10074
form.controls['driverName'].value,
10175
form.controls['locationName'].value,
102-
form.controls['notes'].value,
76+
form.controls['notes'].value
10377
);
104-
105-
console.log("driver:", form.controls['driverName'].value)
10678
});
10779
}
10880

10981
renderTemplate = () => {
11082
// query for the most recent run to get the location name
111-
const runsQueryResponse = this.serverService.query<Run>(() => getLatestRun());
112-
83+
const runsQueryResponse = this.apiService.query<Run>(() => getLatestRun());
11384
this.locationName.optionValue = 'data';
114-
11585
runsQueryResponse.isLoading.subscribe((isLoading: boolean) => {
116-
console.log('Is loading: ', isLoading);
86+
this.templateReady = !isLoading;
11787
});
11888
runsQueryResponse.error.subscribe((error) => {
11989
error && this.messageService.add({ severity: 'error', summary: 'Error', detail: error.message });
12090
if (error) {
12191
console.log('loading error: ', error);
12292
}
12393
});
124-
12594
runsQueryResponse.data.subscribe((data) => {
12695
const run = data;
12796
this.locationName.optionValue = run?.locationName;
12897
this.driverName.optionValue = run?.driverName;
12998
this.notes.optionValue = run?.notes;
130-
131-
console.log('run id: ', data?.id);
132-
console.log('location: ', data?.locationName);
99+
// we set the selected run id to default as the current run
100+
this.selectRunId = run?.id;
133101
});
134102
};
135103
}
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
<info-background>
2-
<div class="current-run-display">
1+
@if (this.navBarStyle()) {
2+
<hstack spacing="5px">
33
<typography variant="header" content="Current Run" additionalStyles="margin: 0px" />
4-
<typography variant="info-subtitle" content="#{{ currentRun }}" additionalStyles="margin: 0px" />
5-
</div>
6-
</info-background>
4+
<typography variant="header" content="#{{ currentRun }}" additionalStyles="margin: 0px" />
5+
</hstack>
6+
} @else {
7+
<info-background>
8+
<div class="current-run-display">
9+
<typography variant="header" content="Current Run" additionalStyles="margin: 0px" />
10+
<typography variant="info-subtitle" content="#{{ currentRun }}" additionalStyles="margin: 0px" />
11+
</div>
12+
</info-background>
13+
}

angular-client/src/pages/landing-page/components/current-run-display/current-run-display.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, inject } from '@angular/core';
1+
import { Component, OnInit, inject, input } from '@angular/core';
22
import Storage from 'src/services/storage.service';
33

44
@Component({
@@ -9,6 +9,7 @@ import Storage from 'src/services/storage.service';
99
export class CurrentRunDisplayComponent implements OnInit {
1010
private storage = inject(Storage);
1111
currentRun: number = 0;
12+
navBarStyle = input<boolean>(false);
1213

1314
ngOnInit() {
1415
this.storage.getCurrentRunId().subscribe((runId) => {

0 commit comments

Comments
 (0)