From d143791321736f8c1eb1e1f02feb20724761dfd2 Mon Sep 17 00:00:00 2001 From: Andy Janata Date: Tue, 27 Feb 2018 13:59:56 -0800 Subject: [PATCH] * Fix some cases of not all decks being listed because the javascript code assumed that duplicate weights would never occur. * Re-enable view cards page. --- WebContent/game.jsp | 4 +--- WebContent/js/cah.cardset.js | 6 ++++-- WebContent/viewcards.jsp | 29 +++++++++++------------------ 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/WebContent/game.jsp b/WebContent/game.jsp index c80f0e8..eb41125 100644 --- a/WebContent/game.jsp +++ b/WebContent/game.jsp @@ -1,6 +1,6 @@ <%-- -Copyright (c) 2012-2017, Andy Janata +Copyright (c) 2012-2018, Andy Janata All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted @@ -132,11 +132,9 @@ HttpSession hSession = request.getSession(true); diff --git a/WebContent/js/cah.cardset.js b/WebContent/js/cah.cardset.js index 44751fe..c7c85c8 100644 --- a/WebContent/js/cah.cardset.js +++ b/WebContent/js/cah.cardset.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Andy Janata + * Copyright (c) 2012-2018, Andy Janata * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted @@ -177,6 +177,8 @@ cah.CardSet.prototype.getWeight = function() { cah.CardSet.populateCardSets = function(cardSets) { cah.CardSet.list = {}; cah.CardSet.byWeight = {}; + // the server already sends us an ordered list, so let's just use that ordering + var i = 0; for ( var key in cardSets) { var cardSetData = cardSets[key]; var cardSet = new cah.CardSet(cardSetData[cah.$.CardSetData.ID], @@ -186,7 +188,7 @@ cah.CardSet.populateCardSets = function(cardSets) { cardSetData[cah.$.CardSetData.BLACK_CARDS_IN_DECK], cardSetData[cah.$.CardSetData.WHITE_CARDS_IN_DECK], cardSetData[cah.$.CardSetData.WEIGHT]); cah.CardSet.list[cardSet.getId()] = cardSet; - cah.CardSet.byWeight[cardSetData[cah.$.CardSetData.WEIGHT]] = cardSet; + cah.CardSet.byWeight[i++] = cardSet; } // not sure if there's a better way to call this... diff --git a/WebContent/viewcards.jsp b/WebContent/viewcards.jsp index 5bda86f..9ae1ce8 100644 --- a/WebContent/viewcards.jsp +++ b/WebContent/viewcards.jsp @@ -1,6 +1,6 @@ <%-- -Copyright (c) 2013, Andy Janata +Copyright (c) 2013-2018, Andy Janata All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted @@ -26,7 +26,7 @@ Interface to view and search all existing cards and card sets. @author Andy Janata (ajanata@socialgamer.net) --%> -<%-- + <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <%@ page import="java.util.ArrayList" %> <%@ page import="java.util.HashMap" %> @@ -36,6 +36,8 @@ Interface to view and search all existing cards and card sets. <%@ page import="java.util.Map" %> <%@ page import="java.util.Set" %> <%@ page import="com.google.inject.Injector" %> +<%@ page import="com.google.inject.Key" %> +<%@ page import="net.socialgamer.cah.CahModule.IncludeInactiveCardsets" %> <%@ page import="net.socialgamer.cah.HibernateUtil" %> <%@ page import="net.socialgamer.cah.StartupUtils" %> <%@ page import="net.socialgamer.cah.db.PyxBlackCard" %> @@ -48,15 +50,16 @@ Interface to view and search all existing cards and card sets. ServletContext servletContext = pageContext.getServletContext(); Injector injector = (Injector) servletContext.getAttribute(StartupUtils.INJECTOR); -Properties props = injector.getInstance(Properties.class); +boolean includeInactive = injector.getInstance(Key.get(Boolean.TYPE, IncludeInactiveCardsets.class)); // cheap way to make sure we can close the hibernate session at the end of the page try { // load from db @SuppressWarnings("unchecked") List cardSets = hibernateSession - .createQuery(PyxCardSet.getCardsetQuery(props)) + .createQuery(PyxCardSet.getCardsetQuery(includeInactive)) .setReadOnly(true) + .setCacheable(true) .list(); // all of the data to send to the client @@ -72,6 +75,7 @@ try { Map cardSetsData = new HashMap(); data.put("cardSets", cardSetsData); + int i = 0; for (PyxCardSet cardSet: cardSets) { Map cardSetData = new HashMap(); cardSetData.put("name", cardSet.getName()); @@ -100,7 +104,7 @@ try { } cardSetData.put("blackCards", blackCardIds); - cardSetsData.put(cardSet.getWeight(), cardSetData); + cardSetsData.put(i++, cardSetData); } Map blackCardsData = new HashMap(); @@ -142,6 +146,7 @@ try { +