Revize 35ab10b2
Přidáno uživatelem Pavel Fidranský před asi 6 roky(ů)
sources/imiger-core/src/main/java/cz/zcu/kiv/offscreen/servlets/api/GetDBDiagramData.java | ||
---|---|---|
1 |
package cz.zcu.kiv.offscreen.servlets.api; |
|
2 |
|
|
3 |
import cz.zcu.kiv.offscreen.servlets.BaseServlet; |
|
4 |
import cz.zcu.kiv.offscreen.user.DB; |
|
5 |
import cz.zcu.kiv.offscreen.user.Diagram; |
|
6 |
import org.apache.commons.lang3.StringUtils; |
|
7 |
import org.apache.logging.log4j.LogManager; |
|
8 |
import org.apache.logging.log4j.Logger; |
|
9 |
|
|
10 |
import javax.servlet.http.HttpServletRequest; |
|
11 |
import javax.servlet.http.HttpServletResponse; |
|
12 |
import java.io.IOException; |
|
13 |
|
|
14 |
/** |
|
15 |
* This class is used for loading diagram's graph JSON from database. |
|
16 |
*/ |
|
17 |
public class GetDBDiagramData extends BaseServlet { |
|
18 |
|
|
19 |
private static final Logger logger = LogManager.getLogger(); |
|
20 |
|
|
21 |
@Override |
|
22 |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { |
|
23 |
logger.debug("Processing request"); |
|
24 |
String diagramId = request.getParameter("id"); |
|
25 |
|
|
26 |
if (StringUtils.isBlank(diagramId)) { |
|
27 |
response.sendError(HttpServletResponse.SC_BAD_REQUEST); |
|
28 |
logger.debug("Diagram id is empty"); |
|
29 |
return; |
|
30 |
} |
|
31 |
|
|
32 |
DB db = new DB(getServletContext()); |
|
33 |
Diagram diagram = new Diagram(db, Integer.parseInt(diagramId)); |
|
34 |
|
|
35 |
if (!diagram.isPublic() && (!isLoggedIn(request) || (isLoggedIn(request) && diagram.getUserId() != getUserId(request)))) { |
|
36 |
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); |
|
37 |
logger.debug("User is unauthorized"); |
|
38 |
return; |
|
39 |
} |
|
40 |
|
|
41 |
String json = diagram.getDiagram().get("graph_json"); |
|
42 |
|
|
43 |
response.setContentType("application/json"); |
|
44 |
response.setCharacterEncoding("UTF-8"); |
|
45 |
response.setStatus(HttpServletResponse.SC_OK); |
|
46 |
response.getWriter().write(json); |
|
47 |
response.getWriter().flush(); |
|
48 |
logger.debug("Response OK"); |
|
49 |
} |
|
50 |
} |
sources/imiger-core/src/main/java/cz/zcu/kiv/offscreen/servlets/api/GetPrivateDiagrams.java | ||
---|---|---|
36 | 36 |
|
37 | 37 |
JsonArray jsonArray = new JsonArray(); |
38 | 38 |
for (Map<String, String> userDiagram : userDiagramList) { |
39 |
|
|
40 | 39 |
JsonObject jsonObject = new JsonObject(); |
41 | 40 |
jsonObject.addProperty("id", userDiagram.get("id")); |
42 | 41 |
jsonObject.addProperty("name", userDiagram.get("name")); |
43 |
|
|
42 |
jsonObject.addProperty("created", userDiagram.get("created")); |
|
43 |
jsonObject.addProperty("last_update", userDiagram.get("last_update")); |
|
44 | 44 |
jsonArray.add(jsonObject); |
45 | 45 |
} |
46 | 46 |
|
sources/imiger-core/src/main/webapp/css/common.css | ||
---|---|---|
1 | 1 |
body { |
2 | 2 |
font-family: 'Arial', sans-serif; |
3 |
font-size: 0.8em;
|
|
3 |
font-size: 0.8em;
|
|
4 | 4 |
margin: 0; |
5 |
background-color: #e8f4ff; |
|
6 |
overflow: hidden; |
|
5 |
background-color: #e8f4ff; |
|
7 | 6 |
} |
8 | 7 |
|
9 | 8 |
ul { |
sources/imiger-core/src/main/webapp/css/show-graph.css | ||
---|---|---|
1 |
body { |
|
2 |
overflow: hidden; |
|
3 |
} |
|
4 |
|
|
1 | 5 |
.graph-content { |
2 | 6 |
display: flex; |
3 | 7 |
height: calc(100vh - 60px - 43px); |
4 |
background-color: #fff;
|
|
8 |
background-color: #fff;
|
|
5 | 9 |
} |
6 | 10 |
|
7 | 11 |
.archetype-icon { |
sources/imiger-core/src/main/webapp/css/upload-files.css | ||
---|---|---|
1 |
.upload-form {
|
|
2 |
width: 200px;
|
|
3 |
margin: 20px auto;
|
|
4 |
padding: 10px;
|
|
5 |
background-color: #CFEAFE;
|
|
6 |
box-shadow: 3px 3px 10px #888;
|
|
1 |
.content {
|
|
2 |
max-width: 480px;
|
|
3 |
margin-top: 45px;
|
|
4 |
margin-left: auto;
|
|
5 |
margin-right: auto;
|
|
6 |
line-height: 1.8;
|
|
7 | 7 |
} |
8 | 8 |
|
9 |
.upload-form button[type="submit"] { |
|
9 |
.section { |
|
10 |
margin-bottom: 45px; |
|
11 |
padding-left: 30px; |
|
12 |
padding-right: 30px; |
|
13 |
} |
|
14 |
|
|
15 |
.section h2 { |
|
16 |
font-size: 1.4em; |
|
17 |
font-weight: normal; |
|
18 |
color: #0b548a; |
|
19 |
margin-top: 15px; |
|
20 |
margin-bottom: 30px; |
|
21 |
border-bottom: 1px solid; |
|
22 |
} |
|
23 |
|
|
24 |
.diagram-form button[type="submit"] { |
|
10 | 25 |
display: block; |
11 | 26 |
width: 100%; |
12 | 27 |
} |
28 |
.diagram-list-item { |
|
29 |
position: relative; |
|
30 |
} |
|
31 |
|
|
32 |
.diagram-list-item:not(:last-child) { |
|
33 |
margin-bottom: 15px; |
|
34 |
} |
|
35 |
|
|
36 |
.diagram-list-item a { |
|
37 |
display: block; |
|
38 |
color: #000; |
|
39 |
text-decoration: none; |
|
40 |
} |
|
41 |
|
|
42 |
.diagram-details { |
|
43 |
color: gray; |
|
44 |
font-size: 0.8em; |
|
45 |
margin-top: 0; |
|
46 |
margin-bottom: 0; |
|
47 |
} |
|
48 |
|
|
49 |
.diagram-details dt, |
|
50 |
.diagram-details dd { |
|
51 |
display: inline; |
|
52 |
} |
|
53 |
|
|
54 |
.diagram-details dd { |
|
55 |
margin-left: 0; |
|
56 |
margin-right: 15px; |
|
57 |
} |
|
58 |
|
|
59 |
.diagram-button-group { |
|
60 |
display: none; |
|
61 |
position: absolute; |
|
62 |
top: 5px; |
|
63 |
right: 0; |
|
64 |
} |
|
65 |
|
|
66 |
.diagram-list-item:focus .diagram-button-group, |
|
67 |
.diagram-list-item:hover .diagram-button-group { |
|
68 |
display: block; |
|
69 |
} |
|
13 | 70 |
|
14 |
.diagrams-menu { |
|
15 |
width: 200px; |
|
16 |
margin: 20px auto; |
|
17 |
padding: 10px; |
|
18 |
background-color: #CFEAFE; |
|
19 |
box-shadow: 3px 3px 10px #888; |
|
71 |
.diagram-button-group li { |
|
72 |
display: inline-block; |
|
20 | 73 |
} |
21 | 74 |
|
22 |
.diagrams-menu li { |
|
75 |
.diagram-button-group .button { |
|
76 |
width: 20px; |
|
23 | 77 |
height: 20px; |
78 |
padding: 0; |
|
79 |
background: transparent; |
|
80 |
border: 0; |
|
81 |
cursor: pointer; |
|
24 | 82 |
} |
25 | 83 |
|
26 |
.diagrams-menu li button { |
|
27 |
float: right; |
|
28 |
width: 20px; |
|
29 |
height: 20px; |
|
30 |
padding: 0; |
|
84 |
.diagram-button-group .delete-diagram-button { |
|
85 |
padding: 1px; |
|
86 |
vertical-align: 1px; |
|
31 | 87 |
} |
32 | 88 |
|
33 |
.diagrams-menu li img {
|
|
89 |
.diagram-button-group .button img {
|
|
34 | 90 |
max-width: 100%; |
35 | 91 |
} |
sources/imiger-core/src/main/webapp/js/uploadFilesApp.js | ||
---|---|---|
36 | 36 |
|
37 | 37 |
// private diagrams list |
38 | 38 |
const privateDiagramList = document.getElementById('privateDiagramList'); |
39 |
privateDiagramList.querySelectorAll('.remove-diagram-button').forEach(button => {
|
|
39 |
privateDiagramList.querySelectorAll('.delete-diagram-button').forEach(button => {
|
|
40 | 40 |
button.addEventListener('click', this._removeDiagram); |
41 | 41 |
}); |
42 | 42 |
|
... | ... | |
79 | 79 |
const data = await AJAX.getJSON(Constants.API.getPrivateDiagrams); |
80 | 80 |
|
81 | 81 |
data.forEach(diagram => { |
82 |
privateDiagramList.appendChild(DOM.h('li', {}, [ |
|
82 |
privateDiagramList.appendChild(DOM.h('li', { |
|
83 |
class: 'diagram-list-item', |
|
84 |
}, [ |
|
83 | 85 |
DOM.h('a', { |
84 | 86 |
href: app.homeUrl + 'graph?diagramId=' + diagram.id, |
85 | 87 |
innerText: diagram.name, |
86 | 88 |
}), |
87 |
DOM.h('a', { |
|
88 |
href: app.homeUrl + 'api/get-diagram-data?id=' + diagram.id, |
|
89 |
download: diagram.name + '.json', |
|
90 |
class: 'button download-diagram-button', |
|
89 |
DOM.h('dl', { |
|
90 |
class: 'diagram-details', |
|
91 | 91 |
}, [ |
92 |
DOM.h('img', { |
|
93 |
src: 'images/button_cancel.png', |
|
94 |
alt: 'stáhnout', |
|
92 |
DOM.h('dt', { |
|
93 |
innerText: 'created:', |
|
94 |
}), |
|
95 |
DOM.h('dd', {}, [ |
|
96 |
DOM.h('time', { |
|
97 |
innerText: diagram.created, |
|
98 |
}), |
|
99 |
]), |
|
100 |
DOM.h('dt', { |
|
101 |
innerText: 'updated:', |
|
95 | 102 |
}), |
103 |
DOM.h('dd', {}, [ |
|
104 |
DOM.h('time', { |
|
105 |
innerText: diagram.last_update, |
|
106 |
}), |
|
107 |
]), |
|
96 | 108 |
]), |
97 |
DOM.h('button', { |
|
98 |
class: 'button remove-diagram-button', |
|
99 |
'data-id': diagram.id, |
|
100 |
'data-name': diagram.name, |
|
101 |
onClick: this._removeDiagram, |
|
109 |
DOM.h('ul', { |
|
110 |
class: 'diagram-button-group', |
|
102 | 111 |
}, [ |
103 |
DOM.h('img', { |
|
104 |
src: 'images/button_cancel.png', |
|
105 |
alt: 'odstranit', |
|
106 |
}), |
|
112 |
DOM.h('li', {}, [ |
|
113 |
DOM.h('a', { |
|
114 |
href: app.homeUrl + 'api/get-diagram-data?id=' + diagram.id, |
|
115 |
download: diagram.name + '.json', |
|
116 |
title: 'download diagram as raw JSON', |
|
117 |
class: 'button download-diagram-button', |
|
118 |
}, [ |
|
119 |
DOM.h('img', { |
|
120 |
src: 'images/icomoon/download3.svg', |
|
121 |
alt: 'download diagram icon', |
|
122 |
}), |
|
123 |
]), |
|
124 |
]), |
|
125 |
DOM.t(' '), |
|
126 |
DOM.h('li', {}, [ |
|
127 |
DOM.h('button', { |
|
128 |
class: 'button delete-diagram-button', |
|
129 |
title: 'delete diagram', |
|
130 |
'data-id': diagram.id, |
|
131 |
'data-name': diagram.name, |
|
132 |
onClick: this._removeDiagram, |
|
133 |
}, [ |
|
134 |
DOM.h('img', { |
|
135 |
src: 'images/icomoon/cross.svg', |
|
136 |
alt: 'delete diagram icon', |
|
137 |
}), |
|
138 |
]), |
|
139 |
]), |
|
107 | 140 |
]), |
108 | 141 |
])); |
109 | 142 |
}); |
sources/imiger-core/src/main/webapp/uploadFiles.jsp | ||
---|---|---|
43 | 43 |
<header class="header" id="header"> |
44 | 44 |
<img src="images/logo_cs.svg" class="header-logo" alt="logo of University of West Bohemia" title="University of West Bohemia"> |
45 | 45 |
|
46 |
<h2 class="header-title">Interactive Multimodal Graph Explorer</h2>
|
|
46 |
<h1 class="header-title">Interactive Multimodal Graph Explorer</h1>
|
|
47 | 47 |
|
48 | 48 |
<div class="user-menu loggedInOnly"> |
49 | 49 |
<span class="username" id="usernameLabel">${user.username}</span> |
... | ... | |
56 | 56 |
</div> |
57 | 57 |
</header> |
58 | 58 |
|
59 |
<main> |
|
60 |
<div class="upload-form">
|
|
61 |
<h3>New diagram</h3>
|
|
59 |
<main class="content">
|
|
60 |
<section class="section">
|
|
61 |
<h2>New diagram</h2>
|
|
62 | 62 |
|
63 | 63 |
<c:if test="${not empty errorMessage}"> |
64 | 64 |
<p class="alert">${errorMessage}</p> |
65 | 65 |
</c:if> |
66 | 66 |
|
67 |
<form method="post" enctype="multipart/form-data"> |
|
67 |
<form method="post" enctype="multipart/form-data" class="diagram-form">
|
|
68 | 68 |
<div class="form-field"> |
69 | 69 |
<label for="file">Select JSON data file:</label><br> |
70 | 70 |
<input type="file" name="file" id="file"> |
... | ... | |
80 | 80 |
|
81 | 81 |
<button id="btnLoad" type="submit">Start visualization</button> |
82 | 82 |
</form> |
83 |
</div>
|
|
83 |
</section>
|
|
84 | 84 |
|
85 |
<div class="diagrams-menu loggedInOnly">
|
|
86 |
<h3>My diagrams</h3>
|
|
85 |
<section class="section loggedInOnly">
|
|
86 |
<h2>My diagrams</h2>
|
|
87 | 87 |
|
88 |
<ul id="privateDiagramList"> |
|
88 |
<ul class="diagram-list" id="privateDiagramList">
|
|
89 | 89 |
<c:forEach items="${diagramsPrivate}" var="diagram"> |
90 |
<li> |
|
90 |
<li class="diagram-list-item">
|
|
91 | 91 |
<a href="${APP_HOME_URL}graph?diagramId=${diagram.id}">${diagram.name}</a> |
92 | 92 |
|
93 |
<a href="${APP_HOME_URL}api/get-diagram-data?id=${diagram.id}" download="${diagram.name}.json" class="button download-diagram-button"> |
|
94 |
<img src="images/button_cancel.png" alt="stáhnout"> |
|
95 |
</a> |
|
96 |
<button class="button remove-diagram-button" data-id="${diagram.id}" data-name="${diagram.name}"> |
|
97 |
<img src="images/button_cancel.png" alt="odstranit"> |
|
98 |
</button> |
|
93 |
<dl class="diagram-details"> |
|
94 |
<dt>created:</dt> |
|
95 |
<dd><time>${diagram.created}</time></dd> |
|
96 |
|
|
97 |
<dt>updated:</dt> |
|
98 |
<dd><time>${diagram.last_update}</time></dd> |
|
99 |
</dl> |
|
100 |
|
|
101 |
<ul class="diagram-button-group"> |
|
102 |
<li> |
|
103 |
<a href="${APP_HOME_URL}api/get-diagram-data?id=${diagram.id}" download="${diagram.name}.json" title="download diagram as raw JSON" class="button download-diagram-button"> |
|
104 |
<img src="images/icomoon/download3.svg" alt="download diagram icon"> |
|
105 |
</a> |
|
106 |
</li> |
|
107 |
<li> |
|
108 |
<button class="button delete-diagram-button" title="delete diagram" data-id="${diagram.id}" data-name="${diagram.name}"> |
|
109 |
<img src="images/icomoon/cross.svg" alt="delete diagram icon"> |
|
110 |
</button> |
|
111 |
</li> |
|
112 |
</ul> |
|
99 | 113 |
</li> |
100 | 114 |
</c:forEach> |
101 | 115 |
</ul> |
102 |
</div>
|
|
116 |
</section>
|
|
103 | 117 |
|
104 |
<div class="diagrams-menu">
|
|
105 |
<h3>Public diagrams</h3>
|
|
118 |
<section class="section">
|
|
119 |
<h2>Public diagrams</h2>
|
|
106 | 120 |
|
107 |
<ul id="publicDiagramList"> |
|
121 |
<ul class="diagram-list" id="publicDiagramList">
|
|
108 | 122 |
<c:forEach items="${diagramsPublic}" var="diagram"> |
109 |
<li> |
|
123 |
<li class="diagram-list-item">
|
|
110 | 124 |
<a href="${APP_HOME_URL}graph?diagramId=${diagram.id}">${diagram.name}</a> |
125 |
|
|
126 |
<dl class="diagram-details"> |
|
127 |
<dt>created:</dt> |
|
128 |
<dd><time>${diagram.created}</time></dd> |
|
129 |
|
|
130 |
<dt>updated:</dt> |
|
131 |
<dd><time>${diagram.last_update}</time></dd> |
|
132 |
</dl> |
|
133 |
|
|
134 |
<ul class="diagram-button-group"> |
|
135 |
<li> |
|
136 |
<a href="${APP_HOME_URL}api/get-diagram-data?id=${diagram.id}" download="${diagram.name}.json" title="download diagram as raw JSON" class="button download-diagram-button"> |
|
137 |
<img src="images/icomoon/download3.svg" alt="download diagram icon"> |
|
138 |
</a> |
|
139 |
</li> |
|
140 |
</ul> |
|
111 | 141 |
</li> |
112 | 142 |
</c:forEach> |
113 | 143 |
</ul> |
114 |
</div>
|
|
144 |
</section>
|
|
115 | 145 |
</main> |
116 | 146 |
|
117 | 147 |
<script type="module"> |
sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/GetDBDiagramData.java | ||
---|---|---|
1 |
package cz.zcu.kiv.offscreen.servlets.api; |
|
2 |
|
|
3 |
import cz.zcu.kiv.offscreen.servlets.BaseServlet; |
|
4 |
import cz.zcu.kiv.offscreen.user.DB; |
|
5 |
import cz.zcu.kiv.offscreen.user.Diagram; |
|
6 |
import org.apache.commons.lang3.StringUtils; |
|
7 |
import org.apache.logging.log4j.LogManager; |
|
8 |
import org.apache.logging.log4j.Logger; |
|
9 |
|
|
10 |
import javax.servlet.http.HttpServletRequest; |
|
11 |
import javax.servlet.http.HttpServletResponse; |
|
12 |
import java.io.IOException; |
|
13 |
|
|
14 |
/** |
|
15 |
* This class is used for loading diagram's graph JSON from database. |
|
16 |
*/ |
|
17 |
public class GetDBDiagramData extends BaseServlet { |
|
18 |
|
|
19 |
private static final Logger logger = LogManager.getLogger(); |
|
20 |
|
|
21 |
@Override |
|
22 |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { |
|
23 |
logger.debug("Processing request"); |
|
24 |
String diagramId = request.getParameter("id"); |
|
25 |
|
|
26 |
if (StringUtils.isBlank(diagramId)) { |
|
27 |
response.sendError(HttpServletResponse.SC_BAD_REQUEST); |
|
28 |
logger.debug("Diagram id is empty"); |
|
29 |
return; |
|
30 |
} |
|
31 |
|
|
32 |
DB db = new DB(getServletContext()); |
|
33 |
Diagram diagram = new Diagram(db, Integer.parseInt(diagramId)); |
|
34 |
|
|
35 |
if (!diagram.isPublic() && (!isLoggedIn(request) || (isLoggedIn(request) && diagram.getUserId() != getUserId(request)))) { |
|
36 |
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); |
|
37 |
logger.debug("User is unauthorized"); |
|
38 |
return; |
|
39 |
} |
|
40 |
|
|
41 |
String json = diagram.getDiagram().get("graph_json"); |
|
42 |
|
|
43 |
response.setContentType("application/json"); |
|
44 |
response.setCharacterEncoding("UTF-8"); |
|
45 |
response.setStatus(HttpServletResponse.SC_OK); |
|
46 |
response.getWriter().write(json); |
|
47 |
response.getWriter().flush(); |
|
48 |
logger.debug("Response OK"); |
|
49 |
} |
|
50 |
} |
Také k dispozici: Unified diff
fix #20: diagram can be downloaded as raw JSON