eg-cat-counter component user/gmcharlt/eg-cat-counter-evgils19
authorGalen Charlton <gmc@equinoxinitiative.org>
Fri, 26 Apr 2019 03:16:37 +0000 (23:16 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Fri, 26 Apr 2019 03:16:37 +0000 (23:16 -0400)
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 <gmc@equinoxinitiative.org>
Open-ILS/src/eg2/src/app/share/cat-counter/cat-counter.component.css [new file with mode: 0644]
Open-ILS/src/eg2/src/app/share/cat-counter/cat-counter.component.html [new file with mode: 0644]
Open-ILS/src/eg2/src/app/share/cat-counter/cat-counter.component.ts [new file with mode: 0644]
Open-ILS/src/eg2/src/app/share/cat-counter/cat-counter.service.ts [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html
Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.module.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 (file)
index 0000000..5dbb2b1
--- /dev/null
@@ -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 (file)
index 0000000..77fb851
--- /dev/null
@@ -0,0 +1,17 @@
+<div class="eg-cat-counter">
+  <span i18n>Cat counter:</span>
+  <eg-combobox #recordTypeSelector
+    id="type-select"
+    (onChange)="selectRecordType($event)"
+    [startId]="initialRecordType" [startIdFiresOnChange]="true"
+    placeholder="Record Type..." i18n-placeholder>
+    <eg-combobox-entry entryId="biblio" entryLabel="Bibliographic"
+      i18n-entryLabel></eg-combobox-entry>
+    <eg-combobox-entry entryId="authority" entryLabel="Authority"
+      i18n-entryLabel></eg-combobox-entry>
+  </eg-combobox>
+  <eg-date-select (onChangeAsDate)="updateCount($event)"></eg-date-select>
+  <span *ngIf="count == 0" i81n>No cats have been counted yet</span>
+  <span *ngFor="let x of [].constructor(count)">🐈</span>
+  <span *ngIf="count > 0" i18n>({{count}})</span>
+</div>
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 (file)
index 0000000..c83ccd9
--- /dev/null
@@ -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 (file)
index 0000000..4997649
--- /dev/null
@@ -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<number> {
+        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;
+        });
+    }
+}
index 84e127e..0bbda11 100644 (file)
@@ -9,6 +9,16 @@
 </eg-title>
 
 <div class="row flex pt-2">
+  <div i18n>Counting cats:</div>
+  <div class="col-lg-3">
+    <eg-cat-counter initialRecordType="biblio"></eg-cat-counter>
+  </div>
+  <div class="col-lg-3">
+    <eg-cat-counter initialRecordType="authority"></eg-cat-counter>
+  </div>
+</div>
+
+<div class="row flex pt-2">
   <div i18n> Modify Page Title: </div>
   <div class="col-lg-2">
     <input type="text" [(ngModel)]="dynamicTitleText" class="form-control"/>
index 58910dd..97ab92b 100644 (file)
@@ -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
   ]
 })