Skip to content

Commit

Permalink
move project index header to primer
Browse files Browse the repository at this point in the history
  • Loading branch information
ulferts committed Dec 19, 2023
1 parent 0be29ca commit 5908ce5
Show file tree
Hide file tree
Showing 12 changed files with 338 additions and 176 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= form_tag({},
method: :get,
class: "project-filters #{show_filters_section? ? '-expanded' : ''}",
class: "project-filters",
data: {
'project-target': 'filterForm',
action: 'submit->project#sendForm:prevent'
Expand All @@ -12,7 +12,7 @@
data-action="project#toggleFilterForm"></a>
<legend><%= t(:label_filter_plural) %></legend>
<ul class="advanced-filters--filters">
<% allowed_filters(query).each do |filter| %>
<% allowed_filters.each do |filter| %>
<% filter_active = query.find_active_filter(filter.name).present? %>
<% filter_boolean = filter.is_a?(Queries::Filters::Shared::BooleanFilter) %>

Expand Down Expand Up @@ -65,7 +65,7 @@
class="filter_rem"
data-action="click->project#removeFilter"
data-project-filter-name-param="<%= filter.name %>">
<%= op_icon("icon-close advanced-filters--remove-filter-icon", title: I18n.t('js.button_delete')) %>
<%= helpers.op_icon("icon-close advanced-filters--remove-filter-icon", title: I18n.t('js.button_delete')) %>
</a>
</div>
</li>
Expand All @@ -77,7 +77,7 @@
<li class="advanced-filters--add-filter">
<!-- Add filters -->
<label for="add_filter_select" aria-hidden="true" class="advanced-filters--add-filter-label ng-binding">
<%= op_icon("icon-add icon4") %>
<%= helpers.op_icon("icon-add icon4") %>
<%= t(:label_filter_add) %>:
</label>
<label for="add_filter_select" class="hidden-for-sighted ng-binding">
Expand All @@ -89,10 +89,10 @@
<div class="advanced-filters--add-filter-value">
<%= select_tag 'add_filter_select',
options_from_collection_for_select(
allowed_filters(query),
:name,
:human_name,
disabled: query.filters.map(&:name)
allowed_filters,
:name,
:human_name,
disabled: query.filters.map(&:name)
),
prompt: t(:actionview_instancetag_blank_option),
class: 'advanced-filters--select',
Expand All @@ -110,12 +110,12 @@
</ul>
<% unless EnterpriseToken.allows_to?(:custom_fields_in_projects_list)%>
<%=
angular_component_tag 'op-enterprise-banner',
inputs: {
collapsible: true,
textMessage: t('ee.upsale.project_filters.description_html'),
moreInfoLink: OpenProject::Static::Links.links[:enterprise_docs][:custom_field_projects][:href],
}
helpers.angular_component_tag 'op-enterprise-banner',
inputs: {
collapsible: true,
textMessage: t('ee.upsale.project_filters.description_html'),
moreInfoLink: OpenProject::Static::Links.links[:enterprise_docs][:custom_field_projects][:href],
}
%>
<% end %>
</fieldset>
Expand Down
59 changes: 59 additions & 0 deletions app/components/projects/filters_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# frozen_string_literal: true

# -- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2010-2023 the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See COPYRIGHT and LICENSE files for more details.
# ++

class Projects::FiltersComponent < ApplicationComponent
options :query

def allowed_filters
query
.available_filters
.select { |f| allowed_filter?(f) }
.sort_by(&:human_name)
end

private

def allowed_filter?(filter)
allowlist = [
Queries::Projects::Filters::ActiveFilter,
Queries::Projects::Filters::TemplatedFilter,
Queries::Projects::Filters::PublicFilter,
Queries::Projects::Filters::ProjectStatusFilter,
Queries::Projects::Filters::MemberOfFilter,
Queries::Projects::Filters::CreatedAtFilter,
Queries::Projects::Filters::LatestActivityAtFilter,
Queries::Projects::Filters::NameAndIdentifierFilter,
Queries::Projects::Filters::TypeFilter
]
allowlist << Queries::Filters::Shared::CustomFields::Base if EnterpriseToken.allows_to?(:custom_fields_in_projects_list)

allowlist.detect { |clazz| filter.is_a? clazz }
end
end
100 changes: 100 additions & 0 deletions app/components/projects/index_page_header_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<%= render(Primer::OpenProject::PageHeader.new) do |header| %>
<% header.with_title { t(:label_project_plural) } %>

<% header.with_actions do %>
<% if current_user.allowed_globally?(:add_project) %>
<%= render(
Primer::Beta::Button.new(
tag: :a,
href: new_project_path,
scheme: :primary,
size: :medium,
aria: { label: I18n.t(:label_project_new) },
mr: BUTTON_MARGIN_RIGHT,
data: { 'test-selector': 'project-new-button' }
)
) do |button|
button.with_leading_visual_icon(icon: :plus)
Project.model_name.human
end
%>
<% end %>

<%= render(
Primer::Beta::IconButton.new(
icon: :filter,
size: :medium,
aria: { label: t(:label_filters_toggle) },
mr: BUTTON_MARGIN_RIGHT,
data: { 'project-target': 'filterFormToggle',
'action': 'project#toggleDisplayFilters',
'test-selector': 'project-filter-toggle' }
)
)
%>

<%= render(
Primer::Beta::Button.new(
tag: :a,
href: activities_path,
size: :medium,
type: :submit,
aria: { label: t(:label_overall_activity) },
mr: BUTTON_MARGIN_RIGHT
)
) do
t(:label_overall_activity)
end
%>

<%= render(
Primer::Beta::Button.new(
tag: :a,
href: gantt_portfolio_query_link,
size: :medium,
disabled: gantt_portfolio_project_ids.empty?,
type: :submit,
aria: { label: t('projects.index.open_as_gantt') },
mr: BUTTON_MARGIN_RIGHT,
id: 'projects-index-open-as-gantt',
target: '_blank'
)
) do |button|
button.with_leading_visual_icon(icon: 'op-view-timeline')
button.with_trailing_visual_icon(icon: 'link-external')
button.with_tooltip(text: gantt_portfolio_title)

t('projects.index.open_as_gantt')
end %>

<%= render(Primer::Alpha::ActionMenu.new) do |menu|
menu.with_show_button(icon: 'op-kebab-vertical', 'aria-label': t(:label_more), data: { 'test-selector': 'project-more-dropdown-menu' })

if current_user.admin?
menu.with_item(
label: t('button_configure'),
href: admin_settings_projects_path,
content_arguments: { target: '_blank' }
) do |item|
item.with_leading_visual_icon(icon: :gear)
end
end

menu.with_item(
label: t('js.label_export'),
content_arguments: { 'data-show-dialog-id': 'project-export-dialog' }
) do |item|
item.with_leading_visual_icon(icon: 'op-file-download')
end
end
%>
<% end %>
<% end %>

<%= render(Primer::Alpha::Dialog.new(title: t('js.label_export'),
id: 'project-export-dialog')) do |d|
d.with_header(variant: :large)
d.with_body do
render partial: 'project_export_modal', locals: { query: query }
end
end %>
61 changes: 61 additions & 0 deletions app/components/projects/index_page_header_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# frozen_string_literal: true

# -- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2010-2023 the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See COPYRIGHT and LICENSE files for more details.
# ++

class Projects::IndexPageHeaderComponent < ApplicationComponent
options :projects,
:current_user,
:query

BUTTON_MARGIN_RIGHT = 2

def gantt_portfolio_query_link
generator = ::Projects::GanttQueryGeneratorService.new(gantt_portfolio_project_ids)
work_packages_path query_props: generator.call
end

def gantt_portfolio_project_ids
@gantt_portfolio_project_ids ||= projects
.where(active: true)
.select(:id)
.uniq
.pluck(:id)
end

def gantt_portfolio_title
title = t('projects.index.open_as_gantt_title')

if current_user.admin?
title << ' '
title << t('projects.index.open_as_gantt_title_admin')
end

title
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<p class="information-section">
<%= helpers.op_icon('icon-info1') %>
<%= t(:label_projects_storage_information,
count: Project.count,
storage: number_to_human_size(Project.total_projects_size, precision: 2)) %>
</p>
37 changes: 37 additions & 0 deletions app/components/projects/storage_information_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

# -- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2010-2023 the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See COPYRIGHT and LICENSE files for more details.
# ++

class Projects::StorageInformationComponent < ApplicationComponent
options :current_user

def render?
current_user.admin?
end
end
48 changes: 0 additions & 48 deletions app/helpers/projects_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,6 @@ def show_filters_section?
params[:filters].present? && !params.key?(:hide_filters_section)
end

def allowed_filters(query)
query
.available_filters
.select { |f| whitelisted_project_filter?(f) }
.sort_by(&:human_name)
end

def whitelisted_project_filter?(filter)
whitelist = [
Queries::Projects::Filters::ActiveFilter,
Queries::Projects::Filters::TemplatedFilter,
Queries::Projects::Filters::PublicFilter,
Queries::Projects::Filters::ProjectStatusFilter,
Queries::Projects::Filters::MemberOfFilter,
Queries::Projects::Filters::CreatedAtFilter,
Queries::Projects::Filters::LatestActivityAtFilter,
Queries::Projects::Filters::NameAndIdentifierFilter,
Queries::Projects::Filters::TypeFilter
]
whitelist << Queries::Filters::Shared::CustomFields::Base if EnterpriseToken.allows_to?(:custom_fields_in_projects_list)

whitelist.detect { |clazz| filter.is_a? clazz }
end

def no_projects_result_box_params
if User.current.allowed_globally?(:add_project)
{ action_url: new_project_path, display_action: true }
Expand Down Expand Up @@ -290,30 +266,6 @@ def allowed_parent_projects(project)
.assignable_parents
end

def gantt_portfolio_query_link(filtered_project_ids)
generator = ::Projects::GanttQueryGeneratorService.new(filtered_project_ids)
work_packages_path query_props: generator.call
end

def gantt_portfolio_project_ids(project_scope)
project_scope
.where(active: true)
.select(:id)
.uniq
.pluck(:id)
end

def gantt_portfolio_title
title = t('projects.index.open_as_gantt_title')

if current_user.admin?
title << ' '
title << t('projects.index.open_as_gantt_title_admin')
end

title
end

def short_project_description(project, length = 255)
unless project.description.present?
return ''
Expand Down
Loading

0 comments on commit 5908ce5

Please sign in to comment.