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