Skip to content
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

UI for create and delete flavors #1818

Merged
merged 1 commit into from
Oct 26, 2017

Conversation

alexander-demicev
Copy link

@alexander-demicev alexander-demicev commented Aug 3, 2017

Compute > Clouds > Flavors
Depends on: ManageIQ/manageiq#15552.

Add UI for create and delete flavors

Adding flavor:
screenshot from 2017-08-03 12-05-40

Removing flavor:
screenshot from 2017-08-03 12-06-30

@alexander-demicev alexander-demicev changed the title UI for create and delete flavors [WIP] UI for create and delete flavors Aug 3, 2017
@miq-bot miq-bot added the wip label Aug 3, 2017
@alexander-demicev alexander-demicev force-pushed the flavors branch 4 times, most recently from 09521f3 to ed37d81 Compare August 3, 2017 12:03
%span.help-block{"ng-show" => "angularForm.rxtx_factor.$error.floatGreaterThanZero"}
= _("RXTX factor must be greater than or equal to 0")

= render :partial => "layouts/angular/x_edit_buttons_angular"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want generic_form_buttons here instead .. those x_edit are for non-controllerAs controllers.

assert_privileges('flavor_delete')
checked = find_checked_items
checked[0] = params[:id] if checked.blank? && params[:id]
FlavorController.model.where(:id => checked).each do |flavor|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be find_records_with_rbac(model, checked_or_params), and you don't need to do the checked[0] = params[:id] etc..

end

private

