"Fossies" - the Fresh Open Source Software Archive

Member "redmine-4.1.1/app/helpers/projects_helper.rb" (6 Apr 2020, 7372 Bytes) of package /linux/www/redmine-4.1.1.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "projects_helper.rb": 4.1.0_vs_4.1.1.

    1 # frozen_string_literal: true
    2 
    3 # Redmine - project management software
    4 # Copyright (C) 2006-2019  Jean-Philippe Lang
    5 #
    6 # This program is free software; you can redistribute it and/or
    7 # modify it under the terms of the GNU General Public License
    8 # as published by the Free Software Foundation; either version 2
    9 # of the License, or (at your option) any later version.
   10 #
   11 # This program is distributed in the hope that it will be useful,
   12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14 # GNU General Public License for more details.
   15 #
   16 # You should have received a copy of the GNU General Public License
   17 # along with this program; if not, write to the Free Software
   18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   19 
   20 module ProjectsHelper
   21   def project_settings_tabs
   22     tabs =
   23       [
   24         {:name => 'info', :action => :edit_project,
   25          :partial => 'projects/edit', :label => :label_project},
   26         {:name => 'members', :action => :manage_members,
   27          :partial => 'projects/settings/members', :label => :label_member_plural},
   28         {:name => 'issues', :action => :edit_project, :module => :issue_tracking,
   29          :partial => 'projects/settings/issues', :label => :label_issue_tracking},
   30         {:name => 'versions', :action => :manage_versions,
   31          :partial => 'projects/settings/versions', :label => :label_version_plural,
   32          :url => {:tab => 'versions', :version_status => params[:version_status],
   33                   :version_name => params[:version_name]}},
   34         {:name => 'categories', :action => :manage_categories,
   35          :partial => 'projects/settings/issue_categories',
   36          :label => :label_issue_category_plural},
   37         {:name => 'repositories', :action => :manage_repository,
   38          :partial => 'projects/settings/repositories', :label => :label_repository_plural},
   39         {:name => 'boards', :action => :manage_boards,
   40          :partial => 'projects/settings/boards', :label => :label_board_plural},
   41         {:name => 'activities', :action => :manage_project_activities,
   42          :partial => 'projects/settings/activities', :label => :label_time_tracking}
   43       ]
   44     tabs.
   45       select {|tab| User.current.allowed_to?(tab[:action], @project)}.
   46       select {|tab| tab[:module].nil? || @project.module_enabled?(tab[:module])}
   47   end
   48 
   49   def parent_project_select_tag(project)
   50     selected = project.parent
   51     # retrieve the requested parent project
   52     parent_id = (params[:project] && params[:project][:parent_id]) || params[:parent_id]
   53     if parent_id
   54       selected = (parent_id.blank? ? nil : Project.find(parent_id))
   55     end
   56 
   57     options = +''
   58     options << "<option value=''>&nbsp;</option>" if project.allowed_parents.include?(nil)
   59     options << project_tree_options_for_select(project.allowed_parents.compact, :selected => selected)
   60     content_tag('select', options.html_safe, :name => 'project[parent_id]', :id => 'project_parent_id')
   61   end
   62 
   63   def render_project_action_links
   64     links = (+"").html_safe
   65     if User.current.allowed_to?(:add_project, nil, :global => true)
   66       links << link_to(l(:label_project_new), new_project_path, :class => 'icon icon-add')
   67     end
   68     if User.current.admin?
   69       links << link_to(l(:label_administration), admin_projects_path, :class => 'icon icon-settings')
   70     end
   71     links
   72   end
   73 
   74   # Renders the projects index
   75   def render_project_hierarchy(projects)
   76     render_project_nested_lists(projects) do |project|
   77       s = link_to_project(project, {}, :class => "#{project.css_classes} #{User.current.member_of?(project) ? 'icon icon-user my-project' : nil}")
   78       if project.description.present?
   79         s << content_tag('div', textilizable(project.short_description, :project => project), :class => 'wiki description')
   80       end
   81       s
   82     end
   83   end
   84 
   85   # Returns a set of options for a select field, grouped by project.
   86   def version_options_for_select(versions, selected=nil)
   87     grouped = Hash.new {|h,k| h[k] = []}
   88     versions.each do |version|
   89       grouped[version.project.name] << [version.name, version.id]
   90     end
   91 
   92     selected = selected.is_a?(Version) ? selected.id : selected
   93     if grouped.keys.size > 1
   94       grouped_options_for_select(grouped, selected)
   95     else
   96       options_for_select((grouped.values.first || []), selected)
   97     end
   98   end
   99 
  100   def project_default_version_options(project)
  101     versions = project.shared_versions.open.to_a
  102     if project.default_version && !versions.include?(project.default_version)
  103       versions << project.default_version
  104     end
  105     version_options_for_select(versions, project.default_version)
  106   end
  107 
  108   def project_default_assigned_to_options(project)
  109     assignable_users = (project.assignable_users.to_a + [project.default_assigned_to]).uniq.compact
  110     principals_options_for_select(assignable_users, project.default_assigned_to)
  111   end
  112 
  113   def format_version_sharing(sharing)
  114     sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing)
  115     l("label_version_sharing_#{sharing}")
  116   end
  117 
  118   def render_boards_tree(boards, parent=nil, level=0, &block)
  119     selection = boards.select {|b| b.parent == parent}
  120     return '' if selection.empty?
  121 
  122     s = ''.html_safe
  123     selection.each do |board|
  124       node = capture(board, level, &block)
  125       node << render_boards_tree(boards, board, level+1, &block)
  126       s << content_tag('div', node)
  127     end
  128     content_tag('div', s, :class => 'sort-level')
  129   end
  130 
  131   def render_api_includes(project, api)
  132     api.array :trackers do
  133       project.trackers.each do |tracker|
  134         api.tracker(:id => tracker.id, :name => tracker.name)
  135       end
  136     end if include_in_api_response?('trackers')
  137 
  138     api.array :issue_categories do
  139       project.issue_categories.each do |category|
  140         api.issue_category(:id => category.id, :name => category.name)
  141       end
  142     end if include_in_api_response?('issue_categories')
  143 
  144     api.array :time_entry_activities do
  145       project.activities.each do |activity|
  146         api.time_entry_activity(:id => activity.id, :name => activity.name)
  147       end
  148     end if include_in_api_response?('time_entry_activities')
  149 
  150     api.array :enabled_modules do
  151       project.enabled_modules.each do |enabled_module|
  152         api.enabled_module(:id => enabled_module.id, :name => enabled_module.name)
  153       end
  154     end if include_in_api_response?('enabled_modules')
  155   end
  156 
  157   def bookmark_link(project, user = User.current)
  158     return '' unless user && user.logged?
  159     @jump_box ||= Redmine::ProjectJumpBox.new user
  160     bookmarked = @jump_box.bookmark?(project)
  161     css = +"icon bookmark "
  162 
  163     if bookmarked
  164       css << "icon-bookmark"
  165       method = "delete"
  166       text = l(:button_project_bookmark_delete)
  167     else
  168       css << "icon-bookmark-off"
  169       method = "post"
  170       text = l(:button_project_bookmark)
  171     end
  172 
  173     url = bookmark_project_path(project)
  174     link_to text, url, remote: true, method: method, class: css
  175   end
  176 
  177   def grouped_project_list(projects, query, &block)
  178     ancestors = []
  179     grouped_query_results(projects, query) do |project, group_name, group_count, group_totals|
  180       ancestors.pop while ancestors.any? && !project.is_descendant_of?(ancestors.last)
  181       yield project, ancestors.size, group_name, group_count, group_totals
  182       ancestors << project unless project.leaf?
  183     end
  184   end
  185 end