luci-0.9: various improvements in package management ui
[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 function opkg_error(code)
28 code = bit.rshift(tonumber(code), 8)
29 return translate(
30 'a_s_packages_code%i' % code,
31 '%s %i' % { translate('code'), code }
32 )
33 end
34
35 local fstat = fs.statvfs(opkg.overlay_root())
36 local space_total = fstat and fstat.blocks or 0
37 local space_free = fstat and fstat.bfree or 0
38 local space_used = space_total - space_free
39
40 local used_perc = math.floor(0.5 + ((space_total > 0) and ((100 / space_total) * space_used) or 100))
41 local free_byte = space_free * fstat.frsize
42
43 -%>
44 <%+header%>
45 <h2><a id="content" name="content"><%:system%> - <%:a_s_packages%></a></h2>
46
47 <form method="post" action="<%=REQUEST_URI%>">
48 <div class="cbi-map">
49 <fieldset class="cbi-section">
50 <ul>
51 <li><a href="<%=REQUEST_URI%>/ipkg"><%:a_s_packages_ipkg%></a></li>
52 <li><a href="<%=REQUEST_URI%>?update=1"><%:a_s_packages_updatelist%></a></li>
53 </ul>
54 <br />
55 <fieldset class="cbi-section-node">
56 <div class="cbi-value">
57 <label class="cbi-value-title"><%:a_s_packages_installurl%>:</label>
58 <div class="cbi-value-field">
59 <input type="text" name="url" size="30" value="" />
60 <input class="cbi-input-save" type="submit" name="submit" value="<%:ok%>" />
61 </div>
62 </div>
63
64 <div class="cbi-value">
65 <label class="cbi-value-title"><%:filter%>:</label>
66 <div class="cbi-value-field">
67 <input type="text" name="query" size="20" value="<%=query%>" />
68 <input type="submit" class="cbi-input-find" name="search" value="<%:a_s_packages_search%>" />
69 </div>
70 </div>
71 </fieldset>
72 </fieldset>
73 <br />
74
75 <h3><%:status%></h3>
76 <fieldset class="cbi-section">
77 <%:a_s_packages_freespace Free space%>: <strong><%=(100-used_perc)%>%</strong> (<strong><%=wa.byte_format(free_byte)%></strong>)
78 <div style="margin:3px 0; width:300px; height:10px; border:1px solid #000000; background-color:#80C080">
79 <div style="background-color:#F08080; border-right:1px solid #000000; height:100%; width:<%=used_perc%>%">&nbsp;</div>
80 </div>
81
82 <% if (install and next(install)) or (remove and next(remove)) or update or upgrade then %>
83 <br /><hr /><br />
84 <% if update then %>
85 <%:a_s_packages_update%>: <% if update == 0 then %><span class="ok"><%:ok%></span><% else %><span class="error"><%:error%> (<%=opkg_error(update)%>)</span><% end %><br />
86 <% end %>
87 <% if upgrade then%>
88 <%:a_s_packages_upgrade%>: <% if upgrade == 0 then %><span class="ok"><%:ok%></span><% else %><span class="error"><%:error%> (<%=opkg_error(upgrade)%>)</span><% end %><br />
89 <% end %>
90 <% if install then for k,v in pairs(install) do %>
91 <%:a_s_packages_install%> '<%=k%>': <% if v == 0 then %><span class="ok"><%:ok%></span><% else %><span class="error"><%:error%> (<%=opkg_error(v)%>)</span><% end %><br />
92 <% end end %>
93 <% if remove then for k,v in pairs(remove) do %>
94 <%:a_s_packages_remove%> '<%=k%>': <% if v == 0 then %><span class="ok"><%:ok%></span><% else %><span class="error"><%:error%> (<%=opkg_error(v)%>)</span><% end %><br />
95 <% end end %>
96 <% end %>
97 </fieldset>
98 <br />
99
100 <h3><%:a_s_packages_installed Installed packages%><% if query then %> (<%=luci.util.pcdata(query)%>)<% end %></h3>
101
102 <fieldset class="cbi-section">
103 <table class="cbi-section-table" style="width:100%">
104 <tr class="cbi-section-table-titles">
105 <th class="cbi-section-table-cell" style="text-align:left">&nbsp;</th>
106 <th class="cbi-section-table-cell" style="text-align:left"><%:a_s_packages_name%></th>
107 <th class="cbi-section-table-cell" style="text-align:left"><%:version%></th>
108 </tr>
109 <% local empty = true; luci.model.ipkg.list_installed(query, function(n, v, d) empty = false %>
110 <tr class="cbi-section-table-row cbi-rowstyle-<%=rowstyle()%>">
111 <td style="text-align:left; width:10%"><a onclick="return window.confirm('<%:delete%> &quot;<%=luci.util.pcdata(n)%>&quot; ?')" href="<%=REQUEST_URI%>?submit=1&amp;remove=<%=luci.util.pcdata(n)%>"><%:delete%></a></td>
112 <td style="text-align:left"><%=luci.util.pcdata(n)%></td>
113 <td style="text-align:left"><%=luci.util.pcdata(v)%></td>
114 </tr>
115 <% end) %>
116 <% if empty then %>
117 <tr class="cbi-section-table-row">
118 <td style="text-align:left">&nbsp;</td>
119 <td style="text-align:left"><em><%:none%></em></td>
120 <td style="text-align:left"><em><%:none%></em></td>
121 </tr>
122 <% end %>
123 </table>
124 </fieldset>
125 <br />
126
127
128 <h3><%:a_s_packages_available Available packages%><% if query then %> (<%=luci.util.pcdata(query)%>)<% end %></h3>
129
130 <fieldset class="cbi-section">
131 <table class="cbi-section-table" style="width:100%">
132 <tr class="cbi-section-table-titles">
133 <th class="cbi-section-table-cell" style="text-align:left">&nbsp;</th>
134 <th class="cbi-section-table-cell" style="text-align:left"><%:a_s_packages_name%></th>
135 <th class="cbi-section-table-cell" style="text-align:left"><%:version%></th>
136 <th class="cbi-section-table-cell" style="text-align:left"><%:descr%></th>
137 </tr>
138 <% local empty = true; luci.model.ipkg.list_all(query, function(n, v, d) empty = false %>
139 <tr class="cbi-section-table-row cbi-rowstyle-<%=rowstyle()%>">
140 <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>
141 <td style="text-align:left"><%=luci.util.pcdata(n)%></td>
142 <td style="text-align:left"><%=luci.util.pcdata(v)%></td>
143 <td style="text-align:left"><%=luci.util.pcdata(d)%></td>
144 </tr>
145 <% end) %>
146 <% if empty then %>
147 <tr class="cbi-section-table-row">
148 <td style="text-align:left">&nbsp;</td>
149 <td style="text-align:left"><em><%:none%></em></td>
150 <td style="text-align:left"><em><%:none%></em></td>
151 <td style="text-align:left"><em><%:none%></em></td>
152 </tr>
153 <% end %>
154 </table>
155 </fieldset>
156 </div>
157 </form>
158 <%+footer%>