MCPcopy Create free account
hub / github.com/angular/examples / FleetService

Class FleetService

logistics-manager-app/src/app/services/fleet.service.ts:18–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16 providedIn: 'root'
17})
18export class FleetService {
19 // Use httpResource to fetch fleet data from the Express backend
20 readonly unitsResource = httpResource<FleetUnit[]>(() => '/api/fleet');
21 readonly serviceQueueResource = httpResource<ServiceTicket[]>(() => '/api/service-queue');
22
23 // Expose the value or an empty array if loading/error
24 readonly units = computed(() => this.unitsResource.value() ?? []);
25 readonly serviceQueue = computed(() => this.serviceQueueResource.value() ?? []);
26
27 readonly activeUnitId = signal<string | null>('V-UNIT 01_BETA');
28 readonly isDarkMode = signal(true);
29 readonly isChatOpen = signal(false);
30
31 readonly fleetWithActiveState = computed(() => {
32 const activeId = this.activeUnitId();
33 return this.units().map(u => ({ ...u, active: u.id === activeId }));
34 });
35
36 constructor() {
37 // Sync the .dark class with the signal state
38 effect(() => {
39 if (typeof document === 'undefined') return;
40 const isDark = this.isDarkMode();
41 if (isDark) {
42 document.documentElement.classList.add('dark');
43 } else {
44 document.documentElement.classList.remove('dark');
45 }
46 });
47
48 // Initialize from DOM if available
49 if (typeof document !== 'undefined') {
50 this.isDarkMode.set(document.documentElement.classList.contains('dark'));
51 }
52 }
53
54 setActiveUnit(id: string) {
55 this.activeUnitId.set(id);
56 }
57
58 toggleTheme() {
59 this.isDarkMode.update(dark => !dark);
60 }
61
62 toggleChat() {
63 this.isChatOpen.update(open => !open);
64 }
65
66 async addServiceTicket(unitId: string, issue: string) {
67 const ticket = {
68 unitId,
69 issue,
70 priority: 'MEDIUM',
71 status: 'OPEN',
72 reportedAt: new Date().toISOString()
73 };
74
75 await fetch('/api/service-queue', {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected