Added short name to benchmarks

This commit is contained in:
ivan-pelly
2026-03-14 18:54:28 -07:00
parent f431fb3e94
commit 242b1bce27
21 changed files with 227 additions and 22 deletions
@@ -15,14 +15,18 @@
@if (loaded()) {
<div class="detail-card">
<div class="field">
<span class="field-label">Goal</span>
<span class="field-value">{{ goalCategory }}</span>
<span class="field-label">Goal: {{ goalCategory }}</span>
</div>
<div class="field">
<label class="field-label" for="benchmarkText">Benchmark</label>
<textarea id="benchmarkText" class="field-input field-textarea" [(ngModel)]="benchmarkText" rows="4"
placeholder="Enter benchmark text..."></textarea>
</div>
<div class="field">
<label class="field-label" for="shortName">Short Name</label>
<input id="shortName" class="field-input" type="text" [(ngModel)]="shortName" maxlength="50"
placeholder="Optional" />
</div>
@if (!isNew()) {
<div class="metadata">
@if (createdByName) {
@@ -42,9 +42,11 @@ export class BenchmarkCardFull implements OnDestroy {
protected readonly successMessage = signal<string | null>(null);
protected readonly saving = signal(false);
// Form field
// Form fields
protected benchmarkText = '';
protected shortName = '';
private savedBenchmarkText = '';
private savedShortName = '';
// Read-only metadata
protected goalCategory = '';
@@ -58,7 +60,8 @@ export class BenchmarkCardFull implements OnDestroy {
// Returns true if the benchmark text has unsaved changes.
// *****************************************************************
hasChanges(): boolean {
return this.benchmarkText !== this.savedBenchmarkText;
return this.benchmarkText !== this.savedBenchmarkText
|| this.shortName !== this.savedShortName;
}
// ************************ Public Methods *************************
@@ -77,11 +80,13 @@ export class BenchmarkCardFull implements OnDestroy {
const result = await this.studentService.createBenchmark(this.studentId, {
goalId: this.goalId,
benchmark: this.benchmarkText,
shortName: this.shortName || undefined,
});
this.saving.set(false);
if (result.success) {
this.successMessage.set('Benchmark created.');
this.savedBenchmarkText = this.benchmarkText;
this.savedShortName = this.shortName;
this.studentService.notifyDataChanged();
if (result.payload?.benchmarkId) {
this.router.navigate(['/students', this.studentId, 'goals', this.goalId, 'benchmarks', result.payload.benchmarkId]);
@@ -90,11 +95,19 @@ export class BenchmarkCardFull implements OnDestroy {
this.errorMessage.set(result.message);
}
} else {
const result = await this.studentService.updateBenchmark(this.studentId, this.benchmarkId!, this.benchmarkText);
const shortNameChanged = this.shortName !== this.savedShortName;
const result = await this.studentService.updateBenchmark(this.studentId, this.benchmarkId!, this.benchmarkText, this.shortName || undefined);
this.saving.set(false);
if (result.success) {
this.savedBenchmarkText = this.benchmarkText;
this.savedShortName = this.shortName;
this.successMessage.set('Changes saved.');
if (shortNameChanged) {
this.studentService.updateSidebarLabel(
['/students', this.studentId, 'goals', this.goalId, 'benchmarks', this.benchmarkId!],
this.shortName || this.benchmarkText
);
}
} else {
this.errorMessage.set(result.message);
}
@@ -106,12 +119,13 @@ export class BenchmarkCardFull implements OnDestroy {
// *****************************************************************
onCancel() {
this.benchmarkText = this.savedBenchmarkText;
this.shortName = this.savedShortName;
this.errorMessage.set(null);
this.successMessage.set(null);
}
onBack() {
this.router.navigate(['/students', this.studentId, 'benchmarks']);
this.router.navigate(['/students', this.studentId, 'goals', this.goalId, 'benchmarks']);
}
ngOnDestroy() {
@@ -127,7 +141,9 @@ export class BenchmarkCardFull implements OnDestroy {
if (!this.benchmarkId) {
this.isNew.set(true);
this.benchmarkText = '';
this.shortName = '';
this.savedBenchmarkText = '';
this.savedShortName = '';
this.loadGoalCategory();
this.loaded.set(true);
return;
@@ -147,7 +163,9 @@ export class BenchmarkCardFull implements OnDestroy {
}
this.benchmarkText = bm.benchmark;
this.shortName = bm.shortName ?? '';
this.savedBenchmarkText = bm.benchmark;
this.savedShortName = bm.shortName ?? '';
this.goalCategory = bm.goalCategory;
this.createdByName = bm.createdByName;
this.createdAt = bm.createdAt;
@@ -0,0 +1 @@
<p>progress-edit works!</p>
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ProgressEdit } from './progress-edit';
describe('ProgressEdit', () => {
let component: ProgressEdit;
let fixture: ComponentFixture<ProgressEdit>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ProgressEdit]
})
.compileComponents();
fixture = TestBed.createComponent(ProgressEdit);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,11 @@
import { Component } from '@angular/core';
@Component({
selector: 'app-progress-edit',
imports: [],
templateUrl: './progress-edit.html',
styleUrl: './progress-edit.scss',
})
export class ProgressEdit {
}