{"action":"created","comment":{"url":"https://api.github.com/repos/opf/openproject/pulls/comments/31441166","id":31441166,"diff_hunk":"@@ -0,0 +1,221 @@\n+module ContentHeaderHelper\n+  class AbstractContent\n+    include ActionView::Helpers\n+    attr_accessor :output_buffer\n+\n+    delegate :key_for, to: OpenProject::AccessKeys\n+  end\n+\n+  class ContentHeader < AbstractContent\n+    def initialize(title:, subtitle: '', helper: nil, scrollable: false, &_block)\n+      @title = title\n+      @subtitle = subtitle\n+      @helper = helper\n+      @scrollable = scrollable\n+    end\n+\n+    def toolbar(&block)\n+      content_tag :div, class: 'toolbar-container' do\n+        class_name = %w(toolbar)\n+        class_name += %w(-scrollable) if @scrollable\n+        header = content_tag :div, class: class_name, role: 'navigation' do\n+          dom_title(@title) + content_tag(:ul, items(&block), class: 'toolbar-items', role: 'menubar')\n+        end\n+        next header if @subtitle.blank?\n+        capture do\n+          concat header\n+          concat content_tag(:p, @subtitle, class: 'subtitle')\n+        end\n+      end\n+    end\n+\n+    protected\n+\n+    def items(&block)\n+      return @helper.capture(ContentToolbar.new, &block) if block_given?\n+      ''\n+    end\n+\n+    def dom_title(title)\n+      content_tag :div, class: 'title-container' do\n+        title_attribute = decode title\n+        content_tag(:h2, title.html_safe, title: title_attribute)\n+      end\n+    end\n+\n+    def decode(string)\n+      raw(strip_tags(string)).strip\n+    end\n+  end\n+\n+  class ContentToolbar < AbstractContent\n+    def initialize\n+      @tabindex = 0\n+    end\n+\n+    def button(text, location, options = {})\n+      options[:class] = %w(button) + Array(options[:class])\n+      item text, location, options\n+    end\n+\n+    def item(text, location, options = {})\n+      return '' unless show?(options)\n+      link_options = extract_from options\n+      toolbar_item do\n+        link_to location, link_options.merge(next_tab_index) do\n+          concat button_icon(options)\n+          concat button_text(options.merge text: text)\n+        end\n+      end\n+    end\n+\n+    def toolbar_item(options = {})\n+      options[:class] = Array(options[:class]) + %w(toolbar-item)\n+      options[:role] = 'menuitem'\n+      if block_given?\n+        content_tag :li, options do\n+          yield\n+        end\n+      else\n+        content_tag :li, '', options\n+      end\n+    end\n+\n+    def watch_button(object, user, options = {})\n+      watch_text = options.delete(:watch_text) || I18n.t(:button_watch)\n+      unwatch_text = options.delete(:unwatch_text) || I18n.t(:button_unwatch)\n+      return '' if !object.respond_to?(:watched_by?) || user.anonymous?\n+      watched = object.watched_by?(user)\n+      text = watched ? unwatch_text : watch_text\n+      method = watched ? :delete : :post\n+      icon = watched ? :'not-watch' : :'watch-1'\n+      additionals = {\n+        data: {\n+          remote: true,\n+          method: method,\n+          watch_text: watch_text,\n+          unwatch_text: unwatch_text,\n+          watch_icon: :'watch-1',\n+          unwatch_icon: :'not-watch',\n+          watch_path: watch_path(object, false),\n+          unwatch_path: watch_path(object, true),\n+          watch_method: :post,\n+          unwatch_method: :delete\n+        },\n+        icon: icon\n+      }\n+      button text, watch_path(object, watched), options.merge(additionals)\n+    end\n+\n+    def submenu(options = {}, &block)","path":"app/helpers/content_header_helper.rb","position":110,"original_position":110,"commit_id":"477b0a6b5172f1d19a7fd97ea4121561f7c7cd54","original_commit_id":"477b0a6b5172f1d19a7fd97ea4121561f7c7cd54","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"Assignment Branch Condition size for submenu is too high. [22.89/15]","created_at":"2015-06-01T16:10:04Z","updated_at":"2015-06-01T16:10:04Z","html_url":"https://github.com/opf/openproject/pull/3029#discussion_r31441166","pull_request_url":"https://api.github.com/repos/opf/openproject/pulls/3029","_links":{"self":{"href":"https://api.github.com/repos/opf/openproject/pulls/comments/31441166"},"html":{"href":"https://github.com/opf/openproject/pull/3029#discussion_r31441166"},"pull_request":{"href":"https://api.github.com/repos/opf/openproject/pulls/3029"}}},"pull_request":{"url":"https://api.github.com/repos/opf/openproject/pulls/3029","id":36304771,"html_url":"https://github.com/opf/openproject/pull/3029","diff_url":"https://github.com/opf/openproject/pull/3029.diff","patch_url":"https://github.com/opf/openproject/pull/3029.patch","issue_url":"https://api.github.com/repos/opf/openproject/issues/3029","number":3029,"state":"open","locked":false,"title":"[Refactoring] Toolbar Helper","user":{"login":"floriank","id":498241,"avatar_url":"https://avatars.githubusercontent.com/u/498241?v=3","gravatar_id":"","url":"https://api.github.com/users/floriank","html_url":"https://github.com/floriank","followers_url":"https://api.github.com/users/floriank/followers","following_url":"https://api.github.com/users/floriank/following{/other_user}","gists_url":"https://api.github.com/users/floriank/gists{/gist_id}","starred_url":"https://api.github.com/users/floriank/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/floriank/subscriptions","organizations_url":"https://api.github.com/users/floriank/orgs","repos_url":"https://api.github.com/users/floriank/repos","events_url":"https://api.github.com/users/floriank/events{/privacy}","received_events_url":"https://api.github.com/users/floriank/received_events","type":"User","site_admin":false},"body":"## Toolbar component\r\n\r\nWe introduced a toolbar component with `release/4.1` which simplifies the generation of the content header for all of the individual sections of OP. the component came with a helper that made code generation a little easier:\r\n\r\n```erb\r\n<%= toolbar title: l(:label_overview) do %>\r\n  <% if User.current.allowed_to?(:add_subprojects, project) %>\r\n    <li class=\"toolbar-item\">\r\n      <%= link_to new_project_path(parent_id: project), class: 'button -alt-highlight' do %>\r\n        <i class=\"icon-add\"></i> <%= l(:label_subproject_new) %>\r\n      <% end %>\r\n    </li>\r\n  <% end %>\r\n  <% if User.current.allowed_to?(:edit_project, project) %>\r\n    <li class=\"toolbar-item\">\r\n      <%= link_to my_projects_overview_path(project), class: 'button', accesskey: accesskey(:edit) do %>\r\n        <i class=\"icon-edit\"></i> <%= l(:label_personalize_page) %>\r\n      <% end %>\r\n    </li>\r\n  <% end %>\r\n<% end %>\r\n```\r\n\r\nWhile being better than using plain HTML, this is still hard to read as the view is cluttered.\r\n\r\n## What this PR does\r\n\r\nThe PR introduces a second helper in addition to the `ToolbarHelper` - as correctly pointed out by @NobodysNightmare, the toolbar is not the component, the content header is. the new helper is thereby called `ContentHeaderHelper` and provides a DSL for creating the header - the code above can be simplified as:\r\n\r\n```erb\r\n<%= content_header title: l(:label_overview) do |header| %>\r\n  <%= header.toolbar do |toolbar| %>\r\n    <%= toolbar.button l(:label_subproject_new), new_project_path(parent_id: project), icon: :add, highlight: :alt, if: User.current.allowed_to?(:add_subprojects, project) %>\r\n    <%= toolbar.button l(:label_personalize_page), my_projects_overview_path(project), icon: :edit, accesskey: :edit, if:  User.current.allowed_to?(:edit_project, project) %>\r\n  <% end %>\r\n<% end %>\r\n```\r\n\r\nThe DSL provides some simplifications such as `icon` and `accesskey` options to the buttons directly and detached the DOM necessary for the component from the individual view, DRYing up all of the partials nicely.\r\n\r\n### Additionals\r\n\r\nThis PR also cleans up some of the path helpers and links, removes a little bit of dead code\r\n\r\n## Still TODO\r\n\r\n- [x] Watcher Links for the toolbar\r\n- [x] Submenus in the toolbar (and the replacement on wiki and work package Legacy pages)\r\n- [ ] full removal of `_action_menu_*` partials\r\n- [ ] Tests for the `ContentHeaderHelper` module and contained classes\r\n\r\n## Plugins?\r\n\r\nThe old `ToolbarHelper` component stays in the code base until all plugins have been updated properly.\r\n","created_at":"2015-05-27T13:43:41Z","updated_at":"2015-06-01T16:10:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a89f9a79edcec69f9bc1807ed9e439cf24c4362a","assignee":{"login":"floriank","id":498241,"avatar_url":"https://avatars.githubusercontent.com/u/498241?v=3","gravatar_id":"","url":"https://api.github.com/users/floriank","html_url":"https://github.com/floriank","followers_url":"https://api.github.com/users/floriank/followers","following_url":"https://api.github.com/users/floriank/following{/other_user}","gists_url":"https://api.github.com/users/floriank/gists{/gist_id}","starred_url":"https://api.github.com/users/floriank/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/floriank/subscriptions","organizations_url":"https://api.github.com/users/floriank/orgs","repos_url":"https://api.github.com/users/floriank/repos","events_url":"https://api.github.com/users/floriank/events{/privacy}","received_events_url":"https://api.github.com/users/floriank/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/opf/openproject/pulls/3029/commits","review_comments_url":"https://api.github.com/repos/opf/openproject/pulls/3029/comments","review_comment_url":"https://api.github.com/repos/opf/openproject/pulls/comments{/number}","comments_url":"https://api.github.com/repos/opf/openproject/issues/3029/comments","statuses_url":"https://api.github.com/repos/opf/openproject/statuses/477b0a6b5172f1d19a7fd97ea4121561f7c7cd54","head":{"label":"floriank:refactoring/toolbar-helper","ref":"refactoring/toolbar-helper","sha":"477b0a6b5172f1d19a7fd97ea4121561f7c7cd54","user":{"login":"floriank","id":498241,"avatar_url":"https://avatars.githubusercontent.com/u/498241?v=3","gravatar_id":"","url":"https://api.github.com/users/floriank","html_url":"https://github.com/floriank","followers_url":"https://api.github.com/users/floriank/followers","following_url":"https://api.github.com/users/floriank/following{/other_user}","gists_url":"https://api.github.com/users/floriank/gists{/gist_id}","starred_url":"https://api.github.com/users/floriank/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/floriank/subscriptions","organizations_url":"https://api.github.com/users/floriank/orgs","repos_url":"https://api.github.com/users/floriank/repos","events_url":"https://api.github.com/users/floriank/events{/privacy}","received_events_url":"https://api.github.com/users/floriank/received_events","type":"User","site_admin":false},"repo":{"id":29468662,"name":"openproject","full_name":"floriank/openproject","owner":{"login":"floriank","id":498241,"avatar_url":"https://avatars.githubusercontent.com/u/498241?v=3","gravatar_id":"","url":"https://api.github.com/users/floriank","html_url":"https://github.com/floriank","followers_url":"https://api.github.com/users/floriank/followers","following_url":"https://api.github.com/users/floriank/following{/other_user}","gists_url":"https://api.github.com/users/floriank/gists{/gist_id}","starred_url":"https://api.github.com/users/floriank/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/floriank/subscriptions","organizations_url":"https://api.github.com/users/floriank/orgs","repos_url":"https://api.github.com/users/floriank/repos","events_url":"https://api.github.com/users/floriank/events{/privacy}","received_events_url":"https://api.github.com/users/floriank/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/floriank/openproject","description":"OpenProject is a web based project management system built on Ruby on Rails","fork":true,"url":"https://api.github.com/repos/floriank/openproject","forks_url":"https://api.github.com/repos/floriank/openproject/forks","keys_url":"https://api.github.com/repos/floriank/openproject/keys{/key_id}","collaborators_url":"https://api.github.com/repos/floriank/openproject/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/floriank/openproject/teams","hooks_url":"https://api.github.com/repos/floriank/openproject/hooks","issue_events_url":"https://api.github.com/repos/floriank/openproject/issues/events{/number}","events_url":"https://api.github.com/repos/floriank/openproject/events","assignees_url":"https://api.github.com/repos/floriank/openproject/assignees{/user}","branches_url":"https://api.github.com/repos/floriank/openproject/branches{/branch}","tags_url":"https://api.github.com/repos/floriank/openproject/tags","blobs_url":"https://api.github.com/repos/floriank/openproject/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/floriank/openproject/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/floriank/openproject/git/refs{/sha}","trees_url":"https://api.github.com/repos/floriank/openproject/git/trees{/sha}","statuses_url":"https://api.github.com/repos/floriank/openproject/statuses/{sha}","languages_url":"https://api.github.com/repos/floriank/openproject/languages","stargazers_url":"https://api.github.com/repos/floriank/openproject/stargazers","contributors_url":"https://api.github.com/repos/floriank/openproject/contributors","subscribers_url":"https://api.github.com/repos/floriank/openproject/subscribers","subscription_url":"https://api.github.com/repos/floriank/openproject/subscription","commits_url":"https://api.github.com/repos/floriank/openproject/commits{/sha}","git_commits_url":"https://api.github.com/repos/floriank/openproject/git/commits{/sha}","comments_url":"https://api.github.com/repos/floriank/openproject/comments{/number}","issue_comment_url":"https://api.github.com/repos/floriank/openproject/issues/comments{/number}","contents_url":"https://api.github.com/repos/floriank/openproject/contents/{+path}","compare_url":"https://api.github.com/repos/floriank/openproject/compare/{base}...{head}","merges_url":"https://api.github.com/repos/floriank/openproject/merges","archive_url":"https://api.github.com/repos/floriank/openproject/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/floriank/openproject/downloads","issues_url":"https://api.github.com/repos/floriank/openproject/issues{/number}","pulls_url":"https://api.github.com/repos/floriank/openproject/pulls{/number}","milestones_url":"https://api.github.com/repos/floriank/openproject/milestones{/number}","notifications_url":"https://api.github.com/repos/floriank/openproject/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/floriank/openproject/labels{/name}","releases_url":"https://api.github.com/repos/floriank/openproject/releases{/id}","created_at":"2015-01-19T11:56:20Z","updated_at":"2015-04-20T08:53:16Z","pushed_at":"2015-06-01T16:09:56Z","git_url":"git://github.com/floriank/openproject.git","ssh_url":"git@github.com:floriank/openproject.git","clone_url":"https://github.com/floriank/openproject.git","svn_url":"https://github.com/floriank/openproject","homepage":"https://www.openproject.org","size":68857,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"dev"}},"base":{"label":"opf:release/4.1","ref":"release/4.1","sha":"2138a4697d7e1cd5b136407c8c42a0202b4dd355","user":{"login":"opf","id":1756674,"avatar_url":"https://avatars.githubusercontent.com/u/1756674?v=3","gravatar_id":"","url":"https://api.github.com/users/opf","html_url":"https://github.com/opf","followers_url":"https://api.github.com/users/opf/followers","following_url":"https://api.github.com/users/opf/following{/other_user}","gists_url":"https://api.github.com/users/opf/gists{/gist_id}","starred_url":"https://api.github.com/users/opf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opf/subscriptions","organizations_url":"https://api.github.com/users/opf/orgs","repos_url":"https://api.github.com/users/opf/repos","events_url":"https://api.github.com/users/opf/events{/privacy}","received_events_url":"https://api.github.com/users/opf/received_events","type":"Organization","site_admin":false},"repo":{"id":6899875,"name":"openproject","full_name":"opf/openproject","owner":{"login":"opf","id":1756674,"avatar_url":"https://avatars.githubusercontent.com/u/1756674?v=3","gravatar_id":"","url":"https://api.github.com/users/opf","html_url":"https://github.com/opf","followers_url":"https://api.github.com/users/opf/followers","following_url":"https://api.github.com/users/opf/following{/other_user}","gists_url":"https://api.github.com/users/opf/gists{/gist_id}","starred_url":"https://api.github.com/users/opf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opf/subscriptions","organizations_url":"https://api.github.com/users/opf/orgs","repos_url":"https://api.github.com/users/opf/repos","events_url":"https://api.github.com/users/opf/events{/privacy}","received_events_url":"https://api.github.com/users/opf/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/opf/openproject","description":"OpenProject is a web-based project management system built on Ruby on Rails","fork":false,"url":"https://api.github.com/repos/opf/openproject","forks_url":"https://api.github.com/repos/opf/openproject/forks","keys_url":"https://api.github.com/repos/opf/openproject/keys{/key_id}","collaborators_url":"https://api.github.com/repos/opf/openproject/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/opf/openproject/teams","hooks_url":"https://api.github.com/repos/opf/openproject/hooks","issue_events_url":"https://api.github.com/repos/opf/openproject/issues/events{/number}","events_url":"https://api.github.com/repos/opf/openproject/events","assignees_url":"https://api.github.com/repos/opf/openproject/assignees{/user}","branches_url":"https://api.github.com/repos/opf/openproject/branches{/branch}","tags_url":"https://api.github.com/repos/opf/openproject/tags","blobs_url":"https://api.github.com/repos/opf/openproject/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/opf/openproject/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/opf/openproject/git/refs{/sha}","trees_url":"https://api.github.com/repos/opf/openproject/git/trees{/sha}","statuses_url":"https://api.github.com/repos/opf/openproject/statuses/{sha}","languages_url":"https://api.github.com/repos/opf/openproject/languages","stargazers_url":"https://api.github.com/repos/opf/openproject/stargazers","contributors_url":"https://api.github.com/repos/opf/openproject/contributors","subscribers_url":"https://api.github.com/repos/opf/openproject/subscribers","subscription_url":"https://api.github.com/repos/opf/openproject/subscription","commits_url":"https://api.github.com/repos/opf/openproject/commits{/sha}","git_commits_url":"https://api.github.com/repos/opf/openproject/git/commits{/sha}","comments_url":"https://api.github.com/repos/opf/openproject/comments{/number}","issue_comment_url":"https://api.github.com/repos/opf/openproject/issues/comments{/number}","contents_url":"https://api.github.com/repos/opf/openproject/contents/{+path}","compare_url":"https://api.github.com/repos/opf/openproject/compare/{base}...{head}","merges_url":"https://api.github.com/repos/opf/openproject/merges","archive_url":"https://api.github.com/repos/opf/openproject/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/opf/openproject/downloads","issues_url":"https://api.github.com/repos/opf/openproject/issues{/number}","pulls_url":"https://api.github.com/repos/opf/openproject/pulls{/number}","milestones_url":"https://api.github.com/repos/opf/openproject/milestones{/number}","notifications_url":"https://api.github.com/repos/opf/openproject/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/opf/openproject/labels{/name}","releases_url":"https://api.github.com/repos/opf/openproject/releases{/id}","created_at":"2012-11-28T09:59:11Z","updated_at":"2015-06-01T08:34:06Z","pushed_at":"2015-06-01T16:09:57Z","git_url":"git://github.com/opf/openproject.git","ssh_url":"git@github.com:opf/openproject.git","clone_url":"https://github.com/opf/openproject.git","svn_url":"https://github.com/opf/openproject","homepage":"https://www.openproject.org","size":210292,"stargazers_count":620,"watchers_count":620,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":268,"mirror_url":null,"open_issues_count":61,"forks":268,"open_issues":61,"watchers":620,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/opf/openproject/pulls/3029"},"html":{"href":"https://github.com/opf/openproject/pull/3029"},"issue":{"href":"https://api.github.com/repos/opf/openproject/issues/3029"},"comments":{"href":"https://api.github.com/repos/opf/openproject/issues/3029/comments"},"review_comments":{"href":"https://api.github.com/repos/opf/openproject/pulls/3029/comments"},"review_comment":{"href":"https://api.github.com/repos/opf/openproject/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/opf/openproject/pulls/3029/commits"},"statuses":{"href":"https://api.github.com/repos/opf/openproject/statuses/477b0a6b5172f1d19a7fd97ea4121561f7c7cd54"}}}}