@everymatrix/casino-tournaments-page-controller 0.0.248 → 0.0.249

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@everymatrix/casino-tournaments-page-controller",
3
- "version": "0.0.248",
3
+ "version": "0.0.249",
4
4
  "main": "dist/casino-tournaments-page-controller.js",
5
5
  "svelte": "src/index.ts",
6
6
  "scripts": {
@@ -37,5 +37,5 @@
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "77f6efa473daab4dd62004b893c587558bf4511c"
40
+ "gitHead": "38af455e241b6ef7ccabb2367be2be59e6b24352"
41
41
  }
@@ -23,7 +23,7 @@
23
23
  export let currency: string = 'EUR';
24
24
  export let tablelimit: string = '30';
25
25
  export let namemask: string = '';
26
-
26
+ export let mobiletablelimit:string = '15';
27
27
  // Variables of topics for communication
28
28
  let sessionTopic;
29
29
 
@@ -44,39 +44,54 @@
44
44
 
45
45
  let tableUpdateEventSource: EventSourcePolyfill;
46
46
 
47
- setupI18n({withLocale: 'en', translations: {}});
47
+ let currentUserData:any = {};
48
+ let currentUserInPage:Boolean = false;
49
+ setupI18n({ withLocale: 'en', translations: {}});
48
50
 
49
51
  Object.keys(TournamentsPageTranslations).forEach((item: any) => {
50
52
  addNewMessages(item, TournamentsPageTranslations[item]);
51
53
  });
52
54
 
53
55
  // @TODO this must be configurable
54
- const tableColumns = ['Position', 'Name', 'Score'];
56
+ const tableColumns = ['Rank', 'Player', 'Points','Prize'];
57
+
58
+ // data for current user
59
+ const transFormCurrentUserData = (item:any) => {
60
+ let userData = {
61
+ Rank: item.rank,
62
+ Player: item.shortName,
63
+ Points: item.score,
64
+ Prize: item.prizeName,
65
+ Unqualified: item.unqualified,
66
+ BetCount: item.betCount,
67
+ };
68
+ return userData;
69
+ }
55
70
 
56
71
  // @TODO data type
57
- const transformTableData = (data: any) => {
58
- let tableData: any = [];
59
-
60
- if (data && data.length > 0) {
61
- data.forEach((item: any) => {
62
- if (item.unqualified == false) {
63
- if (item.userID == playerID) {
64
- firstRowAvailable = true;
65
- firstRowData = {
66
- Position: item.rank,
67
- Name: item.shortName,
68
- Score: item.score,
69
- };
70
- } else {
71
- tableData.push({
72
- Position: item.rank,
73
- Name: item.shortName,
74
- Score: item.score,
75
- });
76
- }
72
+ const transformTableData = (data:any) => {
73
+ let tableData:any = [];
74
+
75
+ if (data && data.length > 0) {
76
+ data.forEach((item:any) => {
77
+ if (item.unqualified == false) {
78
+ if(item.userID == playerID){
79
+ currentUserData = item;
80
+ currentUserInPage = true;
77
81
  }
78
- });
79
- }
82
+ // added duplicated properties for mobile version, requirement more information for desktop version
83
+ tableData.push({
84
+ Rank: item.rank,
85
+ Player: item.shortName,
86
+ Points: item.score,
87
+ Prize: item.prizeName,
88
+ Unqualified: item.unqualified,
89
+ BetCount: item.betCount,
90
+ userID: item.userID
91
+ });
92
+ }
93
+ });
94
+ }
80
95
 
81
96
  return tableData;
82
97
  },
@@ -91,11 +106,18 @@
91
106
  return;
92
107
  }
93
108
  let newTableData = transformTableData(updateTableData.Items);
94
- if (firstRowAvailable && firstRowData) {
95
- window.postMessage({type: 'CasinoTableFirstRowData', tableData: firstRowData}, window.location.href);
109
+ if(updateTableData.item && !currentUserInPage){
110
+ firstRowAvailable = true;
111
+ firstRowData = transFormCurrentUserData(updateTableData.item);
96
112
  }
97
- window.postMessage({type: 'CasinoTableDataUpdate', tableData: newTableData}, window.location.href);
98
- } catch (err) {
113
+ if(firstRowAvailable && firstRowData){
114
+ window.postMessage({ type: 'CasinoTableFirstRowData', tableData: firstRowData }, window.location.href);
115
+ }
116
+ window.postMessage({ type: 'CasinoTableDataUpdate', tableData: newTableData}, window.location.href);
117
+ if(currentUserInPage){
118
+ window.postMessage({ type: 'CasinoTableCurrentUserData', tableData: currentUserData }, window.location.href);
119
+ }
120
+ }catch(err){
99
121
  console.error(err);
100
122
  }
101
123
  },
@@ -144,6 +166,11 @@
144
166
  url.searchParams.append('filter', `shortNameMask=${namemask}`);
145
167
  }
146
168
 
169
+ if (session) {
170
+ let limit = isMobile(userAgent) == true? mobiletablelimit : tablelimit;
171
+ url.searchParams.append('pagination', `offset=0,limit=${limit}`);
172
+ reqHeaders.append('X-SessionID', session);
173
+ }
147
174
  reqHeaders.append('platform', getDevice(userAgent));
148
175
 
149
176
  let requestOptions = {
@@ -155,18 +182,25 @@
155
182
  .then((res: any) => res.json())
156
183
  .then((res: any) => {
157
184
  tournamentTableData = transformTableData(res.items);
185
+ if(res.item && !currentUserInPage){
186
+ firstRowAvailable = true;
187
+ firstRowData = transFormCurrentUserData(res.item);
188
+ }
158
189
  showTable = true;
159
190
 
160
191
  // @TODO data is not iterable error fix
161
192
  window.postMessage({
162
193
  type: 'CasinoTableData',
163
- tableData: tournamentTableData.slice(0, tablelimit)
194
+ tableData: tournamentTableData
164
195
  }, window.location.href);
165
196
  window.postMessage({type: 'CasinoTableColumns', tableColumns}, window.location.href);
166
197
  if (firstRowAvailable) {
167
198
  window.postMessage({type: 'CasinoTableFirstRowData', tableData: firstRowData}, window.location.href);
168
199
  }
169
200
  startupTableDataChangeListener(tourID, url.searchParams);
201
+ if (currentUserInPage){
202
+ window.postMessage({ type: 'CasinoTableCurrentUserData', tableData: currentUserData }, window.location.href);
203
+ }
170
204
  });
171
205
  }
172
206
 
@@ -203,7 +237,9 @@
203
237
 
204
238
  isLoading = false;
205
239
  }
206
-
240
+ const setActiveLanguage = ():void => {
241
+ setLocale(lang);
242
+ }
207
243
  const initialLoad = () => {
208
244
  setLocale(lang);
209
245
  getData(endpoint, tourid);
@@ -230,6 +266,7 @@
230
266
  });
231
267
 
232
268
  $: session && userid && setSession();
269
+ $: lang && setActiveLanguage();
233
270
  $: initialParameters = tourid && endpoint && session && lang;
234
271
  $: initialParameters && initialLoad();
235
272
  $: tourid && cmsendpoint && getDataFromCMS();