]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/circ/patron/messages.component.ts
LP1904036 Messages
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / circ / patron / messages.component.ts
1 import {Component, ViewChild, OnInit, Input, AfterViewInit} from '@angular/core';
2 import {empty} from 'rxjs';
3 import {NetService} from '@eg/core/net.service';
4 import {OrgService} from '@eg/core/org.service';
5 import {PcrudService} from '@eg/core/pcrud.service';
6 import {AuthService} from '@eg/core/auth.service';
7 import {ServerStoreService} from '@eg/core/server-store.service';
8 import {PatronService} from '@eg/staff/share/patron/patron.service';
9 import {PatronContextService} from './patron.service';
10 import {GridDataSource, GridColumn, GridCellTextGenerator} from '@eg/share/grid/grid';
11 import {GridComponent} from '@eg/share/grid/grid.component';
12 import {Pager} from '@eg/share/util/pager';
13 import {DateUtil} from '@eg/share/util/date';
14
15 @Component({
16   selector: 'eg-patron-messages',
17   templateUrl: 'messages.component.html'
18 })
19 export class PatronMessagesComponent implements OnInit {
20
21     @Input() patronId: number;
22
23     mainDataSource: GridDataSource = new GridDataSource();
24     archiveDataSource: GridDataSource = new GridDataSource();
25
26     startDateYmd: string;
27     endDateYmd: string;
28
29     @ViewChild('mainGrid') private mainGrid: GridComponent;
30     @ViewChild('archiveGrid') private archiveGrid: GridComponent;
31
32     constructor(
33         private org: OrgService,
34         private net: NetService,
35         private pcrud: PcrudService,
36         private auth: AuthService,
37         private serverStore: ServerStoreService,
38         public patronService: PatronService,
39         public context: PatronContextService
40     ) {}
41
42     ngOnInit() {
43
44                 const orgIds = this.org.fullPath(this.auth.user().ws_ou(), true);
45
46         const start = new Date();
47         start.setFullYear(start.getFullYear() - 1);
48         this.startDateYmd = DateUtil.localYmdFromDate(start);
49         this.endDateYmd = DateUtil.localYmdFromDate(); // now
50
51         const flesh = {
52             flesh: 1,
53             flesh_fields: {
54                 ausp: ['standing_penalty', 'staff']
55             },
56             order_by: {}
57         };
58
59         this.mainDataSource.getRows = (pager: Pager, sort: any[]) => {
60
61             const orderBy: any = {ausp: 'set_date'};
62             if (sort.length) {
63                 orderBy.ausp = sort[0].name + ' ' + sort[0].dir;
64             }
65
66             const query = {
67                 usr: this.patronId,
68                 org_unit: orgIds,
69                 '-or' : [
70                     {stop_date: null},
71                     {stop_date: {'>' : 'now'}}
72                 ]
73             };
74
75             flesh.order_by = orderBy;
76             return this.pcrud.search('ausp', query, flesh);
77         }
78
79         this.archiveDataSource.getRows = (pager: Pager, sort: any[]) => {
80             const orderBy: any = {ausp: 'set_date'};
81             if (sort.length) {
82                 orderBy.ausp = sort[0].name + ' ' + sort[0].dir;
83             }
84
85             const query = {
86                 usr: this.patronId,
87                 org_unit: orgIds,
88                 stop_date: {'<' : 'now'},
89                 set_date: {between: this.dateRange()}
90             };
91
92             flesh.order_by = orderBy;
93
94             return this.pcrud.search('ausp', query, flesh);
95         }
96     }
97
98     dateRange(): string[] {
99
100         let endDate = this.endDateYmd;
101         const today = DateUtil.localYmdFromDate();
102
103         if (endDate == today) { endDate = 'now'; }
104
105         return [this.startDateYmd, endDate];
106     }
107
108     dateChange(iso: string, start?: boolean) {
109         if (start) {
110             this.startDateYmd = iso;
111         } else {
112             this.endDateYmd = iso;
113         }
114         this.archiveGrid.reload();
115     }
116
117     applyPenalty() {
118     }
119 }
120
121
122