Skip to content

Commit

Permalink
Merge pull request #396 from opentechinstitute/theme-logic-separation
Browse files Browse the repository at this point in the history
Theme logic separation. Testbed by @jheretic; more thorough overview of theme pages should be conducted as part of testing protocol.
  • Loading branch information
jheretic committed Jul 15, 2014
2 parents 5457f00 + ebd0086 commit e650868
Show file tree
Hide file tree
Showing 10 changed files with 335 additions and 255 deletions.
78 changes: 37 additions & 41 deletions luasrc/view/themes/commotion/footer.htm
Original file line number Diff line number Diff line change
@@ -1,47 +1,43 @@
<%#
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
Copyright 2012 David Menting <david@nut-bolt.nl>
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
Copyright 2012 David Menting <david@nut-bolt.nl>
Copyright 2014 Andrew Reynolds <andrew@opentechinstitute.org>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0


footer.htm is a LuCI theme template that builds the bottom portion
of each web UI page. It refers to the LuCI footer, not the HTML
footer, although the HTML footer is included in this file.
-%>
</div>
<%
local disp = require "luci.dispatcher"

local request = disp.context.path

local category = request[1]

local tree = disp.node()

local categories = disp.node_childs(tree)
%>
</section>
<footer>
<nav>
<div class="pointydown"></div>
<ul id="footermenu">
<li class="admin"><a href="<%=controller%>/admin/commotion"><%:Administration%></a></li>
<li class="about"><a href="<%=controller%>/commotion/about/"><%:About%></a></li>
<li class="help"><a href="<%=controller%>/commotion/help/"><%:Help%></a></li>
<li class="license"><a href="<%=controller%>/commotion/license/"><%:License%></a></li>
</ul>
</nav>
<p class="credits">
<a href="http://luci.subsignal.org/">Powered by <%= luci.__appname__ .. " (" .. luci.__version__ .. ")" %></a>
<%=luci.version.distversion%>
</p>
</footer>
</body>
<script src="<%=media%>/respond.min.js"></script>
<script src="<%=media%>/selectnav.min.js"></script>
<script src="<%=media%>/theme.js"></script>
</html>

<%# Footer contained duplicate module imports -%>

<!-- close maincontent. Move to header.htm? -->
</section>

<footer>
<nav>
<div class="pointydown"></div>

<ul id="footermenu">
<li class="admin"><a href="<%=controller%>/admin/commotion"><%:Administration%></a></li>
<li class="about"><a href="<%=controller%>/commotion/about/"><%:About%></a></li>
<li class="help"><a href="<%=controller%>/commotion/help/"><%:Help%></a></li>
<li class="license"><a href="<%=controller%>/commotion/license/"><%:License%></a></li>
</ul>
</nav>

<p class="credits">
<a href="http://luci.subsignal.org/">Powered by <%= luci.__appname__ .. " (" .. luci.__version__ .. ")" %></a><br />
<span id="commotion-release"><%=luci.version.distversion%></span>
</p>
</footer>
</body>
</html>
1 change: 1 addition & 0 deletions luasrc/view/themes/commotion/functions/gen-title.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%=striptags( hostname .. ( (node and node.title) and ' - ' .. translate(node.title) or '')) %> - LuCI
277 changes: 145 additions & 132 deletions luasrc/view/themes/commotion/header.htm
Original file line number Diff line number Diff line change
@@ -1,140 +1,153 @@
<%#
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
Copyright 2012 David Menting <david@nut-bolt.nl>
Copyright 2013 Griffin Boyce <griffin@opentechinstitute.org>
Copyright 2013 Seamus Tuohy <s2e@opentechinstitute.org>
Header.htm is a LuCI theme template that builds the top portion
of each web UI page. It refers to the LuCI header, not the HTML
header, although the HTML header is included in this file.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
HTML begins after LuCI/Lua function definitions.

http://www.apache.org/licenses/LICENSE-2.0
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
Copyright 2012 David Menting <david@nut-bolt.nl>
Copyright 2013 Griffin Boyce <griffin@opentechinstitute.org>
Copyright 2013 Seamus Tuohy <s2e@opentechinstitute.org>
Copyright 2014 Andrew Reynolds <andrew@opentechinstitute.org>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
-%>

<%# Moving these functions to another template puts them out of scope
with no obvious way to pass variables to includes.
Keeping functions in header template for now.

Use this syntax:
include("themes/commotion/functions/header-prep",
{var=var, var=var})
-%>

<%
local crypto = require "luci.commotion.crypto"
local http = require "luci.http"
local sys = require "luci.sys"
local disp = require "luci.dispatcher"
local cdisp = require "luci.commotion.dispatch"

-- ensure that client is running https
crypto.check_https("/admin/", luci.http.getenv())

-- send as HTML5
http.prepare_content("text/html")

hostname = sys.hostname()

--The request path (eg. http://ipaddress/cgi-bin/luci/;id-string/THIS/THIS/THIS/)
request = disp.context.path
local request2 = disp.context.request

--ROOT NODE OF PATH (eg. admin on admin pages)
category = request[1]
section = request[2]

--SAME AGAIN
cattree = category and disp.node(category)

--leaf is length of request2
local leaf = request2[#request2]

--Create a node of the local thread (the current context)
tree = disp.node()

--Show the local node (current menu) on the tree
node = disp.context.dispatched

--An Ordered table of node names of this tree's child nodes
local categories = disp.node_childs(tree)

local c = tree
local i, r

-- tag all nodes leading to this page
for i, r in ipairs(request) do
if c.nodes and c.nodes[r] then
c = c.nodes[r]
c._menu_selected = true
end
end

--nodeurl was here
--subtree was here
-%>
local crypto = require "luci.commotion.crypto"
local http = require "luci.http"
local urlencode = require "luci.http.protocol".urlencode
local sys = require "luci.sys"
local disp = require "luci.dispatcher"
local cdisp = require "luci.commotion.dispatch"

-- ensure that client is running https
crypto.check_https("/admin/", luci.http.getenv())

-- send as HTML5
http.prepare_content("text/html")


-- Prepare variables for use in templates
hostname = sys.hostname()

-- BEGIN menu preparation
--The request path (eg. http://ipaddress/cgi-bin/luci/;id-string/THIS/THIS/THIS/)
request = disp.context.path
local request2 = disp.context.request

-- Node is our position on the menu tree
-- ROOT NODE OF PATH (e.g. admin on admin pages)
category = request[1]
section = request[2]

-- SAME AGAIN // cattree indicates submenu item
cattree = category and disp.node(category)

-- leaf is length of request2
local leaf = request2[#request2]

-- Create a node of the local thread (the current context)
tree = disp.node()

-- Show the local node (current menu) on the tree
node = disp.context.dispatched

-- An Ordered table of node names of this tree s child nodes
local categories = disp.node_childs(tree)

local c = tree
local i, r

-- tag all nodes leading to this page
for i, r in ipairs(request) do
if c.nodes and c.nodes[r] then
c = c.nodes[r]
c._menu_selected = true
end
end
-- END menu preparation

-- BEGIN mesh ip generation (mesh_ip)
uci = require "luci.model.uci".cursor()
ubus = require "ubus"
conn = ubus.connect()

if not conn then
error("Failed to connect to ubusd")
end

mesh_ip = "None"
uci:foreach("wireless", "wifi-iface", function(s)
if s and s.mode and s.mode == "adhoc" and s.network then
local iface = conn:call("network.interface."..s.network, "status", {})
if iface ~= nil and iface["ipv4-address"] then
if iface["ipv4-address"][1] and iface["ipv4-address"][1].address then
mesh_ip = iface["ipv4-address"][1].address
else
mesh_ip = "Unknown"
end
elseif mesh_ip == "None" then
mesh_ip = "Unknown"
end
end
end
)
conn:close()
-- END mesh ip generation

-- BEGIN check for unsaved changes (ucichanges)
-- ucichanges local. Will cause problems
if tree.nodes[category] and tree.nodes[category].ucidata then
local ucichanges = 0

for i, j in pairs(require("luci.model.uci").cursor():changes()) do
for k, l in pairs(j) do
for m, n in pairs(l) do
ucichanges = ucichanges + 1;
end
end
end
end
-- END check for unsaved changes
-%>
<!DOCTYPE html>
<html lang="<%=luci.i18n.context.lang%>">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=yes" />
<title><%=striptags( hostname .. ( (node and node.title) and ' - ' .. translate(node.title) or '')) %> - LuCI</title>

<!-- Stylesheets for mobile and small tablets -->
<link rel="stylesheet" href="<%=media%>/tinycombo.css">

<!-- Stylesheets for desktop and large tablets -->
<link rel="stylesheet" href="<%=media%>/cascade.css" media="screen and (min-device-width:768px) and (min-width:768px), projection">
<link rel="stylesheet" href="<%=media%>/sidebar.css" media="screen and (min-device-width:768px) and (min-width:768px), projection">
<link rel="shortcut icon" href="<%=media%>/favicon.ico">
<% if node and node.css then %>
<link rel="stylesheet" href="<%=resource%>/<%=node.css%>">
<% end -%>
<script src="<%=resource%>/xhr.js"></script>
<script src="<%=media%>/zepto.min.js"></script>
</head>
<body class="lang_<%=luci.i18n.context.lang%> <%- if node then %><%= striptags( node.title ) %><%- end %>">
<header>
<topbar><ul><li></li></ul></topbar>
<a id="device" href="/"><img src="<%=media%>/commotion_tiny.png" alt="Commotion - toggle header" title="Commotion - toggle header" /></a>
<%uci = require "luci.model.uci".cursor()
ubus = require "ubus"
conn = ubus.connect()
if not conn then
error("Failed to connect to ubusd")
end
mesh_ip = "None"
uci:foreach("wireless", "wifi-iface",
function(s)
if s and s.mode and s.mode == "adhoc" and s.network then
local iface = conn:call("network.interface."..s.network, "status", {})
if iface ~= nil and iface["ipv4-address"] then
if iface["ipv4-address"][1] and iface["ipv4-address"][1].address then
mesh_ip = iface["ipv4-address"][1].address
else
mesh_ip = "Unknown"
end
elseif mesh_ip == "None" then
mesh_ip = "Unknown"
end
end
end
)
conn:close()
-%>

<div class="collapsible">
<table id="nodeinfo">
<tr>
<td class="key-item hug-right">Node name:</td><td class="hug-left"><%=hostname%></td>
<td class="tdempty"></td>
<td class="key-item hug-right">Mesh IP-Address:</td><td class="hug-left"><%=mesh_ip%></td>
</tr>
</table>
</div>

<%include("themes/commotion/unsaved_changes", {tree=tree, controller=controller, category=category})%>

<div class="navbar-inners"><div class="color0"></div><div class="color1"></div><div class="color2"></div><div class="color3"></div><div class="color4"></div></div>
</header>

<section id="maincontent">
<%if request[2] == "commotion" then%> <%# TODO Clean and combine these two menu templates after R1 push %>
<%include("themes/commotion/basic_menu", {controller=controller, cattree=cattree, category=category, node=node, section=section})%>
<div class="body-content basic_menu">
<%elseif request[1] ~= "commotion" then%>
<%include("themes/commotion/adv_menu", {controller=controller, cattree=cattree, category=category, node=node, section=section})%>
<%include("themes/commotion/subtree", {controller=controller, category=category, cattree=cattree})%>
<%end%>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=yes" />
<title>
<%include("themes/commotion/functions/gen-title")%>
</title>
<%include("themes/commotion/stylesheets")%>
<%include("themes/commotion/javascript")%>
</head>

<!-- node.title needs to be urlencoded -->
<body class="lang_<%=luci.i18n.context.lang%> <%- if node then %> <%= urlencode(striptags( node.title )) %> <%- end %>">

<header>
<%include("themes/commotion/top-branding",
{ucichanges=ucichanges, tree=tree, controller=controller, category=category})%>
</header>
<!-- Begin maincontent -->
<section id="maincontent">
<%include("themes/commotion/sidenav",
{controller=controller, cattree=cattree, category=category, node=node, section=section})%>
<!-- /section in footer.htm -->
9 changes: 9 additions & 0 deletions luasrc/view/themes/commotion/javascript.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%#
This include is called from header.htm
-%>

<script src="<%=resource%>/xhr.js"></script>
<script src="<%=media%>/zepto.min.js"></script>
<script src="<%=media%>/respond.min.js"></script>
<script src="<%=media%>/selectnav.min.js"></script>
<script src="<%=media%>/theme.js"></script>
Loading

0 comments on commit e650868

Please sign in to comment.