OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Refactor into view components
Alexander Brandon Coles3b05f2b5958f
diff --git a/modules/overviews/app/components/_index.sass b/modules/overviews/app/components/_index.sassindex 747c81a350a..6fef6c9c4ae 100644--- a/modules/overviews/app/components/_index.sass+++ b/modules/overviews/app/components/_index.sass@@ -1,3 +1,3 @@@import "./overviews/project_custom_fields/item_component.sass"@import "./overviews/project_phases/item_component.sass"-@import "./overviews/show_component.sass"+@import "./overviews/overview_grid_component.sass"diff --git a/modules/overviews/app/components/overviews/dashboard_component.html.erb b/modules/overviews/app/components/overviews/dashboard_component.html.erbnew file mode 100644index 00000000000..d9516325423--- /dev/null+++ b/modules/overviews/app/components/overviews/dashboard_component.html.erb@@ -0,0 +1,51 @@+<%#-- copyright+OpenProject is an open source project management software.+Copyright (C) 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.++++#%>++<div class="op-grid-page">+ <% if allowed_to_manage? %>+ <%=+ render(Primer::OpenProject::SubHeader.new(classes: "grid-mx")) do |subheader|+ subheader.with_action_button(+ scheme: :primary,+ leading_icon: :plus,+ label: t(:label_widget_new),+ data: {+ controller: "overview--add-widgets",+ action: "click->overview--add-widgets#addWidget"+ },+ test_selector: "overview--add-widgets-button"+ ) do+ t(:label_widget)+ end+ end+ %>+ <% end %>++ <%= angular_component_tag("opce-dashboard") %>+</div>diff --git a/modules/overviews/app/components/overviews/dashboard_component.rb b/modules/overviews/app/components/overviews/dashboard_component.rbnew file mode 100644index 00000000000..eb54b622297--- /dev/null+++ b/modules/overviews/app/components/overviews/dashboard_component.rb@@ -0,0 +1,54 @@+# frozen_string_literal: true++# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2010-2024 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.+# ++++module Overviews+ class DashboardComponent < ApplicationComponent+ include ApplicationHelper+ include OpPrimer::ComponentHelpers+ include OpTurbo::Streamable+ include AngularHelper+ include Turbo::FramesHelper++ attr_reader :project, :current_user++ def initialize(project:, current_user:)+ super()++ @project = project+ @current_user = current_user+ end++ private++ def allowed_to_manage?+ current_user.allowed_in_project?(:manage_overview, project)+ end+ end+enddiff --git a/modules/overviews/app/components/overviews/overview_grid_component.html.erb b/modules/overviews/app/components/overviews/overview_grid_component.html.erbnew file mode 100644index 00000000000..637cbf72224--- /dev/null+++ b/modules/overviews/app/components/overviews/overview_grid_component.html.erb@@ -0,0 +1,39 @@+<%#-- copyright+OpenProject is an open source project management software.+Copyright (C) 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.++++#%>++<%=+ grid_layout("op-portfolio-overview", tag: :div, align_items: :flex_start) do |grid|+ grid.with_area(:description, tag: :div) do+ render(Overviews::Widgets::DescriptionComponent.new(@project))+ end+ grid.with_area(:subitems, tag: :div) do+ render(Overviews::Widgets::SubitemsComponent.new(@project))+ end+ end+%>diff --git a/modules/overviews/app/components/overviews/overview_grid_component.rb b/modules/overviews/app/components/overviews/overview_grid_component.rbnew file mode 100644index 00000000000..8da276ff9b1--- /dev/null+++ b/modules/overviews/app/components/overviews/overview_grid_component.rb@@ -0,0 +1,42 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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.+#++++module Overviews+ class OverviewGridComponent < ApplicationComponent+ include ApplicationHelper+ include OpPrimer::ComponentHelpers++ def initialize(project:)+ super++ @project = project+ end+ end+enddiff --git a/modules/overviews/app/components/overviews/show_component.sass b/modules/overviews/app/components/overviews/overview_grid_component.sasssimilarity index 100%rename from modules/overviews/app/components/overviews/show_component.sassrename to modules/overviews/app/components/overviews/overview_grid_component.sassdiff --git a/modules/overviews/app/components/overviews/show_component.html.erb b/modules/overviews/app/components/overviews/show_component.html.erbindex 1c5c6b894e6..6b598d0e104 100644--- a/modules/overviews/app/components/overviews/show_component.html.erb+++ b/modules/overviews/app/components/overviews/show_component.html.erb@@ -54,25 +54,6 @@ See COPYRIGHT and LICENSE files for more details.endend- if allowed_to_manage?- concat(- render(Primer::OpenProject::SubHeader.new(classes: { "grid-mx": sidebar_enabled? })) do |subheader|- subheader.with_action_button(- scheme: :primary,- leading_icon: :plus,- label: t(:label_widget_new),- data: {- controller: "overview--add-widgets",- action: "click->overview--add-widgets#addWidget"- },- test_selector: "overview--add-widgets-button"- ) do- t(:label_widget)- end- end- )- end-- concat(angular_component_tag("opce-dashboard"))+ render Overviews::OverviewGridComponent.new(project:)end%>diff --git a/modules/overviews/app/views/overviews/overviews/dashboard.html.erb b/modules/overviews/app/views/overviews/overviews/dashboard.html.erbindex c10246449da..7171009d1d9 100644--- a/modules/overviews/app/views/overviews/overviews/dashboard.html.erb+++ b/modules/overviews/app/views/overviews/overviews/dashboard.html.erb@@ -1,22 +1,2 @@<%= render partial: "page_header" %>--<%=- if User.current.allowed_in_project?(:manage_overview, @project)- render(Primer::OpenProject::SubHeader.new) do |subheader|- subheader.with_action_button(- scheme: :primary,- leading_icon: :plus,- label: t(:label_widget_new),- data: {- controller: "overview--add-widgets",- action: "click->overview--add-widgets#addWidget"- },- test_selector: "overview--add-widgets-button"- ) do- t(:label_widget)- end- end- end-%>--<%= angular_component_tag "opce-dashboard" %>+<%= render(Overviews::DashboardComponent.new(project: @project, current_user:)) %>diff --git a/modules/overviews/app/views/overviews/overviews/show.html.erb b/modules/overviews/app/views/overviews/overviews/show.html.erbindex 40c8baa9128..51441e15064 100644--- a/modules/overviews/app/views/overviews/overviews/show.html.erb+++ b/modules/overviews/app/views/overviews/overviews/show.html.erb@@ -1,53 +1,2 @@-<%=- render(Primer::OpenProject::PageHeader.new) do |header|- header.with_title(variant: :medium) { t("overviews.label") }- header.with_breadcrumbs(- [- { href: project_path(@project), text: @project.name, skip_for_mobile: true },- t("overviews.label")- ]- )- favored = @project.favored_by?(User.current)- header.with_action_icon_button(- icon: favored ? "star-fill" : "star",- mobile_icon: favored ? "star-fill" : "star",- size: :medium,- tag: :a,- href: build_favorite_path(@project, format: :html),- data: { method: favored ? :delete : :post },- classes: favored ? "op-primer--star-icon" : "",- label: favored ? I18n.t(:button_unfavorite) : I18n.t(:button_favorite),- aria: { label: favored ? I18n.t(:button_unfavorite) : I18n.t(:button_favorite) },- test_selector: "project-favorite-button"- )-- header.with_action_menu(- menu_arguments: { anchor_align: :end },- button_arguments: { icon: "kebab-horizontal", "aria-label": t(:label_menu) }- ) do |menu|- if User.current.allowed_in_project?(:select_project_custom_fields, @project)- menu.with_item(- label: t(:label_project_attribute_manage_link),- href: project_settings_project_custom_fields_path(@project),- data: { turbo: false }- ) do |item|- item.with_leading_visual_icon(icon: :pencil)- end- end-- if User.current.allowed_in_project?(:archive_project, @project)- menu.with_item(- label: t(:label_archive_project),- href: project_archive_path(@project, status: "", name: @project.name),- content_arguments: {- data: { method: :post, turbo: false, confirm: t("project.archive.are_you_sure", name: @project.name) }- }- ) do |item|- item.with_leading_visual_icon(icon: :lock)- end- end- end- end-%>-+<%= render partial: "page_header" %><%= render(Overviews::ShowComponent.new(project: @project, current_user:)) %>diff --git a/modules/overviews/spec/components/overviews/dashboard_component_spec.rb b/modules/overviews/spec/components/overviews/dashboard_component_spec.rbnew file mode 100644index 00000000000..8316add8884--- /dev/null+++ b/modules/overviews/spec/components/overviews/dashboard_component_spec.rb@@ -0,0 +1,73 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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.+#++++require "rails_helper"++RSpec.describe Overviews::DashboardComponent, type: :component do+ include Rails.application.routes.url_helpers++ def render_component(...)+ render_inline(described_class.new(...))+ end++ let(:project) { build_stubbed(:project) }+ let(:user) { build_stubbed(:user) }++ current_user { user }++ subject(:rendered_component) do+ render_component(project:, current_user:)+ end++ it "renders widgets" do+ expect(rendered_component).to have_element "opce-dashboard"+ end++ context "when user is not allowed to manage" do+ it "does not render '+ Widget' button" do+ expect(rendered_component).to have_no_button "Widget"+ end+ end++ context "when user is allowed to manage" do+ before do+ mock_permissions_for(user) do |mock|+ mock.allow_in_project(:manage_overview, project:)+ end+ end++ it "renders '+ Widget' button" do+ expect(rendered_component).to have_button "Widget" do |button|+ expect(button).to have_octicon :plus+ expect(button["data-action"]).to include "click->overview--add-widgets#addWidget"+ end+ end+ end+enddiff --git a/modules/overviews/spec/components/overviews/show_component_spec.rb b/modules/overviews/spec/components/overviews/show_component_spec.rbindex b91a5face15..be8a7edc465 100644--- a/modules/overviews/spec/components/overviews/show_component_spec.rb+++ b/modules/overviews/spec/components/overviews/show_component_spec.rb@@ -74,51 +74,8 @@ RSpec.describe Overviews::ShowComponent, type: :component doendend- it "renders widgets" do- expect(rendered_component).to have_element "opce-dashboard"- end-- context "when user is not allowed to manage" do- it "does not render '+ Widget' button" do- expect(rendered_component).to have_no_button "Widget"- end- end-- context "when user is allowed to manage" do- before do- mock_permissions_for(user) do |mock|- mock.allow_in_project(:manage_overview, project:)- end- end-- it "renders '+ Widget' button" do- expect(rendered_component).to have_button "Widget" do |button|- expect(button).to have_octicon :plus- expect(button["data-action"]).to include "click->overview--add-widgets#addWidget"- end- end-- context "when project has no attributes or life cycle" do- it "renders subheader with no margin" do- expect(rendered_component).to have_css ".SubHeader", class: "!grid-mx"- end- end-- context "when project has life cycle and user has permissions to view" do- let(:project) { build(:project) }- let!(:project_phase) { create(:project_phase, project:) }-- before do- mock_permissions_for(user) do |mock|- mock.allow_in_project(:manage_overview, project:)- mock.allow_in_project(:view_project_phases, project:)- end- end-- it "renders subheader with horizontal margin matching widget gap" do- expect(rendered_component).to have_css ".SubHeader", class: "grid-mx"- end- end+ it "renders overview grid" do+ expect(rendered_component).to have_css ".op-portfolio-overview"endcontext "when project has neither project attributes or life cycle" do