forked from ManageIQ/manageiq-ui-classic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ManageIQ#174 from vecerek/miq_pr_13111
Toolbar refactoring: VM buttons
- Loading branch information
Showing
24 changed files
with
431 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class ApplicationHelper::Button::VmCheckCompliance < ApplicationHelper::Button::InstanceCheckCompare | ||
def visible? | ||
true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
class ApplicationHelper::Button::VmConsole < ApplicationHelper::Button::Basic | ||
needs :@record | ||
|
||
def visible? | ||
console_supports_type?('MKS') | ||
end | ||
|
||
def disabled? | ||
unless supported_browser? && supported_os? | ||
@error_message = _('The web-based console is only available on IE, Firefox or Chrome (Windows/Linux)') | ||
return true | ||
end | ||
|
||
yield if block_given? | ||
return true if @error_message.present? | ||
|
||
@error_message = _('The web-based console is not available because the VM is not powered on') unless on? | ||
@error_message.present? | ||
end | ||
|
||
private | ||
|
||
def console_supports_type?(supported_type) | ||
::Settings.server.remote_console_type == supported_type ? @record.console_supported?(supported_type) : false | ||
end | ||
|
||
def on? | ||
@record.current_state == 'on' | ||
end | ||
|
||
def supported_browser? | ||
@view_context.is_browser?(%w(explorer firefox mozilla chrome)) | ||
end | ||
|
||
def supported_os? | ||
@view_context.is_browser_os?(%w(windows linux)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class ApplicationHelper::Button::VmSnapshotAdd < ApplicationHelper::Button::Basic | ||
def disabled? | ||
@error_message = if records_and_role_allows? && !@active | ||
_('Select the Active snapshot to create a new snapshot for this VM') | ||
else | ||
@record.is_available_now_error_message(:create_snapshot) | ||
end | ||
@error_message.present? | ||
end | ||
|
||
private | ||
|
||
def records_and_role_allows? | ||
@record.is_available?(:create_snapshot) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class ApplicationHelper::Button::VmTimeline < ApplicationHelper::Button::Basic | ||
needs :@record | ||
|
||
def disabled? | ||
@error_message = _('No Timeline data has been collected for this VM') unless proper_events? | ||
end | ||
|
||
private | ||
|
||
def proper_events? | ||
@record.has_events? || @record.has_events?(:policy_events) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class ApplicationHelper::Button::VmVmrcConsole < ApplicationHelper::Button::VmConsole | ||
needs :@record | ||
|
||
def visible? | ||
console_supports_type?('VMRC') | ||
end | ||
|
||
def disabled? | ||
super { remote_control_supported? } | ||
end | ||
|
||
private | ||
|
||
def remote_control_supported? | ||
@record.validate_remote_console_vmrc_support | ||
rescue MiqException::RemoteConsoleNotSupportedError => err | ||
@error_message = _('VM VMRC Console error: %{error}') % {:error => err} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class ApplicationHelper::Button::VmVncConsole < ApplicationHelper::Button::VmConsole | ||
needs :@record | ||
|
||
def visible? | ||
return console_supports_type?('VNC') if @record.vendor == 'vmware' | ||
@record.console_supported?('vnc') | ||
end | ||
|
||
def disabled? | ||
@error_message = _('The web-based VNC console is not available because the VM is not powered on') unless on? | ||
@error_message.present? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 3 additions & 14 deletions
17
spec/helpers/application_helper/buttons/container_timeline_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,11 @@ | ||
describe ApplicationHelper::Button::ContainerTimeline do | ||
let(:record) { FactoryGirl.create(:container) } | ||
subject do | ||
let(:button) do | ||
described_class.new(setup_view_context_with_sandbox({}), {}, {'record' => record}, | ||
{:options => {:entity => 'Container'}}) | ||
end | ||
|
||
before { allow(record).to receive(:has_events?).and_return(has_events) } | ||
|
||
describe '#disabled?' do | ||
%i(ems_events policy_events).each do |event_type| | ||
context "record has #{event_type}" do | ||
let(:has_events) { true } | ||
it { expect(subject.disabled?).to be_falsey } | ||
end | ||
end | ||
context 'record has no ems_events or policy_events' do | ||
let(:has_events) { false } | ||
it { expect(subject.disabled?).to be_truthy } | ||
end | ||
describe '#calculate_properties?' do | ||
it_behaves_like 'timeline#calculate_properties', 'No Timeline data has been collected for this Container' | ||
end | ||
end |
13 changes: 13 additions & 0 deletions
13
spec/helpers/application_helper/buttons/vm_console_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
describe ApplicationHelper::Button::VmConsole do | ||
let(:view_context) { setup_view_context_with_sandbox({}) } | ||
let(:record) { FactoryGirl.create(:vm) } | ||
let(:button) { described_class.new(view_context, {}, {'record' => record}, {}) } | ||
|
||
describe '#visible?' do | ||
it_behaves_like 'vm_console_visible?', 'MKS' | ||
end | ||
|
||
describe '#calculate_properties' do | ||
it_behaves_like 'vm_console_calculate_properties' | ||
end | ||
end |
48 changes: 48 additions & 0 deletions
48
spec/helpers/application_helper/buttons/vm_snapshot_add_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
describe ApplicationHelper::Button::VmSnapshotAdd do | ||
let(:view_context) { setup_view_context_with_sandbox({}) } | ||
let(:zone) { EvmSpecHelper.local_miq_server(:is_master => true).zone } | ||
let(:ems) { FactoryGirl.create(:ems_vmware, :zone => zone, :name => 'Test EMS') } | ||
let(:host) { FactoryGirl.create(:host) } | ||
let(:record) { FactoryGirl.create(:vm_vmware, :ems_id => ems.id, :host_id => host.id) } | ||
let(:active) { true } | ||
let(:button) { described_class.new(view_context, {}, {'record' => record, 'active' => active}, {}) } | ||
|
||
describe '#calculate_properties' do | ||
before { button.calculate_properties } | ||
context 'when creating snapshots is available' do | ||
let(:current) { 1 } | ||
let(:record) do | ||
record = FactoryGirl.create(:vm_vmware, :ems_id => ems.id, :host_id => host.id) | ||
record.snapshots = [FactoryGirl.create(:snapshot, | ||
:create_time => 1.minute.ago, | ||
:vm_or_template_id => record.id, | ||
:name => 'EvmSnapshot', | ||
:description => "Some Description", | ||
:current => current)] | ||
record | ||
end | ||
context 'and the selected snapshot is not active' do | ||
let(:active) { false } | ||
it_behaves_like 'a disabled button', 'Select the Active snapshot to create a new snapshot for this VM' | ||
end | ||
context 'and the selected snapshot may be active but the vm is not connected to a host' do | ||
let(:record) { FactoryGirl.create(:vm_vmware) } | ||
it_behaves_like 'a disabled button', 'The VM is not connected to a Host' | ||
end | ||
context 'and the selected snapshot is active and current' do | ||
context 'and current' do | ||
it_behaves_like 'an enabled button' | ||
end | ||
context 'but not current' do | ||
let(:current) { 0 } | ||
it_behaves_like 'a disabled button', | ||
'At least one snapshot has to be active to create a new snapshot for this VM' | ||
end | ||
end | ||
end | ||
context 'when creating snapshots is not available' do | ||
let(:record) { FactoryGirl.create(:vm_amazon) } | ||
it_behaves_like 'a disabled button', 'Create Snapshot operation not supported for Amazon VM' | ||
end | ||
end | ||
end |
Oops, something went wrong.