@everymatrix/lottery-draw-results 0.1.7 → 0.1.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -43,13 +43,75 @@ export class LotteryDrawResults {
43
43
  * The ticket draw count
44
44
  */
45
45
  this.ticketDrawCount = 0;
46
+ /**
47
+ * The ticket winning numbers
48
+ */
49
+ this.ticketNumbers = '';
50
+ /**
51
+ * The session id
52
+ */
53
+ this.sessionId = '';
54
+ /**
55
+ * Client custom styling via string
56
+ */
57
+ this.clientStyling = '';
58
+ /**
59
+ * Client custom styling via url content
60
+ */
61
+ this.clientStylingUrlContent = '';
46
62
  this.multiplier = 3;
47
63
  this.isLoading = true;
48
- this.drawResults = [];
49
64
  this.rules = {};
50
65
  this.toggleDrawer = [false];
51
66
  this.hasErrors = false;
52
67
  this.errorText = '';
68
+ this.ticketData = [];
69
+ this.ticketDataLoaded = false;
70
+ this.ticketDraws = [];
71
+ this.hasDrawNumbers = false;
72
+ this.limitStylingAppends = false;
73
+ this.getTicketsData = () => {
74
+ let url = new URL(`${this.endpoint}/tickets`);
75
+ let drawOptions = {
76
+ method: "GET",
77
+ headers: {
78
+ 'Content-Type': "application/json",
79
+ 'Accept': 'application/json',
80
+ 'Authorization': `Bearer ${this.sessionId}`
81
+ },
82
+ };
83
+ fetch(url.href, drawOptions)
84
+ .then((response) => {
85
+ return response.json();
86
+ })
87
+ .then((data) => {
88
+ if (data) {
89
+ this.ticketData = data;
90
+ this.ticketDataLoaded = true;
91
+ }
92
+ return this.ticketData;
93
+ }).then((response) => {
94
+ response.forEach(ticket => {
95
+ if (ticket.drawResults.length) {
96
+ ticket.drawResults.forEach(draw => {
97
+ fetch(`${this.endpoint}/games/${this.gameId}/draws/${draw.drawId}`)
98
+ .then((response) => {
99
+ return response.json();
100
+ })
101
+ .then((data) => {
102
+ // check if draw id is unique
103
+ if (!this.ticketDraws.some(el => el.drawId === draw.drawId)) {
104
+ this.ticketDraws.push({ drawId: draw.drawId, drawNumbers: data.winningNumbers });
105
+ }
106
+ });
107
+ });
108
+ }
109
+ return this.ticketDraws;
110
+ });
111
+ }).then(() => {
112
+ this.hasDrawNumbers = true;
113
+ });
114
+ };
53
115
  this.changeBox = (index) => {
54
116
  this.toggleDrawer = this.toggleDrawer.map((item, itemIndex) => {
55
117
  if (itemIndex == index) {
@@ -61,6 +123,18 @@ export class LotteryDrawResults {
61
123
  this.toggleDrawer.push(true);
62
124
  }
63
125
  };
126
+ this.setClientStyling = () => {
127
+ let sheet = document.createElement('style');
128
+ sheet.innerHTML = this.clientStyling;
129
+ this.stylingContainer.prepend(sheet);
130
+ };
131
+ this.setClientStylingURL = () => {
132
+ let cssFile = document.createElement('style');
133
+ setTimeout(() => {
134
+ cssFile.innerHTML = this.clientStylingUrlContent;
135
+ this.stylingContainer.prepend(cssFile);
136
+ }, 1);
137
+ };
64
138
  }
65
139
  connectedCallback() {
66
140
  let promises = [];
@@ -68,14 +142,28 @@ export class LotteryDrawResults {
68
142
  if (this.drawId) {
69
143
  promises.push(this.getDrawData());
70
144
  }
145
+ if (!this.drawMode) {
146
+ this.getTicketsData();
147
+ }
71
148
  Promise.all(promises)
72
149
  .then(() => {
73
150
  this.isLoading = false;
74
151
  });
75
152
  }
76
- getDrawData() {
153
+ componentDidRender() {
154
+ // start custom styling area
155
+ if (!this.limitStylingAppends && this.stylingContainer) {
156
+ if (this.clientStyling)
157
+ this.setClientStyling();
158
+ if (this.clientStylingUrlContent)
159
+ this.setClientStylingURL();
160
+ this.limitStylingAppends = true;
161
+ }
162
+ // end custom styling area
163
+ }
164
+ getDrawData(drawID) {
77
165
  return new Promise((resolve, reject) => {
78
- let url = new URL(`${this.endpoint}/games/${this.gameId}/draws/${this.drawId}`);
166
+ let url = new URL(`${this.endpoint}/games/${this.gameId}/draws/${drawID ? drawID : this.drawId}`);
79
167
  fetch(url.href)
80
168
  .then((response) => {
81
169
  // @TODO EXCEPTIONS
@@ -85,6 +173,9 @@ export class LotteryDrawResults {
85
173
  this.drawData = data;
86
174
  resolve(true);
87
175
  this.isLoading = false;
176
+ if (drawID) {
177
+ return this.drawData.winningNumbers;
178
+ }
88
179
  })
89
180
  .catch((err) => {
90
181
  reject(err);
@@ -124,105 +215,99 @@ export class LotteryDrawResults {
124
215
  h("p", null, this.errorText);
125
216
  }
126
217
  else {
127
- return (h("section", { class: "DrawResultsSection" }, !this.drawMode ?
128
- h("div", { class: "DrawResultsArea" },
129
- h("div", { class: "TicketInfo" },
130
- h("div", { class: "TicketGameName" },
131
- translate('drawName', this.language),
132
- ": ",
133
- h("span", null, this.gameName)),
134
- h("div", { class: "TicketDate" },
135
- translate('ticketPurchaseDate', this.language),
136
- ": ",
137
- h("span", null, this.ticketDate.slice(0, 10))),
138
- h("div", { class: "TicketStatus" },
139
- translate('ticketStatus', this.language),
140
- ": ",
141
- h("span", null, this.ticketStatus))),
142
- h("div", { class: "DrawResultsBody" },
143
- h("div", { class: "TicketIdContainer" },
144
- h("p", null,
145
- translate('ticketId', this.language),
218
+ return (h("section", { class: "DrawResultsSection", ref: el => this.stylingContainer = el }, this.drawMode ?
219
+ h("div", { class: "DrawResultsArea" }, this.drawData &&
220
+ h("div", null,
221
+ h("div", { class: "DrawResultsHeader" },
222
+ h("span", null,
223
+ translate('drawId', this.language),
224
+ ": ",
225
+ this.drawData.id),
226
+ h("span", null,
227
+ translate('drawDate', this.language),
146
228
  ": ",
147
- h("span", null, this.ticketId))),
148
- h("div", { class: "TicketAmountContainer" },
149
- h("p", null,
150
- translate('ticketAmount', this.language),
151
- " ",
152
- h("span", null, this.ticketAmount))),
153
- h("div", { class: "DrawNumbersGrid" },
154
- h("p", null,
155
- translate('drawNumbersGridTicket', this.language),
156
- ":"),
157
- h("div", { class: "BulletContainer" },
158
- h("lottery-grid", { "maximum-allowed": this.rules.maximumAllowed, "total-numbers": this.rules.totalNumbers, "selected-numbers": this.selection, selectable: false, "display-selected": true, language: this.language }))),
159
- h("div", { class: "DrawMultipler" },
160
- h("label", { class: "Label" },
161
- translate('winUpTo', this.language),
162
- " ",
163
- h("span", null, JSON.stringify(this.ticketMultiplier)))),
164
- h("div", { class: "NumberOfDrawsContainer" },
165
- h("p", null,
166
- translate('numberOfDraws', this.language),
167
- ": ",
168
- this.ticketDrawCount),
169
- h("div", { class: "DrawTicketsContainer" }, this.drawResults.map((item, index) => h("div", { class: "ExpandableBoxes" },
170
- h("div", { class: this.toggleDrawer[index] ? 'ExpandableBox ShowBox' : 'ExpandableBox', onClick: () => this.changeBox(index) },
171
- h("div", { class: "TicketResultContainer" },
172
- h("p", null,
173
- translate('ticketResult', this.language),
174
- ": ",
175
- item.status)),
176
- item.state == 'won' &&
177
- h("div", { class: "AmountWonContainer" },
229
+ this.drawData.date.slice(0, 10))),
230
+ h("div", { class: "DrawResultsBody" },
231
+ h("div", { class: "DrawNumbersGrid" },
232
+ h("p", null,
233
+ translate('drawNumbersGridDraw', this.language),
234
+ "0:"),
235
+ h("div", { class: "BulletContainer" },
236
+ h("lottery-grid", { "maximum-allowed": this.rules.maximumAllowed, "total-numbers": this.rules.totalNumbers, "selected-numbers": this.drawData.winningNumbers.join(','), "display-selected": true, selectable: false, language: this.language, "grid-type": 'ticket', "client-styling": this.clientStyling, "client-styling-url-content": this.clientStylingUrlContent })),
237
+ h("div", { class: "DrawMultipler" },
238
+ h("label", { class: "Label" },
239
+ translate('multiplier', this.language),
240
+ " ",
241
+ this.multiplier))))))
242
+ :
243
+ h("div", { class: "DrawResultsArea TicketDraws" },
244
+ h("div", { class: "DrawResultsBody" },
245
+ h("div", { class: "TicketIdContainer" },
246
+ h("label", { class: "Label" },
247
+ translate('ticketId', this.language),
248
+ ": ",
249
+ h("span", null, this.ticketId))),
250
+ h("div", { class: "TicketAmountContainer" },
251
+ h("label", { class: "Label" },
252
+ translate('ticketAmount', this.language),
253
+ " ",
254
+ h("span", null, this.ticketAmount))),
255
+ h("div", { class: "DrawNumbersGrid" },
256
+ h("label", { class: "Label" },
257
+ translate('drawNumbersGridTicket', this.language),
258
+ "0:"),
259
+ h("div", { class: "BulletContainer" },
260
+ h("lottery-grid", { "maximum-allowed": this.rules.maximumAllowed, "total-numbers": this.rules.totalNumbers, "selected-numbers": JSON.parse(this.ticketNumbers).join(','), selectable: false, "display-selected": true, language: this.language, "grid-type": 'ticket', "client-styling": this.clientStyling, "client-styling-url-content": this.clientStylingUrlContent }))),
261
+ h("div", { class: "DrawMultipler" },
262
+ h("label", { class: "Label" },
263
+ translate('multiplier', this.language),
264
+ " ",
265
+ JSON.stringify(this.ticketMultiplier))),
266
+ h("div", { class: "NumberOfDrawsContainer" },
267
+ h("label", { class: "Label" },
268
+ translate('numberOfDraws', this.language),
269
+ ": ",
270
+ this.ticketDrawCount),
271
+ h("div", { class: "DrawTicketsContainer" }, this.ticketData.map((ticket) => h("div", { class: "ExpandableBoxes" }, ticket.drawResults.length ?
272
+ h("div", null, ticket.id == this.ticketId && ticket.drawResults.map((item, index) => h("div", { class: this.toggleDrawer[index] ? 'ExpandableBox ShowBox' : 'ExpandableBox', onClick: () => this.changeBox(index) },
273
+ h("div", { class: "TicketResultContainer" },
274
+ h("p", null,
275
+ translate('ticketResult', this.language),
276
+ ": ",
277
+ item.state)),
278
+ item.state == 'won' &&
279
+ h("div", { class: "AmountWonContainer" },
280
+ h("p", null,
281
+ translate('amountWon', this.language),
282
+ ": ",
283
+ Number(item.amount).toLocaleString('en'),
284
+ " ",
285
+ item.currency)),
286
+ h("div", { class: "DrawIdContainer" },
287
+ h("p", null,
288
+ translate('drawId', this.language),
289
+ ": ",
290
+ item.drawId)),
291
+ h("div", { class: "DrawDateContainer" },
178
292
  h("p", null,
179
- translate('amountWon', this.language),
293
+ translate('drawDate', this.language),
180
294
  ": ",
181
- Number(item.amount).toLocaleString('en'),
295
+ item.updatedAt.slice(0, 10),
296
+ " | ",
297
+ item.updatedAt.slice(11, 19))),
298
+ h("div", { class: "DrawNumbersGrid" }, this.hasDrawNumbers && this.ticketDraws.map((ticketDraw) => item.drawId && item.drawId === ticketDraw.drawId &&
299
+ h("div", null,
300
+ h("label", { class: "Label" },
301
+ translate('drawNumbersGridDraw', this.language),
302
+ "A:"),
303
+ h("lottery-grid", { "maximum-allowed": this.rules.maximumAllowed, "total-numbers": this.rules.totalNumbers, "selected-numbers": ticketDraw.drawNumbers.join(','), selectable: false, "display-selected": true, language: this.language, "grid-type": 'ticket', "client-styling": this.clientStyling, "client-styling-url-content": this.clientStylingUrlContent })))),
304
+ h("div", { class: "DrawMultipler" },
305
+ h("label", { class: "Label" },
306
+ translate('multiplier', this.language),
182
307
  " ",
183
- item.currency)),
184
- h("div", { class: "DrawIdContainer" },
185
- h("p", null,
186
- translate('drawId', this.language),
187
- ": ",
188
- item.drawId)),
189
- h("div", { class: "DrawDateContainer" },
190
- h("p", null,
191
- translate('drawDate', this.language),
192
- ": ",
193
- item.updatedAt.slice(0, 10),
194
- " | ",
195
- item.updatedAt.slice(11, 19))),
196
- h("div", { class: "DrawNumbersGrid" }),
197
- h("div", { class: "DrawMultipler" },
198
- h("label", { class: "Label" },
199
- translate('winUpTo', this.language),
200
- " ",
201
- item.multiplier)))))))))
202
- :
203
- h("div", { class: "DrawResultsArea" }, this.drawData &&
204
- h("div", null,
205
- h("div", { class: "DrawResultsHeader" },
206
- h("span", null,
207
- translate('drawId', this.language),
208
- ": ",
209
- this.drawData.id),
210
- h("span", null,
211
- translate('drawDate', this.language),
212
- ": ",
213
- this.drawData.date.slice(0, 10))),
214
- h("div", { class: "DrawResultsBody" },
215
- h("div", { class: "DrawNumbersGrid" },
216
- h("p", null,
217
- translate('drawNumbersGridDraw', this.language),
218
- ":"),
219
- h("div", { class: "BulletContainer" },
220
- h("lottery-grid", { "maximum-allowed": this.rules.maximumAllowed, "total-numbers": this.rules.totalNumbers, selectedNumbers: this.drawData.winningNumbers.join(','), "display-selected": true, selectable: false, language: this.language })),
221
- h("div", { class: "DrawMultipler" },
222
- h("label", { class: "Label" },
223
- translate('multiplier', this.language),
224
- " ",
225
- this.multiplier))))))));
308
+ item.multiplier)))))
309
+ :
310
+ h("span", null)))))))));
226
311
  }
227
312
  }
228
313
  static get is() { return "lottery-draw-results"; }
@@ -464,15 +549,91 @@ export class LotteryDrawResults {
464
549
  "attribute": "ticket-draw-count",
465
550
  "reflect": false,
466
551
  "defaultValue": "0"
552
+ },
553
+ "ticketNumbers": {
554
+ "type": "string",
555
+ "mutable": false,
556
+ "complexType": {
557
+ "original": "string",
558
+ "resolved": "string",
559
+ "references": {}
560
+ },
561
+ "required": false,
562
+ "optional": false,
563
+ "docs": {
564
+ "tags": [],
565
+ "text": "The ticket winning numbers"
566
+ },
567
+ "attribute": "ticket-numbers",
568
+ "reflect": false,
569
+ "defaultValue": "''"
570
+ },
571
+ "sessionId": {
572
+ "type": "string",
573
+ "mutable": false,
574
+ "complexType": {
575
+ "original": "string",
576
+ "resolved": "string",
577
+ "references": {}
578
+ },
579
+ "required": false,
580
+ "optional": false,
581
+ "docs": {
582
+ "tags": [],
583
+ "text": "The session id"
584
+ },
585
+ "attribute": "session-id",
586
+ "reflect": false,
587
+ "defaultValue": "''"
588
+ },
589
+ "clientStyling": {
590
+ "type": "string",
591
+ "mutable": false,
592
+ "complexType": {
593
+ "original": "string",
594
+ "resolved": "string",
595
+ "references": {}
596
+ },
597
+ "required": false,
598
+ "optional": false,
599
+ "docs": {
600
+ "tags": [],
601
+ "text": "Client custom styling via string"
602
+ },
603
+ "attribute": "client-styling",
604
+ "reflect": false,
605
+ "defaultValue": "''"
606
+ },
607
+ "clientStylingUrlContent": {
608
+ "type": "string",
609
+ "mutable": false,
610
+ "complexType": {
611
+ "original": "string",
612
+ "resolved": "string",
613
+ "references": {}
614
+ },
615
+ "required": false,
616
+ "optional": false,
617
+ "docs": {
618
+ "tags": [],
619
+ "text": "Client custom styling via url content"
620
+ },
621
+ "attribute": "client-styling-url-content",
622
+ "reflect": false,
623
+ "defaultValue": "''"
467
624
  }
468
625
  }; }
469
626
  static get states() { return {
470
627
  "multiplier": {},
471
628
  "isLoading": {},
472
- "drawResults": {},
473
629
  "rules": {},
474
630
  "toggleDrawer": {},
475
631
  "hasErrors": {},
476
- "errorText": {}
632
+ "errorText": {},
633
+ "ticketData": {},
634
+ "ticketDataLoaded": {},
635
+ "ticketDraws": {},
636
+ "hasDrawNumbers": {},
637
+ "limitStylingAppends": {}
477
638
  }; }
478
639
  }
@@ -6,8 +6,8 @@ const TRANSLATIONS = {
6
6
  drawId: 'Draw ID',
7
7
  drawName: 'Game name',
8
8
  drawDate: 'Draw Date',
9
- drawNumbersGridDraw: 'Draw numbers Grid A',
10
- drawNumbersGridTicket: 'Draw numbers Grid B',
9
+ drawNumbersGridDraw: 'Draw numbers Grid ',
10
+ drawNumbersGridTicket: 'Draw numbers Grid ',
11
11
  ticketResult: 'Ticket result',
12
12
  amountWon: 'Amount won',
13
13
  numberOfDraws: 'Number of draws',
@@ -23,8 +23,8 @@ const TRANSLATIONS = {
23
23
  drawId: 'Id extragere',
24
24
  drawName: 'Numele jocului',
25
25
  drawDate: 'Data extragerii',
26
- drawNumbersGridDraw: 'Numerele extrase Grid A',
27
- drawNumbersGridTicket: 'Numerele extrase Grid B',
26
+ drawNumbersGridDraw: 'Numerele extrase Grid',
27
+ drawNumbersGridTicket: 'Numerele extrase Grid',
28
28
  ticketResult: 'Rezultatul biletului',
29
29
  amountWon: 'Suma castigata',
30
30
  numberOfDraws: 'Numarul de extrageri',