def textual_group_list
[%i(properties relationships), %i(tags)]
[%i[properties relationships], %i[tags]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change back to how it was.

@@ -10,15 +10,59 @@ class FlavorController < ApplicationController
include Mixins::GenericSessionMixin

def self.display_methods
%w(instances)
%w[instances]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change back to how it was.

var getBack = function(response) {
var message = '';
var err = false;
if (response.hasOwnProperty('results')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the API really returns a 200 on error?

Can you perhaps separate this function into 2? (error and non-error) .. looks like this has too many if (! err) all around, and could be more readable as 2 functions.

miqService.sparkleOff();
};

function getEmsFormDataComplete(response) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're changing the model here, but setForm can already have been called in getManagerResource .. I guess you want to wait for both requests to suceed before calling setForm and sparkleOff.

($q.all is your friend :))

.then(getManagerResource)
.catch(miqService.handleFailure);
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also looks like you may be missing resetClicked

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reset button is enabled when record is not new, flavor updating is not possible, for now I don`t need it.

return {
require: 'ngModel',
link: function(_scope, _elem, _attrs, ctrl) {
ctrl.$validators.intGreaterThanZero = function(modelValue, viewValue) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably split these directives differently..

Right now, you have..

  1. is float && >0
  2. is int && >0
  3. is int && >= 0

This looks like it could better split as..

  1. is int
  2. is float
  3. is >0
  4. is >=0

.. and since we're using angular.validators (https://github.com/gkaimakas/angular.validators) ...

  1. We already have is-float
  2. We already have is-int
  3. input type=number min=0 already validates >= 0, but the only way to test a float for >0 would be step="0.01" + min="0.01", which may be undesirable .. but we can have a greaterThanZero directive..
  4. input type=number min=0 already validates >= 0, unless you can't use an input type number, in which case we'd need a greaterOrZero as well.

@@ -1,4 +1,30 @@
class ApplicationHelper::Toolbar::FlavorsCenter < ApplicationHelper::Toolbar::Basic
button_group('flavor_configuration', [
select(
:aflavor_configuration_choice,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Atypo? :) Guessing this should be :flavor_configuration_choice :)

@alexander-demicev
Copy link
Author

alexander-demicev commented Aug 4, 2017

Thank you for review, @himdel ! Does it look better now?

@alexander-demicev alexander-demicev changed the title [WIP] UI for create and delete flavors UI for create and delete flavors Aug 4, 2017
@miq-bot miq-bot removed the wip label Aug 4, 2017
@alexander-demicev alexander-demicev force-pushed the flavors branch 3 times, most recently from 68921cd to e7d7bd2 Compare August 12, 2017 13:50
@@ -0,0 +1,21 @@
ManageIQ.angular.app.directive('isFloat', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a duplicate of angular validator's is-float.

So I think you can just remove this file and it will work equally well ;)

@@ -0,0 +1,22 @@
ManageIQ.angular.app.directive('isInteger', function() {
Copy link
Contributor

@himdel himdel Aug 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, is-integer already exists in angular-validators ... except it is called is-int ;)

@himdel
Copy link
Contributor

himdel commented Aug 17, 2017

@alexander-demichev The code looks fine now (EDIT: except for response, and stuff), but I never see that Configuration button in Flavors.
Does this depend on a manageiq/ PR that's not merged yet? (I assume I'm missing the rbac features needed to see those buttons.)

@himdel
Copy link
Contributor

himdel commented Aug 17, 2017

Aah... indeed it does.. ManageIQ/manageiq#15552.

@alexander-demichev for future reference, in such cases, you need to mention the PR in the description, and add a pending core label until it is merged. I've done so for now :).

(I've also added info on where to look for those screens.)

@dclarizio
Copy link

@himdel can you please review the cc issues, perhaps a few more can be addressed.

@alexander-demicev alexander-demicev force-pushed the flavors branch 2 times, most recently from b242cad to 0b8e291 Compare October 20, 2017 13:50
@tzumainn
Copy link
Contributor

Changes look good to me, thanks!

@Loicavenel
Copy link

@himdel Martin, we need your help here.. thanks

flavors = find_records_with_rbac(Flavor, checked_or_params)
flavors.each do |flavor|
begin
flavor.delete_flavor_queue(User.current_user.id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shoud be done through the API, not here :-(

@martinpovolny
Copy link
Member

martinpovolny commented Oct 25, 2017

Oh, I see that @himdel agreed to get this fixed later...

But we really need to stop doing that!

@martinpovolny
Copy link
Member

martinpovolny commented Oct 25, 2017

Guys, these CC issues are easy to fix:

'miqFlashLater' is not defined. NEW
    miqFlashLater(flashMessage);
Severity: MinorFound in app/assets/javascripts/controllers/flavor/flavor_form_controller.js by eslint

'miqFlashLater' is not defined. NEW
    miqFlashLater(flashMessage);
Severity: MinorFound in app/assets/javascripts/controllers/flavor/flavor_form_controller.js by eslint

Avoid using a variable and instead use chaining with the getter syntax. NEW

ManageIQ.angular.app.directive('greaterOrZero', function() {
Severity: MinorFound in app/assets/javascripts/directives/greater_or_zero.js by eslint

'modelValue' is defined but never used. NEW
      ctrl.$validators.greaterOrZero = function(modelValue, viewValue) {
Severity: MinorFound in app/assets/javascripts/directives/greater_or_zero.js by eslint

'modelValue' is defined but never used. NEW
      ctrl.$validators.greaterThanZero = function(modelValue, viewValue) {

@Loicavenel
Copy link

@aufi @tzumainn for visibility...

@alexander-demicev alexander-demicev force-pushed the flavors branch 4 times, most recently from 108e01b to 2e771b5 Compare October 26, 2017 12:45
@tzumainn
Copy link
Contributor

The style issues seem okay to me - I think a few of the CC issues are still fixable though?

@alexander-demicev alexander-demicev force-pushed the flavors branch 2 times, most recently from ecd495b to 1af8de3 Compare October 26, 2017 13:44
@miq-bot
Copy link
Member

miq-bot commented Oct 26, 2017

Checked commit alexander-demicev@f64713b with ruby 2.3.3, rubocop 0.47.1, and haml-lint 0.20.0
3 files checked, 2 offenses detected

app/helpers/application_helper/toolbar/flavors_center.rb

  • ❗ - Line 28, Col 3 - Style/IndentArray - Indent the right bracket the same as the first position after the preceding left parenthesis.
  • ❗ - Line 3, Col 5 - Style/IndentArray - Use 2 spaces for indentation in an array, relative to the first position after the preceding left parenthesis.

@alexander-demicev
Copy link
Author

@h-kataria Hi, can you take a look to this PR, it's close to be resolved.

@tzumainn
Copy link
Contributor

@alexander-demichev is the chaining issue in cc fixable?

@alexander-demicev
Copy link
Author

@tzumainn I don't know, didn't find any examples in other controllers/directives.

@tzumainn
Copy link
Contributor

@alexander-demichev you're right, this does seem to match the existing code. Okay, nevermind!

@h-kataria
Copy link
Contributor

looks like most comments/concerns have been addressed, merging.

@h-kataria h-kataria added this to the Sprint 72 Ending Oct 30, 2017 milestone Oct 26, 2017
@h-kataria h-kataria merged commit bd7855a into ManageIQ:master Oct 26, 2017
@martinpovolny
Copy link
Member

martinpovolny commented Nov 1, 2017

Oh my!

Gentleman and ladies, https://github.com/ManageIQ/manageiq-ui-classic/pull/1818/files#diff-3dcd700167653275bbf7873cfa7fa7c7R23

The delete in the else branch. That is like when one shoots himself in the leg with a mortar.

Now when I try to tag a flavor I delete it.

We need to aproach things (especially the destructive ones) with care!

We are reviewing and merging in too much hurry :-(

add_flash(_("Delete of Flavor \"%{name}\" was successfully initiated.") % {:name => flavor.name})
rescue => error
add_flash(_("Unable to delete Flavor \"%{name}\": %{details}") % {:name => flavor.name,
:details => error},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error is an exception, not a message. What do you expect to get displayed here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants