@everymatrix/casino-tournaments-controller 0.0.367 → 0.0.368
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.
- package/.eslintrc +84 -84
- package/dist/casino-tournaments-controller.js +1 -1
- package/dist/casino-tournaments-controller.js.map +1 -1
- package/documentation.md +170 -170
- package/index.html +29 -29
- package/index.js +1 -1
- package/package.json +2 -2
- package/public/reset.css +47 -47
- package/rollup.config.js +67 -67
- package/src/CasinoTournamentsController.svelte +427 -427
- package/src/i18n.js +27 -27
- package/src/index.ts +4 -4
- package/src/translations.js +101 -101
- package/stories/CasinoTournamentsController.stories.js +13 -13
- package/tsconfig.json +6 -6
|
@@ -1,427 +1,427 @@
|
|
|
1
|
-
<svelte:options tag={null} />
|
|
2
|
-
|
|
3
|
-
<script lang="ts">
|
|
4
|
-
import { onMount } from 'svelte';
|
|
5
|
-
import { getDevice } from 'rvhelper';
|
|
6
|
-
import { _, addNewMessages, setLocale, setupI18n } from './i18n';
|
|
7
|
-
import { TournamentsControllerTranslations } from './translations';
|
|
8
|
-
import { EventSourcePolyfill } from 'event-source-polyfill';
|
|
9
|
-
|
|
10
|
-
import '@everymatrix/casino-tournaments-filter-controller';
|
|
11
|
-
import '@everymatrix/casino-tournaments-list-controller';
|
|
12
|
-
|
|
13
|
-
// endpoint for NorWAy
|
|
14
|
-
export let session:string = '';
|
|
15
|
-
export let userid:string = '';
|
|
16
|
-
export let endpoint:string = '';
|
|
17
|
-
export let lang:string = 'en';
|
|
18
|
-
// number of default tournaments shown
|
|
19
|
-
export let numberoftournaments:string = '6';
|
|
20
|
-
// number of added elements to the list when showmore is clicked
|
|
21
|
-
export let showmorestep:string = '2';
|
|
22
|
-
export let filters:string = 'All';
|
|
23
|
-
export let loginevent:string = '';
|
|
24
|
-
export let registerevent:string = '';
|
|
25
|
-
export let loginurl:string = '';
|
|
26
|
-
export let registerurl:string = '';
|
|
27
|
-
export let currency:string = 'EUR';
|
|
28
|
-
export let containermaxwidth:string = '';
|
|
29
|
-
export let keepbrowsercontext:string = 'false';
|
|
30
|
-
export let sorttype: string = '';
|
|
31
|
-
|
|
32
|
-
// Variables of topics for communication
|
|
33
|
-
let hasErrors:boolean = false;
|
|
34
|
-
let error:string = '';
|
|
35
|
-
let isLoggedIn:boolean = false;
|
|
36
|
-
let sessionID:string = '';
|
|
37
|
-
let playerID:string = '';
|
|
38
|
-
let userAgent:string = window.navigator.userAgent;
|
|
39
|
-
let isLoading:boolean = true;
|
|
40
|
-
let filtersLoaded:boolean = false;
|
|
41
|
-
let startingTournamentUpdater:boolean = false;
|
|
42
|
-
|
|
43
|
-
let filtersArray = 'All,Scheduled,Ongoing,Finished';
|
|
44
|
-
let tournamentsNumber:number = 0;
|
|
45
|
-
|
|
46
|
-
// Default state
|
|
47
|
-
let tournamentsShownNumber:number = 6;
|
|
48
|
-
let allTournamentsShown:boolean = true;
|
|
49
|
-
let activeFilters:Array<string> = [];
|
|
50
|
-
|
|
51
|
-
let lastMonthDate:any = new Date();
|
|
52
|
-
let tournamentsSearchParams:string;
|
|
53
|
-
let tournamentsUpdateEventSource:any;
|
|
54
|
-
|
|
55
|
-
lastMonthDate.setMonth(lastMonthDate.getMonth() - 1);
|
|
56
|
-
lastMonthDate = lastMonthDate.toISOString().substring(0, 10);
|
|
57
|
-
|
|
58
|
-
setupI18n({ withLocale: 'en', translations: {}});
|
|
59
|
-
|
|
60
|
-
Object.keys(TournamentsControllerTranslations).forEach((item:any) => {
|
|
61
|
-
addNewMessages(item, TournamentsControllerTranslations[item]);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
const messageHandler = (e:any) => {
|
|
65
|
-
if (e.data && e.data.type === 'UserSessionID') {
|
|
66
|
-
isLoggedIn = true;
|
|
67
|
-
sessionID = e.data.session;
|
|
68
|
-
playerID = e.data.userid;
|
|
69
|
-
|
|
70
|
-
getData(endpoint, 0, tournamentsShownNumber);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (e.data && e.data.type === 'TournamentsFiltersSelected') {
|
|
74
|
-
activeFilters = e.data.filters;
|
|
75
|
-
|
|
76
|
-
getData(endpoint, 0, tournamentsShownNumber);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const matchStatus = (status:string) => {
|
|
81
|
-
if (status == 'Scheduled') {
|
|
82
|
-
return 'Unstarted';
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (status == 'Ongoing') {
|
|
86
|
-
return 'Running';
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return 'Closing|Closed';
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const getData = async (url:string, offset:number, limit:number) => {
|
|
93
|
-
isLoading = true;
|
|
94
|
-
tournamentsNumber = 0;
|
|
95
|
-
|
|
96
|
-
const res = await fetcher(url, offset, limit)
|
|
97
|
-
|
|
98
|
-
setTimeout(() => {
|
|
99
|
-
window.postMessage({ type: 'TournamentList', tournamentList: res.items }, window.location.href);
|
|
100
|
-
}, 50)
|
|
101
|
-
|
|
102
|
-
isLoading = false;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const getDataWithoutfresh = async (url:string, offset:number, limit:number) => {
|
|
106
|
-
const res = await fetcher(url, offset, limit)
|
|
107
|
-
|
|
108
|
-
window.postMessage({ type: 'TournamentListShowMore', tournamentList: res.items }, window.location.href);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const fetcher = async (url:string, offset:number, limit:number) => {
|
|
112
|
-
|
|
113
|
-
let tournamentsUrl:URL = new URL(`${url}/tournaments`);
|
|
114
|
-
let reqHeaders:Headers = new Headers();
|
|
115
|
-
|
|
116
|
-
tournamentsUrl.searchParams.append('pagination', `offset=${offset},limit=${limit}`);
|
|
117
|
-
tournamentsUrl.searchParams.append('sortField', 'StartTime');
|
|
118
|
-
tournamentsUrl.searchParams.append('sortOrder', 'desc');
|
|
119
|
-
tournamentsUrl.searchParams.append('language', lang);
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (activeFilters.length > 0 && activeFilters[0] != 'All') {
|
|
123
|
-
let state = activeFilters.map((item:any) => matchStatus(item)).join("|");
|
|
124
|
-
|
|
125
|
-
tournamentsUrl.searchParams.append('filter', `state=${state},StartTimeAfter=${lastMonthDate}`);
|
|
126
|
-
} else {
|
|
127
|
-
tournamentsUrl.searchParams.append('filter', `StartTimeAfter=${lastMonthDate}`);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
tournamentsUrl.searchParams.append('platform', getDevice(userAgent));
|
|
131
|
-
|
|
132
|
-
if(sorttype){
|
|
133
|
-
tournamentsUrl.searchParams.append('sortType', sorttype);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (isLoggedIn) {
|
|
137
|
-
reqHeaders.append("X-SessionID", sessionID);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
let requestOptions = {
|
|
141
|
-
method: 'GET',
|
|
142
|
-
headers: reqHeaders,
|
|
143
|
-
cache: 'no-cache'
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
return fetch(tournamentsUrl, requestOptions)
|
|
147
|
-
.then((res:any) => res.json())
|
|
148
|
-
.then((res:any) => {
|
|
149
|
-
tournamentsSearchParams = tournamentsUrl.searchParams.toString();
|
|
150
|
-
|
|
151
|
-
tournamentsNumber = res.total;
|
|
152
|
-
|
|
153
|
-
if (tournamentsShownNumber >= tournamentsNumber) {
|
|
154
|
-
allTournamentsShown = true;
|
|
155
|
-
} else {
|
|
156
|
-
allTournamentsShown = false;
|
|
157
|
-
}
|
|
158
|
-
if(!startingTournamentUpdater){
|
|
159
|
-
startupTouramentDataChangeListener();
|
|
160
|
-
}
|
|
161
|
-
return res
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
const tournamentsUpdateMessageHandler = (message: any)=>{
|
|
165
|
-
if(message.type != 'message'){
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
let messageData = message.data;
|
|
169
|
-
if(messageData){
|
|
170
|
-
try{
|
|
171
|
-
let updateTourData = JSON.parse(messageData);
|
|
172
|
-
if(!updateTourData || !updateTourData.item){
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
let updateInfo = updateTourData.item;
|
|
176
|
-
if(updateTourData.messageType == "TournamentUpdate"){
|
|
177
|
-
window.postMessage({type: 'UpdateTournamentView', tournamentData: updateInfo}, window.location.href);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if(updateTourData.messageType == 'TournamentRemove'){
|
|
181
|
-
//remove tournament from TournamentList by id
|
|
182
|
-
window.postMessage({ type: 'TournamentList', tournamentList: updateTourData.items }, window.location.href);
|
|
183
|
-
}
|
|
184
|
-
}catch(err){
|
|
185
|
-
console.error(err);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
const startupTouramentDataChangeListener = ()=>{
|
|
190
|
-
startingTournamentUpdater = true;
|
|
191
|
-
setTimeout(()=>{
|
|
192
|
-
startingTournamentUpdater = false;//to make sure only one eventsource work at the same time when query parameter changed
|
|
193
|
-
}, 1000)
|
|
194
|
-
if(tournamentsUpdateEventSource){
|
|
195
|
-
tournamentsUpdateEventSource.removeEventListener('message', tournamentsUpdateMessageHandler);
|
|
196
|
-
tournamentsUpdateEventSource.close();
|
|
197
|
-
}
|
|
198
|
-
let endpointURL:String = `${endpoint}/tournaments/updates?${tournamentsSearchParams}&XSessionId=${session}`;
|
|
199
|
-
if(!EventSource){
|
|
200
|
-
tournamentsUpdateEventSource = new EventSourcePolyfill(endpointURL, {headers: {'accept': 'text/event-stream'}});
|
|
201
|
-
}else{
|
|
202
|
-
tournamentsUpdateEventSource = new EventSource(endpointURL);
|
|
203
|
-
}
|
|
204
|
-
if(typeof(tournamentsUpdateEventSource) != "undefined"){
|
|
205
|
-
tournamentsUpdateEventSource.addEventListener('message', tournamentsUpdateMessageHandler);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const showMoreAction = async () => {
|
|
210
|
-
let previousNumber = tournamentsShownNumber
|
|
211
|
-
|
|
212
|
-
const _showmorestep = parseInt(showmorestep, 10);
|
|
213
|
-
tournamentsShownNumber += _showmorestep
|
|
214
|
-
|
|
215
|
-
window.postMessage({ type: 'TournamentsPagination', offset: 0, limit: tournamentsShownNumber }, window.location.href);
|
|
216
|
-
|
|
217
|
-
await getDataWithoutfresh(endpoint, previousNumber, _showmorestep)
|
|
218
|
-
|
|
219
|
-
if (tournamentsShownNumber >= tournamentsNumber) {
|
|
220
|
-
allTournamentsShown = true;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
const checkAttrs = () => {
|
|
225
|
-
if (!endpoint) {
|
|
226
|
-
error = "Endpoint is missing! Please provide a valid endpointURL.";
|
|
227
|
-
hasErrors = true;
|
|
228
|
-
|
|
229
|
-
console.error(error);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (!lang || lang.length != 2) {
|
|
233
|
-
error = "Language is missing! Please provide a valid language (alpha2code)";
|
|
234
|
-
hasErrors = true;
|
|
235
|
-
|
|
236
|
-
console.error(error);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
return hasErrors;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const initialLoad = () => {
|
|
243
|
-
if (!checkAttrs()) {
|
|
244
|
-
tournamentsShownNumber = parseInt(numberoftournaments, 10);
|
|
245
|
-
|
|
246
|
-
setLocale(lang);
|
|
247
|
-
|
|
248
|
-
getData(endpoint, 0, tournamentsShownNumber);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const setActiveLanguage = ():void => {
|
|
253
|
-
setLocale(lang);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
const setActiveFilters = () => {
|
|
257
|
-
activeFilters = filters.split(',');
|
|
258
|
-
filtersLoaded = true;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
const setSession = () => {
|
|
262
|
-
if (session.length > 0 && session != 'false') {
|
|
263
|
-
isLoggedIn = true;
|
|
264
|
-
isLoading = true;
|
|
265
|
-
sessionID = session;
|
|
266
|
-
} else {
|
|
267
|
-
isLoggedIn = false;
|
|
268
|
-
initialLoad();
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
const setPlayerID = () => {
|
|
273
|
-
playerID = userid;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
onMount(() => {
|
|
277
|
-
window.addEventListener('message', messageHandler, false);
|
|
278
|
-
return () => {
|
|
279
|
-
window.removeEventListener('message', messageHandler);
|
|
280
|
-
if(tournamentsUpdateEventSource){
|
|
281
|
-
tournamentsUpdateEventSource.removeEventListener('message', tournamentsUpdateMessageHandler);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
$: session && setSession();
|
|
287
|
-
$: userid && setPlayerID();
|
|
288
|
-
$: lang && setLocale(lang);
|
|
289
|
-
$: filters && setActiveFilters();
|
|
290
|
-
$: lang && setActiveLanguage();
|
|
291
|
-
$: initialParameters = endpoint && numberoftournaments && showmorestep && lang;
|
|
292
|
-
$: readyToLoad = session ? initialParameters && session : initialParameters;
|
|
293
|
-
$: readyToLoad && initialLoad();
|
|
294
|
-
</script>
|
|
295
|
-
|
|
296
|
-
{#if hasErrors}
|
|
297
|
-
<p>{$_('tournamentsController.500')}</p>
|
|
298
|
-
<p>{error}</p>
|
|
299
|
-
{:else}
|
|
300
|
-
<div class="TournamentsWrapper" part="TournamentsWrapper">
|
|
301
|
-
<div class="Tournaments" style="max-width: {containermaxwidth}px;" part="Tournaments">
|
|
302
|
-
<div class="FirstRow" part="FirstRow">
|
|
303
|
-
{#if filtersLoaded}
|
|
304
|
-
<casino-tournaments-filter-controller
|
|
305
|
-
filters={filtersArray}
|
|
306
|
-
activefilters={filters}
|
|
307
|
-
exportparts="FiltersController, MobileClass, Non-MobileClass/empty, Active, FilterButton, bi, bi-check, FiltersList, FiltersTitle, FiltersItem"
|
|
308
|
-
></casino-tournaments-filter-controller>
|
|
309
|
-
{/if}
|
|
310
|
-
</div>
|
|
311
|
-
<div class="SecondRow" part="SecondRow">
|
|
312
|
-
{#if tournamentsNumber == 0}
|
|
313
|
-
{#if isLoading}
|
|
314
|
-
<p class="LoadingMessage" part="LoadingMessage">{$_('tournamentsController.loading')}</p>
|
|
315
|
-
{:else}
|
|
316
|
-
<p class="NoTournaments" part="NoTournaments">{$_('tournamentsController.noTournaments')}</p>
|
|
317
|
-
{/if}
|
|
318
|
-
{:else}
|
|
319
|
-
<casino-tournaments-list-controller
|
|
320
|
-
session={session}
|
|
321
|
-
userid={userid}
|
|
322
|
-
numberoftournaments={numberoftournaments}
|
|
323
|
-
endpoint={endpoint}
|
|
324
|
-
loginurl={loginurl}
|
|
325
|
-
loginevent={loginevent}
|
|
326
|
-
registerurl={registerurl}
|
|
327
|
-
registerevent={registerevent}
|
|
328
|
-
{lang}
|
|
329
|
-
{currency}
|
|
330
|
-
{keepbrowsercontext}
|
|
331
|
-
exportparts="Thumbnail, Status, Enrolled, CardImg, CardImgFinished, Details, Title, Date, ScoreCriteria, ScoreCriteriaP, ScoreCriteriaSpan, Games, GamesP, GamesAnchor, TournamentPrizes, TournamentPrizesSvg, a, TournamentPrizesSvgA, PrizesTitle, Prizes, Prize, PrizeText, PrizeRank,
|
|
332
|
-
TournamentDuration, TournamentDates, StartDate, EndDate, ProgressBar, ProgressBarFillEnd, Finished, ProgressBarFillStarting, Remaining, ProgressBarFill,
|
|
333
|
-
TournamentsGamesSlider, SliderNavButton, items, item, PlayNowButton, itemHover, SliderNavButton
|
|
334
|
-
TournamentCard, CardMaxWidth, CardFullSize, elementToFadeOut, elementToFadeIn, ph-item, ph-col-12, ph-picture, ph-row, ph-col-6, big, ph-col-4, empty, ph-col-8, TournamentButtons, LoginButton, RegisterButton, DetailsButton, EnrolledButton, JoinButton, JoinButtonSpan, JoinButtonSvg, JoinButtonSvgA, JoinButtonFullSize, spinner, DetailsLargeButton, ErrorText, TournamentList, StatusUnstarted, StatusRunning, StatusClosed, StatusClosing, TournamentPrizesIconSection, TournamentPrizesIconWrapper"
|
|
335
|
-
></casino-tournaments-list-controller>
|
|
336
|
-
{/if}
|
|
337
|
-
</div>
|
|
338
|
-
{#if !allTournamentsShown}
|
|
339
|
-
<div class="ThirdRow" part="ThirdRow">
|
|
340
|
-
<div class="CenterButton" part="CenterButton">
|
|
341
|
-
<button class="ShowMoreButton" part="ShowMoreButton" on:click="{() => showMoreAction()}" title="Show More">{$_('tournamentsController.showMore')}</button>
|
|
342
|
-
</div>
|
|
343
|
-
</div>
|
|
344
|
-
{/if}
|
|
345
|
-
</div>
|
|
346
|
-
</div>
|
|
347
|
-
{/if}
|
|
348
|
-
|
|
349
|
-
<style lang="scss">
|
|
350
|
-
$primary-background-color: var(--emfe-w-color-contrast, #07072A);
|
|
351
|
-
$font-stack: "Helvetica Neue", "Helvetica", sans-serif;
|
|
352
|
-
$primary-font-color: var(--emfe-w-color-white, #FFFFFF);
|
|
353
|
-
$primary-font-size: 1rem;
|
|
354
|
-
|
|
355
|
-
:host {
|
|
356
|
-
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
*,
|
|
360
|
-
*::before,
|
|
361
|
-
*::after {
|
|
362
|
-
margin: 0;
|
|
363
|
-
padding: 0;
|
|
364
|
-
list-style: none;
|
|
365
|
-
text-decoration: none;
|
|
366
|
-
outline: none;
|
|
367
|
-
box-sizing: border-box;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
.ShowMoreButton {
|
|
371
|
-
background: var(--emfe-w-color-contrast, #07072A);
|
|
372
|
-
font-size: 18px;
|
|
373
|
-
width: 280px;
|
|
374
|
-
height: 60px;
|
|
375
|
-
text-align: center;
|
|
376
|
-
color: var(--emfe-w-color-green, #48952a);
|
|
377
|
-
border: solid var(--emfe-w-color-green, #48952a) 1px;
|
|
378
|
-
text-transform: uppercase;
|
|
379
|
-
margin-bottom: 20px;
|
|
380
|
-
cursor: pointer;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
.ShowMoreButton:hover {
|
|
384
|
-
opacity: 0.7;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
.TournamentsWrapper {
|
|
388
|
-
background: $primary-background-color;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
.Tournaments {
|
|
392
|
-
color: $primary-font-color;
|
|
393
|
-
display: flex;
|
|
394
|
-
flex-direction: column;
|
|
395
|
-
position: relative;
|
|
396
|
-
margin: 0 auto;
|
|
397
|
-
padding: 24px 0;
|
|
398
|
-
|
|
399
|
-
@media screen and (max-width: 1300px) {
|
|
400
|
-
padding: 24px 2.4%;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
.FirstRow {
|
|
404
|
-
width: 100%;
|
|
405
|
-
margin: 0 auto;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
.SecondRow {
|
|
409
|
-
margin: 0 auto;
|
|
410
|
-
width: 100%;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
.ThirdRow {
|
|
414
|
-
display: flex;
|
|
415
|
-
flex-direction: column;
|
|
416
|
-
justify-content: center;
|
|
417
|
-
|
|
418
|
-
.CenterButton {
|
|
419
|
-
padding-top: 20px;
|
|
420
|
-
width: 100%;
|
|
421
|
-
display: flex;
|
|
422
|
-
justify-content: center;
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
</style>
|
|
1
|
+
<svelte:options tag={null} />
|
|
2
|
+
|
|
3
|
+
<script lang="ts">
|
|
4
|
+
import { onMount } from 'svelte';
|
|
5
|
+
import { getDevice } from 'rvhelper';
|
|
6
|
+
import { _, addNewMessages, setLocale, setupI18n } from './i18n';
|
|
7
|
+
import { TournamentsControllerTranslations } from './translations';
|
|
8
|
+
import { EventSourcePolyfill } from 'event-source-polyfill';
|
|
9
|
+
|
|
10
|
+
import '@everymatrix/casino-tournaments-filter-controller';
|
|
11
|
+
import '@everymatrix/casino-tournaments-list-controller';
|
|
12
|
+
|
|
13
|
+
// endpoint for NorWAy
|
|
14
|
+
export let session:string = '';
|
|
15
|
+
export let userid:string = '';
|
|
16
|
+
export let endpoint:string = '';
|
|
17
|
+
export let lang:string = 'en';
|
|
18
|
+
// number of default tournaments shown
|
|
19
|
+
export let numberoftournaments:string = '6';
|
|
20
|
+
// number of added elements to the list when showmore is clicked
|
|
21
|
+
export let showmorestep:string = '2';
|
|
22
|
+
export let filters:string = 'All';
|
|
23
|
+
export let loginevent:string = '';
|
|
24
|
+
export let registerevent:string = '';
|
|
25
|
+
export let loginurl:string = '';
|
|
26
|
+
export let registerurl:string = '';
|
|
27
|
+
export let currency:string = 'EUR';
|
|
28
|
+
export let containermaxwidth:string = '';
|
|
29
|
+
export let keepbrowsercontext:string = 'false';
|
|
30
|
+
export let sorttype: string = '';
|
|
31
|
+
|
|
32
|
+
// Variables of topics for communication
|
|
33
|
+
let hasErrors:boolean = false;
|
|
34
|
+
let error:string = '';
|
|
35
|
+
let isLoggedIn:boolean = false;
|
|
36
|
+
let sessionID:string = '';
|
|
37
|
+
let playerID:string = '';
|
|
38
|
+
let userAgent:string = window.navigator.userAgent;
|
|
39
|
+
let isLoading:boolean = true;
|
|
40
|
+
let filtersLoaded:boolean = false;
|
|
41
|
+
let startingTournamentUpdater:boolean = false;
|
|
42
|
+
|
|
43
|
+
let filtersArray = 'All,Scheduled,Ongoing,Finished';
|
|
44
|
+
let tournamentsNumber:number = 0;
|
|
45
|
+
|
|
46
|
+
// Default state
|
|
47
|
+
let tournamentsShownNumber:number = 6;
|
|
48
|
+
let allTournamentsShown:boolean = true;
|
|
49
|
+
let activeFilters:Array<string> = [];
|
|
50
|
+
|
|
51
|
+
let lastMonthDate:any = new Date();
|
|
52
|
+
let tournamentsSearchParams:string;
|
|
53
|
+
let tournamentsUpdateEventSource:any;
|
|
54
|
+
|
|
55
|
+
lastMonthDate.setMonth(lastMonthDate.getMonth() - 1);
|
|
56
|
+
lastMonthDate = lastMonthDate.toISOString().substring(0, 10);
|
|
57
|
+
|
|
58
|
+
setupI18n({ withLocale: 'en', translations: {}});
|
|
59
|
+
|
|
60
|
+
Object.keys(TournamentsControllerTranslations).forEach((item:any) => {
|
|
61
|
+
addNewMessages(item, TournamentsControllerTranslations[item]);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const messageHandler = (e:any) => {
|
|
65
|
+
if (e.data && e.data.type === 'UserSessionID') {
|
|
66
|
+
isLoggedIn = true;
|
|
67
|
+
sessionID = e.data.session;
|
|
68
|
+
playerID = e.data.userid;
|
|
69
|
+
|
|
70
|
+
getData(endpoint, 0, tournamentsShownNumber);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (e.data && e.data.type === 'TournamentsFiltersSelected') {
|
|
74
|
+
activeFilters = e.data.filters;
|
|
75
|
+
|
|
76
|
+
getData(endpoint, 0, tournamentsShownNumber);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const matchStatus = (status:string) => {
|
|
81
|
+
if (status == 'Scheduled') {
|
|
82
|
+
return 'Unstarted';
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (status == 'Ongoing') {
|
|
86
|
+
return 'Running';
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return 'Closing|Closed';
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const getData = async (url:string, offset:number, limit:number) => {
|
|
93
|
+
isLoading = true;
|
|
94
|
+
tournamentsNumber = 0;
|
|
95
|
+
|
|
96
|
+
const res = await fetcher(url, offset, limit)
|
|
97
|
+
|
|
98
|
+
setTimeout(() => {
|
|
99
|
+
window.postMessage({ type: 'TournamentList', tournamentList: res.items }, window.location.href);
|
|
100
|
+
}, 50)
|
|
101
|
+
|
|
102
|
+
isLoading = false;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const getDataWithoutfresh = async (url:string, offset:number, limit:number) => {
|
|
106
|
+
const res = await fetcher(url, offset, limit)
|
|
107
|
+
|
|
108
|
+
window.postMessage({ type: 'TournamentListShowMore', tournamentList: res.items }, window.location.href);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const fetcher = async (url:string, offset:number, limit:number) => {
|
|
112
|
+
|
|
113
|
+
let tournamentsUrl:URL = new URL(`${url}/tournaments`);
|
|
114
|
+
let reqHeaders:Headers = new Headers();
|
|
115
|
+
|
|
116
|
+
tournamentsUrl.searchParams.append('pagination', `offset=${offset},limit=${limit}`);
|
|
117
|
+
tournamentsUrl.searchParams.append('sortField', 'StartTime');
|
|
118
|
+
tournamentsUrl.searchParams.append('sortOrder', 'desc');
|
|
119
|
+
tournamentsUrl.searchParams.append('language', lang);
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
if (activeFilters.length > 0 && activeFilters[0] != 'All') {
|
|
123
|
+
let state = activeFilters.map((item:any) => matchStatus(item)).join("|");
|
|
124
|
+
|
|
125
|
+
tournamentsUrl.searchParams.append('filter', `state=${state},StartTimeAfter=${lastMonthDate}`);
|
|
126
|
+
} else {
|
|
127
|
+
tournamentsUrl.searchParams.append('filter', `StartTimeAfter=${lastMonthDate}`);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
tournamentsUrl.searchParams.append('platform', getDevice(userAgent));
|
|
131
|
+
|
|
132
|
+
if(sorttype){
|
|
133
|
+
tournamentsUrl.searchParams.append('sortType', sorttype);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (isLoggedIn) {
|
|
137
|
+
reqHeaders.append("X-SessionID", sessionID);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
let requestOptions = {
|
|
141
|
+
method: 'GET',
|
|
142
|
+
headers: reqHeaders,
|
|
143
|
+
cache: 'no-cache'
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
return fetch(tournamentsUrl, requestOptions)
|
|
147
|
+
.then((res:any) => res.json())
|
|
148
|
+
.then((res:any) => {
|
|
149
|
+
tournamentsSearchParams = tournamentsUrl.searchParams.toString();
|
|
150
|
+
|
|
151
|
+
tournamentsNumber = res.total;
|
|
152
|
+
|
|
153
|
+
if (tournamentsShownNumber >= tournamentsNumber) {
|
|
154
|
+
allTournamentsShown = true;
|
|
155
|
+
} else {
|
|
156
|
+
allTournamentsShown = false;
|
|
157
|
+
}
|
|
158
|
+
if(!startingTournamentUpdater){
|
|
159
|
+
startupTouramentDataChangeListener();
|
|
160
|
+
}
|
|
161
|
+
return res
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
const tournamentsUpdateMessageHandler = (message: any)=>{
|
|
165
|
+
if(message.type != 'message'){
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
let messageData = message.data;
|
|
169
|
+
if(messageData){
|
|
170
|
+
try{
|
|
171
|
+
let updateTourData = JSON.parse(messageData);
|
|
172
|
+
if(!updateTourData || !updateTourData.item){
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
let updateInfo = updateTourData.item;
|
|
176
|
+
if(updateTourData.messageType == "TournamentUpdate"){
|
|
177
|
+
window.postMessage({type: 'UpdateTournamentView', tournamentData: updateInfo}, window.location.href);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if(updateTourData.messageType == 'TournamentRemove'){
|
|
181
|
+
//remove tournament from TournamentList by id
|
|
182
|
+
window.postMessage({ type: 'TournamentList', tournamentList: updateTourData.items }, window.location.href);
|
|
183
|
+
}
|
|
184
|
+
}catch(err){
|
|
185
|
+
console.error(err);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const startupTouramentDataChangeListener = ()=>{
|
|
190
|
+
startingTournamentUpdater = true;
|
|
191
|
+
setTimeout(()=>{
|
|
192
|
+
startingTournamentUpdater = false;//to make sure only one eventsource work at the same time when query parameter changed
|
|
193
|
+
}, 1000)
|
|
194
|
+
if(tournamentsUpdateEventSource){
|
|
195
|
+
tournamentsUpdateEventSource.removeEventListener('message', tournamentsUpdateMessageHandler);
|
|
196
|
+
tournamentsUpdateEventSource.close();
|
|
197
|
+
}
|
|
198
|
+
let endpointURL:String = `${endpoint}/tournaments/updates?${tournamentsSearchParams}&XSessionId=${session}`;
|
|
199
|
+
if(!EventSource){
|
|
200
|
+
tournamentsUpdateEventSource = new EventSourcePolyfill(endpointURL, {headers: {'accept': 'text/event-stream'}});
|
|
201
|
+
}else{
|
|
202
|
+
tournamentsUpdateEventSource = new EventSource(endpointURL);
|
|
203
|
+
}
|
|
204
|
+
if(typeof(tournamentsUpdateEventSource) != "undefined"){
|
|
205
|
+
tournamentsUpdateEventSource.addEventListener('message', tournamentsUpdateMessageHandler);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const showMoreAction = async () => {
|
|
210
|
+
let previousNumber = tournamentsShownNumber
|
|
211
|
+
|
|
212
|
+
const _showmorestep = parseInt(showmorestep, 10);
|
|
213
|
+
tournamentsShownNumber += _showmorestep
|
|
214
|
+
|
|
215
|
+
window.postMessage({ type: 'TournamentsPagination', offset: 0, limit: tournamentsShownNumber }, window.location.href);
|
|
216
|
+
|
|
217
|
+
await getDataWithoutfresh(endpoint, previousNumber, _showmorestep)
|
|
218
|
+
|
|
219
|
+
if (tournamentsShownNumber >= tournamentsNumber) {
|
|
220
|
+
allTournamentsShown = true;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const checkAttrs = () => {
|
|
225
|
+
if (!endpoint) {
|
|
226
|
+
error = "Endpoint is missing! Please provide a valid endpointURL.";
|
|
227
|
+
hasErrors = true;
|
|
228
|
+
|
|
229
|
+
console.error(error);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (!lang || lang.length != 2) {
|
|
233
|
+
error = "Language is missing! Please provide a valid language (alpha2code)";
|
|
234
|
+
hasErrors = true;
|
|
235
|
+
|
|
236
|
+
console.error(error);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return hasErrors;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const initialLoad = () => {
|
|
243
|
+
if (!checkAttrs()) {
|
|
244
|
+
tournamentsShownNumber = parseInt(numberoftournaments, 10);
|
|
245
|
+
|
|
246
|
+
setLocale(lang);
|
|
247
|
+
|
|
248
|
+
getData(endpoint, 0, tournamentsShownNumber);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const setActiveLanguage = ():void => {
|
|
253
|
+
setLocale(lang);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const setActiveFilters = () => {
|
|
257
|
+
activeFilters = filters.split(',');
|
|
258
|
+
filtersLoaded = true;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const setSession = () => {
|
|
262
|
+
if (session.length > 0 && session != 'false') {
|
|
263
|
+
isLoggedIn = true;
|
|
264
|
+
isLoading = true;
|
|
265
|
+
sessionID = session;
|
|
266
|
+
} else {
|
|
267
|
+
isLoggedIn = false;
|
|
268
|
+
initialLoad();
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const setPlayerID = () => {
|
|
273
|
+
playerID = userid;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
onMount(() => {
|
|
277
|
+
window.addEventListener('message', messageHandler, false);
|
|
278
|
+
return () => {
|
|
279
|
+
window.removeEventListener('message', messageHandler);
|
|
280
|
+
if(tournamentsUpdateEventSource){
|
|
281
|
+
tournamentsUpdateEventSource.removeEventListener('message', tournamentsUpdateMessageHandler);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
$: session && setSession();
|
|
287
|
+
$: userid && setPlayerID();
|
|
288
|
+
$: lang && setLocale(lang);
|
|
289
|
+
$: filters && setActiveFilters();
|
|
290
|
+
$: lang && setActiveLanguage();
|
|
291
|
+
$: initialParameters = endpoint && numberoftournaments && showmorestep && lang;
|
|
292
|
+
$: readyToLoad = session ? initialParameters && session : initialParameters;
|
|
293
|
+
$: readyToLoad && initialLoad();
|
|
294
|
+
</script>
|
|
295
|
+
|
|
296
|
+
{#if hasErrors}
|
|
297
|
+
<p>{$_('tournamentsController.500')}</p>
|
|
298
|
+
<p>{error}</p>
|
|
299
|
+
{:else}
|
|
300
|
+
<div class="TournamentsWrapper" part="TournamentsWrapper">
|
|
301
|
+
<div class="Tournaments" style="max-width: {containermaxwidth}px;" part="Tournaments">
|
|
302
|
+
<div class="FirstRow" part="FirstRow">
|
|
303
|
+
{#if filtersLoaded}
|
|
304
|
+
<casino-tournaments-filter-controller
|
|
305
|
+
filters={filtersArray}
|
|
306
|
+
activefilters={filters}
|
|
307
|
+
exportparts="FiltersController, MobileClass, Non-MobileClass/empty, Active, FilterButton, bi, bi-check, FiltersList, FiltersTitle, FiltersItem"
|
|
308
|
+
></casino-tournaments-filter-controller>
|
|
309
|
+
{/if}
|
|
310
|
+
</div>
|
|
311
|
+
<div class="SecondRow" part="SecondRow">
|
|
312
|
+
{#if tournamentsNumber == 0}
|
|
313
|
+
{#if isLoading}
|
|
314
|
+
<p class="LoadingMessage" part="LoadingMessage">{$_('tournamentsController.loading')}</p>
|
|
315
|
+
{:else}
|
|
316
|
+
<p class="NoTournaments" part="NoTournaments">{$_('tournamentsController.noTournaments')}</p>
|
|
317
|
+
{/if}
|
|
318
|
+
{:else}
|
|
319
|
+
<casino-tournaments-list-controller
|
|
320
|
+
session={session}
|
|
321
|
+
userid={userid}
|
|
322
|
+
numberoftournaments={numberoftournaments}
|
|
323
|
+
endpoint={endpoint}
|
|
324
|
+
loginurl={loginurl}
|
|
325
|
+
loginevent={loginevent}
|
|
326
|
+
registerurl={registerurl}
|
|
327
|
+
registerevent={registerevent}
|
|
328
|
+
{lang}
|
|
329
|
+
{currency}
|
|
330
|
+
{keepbrowsercontext}
|
|
331
|
+
exportparts="Thumbnail, Status, Enrolled, CardImg, CardImgFinished, Details, Title, Date, ScoreCriteria, ScoreCriteriaP, ScoreCriteriaSpan, Games, GamesP, GamesAnchor, TournamentPrizes, TournamentPrizesSvg, a, TournamentPrizesSvgA, PrizesTitle, Prizes, Prize, PrizeText, PrizeRank,
|
|
332
|
+
TournamentDuration, TournamentDates, StartDate, EndDate, ProgressBar, ProgressBarFillEnd, Finished, ProgressBarFillStarting, Remaining, ProgressBarFill,
|
|
333
|
+
TournamentsGamesSlider, SliderNavButton, items, item, PlayNowButton, itemHover, SliderNavButton
|
|
334
|
+
TournamentCard, CardMaxWidth, CardFullSize, elementToFadeOut, elementToFadeIn, ph-item, ph-col-12, ph-picture, ph-row, ph-col-6, big, ph-col-4, empty, ph-col-8, TournamentButtons, LoginButton, RegisterButton, DetailsButton, EnrolledButton, JoinButton, JoinButtonSpan, JoinButtonSvg, JoinButtonSvgA, JoinButtonFullSize, spinner, DetailsLargeButton, ErrorText, TournamentList, StatusUnstarted, StatusRunning, StatusClosed, StatusClosing, TournamentPrizesIconSection, TournamentPrizesIconWrapper"
|
|
335
|
+
></casino-tournaments-list-controller>
|
|
336
|
+
{/if}
|
|
337
|
+
</div>
|
|
338
|
+
{#if !allTournamentsShown}
|
|
339
|
+
<div class="ThirdRow" part="ThirdRow">
|
|
340
|
+
<div class="CenterButton" part="CenterButton">
|
|
341
|
+
<button class="ShowMoreButton" part="ShowMoreButton" on:click="{() => showMoreAction()}" title="Show More">{$_('tournamentsController.showMore')}</button>
|
|
342
|
+
</div>
|
|
343
|
+
</div>
|
|
344
|
+
{/if}
|
|
345
|
+
</div>
|
|
346
|
+
</div>
|
|
347
|
+
{/if}
|
|
348
|
+
|
|
349
|
+
<style lang="scss">
|
|
350
|
+
$primary-background-color: var(--emfe-w-color-contrast, #07072A);
|
|
351
|
+
$font-stack: "Helvetica Neue", "Helvetica", sans-serif;
|
|
352
|
+
$primary-font-color: var(--emfe-w-color-white, #FFFFFF);
|
|
353
|
+
$primary-font-size: 1rem;
|
|
354
|
+
|
|
355
|
+
:host {
|
|
356
|
+
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
*,
|
|
360
|
+
*::before,
|
|
361
|
+
*::after {
|
|
362
|
+
margin: 0;
|
|
363
|
+
padding: 0;
|
|
364
|
+
list-style: none;
|
|
365
|
+
text-decoration: none;
|
|
366
|
+
outline: none;
|
|
367
|
+
box-sizing: border-box;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
.ShowMoreButton {
|
|
371
|
+
background: var(--emfe-w-color-contrast, #07072A);
|
|
372
|
+
font-size: 18px;
|
|
373
|
+
width: 280px;
|
|
374
|
+
height: 60px;
|
|
375
|
+
text-align: center;
|
|
376
|
+
color: var(--emfe-w-color-green, #48952a);
|
|
377
|
+
border: solid var(--emfe-w-color-green, #48952a) 1px;
|
|
378
|
+
text-transform: uppercase;
|
|
379
|
+
margin-bottom: 20px;
|
|
380
|
+
cursor: pointer;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
.ShowMoreButton:hover {
|
|
384
|
+
opacity: 0.7;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
.TournamentsWrapper {
|
|
388
|
+
background: $primary-background-color;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
.Tournaments {
|
|
392
|
+
color: $primary-font-color;
|
|
393
|
+
display: flex;
|
|
394
|
+
flex-direction: column;
|
|
395
|
+
position: relative;
|
|
396
|
+
margin: 0 auto;
|
|
397
|
+
padding: 24px 0;
|
|
398
|
+
|
|
399
|
+
@media screen and (max-width: 1300px) {
|
|
400
|
+
padding: 24px 2.4%;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
.FirstRow {
|
|
404
|
+
width: 100%;
|
|
405
|
+
margin: 0 auto;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
.SecondRow {
|
|
409
|
+
margin: 0 auto;
|
|
410
|
+
width: 100%;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
.ThirdRow {
|
|
414
|
+
display: flex;
|
|
415
|
+
flex-direction: column;
|
|
416
|
+
justify-content: center;
|
|
417
|
+
|
|
418
|
+
.CenterButton {
|
|
419
|
+
padding-top: 20px;
|
|
420
|
+
width: 100%;
|
|
421
|
+
display: flex;
|
|
422
|
+
justify-content: center;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
</style>
|