define(['m', '_', 'resultParser', 'teams', 'views/topNavBar', 'views/footer'], function(m, _, resultParser, teams, topNavBar, footer) { var statsView = {}; statsView.controller = function(){ var games = m.prop([]); return m.request({method: "GET", url: "/api/resultats.json"}) .then(games) .then(resultParser.getStats); }; statsView.getStatRow = function(teamStats){ var formatStat = function(n){ return teamStats.gamePlayed === 0 ? '-' : n; }; return m('tr', [ m('td', teamStats.team), m('td', teamStats.gamePlayed), m('td', formatStat(teamStats.victories)), m('td', formatStat(teamStats.defeats)), m('td', formatStat(teamStats.draws)), m('td', formatStat(teamStats.pointsFor)), m('td', formatStat(teamStats.pointsAgaint)), m('td', formatStat(teamStats.pointsFor - teamStats.pointsAgaint)), m('td', "? ") ]); }; statsView.mainTable = function(stats){ return m('table.uk-table.uk-table-hover.uk-table-striped',[ m('thead', m('tr', [ m('th', 'Équipes'), m('th', 'PJ'), m('th', 'V'), m('th', 'D'), m('th', 'N'), m('th', 'PP'), m('th', 'PC'), m('th', 'DIF'), m('th', 'PTS') ])), m('tbody', _.map(stats, statsView.getStatRow)) ]); }; statsView.legend = function(){ var items = ["PJ : Parties joués", "V : Victoire", "D : Défaite", "N : Nul", "PP : Points pour", "PC : Points contre", "DIF : Diférenciel","PTS : Points"]; return m('ul.uk-subnav.uk-subnav-line.uk-flex-center',[ _.map(items, function(itm){ return m('li', itm); }) ]); }; statsView.view = function(stats){ return m('div.uk-grid', m('div.uk-width-1-1',[ m('h2', 'Classement 2016'), statsView.mainTable(stats()), statsView.legend() ])); }; var schedulView = {}; schedulView.controller = function(){ var games = m.prop([]); return m.request({method: "GET", url: "/api/resultats.json"}) .then(games) .then(resultParser.getNightGames); }; schedulView._getTeamTag = function(teamName){ var teamColor = teams.getTeamColor(teamName); return [ m('i.fa.fa-flag', {style: {color: teamColor}}), m('span', ' ' + teamName) ]; }; schedulView._asGamePoints = function(points){ return !_.isNumber(points) ? '-' : points + ''; }; schedulView._gameRow = function(game){ return m('tr',[ m('td', game.time), m('td', schedulView._getTeamTag(game.home)), m('td', schedulView._asGamePoints(game.home_points)), m('td', 'vs'), m('td', schedulView._getTeamTag(game.away)), m('td', schedulView._asGamePoints(game.away_points)) ]); }; schedulView._gameView = function(gameNight){ return m('div', [m('h3', gameNight.date), m('table.uk-table.uk-table-hover.uk-table-condensed.uk-table-striped', m('tbody',[ _.map(gameNight.games, schedulView._gameRow), ]) ) ]); }; schedulView.view = function(games){ return m('div.uk-grid', m('div.uk-width-3-5', _.concat([m('h2', 'Calendrier 2016')], _.map(games(), schedulView._gameView)))); }; calendarPage = {}; calendarPage.view = function(){ return [m.component(topNavBar), m('div.uk-grid', m('div.uk-width-3-5.uk-push-1-5',[ m.component(statsView), m.component(schedulView)])), m.component(footer)]; }; return calendarPage; });