Skip to content

Commit

Permalink
Merge pull request #5 from AhmedKamal1432/amahi-8
Browse files Browse the repository at this point in the history
Delete partition path
  • Loading branch information
cpg committed Aug 10, 2015
2 parents 2f63e6c + 238fd80 commit 903195a
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 9 deletions.
22 changes: 17 additions & 5 deletions app/controllers/disk_wizard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class DiskWizardController < ApplicationController
before_filter :clear_mode, except: [:process_disk]

layout 'wizard'
DELELTE_OPTION = '2'

# @return [Device Array] : Return array of Device objects, which are mounted(permanent or temporary) in the HDA.
# Render the first step of the Disk-Wizard(DW)
Expand Down Expand Up @@ -96,11 +97,22 @@ def process_disk
jobs_queue.enqueue({job_name: job_name, job_para: para})
end

if user_selections['option']
para = {path: path, label: label}
job_name = :mount_job
DebugLogger.info "|#{self.class.name}|>|#{__method__}|:Job_name = #{job_name}, para = #{para}"
jobs_queue.enqueue({job_name: job_name, job_para: para})
unless user_selections['option'].blank?
option = user_selections['option'].first.to_i
if option.eql?(1)
para = {path: path, label: label}
job_name = :mount_job
jobs_queue.enqueue({job_name: job_name, job_para: para})
elsif option.eql?(2)
if user_selections['path'].blank?
redirect_to disk_wizards_engine.select_path, :flash => {:error => "You have to choose a partition"}
return false
end
para = {partition: user_selections['path']}
job_name = :delete_partition_job
DebugLogger.info "|#{self.class.name}|>|#{__method__}|:Job_name = #{job_name}, para = #{para}"
jobs_queue.enqueue({job_name: job_name, job_para: para})
end
end

jobs_queue.enqueue({job_name: :post_checks_job, job_para: {path: path}})
Expand Down
12 changes: 12 additions & 0 deletions app/views/disk_wizard/confirmation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@
Mount
Location
</li>
<% elsif option == DiskWizardController::DELELTE_OPTION%>
<!-- delete partitioon -->
<li class="list-group-item text-left">
<span class="badge alert-danger"> <span class="glyphicon glyphicon-ok"></span> </span> Delete Partition
</li>
<% if Partition.method_defined?(:label) and not @selected_disk.label.blank? %>
<li class="list-group-item text-left">
<span class="badge alert-info"><%= @selected_disk.label %></span>
Partition Label
</li>
<% end %>

<% else %>
<li class="list-group-item text-left">
<span class="badge alert-warning"> [Experimental] </span> Add it to shared stroage pool
Expand Down
23 changes: 21 additions & 2 deletions app/views/disk_wizard/done.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@
</tbody>
</table>
</div>
<% else
@user_selections["format"] %>
<% elsif @user_selections["format"] %>
<div class="col-md-6 col-md-offset-3">
<table class="table">
<thead>
Expand All @@ -122,6 +121,26 @@
</tr>
</tbody>
</table>
<% elsif user_selections['option'].eql?(2) %>
<!-- delete partition -->
<div class="col-md-6 col-md-offset-3">
<table class="table">
<thead>
<tr>
<th>Disk name</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<th> <%= user_selections['path'] %></th>
<th class="alert-success"> Deleted</th>
</tr>
</tbody>
</table>
</div>
<% else %>
<!-- Do nothing -->
<% end %>
<div class="col-md-12 well well-sm">
<a href="/tab/disks/disk_wizards" class="btn btn-success"> Continue with another device </a>
Expand Down
21 changes: 19 additions & 2 deletions app/views/disk_wizard/manage_disk.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@
</li>
<li class="list-group-item">
<div class="checkbox">
<%= check_box_tag('option[]', 1, !!((user_selections['option'].include? '1') rescue false), class: 'mount_check') %>
<%= radio_button_tag('option[]', "", !!((user_selections['option'].include? '') rescue false))%>
<div class="alert alert-info">
<label > Nothing </label>
</div>
</div>
</li>
<li class="list-group-item">
<div class="checkbox">
<%= radio_button_tag('option[]', "1", !!((user_selections['option'].include? '1') rescue false), class: 'mount_check') %>
<div class="alert alert-info">
<label for="option_"> Mount this drive automatically.</label>
<div style="<%= !!((user_selections['option'].include? '1') rescue false) ? nil : 'display: none' %>" id="label_input" class="input-group input-group-sm">
Expand All @@ -33,7 +41,16 @@
</div>
</div>
</li>

<% if user_selections['format'].blank?%>
<li class="list-group-item">
<div class="checkbox">
<%= radio_button_tag('option[]', "2", !!((user_selections['option'].include? '2') rescue false)) %>
<div class="alert alert-info">
<label > Delete this partition</label>
</div>
</div>
</li>
<% end %>
</ul>
</div>
</div>
Expand Down
17 changes: 17 additions & 0 deletions lib/modules/operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Operation
def delete
#TODO: remove fstab entry if disk is permanently mounted
#unmount if mountpoint
DebugLogger.info "|#{self.class.name}|>|#{__method__}|:Delete #{self.path}"
DiskUtils.delete_partition self
end

Expand Down Expand Up @@ -66,6 +67,22 @@ def pre_checks_job params_hash
DiskUtils.clear_multipath
end

def delete_partition_job params_hash
DebugLogger.info "|#{self.class.name}|>|#{__method__}|:Params_hash #{params_hash}"
if self.instance_of? Partition
partition = self
else
self.partition.each do |part|
partition = part if part.path = params_hash['partition']
end
unless partition
partition = Device.find params_hash['partition']
end
end
partition.unmount if partition.mountpoint
partition.delete
end

def post_checks_job params_hash
# TODO: Only revert the changes which was done by DW itself.
end
Expand Down

0 comments on commit 903195a

Please sign in to comment.