Skip to content

Commit 4200819

Browse files
committed
Introduce VM description editing page
1 parent f436db4 commit 4200819

File tree

7 files changed

+172
-114
lines changed

7 files changed

+172
-114
lines changed

app/controllers/application_controller/explorer.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,15 @@ def x_history
4646
'manager_pause' => :s1, 'manager_resume' => :s1,
4747

4848
# group 2
49-
'clone' => :s2, 'compare' => :s2, 'drift' => :s2,
50-
'edit' => :s2, 'evm_relationship' => :s2, 'migrate' => :s2,
51-
'ownership' => :s2, 'policy_sim' => :s2, 'protect' => :s2,
52-
'publish' => :s2, 'reconfigure' => :s2, 'miq_request_new' => :s2,
53-
'retire' => :s2, 'right_size' => :s2, 'snapshot_add' => :s2,
54-
'tag' => :s2, 'timeline' => :s2, 'resize' => :s2,
55-
'live_migrate' => :s2, 'attach' => :s2, 'detach' => :s2,
56-
'evacuate' => :s2, 'service_dialog' => :s2,
49+
'clone' => :s2, 'compare' => :s2, 'drift' => :s2,
50+
'edit_description' => :s2,
51+
'edit' => :s2, 'evm_relationship' => :s2, 'migrate' => :s2,
52+
'ownership' => :s2, 'policy_sim' => :s2, 'protect' => :s2,
53+
'publish' => :s2, 'reconfigure' => :s2, 'miq_request_new' => :s2,
54+
'retire' => :s2, 'right_size' => :s2, 'snapshot_add' => :s2,
55+
'tag' => :s2, 'timeline' => :s2, 'resize' => :s2,
56+
'live_migrate' => :s2, 'attach' => :s2, 'detach' => :s2,
57+
'evacuate' => :s2, 'service_dialog' => :s2,
5758
'manager_configuration_script_service_dialog' => :s2,
5859
'associate_floating_ip' => :s2,
5960
'disassociate_floating_ip' => :s2,

app/controllers/vm_common.rb

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,25 +578,36 @@ def remove_service
578578
end
579579
end
580580

581-
def edit
581+
def edit_data(edit_description)
582582
@record = find_record_with_rbac(VmOrTemplate, params[:id]) # Set the VM object
583-
583+
584584
# reset @explorer if coming from explorer views
585585
@edit ||= {}
586586
@edit[:explorer] = true if params[:action] == "x_button" || session.fetch_path(:edit, :explorer)
587587
@explorer = true if @edit[:explorer]
588588
@in_a_form = true
589-
@title = _("Editing %{vm_or_template} \"%{name}\"") % {:name => @record.name, :vm_or_template => model_for_vm(@record).display_name}
589+
title = edit_description ? _("Editing Description of %{vm_or_template} \"%{name}\"") : _("Editing%{vm_or_template} \"%{name}\"")
590+
@title = title % {:name => @record.name, :vm_or_template => model_for_vm(@record).display_name}
590591
@right_cell_text = @title
591592
drop_breadcrumb(:name => @title, :url => "/vm/edit") unless @explorer
592593
@lastaction = "show_list"
593594
@refresh_partial = "vm_common/form"
595+
@edit_description = edit_description
596+
end
597+
598+
def edit
599+
edit_data(false)
600+
end
601+
602+
def edit_description
603+
edit_data(true)
594604
end
595605

596606
# FIXME: these match toolbar button names/features
597607
alias_method :image_edit, :edit
598608
alias_method :instance_edit, :edit
599609
alias_method :vm_edit, :edit
610+
alias_method :vm_edit_description, :edit_description
600611
alias_method :miq_template_edit, :edit
601612

602613
def set_checked_items
@@ -1222,6 +1233,9 @@ def set_right_cell_vars(options = {})
12221233
when "edit"
12231234
partial = "vm_common/form"
12241235
header = _("Editing %{vm_or_template} \"%{name}\"") % {:name => name, :vm_or_template => model_for_vm(@record).display_name}
1236+
when "edit_description"
1237+
partial = "vm_common/form"
1238+
header = _("Editing Description of %{vm_or_template} \"%{name}\"") % {:name => name, :vm_or_template => model_for_vm(@record).display_name}
12251239
when 'chargeback'
12261240
partial = @refresh_partial
12271241
header = _('Chargeback preview for "%{vm_name}"') % { :vm_name => name }

app/helpers/application_helper/toolbar/x_vm_center.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ class ApplicationHelper::Toolbar::XVmCenter < ApplicationHelper::Toolbar::Basic
4343
'pficon pficon-edit fa-lg',
4444
t = N_('Edit this VM'),
4545
t),
46+
button(
47+
:vm_edit_description,
48+
'pficon pficon-edit fa-lg',
49+
t = N_('Edit this VM Description'),
50+
t,
51+
:options => {:feature => :set_description}),
4652
button(
4753
:vm_rename,
4854
'pficon pficon-edit fa-lg',

app/javascript/components/vm-edit-form/helper.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ export const getNoEmsInitialValues = (recordId, isTemplate, setState) => {
7676
});
7777
};
7878

79+
export const descriptionData = (values) => ({
80+
action: 'edit',
81+
resource: { description: values.description ? values.description : '' },
82+
});
83+
7984
export const getSubmitData = (values) => {
8085
let customIdentifier = '';
8186
let description = '';

app/javascript/components/vm-edit-form/index.jsx

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,23 @@ import createSchema from './vm-edit-form.schema';
77
import { API } from '../../http_api';
88
import miqRedirectBack from '../../helpers/miq-redirect-back';
99
import handleFailure from '../../helpers/handle-failure';
10-
import { getInitialValues, getNoEmsInitialValues, getSubmitData } from './helper';
10+
import {
11+
getInitialValues, getNoEmsInitialValues, getSubmitData, descriptionData,
12+
} from './helper';
1113

1214
const VmEditForm = ({
13-
recordId, emsId, displayName, isTemplate,
15+
recordId, emsId, displayName, isTemplate, editDescription,
1416
}) => {
17+
let returnURL = '/vm_infra/explorer/';
18+
if (displayName === 'Image' || displayName === 'Instance') {
19+
returnURL = '/vm_cloud/explorer/';
20+
}
21+
22+
let URL = `/api/vms/${recordId}`;
23+
if (isTemplate) {
24+
URL = `/api/templates/${recordId}`;
25+
}
26+
1527
const [{
1628
initialValues, parentOptions, isLoading,
1729
}, setState] = useState({
@@ -34,20 +46,22 @@ const VmEditForm = ({
3446
}
3547
});
3648

37-
const onSubmit = (values) => {
38-
miqSparkleOn();
39-
let URL = `/api/vms/${recordId}`;
40-
let returnURL = '/vm_infra/explorer/';
41-
const data = getSubmitData(values);
42-
43-
if (displayName === 'Image' || displayName === 'Instance') {
44-
returnURL = '/vm_cloud/explorer/';
45-
}
46-
47-
if (isTemplate) {
48-
URL = `/api/templates/${recordId}`;
49-
}
49+
/** Function to update just the description of the record on form submit. */
50+
const updateDescription = (values) => {
51+
// const data = descriptionData(values);
52+
const payload = { action: 'set_description', resource: { new_description: 'test_description' } };
53+
return API.post(URL, payload)
54+
.then(() => {
55+
miqSparkleOn();
56+
const message = sprintf(__('%s "%s" description was saved'), displayName, initialValues.name);
57+
miqRedirectBack(message, 'success', returnURL);
58+
})
59+
.catch(handleFailure);
60+
};
5061

62+
/** Function to update the entire record on form submit. */
63+
const updateRecord = (values) => {
64+
const data = getSubmitData(values);
5165
return API.post(URL, data)
5266
.then(() => {
5367
miqSparkleOn();
@@ -57,6 +71,13 @@ const VmEditForm = ({
5771
.catch(handleFailure);
5872
};
5973

74+
/** Function to handle the form submit event. */
75+
const onSubmit = (values) => {
76+
miqSparkleOn();
77+
return editDescription ? updateDescription(values) : updateRecord(values);
78+
};
79+
80+
/** Function to handle the form cancel event. */
6081
const onCancel = () => {
6182
miqSparkleOn();
6283
let returnURL = '/vm_infra/explorer/';
@@ -70,7 +91,7 @@ const VmEditForm = ({
7091
if (isLoading) return <Loading className="export-spinner" withOverlay={false} small />;
7192
return !isLoading && (
7293
<MiqFormRenderer
73-
schema={createSchema(emsId, parentOptions)}
94+
schema={createSchema(emsId, parentOptions, editDescription)}
7495
initialValues={initialValues}
7596
canReset={!!recordId}
7697
validate={validation}
@@ -88,6 +109,7 @@ VmEditForm.propTypes = {
88109
emsId: PropTypes.string,
89110
displayName: PropTypes.string.isRequired,
90111
isTemplate: PropTypes.bool.isRequired,
112+
editDescription: PropTypes.bool.isRequired,
91113
};
92114

93115
VmEditForm.defaultProps = {
Lines changed: 91 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,100 @@
11
import { componentTypes } from '@@ddf';
22

3-
function createSchema(emsId, parentOptions) {
4-
const fields = [
5-
{
6-
component: componentTypes.SUB_FORM,
7-
name: 'BasicInformation',
8-
title: __('Basic Information'),
9-
fields: [
10-
{
11-
component: componentTypes.TEXT_FIELD,
12-
name: 'custom_1',
13-
label: __('Custom Identifier'),
14-
maxLength: 50,
15-
autoFocus: true,
3+
/** Function to return the description field schema. */
4+
const descriptionField = () => ([{
5+
component: componentTypes.TEXTAREA,
6+
name: 'description',
7+
label: __('Description'),
8+
maxLength: 100,
9+
}]);
10+
11+
/** Function to return the form schema. */
12+
const defaultFields = (emsId, parentOptions) => ([
13+
{
14+
component: componentTypes.SUB_FORM,
15+
name: 'BasicInformation',
16+
title: __('Basic Information'),
17+
fields: [
18+
{
19+
component: componentTypes.TEXT_FIELD,
20+
name: 'custom_1',
21+
label: __('Custom Identifier'),
22+
maxLength: 50,
23+
autoFocus: true,
24+
},
25+
descriptionField(),
26+
],
27+
},
28+
{
29+
component: componentTypes.SUB_FORM,
30+
name: 'ParentVmSelection',
31+
title: __('Parent VM Selection'),
32+
fields: [
33+
{
34+
component: componentTypes.SELECT,
35+
label: __('Parent VM'),
36+
name: 'parent_vm',
37+
id: 'parent_vm',
38+
placeholder: __('No Parent'),
39+
includeEmpty: true,
40+
validateOnMount: true,
41+
options: parentOptions,
42+
},
43+
],
44+
},
45+
{
46+
component: componentTypes.SUB_FORM,
47+
name: 'ChildVMSelection',
48+
fields: [
49+
{
50+
component: 'dual-list-select',
51+
id: 'child_vms',
52+
name: 'child_vms',
53+
key: `alerts-${emsId}`,
54+
label: __('Child VM Selection'),
55+
rightTitle: __('Child VMs:'),
56+
leftTitle: __('Available VMs:'),
57+
allToRight: true,
58+
moveLeftTitle: __('Move selected VMs to left'),
59+
moveRightTitle: __('Move selected VMs to right'),
60+
moveAllRightTitle: __('Move all VMs to right'),
61+
moveAllLeftTitle: __('Remove All'),
62+
noValueTitle: __('No option selected'),
63+
noOptionsTitle: __('No available options'),
64+
filterOptionsTitle: __('Filter options'),
65+
filterValuesTitle: __('Filter values'),
66+
AddButtonProps: {
67+
id: 'addButtonProps',
68+
className: 'addButtonProps',
69+
size: 'small',
70+
iconDescription: 'Add Selected',
1671
},
17-
{
18-
component: componentTypes.TEXTAREA,
19-
name: 'description',
20-
label: __('Description'),
21-
maxLength: 100,
72+
AddAllButtonProps: {
73+
size: 'small',
74+
iconDescription: 'Add All',
2275
},
23-
],
24-
},
25-
{
26-
component: componentTypes.SUB_FORM,
27-
name: 'ParentVmSelection',
28-
title: __('Parent VM Selection'),
29-
fields: [
30-
{
31-
component: componentTypes.SELECT,
32-
label: __('Parent VM'),
33-
name: 'parent_vm',
34-
id: 'parent_vm',
35-
placeholder: __('No Parent'),
36-
includeEmpty: true,
37-
validateOnMount: true,
38-
options: parentOptions,
76+
RemoveButtonProps: {
77+
id: 'removeButtonProps',
78+
className: 'removeButtonProps',
79+
size: 'small',
80+
iconDescription: 'Remove Selected',
3981
},
40-
],
41-
},
42-
{
43-
component: componentTypes.SUB_FORM,
44-
name: 'ChildVMSelection',
45-
fields: [
46-
{
47-
component: 'dual-list-select',
48-
id: 'child_vms',
49-
name: 'child_vms',
50-
key: `alerts-${emsId}`,
51-
label: __('Child VM Selection'),
52-
rightTitle: __('Child VMs:'),
53-
leftTitle: __('Available VMs:'),
54-
allToRight: true,
55-
moveLeftTitle: __('Move selected VMs to left'),
56-
moveRightTitle: __('Move selected VMs to right'),
57-
moveAllRightTitle: __('Move all VMs to right'),
58-
moveAllLeftTitle: __('Remove All'),
59-
noValueTitle: __('No option selected'),
60-
noOptionsTitle: __('No available options'),
61-
filterOptionsTitle: __('Filter options'),
62-
filterValuesTitle: __('Filter values'),
63-
AddButtonProps: {
64-
id: 'addButtonProps',
65-
className: 'addButtonProps',
66-
size: 'small',
67-
iconDescription: "Add Selected",
68-
},
69-
AddAllButtonProps: {
70-
size: 'small',
71-
iconDescription: "Add All",
72-
},
73-
RemoveButtonProps: {
74-
id: 'removeButtonProps',
75-
className: 'removeButtonProps',
76-
size: 'small',
77-
iconDescription: "Remove Selected",
78-
},
79-
RemoveAllButtonProps: {
80-
size: 'small',
81-
iconDescription: "Remove All",
82-
},
83-
options: parentOptions,
82+
RemoveAllButtonProps: {
83+
size: 'small',
84+
iconDescription: 'Remove All',
8485
},
85-
],
86-
},
87-
];
88-
return { fields };
86+
options: parentOptions,
87+
},
88+
],
89+
},
90+
]);
91+
92+
function createSchema(emsId, parentOptions, editDescription) {
93+
console.log(editDescription);
94+
if (editDescription) {
95+
return { fields: descriptionField(emsId, parentOptions) };
96+
}
97+
return { fields: defaultFields(emsId, parentOptions) };
8998
}
9099

91100
export default createSchema;

app/views/vm_common/_form.html.haml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#main_div
22
= render :partial => "layouts/flash_msg"
3-
= react('VmEditForm', {:recordId => @record.id&.to_s,
4-
:emsId => @record.ems_id&.to_s,
5-
:showTitle => !@edit[:explorer],
6-
:isTemplate => @record.kind_of?(::MiqTemplate),
7-
:displayName => model_for_vm(@record).display_name})
3+
= react('VmEditForm', {:recordId => @record.id&.to_s,
4+
:emsId => @record.ems_id&.to_s,
5+
:showTitle => !@edit[:explorer],
6+
:isTemplate => @record.kind_of?(::MiqTemplate),
7+
:displayName => model_for_vm(@record).display_name,
8+
:editDescription => @edit_description || false})

0 commit comments

Comments
 (0)