AP-64 (#86)
Some checks failed
Backend Deploy / build (push) Successful in 23s
Backend Build and Test / build (push) Failing after 2m2s

closes #64

Reviewed-on: #86
This commit is contained in:
Huffle 2025-05-26 09:10:25 +02:00
parent daebcdeccd
commit 550933db11
15 changed files with 250 additions and 22 deletions

Binary file not shown.

View File

@ -11,7 +11,6 @@ const routes: Routes = [
path: '',
loadChildren: () => import('./pages/tabs/tabs.module').then(m => m.TabsPageModule)
},
];
@NgModule({
imports: [

View File

@ -6,6 +6,14 @@ const routes: Routes = [
{
path: ':id',
component: AllowancePage,
},
{
path: ':id/add',
loadChildren: () => import('../edit-allowance/edit-allowance.module').then(m => m.EditAllowancePageModule)
},
{
path: ':id/edit/:goalId',
loadChildren: () => import('../edit-allowance/edit-allowance.module').then(m => m.EditAllowancePageModule)
}
];

View File

@ -1,8 +1,11 @@
<ion-header [translucent]="true" class="ion-no-border">
<ion-toolbar>
<ion-title>
Allowance
</ion-title>
<div class="toolbar">
<ion-title>
Allowance
</ion-title>
<button class="top-add-button" (click)="createAllowance()">Add Goal</button>
</div>
</ion-toolbar>
</ion-header>

View File

@ -58,11 +58,10 @@ button {
padding-inline: 30px;
border-radius: 10px;
color: white;
font-size: 16px;
}
button:disabled,
button[disabled]{
button[disabled] {
opacity: 0.5;
}
@ -127,4 +126,14 @@ button[disabled]{
background-color: var(--legend-color);
border-radius: 20px;
margin-right: 2px;
}
.toolbar {
display: flex;
}
.top-add-button {
background-color: var(--ion-color-primary);
margin-right: 15px;
padding-inline: 15px;
}

View File

@ -1,5 +1,5 @@
import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { BehaviorSubject } from 'rxjs';
import { Allowance } from 'src/app/models/allowance';
import { AllowanceService } from 'src/app/services/allowance.service';
@ -14,23 +14,11 @@ import { ViewWillEnter } from '@ionic/angular';
})
export class AllowancePage implements ViewWillEnter {
private id: number;
// Move to add/edit page later
private possibleColors: Array<string> = [
'#6199D9',
'#D98B61',
'#DBC307',
'#13DEB5',
'#7DCB7D',
'#CF1DBD',
'#F53311',
'#2F00FF',
'#098B0D',
'#1BC2E8'
];
public allowance$: BehaviorSubject<Array<Allowance>> = new BehaviorSubject<Array<Allowance>>([]);
constructor(
private route: ActivatedRoute,
private router: Router,
private allowanceService: AllowanceService
) {
this.id = this.route.snapshot.params['id'];
@ -46,7 +34,6 @@ export class AllowancePage implements ViewWillEnter {
this.allowanceService.getAllowanceList(this.id).subscribe(allowance => {
allowance[0].colour = '#9C4BE4';
allowance[0].name = 'Main Allowance';
console.log('Allowance list: ', allowance);
this.allowance$.next(allowance);
})
}, 10);
@ -72,4 +59,12 @@ export class AllowancePage implements ViewWillEnter {
}
return goal.progress / allowanceTotal * 100;
}
createAllowance() {
this.router.navigate(['add'], { relativeTo: this.route });
}
updateAllowance(id: number) {
this.router.navigate(['edit', id], { relativeTo: this.route });
}
}

View File

@ -0,0 +1,17 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { EditAllowancePage } from './edit-allowance.page';
const routes: Routes = [
{
path: '',
component: EditAllowancePage
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class EditAllowancePageRoutingModule {}

View File

@ -0,0 +1,21 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { IonicModule } from '@ionic/angular';
import { EditAllowancePageRoutingModule } from './edit-allowance-routing.module';
import { EditAllowancePage } from './edit-allowance.page';
@NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule,
EditAllowancePageRoutingModule,
ReactiveFormsModule
],
declarations: [EditAllowancePage]
})
export class EditAllowancePageModule {}

View File

