LP1904036 Messages
authorBill Erickson <berickxx@gmail.com>
Thu, 1 Apr 2021 22:01:54 +0000 (18:01 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Fri, 28 Oct 2022 00:13:29 +0000 (20:13 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <js7389@princeton.edu>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/circ/patron/messages.component.html [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/circ/patron/messages.component.ts [new file with mode: 0644]

diff --git a/Open-ILS/src/eg2/src/app/staff/circ/patron/messages.component.html b/Open-ILS/src/eg2/src/app/staff/circ/patron/messages.component.html
new file mode 100644 (file)
index 0000000..bec7338
--- /dev/null
@@ -0,0 +1,34 @@
+
+<div class="row mb-2">
+  <div class="col-lg-12">
+    <h3 i18n>Penalties and Messages</h3>
+  </div>
+</div>
+
+<eg-grid #mainGrid idlClass="ausp" [dataSource]="mainDataSource"
+  hideFields="id,usr,stop_date">
+  <eg-grid-toolbar-button i18n-label label="Apply Penalty / Message"
+    (onClick)="applyPenalty()">
+  </eg-grid-toolbar-button>
+  <eg-grid-column path="standing_penalty.label">
+  </eg-grid-column>
+  <eg-grid-column path="standing_penalty.staff_alert">
+  </eg-grid-column>
+</eg-grid>
+
+<hr class="mt-4 mb-2"/>
+
+<div class="row mt-4 mb-2">
+  <div class="col-lg-4">
+    <h3 i18n>Archived Penalties / Messages</h3>
+  </div>
+</div>
+
+<eg-grid #archiveGrid idlClass="ausp" [dataSource]="archiveDataSource"
+  hideFields="id,usr,stop_date">
+  <eg-grid-column path="standing_penalty.label">
+  </eg-grid-column>
+  <eg-grid-column path="standing_penalty.staff_alert">
+  </eg-grid-column>
+</eg-grid>
+
diff --git a/Open-ILS/src/eg2/src/app/staff/circ/patron/messages.component.ts b/Open-ILS/src/eg2/src/app/staff/circ/patron/messages.component.ts
new file mode 100644 (file)
index 0000000..b5f0a91
--- /dev/null
@@ -0,0 +1,113 @@
+import {Component, ViewChild, OnInit, Input, AfterViewInit} from '@angular/core';
+import {empty} from 'rxjs';
+import {NetService} from '@eg/core/net.service';
+import {OrgService} from '@eg/core/org.service';
+import {PcrudService} from '@eg/core/pcrud.service';
+import {AuthService} from '@eg/core/auth.service';
+import {ServerStoreService} from '@eg/core/server-store.service';
+import {PatronService} from '@eg/staff/share/patron/patron.service';
+import {PatronContextService} from './patron.service';
+import {GridDataSource, GridColumn, GridCellTextGenerator} from '@eg/share/grid/grid';
+import {GridComponent} from '@eg/share/grid/grid.component';
+import {Pager} from '@eg/share/util/pager';
+import {DateUtil} from '@eg/share/util/date';
+
+@Component({
+  selector: 'eg-patron-messages',
+  templateUrl: 'messages.component.html'
+})
+export class PatronMessagesComponent implements OnInit {
+
+    @Input() patronId: number;
+
+    mainDataSource: GridDataSource = new GridDataSource();
+    archiveDataSource: GridDataSource = new GridDataSource();
+
+    startDateYmd: string;
+    endDateYmd: string;
+
+    @ViewChild('mainGrid') private mainGrid: GridComponent;
+    @ViewChild('archiveGrid') private archiveGrid: GridComponent;
+
+    constructor(
+        private org: OrgService,
+        private net: NetService,
+        private pcrud: PcrudService,
+        private auth: AuthService,
+        private serverStore: ServerStoreService,
+        public patronService: PatronService,
+        public context: PatronContextService
+    ) {}
+
+    ngOnInit() {
+
+               const orgIds = this.org.fullPath(this.auth.user().ws_ou(), true);
+
+        const start = new Date();
+        start.setFullYear(start.getFullYear() - 1);
+        this.startDateYmd = DateUtil.localYmdFromDate(start);
+        this.endDateYmd = DateUtil.localYmdFromDate(); // now
+
+        const flesh = {
+            flesh: 1,
+            flesh_fields: {
+                ausp: ['standing_penalty', 'staff']
+            },
+            order_by: {}
+        };
+
+        this.mainDataSource.getRows = (pager: Pager, sort: any[]) => {
+
+            const orderBy: any = {ausp: 'set_date'};
+            if (sort.length) {
+                orderBy.ausp = sort[0].name + ' ' + sort[0].dir;
+            }
+
+            const query = {
+                usr: this.patronId,
+                org_unit: orgIds,
+                '-or' : [
+                    {stop_date: null},
+                    {stop_date: {'>' : 'now'}}
+                ]
+            };
+
+            flesh.order_by = orderBy;
+            return this.pcrud.search('ausp', query, flesh);
+        }
+
+        this.archiveDataSource.getRows = (pager: Pager, sort: any[]) => {
+            const orderBy: any = {ausp: 'set_date'};
+            if (sort.length) {
+                orderBy.ausp = sort[0].name + ' ' + sort[0].dir;
+            }
+
+            const query = {
+                usr: this.patronId,
+                org_unit: orgIds,
+                stop_date: {'<' : 'now'},
+                set_date: {between: this.dateRange()}
+            };
+
+            flesh.order_by = orderBy;
+
+            return this.pcrud.search('ausp', query, flesh);
+        }
+    }
+
+    dateRange(): string[] {
+
+        let endDate = this.endDateYmd;
+        const today = DateUtil.localYmdFromDate();
+
+        if (endDate == today) { endDate = 'now'; }
+
+        return [this.startDateYmd, endDate];
+    }
+
+    applyPenalty() {
+    }
+}
+
+
+