Download src/app/case-store.service.ts from pykara/Py-detect: direct link, hf CLI and curl.
- Browser
- Download file 4.74 kB
-
https://huggingface.co/spaces/pykara/Py-detect/resolve/main/src/app/case-store.service.ts
- Command line
-
hf download hf://spaces/pykara/Py-detect/src/app/case-store.service.ts
-
curl -L -o case-store.service.ts https://huggingface.co/spaces/pykara/Py-detect/resolve/main/src/app/case-store.service.ts
4.74 kB
| import { Injectable } from '@angular/core'; | |
| export interface LegalInfo { | |
| witnessStatements: string; | |
| confessions: string; | |
| evidence: File[]; // Assuming you're collecting file(s) as evidence | |
| } | |
| export interface PoliceCase { | |
| // Optional metadata used by your UI | |
| caseId?: string; | |
| firRef?: string; | |
| occurredFrom?: string; | |
| occurredTo?: string; | |
| jurisdiction?: string; | |
| sceneType?: string; | |
| dateTime?: string; | |
| status?: 'Open' | 'Under Investigation' | 'Closed'; | |
| 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; | |
| }; | |
| legal: LegalInfo; // Add the legal property here | |
| victimName?: string; | |
| caseCategory?: string; | |
| reportedBy?: string; | |
| lastUpdated?: string; | |
| verifiedBy?: string; | |
| } | |
| ({ providedIn: 'root' }) | |
| export class CaseStoreService { | |
| private readonly storageKey = 'py_detect_police_cases'; | |
| private cases: PoliceCase[] = []; | |
| constructor() { | |
| this.load(); | |
| } | |
| /** Create (newest first) */ | |
| private getNextCaseId(): string { | |
| const max = this.cases | |
| .map(c => c.caseId) | |
| .map(id => parseInt((id || '').replace('CASE-', ''), 10)) | |
| .filter(n => !isNaN(n)) | |
| .reduce((a, b) => Math.max(a, b), 0); | |
| return `CASE-${(max + 1).toString().padStart(3, '0')}`; | |
| } | |
| addPoliceCase(c: PoliceCase): void { | |
| if (!c.caseId) { | |
| c.caseId = this.getNextCaseId(); | |
| } | |
| c.lastUpdated = new Date().toISOString(); | |
| c.verifiedBy = c.verifiedBy || ''; | |
| this.cases.unshift(c); | |
| this.save(); | |
| } | |
| /** Read */ | |
| getPoliceCases(): PoliceCase[] { | |
| return this.cases; | |
| } | |
| /** Update by array index */ | |
| updatePoliceCaseAt(index: number, updated: PoliceCase): void { | |
| if (index >= 0 && index < this.cases.length) { | |
| updated.lastUpdated = new Date().toISOString(); | |
| this.cases[index] = updated; | |
| this.save(); | |
| } | |
| } | |
| /** Delete by array index */ | |
| deletePoliceCaseAt(index: number): void { | |
| if (index >= 0 && index < this.cases.length) { | |
| this.cases.splice(index, 1); | |
| this.save(); | |
| } | |
| } | |
| /** | |
| * Convenience: map Info page reactive-form value to PoliceCase and store it. | |
| * Call with the whole this.form.value from InfopageComponent. | |
| */ | |
| addFromInfoForm(formValue: any): void { | |
| const crime = (formValue && formValue.crime) || {}; | |
| const suspect = (formValue && formValue.suspect) || {}; | |
| const notes = (formValue && formValue.notes) || {}; | |
| const legal = (formValue && formValue.legal) || {}; | |
| const mapped: PoliceCase = { | |
| caseId: crime.caseId || '', | |
| firRef: crime['FIR / Ref #'] || formValue['FIR / Ref #'] || '', | |
| occurredFrom: crime['Occurred From'] || formValue['Occurred From'] || '', | |
| occurredTo: crime['Occurred To'] || formValue['Occurred To'] || '', | |
| jurisdiction: crime['Jurisdiction / PS'] || formValue['Jurisdiction / PS'] || '', | |
| sceneType: crime['Scene Type'] || formValue['Scene Type'] || '', | |
| 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 || '' | |
| }, | |
| legal: { | |
| witnessStatements: legal.witnessStatements || '', | |
| confessions: legal.confessions || '', | |
| evidence: legal.evidence || [] | |
| }, | |
| victimName: crime.victimName || formValue['Victim Name'] || '', | |
| caseCategory: crime.caseCategory || formValue['Case Category'] || '', | |
| reportedBy: crime.reportedBy || formValue['Reported By'] || '', | |
| lastUpdated: new Date().toISOString(), | |
| verifiedBy: formValue.verifiedBy || '', | |
| }; | |
| this.addPoliceCase(mapped); | |
| } | |
| /** Persist to localStorage (safe to keep; remove if not needed) */ | |
| private save(): void { | |
| try { localStorage.setItem(this.storageKey, JSON.stringify(this.cases)); } catch { } | |
| } | |
| /** Load from localStorage */ | |
| private load(): void { | |
| try { | |
| const raw = localStorage.getItem(this.storageKey); | |
| this.cases = raw ? (JSON.parse(raw) as PoliceCase[]) : []; | |
| } catch { | |
| this.cases = []; | |
| } | |
| } | |
| } | |