diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueDAO.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueDAO.java index 23c92ca7a..70b9450f2 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueDAO.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueDAO.java @@ -74,7 +74,7 @@ public class LeagueDAO { private void loadActiveLeagues(int currentTime) throws SQLException, IOException { Connection conn = _dbAccess.getDataSource().getConnection(); try { - PreparedStatement statement = conn.prepareStatement("select id, name, type, collection from league where start<=? and end>=?"); + PreparedStatement statement = conn.prepareStatement("select id, name, type, collection, start, end from league where start<=? and end>=?"); try { statement.setInt(1, currentTime); statement.setInt(2, currentTime); @@ -84,13 +84,15 @@ public class LeagueDAO { int id = rs.getInt(1); String name = rs.getString(2); String type = rs.getString(3); + int start = rs.getInt(5); + int end = rs.getInt(6); Blob baseCollection = rs.getBlob(4); try { final InputStream inputStream = baseCollection.getBinaryStream(); try { MutableCardCollection collection = _serializer.deserializeCollection(inputStream); - _activeLeagues.add(new League(id, type, name, collection)); + _activeLeagues.add(new League(id, type, name, collection, start, end)); } finally { inputStream.close(); } diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueMatchDAO.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueMatchDAO.java index 411885931..96e9cfb39 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueMatchDAO.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueMatchDAO.java @@ -2,7 +2,7 @@ package com.gempukku.lotro.db; import com.gempukku.lotro.db.vo.League; import com.gempukku.lotro.db.vo.LeagueMatch; -import com.gempukku.lotro.db.vo.LeagueSeason; +import com.gempukku.lotro.db.vo.LeagueSerie; import java.sql.Connection; import java.sql.PreparedStatement; @@ -17,7 +17,7 @@ public class LeagueMatchDAO { _dbAccess = dbAccess; } - public Collection getPlayerMatchesPlayedOn(League league, LeagueSeason leagueSeason, String player) { + public Collection getPlayerMatchesPlayedOn(League league, LeagueSerie leagueSeason, String player) { try { Connection conn = _dbAccess.getDataSource().getConnection(); try { @@ -51,7 +51,7 @@ public class LeagueMatchDAO { } } - public void addPlayedMatch(League league, LeagueSeason leagueSeason, String winner, String loser) { + public void addPlayedMatch(League league, LeagueSerie leagueSeason, String winner, String loser) { try { Connection conn = _dbAccess.getDataSource().getConnection(); try { diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeaguePointsDAO.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeaguePointsDAO.java index 9c94e8a67..4f2a2c532 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeaguePointsDAO.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeaguePointsDAO.java @@ -1,11 +1,14 @@ package com.gempukku.lotro.db; import com.gempukku.lotro.db.vo.League; -import com.gempukku.lotro.db.vo.LeagueSeason; +import com.gempukku.lotro.db.vo.LeagueSerie; import java.sql.Connection; import java.sql.PreparedStatement; +import java.sql.ResultSet; import java.sql.SQLException; +import java.util.LinkedHashMap; +import java.util.Map; public class LeaguePointsDAO { private DbAccess _dbAccess; @@ -14,7 +17,7 @@ public class LeaguePointsDAO { _dbAccess = dbAccess; } - public void addPoints(League league, LeagueSeason season, String playerName, int points) { + public void addPoints(League league, LeagueSerie season, String playerName, int points) { try { Connection conn = _dbAccess.getDataSource().getConnection(); try { @@ -35,4 +38,65 @@ public class LeaguePointsDAO { throw new RuntimeException(exp); } } + + public Map getLeagueStandings(League league) { + try { + Connection conn = _dbAccess.getDataSource().getConnection(); + try { + PreparedStatement statement = conn.prepareStatement("select player_name, sum(points) from league_points where league_type=? order by 2 desc"); + try { + statement.setString(1, league.getType()); + ResultSet rs = statement.executeQuery(); + try { + Map result = new LinkedHashMap(); + while (rs.next()) { + String playerName = rs.getString(1); + int sumPoints = rs.getInt(2); + result.put(playerName, sumPoints); + } + return result; + } finally { + rs.close(); + } + } finally { + statement.close(); + } + } finally { + conn.close(); + } + } catch (SQLException exp) { + throw new RuntimeException(exp); + } + } + + public Map getSerieStandings(League league, LeagueSerie serie) { + try { + Connection conn = _dbAccess.getDataSource().getConnection(); + try { + PreparedStatement statement = conn.prepareStatement("select player_name, sum(points) from league_points where league_type=? and season_type=? group by player_name order by 2 desc"); + try { + statement.setString(1, league.getType()); + statement.setString(2, serie.getType()); + ResultSet rs = statement.executeQuery(); + try { + Map result = new LinkedHashMap(); + while (rs.next()) { + String playerName = rs.getString(1); + int sumPoints = rs.getInt(2); + result.put(playerName, sumPoints); + } + return result; + } finally { + rs.close(); + } + } finally { + statement.close(); + } + } finally { + conn.close(); + } + } catch (SQLException exp) { + throw new RuntimeException(exp); + } + } } diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueSeasonDAO.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueSerieDAO.java similarity index 50% rename from gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueSeasonDAO.java rename to gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueSerieDAO.java index 93357feb8..bd1065f44 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueSeasonDAO.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueSerieDAO.java @@ -1,21 +1,23 @@ package com.gempukku.lotro.db; import com.gempukku.lotro.db.vo.League; -import com.gempukku.lotro.db.vo.LeagueSeason; +import com.gempukku.lotro.db.vo.LeagueSerie; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.LinkedList; +import java.util.List; -public class LeagueSeasonDAO { +public class LeagueSerieDAO { private DbAccess _dbAccess; - public LeagueSeasonDAO(DbAccess dbAccess) { + public LeagueSerieDAO(DbAccess dbAccess) { _dbAccess = dbAccess; } - public void addSeason(String leagueType, String seasonType, int start, int end, int maxMatches) { + public void addSerie(String leagueType, String seasonType, int start, int end, int maxMatches) { try { Connection conn = _dbAccess.getDataSource().getConnection(); try { @@ -38,11 +40,43 @@ public class LeagueSeasonDAO { } } - public LeagueSeason getSeasonForLeague(League league, int inTime) { + public List getSeriesForLeague(League league) { try { Connection conn = _dbAccess.getDataSource().getConnection(); try { - PreparedStatement statement = conn.prepareStatement("select season_type, max_matches from league_season where league_type=? and start<=? and end>=?"); + PreparedStatement statement = conn.prepareStatement("select season_type, max_matches, start, end from league_season where league_type=? order by start asc"); + try { + statement.setString(1, league.getType()); + ResultSet rs = statement.executeQuery(); + try { + List seasons = new LinkedList(); + while (rs.next()) { + String type = rs.getString(1); + int maxMatches = rs.getInt(2); + int start = rs.getInt(3); + int end = rs.getInt(4); + seasons.add(new LeagueSerie(type, maxMatches, start, end)); + } + return seasons; + } finally { + rs.close(); + } + } finally { + statement.close(); + } + } finally { + conn.close(); + } + } catch (SQLException exp) { + throw new RuntimeException(exp); + } + } + + public LeagueSerie getSerieForLeague(League league, int inTime) { + try { + Connection conn = _dbAccess.getDataSource().getConnection(); + try { + PreparedStatement statement = conn.prepareStatement("select season_type, max_matches, start, end from league_season where league_type=? and start<=? and end>=?"); try { statement.setString(1, league.getType()); statement.setInt(2, inTime); @@ -52,7 +86,9 @@ public class LeagueSeasonDAO { if (rs.next()) { String type = rs.getString(1); int maxMatches = rs.getInt(2); - return new LeagueSeason(type, maxMatches); + int start = rs.getInt(3); + int end = rs.getInt(4); + return new LeagueSerie(type, maxMatches, start, end); } return null; } finally { diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/League.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/League.java index f56572d32..81849c444 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/League.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/League.java @@ -7,12 +7,16 @@ public class League { private String _type; private String _name; private MutableCardCollection _baseCollection; + private int _start; + private int _end; - public League(int id, String type, String name, MutableCardCollection baseCollection) { + public League(int id, String type, String name, MutableCardCollection baseCollection, int start, int end) { _id = id; _type = type; _name = name; _baseCollection = baseCollection; + _start = start; + _end = end; } public int getId() { @@ -30,4 +34,12 @@ public class League { public MutableCardCollection getBaseCollection() { return _baseCollection; } + + public int getEnd() { + return _end; + } + + public int getStart() { + return _start; + } } diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/LeagueSeason.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/LeagueSeason.java deleted file mode 100644 index c7765995d..000000000 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/LeagueSeason.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.gempukku.lotro.db.vo; - -public class LeagueSeason { - private String _type; - private int _maxMatches; - - public LeagueSeason(String type, int maxMatches) { - _type = type; - _maxMatches = maxMatches; - } - - public int getMaxMatches() { - return _maxMatches; - } - - public String getType() { - return _type; - } -} diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/LeagueSerie.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/LeagueSerie.java new file mode 100644 index 000000000..28af3183f --- /dev/null +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/LeagueSerie.java @@ -0,0 +1,31 @@ +package com.gempukku.lotro.db.vo; + +public class LeagueSerie { + private String _type; + private int _maxMatches; + private int _start; + private int _end; + + public LeagueSerie(String type, int maxMatches, int start, int end) { + _type = type; + _maxMatches = maxMatches; + _start = start; + _end = end; + } + + public int getMaxMatches() { + return _maxMatches; + } + + public String getType() { + return _type; + } + + public int getEnd() { + return _end; + } + + public int getStart() { + return _start; + } +} diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeagueService.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeagueService.java index 05c272a85..a279bdaad 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeagueService.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeagueService.java @@ -3,7 +3,7 @@ package com.gempukku.lotro.league; import com.gempukku.lotro.db.*; import com.gempukku.lotro.db.vo.League; import com.gempukku.lotro.db.vo.LeagueMatch; -import com.gempukku.lotro.db.vo.LeagueSeason; +import com.gempukku.lotro.db.vo.LeagueSerie; import com.gempukku.lotro.game.*; import com.gempukku.lotro.logic.timing.GameResultListener; @@ -11,13 +11,13 @@ import java.util.*; public class LeagueService { private LeagueDAO _leagueDao; - private LeagueSeasonDAO _leagueSeasonDao; + private LeagueSerieDAO _leagueSeasonDao; private LeaguePointsDAO _leaguePointsDao; private LeagueMatchDAO _leagueMatchDao; private CollectionDAO _collectionDao; private LotroCardBlueprintLibrary _library; - public LeagueService(LeagueDAO leagueDao, LeagueSeasonDAO leagueSeasonDao, LeaguePointsDAO leaguePointsDao, LeagueMatchDAO leagueMatchDao, CollectionDAO collectionDao, LotroCardBlueprintLibrary library) { + public LeagueService(LeagueDAO leagueDao, LeagueSerieDAO leagueSeasonDao, LeaguePointsDAO leaguePointsDao, LeagueMatchDAO leagueMatchDao, CollectionDAO collectionDao, LotroCardBlueprintLibrary library) { _leagueDao = leagueDao; _leagueSeasonDao = leagueSeasonDao; _leaguePointsDao = leaguePointsDao; @@ -63,7 +63,7 @@ public class LeagueService { public void leagueGameStarting(final League league, LotroGameMediator gameMediator) { final int startDay = getCurrentDate(); - final LeagueSeason season = _leagueSeasonDao.getSeasonForLeague(league, startDay); + final LeagueSerie season = _leagueSeasonDao.getSerieForLeague(league, startDay); if (season != null && isRanked(league, season, gameMediator)) { gameMediator.addGameResultListener( new GameResultListener() { @@ -86,7 +86,7 @@ public class LeagueService { return date.get(Calendar.YEAR) * 10000 + (date.get(Calendar.MONTH) + 1) * 100 + date.get(Calendar.DAY_OF_MONTH); } - private boolean isRanked(League league, LeagueSeason season, LotroGameMediator gameMediator) { + private boolean isRanked(League league, LeagueSerie season, LotroGameMediator gameMediator) { Set playersPlaying = gameMediator.getPlayersPlaying(); for (String player : playersPlaying) { int maxMatches = season.getMaxMatches(); diff --git a/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/AdminResource.java b/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/AdminResource.java index 96f52435c..2b758c218 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/AdminResource.java +++ b/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/AdminResource.java @@ -3,7 +3,7 @@ package com.gempukku.lotro.server; import com.gempukku.lotro.db.CollectionDAO; import com.gempukku.lotro.db.DeckDAO; import com.gempukku.lotro.db.LeagueDAO; -import com.gempukku.lotro.db.LeagueSeasonDAO; +import com.gempukku.lotro.db.LeagueSerieDAO; import com.gempukku.lotro.db.vo.League; import com.gempukku.lotro.game.DefaultCardCollection; import com.gempukku.lotro.game.LotroCardBlueprintLibrary; @@ -30,7 +30,7 @@ public class AdminResource extends AbstractResource { @Context private LeagueDAO _leagueDao; @Context - private LeagueSeasonDAO _leagueSeasonDao; + private LeagueSerieDAO _leagueSeasonDao; @Context private LotroCardBlueprintLibrary _library; @Context @@ -95,7 +95,7 @@ public class AdminResource extends AbstractResource { @Context HttpServletRequest request) throws Exception { validateAdmin(request); - _leagueSeasonDao.addSeason(leagueType, type, start, end, maxMatches); + _leagueSeasonDao.addSerie(leagueType, type, start, end, maxMatches); return "OK"; } diff --git a/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/DaoProvider.java b/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/DaoProvider.java index 534bec46e..df6711e46 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/DaoProvider.java +++ b/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/DaoProvider.java @@ -18,7 +18,7 @@ public class DaoProvider implements InjectableProvider { private Injectable _gameHistoryDAOInjectable; private Injectable _leagueDaoInjectable; - private Injectable _leagueSeasonDAOInjectable; + private Injectable _leagueSeasonDAOInjectable; private Injectable _leagueMatchDAOInjectable; private Injectable _leaguePointsDAOInjectable; @@ -40,7 +40,7 @@ public class DaoProvider implements InjectableProvider { return getGameHistoryDaoSafely(); else if (type.equals(LeagueDAO.class)) return getLeagueDaoSafely(); - else if (type.equals(LeagueSeasonDAO.class)) + else if (type.equals(LeagueSerieDAO.class)) return getLeagueSeasonDaoSafely(); else if (type.equals(LeagueMatchDAO.class)) return getLeagueMatchDaoSafely(); @@ -75,12 +75,12 @@ public class DaoProvider implements InjectableProvider { return _leagueMatchDAOInjectable; } - private synchronized Injectable getLeagueSeasonDaoSafely() { + private synchronized Injectable getLeagueSeasonDaoSafely() { if (_leagueSeasonDAOInjectable == null) { - final LeagueSeasonDAO leagueSeasonDao = new LeagueSeasonDAO(_dbAccess); - _leagueSeasonDAOInjectable = new Injectable() { + final LeagueSerieDAO leagueSeasonDao = new LeagueSerieDAO(_dbAccess); + _leagueSeasonDAOInjectable = new Injectable() { @Override - public LeagueSeasonDAO getValue() { + public LeagueSerieDAO getValue() { return leagueSeasonDao; } }; diff --git a/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/LeagueResource.java b/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/LeagueResource.java new file mode 100644 index 000000000..2eb4c282f --- /dev/null +++ b/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/LeagueResource.java @@ -0,0 +1,72 @@ +package com.gempukku.lotro.server; + +import com.gempukku.lotro.db.LeagueDAO; +import com.gempukku.lotro.db.LeaguePointsDAO; +import com.gempukku.lotro.db.LeagueSerieDAO; +import com.gempukku.lotro.db.vo.League; +import com.gempukku.lotro.db.vo.LeagueSerie; +import com.sun.jersey.spi.resource.Singleton; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Context; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.util.List; +import java.util.Map; + +@Singleton +@Path("/league") +public class LeagueResource extends AbstractResource { + @Context + private LeagueDAO _leagueDao; + @Context + private LeagueSerieDAO _leagueSerieDao; + @Context + private LeaguePointsDAO _leaguePointsDao; + + @GET + public Document getLeagueInformation() throws ParserConfigurationException { + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); + + Document doc = documentBuilder.newDocument(); + Element leagues = doc.createElement("leagues"); + + for (League league : _leagueDao.getActiveLeagues()) { + Element leagueElem = doc.createElement("league"); + leagueElem.setAttribute("type", league.getType()); + leagueElem.setAttribute("name", league.getName()); + leagueElem.setAttribute("start", String.valueOf(league.getStart())); + leagueElem.setAttribute("end", String.valueOf(league.getEnd())); + + List series = _leagueSerieDao.getSeriesForLeague(league); + for (LeagueSerie serie : series) { + Element serieElem = doc.createElement("serie"); + serieElem.setAttribute("type", serie.getType()); + serieElem.setAttribute("maxMatches", String.valueOf(serie.getMaxMatches())); + serieElem.setAttribute("start", String.valueOf(serie.getStart())); + serieElem.setAttribute("end", String.valueOf(serie.getEnd())); + + Map standings = _leaguePointsDao.getSerieStandings(league, serie); + for (Map.Entry playerPoints : standings.entrySet()) { + Element standing = doc.createElement("standing"); + standing.setAttribute("player", playerPoints.getKey()); + standing.setAttribute("points", playerPoints.getValue().toString()); + serieElem.appendChild(standing); + } + + leagueElem.appendChild(serieElem); + } + + leagues.appendChild(leagueElem); + } + + doc.appendChild(leagues); + + return doc; + } +} diff --git a/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/ServerProvider.java b/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/ServerProvider.java index aa4eb957e..63c2c568f 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/ServerProvider.java +++ b/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/ServerProvider.java @@ -27,7 +27,7 @@ public class ServerProvider implements InjectableProvider { @Context private LeagueDAO _leagueDao; @Context - private LeagueSeasonDAO _leagueSeasonDao; + private LeagueSerieDAO _leagueSeasonDao; @Context private LeagueMatchDAO _leagueMatchDao; @Context diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/hall.html b/gemp-lotr/gemp-lotr-web/src/main/webapp/hall.html index 77f49ad1a..26cae5c44 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/hall.html +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/hall.html @@ -87,6 +87,11 @@ padding: .2em .5em; } + .standings td, .standings th { + padding: 2px; + border: 1px solid white; + } + .gameHistory td, .gameHistory th { padding: 2px; border: 1px solid white; @@ -104,6 +109,7 @@ + +All times are GMT based. +
\ No newline at end of file diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/communication.js b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/communication.js index 6eb7a0745..d0f314eff 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/communication.js +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/communication.js @@ -21,6 +21,20 @@ var GempLotrCommunication = Class.extend({ dataType: "xml" }); }, + + getLeagues: function(callback) { + $.ajax({ + type: "GET", + url: this.url + "/league", + cache: false, + data: { + participanId: getUrlParam("participantId") }, + success: callback, + error: this.failure, + dataType: "xml" + }); + }, + getReplay: function(replayId, callback) { $.ajax({ type: "GET", diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/leagueResultsUi.js b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/leagueResultsUi.js new file mode 100644 index 000000000..86241d650 --- /dev/null +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/leagueResultsUi.js @@ -0,0 +1,69 @@ +var LeagueResultsUI = Class.extend({ + communication: null, + + init: function(url) { + this.communication = new GempLotrCommunication(url, + function(xhr, ajaxOptions, thrownError) { + }); + this.loadResults(); + }, + + loadResults: function() { + var that = this; + this.communication.getLeagues( + function(xml) { + that.loadedLeagueResults(xml); + }); + }, + + getDateString: function(date) { + return date.substring(0, 4) + "-" + date.substring(4, 6) + "-" + date.substring(6, 8); + }, + + loadedLeagueResults: function(xml) { + log(xml); + var root = xml.documentElement; + if (root.tagName == 'leagues') { + $("#leagueResults").html(""); + + var leagues = root.getElementsByTagName("league"); + for (var i = 0; i < leagues.length; i++) { + var league = leagues[i]; + var leagueName = league.getAttribute("name"); + var start = league.getAttribute("start"); + var end = league.getAttribute("end"); + + var leagueText = leagueName + " - " + this.getDateString(start) + " to " + this.getDateString(end); + $("#leagueResults").append("

" + leagueText + "

"); + + var series = league.getElementsByTagName("serie"); + for (var j = 0; j < series.length; j++) { + var serie = series[j]; + var serieName = serie.getAttribute("type"); + var serieStart = serie.getAttribute("start"); + var serieEnd = serie.getAttribute("end"); + + var serieText = serieName + " - " + this.getDateString(serieStart) + " to " + this.getDateString(serieEnd); + $("#leagueResults").append("

" + serieText + "

"); + + var standings = serie.getElementsByTagName("standing"); + if (standings.length > 0) { + var standingsTable = $("
"); + + standingsTable.append("PlayerPoints"); + + for (var k = 0; k < standings.length; k++) { + var standing = standings[k]; + var player = standing.getAttribute("player"); + var points = standing.getAttribute("points"); + + standingsTable.append("" + player + "" + points + ""); + } + + $("#leagueResults").append(standingsTable); + } + } + } + } + } +}); \ No newline at end of file