Revize f2181c0e
Přidáno uživatelem Tomáš Šimandl před více než 6 roky(ů)
sources/src/main/java/cz/zcu/kiv/offscreen/servlets/LoadGraphData.java | ||
---|---|---|
8 | 8 |
import cz.zcu.kiv.offscreen.graph.loader.GraphJSONDataLoader; |
9 | 9 |
import cz.zcu.kiv.offscreen.graph.loader.JSONConfigLoader; |
10 | 10 |
import cz.zcu.kiv.offscreen.loader.configuration.ConfigurationLoader; |
11 |
import cz.zcu.kiv.offscreen.user.DB; |
|
12 |
import cz.zcu.kiv.offscreen.user.Diagram; |
|
11 | 13 |
import net.sf.json.JSONObject; |
12 | 14 |
|
13 | 15 |
import javax.servlet.ServletException; |
... | ... | |
35 | 37 |
|
36 | 38 |
if (request.getSession().getAttribute("demo_id") == null) { |
37 | 39 |
|
38 |
String jsonToDisplay = (String)request.getSession().getAttribute("json_graph"); |
|
39 |
request.getSession().removeAttribute("json_graph"); |
|
40 |
String diagram_id = request.getParameter("diagramId"); |
|
40 | 41 |
|
41 |
if (!Strings.isNullOrEmpty(jsonToDisplay)) { |
|
42 |
GraphManager graphManager = new GraphJSONDataLoader(jsonToDisplay).LoadData(); |
|
43 |
String configLocation = ConfigurationLoader.getConfigLocation(request.getServletContext()); |
|
44 |
JSONConfigLoader configLoader = new JSONConfigLoader(graphManager, configLocation); |
|
45 |
Graph graph = graphManager.createGraph(configLoader); |
|
46 |
GraphExport export = new GraphExport(graph); |
|
47 |
JSONObject json = JSONObject.fromObject(export); |
|
42 |
if (diagram_id == null) { |
|
43 |
String jsonToDisplay; |
|
44 |
jsonToDisplay = (String)request.getSession().getAttribute("json_graph"); |
|
45 |
request.getSession().removeAttribute("json_graph"); |
|
48 | 46 |
|
49 |
String resultJsonString = json.toString(); |
|
47 |
if (!Strings.isNullOrEmpty(jsonToDisplay)) { |
|
48 |
GraphManager graphManager = new GraphJSONDataLoader(jsonToDisplay).LoadData(); |
|
49 |
String configLocation = ConfigurationLoader.getConfigLocation(request.getServletContext()); |
|
50 |
JSONConfigLoader configLoader = new JSONConfigLoader(graphManager, configLocation); |
|
51 |
Graph graph = graphManager.createGraph(configLoader); |
|
52 |
GraphExport export = new GraphExport(graph); |
|
53 |
JSONObject json = JSONObject.fromObject(export); |
|
54 |
|
|
55 |
String resultJsonString = json.toString(); |
|
56 |
|
|
57 |
response.getWriter().write(resultJsonString); |
|
58 |
} else { |
|
59 |
response.getWriter().write(""); |
|
60 |
} |
|
50 | 61 |
|
51 |
response.getWriter().write(resultJsonString); |
|
52 | 62 |
} else { |
53 |
response.getWriter().write(""); |
|
63 |
// TODO check user permissions to this graph |
|
64 |
Integer diagramId = Integer.parseInt(diagram_id); |
|
65 |
|
|
66 |
DB db = new DB(getServletContext()); |
|
67 |
Diagram diagram = new Diagram(db, diagramId); |
|
68 |
response.getWriter().write(diagram.getJsonDiagram()); |
|
54 | 69 |
} |
70 |
|
|
71 |
|
|
55 | 72 |
} else { |
56 | 73 |
String demoId = request.getSession().getAttribute("demo_id").toString(); |
57 | 74 |
String path = "/WEB-INF" + File.separator + "demoDiagram" + File.separator + demoId + ".json"; |
sources/src/main/java/cz/zcu/kiv/offscreen/user/Diagram.java | ||
---|---|---|
50 | 50 |
return -1; |
51 | 51 |
} |
52 | 52 |
|
53 |
public String getJsonDiagram(){ |
|
54 |
if(this.id < 0) return ""; |
|
55 |
|
|
56 |
String qy = "SELECT graph_json FROM diagram WHERE id = '" + this.id + "'"; |
|
57 |
ResultSet rs = db.exQuery(qy); |
|
58 |
|
|
59 |
try{ |
|
60 |
if (rs != null && rs.next()) { |
|
61 |
return rs.getString("graph_json"); |
|
62 |
} |
|
63 |
} catch (SQLException e){ |
|
64 |
e.printStackTrace(); |
|
65 |
} |
|
66 |
return ""; |
|
67 |
} |
|
68 |
|
|
53 | 69 |
/** |
54 | 70 |
* Method return map of values of actual diagram or empty map if id of diagram is invalid. |
55 | 71 |
* |
sources/src/main/webapp/logged_user_menu.jsp | ||
---|---|---|
7 | 7 |
<ul> |
8 | 8 |
<c:forEach items="${diagramNames}" var="diagramName"> |
9 | 9 |
<li id="diagram_id_${diagramName.id}"> |
10 |
<a href="<%= getServletContext().getInitParameter("HOME_URL") %>?diagram_id=${diagramName.id}&diagram_hash=${diagramName.hash}">${diagramName.name}</a><a href="#" onclick="return deleteDiagram(${diagramName.id});"><img src="images/button_cancel.png" alt="odstranit" class="imgDelete"/></a>
|
|
10 |
<a href="/graph?diagramId=${diagramPublic.id}">${diagramName.name}</a><a href="#" onclick="return deleteDiagram(${diagramName.id});"><img src="images/button_cancel.png" alt="odstranit" class="imgDelete"/></a>
|
|
11 | 11 |
</li> |
12 | 12 |
</c:forEach> |
13 | 13 |
<li id="diagram_id_new"> |
... | ... | |
21 | 21 |
<ul> |
22 | 22 |
<c:forEach items="${diagramPublic}" var="diagramPublic"> |
23 | 23 |
<li id="public_diagram_id_${diagramPublic.id}"> |
24 |
<a href="<%= getServletContext().getInitParameter("HOME_URL") %>?diagram_id=${diagramPublic.id}&diagram_hash=${diagramPublic.hash}">${diagramPublic.name}</a>
|
|
24 |
<a href="/graph?diagramId=${diagramPublic.id}">${diagramPublic.name}</a>
|
|
25 | 25 |
</li> |
26 | 26 |
</c:forEach> |
27 | 27 |
</ul> |
sources/src/main/webapp/showGraph.jsp | ||
---|---|---|
227 | 227 |
app.HOME_URL = '<%=getPath%>imiger/'; |
228 | 228 |
|
229 | 229 |
$(document).ready(function() { |
230 |
var loaderFn = app.diagramLoader('<%=request.getParameter("diagram_id")%>', '<%=request.getParameter("diagram_hash")%>');
|
|
230 |
var loaderFn = app.diagramLoader('<%=request.getParameter("diagramId")%>', '<%=request.getParameter("diagram_hash")%>');
|
|
231 | 231 |
|
232 | 232 |
app.run(loaderFn); |
233 | 233 |
}); |
Také k dispozici: Unified diff
loading of saved diagrams