| import { Injectable } from '@angular/core'; |
|
|
| export interface PoliceCase { |
| |
| caseId?: string; |
| dateTime?: string; |
| status?: 'Open' | 'Under Investigation' | 'Closed' | 'Archived'; |
| crime: string; |
| police: { |
| name: string; |
| station: string; |
| address: string; |
| pincode: string; |
| dutyPerson: string; |
| modeOfCrime: string; |
| information?: string; |
| }; |
| accused: { |
| name: string; |
| age: string | number; |
| gender: string; |
| address: string; |
| occupation?: string; |
| }; |
| lastUpdated?: string; |
| nextAction?: string; |
| casePriority?: 'High' | 'Medium' | 'Low'; |
| reportedBy?: string; |
| verifiedBy?: string; |
| briefDescription?: string; |
| caseCategory?: string; |
| } |
|
|
| @Injectable({ providedIn: 'root' }) |
| export class CaseStoreService { |
| private readonly storageKey = 'py_detect_police_cases'; |
| private cases: PoliceCase[] = []; |
|
|
| constructor() { |
| this.load(); |
| } |
|
|
| |
| addPoliceCase(c: PoliceCase): void { |
| this.cases.unshift(c); |
| this.save(); |
| } |
|
|
| |
| getPoliceCases(): PoliceCase[] { |
| return this.cases; |
| } |
|
|
| |
| updatePoliceCaseAt(index: number, updated: PoliceCase): void { |
| if (index >= 0 && index < this.cases.length) { |
| this.cases[index] = updated; |
| this.save(); |
| } |
| } |
|
|
| |
| updatePoliceCaseById(caseId: string, updated: PoliceCase): void { |
| const idx = this.cases.findIndex(c => c.caseId === caseId); |
| if (idx !== -1) { |
| this.cases[idx] = updated; |
| this.save(); |
| } |
| } |
|
|
| |
| |
| |
| |
| addFromInfoForm(formValue: any): void { |
| const crime = (formValue && formValue.crime) || {}; |
| const suspect = (formValue && formValue.suspect) || {}; |
| const notes = (formValue && formValue.notes) || {}; |
|
|
| const mapped: PoliceCase = { |
| caseId: crime.caseId || '', |
| dateTime: crime.dateTime || '', |
| status: notes.status || 'Open', |
| crime: crime.crimeType || 'Unknown', |
| police: { |
| name: notes.officerInCharge || '—', |
| station: '—', |
| address: crime.location || '—', |
| pincode: '', |
| dutyPerson: notes.officerInCharge || '—', |
| modeOfCrime: crime.crimeType || '—', |
| information: notes.initialFindings || '' |
| }, |
| accused: { |
| name: suspect.fullName || '—', |
| age: suspect.age || '—', |
| gender: suspect.gender || '—', |
| address: suspect.address || '—', |
| occupation: suspect.alias || '' |
| } |
| }; |
|
|
| this.addPoliceCase(mapped); |
| } |
|
|
| |
| addOrUpdateFromInfoForm(formValue: any): void { |
| const crime = (formValue && formValue.crime) || {}; |
| const suspect = (formValue && formValue.suspect) || {}; |
| const notes = (formValue && formValue.notes) || {}; |
| const mapped: PoliceCase = { |
| caseId: crime.caseId || '', |
| dateTime: crime.dateTime || '', |
| status: notes.status || 'Open', |
| crime: crime.crimeType || 'Unknown', |
| police: { |
| name: notes.officerInCharge || '—', |
| station: '—', |
| address: crime.location || '—', |
| pincode: '', |
| dutyPerson: notes.officerInCharge || '—', |
| modeOfCrime: crime.crimeType || '—', |
| information: notes.initialFindings || '' |
| }, |
| accused: { |
| name: suspect.fullName || '—', |
| age: suspect.age || '—', |
| gender: suspect.gender || '—', |
| address: suspect.address || '—', |
| occupation: suspect.alias || '' |
| }, |
| reportedBy: crime.reportedBy || '', |
| verifiedBy: notes.verifiedBy || '', |
| briefDescription: crime.briefDescription || '', |
| }; |
| const idx = this.cases.findIndex(c => c.caseId === mapped.caseId); |
| if (idx !== -1) { |
| this.cases[idx] = mapped; |
| this.save(); |
| } else { |
| this.addPoliceCase(mapped); |
| } |
| } |
|
|
| |
| private save(): void { |
| try { localStorage.setItem(this.storageKey, JSON.stringify(this.cases)); } catch { } |
| } |
|
|
| |
| private load(): void { |
| try { |
| const raw = localStorage.getItem(this.storageKey); |
| this.cases = raw ? (JSON.parse(raw) as PoliceCase[]) : []; |
| } catch { |
| this.cases = []; |
| } |
| |
| if (this.cases.length === 0) { |
| this.cases = [ |
| { |
| caseId: 'CASE-001', |
| dateTime: new Date().toISOString(), |
| status: 'Open', |
| crime: 'Theft', |
| police: { |
| name: 'Officer John Doe', |
| station: 'Central Station', |
| address: '123 Main St, City', |
| pincode: '123456', |
| dutyPerson: 'Officer John Doe', |
| modeOfCrime: 'Burglary', |
| information: 'Initial investigation started.' |
| }, |
| accused: { |
| name: 'Jane Smith', |
| age: 30, |
| gender: 'Female', |
| address: '456 Side Rd, City', |
| occupation: 'Unemployed' |
| } |
| } |
| ]; |
| this.save(); |
| } |
| } |
| } |
|
|