Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/screenshots/frontend-add-tool-qr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshots/frontend-edit-tool-qr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
288 changes: 278 additions & 10 deletions frontend/tool-inventory-app/package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions frontend/tool-inventory-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@angular/material": "^21.2.13",
"@angular/platform-browser": "^21.2.0",
"@angular/router": "^21.2.0",
"qrcode": "^1.5.4",
"@zxing/ngx-scanner": "^21.0.0",
"rxjs": "~7.8.0",
"tslib": "^2.3.0"
Expand All @@ -28,6 +29,7 @@
"@angular/build": "^21.2.13",
"@angular/cli": "^21.2.13",
"@angular/compiler-cli": "^21.2.0",
"@types/qrcode": "^1.5.5",
"jsdom": "^28.0.0",
"prettier": "^3.8.1",
"typescript": "~5.9.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,41 @@ <h2 mat-dialog-title>{{ isEdit ? 'Edit Tool' : 'Add Tool' }}</h2>
<textarea matInput formControlName="description" rows="2"></textarea>
</mat-form-field>

<div class="row">
<mat-form-field appearance="outline" class="half-width">
<mat-label>Make (Manufacturer)</mat-label>
<input matInput formControlName="make">
</mat-form-field>

<mat-form-field appearance="outline" class="half-width">
<mat-label>Model</mat-label>
<input matInput formControlName="model">
</mat-form-field>
</div>

<mat-form-field appearance="outline" class="full-width">
<mat-label>Serial number</mat-label>
<input matInput formControlName="serialNumber">
</mat-form-field>

<mat-form-field appearance="outline" class="full-width">
<mat-label>Owner</mat-label>
<input matInput formControlName="owner">
</mat-form-field>

<mat-form-field appearance="outline" class="full-width">
<mat-label>Barcode / QR Code</mat-label>
<input matInput formControlName="barcode">
<input matInput formControlName="barcode" readonly>
<mat-icon matSuffix svgIcon="ui-qr" aria-hidden="true"></mat-icon>
</mat-form-field>

@if (qrCodeDataUrl) {
<div class="qr-preview">
<h3>QR payload preview</h3>
<img [src]="qrCodeDataUrl" alt="Tool QR code preview">
</div>
}

<div class="row">
<mat-form-field appearance="outline" class="half-width">
<mat-label>Location</mat-label>
Expand Down Expand Up @@ -62,4 +91,3 @@ <h2 mat-dialog-title>{{ isEdit ? 'Edit Tool' : 'Add Tool' }}</h2>
{{ isEdit ? 'Update' : 'Create' }}
</button>
</mat-dialog-actions>

Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,24 @@
.half-width {
flex: 1;
}

.qr-preview {
margin-bottom: 16px;
padding: 12px;
border: 1px solid #e0e0e0;
border-radius: 8px;
text-align: center;
background-color: #fafafa;
}

.qr-preview h3 {
margin: 0 0 8px;
font-size: 14px;
font-weight: 600;
}

.qr-preview img {
width: 220px;
height: 220px;
max-width: 100%;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Component, OnInit, inject } from '@angular/core';
import { Component, DestroyRef, OnInit, inject } from '@angular/core';
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog';
import { MatButtonModule } from '@angular/material/button';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { MatSelectModule } from '@angular/material/select';
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
import * as QRCode from 'qrcode';
import { Category } from '../../../models/category.model';
import { Tool, ToolStatus } from '../../../models/tool.model';
import { CategoryService } from '../../../services/category.service';
Expand All @@ -33,21 +35,27 @@ export class ToolFormDialogComponent implements OnInit {
private readonly categoryService = inject(CategoryService);
private readonly dialogRef = inject(MatDialogRef<ToolFormDialogComponent>);
private readonly snackBar = inject(MatSnackBar);
private readonly destroyRef = inject(DestroyRef);
readonly data: Tool | null = inject(MAT_DIALOG_DATA, { optional: true }) ?? null;

readonly categories: Category[] = [];
readonly statuses: ToolStatus[] = ['Available', 'CheckedOut', 'UnderMaintenance', 'Retired'];

readonly form = this.fb.group({
name: ['', Validators.required],
make: [''],
model: [''],
serialNumber: [''],
owner: [''],
description: [''],
barcode: [''],
barcode: [{ value: '', disabled: true }],
location: [''],
systainer: [''],
imageUrl: [''],
categoryId: [null as number | null],
status: ['Available' as ToolStatus, Validators.required]
});
qrCodeDataUrl = '';

get isEdit(): boolean {
return !!this.data;
Expand All @@ -61,6 +69,10 @@ export class ToolFormDialogComponent implements OnInit {
if (this.data) {
this.form.patchValue({
name: this.data.name,
make: this.data.make ?? '',
model: this.data.model ?? '',
serialNumber: this.data.serialNumber ?? '',
owner: this.data.owner ?? '',
description: this.data.description ?? '',
barcode: this.data.barcode ?? '',
location: this.data.location ?? '',
Expand All @@ -69,7 +81,14 @@ export class ToolFormDialogComponent implements OnInit {
categoryId: this.data.categoryId ?? null,
status: this.data.status
});
} else {
this.form.patchValue({ barcode: this.generateBarcode() });
}

this.form.valueChanges
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => void this.refreshQrCode());
void this.refreshQrCode();
}

save(): void {
Expand All @@ -86,8 +105,11 @@ export class ToolFormDialogComponent implements OnInit {
if (this.isEdit && this.data) {
this.toolService.update(this.data.id, {
name,
make: value.make || undefined,
model: value.model || undefined,
serialNumber: value.serialNumber || undefined,
owner: value.owner || undefined,
description: value.description || undefined,
barcode: value.barcode || undefined,
location: value.location || undefined,
systainer: value.systainer || undefined,
imageUrl: value.imageUrl || undefined,
Expand All @@ -103,6 +125,10 @@ export class ToolFormDialogComponent implements OnInit {
} else {
this.toolService.create({
name,
make: value.make || undefined,
model: value.model || undefined,
serialNumber: value.serialNumber || undefined,
owner: value.owner || undefined,
description: value.description || undefined,
barcode: value.barcode || undefined,
location: value.location || undefined,
Expand All @@ -122,4 +148,31 @@ export class ToolFormDialogComponent implements OnInit {
cancel(): void {
this.dialogRef.close(false);
}

private async refreshQrCode(): Promise<void> {
const value = this.form.getRawValue();
const barcode = (value.barcode ?? '').trim();
if (!barcode) {
this.qrCodeDataUrl = '';
return;
}

const payload = JSON.stringify({
id: barcode,
make: (value.make ?? '').trim(),
model: (value.model ?? '').trim(),
owner: (value.owner ?? '').trim()
});
this.qrCodeDataUrl = await QRCode.toDataURL(payload, { width: 220, margin: 1 });
}

private generateBarcode(): string {
if (globalThis.crypto?.randomUUID) {
return globalThis.crypto.randomUUID().toUpperCase();
}

return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, c =>
(Number(c) ^ (Math.random() * 16 >> (Number(c) / 4))).toString(16)
).toUpperCase();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,13 @@ export class ToolsListComponent implements OnInit, AfterViewInit {
}

toolMeta(tool: Tool): string {
return [tool.systainer, tool.barcode].filter(Boolean).join(' · ') || 'No barcode or systainer assigned';
const modelInfo = [tool.make, tool.model].filter(Boolean).join(' ');
return [modelInfo, tool.serialNumber, tool.owner, tool.systainer, tool.barcode].filter(Boolean).join(' | ')
|| 'No make, model, serial number, owner, barcode, or systainer assigned';
}

locationMeta(tool: Tool): string {
return [tool.location, tool.description].filter(Boolean).join(' · ') || 'No location details';
return [tool.location, tool.description].filter(Boolean).join(' � ') || 'No location details';
}

private performCheckIn(tool: Tool): void {
Expand Down Expand Up @@ -417,6 +419,10 @@ export class ToolsListComponent implements OnInit, AfterViewInit {

return [
tool.name,
tool.make,
tool.model,
tool.serialNumber,
tool.owner,
tool.categoryName,
tool.location,
tool.systainer,
Expand Down Expand Up @@ -515,5 +521,3 @@ export class ToolsListComponent implements OnInit, AfterViewInit {
&& date.getDate() === compareDate.getDate();
}
}


8 changes: 8 additions & 0 deletions frontend/tool-inventory-app/src/app/models/tool.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ export type ToolStatus = 'Available' | 'CheckedOut' | 'UnderMaintenance' | 'Reti
export interface Tool {
id: number;
name: string;
make?: string;
model?: string;
serialNumber?: string;
owner?: string;
description?: string;
barcode?: string;
location?: string;
Expand All @@ -15,6 +19,10 @@ export interface Tool {

export interface CreateTool {
name: string;
make?: string;
model?: string;
serialNumber?: string;
owner?: string;
description?: string;
barcode?: string;
location?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ export class ScannerDialogComponent implements OnDestroy {
return;
}

const toolId = this.extractToolId(code);
this.lastScannedCode.set(code);
this.scanning.set(false);
this.loading.set(true);
this.foundTool.set(null);
this.errorMessage.set(null);

this.toolService.getByBarcode(code).subscribe({
this.toolService.getByBarcode(toolId).subscribe({
next: tool => {
this.loading.set(false);
this.foundTool.set(tool);
Expand All @@ -71,7 +72,7 @@ export class ScannerDialogComponent implements OnDestroy {
this.loading.set(false);
this.errorMessage.set(
err.status === 404
? `No tool found for barcode: ${code}`
? `No tool found for barcode: ${toolId}`
: 'Error looking up barcode. Please try again.'
);
}
Expand Down Expand Up @@ -118,4 +119,22 @@ export class ScannerDialogComponent implements OnDestroy {
ngOnDestroy(): void {
this.scanning.set(false);
}

private extractToolId(code: string): string {
const scanned = code.trim();
if (!scanned.startsWith('{')) {
return scanned;
}

try {
const parsed = JSON.parse(scanned) as { id?: unknown };
if (typeof parsed.id === 'string' && parsed.id.trim()) {
return parsed.id.trim();
}
} catch {
// Keep backwards compatibility with plain barcode values.
}

return scanned;
}
}
1 change: 1 addition & 0 deletions mobile/ToolInventory.MAUI/ToolInventory.MAUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.2" />
<PackageReference Include="Microsoft.Maui.Controls" Version="10.0.60" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="10.0.0" />
<PackageReference Include="QRCoder" Version="1.6.0" />
<PackageReference Include="ZXing.Net.Maui.Controls" Version="0.7.4" />
</ItemGroup>

Expand Down
Loading
Loading