Commit 38df79e3 authored by Romain Courteaud's avatar Romain Courteaud

erp5_web_but: parse rugby json

parent 5f573c30
......@@ -283,3 +283,7 @@ body > main > table thead th {
min-width: 10em;
text-transform: uppercase;
}
table {
text-align: center;
}
\ No newline at end of file
......@@ -248,7 +248,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>968.15468.48654.57804</string> </value>
<value> <string>1010.49822.40856.18739</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -268,7 +268,7 @@
</tuple>
<state>
<tuple>
<float>1529064254.49</float>
<float>1693772961.07</float>
<string>UTC</string>
</tuple>
</state>
......
<!DOCTYPE html>
<html manifest="world_cup_2018.appcache">
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
......@@ -45,8 +45,8 @@
{{/if}}
</li>{{/each}}</ul>
<button type="button" data-wc2018="renderExport">Share!</button>
<button type="button" data-wc2018="renderImport">Import</button>
<button type="button" data-wc2018="renderResult">Result</button>
<!--button type="button" data-wc2018="renderImport">Import</button-->
<!--button type="button" data-wc2018="renderResult">Result</button-->
</script>
<script id="share_template" type="text/x-handlebars-template">
......@@ -73,21 +73,22 @@
<script id="day_form_template" type="text/x-handlebars-template">
<form data-wc2018="submitBet">
<h2>{{day_string}}</h2>
<ul>
{{#each match_list}}<li>
<!--input type="radio" name="couscous" id="couscous_1" required />
<label for="couscous_1">Home</label-->
<label for="{{home_bet_reference}}">{{home_bet_title}}</label>
<input required type="integer" name="{{home_bet_reference}}"
id="{{home_bet_reference}}" value="{{home_bet}}"></input>
/
<input required type="integer" name="{{away_bet_reference}}"
id="{{away_bet_reference}}" value="{{away_bet}}"></input>
<label for="{{away_bet_reference}}">{{away_bet_title}}</label>
<!--input type="radio" name="couscous" id="couscous_2" required />
<label for="couscous_2">Away</label-->
</li>{{/each}}
</ul>
<table>
<tr><td></td><td></td><td>Draw</td><td></td><td></td></tr>
{{#each match_list}}<tr>
<td>
<label for="{{match_id}}winnerChoice1">{{home_bet_title}}</label>
</td><td>
<input type="radio" id="{{match_id}}winnerChoice1" name="{{match_id}}" value="home" {{home_checked}}/>
</td><td>
<input type="radio" id="{{match_id}}winnerChoice2" name="{{match_id}}" value="draw" {{draw_checked}} />
</td><td>
<input type="radio" id="{{match_id}}winnerChoice3" name="{{match_id}}" value="away" {{away_checked}}/>
</td><td>
<label for="{{match_id}}winnerChoice3">{{away_bet_title}}</label>
</td>
</tr>{{/each}}
</table>
<input type="submit" value="Save"></input>
</form>
</script>
......@@ -97,8 +98,8 @@
<body>
<header>
<h1>Fifa World Cup</h1>
<p>Russia 2018</p>
<h1>Rugby World Cup</h1>
<p>France 2023</p>
</header>
<main></main>
</body>
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>968.15868.5231.7987</string> </value>
<value> <string>1010.58506.47731.21435</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -262,7 +262,7 @@
</tuple>
<state>
<tuple>
<float>1529087777.33</float>
<float>1693772860.24</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -36,6 +36,7 @@
team_dict = {};
// Parse teams
/*
for (i = this._parser.teams.length; i > 0; i -= 1) {
tmp = this._parser.teams[i - 1];
result_list.push({
......@@ -49,8 +50,34 @@
});
team_dict[tmp.id] = tmp.name;
}
*/
// Parse groups
for (i = 0; i < this._parser.matches.length; i += 1) {
tmp = this._parser.matches[i];
if (tmp.eventPhaseId.type !== 'Pool') {
continue;
}
result_list.push({
id: 'match_' + (i + 1),
value: {},
doc: {
portal_type: 'World Cup 2023 Match',
match_id: tmp.matchId,
group_match: true,
start_date: tmp.time.label,
home_team: tmp.teams[0].id,
home_team_title: tmp.teams[0].name,
home_result: tmp.scores[0],
away_team: tmp.teams[1].id,
away_team_title: tmp.teams[1].name,
away_result: tmp.scores[1],
finished: tmp.status !== "U",
title: tmp.teams[0].name + ' / ' + tmp.teams[1].name
}
});
}
/*
for (key in this._parser.groups) {
if (this._parser.groups.hasOwnProperty(key)) {
// Group document
......@@ -64,28 +91,10 @@
});
// Match documents
for (i = this._parser.groups[key].matches.length; i > 0; i -= 1) {
tmp = this._parser.groups[key].matches[i - 1];
result_list.push({
id: 'match_' + tmp.name,
value: {},
doc: {
portal_type: 'World Cup 2018 Match',
group_match: true,
start_date: tmp.date,
home_team: tmp.home_team,
home_team_title: team_dict[tmp.home_team],
home_result: tmp.home_result,
away_team: tmp.away_team,
away_team_title: team_dict[tmp.away_team],
away_result: tmp.away_result,
finished: tmp.finished,
title: team_dict[tmp.home_team] + ' / ' + team_dict[tmp.away_team]
}
});
}
}
}
*/
/*
// Parse knockout
for (key in this._parser.knockout) {
......@@ -131,10 +140,7 @@
return storage._parser;
});
}
return new RSVP.Queue()
.push(function () {
return storage._parser;
});
return new RSVP.Queue(storage._parser);
}
/////////////////////////////////////////////////////////////
......@@ -195,7 +201,12 @@
len = form.elements.length;
for (i = 0; i < len; i += 1) {
if (form.elements[i].hasAttribute('name')) {
form_data[form.elements[i].name] = form.elements[i].value;
if (((form.elements[i].type === 'radio') &&
(form.elements[i].checked)) ||
(form.elements[i].type !== 'radio')) {
form_data[form.elements[i].name] = form.elements[i].value;
}
}
}
return form_data;
......@@ -229,8 +240,8 @@
},
remote_sub_storage: {
type: 'world_cup_data',
// document_id: 'world_cup_2018_data.json',
document_id: 'https://raw.githubusercontent.com/lsv/' +
document_id: './world_cup_2018_data.json',
document_idXXX: 'https://raw.githubusercontent.com/lsv/' +
'fifa-worldcup-2018/master/data.json',
attachment_id: 'enclosure',
sub_storage: {
......@@ -302,7 +313,7 @@
.declareMethod('renderCalendar', function renderLauncher() {
var gadget = this;
return gadget._storage.allDocs({
query: 'portal_type:"World Cup 2018 Match"',
query: 'portal_type:"World Cup 2023 Match"',
select_list: ['portal_type', 'start_date', 'home_team', 'title'],
sort_on: [['start_date', 'ascending'], ['title', 'ascending']]
})
......@@ -355,10 +366,10 @@
.push(function (result) {
bet = result;
return gadget._storage.allDocs({
query: 'portal_type:"World Cup 2018 Match" AND ' +
'start_date:"' + day_query + '%"',
query: 'portal_type:"World Cup 2023 Match" AND ' +
'start_date:"' + day_query + '"',
select_list: ['portal_type', 'start_date', 'title',
'home_team_title', 'away_team_title'],
'home_team_title', 'away_team_title', 'match_id'],
sort_on: [['start_date', 'ascending'], ['title', 'ascending']]
});
})
......@@ -367,13 +378,16 @@
length = result.data.rows.length,
match_list = [],
match;
if (length === 0) {
throw new Error("No result for date " + day_query);
}
for (i = 0; i < length; i += 1) {
match = result.data.rows[i].value;
match.home_bet_reference = result.data.rows[i].id + '_A';
match.away_bet_reference = result.data.rows[i].id + '_B';
// init to 0
match.home_bet = bet[match.home_bet_reference] || 0;
match.away_bet = bet[match.away_bet_reference] || 0;
match.bet = bet[match.match_id] || 'draw';
match.home_checked = match.bet === 'home' ? 'checked' : '';
match.draw_checked = match.bet === 'draw' ? 'checked' : '';
match.away_checked = match.bet === 'away' ? 'checked' : '';
match.home_bet_title = match.home_team_title;
match.away_bet_title = match.away_team_title;
match_list.push(result.data.rows[i].value);
......@@ -389,32 +403,34 @@
var gadget = this,
match_list;
return gadget._storage.allDocs({
query: 'portal_type:"World Cup 2018 Match" AND ' +
query: 'portal_type:"World Cup 2023 Match" AND ' +
'group_match: true',
select_list: ['start_date'],
sort_on: [['start_date', 'ascending'], ['title', 'ascending']]
select_list: ['start_date', 'match_id'],
sort_on: [['match_id', 'ascending']]
})
.push(function (result) {
match_list = result.data.rows;
return gadget.getBet();
})
.push(function (doc) {
.push(function (bet) {
var i,
j,
result = '',
key,
suffix_list = ['_A', '_B'];
score,
key;
for (i = 0; i < match_list.length; i += 1) {
for (j = 0; j < suffix_list.length; j += 1) {
key = 'match_' + (i + 1) + suffix_list[j];
if ((!doc.hasOwnProperty(key)) ||
(parseInt(doc[key], 10) > 15)) {
// Bet between 0 and 15
return gadget.renderCard(match_list[i].value
.start_date.substr(0, 10));
}
result += parseInt(doc[key], 10).toString(16);
key = match_list[i].value.match_id;
if (!bet.hasOwnProperty(key)) {
return gadget.renderCard(match_list[i].value
.start_date.substr(0, 10));
}
if (bet[key] === 'draw') {
score = '0';
} else if (bet[key] === 'home') {
score = '1';
} else {
score = '2';
}
result += parseInt(score, 10).toString(16);
}
gadget.element.querySelector('main').innerHTML = share_template({
code: LZString.compressToBase64(result)
......@@ -423,7 +439,7 @@
})
.declareMethod('renderImport', function renderExport() {
.declareMethod('renderImport', function renderImport() {
var gadget = this;
return gadget.getCodeDict()
.push(function (code_dict) {
......@@ -443,17 +459,18 @@
var gadget = this,
match_list;
return gadget._storage.allDocs({
query: 'portal_type:"World Cup 2018 Match" AND finished:true AND ' +
query: 'portal_type:"World Cup 2023 Match" AND finished:true AND ' +
'group_match: true',
select_list: ['start_date', 'home_result', 'away_result',
'home_team_title', 'away_team_title', 'title'],
sort_on: [['start_date', 'ascending'], ['title', 'ascending']]
sort_on: [['match_id', 'ascending']]
})
.push(function (result) {
match_list = result.data.rows;
return gadget.getCodeDict();
})
.push(function (code_dict) {
console.log(code_dict);
// First, decode all codes
var key,
i,
......
......@@ -236,7 +236,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>968.19633.6812.24251</string> </value>
<value> <string>1010.58492.51761.29798</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -256,7 +256,7 @@
</tuple>
<state>
<tuple>
<float>1529314173.15</float>
<float>1693771993.21</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -257,7 +257,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>World Cup 2018</string> </value>
<value> <string>World Cup 2023</string> </value>
</item>
<item>
<key> <string>visible</string> </key>
......@@ -428,7 +428,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>968.59.40410.23688</string> </value>
<value> <string>1010.49822.40856.18739</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -448,7 +448,7 @@
</tuple>
<state>
<tuple>
<float>1529060918.21</float>
<float>1693252020.78</float>
<string>UTC</string>
</tuple>
</state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment