luci-theme-bootstrap: translate Lua templates to ucode equivalents

Add ucode template equivalents for the Lua templates used by the theme.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2022-09-09 20:08:57 +02:00
parent f478fe6c43
commit 2e3282e624
7 changed files with 116 additions and 134 deletions

View file

@ -1,21 +0,0 @@
<%#
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
Copyright 2012 David Menting <david@nut-bolt.nl>
Licensed to the public under the Apache License 2.0.
-%>
<% if not blank_page then %>
<% local ver = require "luci.version" %>
</div>
<footer>
<span>
<a href="https://github.com/openwrt/luci">Powered by <%= ver.luciname %> (<%= ver.luciversion %>)</a> / <%= ver.distversion %>
</span>
<ul class="breadcrumb pull-right" id="modemenu" style="display:none"></ul>
</footer>
<script type="text/javascript">L.require('menu-bootstrap')</script>
<% end %>
</body>
</html>

View file

@ -1,95 +0,0 @@
<%#
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008-2016 Jo-Philipp Wich <jow@openwrt.org>
Copyright 2012 David Menting <david@nut-bolt.nl>
Licensed to the public under the Apache License 2.0.
-%>
<%
local sys = require "luci.sys"
local util = require "luci.util"
local http = require "luci.http"
local disp = require "luci.dispatcher"
local boardinfo = util.ubus("system", "board")
local node = disp.context.dispatched
local darkpref
if theme == "bootstrap-dark" then
darkpref = "true"
elseif theme == "bootstrap-light" then
darkpref = "false"
end
-- send as HTML5
http.prepare_content("text/html")
-%>
<!DOCTYPE html>
<html lang="<%=luci.i18n.context.lang%>"<%= ifattr(darkpref ~= nil, "data-darkmode", darkpref) %>>
<head>
<meta charset="utf-8">
<title><%=striptags( (boardinfo.hostname or "?") .. ( (node and node.title) and ' - ' .. translate(node.title) or '')) %> - LuCI</title>
<% if darkpref == nil then %>
<script type="text/javascript">
var mediaQuery = window.matchMedia('(prefers-color-scheme: dark)'),
rootElement = document.querySelector(':root'),
setDarkMode = function(match) { rootElement.setAttribute('data-darkmode', match.matches) };
mediaQuery.addEventListener('change', setDarkMode);
setDarkMode(mediaQuery);
</script>
<% end %>
<meta name="viewport" content="initial-scale=1.0">
<link rel="stylesheet" href="<%=media%>/cascade.css">
<link rel="stylesheet" media="only screen and (max-device-width: 854px)" href="<%=media%>/mobile.css" type="text/css" />
<link rel="shortcut icon" href="<%=media%>/favicon.png">
<% if node and node.css then %>
<link rel="stylesheet" href="<%=resource%>/<%=node.css%>">
<% end -%>
<% if css then %>
<style title="text/css"><%= css %></style>
<% end -%>
<script src="<%=url('admin/translations', luci.i18n.context.lang)%><%# ?v=PKG_VERSION %>"></script>
<script src="<%=resource%>/cbi.js"></script>
</head>
<body class="lang_<%=luci.i18n.context.lang%> <% if node then %><%= striptags( node.title ) %><%- end %>" data-page="<%= pcdata(table.concat(disp.context.requestpath, "-")) %>">
<% if not blank_page then %>
<header>
<a class="brand" href="/"><%=striptags(boardinfo.hostname or "?")%></a>
<ul class="nav" id="topmenu" style="display:none"></ul>
<div id="indicators" class="pull-right"></div>
</header>
<div id="maincontent" class="container">
<%- if luci.sys.process.info("uid") == 0 and luci.sys.user.getuser("root") and not luci.sys.user.getpasswd("root") then -%>
<div class="alert-message warning">
<h4><%:No password set!%></h4>
<p><%:There is no password set on this router. Please configure a root password to protect the web interface.%></p>
<% if disp.lookup("admin/system/admin") then %>
<div class="right"><a class="btn" href="<%=url("admin/system/admin")%>"><%:Go to password configuration...%></a></div>
<% end %>
</div>
<%- end -%>
<%- if boardinfo.rootfs_type == "initramfs" then -%>
<div class="alert-message warning">
<h4><%:System running in recovery (initramfs) mode.%></h4>
<p><%:No changes to settings will be stored and are lost after rebooting. This mode should only be used to install a firmware upgrade%></p>
<% if disp.lookup("admin/system/flash") then %>
<div class="right"><a class="btn" href="<%=url("admin/system/flash")%>"><%:Go to firmware upgrade...%></a></div>
<% end %>
</div>
<%- end -%>
<noscript>
<div class="alert-message warning">
<h4><%:JavaScript required!%></h4>
<p><%:You must enable JavaScript in your browser or LuCI will not work properly.%></p>
</div>
</noscript>
<div id="tabmenu" style="display:none"></div>
<% end %>

