src/main/java/com/webcheckers/ui/GetHomeRoute.java
/**
     * Render the WebCheckers Home page.
     *
     * @param request
     *   the HTTP request
     * @param response
     *   the HTTP response
     *
     * @return
     *   the rendered HTML for the Home page
     */
Render the WebCheckers Home page.
@param request
the HTTP request
@param response
the HTTP response

@return
the rendered HTML for the Home page
Render the WebCheckers Home page . @param request the HTTP request @param response the HTTP response @return the rendered HTML for the Home page
@Override
    public Object handle(Request request, Response response) {
        final Session httpSession = request.session();
        LOG.finer("GetHomeRoute is invoked.");
        if(httpSession.attribute(SessionAttributes.PLAYER) == null) {
            Map<String, Object> vm = new HashMap<>();
            vm.put(VMAttributes.TITLE, WELCOME_STR);
            vm.put(VMAttributes.MESSAGE, WELCOME_MSG);
            vm.put(VMAttributes.NUM_PLAYERS, Application.playerLobby.getNum_logged_in());
            return templateEngine.render(new ModelAndView(vm, "home.ftl"));
        } else {
            Map<String, Object> vm = new HashMap<>();
            Game game = Application.gameCenter.getGameByPlayer(httpSession.attribute(SessionAttributes.PLAYER));
            if (game != null) {
                if (game.isGameOver()){
                    Application.gameCenter.endGame(game);
                }
                else {
                    httpSession.attribute("ID", game.gameid);
                    response.redirect(GAME_URL);
                    return null;
                }
            }
            vm.put(VMAttributes.TITLE, WELCOME_STR);
            if (httpSession.attribute(SessionAttributes.ERROR) != null){
                vm.put(VMAttributes.MESSAGE, httpSession.attribute(SessionAttributes.ERROR));
                httpSession.attribute(SessionAttributes.ERROR, null);
            } else {
                vm.put(VMAttributes.MESSAGE, WELCOME_MSG);
            }
            vm.put(VMAttributes.CURRENT_USER, httpSession.attribute(SessionAttributes.PLAYER));
            vm.put(VMAttributes.SIGNED, Application.playerLobby.get_logged_names());
            vm.put(VMAttributes.PLAYING, Application.playerLobby.get_playing());
            vm.put(VMAttributes.SPECTATING, Application.playerLobby.get_spectating());
            return templateEngine.render(new ModelAndView(vm, "home.ftl"));
        }
    }
@ Override public Object handle ( Request request , Response response ) { final Session httpSession = request . session ( ) ; LOG . finer ( "GetHomeRoute is invoked." ) ; if ( httpSession . attribute ( SessionAttributes . PLAYER ) == null ) { Map < String , Object > vm = new HashMap < > ( ) ; vm . put ( VMAttributes . TITLE , WELCOME_STR ) ; vm . put ( VMAttributes . MESSAGE , WELCOME_MSG ) ; vm . put ( VMAttributes . NUM_PLAYERS , Application . playerLobby . getNum_logged_in ( ) ) ; return templateEngine . render ( new ModelAndView ( vm , "home.ftl" ) ) ; } else { Map < String , Object > vm = new HashMap < > ( ) ; Game game = Application . gameCenter . getGameByPlayer ( httpSession . attribute ( SessionAttributes . PLAYER ) ) ; if ( game != null ) { if ( game . isGameOver ( ) ) { Application . gameCenter . endGame ( game ) ; } else { httpSession . attribute ( "ID" , game . gameid ) ; response . redirect ( GAME_URL ) ; return null ; } } vm . put ( VMAttributes . TITLE , WELCOME_STR ) ; if ( httpSession . attribute ( SessionAttributes . ERROR ) != null ) { vm . put ( VMAttributes . MESSAGE , httpSession . attribute ( SessionAttributes . ERROR ) ) ; httpSession . attribute ( SessionAttributes . ERROR , null ) ; } else { vm . put ( VMAttributes . MESSAGE , WELCOME_MSG ) ; } vm . put ( VMAttributes . CURRENT_USER , httpSession . attribute ( SessionAttributes . PLAYER ) ) ; vm . put ( VMAttributes . SIGNED , Application . playerLobby . get_logged_names ( ) ) ; vm . put ( VMAttributes . PLAYING , Application . playerLobby . get_playing ( ) ) ; vm . put ( VMAttributes . SPECTATING , Application . playerLobby . get_spectating ( ) ) ; return templateEngine . render ( new ModelAndView ( vm , "home.ftl" ) ) ; } }
Render the WebCheckers Home page.
Render the WebCheckers Home page .
// display a user message in the Home page // render the View