{"action":"created","issue":{"url":"https://api.github.com/repos/ManageIQ/manageiq/issues/13052","repository_url":"https://api.github.com/repos/ManageIQ/manageiq","labels_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/13052/labels{/name}","comments_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/13052/comments","events_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/13052/events","html_url":"https://github.com/ManageIQ/manageiq/pull/13052","id":194327839,"number":13052,"title":"[WIP] Button class refactoring: #calculate_properties","user":{"login":"vecerek","id":5737996,"avatar_url":"https://avatars.githubusercontent.com/u/5737996?v=3","gravatar_id":"","url":"https://api.github.com/users/vecerek","html_url":"https://github.com/vecerek","followers_url":"https://api.github.com/users/vecerek/followers","following_url":"https://api.github.com/users/vecerek/following{/other_user}","gists_url":"https://api.github.com/users/vecerek/gists{/gist_id}","starred_url":"https://api.github.com/users/vecerek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vecerek/subscriptions","organizations_url":"https://api.github.com/users/vecerek/orgs","repos_url":"https://api.github.com/users/vecerek/repos","events_url":"https://api.github.com/users/vecerek/events{/privacy}","received_events_url":"https://api.github.com/users/vecerek/received_events","type":"User","site_admin":false},"labels":[{"id":495693084,"url":"https://api.github.com/repos/ManageIQ/manageiq/labels/unmergeable","name":"unmergeable","color":"ededed","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-12-08T12:49:34Z","updated_at":"2016-12-08T13:01:38Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/13052","html_url":"https://github.com/ManageIQ/manageiq/pull/13052","diff_url":"https://github.com/ManageIQ/manageiq/pull/13052.diff","patch_url":"https://github.com/ManageIQ/manageiq/pull/13052.patch"},"body":"### Refactoring #calculate_properties\r\n\r\nMany of the buttons use the following method to update their `:title` property in case of being disabled:\r\n```\r\ndef calculate_properties\t\t\r\n  super\t\t\r\n  self[:title] = @error_message if @error_message.present?\t\t\r\nend\r\n```\r\n\r\nThus, this small part of code has gradually been duplicated across many button classes. It would be much better to incorporate this step into the base method of `#calculate_properties` and adjust the existing `disabled?` methods, so the `@error_message` would be set inside of them and they would return `@error_message.present?`.\r\n\r\n---\r\n\r\n### Simplification of ServerPromote\r\n\r\nThe logic of `#disabled?` has been simplified in `ServerPromote` button class as stated below.\r\nLet the following terms be defined as:\r\n```\r\np = @record.priority\r\nA = @record.priority != 1\r\nB = @record.priority != 2\r\nC = @record.priority == 2\r\nT = (A && B) || C\r\n```\r\n\r\n| p | A | B | C | T |\r\n|---|---|---|---|---|\r\n| 1 | 0 | 1 | 0 | 0 |\r\n| 2 | 1 | 0 | 1 | 1 |\r\n| -1, 3, 4, ... | 1 | 1 | 0 | 1 |\r\n\r\nThe truth table above shows that the term is false only in case that the priority is set to `1` -> the term can be simplified to `@record.priority != 1`.\r\n\r\n---\r\nSome of the specs also had to be adjusted to reflect the changes.\r\n\r\n# Links\r\nRelated issue: #6554"},"comment":{"url":"https://api.github.com/repos/ManageIQ/manageiq/issues/comments/265734643","html_url":"https://github.com/ManageIQ/manageiq/pull/13052#issuecomment-265734643","issue_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/13052","id":265734643,"user":{"login":"vecerek","id":5737996,"avatar_url":"https://avatars.githubusercontent.com/u/5737996?v=3","gravatar_id":"","url":"https://api.github.com/users/vecerek","html_url":"https://github.com/vecerek","followers_url":"https://api.github.com/users/vecerek/followers","following_url":"https://api.github.com/users/vecerek/following{/other_user}","gists_url":"https://api.github.com/users/vecerek/gists{/gist_id}","starred_url":"https://api.github.com/users/vecerek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vecerek/subscriptions","organizations_url":"https://api.github.com/users/vecerek/orgs","repos_url":"https://api.github.com/users/vecerek/repos","events_url":"https://api.github.com/users/vecerek/events{/privacy}","received_events_url":"https://api.github.com/users/vecerek/received_events","type":"User","site_admin":false},"created_at":"2016-12-08T13:01:38Z","updated_at":"2016-12-08T13:01:38Z","body":"@miq-bot add_label wip"}}
{"actor":{"display_login":"vecerek"}}