source: extensions/net.sf.basedb.reggie/trunk/resources/admin/install.jsp @ 2214

Last change on this file since 2214 was 2214, checked in by Nicklas Nordborg, 9 years ago

Fixes #570: Installation wizard incorrectly display '0 more...'

File size: 9.5 KB
Line 
1<%@ page
2  pageEncoding="UTF-8"
3  session="false"
4  import="net.sf.basedb.core.Application"
5  import="net.sf.basedb.core.User"
6  import="net.sf.basedb.core.DbControl"
7  import="net.sf.basedb.core.SessionControl"
8  import="net.sf.basedb.clients.web.Base"
9  import="net.sf.basedb.clients.web.util.HTML"
10  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
11  import="net.sf.basedb.util.Values"
12%>
13<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
14<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
15<%
16final SessionControl sc = Base.getExistingSessionControl(request, true);
17final String ID = sc.getId();
18final float scale = Base.getScale(sc);
19final String home = ExtensionsControl.getHomeUrl("net.sf.basedb.reggie");
20DbControl dc = null;
21try
22{
23  dc = sc.newDbControl();
24  final User user = User.getById(dc, sc.getLoggedInUserId());
25%>
26<base:page type="default" >
27<base:head scripts="ajax.js" styles="path.css,table.css">
28  <link rel="stylesheet" type="text/css" href="../css/reggie.css">
29  <script language="JavaScript" src="../reggie.js" type="text/javascript" charset="UTF-8"></script>
30
31<script language="JavaScript">
32
33function createMissingItems()
34{
35  init('Install');
36}
37
38function init(cmd)
39{
40  var request = Ajax.getXmlHttpRequest();
41  var url = '../Install.servlet?ID=<%=ID%>&cmd='+cmd;
42  request.open("GET", url, false);
43  request.send(null);
44 
45  var response = JSON.parse(request.responseText);
46  if (response.status != 'ok')
47  {
48    setFatalError(response.message);
49    return false;
50  }
51  var COL_BREAKS = ['ANNOTATIONTYPE', 'PLUGINDEFINITION'];
52 
53  var numMissing = 0;
54  var numWarnings = 0;
55  var numErrors = 0;
56  var numIncomplete = 0;
57  var checks = response.checks;
58  var html = '<table class="report">';
59  var lastItemType = null;
60  var index = 0;
61  var topLines = []; // Top lines are for items with error/warning/special message
62  var bottomLines = []; // Bottom lines are for all 'OK' items
63  var allOk = true;
64 
65  for (var i = 0; i < checks.length; i++)
66  {
67    var check = checks[i];
68    var icon = 'ok.png';
69    check.ok = true;
70    if (check.status == 'missing') 
71    {
72      numMissing++;
73      icon = 'error.png';
74      check.ok = false;
75    }
76    if (check.status == 'incomplete')
77    {
78      numIncomplete++;
79      icon = 'warning.png';
80      check.ok = false;
81    }
82    if (check.status == 'error') 
83    {
84      numErrors++;
85      icon = 'error.png';
86      check.ok = false;
87    }
88    if (check.status == 'warning') 
89    {
90      numWarnings++;
91      icon = 'warning.png';
92      check.ok = false;
93    }
94    allOk &= check.ok;
95   
96    var sameSection = lastItemType == check.itemType;
97    // Do not start new section when switching between plugin definition and configuration
98    if (!sameSection) sameSection = lastItemType == 'PLUGINDEFINITION' && check.itemType == 'PLUGINCONFIGURATION';
99    if (!sameSection) sameSection = lastItemType == 'PLUGINCONFIGURATION' && check.itemType == 'PLUGINDEFINITION';
100    if (!sameSection)
101    {
102      html += topLines.join(''); // Always show the top-lines
103      if ((topLines.length + bottomLines.length > 13) && bottomLines.length > 0)
104      {
105        // Show 10 lines and hide the rest
106        var showMoreFrom = Math.max(0, 10 - topLines.length);
107        if (showMoreFrom > 0)
108        {
109          html += bottomLines.slice(0, showMoreFrom).join('');
110        }
111        html += '<tr class="sameitemtype highlight" id="'+check.itemType+'" onclick="showMore(event)">';
112        html += '<td class="link">&hellip; '+(bottomLines.length-showMoreFrom)+' more</td>';
113        html += '<td><img src="../images/ok.png"></td><td>Ok</td></tr>';
114        html += '<tbody id="'+check.itemType+'.more" style="display: none;">';
115        html += bottomLines.slice(showMoreFrom).join('');
116        html += '</tbody>';
117      }
118      else
119      {
120        html += bottomLines.join('');
121      }
122     
123      topLines = [];
124      bottomLines = [];
125      allOk = true;
126      index = 0;
127     
128      var col_break = COL_BREAKS.indexOf(check.itemType);
129      if (col_break >= 0)
130      {
131        // End the left side and start on the right
132        html += '</table>';
133        setInnerHTML('validationResult'+col_break, html);
134        html = '<table class="report">';
135      }
136      html += '<tr class="newitemtype"><td colspan="3">'+check.itemType+'</td></tr>';
137    }
138   
139    var line = '<tr class="sameitemtype highlight '+check.itemType+' ' + (check.ok ? 'check-ok' : 'check-not-ok') + '">';
140    lastItemType = check.itemType;
141    var name = check.name;
142    if (check.mainType) name += ' <span class="itemsubtype">[' + check.mainType + ']</span>';
143    if (check.id)
144    {
145      line += '<td class="itemTypeCol"><div class="link" onclick="itemOnClick(event, \''+check.itemType+'\','+check.id+')"';
146      line += ' title="View this item (use CTRL, ALT or SHIFT to edit)">'+name+'</div></td>';
147    }
148    else
149    {
150      line += '<td class="itemTypeCol"><i>' + name + '</i></td>';
151    }
152    line += '<td class="iconCol"><img src="../images/'+icon+'"></td>';
153    line += '<td class="statusCol">';
154    if (check.messages.length > 1)
155    {
156      for (var m = 0; m < check.messages.length; m++)
157      {
158        line += '• '+check.messages[m] + '<br>';
159      }
160    }
161    else
162    {
163      line += check.messages;
164    }
165    line += '</td></tr>';
166   
167    if (!check.ok || check.messages != 'Ok')
168    {
169      topLines[topLines.length] = line;
170    }
171    else
172    {
173      bottomLines[bottomLines.length] = line;
174    }
175    index++;
176  }
177 
178  html += topLines.join('');
179  if ((topLines.length + bottomLines.length > 13) && bottomLines.length > 0)
180  {
181    // Show 10 lines and hide the rest
182    var showMoreFrom = Math.max(0, 10 - topLines.length);
183    if (showMoreFrom > 0)
184    {
185      html += bottomLines.slice(0, showMoreFrom).join('');
186    }
187    html += '<tr class="sameitemtype highlight" id="'+check.itemType+'" onclick="showMore(event)">';
188    html += '<td class="link">&hellip; '+(bottomLines.length-showMoreFrom)+' more</td>';
189    html += '<td><img src="../images/ok.png"></td><td>Ok</td></tr>';
190    html += '<tbody id="'+check.itemType+'.more" style="display: none;">';
191    html += bottomLines.slice(showMoreFrom).join('');
192    html += '</tbody>';
193  }
194  else
195  {
196    html += bottomLines.join('');
197  }
198 
199  html += '</table>';
200  setInnerHTML('validationResult'+COL_BREAKS.length, html);
201 
202  if (numErrors > 0)
203  {
204    setFatalError(numErrors+' errors was detected. You need to fix those manually.');
205  }
206  else if (numWarnings > 0)
207  {
208    setWarningMessage(numWarnings+' warnings was detected. Reggie may still work. If not, you need to fix it manually.');
209  }
210  Main.showHide('createMissingItems', numMissing > 0);
211  Main.showHide('fixIncompleteItems', numMissing == 0 && numIncomplete > 0);
212}
213
214function setWarningMessage(message)
215{
216  setInnerHTML('warningMessage.message', message);
217  Main.show('warningMessage');
218}
219
220function itemOnClick(event, itemType, itemId)
221{
222  Main.itemOnClick(event, '<%=ID%>', itemType, itemId, true);
223}
224
225function showMore(event)
226{
227  var target = event.currentTarget;
228  Main.show(target.id + '.more');
229  Main.hide(target.id);
230}
231
232</script>
233<style>
234.report
235{
236  width: 100%;
237  border-collapse: collapse;
238}
239
240.report .itemTypeCol
241{
242  width: 18em;
243  overflow: hidden;
244  text-overflow: ellipsis;
245}
246
247.report .iconCol
248{
249  width: 20px;
250}
251.report .statusCol
252{}
253
254
255.report th
256{
257  font-weight: bold;
258  text-align: left;
259  background: #E8E8E8;
260  padding: 2px 4px 2px 4px;
261}
262
263.report td
264{
265  padding: 2px;
266}
267
268.report .newitemtype
269{
270  border-top: 1px solid #A0A0A0;
271  border-bottom: 1px solid #A0A0A0;
272  font-weight: bold;
273  background-color: #E8E8E8;
274}
275.report .sameitemtype
276{
277  border-top: 1px dotted #A0A0A0;
278  border-bottom: 1px dotted #A0A0A0;
279}
280
281.report .sameitemtype > td:first-child
282{
283  padding-left: 1em;
284}
285
286.report .check-not-ok
287{
288  font-weight: bold;
289}
290
291.report .sameitemtype.PLUGINCONFIGURATION > td:first-child
292{
293  padding-left: 2.5em;
294  font-style: italic;
295}
296
297.report td
298{
299  white-space: nowrap;
300  overflow: hidden;
301  text-overflow: ellipsis;
302}
303</style>
304</base:head>
305<base:body onload="init('Validate')">
306
307  <p:path><p:pathelement 
308    title="Reggie" href="<%="../index.jsp?ID="+ID%>" 
309    /><p:pathelement title="Installation wizard" 
310    /></p:path>
311
312  <div class="content" style="padding-left: 2em;">
313
314    <div class="absolutefull" style="width: 33%; bottom: 10em;">
315      <div id="validationResult0" class="absolutefull fullborder" style="left: 1em; right: 0.5em; border-top-width: 0 !important;">
316        Checking; please wait...
317      </div>
318    </div>
319   
320    <div class="absolutefull" style="width: 33%; bottom: 10em; left: 33%;">
321      <div id="validationResult1" class="absolutefull fullborder" style="left: 0.5em; right: 1em; border-top-width: 0 !important;">
322      </div>
323    </div>
324
325    <div class="absolutefull" style="width: 34%; bottom: 10em; left: auto;">
326      <div id="validationResult2" class="absolutefull fullborder" style="left: 0.5em; right: 1em; border-top-width: 0 !important;">
327      </div>
328    </div>
329
330    <div class="absolutefull" style="top: auto; height: 10em; left: 1em; right: 1em;">
331      <div id="createMissingItems" style="display:none; margin-top: 1em;">
332        <base:buttongroup>
333        <base:button title="Create missing items" image="add.png" onclick="createMissingItems()"/>
334        </base:buttongroup>
335      </div>
336   
337      <div id="fixIncompleteItems" style="display:none; margin-top: 1em;">
338        <base:buttongroup>
339        <base:button title="Fix items" image="fixit.png" onclick="createMissingItems()"/>
340        </base:buttongroup>
341      </div>
342   
343      <div class="messagecontainer error" id="errorMessage" style="display: none;"></div>
344   
345      <div class="messagecontainer note" id="warningMessage" style="display: none;">
346        <div id="warningMessage.message"></div>
347      </div>
348    </div>
349 
350  </div>
351 
352</base:body>
353</base:page>
354<%
355}
356finally
357{
358  if (dc != null) dc.close();
359}
360%>
Note: See TracBrowser for help on using the repository browser.