From: Bill Erickson Date: Tue, 30 May 2023 15:11:24 +0000 (-0400) Subject: LP2018410 DOM AutoId Service X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=refs%2Fheads%2Fuser%2Fberick%2Flp2018410-dom-auto-id;p=working%2FEvergreen.git LP2018410 DOM AutoId Service Usage: Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/eg2/src/app/share/util/autoid.service.spec.ts b/Open-ILS/src/eg2/src/app/share/util/autoid.service.spec.ts new file mode 100644 index 0000000000..8801766681 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/share/util/autoid.service.spec.ts @@ -0,0 +1,20 @@ +import {AutoIdService} from './autoid.service'; + +let autoId: AutoIdService; + +beforeEach(() => { + autoId = new AutoIdService(); +}); + +describe('AutoId', () => { + it('Should always increase', () => { + expect(autoId.next() < autoId.next()).toBe(true); + }); + it('Should always increase', () => { + expect(autoId.next() < autoId.next()).toBe(true); + }); + it('Should always increase', () => { + expect(autoId.next() < autoId.next()).toBe(true); + }); +}); + diff --git a/Open-ILS/src/eg2/src/app/share/util/autoid.service.ts b/Open-ILS/src/eg2/src/app/share/util/autoid.service.ts new file mode 100644 index 0000000000..c49e29a88a --- /dev/null +++ b/Open-ILS/src/eg2/src/app/share/util/autoid.service.ts @@ -0,0 +1,17 @@ +import {Injectable} from '@angular/core'; + +@Injectable({providedIn: 'root'}) +export class AutoIdService { + static seed = 0; + + // Returns the next generated ID. + next(elm?: any): string { + // If the element has an ID, keep it. Otherwise, we end up + // auto-generating IDs repeatedly for the same element for + // every page load. + if (elm && elm.id) { return elm.id; } + + AutoIdService.seed++; + return `auto-${AutoIdService.seed}`; + } +} diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html index e9737bc48c..a06e71519c 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html @@ -2,6 +2,7 @@ + + + + + +