@ -0,0 +1,31 @@
<ion-header [translucent]="true">
<ion-toolbar>
<div class="toolbar">
<ion-title *ngIf="isAddMode">Create Goal</ion-title>
<ion-title *ngIf="!isAddMode">Edit Goal</ion-title>
</div>
</ion-toolbar>
</ion-header>
<ion-content [fullscreen]="true">
<form [formGroup]="form">
<label>Goal Name</label>
<input id="name" type="text" formControlName="name"/>
<label>Target</label>
<input id="target" type="number" placeholder="0.00" name="price" min="0" value="0" step="0.01" formControlName="target"/>
<label>Weight</label>
<input id="weight" type="number" placeholder="0.00" name="price" min="0" value="0" step="0.01" formControlName="weight"/>
<label>Colour</label>
<select formControlName="color">
<option *ngFor="let color of possibleColors" [value]="color" [style.--background]="color">{{color}}</option>
</select>
<button type="button" [disabled]="!form.valid" (click)="submit()">
<span *ngIf="isAddMode">Add Goal</span>
<span *ngIf="!isAddMode">Update Goal</span>
</button>
</form>
</ion-content>

View File

@ -0,0 +1,45 @@
.toolbar {
display: flex;
}
form {
display: flex;
flex-direction: column;
align-items: center;
height: 100%;
}
label {
color: var(--ion-color-primary);
margin-top: 25px;
margin-bottom: 10px;
}
input,
select {
border: 1px solid var(--ion-color-primary);
border-radius: 5px;
width: 250px;
}
option {
--background: white;
background-color: var(--background);
color: var(--background);
font-family: var(--ion-font-family);
}
button {
background-color: var(--ion-color-primary);
border-radius: 5px;
color: white;
padding: 10px;
width: 250px;
margin-top: auto;
margin-bottom: 50px;
}
button:disabled,
button[disabled]{
opacity: 0.5;
}

View File

@ -0,0 +1,17 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { EditAllowancePage } from './edit-allowance.page';
describe('EditAllowancePage', () => {
let component: EditAllowancePage;
let fixture: ComponentFixture<EditAllowancePage>;
beforeEach(() => {
fixture = TestBed.createComponent(EditAllowancePage);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,75 @@
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { AllowanceService } from 'src/app/services/allowance.service';
@Component({
selector: 'app-edit-allowance',
templateUrl: './edit-allowance.page.html',
styleUrls: ['./edit-allowance.page.scss'],
standalone: false
})
export class EditAllowancePage implements OnInit {
public form: FormGroup;
public goalId: number;
public userId: number;
public isAddMode: boolean;
public possibleColors: Array<string> = [
'#6199D9',
'#D98B61',
'#DBC307',
'#13DEB5',
'#7DCB7D',
'#CF1DBD',
'#F53311',
'#2F00FF',
'#098B0D',
'#1BC2E8'
];
constructor(
private route: ActivatedRoute,
private formBuilder: FormBuilder,
private allowanceService: AllowanceService,
private router: Router
) {
this.userId = this.route.snapshot.params['id'];
this.goalId = this.route.snapshot.params['goalId'];
this.isAddMode = !this.goalId;
this.allowanceService.getAllowanceList(this.userId).subscribe((list) => {
for (let allowance of list) {
this.possibleColors = this.possibleColors.filter(color => color !== allowance.colour);
if (!this.isAddMode && this.goalId === allowance.id) {
this.possibleColors.unshift(allowance.colour);
}
}
});
this.form = this.formBuilder.group({
name: ['', Validators.required],
target: ['', Validators.required],
weight: ['', Validators.required],
color: ['', Validators.required]
});
}
ngOnInit() {
}
submit() {
const formValue = this.form.value;
const allowance = {
name: formValue.name,
target: formValue.target,
weight: formValue.weight,
colour: formValue.color,
};
if (this.isAddMode) {
this.allowanceService.createAllowance(allowance, this.userId);
}
this.router.navigate(['/tabs/allowance', this.userId]);
}
}

View File

@ -18,7 +18,7 @@
<input id="name" type="text" formControlName="name"/>
<label>Reward</label>
<input id="name" type="number" placeholder="0.00" name="price" min="0" value="0" step="0.01" formControlName="reward"/>
<input id="reward" type="number" placeholder="0.00" name="price" min="0" value="0" step="0.01" formControlName="reward"/>
<label>Assigned</label>
<select formControlName="assigned">

View File

@ -14,4 +14,8 @@ export class AllowanceService {
getAllowanceList(userId: number): Observable<Array<Allowance>> {
return this.http.get<Allowance[]>(`${this.url}/user/${userId}/allowance`);
}
createAllowance(allowance: Partial<Allowance>, userId: number) {
this.http.post(`${this.url}/user/${userId}/allowance`, allowance).subscribe();
}
}

View File

@ -42,4 +42,8 @@ ion-title {
ion-header {
border-bottom: 1px solid var(--line-color);
}
button {
font-size: 16px;
}