New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #2314 - fine grain for RAM selectors #3774
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
span.ui-spinner { | ||
width: 100%; | ||
border: none; | ||
border-bottom-right-radius: 0; | ||
border-bottom-left-radius: 0; | ||
border-top-right-radius: 0; | ||
border-top-left-radius: 0; | ||
} | ||
|
||
input.ui-spinner-input { | ||
margin: 0; | ||
} | ||
|
||
.ui-spinner a.ui-spinner-button { | ||
border-radius: 0; | ||
border: 1px solid #bababa; | ||
background-color: #eee; | ||
&.ui-spinner-up { | ||
border-bottom: none; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,6 +192,18 @@ def autocomplete_f(f, attr, options = {}) | |
end | ||
end | ||
|
||
def byte_size_f(f, attr, options = {}) | ||
options[:class] = options[:class].to_s + ' byte_spinner' | ||
options[:help_inline] ||= popover('', _("When specifying custom value, add 'MB' or 'GB' at the end. Field is not case sensitive and MB is default if unspecified.")) | ||
options[:help_block] ||= content_tag(:span, :class => 'maximum-limit hidden') do | ||
content_tag(:i, '', :class => 'pficon-warning-triangle-o') + | ||
content_tag(:span, ' ' + _('Specified value is higher than recommended maximum'), :class => 'error-message') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be validated by the server? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so, the thing is that that many CR hardcode some maximum which should not limit the users if they know what they're doing. Later I'd like to remove artificial limits but that needs more CR code refactoring first. So now we can just display a warning. |
||
end | ||
options[:help_block] += f.hidden_field(attr, :class => "real-hidden-value", :id => nil) | ||
|
||
text_f(f, attr, options) | ||
end | ||
|
||
def form_to_submit_id(f) | ||
object = f.object.respond_to?(:to_model) ? f.object.to_model : f.object | ||
key = if object.present? | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
const megabyte = 1024 * 1024; | ||
const gigabyte = 1024 * megabyte; | ||
|
||
$(function () { | ||
$.widget('ui.limitedSpinner', $.ui.spinner, { | ||
options: { | ||
softMaximum: 0, | ||
errorTarget: null | ||
}, | ||
validate: function () { | ||
return this._validate(); | ||
}, | ||
_validate: function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem to trigger on manual changes of the field (ie not using the spinner) |
||
if (this.options.softMaximum !== 0) { | ||
this.options.errorTarget.toggle(this.value() > this.options.softMaximum); | ||
} | ||
}, | ||
_spin: function (step, event) { | ||
let result = this._super(step, event); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expected blank line after variable declarations newline-after-var There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason to save this in a variable instead of just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to keep the interface of method I'm overriding |
||
|
||
this._validate(); | ||
return result; | ||
} | ||
}); | ||
|
||
$.widget('ui.byteSpinner', $.ui.limitedSpinner, { | ||
options: { | ||
step: 1, | ||
min: 1, | ||
incremental: false, | ||
valueTarget: null | ||
}, | ||
updateValueTarget: function () { | ||
this.options.valueTarget.val(this.value()); | ||
}, | ||
_gigabyteSpin: function (step) { | ||
if (step > 0) { | ||
if (step % gigabyte === 0) { | ||
step = gigabyte; | ||
} else { | ||
step = gigabyte - (this.value() % gigabyte); | ||
} | ||
} else if (step < 0) { | ||
if (this.value() % gigabyte === 0) { | ||
step = -1 * gigabyte; | ||
} else { | ||
step = -1 * (this.value() % gigabyte); | ||
} | ||
} | ||
return step; | ||
}, | ||
_megabyteSpin: function (step) { | ||
const megabyteStep = step * 256 * megabyte; | ||
|
||
if (this.value() + megabyteStep > gigabyte) { | ||
step = gigabyte - this.value(); | ||
} else if (this.value() + megabyteStep < megabyte) { | ||
step = step * (this.value() - megabyte); | ||
} else if (this.value() === megabyte && step > 0) { | ||
step = 255 * megabyte; | ||
} else { | ||
step = megabyteStep; | ||
} | ||
return step; | ||
}, | ||
_spin: function (step, event) { | ||
let result = null; | ||
|
||
if ((this.value() > gigabyte && step < 0) || | ||
(this.value() >= gigabyte && step > 0)) { | ||
step = this._gigabyteSpin(step); | ||
} else { | ||
step = this._megabyteSpin(step); | ||
} | ||
|
||
result = this._super(step, event); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again, any reason to save this rather then directly returning it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there's one more call after this but I want to keep the same interface for this function so returning whatever There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct me if i'm wrong, but the other call doesn't modify this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does not but |
||
this.updateValueTarget(); | ||
|
||
return result; | ||
}, | ||
_parse: function (value) { | ||
if (typeof value === 'string') { | ||
if (value.match(/gb$/i)) { | ||
return parseFloat(value) * gigabyte; | ||
} else if (value.match(/mb$/i) || parseInt(value, 10) < megabyte) { | ||
return parseInt(value, 10) * megabyte; | ||
} | ||
} | ||
return value; | ||
}, | ||
// prints value with unit, if it's multiple of gigabytes use GB, otherwise format in MB | ||
_format: value => | ||
(value % gigabyte === 0) ? (value / gigabyte) + ' GB' : (value / megabyte) + ' MB' | ||
}); | ||
}); | ||
|
||
export function initByteSpinner() { | ||
$('input.byte_spinner').each(function () { | ||
let field = $(this); | ||
let errorMessage = field.closest('.form-group').find('.maximum-limit'); | ||
let valueTarget = field.closest('.form-group').find('.real-hidden-value'); | ||
|
||
field.byteSpinner({ | ||
valueTarget: valueTarget, | ||
softMaximum: field.data('softMax'), | ||
errorTarget: errorMessage | ||
}); | ||
|
||
field.change(function () { | ||
field.byteSpinner('updateValueTarget'); | ||
field.byteSpinner('validate'); | ||
}); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why use jquery.ui.spinner instead of patternfly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
patternfly spinner didn't allow me to customize the output and parsing - note that gb/mb is part of the input so user can type "5gb" and it will get parsed correctly