modules/admin-full: use luci.model.ipkg.find() to support searching packages by descr...
[project/luci.git] / modules / admin-full / luasrc / view / admin_system / packages.htm
index 084dab2..00b4be4 100644 (file)
@@ -1,7 +1,7 @@
 <%#
 LuCI - Lua Configuration Interface
 Copyright 2008 Steven Barth <steven@midlink.org>
-Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
+Copyright 2008-2010 Jo-Philipp Wich <xm@subsignal.org>
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
@@ -9,90 +9,192 @@ You may obtain a copy of the License at
 
        http://www.apache.org/licenses/LICENSE-2.0
 
-$Id$
-
 -%>
 <%-
+local bit = require "bit"
+local opkg = require "luci.model.ipkg"
+local fs = require "nixio.fs"
+local wa = require "luci.tools.webadmin"
 local rowcnt = 1
+
 function rowstyle()
        rowcnt = rowcnt + 1
        return (rowcnt % 2) + 1
 end
+
+local fstat = fs.statvfs(opkg.overlay_root())
+local space_total = fstat and fstat.blocks or 0
+local space_free  = fstat and fstat.bfree  or 0
+local space_used  = space_total - space_free
+
+local used_perc = math.floor(0.5 + ((space_total > 0) and ((100 / space_total) * space_used) or 100))
+local free_byte = space_free * fstat.frsize
+
+local filter = { }
+
+
+local opkg_list = luci.model.ipkg.list_all
+local querypat
+if query and #query > 0 then
+       querypat = '*%s*' % query
+       opkg_list = luci.model.ipkg.find
+end
+
+local letterpat
+if letter == 35 then
+       letterpat = "[^a-z]*"
+else
+       letterpat = string.char(letter, 42) -- 'A' '*'
+end
+
 -%>
+
 <%+header%>
-<h2><a id="content" name="content"><%:system%></a></h2>
-<h3><%:a_s_packages%></h3>
-
-<br />
-
-<% if install or remove or update or upgrade then %>
-<div class="code"><strong><%:status%>:</strong><br />
-<% if update then %>
-       <%:a_s_packages_update%>: <% if update == 0 then %><span class="ok"><%:ok%></span><% else %><span class="error"><%:error%> (<%:code%> <%=update%>)</span><% end %><br />
-<% end %>
-<% if upgrade then%>
-       <%:a_s_packages_upgrade%>: <% if upgrade == 0 then %><span class="ok"><%:ok%></span><% else %><span class="error"><%:error%> (<%:code%> <%=upgrade%>)</span><% end %><br />
-<% end %>
-<% if install then for k,v in pairs(install) do %>
-       <%:a_s_packages_install%> '<%=k%>': <% if v == 0 then %><span class="ok"><%:ok%></span><% else %><span class="error"><%:error%> (<%:code%> <%=v%>)</span><% end %><br />
-<% end end %>
-<% if remove then for k,v in pairs(remove) do %>
-       <%:a_s_packages_remove%> '<%=k%>': <% if v == 0 then %><span class="ok"><%:ok%></span><% else %><span class="error"><%:error%> (<%:code%> <%=v%>)</span><% end %><br />
-<% end end %>
-</div>
-<br />
-<% end %>
+
+<h2><a id="content" name="content"><%:Software%></a></h2>
 
 <form method="post" action="<%=REQUEST_URI%>">
        <div class="cbi-map">
+
+               <ul class="cbi-tabmenu">
+                       <li class="cbi-tab"><a href="#"><%:Actions%></a></li>
+                       <li class="cbi-tab-disabled"><a href="<%=REQUEST_URI%>/ipkg"><%:Configuration%></a></li>
+               </ul>
+
                <fieldset class="cbi-section">
-                       <ul>
-                               <li><a href="<%=REQUEST_URI%>/ipkg"><%:a_s_packages_ipkg%></a></li>
-                               <li><a href="<%=REQUEST_URI%>?update=1"><%:a_s_packages_updatelist%></a></li>
-                       </ul>
-                       <br />
+
+
                        <fieldset class="cbi-section-node">
