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

Cat tree refactoring #22

Merged
merged 9 commits into from
Jan 9, 2017
Merged

Conversation

MilanPospisil
Copy link
Contributor

@MilanPospisil MilanPospisil commented Dec 23, 2016

Cat tree renewed from the old saved files - two files (tree class an specs) were created from old files, changes in javascript, controller and view was made by hand.

@miq-bot add_label ui,technical debt

ManageIQ/manageiq#12868

Location:
controller/miq_policy_controller/miq_actions.rb
action_build_cat_tree
app/views/miq_policy/_action_options.html.haml

UI location:
Menu/Control/Explorer/Actions/Configuration(Add new action)/Action type - tags

old pr: ManageIQ/manageiq#12869

@miq-bot
Copy link
Member

miq-bot commented Dec 23, 2016

@MilanPospisil Cannot apply the following label because they are not recognized: ui

@@ -138,11 +138,11 @@ def action_field_changed
def action_tag_pressed
@edit = session[:edit]
@action = @edit[:action_id] ? MiqAction.find_by_id(@edit[:action_id]) : MiqAction.new
tag_name = params[:id].split('__')[1]
id = TreeBuilder.from_cid(params[:id].split('-')[1])
Copy link
Contributor

@himdel himdel Dec 31, 2016

Choose a reason for hiding this comment

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

from_cid should be available in controllers without the TreeBuilder...

Or even better, @ZitaNemeckova don't we have a TreeBuilder method that gives you that parsed out id?

.. I'm thinking _, id, _ = TreeBuilder.extract_node_model_and_id(params[:id]) (if it works with Classifications..)

:click_url => "/miq_policy/action_tag_pressed/",
:onclick => "miqOnClickTagCat"})
= render(:partial => 'shared/tree',
:locals => {:tree => @cat_tree, :name => @cat_tree.name})
Copy link
Contributor

Choose a reason for hiding this comment

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

broken formatting ;)

leaf = !object.entries.any?
img = "tag.png" unless leaf
node[:icon] = img
node[:image] = "100/#{img}"
Copy link
Contributor

Choose a reason for hiding this comment

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

You shouldn't need to override the image here, what happens if you don't?

img = "blank.gif"
leaf = !object.entries.any?
img = "tag.png" unless leaf
node[:icon] = img
Copy link
Contributor

Choose a reason for hiding this comment

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

node[:icon] should not set, unless you really have a fonticon

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, i forgot it here from old version...

@@ -68,12 +68,8 @@
.form-group
.col-md-8
#action_tags_treebox.treeview-pf-hover.treeview-pf-select
Copy link
Contributor

@himdel himdel Dec 31, 2016

Choose a reason for hiding this comment

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

Either this whole line doesn't belong here anymore, or just the id, but shared/tree already creates a action_tags_treebox, and we don't want two :)

@tenant = "TestTenant"
@tenant = "#{@tenant} Tags"
end
context 'read-only mode' do
Copy link
Contributor

@himdel himdel Dec 31, 2016

Choose a reason for hiding this comment

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

newlines please ;) (before every it and context and before, except when first in a block)

And you probably want to look into using let and let!, instead of instance variables here..

@@ -138,7 +138,7 @@ def action_field_changed
def action_tag_pressed
@edit = session[:edit]
@action = @edit[:action_id] ? MiqAction.find_by_id(@edit[:action_id]) : MiqAction.new
id = from_cid(params[:id].split('-')[1])
_, id = parse_nodetype_and_id(params[:id])
Copy link
Contributor

Choose a reason for hiding this comment

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

still needs from_cid

@himdel
Copy link
Contributor

himdel commented Jan 6, 2017