View file

@ -0,0 +1,20 @@
{% if (!blank_page): %}
</div>
<footer>
<span>
Powered by
<a href="https://github.com/openwrt/luci">
{{ version.luciname }} ({{ version.luciversion }})</a>
/
<a href="{{ entityencode(version.disturl ?? '#', true) }}">
{{ version.distname }} {{ version.distversion }} ({{ version.distrevision }})</a>
{% if (lua_active): %}
/ {{ _('Lua compatibility mode active') }}
{% endif %}
</span>
<ul class="breadcrumb pull-right" id="modemenu" style="display:none"></ul>
</footer>
<script type="text/javascript">L.require('menu-bootstrap')</script>
{% endif %}
</body>
</html>

View file

@ -0,0 +1,83 @@
{#
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2012 David Menting <david@nut-bolt.nl>
Copyright 2008-2022 Jo-Philipp Wich <jo@mein.io>
Licensed to the public under the Apache License 2.0.
-#}
{%
import { getuid, getspnam } from 'luci.core';
const boardinfo = ubus.call('system', 'board');
const darkpref = (theme == 'bootstrap-dark' ? 'true' : (theme == 'bootstrap-light' ? 'false' : null));
http.prepare_content('text/html; charset=UTF-8');
-%}
<!DOCTYPE html>
<html lang="{{ dispatcher.lang }}" {{ darkpref ? `data-darkmode="${darkpref}"` : '' }}>
<head>
<meta charset="utf-8">
<title>{{ striptags(`${boardinfo.hostname ?? '?'}${node ? ` - ${node.title}` : ''}`) }} - LuCI</title>
{% if (!darkpref): %}
<script type="text/javascript">
var mediaQuery = window.matchMedia('(prefers-color-scheme: dark)'),
rootElement = document.querySelector(':root'),
setDarkMode = function(match) { rootElement.setAttribute('data-darkmode', match.matches) };
mediaQuery.addEventListener('change', setDarkMode);
setDarkMode(mediaQuery);
</script>
{% endif %}
<meta name="viewport" content="initial-scale=1.0">
<link rel="stylesheet" href="{{ media }}/cascade.css">
<link rel="stylesheet" media="only screen and (max-device-width: 854px)" href="{{ media }}/mobile.css" type="text/css" />
<link rel="shortcut icon" href="{{ media }}/favicon.png">
{% if (node?.css): %}
<link rel="stylesheet" href="{{ resource }}/{{ node.css }}">
{% endif %}
{% if (css): %}
<style title="text/css">{{ css }}</style>
{% endif %}
<script src="{{ dispatcher.build_url('admin/translations', dispatcher.lang) }}"></script>
<script src="{{ resource }}/cbi.js"></script>
</head>
<body class="lang_{{ dispatcher.lang }} {{ entityencode(striptags(node?.title ?? ''), true) }}" data-page="{{ entityencode(join('-', ctx.request_path), true) }}">
{% if (!blank_page): %}
<header>
<a class="brand" href="/">{{ striptags(boardinfo.hostname ?? '?') }}</a>
<ul class="nav" id="topmenu" style="display:none"></ul>
<div id="indicators" class="pull-right"></div>
</header>
<div id="maincontent" class="container">
{% if (getuid() == 0 && getspnam('root')?.pwdp === ''): %}
<div class="alert-message warning">
<h4>{{ _('No password set!') }}</h4>
<p>{{ _('There is no password set on this router. Please configure a root password to protect the web interface.') }}</p>
{% if (dispatcher.lookup("admin/system/admin")): %}
<div class="right"><a class="btn" href="{{ dispatcher.build_url("admin/system/admin") }}">{{ _('Go to password configuration...') }}</a></div>
{% endif %}
</div>
{% endif %}
{% if (boardinfo.rootfs_type == "initramfs"): %}
<div class="alert-message warning">
<h4>{{ _('System running in recovery (initramfs) mode.') }}</h4>
<p>{{ _('No changes to settings will be stored and are lost after rebooting. This mode should only be used to install a firmware upgrade') }}</p>
{% if (dispatcher.lookup("admin/system/flash")): %}
<div class="right"><a class="btn" href="{{ dispatcher.build_url("admin/system/flash") }}">{{ _('Go to firmware upgrade...') }}</a></div>
{% endif %}
</div>
{% endif %}
<noscript>
<div class="alert-message warning">
<h4>{{ _('JavaScript required!') }}</h4>
<p>{{ _('You must enable JavaScript in your browser or LuCI will not work properly.') }}</p>
</div>
</noscript>
<div id="tabmenu" style="display:none"></div>
{% endif %}

View file

@ -1,27 +1,22 @@
<%#
Copyright 2021 Jo-Philipp Wich <jo@mein.io>
{#
Copyright 2022 Jo-Philipp Wich <jo@mein.io>
Licensed to the public under the Apache License 2.0.
-%>
-#}
<%
-- tell bootstrap's templates to not render header and footer
blank_page = true
%>
<%+header%>
{% include('header', { blank_page: true }) %}
<section hidden>
<form method="post" class="cbi-map">
<div class="cbi-section">
<div class="cbi-section-node">
<div class="cbi-value">
<label class="cbi-value-title" for="luci_username"><%:Username%></label>
<label class="cbi-value-title" for="luci_username">{{ _('Username') }}</label>
<div class="cbi-value-field">
<input name="luci_username" id="luci_username" type="text" autocomplete="username" <%=attr("value", duser)%>>
<input name="luci_username" id="luci_username" type="text" autocomplete="username" value="{{ entityencode(duser, true) }}">
</div>
</div>
<div class="cbi-value">
<label class="cbi-value-title" for="luci_password"><%:Password%></label>
<label class="cbi-value-title" for="luci_password">{{ _('Password') }}</label>
<div class="cbi-value-field">
<input name="luci_password" id="luci_password" type="password" autocomplete="current-password">
</div>
@ -32,17 +27,17 @@
<hr>
<% if fuser then %>
{% if (fuser): %}
<div class="alert-message error">
<%:Invalid username and/or password! Please try again.%>
{{ _('Invalid username and/or password! Please try again.') }}
</div>
<% end %>
{% endif %}
<button class="btn cbi-button-positive important"><%:Login%></button>
<button class="btn cbi-button-positive important">{{ _('Login') }}</button>
</section>
<div id="view">
<div class="spinning"><%:Loading view…%></div>
<div class="spinning">{{ _('Loading view…') }}</div>
<script type="text/javascript">
L.require('ui').then(function(ui) {
ui.instantiateView('bootstrap.sysauth');
@ -50,4 +45,4 @@
</script>
</div>
<%+footer%>
{% include('footer', { blank_page: true }) %}