Add volume_info helper method

This commit is contained in:
kyg516 2016-09-29 15:53:08 +09:00
parent fbea26361d
commit afe9c6d309
2 changed files with 238 additions and 256 deletions

View File

@ -1,8 +1,42 @@
module VolumeHelper
def volume_info(volume)
def volume_info(volume, index)
params = ['Type', 'Volume ID', 'Status', 'Number of Bricks', 'Transport-type', 'Bricks', 'Options Reconfigured', 'Mount State', 'Mount Point']
arrow = ((index == 0) ? "up" : "down")
display = ((index != 0) ? "style='display: none;'" : "")
lights = []
lights << ((volume['Status'].eql? " Stopped" or volume['Status'].eql? " Created") ? "red" : "")
lights << ((!volume['Mount State'].eql? "mounted" and volume['Status'].eql? " Started") ? "blue" : "")
lights << ((volume['Mount State'].eql? "mounted") ? "green" : "")
html = ''
html << "<div class='col-md-6 col-sm-6 col-xs-12'>"
html << "<div class='x_panel'>"
html << "<div class='x_title'>"
# left title
html << "<h2>Infomation <small>#{volume['Volume Name']}</small></h2>"
# right title
html << "<ul class='nav navbar-right panel_toolbox'>"
html << "<li><a class='collapse-link'>"
html << "<i class='fa fa-chevron-#{arrow}'></i></a></li>"
html << "<li class='dropdown'>"
html << "<a class='dropdown-toggle' data-toggle='dropdown' role='button' aria-expanded='false'><i class='fa fa-wrench'></i></a>"
html << "<ul class='dropdown-menu' role='menu'>"
html << "<li><a href='#'>Settings 1</a></li>"
html << "<li><a href='#'>Settings 2</a></li>"
html << "</ul>"
html << "</li>"
html << "<li><a><i class='fa fa-circle #{lights[2]}'></i></a></li>"
html << "<li><a><i class='fa fa-circle #{lights[1]}'></i></a></li>"
html << "<li><a><i class='fa fa-circle #{lights[0]}'></i></a></li>"
html << "</ul>"
html << "<div class='clearfix'></div>"
html << "</div>"
html << "<div class='x_content' #{display}>"
# left content
html << "<div class='col-md-6 col-sm-6 col-xs-12'>"
html << "<div style='margin: 10px'>"
html << "<p class='text-muted font-13 m-b-30'><span class='badge bg-blue'>Volume Info</span></p>"
# volume_info
html << "<div>"
params.each do |t|
next if volume[t].nil?
@ -11,7 +45,47 @@ module VolumeHelper
html << "</p>"
end
html << "</div>"
raw(html)
html << "</div>"
# buttons
if volume["Mount State"] == "mounted"
html << "<a class='btn btn-app' href='/volume/unmount/#{volume['Volume Name'].delete(' ')}'><i class='fa fa-upload'></i> Unmount</a>"
elsif volume["Status"] == " Started"
html << "<a class='btn btn-app' href='/volume/stop/#{volume['Volume Name'].delete(' ')}%>'>"
html << "<i class='fa fa-pause' style='color:#d9534f;'></i>"
html << "<p style='color:#d9534f;'>Stop</p>"
html << "</a>"
html << "<a class='btn btn-app' href='?volume_name=#{volume['Volume Name'].delete(' ')}%>#popup_mount'><i class='fa fa-download'></i> Mount</a>"
else
html << "<a class='btn btn-app' href='/volume/start/#{volume['Volume Name'].delete(' ')}'>"
html << "<i class='fa fa-play' style='color:#26B99A;'></i>"
html << "<p style='color:#26B99A;'>Start</p>"
html << "</a>"
html << "<a class='btn btn-app' href='/volume/delete/#{volume['Volume Name'].delete(' ')}'>"
html << "<i class='fa fa-trash'></i> Delete"
html << "</a>"
end
html << "</div>"
# right content
html << "<div class='col-md-6 col-sm-6 col-xs-12'>"
if volume["Mount State"] == "mounted"
html << "<p class='text-muted font-13 m-b-30'><span class='badge bg-green'>Uploader</span> Activated</p>"
html << "<form action='/file_upload/#{volume['Volume Name'].delete(' ')}' method='post' enctype='multipart/form-data' class='dropzone' style='border: 1px solid #e5e5e5; height: 300px; overflow:auto;'>"
html << "</form>"
html << "<br/>"
else
html << "<p class='text-muted font-13 m-b-30'><span class='badge bg-red'>Uploader</span> Inactivated</p>"
html << "<form style='border: 1px solid #e5e5e5; height: 300px; overflow:auto;'>"
html << "</form>"
html << "<br/>"
end
html << "</div>"
html << "</div>"
html << "</div>"
html << "</div>"
html
end
def mount_table(dir = @current_dir, id = "mount_table", class_option = "table table-striped table-bordered jambo_table")

View File

@ -88,100 +88,8 @@
</div>
<div class="clearfix"></div>
<div class="row">
<% volumes.each_with_index do |t, index| %>
<div class="col-md-6 col-sm-6 col-xs-12">
<div class="x_panel">
<div class="x_title">
<!-- left title -->
<h2>Infomation <small><%=t["Volume Name"]%></small></h2>
<!-- right title -->
<ul class="nav navbar-right panel_toolbox">
<li><a class="collapse-link">
<% if index == 0 %>
<i class="fa fa-chevron-up"></i>
<% else %>
<i class="fa fa-chevron-down"></i>
<% end %></a>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Settings 1</a>
</li>
<li><a href="#">Settings 2</a>
</li>
</ul>
</li>
<li>
<%if t['Mount State'].eql? "mounted" %>
<a><i class="fa fa-circle green"></i></a>
<% else %>
<a><i class="fa fa-circle"></i></a>
<% end %>
</li>
<li>
<%if !t['Mount State'].eql? "mounted" and t['Status'].eql? " Started" %>
<a><i class="fa fa-circle blue"></i></a>
<% else %>
<a><i class="fa fa-circle"></i></a>
<% end %>
</li>
<li>
<%if t['Status'].eql? " Stopped" or t['Status'].eql? " Created" %>
<a><i class="fa fa-circle red"></i></a>
<% else %>
<a><i class="fa fa-circle"></i></a>
<% end %>
</li>
</ul>
<div class="clearfix"></div>
</div>
<% if index == 0 %>
<div class="x_content">
<% else %>
<div class="x_content" style="display: none;">
<% end %>
<!-- left content -->
<div class="col-md-6 col-sm-6 col-xs-12">
<div style="margin: 10px">
<p class="text-muted font-13 m-b-30"><span class="badge bg-blue">Volume Info</span></p>
<%= volume_info t %>
</div>
<% if t["Mount State"] == "mounted" %>
<a class="btn btn-app" href="/volume/unmount/<%=t['Volume Name'].delete(' ')%>"><i class="fa fa-upload"></i> Unmount</a>
<% elsif t["Status"] == " Started" %>
<a class="btn btn-app" href="/volume/stop/<%=t['Volume Name'].delete(' ')%>">
<i class="fa fa-pause" style="color:#d9534f;"></i>
<p style="color:#d9534f;">Stop</p>
</a>
<a class="btn btn-app" href="?volume_name=<%=t['Volume Name'].delete(' ')%>#popup_mount"><i class="fa fa-download"></i> Mount</a>
<% else %>
<a class="btn btn-app" href="/volume/start/<%=t['Volume Name'].delete(' ')%>">
<i class="fa fa-play" style="color:#26B99A;"></i>
<p style="color:#26B99A;">Start</p>
</a>
<a class="btn btn-app" href="/volume/delete/<%=t['Volume Name'].delete(' ')%>">
<i class="fa fa-trash"></i> Delete
</a>
<% end %>
</div>
<!-- right content -->
<div class="col-md-6 col-sm-6 col-xs-12">
<% if t["Mount State"] == "mounted" %>
<p class="text-muted font-13 m-b-30"><span class="badge bg-green">Uploader</span> Activated</p>
<form action="/file_upload/<%=t['Volume Name'].delete(' ')%>" method="post" enctype="multipart/form-data" class="dropzone" style="border: 1px solid #e5e5e5; height: 300px; overflow:auto;">
</form>
<br/>
<% else %>
<p class="text-muted font-13 m-b-30"><span class="badge bg-red">Uploader</span> Inactivated</p>
<form style="border: 1px solid #e5e5e5; height: 300px; overflow:auto;">
</form>
<br/>
<% end %>
</div>
</div>
</div>
</div>
<% volumes.each_with_index do |volume, index| %>
<%= raw volume_info(volume, index) %>
<%end%>
</div>
</div>