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';
16 selector: 'eg-patron-messages',
17 templateUrl: 'messages.component.html'
19 export class PatronMessagesComponent implements OnInit {
21 @Input() patronId: number;
23 mainDataSource: GridDataSource = new GridDataSource();
24 archiveDataSource: GridDataSource = new GridDataSource();
29 @ViewChild('mainGrid') private mainGrid: GridComponent;
30 @ViewChild('archiveGrid') private archiveGrid: GridComponent;
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
44 const orgIds = this.org.fullPath(this.auth.user().ws_ou(), true);
46 const start = new Date();
47 start.setFullYear(start.getFullYear() - 1);
48 this.startDateYmd = DateUtil.localYmdFromDate(start);
49 this.endDateYmd = DateUtil.localYmdFromDate(); // now
54 ausp: ['standing_penalty', 'staff']
59 this.mainDataSource.getRows = (pager: Pager, sort: any[]) => {
61 const orderBy: any = {ausp: 'set_date'};
63 orderBy.ausp = sort[0].name + ' ' + sort[0].dir;
71 {stop_date: {'>' : 'now'}}
75 flesh.order_by = orderBy;
76 return this.pcrud.search('ausp', query, flesh);
79 this.archiveDataSource.getRows = (pager: Pager, sort: any[]) => {
80 const orderBy: any = {ausp: 'set_date'};
82 orderBy.ausp = sort[0].name + ' ' + sort[0].dir;
88 stop_date: {'<' : 'now'},
89 set_date: {between: this.dateRange()}
92 flesh.order_by = orderBy;
94 return this.pcrud.search('ausp', query, flesh);
98 dateRange(): string[] {
100 let endDate = this.endDateYmd;
101 const today = DateUtil.localYmdFromDate();
103 if (endDate == today) { endDate = 'now'; }
105 return [this.startDateYmd, endDate];
108 dateChange(iso: string, start?: boolean) {
110 this.startDateYmd = iso;
112 this.endDateYmd = iso;
114 this.archiveGrid.reload();