Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew committed May 17, 2019
2 parents 34780d9 + 7bf730a commit 2be4602
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 28 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,12 @@ Prerequisites:

* [Flight Inventory](https://github.com/openflighthpc/flight-inventory) installed
* [Flight Inventory Diagrams](https://github.com/alces-software/flight-inventory-diagrams) plugin installed
* [Template](templates/switchOW.md.erb) moved to the `templates` directory of the `Flight Inventory` install
* Within `Flight Inventory` add the following to the `etc/templates.yml` file:

```
overware:
default: server.md.erb
server: server.md.erb
switch: switchOW.md.erb
```
7 changes: 7 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,10 @@ textarea {
max-width: initial;
max-width: max-content;
}

a.fill-container {
display: block;
height: 100%;
width: 100%;
text-decoration: none;
}
10 changes: 10 additions & 0 deletions app/assets/stylesheets/assets.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@
white-space: nowrap;
padding: 0px 4px;
}

h1 span {
position: relative;
}

h1 span i {
position: absolute;
right: calc(100% + 20px);
margin-top: 0.5rem !important;
}
36 changes: 10 additions & 26 deletions app/controllers/assets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,33 @@ class AssetsController < ApplicationController

def index
redirect_unless_bolt_on('Assets')

cmd = "flight inventory list"
if params[:filter_on] and !params[:filter_arg].blank?
@active_cluster = execute("flight inventory list-cluster").
lines.first.remove('*').strip.capitalize

if params[:filter_on]
cmd = cmd + " --#{params[:filter_on]} #{params[:filter_arg].downcase}"
end

@assets = get_assets(cmd)
end

def single_asset
redirect_unless_bolt_on('Assets')

@name = params[:name]
cmd = "flight inventory show #{@name} -f diagram-markdown;"
cmd = "flight inventory show #{@name} -f overware;"
@asset_data = execute(cmd)
img_regex = /<img\ssrc=.+>/
if @asset_data.match?(img_regex)
parts = @asset_data.partition(img_regex)

asset_list = []
get_assets.each do |key, value|
asset_list.concat(value)
end

parts[0] = format_markdown(parts[0])
parts[2] = format_markdown(parts[2])

[parts[0], parts[2]].each do |p|
p.scan(/[\w-]+/).each do |w|
if asset_list.include?(w)
p[w] = view_context.link_to(w, assets_path + '/' + w)
end
end
end

@content = parts.reduce{ |a, b| a + b }
else
@content = format_markdown(@asset_data)
end
@content = format_markdown(@asset_data)
end

def asset_params
params.require(:asset).permit(:filter_on, :filter_arg)
end

private

# currently just returns stdout, this may need to be altered
def execute(cmd)
#This ';' is neccessary to force shell execution
Expand Down
1 change: 1 addition & 0 deletions app/models/concerns/markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def self.render(markdown_text)
[
:GITHUB_PRE_LANG,
:HARDBREAKS,
:UNSAFE,
],
[:tagfilter]
).strip
Expand Down
10 changes: 8 additions & 2 deletions app/views/assets/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,23 @@
<% end %>
</div>
</div>
<h1>
<span>
<i class="fa fa-server"></i>
<%= @active_cluster %>
</span>
</h1>
<br>
<% if @assets and not @assets.empty? %>
<% @assets.each do |type, assets| %>
<div id="accordion-<%= type.downcase %>" class="center w-25">
<div class="card mb-1">
<div class="card-header">
<h5 class="mb-0">
<a data-toggle="collapse" href="#<%= type %>">
<a data-toggle="collapse" href="#<%= type %>" class="fill-container">
<%= type.downcase.capitalize %>
<i class="fa fa-minus fa-pull-right mt-1"></i>
</a>
<i class="fa fa-minus fa-pull-right mt-1"></i>
</h5>
</div>

Expand Down
20 changes: 20 additions & 0 deletions templates/switchOW.md.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# <a href="<%= @asset_data.name %>"><%= @asset_data.name %></a>

<% @asset_hash['mutable']['maps'].each do |map| %>

## <%= map.first %>

<img class="mb-2" src="data:image/svg+xml;base64,<%= render_switch_base64(
map[1]['map'],
width: map[1]['map_width'],
height: map[1]['map_height'],
layout: map[1]['map_layout'],
)%>">


|Port|Note|
|----|----|
<% (map[1]['map'] || {}).to_h.each do |k,v| -%>
|<%= k %>|<a href="<%= v %>"><%= v %></a>|
<% end %>
<% end %>

0 comments on commit 2be4602

Please sign in to comment.