Bladeren bron

Migrated about sections to common header and footer, converted logs to mako

Enrico Berti 14 jaren geleden
bovenliggende
commit
0034ec2c1e

+ 41 - 0
desktop/core/src/desktop/templates/about_layout.mako

@@ -0,0 +1,41 @@
+## Licensed to Cloudera, Inc. under one
+## or more contributor license agreements.  See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership.  Cloudera, Inc. licenses this file
+## to you 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
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+##
+##
+## no spaces in this method please; we're declaring a CSS class, and ART uses this value for stuff, and it splits on spaces, and
+## multiple spaces and line breaks cause issues
+<%!
+def is_selected(section, matcher):
+  if section == matcher:
+    return "selected"
+  else:
+    return ""
+%>
+
+<%def name="menubar(section='')">
+	<div class="menubar">
+		<div class="menubar-inner">
+			<div class="container-fluid">
+				<ul class="nav">
+					<li><a href="${url("desktop.views.dump_config")}" class="${is_selected(section, 'dump_config')}">Configuration</a></li>
+					<li><a href="${url("desktop.views.check_config")}" class="${is_selected(section, 'check_config')}">Check for misconfiguration</a></li>
+					<li><a href="${url("desktop.views.log_view")}" class="${is_selected(section, 'log_view')}">Server Logs</a></li>
+				</ul>
+			</div>
+		</div>
+	</div>
+</%def>
+

+ 2 - 13
desktop/core/src/desktop/templates/check_config.mako

@@ -17,20 +17,9 @@
 from desktop.lib.conf import BoundConfig
 from desktop.views import commonheader, commonfooter
 %>
+<%namespace name="layout" file="about_layout.mako" />
 ${commonheader("About", "about", "100px")}
-
-	<div class="menubar">
-		<div class="menubar-inner">
-			<div class="container-fluid">
-				<ul class="nav">
-					<li><a href="${url("desktop.views.dump_config")}">Configuration</a></li>
-					<li><a href="${url("desktop.views.check_config")}" class="selected">Check for misconfiguration</a></li>
-					<li><a href="${url("desktop.views.log_view")}">Server Logs</a></li>
-				</ul>
-			</div>
-		</div>
-	</div>
-
+${layout.menubar(section='check_config')}
 
 	<div class="container-fluid">
 

+ 70 - 131
desktop/core/src/desktop/templates/dump_config.mako

@@ -17,91 +17,17 @@
 ## Note that this is similar to the config_dump management command.
 <%!
 from desktop.lib.conf import BoundContainer, is_anonymous
+from desktop.views import commonheader, commonfooter
 %>
+<%namespace name="layout" file="about_layout.mako" />
+${commonheader("About", "about", "100px")}
+${layout.menubar(section='dump_config')}
 
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
-	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
-	<meta name="viewport" content="width=device-width user-scalable=no initial-scale=1" />
-	<meta name="apple-mobile-web-app-capable" content="yes" />
-	<title>About :: Hue Configuration</title>
-	<link rel="stylesheet" href="/static/ext/css/bootstrap.min.css" type="text/css" media="screen" title="no title" charset="utf-8" />
-	<link rel="stylesheet" href="/static/css/jhue.css" type="text/css" media="screen" title="no title" charset="utf-8" />
-	<link rel="stylesheet" href="/static/ext/css/fileuploader.css" type="text/css" media="screen" title="no title" charset="utf-8" />
-	
-	<style type="text/css">
-      body {
-        padding-top: 100px;
-      }
-    </style>
-	<script src="/static/ext/js/jquery/jquery-1.7.min.js" type="text/javascript" charset="utf-8"></script>
-	<script src="/static/js/Source/jHue/jquery.showusername.js" type="text/javascript" charset="utf-8"></script>
-	<script src="/static/js/Source/jHue/jquery.filechooser.js" type="text/javascript" charset="utf-8"></script>
-	<script src="/static/js/Source/jHue/jquery.contextmenu.js" type="text/javascript" charset="utf-8"></script>
-	<script src="/static/ext/js/jquery/plugins/jquery.simpleplaceholder.js" type="text/javascript" charset="utf-8"></script>
-	<script src="/static/ext/js/jquery/plugins/jquery.dataTables.1.8.2.min.js" type="text/javascript" charset="utf-8"></script>
-	<script src="/static/ext/js/bootstrap-dropdown.js" type="text/javascript" charset="utf-8"></script>	
-	<script src="/static/ext/js/bootstrap-tabs.js" type="text/javascript" charset="utf-8"></script>	
-	<script src="/static/ext/js/bootstrap-modal.js" type="text/javascript" charset="utf-8"></script>	
-	<script src="/static/ext/js/bootstrap-twipsy.js" type="text/javascript" charset="utf-8"></script>	
-	<script src="/static/ext/js/bootstrap-popover.js" type="text/javascript" charset="utf-8"></script>	
-	<script src="/static/ext/js/fileuploader.js" type="text/javascript" charset="utf-8"></script>
-
-	<script type="text/javascript" charset="utf-8">
-		$(document).ready(function(){
-			$("#username").showUsername();
-			$("input:text[placeholder]").simplePlaceholder();
-			$(".submitter").keydown(function(e){
-				if (e.keyCode==13){
-					$(this).closest("form").submit();
-				}
-			}).change(function(){
-				$(this).closest("form").submit();
-			});
-		});
-	</script>
-	
-</head>
-<body>
-	<div class="topbar">
-		<div class="topbar-inner">
-			<div class="container-fluid">
-				<a class="brand" href="#">jHue</a>
-				<ul class="nav">
-					<li><a href="/beeswax">Beeswax</a></li>
-					<li><a href="/filebrowser/">File Browser</a></li>
-					<li><a href="/jobsub/">Job Designer</a></li>
-					<li><a href="/jobbrowser/jobs/">Job Browser</a></li>
-					<li><a href="/useradmin/">User Admin</a></li>
-					<li><a href="/shell/">Shell</a></li>
-					<li><a href="/help/">Help</a></li>
-					<li class="active"><a href="/about/">About</a></li>
-				</ul>
-				<p class="pull-right">Logged in as <a id="username" href="/accounts/logout">xxx</a></p>
-			</div>
-		</div>
-	</div>
-	<div class="menubar">
-		<div class="menubar-inner">
-			<div class="container-fluid">
-				<ul class="nav">
-					<li><a href="${url("desktop.views.dump_config")}" class="selected">Configuration</a></li>
-					<li><a href="${url("desktop.views.check_config")}">Check for misconfiguration</a></li>
-					<li><a href="${url("desktop.views.log_view")}">Server Logs</a></li>
-				</ul>
-			</div>
-		</div>
-	</div>
-	
-	
 	<div class="container-fluid">
 
 		Configuration files located in <code>${conf_dir}</code>
 		<br/><br/>
-		
+
 		<h2>Installed applications</h2>
 		<ul>
 		% for app in sorted(apps, key=lambda app: app.name.lower()):
@@ -109,65 +35,79 @@ from desktop.lib.conf import BoundContainer, is_anonymous
 		% endfor
 		</ul>
 
-		<h2>Configuration Sections</h2>
-		
+
+
+
+		<h2>Configuration Sections and Variables</h2>
+
 		<ul class="tabs">
 			% for obj in top_level.get().values():
-				<li><a href="#${obj.config.key}">${obj.config.key}</a></li>
+				<li><a href="#${obj.config.key}Conf">${obj.config.key}</a></li>
 			% endfor
 		</ul>
 
-		
-		
-
-		<h2>Configuration Variables</h2>
+		<%def name="showTopLevel(config_obj, depth=0)">
+			<div class="tab-content">
+				% if isinstance(config_obj, BoundContainer):
+					% for v in config_obj.get().values():
+				<%
+				      # Don't recurse into private variables.
+				      if v.config.private and not show_private:
+				        continue
+				%>
+					<div id="${v.config.key}Conf" class="tab-pane">
+				    	${recurse(v, depth + 1)}
+					</div>
+				    % endfor
+				% endif
+			</div>
+		</%def>
 
 		<%def name="recurse(config_obj, depth=0)">
