modules/admin-full: make software page tabbed, show available list broken down by...
[project/luci.git] / modules / admin-full / luasrc / view / admin_system / packages.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2008 Steven Barth <steven@midlink.org>
4 Copyright 2008-2010 Jo-Philipp Wich <xm@subsignal.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10         http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13
14 -%>
15 <%-
16 local bit = require "bit"
17 local opkg = require "luci.model.ipkg"
18 local fs = require "nixio.fs"
19 local wa = require "luci.tools.webadmin"
20 local rowcnt = 1
21
22 function rowstyle()
23         rowcnt = rowcnt + 1
24         return (rowcnt % 2) + 1
25 end
26
27 local fstat = fs.statvfs(opkg.overlay_root())
28 local space_total = fstat and fstat.blocks or 0
29 local space_free  = fstat and fstat.bfree  or 0
30 local space_used  = space_total - space_free
31
32 local used_perc = math.floor(0.5 + ((space_total > 0) and ((100 / space_total) * space_used) or 100))
33 local free_byte = space_free * fstat.frsize
34
35 local filter = { }
36
37
38 local querypat
39 if query and #query > 0 then
40         querypat = "*%s*" % query
41 end
42
43 local letterpat
44 if letter == 35 then
45         letterpat = "[^a-zA-Z]*"
46 else
47         letterpat = string.char(91, letter, letter + 32, 93, 42) -- '[' 'A' 'a' ']' '*'
48 end
49
50 -%>
51 <%+header%>
52 <h2><a id="content" name="content"><%:System%> - <%:Software%></a></h2>
53
54 <form method="post" action="<%=REQUEST_URI%>">
55         <div class="cbi-map">
56                 <fieldset class="cbi-section">
57                         <ul>
58                                 <li><a href="<%=REQUEST_URI%>/ipkg"><%:Edit package lists and installation targets%></a></li>
59                                 <li><a href="<%=REQUEST_URI%>?update=1"><%:Update package lists%></a></li>
60                         </ul>
61                         <br />
62                         <fieldset class="cbi-section-node">
63                                 <div class="cbi-value">
64                                         <label class="cbi-value-title"><%:Download and install package%>:</label>
65                                         <div class="cbi-value-field">
66                                                 <input type="text" name="url" size="30" value="" />
67                                                 <input class="cbi-button cbi-input-save" type="submit" name="submit" value="<%:OK%>" />
68                                         </div>
69                                 </div>
70
71                                 <div class="cbi-value cbi-value-last">
72                                         <label class="cbi-value-title"><%:Filter%>:</label>
73                                         <div class="cbi-value-field">
74                                                 <input type="hidden" name="display" value="<%=pcdata(display)%>" />
75                                                 <input type="text" name="query" size="20" value="<%=pcdata(query)%>" />
76                                                 <input type="submit" class="cbi-button cbi-input-find" name="search" value="<%:Find package%>" />
77                                         </div>
78                                 </div>
79                         </fieldset>
80                 </fieldset>
81                 <br />
82
83                 <h3><%:Status%></h3>
84                 <fieldset class="cbi-section">
85                         <%:Free space%>: <strong><%=(100-used_perc)%>%</strong> (<strong><%=wa.byte_format(free_byte)%></strong>)
86                         <div style="margin:3px 0; width:300px; height:10px; border:1px solid #000000; background-color:#80C080">
87                                 <div style="background-color:#F08080; border-right:1px solid #000000; height:100%; width:<%=used_perc%>%">&#160;</div>
88                         </div>
89
90                         <% if querypat then %>
91                                 <br /><hr /><br />
92                                 <%:Displaying only packages containing%> <strong>"<%=pcdata(query)%>"</strong>
93                                 <input type="button" onclick="location.href='?display=<%=pcdata(display)%>'" href="#" class="cbi-button cbi-button-reset" style="margin-left:3em" value="Reset" />
94                         <% end %>
95
96                         <% if (install and next(install)) or (remove and next(remove)) or update or upgrade then %>
97                                 <br /><hr /><br />
98                                 <% if #stdout > 0 then %><pre><%=pcdata(stdout)%></pre><% end %>
99                                 <% if #stderr > 0 then %><pre class="error"><%=pcdata(stderr)%></pre><% end %>
100                         <% end %>
101                 </fieldset>
102                 <br />
103
104                 <ul class="cbi-tabmenu">
105                         <li class="cbi-tab<% if display ~= "installed" then %>-disabled<% end %>"><a href="?display=installed&amp;query=<%=pcdata(query)%>"><%:Installed packages%><% if query then %> (<%=pcdata(query)%>)<% end %></a></li>
106                         <li class="cbi-tab<% if display ~= "available" then %>-disabled<% end %>"><a href="?display=available&amp;query=<%=pcdata(query)%>"><%:Available packages%><% if query then %> (<%=pcdata(query)%>)<% end %></a></li>
107                 </ul>
108                 
109                 <% if display ~= "available" then %>
110                         <fieldset class="cbi-section">
111                                 <table class="cbi-section-table" style="width:100%">
112                                         <tr class="cbi-section-table-titles">
113                                                 <th class="cbi-section-table-cell" style="text-align:left">&#160;</th>
114                                                 <th class="cbi-section-table-cell" style="text-align:left"><%:Package name%></th>
115                                                 <th class="cbi-section-table-cell" style="text-align:left"><%:Version%></th>
116                                         </tr>
117                                         <% local empty = true; luci.model.ipkg.list_installed(querypat, function(n, v, d) empty = false; filter[n] = true %>
118                                         <tr class="cbi-section-table-row cbi-rowstyle-<%=rowstyle()%>">
119                                                 <td style="text-align:left; width:10%"><a onclick="return window.confirm('<%:Remove%> &quot;<%=luci.util.pcdata(n)%>&quot; ?')" href="<%=REQUEST_URI%>?submit=1&amp;remove=<%=luci.util.pcdata(n)%>"><%:Remove%></a></td>
120                                                 <td style="text-align:left"><%=luci.util.pcdata(n)%></td>
121                                                 <td style="text-align:left"><%=luci.util.pcdata(v)%></td>
122                                         </tr>
123                                         <% end) %>
124                                         <% if empty then %>
125                                         <tr class="cbi-section-table-row">
126                                                 <td style="text-align:left">&#160;</td>
127                                                 <td style="text-align:left"><em><%:none%></em></td>
128                                                 <td style="text-align:left"><em><%:none%></em></td>
129                                         </tr>
130                                         <% end %>
131                                 </table>
132                         </fieldset>
133                 <% else %>
134                         <fieldset class="cbi-section">
135                         <% if not querypat then %>
136                                 <ul class="cbi-tabmenu">
137                                         <% local i; for i = 65, 90 do %>
138                                         <li class="cbi-tab<% if letter ~= i then %>-disabled<% end %>"><a href="?display=available&amp;letter=<%=string.char(i)%>"><%=string.char(i)%></a></li>
139                                         <% end %>
140                                         <li class="cbi-tab<% if letter ~= 35 then %>-disabled<% end %>"><a href="?display=available&amp;letter=%23">#</a></li>
141                                 </ul>
142                                 <div class="cbi-section-node">
143                         <% end %>
144                                 <table class="cbi-section-table" style="width:100%">
145                                         <tr class="cbi-section-table-titles">
146                                                 <th class="cbi-section-table-cell" style="text-align:left">&#160;</th>
147                                                 <th class="cbi-section-table-cell" style="text-align:left"><%:Package name%></th>
148                                                 <th class="cbi-section-table-cell" style="text-align:left"><%:Version%></th>
149                                                 <th class="cbi-section-table-cell" style="text-align:left"><%:Description%></th>
150                                         </tr>
151                                         <% local empty = true; luci.model.ipkg.list_all(querypat or letterpat, function(n, v, d) if filter[n] then return end; empty = false %>
152                                         <tr class="cbi-section-table-row cbi-rowstyle-<%=rowstyle()%>">
153                                                 <td style="text-align:left; width:10%"><a onclick="return window.confirm('<%:Install%> &quot;<%=luci.util.pcdata(n)%>&quot; ?')" href="<%=REQUEST_URI%>?submit=1&amp;install=<%=luci.util.pcdata(n)%>"><%:Install%></a></td>
154                                                 <td style="text-align:left"><%=luci.util.pcdata(n)%></td>
155                                                 <td style="text-align:left"><%=luci.util.pcdata(v)%></td>
156                                                 <td style="text-align:left"><%=luci.util.pcdata(d)%></td>
157                                         </tr>
158                                         <% end) %>
159                                         <% if empty then %>
160                                         <tr class="cbi-section-table-row">
161                                                 <td style="text-align:left">&#160;</td>
162                                                 <td style="text-align:left"><em><%:none%></em></td>
163                                                 <td style="text-align:left"><em><%:none%></em></td>
164                                                 <td style="text-align:left"><em><%:none%></em></td>
165                                         </tr>
166                                         <% end %>
167                                 </table>
168                         <% if not querypat then %>
169                                 </div>
170                         <% end %>
171                         </fieldset>
172                 <% end %>
173         </div>
174 </form>
175 <%+footer%>