]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/util/sample-data.service.ts
LP 2061136 follow-up: ng lint --fix
[Evergreen.git] / Open-ILS / src / eg2 / src / app / share / util / sample-data.service.ts
1 /* eslint-disable no-magic-numbers */
2 import {Injectable} from '@angular/core';
3 import {IdlService, IdlObject} from '@eg/core/idl.service';
4
5 /** Service for generating sample data for testing, demo, etc. */
6
7 // TODO: I could also imagine this coming from a web service or
8 // even a flat file of web-served JSON.
9
10 const NOW_DATE = new Date().toISOString();
11
12 // Copied from sample of Concerto data set
13 const DATA = {
14     au: [
15         {first_given_name: 'Vincent',  second_given_name: 'Kenneth',   family_name: 'Moran'},
16         {first_given_name: 'Gregory',  second_given_name: 'Adam',      family_name: 'Jones'},
17         {first_given_name: 'Brittany', second_given_name: 'Geraldine', family_name: 'Walker'},
18         {first_given_name: 'Ernesto',  second_given_name: 'Robert',    family_name: 'Miller'},
19         {first_given_name: 'Robert',   second_given_name: 'Louis',     family_name: 'Hill'},
20         {first_given_name: 'Edward',   second_given_name: 'Robert',    family_name: 'Lopez'},
21         {first_given_name: 'Andrew',   second_given_name: 'Alberto',   family_name: 'Bell'},
22         {first_given_name: 'Jennifer', second_given_name: 'Dorothy',   family_name: 'Mitchell'},
23         {first_given_name: 'Jo',       second_given_name: 'Mai',       family_name: 'Madden'},
24         {first_given_name: 'Maomi',    second_given_name: 'Julie',     family_name: 'Harding'}
25     ],
26     ac: [
27         {barcode: '908897239000'},
28         {barcode: '908897239001'},
29         {barcode: '908897239002'},
30         {barcode: '908897239003'},
31         {barcode: '908897239004'},
32         {barcode: '908897239005'},
33         {barcode: '908897239006'},
34         {barcode: '908897239007'},
35         {barcode: '908897239008'},
36         {barcode: '908897239009'}
37     ],
38     aua: [
39         {street1: '1809 Target Way', city: 'Vero beach', state: 'FL', post_code: 32961},
40         {street1: '3481 Facility Island', city: 'Campton', state: 'KY', post_code: 41301},
41         {street1: '5150 Dinner Expressway', city: 'Dodge center', state: 'MN', post_code: 55927},
42         {street1: '8496 Random Trust Points', city: 'Berryville', state: 'VA', post_code: 22611},
43         {street1: '7626 Secret Institute Courts', city: 'Anchorage', state: 'AK', post_code: 99502},
44         {street1: '7044 Regular Index Path', city: 'Livingston', state: 'KY', post_code: 40445},
45         {street1: '3403 Thundering Heat Meadows', city: 'Miami', state: 'FL', post_code: 33157},
46         {street1: '759 Doubtful Government Extension', city: 'Sellersville', state: 'PA', post_code: 18960},
47         {street1: '5431 Japanese Work Rapid', city: 'Society hill', state: 'SC', post_code: 29593},
48         {street1: '5253 Agricultural Exhibition Stravenue', city: 'La place', state: 'IL', post_code: 61936}
49     ],
50     ahr: [
51         {request_time: NOW_DATE, hold_type: 'T', capture_time: null,     fulfillment_time: null},
52         {request_time: NOW_DATE, hold_type: 'T', capture_time: null,     fulfillment_time: null},
53         {request_time: NOW_DATE, hold_type: 'V', capture_time: null,     fulfillment_time: null},
54         {request_time: NOW_DATE, hold_type: 'C', capture_time: null,     fulfillment_time: null},
55         {request_time: NOW_DATE, hold_type: 'T', capture_time: null,     fulfillment_time: null, frozen: true},
56         {request_time: NOW_DATE, hold_type: 'T', capture_time: NOW_DATE, fulfillment_time: null},
57         {request_time: NOW_DATE, hold_type: 'T', capture_time: NOW_DATE, fulfillment_time: null},
58         {request_time: NOW_DATE, hold_type: 'T', capture_time: NOW_DATE, fulfillment_time: NOW_DATE},
59         {request_time: NOW_DATE, hold_type: 'T', capture_time: NOW_DATE, fulfillment_time: NOW_DATE},
60         {request_time: NOW_DATE, hold_type: 'T', capture_time: NOW_DATE, fulfillment_time: NOW_DATE}
61     ],
62     acp: [
63         {barcode: '208897239000'},
64         {barcode: '208897239001'},
65         {barcode: '208897239002'},
66         {barcode: '208897239003'},
67         {barcode: '208897239004'},
68         {barcode: '208897239005'},
69         {barcode: '208897239006'},
70         {barcode: '208897239007'},
71         {barcode: '208897239008'},
72         {barcode: '208897239009'}
73     ],
74     mwde: [
75         {title: 'Sinidos sinfónicos : an orchestral sampler'},
76         {title: 'Piano concerto, op. 38'},
77         {title: 'Critical entertainments : music old and new'},
78         {title: 'Piano concerto in C major, op. 39'},
79         {title: 'Double concerto in A minor, op. 102 ; Variations on a theme by Haydn, op. 56a ; Tragic overture, op. 81'},
80         {title: 'Trombone concerto (1991) subject: american'},
81         {title: 'Violin concerto no. 2 ; Six duos (from 44 Duos)'},
82         {title: 'Piano concerto no. 1 (1926) ; Rhapsody, op. 1 (1904)'},
83         {title: 'Piano concertos 2 & 3 & the devil makes me?'},
84         {title: 'Composition student recital, April 6, 2000, Huntington University / composition students of Daniel Bédard'},
85     ],
86     mbt: [
87         {id: 1, xact_start: new Date().toISOString()},
88         {id: 2, xact_start: new Date().toISOString()},
89         {id: 3, xact_start: new Date().toISOString()}
90     ],
91     mbts: [
92         {   balance_owed: 1,
93             last_billing_note: 'a note',
94             last_billing_ts: new Date().toISOString(),
95             last_billing_type: 'Overdue Materials',
96             last_payment_note: '',
97             last_payment_ts: new Date().toISOString(),
98             last_payment_type: 'cash_payment',
99             total_owed: 5,
100             total_paid: 3,
101             xact_start: new Date().toISOString(),
102             xact_type: 'circulation'
103         }
104     ]
105 };
106
107
108 @Injectable()
109 export class SampleDataService {
110
111     constructor(private idl: IdlService) {}
112
113     randomValue(list: any[], field: string): string {
114         return list[Math.floor(Math.random() * list.length)][field];
115     }
116
117     listOfThings(idlClass: string, count = 1): IdlObject[] {
118         if (!(idlClass in DATA)) {
119             throw new Error(`No sample data for class ${idlClass}'`);
120         }
121
122         const things: IdlObject[] = [];
123         for (let i = 0; i < count; i++) {
124             const thing = this.idl.create(idlClass);
125             Object.keys(DATA[idlClass][0]).forEach(field =>
126                 thing[field](this.randomValue(DATA[idlClass], field))
127             );
128             things.push(thing);
129         }
130
131         return things;
132     }
133
134     // Returns a random-ish date in the past or the future.
135     randomDate(future = false): Date {
136         const rando = Math.random() * 10000000000;
137         const time = new Date().getTime();
138         return new Date(future ? time + rando : time - rando);
139     }
140
141     randomDateIso(future = false): string {
142         return this.randomDate(future).toISOString();
143     }
144 }
145
146