-                       <div class="cbi-value">
-                               <label class="cbi-value-title"><%:a_s_packages_installurl%>:</label>
-                               <div class="cbi-value-field">
-                                       <input type="text" name="url" size="30" value="" />
-                                       <input class="cbi-input-save" type="submit" name="submit" value="<%:ok%>" />
+                               <% if (install and next(install)) or (remove and next(remove)) or update or upgrade then %>
+                               <div class="cbi-value">
+                                       <% if #stdout > 0 then %><pre><%=pcdata(stdout)%></pre><% end %>
+                                       <% if #stderr > 0 then %><pre class="error"><%=pcdata(stderr)%></pre><% end %>
                                </div>
-                       </div>
+                               <% end %>
+
+                               <% if querypat then %>
+                               <div class="cbi-value">
+                                       <%:Displaying only packages containing%> <strong>"<%=pcdata(query)%>"</strong>
+                                       <input type="button" onclick="location.href='?display=<%=pcdata(display)%>'" href="#" class="cbi-button cbi-button-reset" style="margin-left:1em" value="<%:Reset%>" />
+                                       <br style="clear:both" />
+                               </div>
+                               <% end %>
 
-                       <div class="cbi-value">
-                               <label class="cbi-value-title"><%:filter%>:</label>
-                               <div class="cbi-value-field">
-                                       <input type="text" name="query" size="20" value="<%=query%>" />
-                                       <input type="submit" class="cbi-input-find" name="search" value="<%:a_s_packages_search%>" />
+                               <% if no_lists or old_lists then %>
+                               <div class="cbi-value">
+                                       <% if old_lists then %>
+                                               <%:Package lists are older than 24 hours%>
+                                       <% else %>
+                                               <%:No package lists available%>
+                                       <% end %>
+                                       <input type="button" onclick="location.href='?update=1'" href="#" class="cbi-button cbi-button-apply" style="margin-left:3em" value="<%:Update lists%>" />
                                </div>
-                       </div>
-
-                       <table class="cbi-section-table">
-                               <tr class="cbi-section-table-titles">
-                                       <th class="cbi-section-table-cell"><%:a_s_packages_name%></th>
-                                       <th class="cbi-section-table-cell"><%:version%></th>
-                                       <th class="cbi-section-table-cell"><%:install%></th>
-                                       <th class="cbi-section-table-cell"><%:delete%></th>
-                                       <th class="cbi-section-table-cell"><%:descr%></th>
-                               </tr>
-                               <% for k, pkg in pairs(pkgs) do %>
-                               <tr class="cbi-section-table-row cbi-rowstyle-<%=rowstyle()%>">
-                                       <td><%=luci.util.pcdata(pkg.Package)%></td>
-                                       <td><%=luci.util.pcdata(pkg.Version)%></td>
-                                       <td><% if not pkg.Status or not pkg.Status.installed then %><input type="checkbox" name="install.<%=pkg.Package%>" value="1" /><% else %><%:installed%><% end %></td>
-                                       <td><% if pkg.Status and pkg.Status.installed then %><input type="checkbox" name="remove.<%=pkg.Package%>" value="1" /><% else %><%:notinstalled%><% end %></td>
-                                       <td><%=luci.util.pcdata(pkg.Description)%></td>
-                               </tr>
                                <% end %>
-                       </table>
+
+                               <div class="cbi-value cbi-value-last">
+                                       <%:Free space%>: <strong><%=(100-used_perc)%>%</strong> (<strong><%=wa.byte_format(free_byte)%></strong>)
+                                       <div style="margin:3px 0; width:300px; height:10px; border:1px solid #000000; background-color:#80C080">
+                                               <div style="background-color:#F08080; border-right:1px solid #000000; height:100%; width:<%=used_perc%>%">&#160;</div>
+                                       </div>
+                               </div>
+                       </fieldset>
 
                        <br />
 
-                       <div style="text-align: right">
-                               <input type="submit" class="cbi-input-apply" name="submit" value="<%:a_s_packages_do%>" />
-                       </div>
-               </fieldset></fieldset>
+                       <fieldset class="cbi-section-node">
+                               <input type="hidden" name="display" value="<%=pcdata(display)%>" />
+
+                               <div class="cbi-value">
+                                       <label class="cbi-value-title"><%:Download and install package%>:</label>
+                                       <div class="cbi-value-field">
+                                               <input type="text" name="url" size="30" value="" />
+                                               <input class="cbi-button cbi-input-save" type="submit" name="submit" value="<%:OK%>" />
+                                       </div>
+                               </div>
+
+                               <div class="cbi-value cbi-value-last">
+                                       <label class="cbi-value-title"><%:Filter%>:</label>
+                                       <div class="cbi-value-field">
+                                               <input type="text" name="query" size="20" value="<%=pcdata(query)%>" />
+                                               <input type="submit" class="cbi-button cbi-input-find" name="search" value="<%:Find package%>" />
+                                       </div>
+                               </div>
+                       </fieldset>
+               </fieldset>
+               <br />
+
+               <h3><%:Status%></h3>
+
+
+               <ul class="cbi-tabmenu">
+                       <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>
+                       <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>
+               </ul>
+
+               <% if display ~= "available" then %>
+                       <fieldset class="cbi-section">
+                               <table class="cbi-section-table" style="width:100%">
+                                       <tr class="cbi-section-table-titles">
+                                               <th class="cbi-section-table-cell" style="text-align:left">&#160;</th>
+                                               <th class="cbi-section-table-cell" style="text-align:left"><%:Package name%></th>
+                                               <th class="cbi-section-table-cell" style="text-align:left"><%:Version%></th>
+                                       </tr>
+                                       <% local empty = true; luci.model.ipkg.list_installed(querypat, function(n, v, d) empty = false; filter[n] = true %>
+                                       <tr class="cbi-section-table-row cbi-rowstyle-<%=rowstyle()%>">
+                                               <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>
+                                               <td style="text-align:left"><%=luci.util.pcdata(n)%></td>
+                                               <td style="text-align:left"><%=luci.util.pcdata(v)%></td>
+                                       </tr>
+                                       <% end) %>
+                                       <% if empty then %>
+                                       <tr class="cbi-section-table-row">
+                                               <td style="text-align:left">&#160;</td>
+                                               <td style="text-align:left"><em><%:none%></em></td>
+                                               <td style="text-align:left"><em><%:none%></em></td>
+                                       </tr>
+                                       <% end %>
+                               </table>
+                       </fieldset>
+               <% else %>
+                       <fieldset class="cbi-section">
+                       <% if not querypat then %>
+                               <ul class="cbi-tabmenu">
+                                       <% local i; for i = 65, 90 do %>
+                                       <li class="cbi-tab<% if letter ~= i then %>-disabled<% end %>"><a href="?display=available&amp;letter=<%=string.char(i)%>"><%=string.char(i)%></a></li>
+                                       <% end %>
+                                       <li class="cbi-tab<% if letter ~= 35 then %>-disabled<% end %>"><a href="?display=available&amp;letter=%23">#</a></li>
+                               </ul>
+                               <div class="cbi-section-node">
+                       <% end %>
+                               <table class="cbi-section-table" style="width:100%">
+                                       <tr class="cbi-section-table-titles">
+                                               <th class="cbi-section-table-cell" style="text-align:left">&#160;</th>
+                                               <th class="cbi-section-table-cell" style="text-align:left"><%:Package name%></th>
+                                               <th class="cbi-section-table-cell" style="text-align:left"><%:Version%></th>
+                                               <th class="cbi-section-table-cell" style="text-align:left"><%:Description%></th>
+                                       </tr>
+                                       <% local empty = true; opkg_list(querypat or letterpat, function(n, v, d) if filter[n] then return end; empty = false %>
+                                       <tr class="cbi-section-table-row cbi-rowstyle-<%=rowstyle()%>">
+                                               <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>
+                                               <td style="text-align:left"><%=luci.util.pcdata(n)%></td>
+                                               <td style="text-align:left"><%=luci.util.pcdata(v)%></td>
+                                               <td style="text-align:left"><%=luci.util.pcdata(d)%></td>
+                                       </tr>
+                                       <% end) %>
+                                       <% if empty then %>
+                                       <tr class="cbi-section-table-row">
+                                               <td style="text-align:left">&#160;</td>
+                                               <td style="text-align:left"><em><%:none%></em></td>
+                                               <td style="text-align:left"><em><%:none%></em></td>
+                                               <td style="text-align:left"><em><%:none%></em></td>
+                                       </tr>
+                                       <% end %>
+                               </table>
+                       <% if not querypat then %>
+                               </div>
+                       <% end %>
+                       </fieldset>
+               <% end %>
        </div>
 </form>
 <%+footer%>