Please add instructions on where to find the tree to the description, and, in the future, I recommend doing a before and after screenshot. (It is required in PRs that change the UI in any visible way, not when they don't ... but:... :) )


Found 2 differences:

  • there are more categories than before now, I guess some filter is missing
  • clicking on a tag does not update the Tag to Apply field now (and in fact, trying to save complains that no tag is selected)

The list of categories before and after:

cat-all-pre


Selected tag before:

cat-pre

Selected tag after:

cat-post


def override(node, object, _pid, _options)
img = "blank.gif"
leaf = !object.entries.any?
Copy link
Contributor

@himdel himdel Jan 6, 2017

Choose a reason for hiding this comment

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

leaf = object.parent_id != 0 doesn't trigger a DB query and probably does the same thing.

(Well, there is a difference for objects with non-null parent_id which do have entries, but that doesn't seem to happen.)

EDIT: verified that the difference is a good thing...

Classification.all.select { |c| c.parent_id != 0 && c.entries.any? } yields [] for me..
..and Classification.all.select { |c| c.parent_id == 0 && c.entries.none? } gives me 2 entries which are clearly categories, but don't have any values that could be assigned as a tag

Copy link
Contributor

@himdel himdel Jan 6, 2017

Choose a reason for hiding this comment

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

Even better .. leaf = !object.category? (category? does parent_id == 0)

def override(node, object, _pid, _options)
img = "blank.gif"
leaf = !object.entries.any?
img = "tag.png" unless leaf
Copy link
Contributor

@himdel himdel Jan 6, 2017

Choose a reason for hiding this comment

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

Please try to always keep the whole image name in one place, 100/#{img} means that if you search for 100/tag.png, you won't find it :) (Granted, slightly less evil than 100/#{img}.png but still..)

Also, blank.gif is no longer needed, simple nil would suffice.

So, I'd propose something like

image = leaf ? nil : "100/tag.png"
node[:image] = image && ActionController::Base.helpers.image_path(image)

leaf = !object.entries.any?
img = "tag.png" unless leaf
node[:image] = ActionController::Base.helpers.image_path("100/#{img}")
node[:title] = object.description
Copy link
Contributor

Choose a reason for hiding this comment

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

Setting node[:title] here seems completely superfluous, it already is that way.

img = "tag.png" unless leaf
node[:image] = ActionController::Base.helpers.image_path("100/#{img}")
node[:title] = object.description
node[:tooltip] = _("Category: %{description}") % {:description => object.description}
Copy link
Contributor

Choose a reason for hiding this comment

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

Setting node[:tooltip] is also superfluous, already there.

node[:title] = object.description
node[:tooltip] = _("Category: %{description}") % {:description => object.description}
node[:cfmeNoClick] = !leaf
node[:hideCheckbox] = true
Copy link
Contributor

Choose a reason for hiding this comment

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

node[:hideCheckbox] is also already true, always

node[:tooltip] = _("Category: %{description}") % {:description => object.description}
node[:cfmeNoClick] = !leaf
node[:hideCheckbox] = true
node
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to return anything here, the call relies on override mutating node, not returning a new one.

Copy link
Contributor Author

@MilanPospisil MilanPospisil Jan 8, 2017

Choose a reason for hiding this comment

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

In code yes, but i need some easy way to test this method. Anyway I do not see anyone to test override in other trees, this is maybe because the only way to test it without returing node is using tree traversal on the json result?

node[:image] = ActionController::Base.helpers.image_path("100/#{img}")
node[:title] = object.description
node[:tooltip] = _("Category: %{description}") % {:description => object.description}
node[:cfmeNoClick] = !leaf
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe node[:cfmeNoClick] = false if leaf would be more explicit here? But either is fine, feel free to ignore :)

if cats.any?
r_kids = []
cats.sort_by { |c| c.description.downcase }.each do |c|
next if c.read_only
Copy link
Contributor

@himdel himdel Jan 6, 2017

Choose a reason for hiding this comment

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

This is the missing filter that affects those Parent Folder Path (*) (thanks @ZitaNemeckova for the find! :))

@miq-bot
Copy link
Member

miq-bot commented Jan 8, 2017

Checked commits MilanPospisil/manageiq-ui-classic@80e5ec6~...4811281 with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1
4 files checked, 2 offenses detected

**

  • 💣 💥 🔥 🚒 - Linter/Haml - missing config files

app/controllers/miq_policy_controller/miq_actions.rb

@MilanPospisil
Copy link
Contributor Author

MilanPospisil commented Jan 8, 2017

@himdel About that tag to apply problem. It does work on my computer. Maybe check the javascript cache. The js method miqOnClickTagCat was changed.

@himdel
Copy link
Contributor

himdel commented Jan 8, 2017

@MilanPospisil will do, but if it works for you, then most likely there's another missing from_cid call somewhere..

EDIT: never mind, you were right, works now :)

@himdel himdel added the euwe/no label Jan 9, 2017
@himdel
Copy link
Contributor

himdel commented Jan 9, 2017

Tested in the UI 👍

@himdel himdel merged commit 07ae769 into ManageIQ:master Jan 9, 2017
@chessbyte chessbyte added this to the Sprint 51 Ending Jan 2, 2017 milestone Mar 17, 2017
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.

4 participants