-		% if is_anonymous(config_obj.config.key):
-			moo
-		% else:
-		    % if depth == 1:			  
-		      <hr/>
-		    % endif
-        % endif
-		<table>
-		<tr>
-		  <th>
-		  % if is_anonymous(config_obj.config.key):
-		    <i>(default section)</i>
-		  % else:
-		    % if depth == 1:			  
-		      <a name=${config_obj.config.key}></a>
-		    % endif
-		    ${config_obj.config.key}
-		  % endif
-		  </th>
-		  <td>
-		  % if isinstance(config_obj, BoundContainer):
-		    <p class="dump_config_help"><i>${config_obj.config.help or "No help available."}</i></p>
-
-		    % for v in config_obj.get().values():
-		<%
-		      # Don't recurse into private variables.
-		      if v.config.private and not show_private:
-		        continue
-		%>
-		    ${recurse(v, depth + 1)}
-		    % endfor
-		  % else:
-		    <p>${str(config_obj.get())}</p>
-		    <p class="dump_config_help"><i>${config_obj.config.help or "No help available."}</i></p>
-		    <p class="dump_config_default">Default: <i>${config_obj.config.default}</i></p>
-		  % endif
-		  </td>
-		</tr>
-		</table>
+			<table>
+			<tr>
+			 % if depth > 1:
+			  <th>
+			  % if is_anonymous(config_obj.config.key):
+			    <i>(default section)</i>
+			  % else:
+			    ${config_obj.config.key}
+			  % endif
+			  </th>
+			 % endif
+    		 % if depth == 1:
+				<td style="border-top:0">
+	         % else:
+			  	<td>
+			 % endif
+			  % if isinstance(config_obj, BoundContainer):
+			    <p class="dump_config_help"><i>${config_obj.config.help or "No help available."}</i></p>
+
+			    % for v in config_obj.get().values():
+			<%
+			      # Don't recurse into private variables.
+			      if v.config.private and not show_private:
+			        continue
+			%>
+			    ${recurse(v, depth + 1)}
+			    % endfor
+			  % else:
+			    <p>${str(config_obj.get())}</p>
+			    <p class="dump_config_help"><i>${config_obj.config.help or "No help available."}</i></p>
+			    <p class="dump_config_default">Default: <i>${config_obj.config.default}</i></p>
+			  % endif
+			  </td>
+			</tr>
+			</table>
 		</%def>
-		
-		${recurse(top_level)}
 
-		<hr/>
-		
+
+		${showTopLevel(top_level)}
+
+		<br/>
+		<br/>
+		<br/>
+
 	</div>
 
 	<script type="text/javascript" charset="utf-8">
@@ -175,6 +115,5 @@ from desktop.lib.conf import BoundContainer, is_anonymous
 			$(".tabs").tabs();
 		});
 	</script>
-</body>
 
-</html>
+${commonfooter()}

+ 44 - 0
desktop/core/src/desktop/templates/logs.mako

@@ -0,0 +1,44 @@
+## Licensed to Cloudera, Inc. under one
+## or more contributor license agreements.  See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership.  Cloudera, Inc. licenses this file
+## to you 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
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+<%!
+from desktop.lib.conf import BoundConfig
+from desktop.views import commonheader, commonfooter
+import re
+%>
+<%namespace name="layout" file="about_layout.mako" />
+${commonheader("About", "about", "100px")}
+${layout.menubar(section='log_view')}
+	<%
+		def remove_html_tags(data):
+		    p = re.compile(r'<.*?>')
+		    return p.sub('', data)
+	%>
+
+	<div class="container-fluid">
+		<h1>Log entries (most recent first)</h1>
+
+		<a href="/download_logs">Download entire log as zip</a>
+		<hr/>
+		<% log.reverse() %>
+		<pre>
+		% for l in log:
+${remove_html_tags(l)}
+		% endfor
+		</pre>
+
+	</div>
+
+${commonfooter()}

+ 3 - 2
desktop/core/src/desktop/views.py

@@ -48,8 +48,9 @@ def log_view(request):
   l = logging.getLogger()
   for h in l.handlers:
     if isinstance(h, desktop.log.log_buffer.FixedBufferHandler):
-      return render_to_response("logs.html", dict(log=[l for l in h.buf]))
-  return render_to_response("logs.html", dict(log=["No logs found!"]))
+	  return render('logs.mako', request, dict(log=[l for l in h.buf]))
+
+  return render('logs.mako', request, dict(log=["No logs found!"]))
 
 @access_log_level(logging.WARN)
 def download_log_view(request):