1 | <%-- $Id7 $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2017 Nicklas Nordborg |
---|
4 | |
---|
5 | This file is part of BASE - BioArray Software Environment. |
---|
6 | Available at http://base.thep.lu.se/ |
---|
7 | |
---|
8 | BASE is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU General Public License |
---|
10 | as published by the Free Software Foundation; either version 3 |
---|
11 | of the License, or (at your option) any later version. |
---|
12 | |
---|
13 | BASE is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | GNU General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with BASE. If not, see <http://www.gnu.org/licenses/>. |
---|
20 | ------------------------------------------------------------------ |
---|
21 | |
---|
22 | @author Nicklas |
---|
23 | --%> |
---|
24 | <%@ page pageEncoding="UTF-8" session="false" |
---|
25 | import="net.sf.basedb.core.SessionControl" |
---|
26 | import="net.sf.basedb.core.DbControl" |
---|
27 | import="net.sf.basedb.core.Item" |
---|
28 | import="net.sf.basedb.core.ItemContext" |
---|
29 | import="net.sf.basedb.core.Permission" |
---|
30 | import="net.sf.basedb.core.UserDevice" |
---|
31 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
32 | import="net.sf.basedb.core.PluginDefinition" |
---|
33 | import="net.sf.basedb.core.plugin.GuiContext" |
---|
34 | import="net.sf.basedb.core.plugin.Plugin" |
---|
35 | import="net.sf.basedb.core.Project" |
---|
36 | import="net.sf.basedb.core.Session" |
---|
37 | import="net.sf.basedb.core.ItemQuery" |
---|
38 | import="net.sf.basedb.core.ItemResultList" |
---|
39 | import="net.sf.basedb.core.query.Orders" |
---|
40 | import="net.sf.basedb.core.query.Hql" |
---|
41 | import="net.sf.basedb.util.GeoLocation" |
---|
42 | import="net.sf.basedb.util.Values" |
---|
43 | import="net.sf.basedb.util.HttpUtil" |
---|
44 | import="net.sf.basedb.clients.web.Base" |
---|
45 | import="net.sf.basedb.clients.web.PermissionUtil" |
---|
46 | import="net.sf.basedb.clients.web.util.HTML" |
---|
47 | import="net.sf.basedb.util.formatter.Formatter" |
---|
48 | import="net.sf.basedb.clients.web.formatter.FormatterFactory" |
---|
49 | import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
---|
50 | import="net.sf.basedb.clients.web.extensions.JspContext" |
---|
51 | import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer" |
---|
52 | import="net.sf.basedb.clients.web.extensions.toolbar.ButtonAction" |
---|
53 | import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil" |
---|
54 | import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
---|
55 | import="java.util.Date" |
---|
56 | import="java.util.Collections" |
---|
57 | import="java.util.List" |
---|
58 | import="java.util.Map" |
---|
59 | import="java.util.Set" |
---|
60 | %> |
---|
61 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
62 | <%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %> |
---|
63 | <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
---|
64 | <%@ taglib prefix="p" uri="/WEB-INF/path.tld" %> |
---|
65 | <%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %> |
---|
66 | <%! |
---|
67 | private static final Item itemType = Item.USERDEVICE; |
---|
68 | private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM); |
---|
69 | %> |
---|
70 | <% |
---|
71 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
72 | final String ID = sc.getId(); |
---|
73 | final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null); |
---|
74 | final int itemId = cc.getId(); |
---|
75 | final String tab = Values.getString(request.getParameter("tab"), "properties"); |
---|
76 | final float scale = Base.getScale(sc); |
---|
77 | final DbControl dc = sc.newDbControl(); |
---|
78 | try |
---|
79 | { |
---|
80 | Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc); |
---|
81 | Formatter<Date> dateTimeFormatter = FormatterFactory.getDateTimeFormatter(sc); |
---|
82 | Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext); |
---|
83 | |
---|
84 | String title = null; |
---|
85 | final UserDevice device = UserDevice.getById(dc, itemId); |
---|
86 | String mapURL = GeoLocation.getURLToMap(device.getLocationLatitude(), device.getLocationLongitude()); |
---|
87 | final boolean writePermission = device.hasPermission(Permission.WRITE); |
---|
88 | final boolean deletePermission = device.hasPermission(Permission.DELETE); |
---|
89 | JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, device); |
---|
90 | ExtensionsInvoker<ButtonAction> invoker = ToolbarUtil.useExtensions(jspContext); |
---|
91 | %> |
---|
92 | <base:page title="<%=title%>" id="view-page"> |
---|
93 | <base:head scripts="table.js,tabcontrol-2.js,~devices.js" styles="table.css,toolbar.css,headertabcontrol.css,path.css"> |
---|
94 | <ext:scripts context="<%=jspContext%>" /> |
---|
95 | <ext:stylesheets context="<%=jspContext%>" /> |
---|
96 | </base:head> |
---|
97 | <base:body> |
---|
98 | <p:path><p:pathelement |
---|
99 | title="Devices" href="<%="index.jsp?ID="+ID%>" |
---|
100 | /><p:pathelement title="<%=HTML.encodeTags(device.getName())%>" |
---|
101 | /></p:path> |
---|
102 | <div id="page-data" data-item-id="<%=itemId%>"></div> |
---|
103 | |
---|
104 | <t:tabcontrol |
---|
105 | id="main" |
---|
106 | subclass="content mastertabcontrol" |
---|
107 | active="<%=tab%>"> |
---|
108 | <t:tab id="properties" title="Properties"> |
---|
109 | <div> |
---|
110 | <table class="fullform bottomborder"> |
---|
111 | <tr> |
---|
112 | <th class="itemstatus"> |
---|
113 | </th> |
---|
114 | <td style="padding: 0px;"> |
---|
115 | <tbl:toolbar subclass="bottomborder bg-filled-50"> |
---|
116 | <tbl:button |
---|
117 | id="btnEdit" |
---|
118 | disabled="<%=!writePermission%>" |
---|
119 | image="edit.png" |
---|
120 | title="Edit…" |
---|
121 | tooltip="<%=writePermission ? "Edit this device" : "You do not have permission to edit this device"%>" |
---|
122 | /> |
---|
123 | <tbl:button |
---|
124 | id="btnDelete" |
---|
125 | disabled="<%=!deletePermission%>" |
---|
126 | image="delete.png" |
---|
127 | title="Delete" |
---|
128 | tooltip="<%=deletePermission ? "Delete this device" : "You do not have permission to delete this device"%>" |
---|
129 | /> |
---|
130 | <tbl:button |
---|
131 | id="btnExport" |
---|
132 | image="export.png" |
---|
133 | data-plugin-type="EXPORT" |
---|
134 | title="Export…" |
---|
135 | tooltip="Export data" |
---|
136 | visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>" |
---|
137 | /> |
---|
138 | <tbl:button |
---|
139 | id="btnRunPlugin" |
---|
140 | image="runplugin.png" |
---|
141 | data-plugin-type="OTHER" |
---|
142 | title="Run plugin…" |
---|
143 | tooltip="Run a plugin" |
---|
144 | visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>" |
---|
145 | /> |
---|
146 | <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" |
---|
147 | wrapper="<%=new PrefixSuffixRenderer<ButtonAction>(jspContext, "<td>", "</td>") %>"/> |
---|
148 | <tbl:button |
---|
149 | image="help.png" |
---|
150 | subclass="auto-init" |
---|
151 | data-auto-init="help" |
---|
152 | data-help-id="device.view.properties" |
---|
153 | title="Help…" |
---|
154 | tooltip="Get help about this page" |
---|
155 | /> |
---|
156 | </tbl:toolbar> |
---|
157 | </td> |
---|
158 | </tr> |
---|
159 | <tr> |
---|
160 | <th>Name</th> |
---|
161 | <td><%=HTML.encodeTags(device.getName())%></td> |
---|
162 | </tr> |
---|
163 | <tr> |
---|
164 | <th>Verified</th> |
---|
165 | <td><%=device.isVerified() ? "Yes" : "No"%></td> |
---|
166 | </tr> |
---|
167 | <tr> |
---|
168 | <th>Registered</th> |
---|
169 | <td><%=dateFormatter.format(device.getEntryDate())%></td> |
---|
170 | </tr> |
---|
171 | <tr> |
---|
172 | <th>Last used</th> |
---|
173 | <td><%=dateTimeFormatter.format(device.getLastUsed())%></td> |
---|
174 | </tr> |
---|
175 | <tr> |
---|
176 | <th>Last remote ID</th> |
---|
177 | <td><%=HTML.encodeTags(device.getLastRemoteId())%></td> |
---|
178 | </tr> |
---|
179 | <tr> |
---|
180 | <th>Location</th> |
---|
181 | <td><%=HTML.encodeTags(device.getLocation())%> |
---|
182 | <base:icon href="<%=mapURL%>" image="map.png" tooltip="Show map" visible="<%=mapURL != null %>" /> |
---|
183 | </td> |
---|
184 | </tr> |
---|
185 | <tr> |
---|
186 | <th>User</th> |
---|
187 | <td><base:propertyvalue item="<%=device%>" property="user" /></td> |
---|
188 | </tr> |
---|
189 | <tr> |
---|
190 | <th>Client application</th> |
---|
191 | <td><base:propertyvalue item="<%=device%>" property="client" /></td> |
---|
192 | </tr> |
---|
193 | <tr> |
---|
194 | <th>User agent</th> |
---|
195 | <td><%=HTML.encodeTags(HttpUtil.getSummaryOfUserAgent(device.getUserAgent()))%></td> |
---|
196 | </tr> |
---|
197 | <tr> |
---|
198 | <th>User agent (raw)</th> |
---|
199 | <td><%=HTML.encodeTags(device.getUserAgent())%></td> |
---|
200 | </tr> |
---|
201 | <tr> |
---|
202 | <th>Permissions</th> |
---|
203 | <td><%=PermissionUtil.getFullPermissionNames(device)%></td> |
---|
204 | </tr> |
---|
205 | <tr> |
---|
206 | <th>Description</th> |
---|
207 | <td><%=HTML.niceFormat(device.getDescription())%></td> |
---|
208 | </tr> |
---|
209 | </table> |
---|
210 | </div> |
---|
211 | |
---|
212 | <% |
---|
213 | ItemQuery<Session> sessionQuery = device.getSessions(); |
---|
214 | sessionQuery.order(Orders.desc(Hql.property("loginTime"))); |
---|
215 | sessionQuery.setMaxResults(10); |
---|
216 | ItemResultList<Session> sessions = sessionQuery.list(dc); |
---|
217 | %> |
---|
218 | <base:section |
---|
219 | id="sessions" |
---|
220 | title="<%="Recent sessions with this device (max 10)"%>" |
---|
221 | context="<%=cc%>" |
---|
222 | > |
---|
223 | <% |
---|
224 | if (sessions.size() == 0) |
---|
225 | { |
---|
226 | %> |
---|
227 | <div class="messagecontainer note"> |
---|
228 | There are no registered sessions with this device. |
---|
229 | </div> |
---|
230 | <% |
---|
231 | } |
---|
232 | else |
---|
233 | { |
---|
234 | %> |
---|
235 | <tbl:table |
---|
236 | id="tbl.sessions" |
---|
237 | columns="all" |
---|
238 | > |
---|
239 | <tbl:columndef |
---|
240 | id="loginTime" |
---|
241 | title="Login time" |
---|
242 | /> |
---|
243 | <tbl:columndef |
---|
244 | id="logoutTime" |
---|
245 | title="Logout time" |
---|
246 | /> |
---|
247 | <tbl:columndef |
---|
248 | id="authenticationMethod" |
---|
249 | title="Authentication method" |
---|
250 | /> |
---|
251 | <tbl:columndef |
---|
252 | id="impersonated" |
---|
253 | title="Impersonated" |
---|
254 | /> |
---|
255 | <tbl:columndef |
---|
256 | id="remoteId" |
---|
257 | title="Remote ID" |
---|
258 | /> |
---|
259 | <tbl:columndef |
---|
260 | id="location" |
---|
261 | title="Location" |
---|
262 | /> |
---|
263 | <tbl:columndef |
---|
264 | id="comment" |
---|
265 | title="Comment" |
---|
266 | /> |
---|
267 | <tbl:data> |
---|
268 | <tbl:headers> |
---|
269 | <tbl:headerrow> |
---|
270 | <tbl:columnheaders /> |
---|
271 | </tbl:headerrow> |
---|
272 | </tbl:headers> |
---|
273 | <tbl:rows> |
---|
274 | <% |
---|
275 | for (Session item : sessions) |
---|
276 | { |
---|
277 | %> |
---|
278 | <tbl:row> |
---|
279 | <tbl:cell column="loginTime"><%=dateTimeFormatter.format(item.getLoginTime())%></tbl:cell> |
---|
280 | <tbl:cell column="logoutTime"><%=dateTimeFormatter.format(item.getLogoutTime())%></tbl:cell> |
---|
281 | <tbl:cell column="authenticationMethod"><%=HTML.encodeTags(item.getAuthenticationMethod())%></tbl:cell> |
---|
282 | <tbl:cell column="impersonated"><%=item.getImpersonated()%></tbl:cell> |
---|
283 | <tbl:cell column="remoteId"><%=HTML.encodeTags(item.getRemoteId())%></tbl:cell> |
---|
284 | <tbl:cell column="location"><%=HTML.encodeTags(item.getLocation())%> |
---|
285 | <% mapURL = GeoLocation.getURLToMap(item.getLocationLatitude(), item.getLocationLongitude()); %> |
---|
286 | <base:icon href="<%=mapURL%>" image="map.png" tooltip="Show map" visible="<%=mapURL != null %>"/> |
---|
287 | </tbl:cell> |
---|
288 | <tbl:cell column="comment"><%=HTML.encodeTags(item.getLoginComment())%></tbl:cell> |
---|
289 | </tbl:row> |
---|
290 | <% |
---|
291 | } |
---|
292 | %> |
---|
293 | </tbl:rows> |
---|
294 | </tbl:data> |
---|
295 | </tbl:table> |
---|
296 | <% |
---|
297 | } |
---|
298 | %> |
---|
299 | </base:section> |
---|
300 | |
---|
301 | |
---|
302 | </t:tab> |
---|
303 | </t:tabcontrol> |
---|
304 | |
---|
305 | </base:body> |
---|
306 | </base:page> |
---|
307 | <% |
---|
308 | } |
---|
309 | finally |
---|
310 | { |
---|
311 | if (dc != null) dc.close(); |
---|
312 | } |
---|
313 | |
---|
314 | %> |
---|