--- /dev/null
+.eg-cat-counter {
+ border-style: dotted;
+ padding: 4px;
+ margin: 4px;
+}
--- /dev/null
+<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>
--- /dev/null
+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;
+ });
+ }
+}
--- /dev/null
+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;
+ });
+ }
+}
</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"/>
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
]
})