Skip to content

Commit

Permalink
fix base navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
mose committed Jan 25, 2016
1 parent 7915bf2 commit 00ab2d8
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 42 deletions.
28 changes: 8 additions & 20 deletions app/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,21 @@ class Common < Sinatra::Base

helpers do
def prepare_base(e, r)
path = validate_basepath(e, r)
@base = get_base(path)
if @base == ''
@base_name = File.basename(settings.configdata['basepath'])
else
e = File.basename(settings.configdata['basepath']) unless e
path = get_path(e)[0]
if path
@base = get_base(path)
@base_name = @base.gsub(/\//,'')
get_config(path)
end
get_config(path)
end
def get_path(path)
if settings.basepaths
settings.basepaths.select do |p|
path == File.basename(p)
end
end
end
def validate_basepath(path, url)
if path
if get_path(path)
get_path(path)[0]
else
redirect url
end
else
[ settings.configdata['basepath'] ]
end
end
def get_config(path)
Expand All @@ -53,11 +45,7 @@ def get_config(path)
end
end
def get_base(path)
if path
"/#{File.basename(path)}"
else
''
end
"/#{File.basename(path)}"
end
end

Expand Down
18 changes: 10 additions & 8 deletions app/public/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ input {
line-height: .5em;
margin-right: 1em;
}
.head .nav, .head .env {
.head .nav, .head .nav .base {
position: relative;
float: left;
display: inline-block;
}
.head .env .current {

.head .base .current {
position: relative;
color: #fff;
background-color: #666;
Expand All @@ -56,30 +57,31 @@ input {
margin-right: 1em;
cursor: pointer;
}
.head .env .allenvs {
.head .base .all {
position: absolute;
/*display: none;*/
background-color: #fff;
width: auto;
overflow-x: visible;
margin-top: 1em;
border: 1px solid #666;
}
.head .env .allenvs .filter {
.head .base .all .filter {
margin: 0;
background-color: #999;
font-size: 1.2em;
}
.head .env .allenvs .filter input {
.head .base .all .filter input {
width: 100%;
margin-bottom: .1em;
padding: .1em 1em;
}
.head .env .allenvs .selectenv {
.head .base .all .select {
padding: .2em 1em;
color: #666;
cursor: pointer;
}
.head .env .allenvs .selectenv:hover {
.head .base .all .select:hover {
color: #000;
background-color: #ddd;
}
Expand All @@ -99,7 +101,7 @@ input {
background-color: #fff;
color: #000;
}
.head .envs {
.head .base {
position: relative;
float: right;
display: inline-block;
Expand Down
13 changes: 13 additions & 0 deletions app/public/js/base-switch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

ready( () => {
var bases = document.querySelectorAll('.base .all .select');
filterBox(".base .all .filter input", bases);

/* declaration of events for the bases menu */
Array.prototype.forEach.call(bases, (item, i) => {
item.addEventListener('click', (ev) => {

});
});

});
10 changes: 6 additions & 4 deletions app/views/_head.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
</a>
</div>

<% if session[:access_token] && @username != '' -%>
<% if session[:access_token] && @username != '' and @base -%>
<div class="nav">
<% if settings.basepaths -%>
<div class="env">
<div class="base">
<span class="current"><%= @base_name %></span>
<div class="allenvs">
<div class="all">

<form class="filter">
<input type="text" name="filter" />
</form>

<% settings.basepaths.map { |p| File.basename(p) }.each do |e| -%>
<div class="selectenv"><%= e %></div>
<div class="select"><%= e %></div>
<% end -%>
</div>
</div>
Expand All @@ -27,7 +27,9 @@
<a href="<%= @base %>/modules" class="modules">Modules</a>
<a href="<%= @base %>/resources" class="resources">Resources</a>
</div>
<% end -%>
<% if session[:access_token] && @username != '' -%>
<div class="auth">
<div class="username">
identified as <a href="<%= @base %>/user" class="link"><%= @username %></a>
Expand Down
3 changes: 3 additions & 0 deletions app/views/_layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<link href="/css/main.css" rel="stylesheet" type="text/css">
<script src="/js/fetch.js"></script>
<script src="/js/main.js"></script>
<% if settings.basepaths -%>
<script src="/js/base-switch.js"></script>
<% end -%>
<% if session['access_token'] -%>
<script>var session_key = "<%= session['access_token'] %>";</script>
<% end -%>
Expand Down
17 changes: 9 additions & 8 deletions app/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,33 +121,33 @@ def check_authorization
end
end

get %r{/?([-_\.a-zA-Z0-9]+)?(/nodes)} do |e, r|
get %r{^/?([-_\.a-zA-Z0-9]+)?(/nodes)} do |e, r|
@username = check_authorization
hieracles_config = prepare_base(e, r)
@nodes = Hieracles::Registry.nodes(hieracles_config)
erb :nodes
erb :nodes
end

get %r{/?([-_\.a-zA-Z0-9]+)?(/farms)} do |e, r|
get %r{^/?([-_\.a-zA-Z0-9]+)?(/farms)} do |e, r|
@username = check_authorization
hieracles_config = prepare_base(e, r)
@farms = Hieracles::Registry.farms(hieracles_config)
erb :farms
end

get %r{/?([-_\.a-zA-Z0-9]+)?(/modules)} do |e, r|
get %r{^/?([-_\.a-zA-Z0-9]+)?(/modules)} do |e, r|
@username = check_authorization
hieracles_config = prepare_base(e, r)
erb :modules
end

get %r{/?([-_\.a-zA-Z0-9]+)?(/resources)} do |e, r|
get %r{^/?([-_\.a-zA-Z0-9]+)?(/resources)} do |e, r|
@username = check_authorization
hieracles_config = prepare_base(e, r)
erb :resources
erb :resources if hieracles_config
end

get %r{/?([-_\.a-zA-Z0-9]+)?(user)} do |e, r|
get %r{^/?([-_\.a-zA-Z0-9]+)?(/user)} do |e, r|
@username = check_authorization
hieracles_config = prepare_base(e, r)
if session[:access_token]
Expand All @@ -158,7 +158,7 @@ def check_authorization
erb :user
end

get %r{/([-_\.a-zA-Z0-9]+)} do |e|
get %r{^/([-_\.a-zA-Z0-9]+)$} do |e|
@username = get_username
hieracles_config = prepare_base(e, '/')
erb :home
Expand All @@ -179,6 +179,7 @@ def check_authorization
# debug pages --------------------

not_found do
@username = get_username
erb :not_found, layout: :_layout
end

Expand Down
4 changes: 2 additions & 2 deletions spec/app/web_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
before { get '/resources' }
it { expect(last_response.body).to include 'Work In Progress' }
end
describe "GET /toto" do
before { get '/toto' }
describe "GET /tata/toto" do
before { get '/tata/toto' }
it { expect(last_response.status).to eq 404 }
it { expect(last_response.body).to include 'Page not found' }
end
Expand Down

0 comments on commit 00ab2d8

Please sign in to comment.