From 556b56f9c6a6f1f033e4fe5cf3446f95a673ced6 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Thu, 25 Apr 2019 23:16:37 -0400 Subject: [PATCH] eg-cat-counter component This adds a componet that allows the user to supply a record type and a date and count the number of bibliographic or authority records that were last edited on the supplied date. This is a toy meant for a presentation made during the 2019 Evergreen International Conference Signed-off-by: Galen Charlton --- .../share/cat-counter/cat-counter.component.css | 5 ++++ .../share/cat-counter/cat-counter.component.html | 17 ++++++++++++ .../app/share/cat-counter/cat-counter.component.ts | 31 +++++++++++++++++++++ .../app/share/cat-counter/cat-counter.service.ts | 32 ++++++++++++++++++++++ .../src/app/staff/sandbox/sandbox.component.html | 10 +++++++ .../eg2/src/app/staff/sandbox/sandbox.module.ts | 6 +++- 6 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 Open-ILS/src/eg2/src/app/share/cat-counter/cat-counter.component.css create mode 100644 Open-ILS/src/eg2/src/app/share/cat-counter/cat-counter.component.html create mode 100644 Open-ILS/src/eg2/src/app/share/cat-counter/cat-counter.component.ts create mode 100644 Open-ILS/src/eg2/src/app/share/cat-counter/cat-counter.service.ts diff --git a/Open-ILS/src/eg2/src/app/share/cat-counter/cat-counter.component.css b/Open-ILS/src/eg2/src/app/share/cat-counter/cat-counter.component.css new file mode 100644 index 0000000000..5dbb2b148d --- /dev/null +++ b/Open-ILS/src/eg2/src/app/share/cat-counter/cat-counter.component.css @@ -0,0 +1,5 @@ +.eg-cat-counter { + border-style: dotted; + padding: 4px; + margin: 4px; +} diff --git a/Open-ILS/src/eg2/src/app/share/cat-counter/cat-counter.component.html b/Open-ILS/src/eg2/src/app/share/cat-counter/cat-counter.component.html new file mode 100644 index 0000000000..77fb8511ad --- /dev/null +++ b/Open-ILS/src/eg2/src/app/share/cat-counter/cat-counter.component.html @@ -0,0 +1,17 @@ +
+ Cat counter: + + + + + + No cats have been counted yet + 🐈 + ({{count}}) +
diff --git a/Open-ILS/src/eg2/src/app/share/cat-counter/cat-counter.component.ts b/Open-ILS/src/eg2/src/app/share/cat-counter/cat-counter.component.ts new file mode 100644 index 0000000000..c83ccd9f5c --- /dev/null +++ b/Open-ILS/src/eg2/src/app/share/cat-counter/cat-counter.component.ts @@ -0,0 +1,31 @@ +import {Component, Input, Output} from '@angular/core'; +import {ComboboxEntry} from '@eg/share/combobox/combobox.component'; +import {CatCounterService} from './cat-counter.service'; + +@Component({ + selector: 'eg-cat-counter', + templateUrl: 'cat-counter.component.html', + styleUrls: ['cat-counter.component.css'] +}) + +export class CatCounterComponent { + @Input() initialRecordType: string; + @Output() count: number = 0; + + private recordType: string; + + constructor( + private counter: CatCounterService + ) { + this.recordType = this.initialRecordType; + } + + selectRecordType($event: ComboboxEntry) { + this.recordType = $event.id; + } + updateCount($event) { + this.counter.getCatCount(this.recordType, $event).then(ct => { + this.count = ct; + }); + } +} diff --git a/Open-ILS/src/eg2/src/app/share/cat-counter/cat-counter.service.ts b/Open-ILS/src/eg2/src/app/share/cat-counter/cat-counter.service.ts new file mode 100644 index 0000000000..4997649707 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/share/cat-counter/cat-counter.service.ts @@ -0,0 +1,32 @@ +import {Injectable} from '@angular/core'; +import {PcrudService} from '@eg/core/pcrud.service'; + +@Injectable() +export class CatCounterService { + + constructor( + private pcrud: PcrudService + ) { } + + addDay(date: Date): Date { + let newDate = new Date(date); + newDate.setDate(date.getDate() + 1); + return newDate; + } + + getCatCount(recordType: string, date: Date): Promise { + const cls = (recordType === 'authority') ? 'are' : 'bre'; + + let search: any = [ + { id: { "!=" : null } }, + { edit_date: {">": date.toISOString() } }, + { edit_date: {"<=": this.addDay(date).toISOString() } }, + ]; + + return this.pcrud.search( + cls, search, {}, {atomic:true} + ).toPromise().then(list => { + return list.length; + }); + } +} 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 84e127e3c0..0bbda11985 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 @@ -9,6 +9,16 @@
+
Counting cats:
+
+ +
+
+ +
+
+ +
Modify Page Title:
diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.module.ts b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.module.ts index 58910dddbb..97ab92bb6a 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.module.ts @@ -2,16 +2,20 @@ import {NgModule} from '@angular/core'; import {StaffCommonModule} from '@eg/staff/common.module'; import {SandboxRoutingModule} from './routing.module'; import {SandboxComponent} from './sandbox.component'; +import {CatCounterComponent} from '@eg/share/cat-counter/cat-counter.component'; +import {CatCounterService} from '@eg/share/cat-counter/cat-counter.service'; @NgModule({ declarations: [ - SandboxComponent + SandboxComponent, + CatCounterComponent ], imports: [ StaffCommonModule, SandboxRoutingModule, ], providers: [ + CatCounterService ] }) -- 2.11.0