package com.perforce.spark; import java.util.HashMap; import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; import spark.Request; public class NavBar { private static SortedMap<String, NavBarItem> map = new TreeMap<>(); static { add(new NavBarItem("Browse", "browse")); add(new NavBarItem("Search", "search")); add(new NavBarItem("Deploy", "deploy")); } public static void add(NavBarItem item) { String id = item.getPage(); map.put(id, item); } public static Map<String, Object> attributes(String selected, Request req) { Map<String, Object> attributes = new HashMap<>(); attributes.put("navBar", navBar(selected)); attributes.put("title", title(selected)); attributes.put("login", login(req)); attributes.put("topPage", selected + ".ftl"); attributes.put("error_show", "none"); attributes.put("error_message", ""); return attributes; } private static String login(Request req) { String ticket = req.session().attribute(ConnectionSession.TICKET); if (ticket == null) { return "navLogin.ftl"; } else { return "navLogout.ftl"; } } private static String navBar(String selected) { StringBuilder form = new StringBuilder(); form.append("<ul class=\"nav navbar-nav\">"); for (String id : map.keySet()) { NavBarItem nav = map.get(id); if (id.equals(selected)) { form.append("<li class=\"active\">"); } else { form.append("<li>"); } form.append("<a href=\"/"); form.append(nav.getPage()); form.append("\">"); form.append(nav.getTitle()); form.append("</a>"); } form.append("</ul>"); return form.toString(); } private static String title(String id) { String title = ""; if (map.containsKey(id)) { title = map.get(id).getTitle(); } return title; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#6 | 14181 | Paul Allen | Lots of updates and refactoring. | ||
#5 | 13869 | Paul Allen |
- Fix logout when testing cookie. - Refactor ftl->html - Add local bootstrap |
||
#4 | 13798 | Paul Allen | Basic file upload and login/logout cookie tidyup | ||
#3 | 13728 | Paul Allen | Error support | ||
#2 | 13722 | Paul Allen | Login UX | ||
#1 | 13720 | Paul Allen | Perforce Asset Manager (PAM or P4AM) -- ideas |