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
Add ability to create "Basic" Boards globally
Aaron Contreras182ca9061dd6
diff --git a/modules/boards/app/contracts/boards/global_create_contract.rb b/modules/boards/app/contracts/boards/global_create_contract.rbnew file mode 100644index 00000000000..bb431cde82c--- /dev/null+++ b/modules/boards/app/contracts/boards/global_create_contract.rb@@ -0,0 +1,6 @@+# frozen_string_literal: true++module Boards+ class GlobalCreateContract < ::Grids::CreateContract+ end+enddiff --git a/modules/boards/app/controllers/boards/boards_controller.rb b/modules/boards/app/controllers/boards/boards_controller.rbindex 6033614b7e5..030316fee34 100644--- a/modules/boards/app/controllers/boards/boards_controller.rb+++ b/modules/boards/app/controllers/boards/boards_controller.rb@@ -1,6 +1,7 @@module ::Boardsclass BoardsController < BaseControllerbefore_action :find_optional_project+ before_action :build_board_grid, only: %i[new]with_options only: [:index] do# The boards permission alone does not suffice@@ -9,7 +10,7 @@ module ::Boardsbefore_action :authorize_work_package_permissionend- before_action :authorize_global, only: :overview+ before_action :authorize_global, only: %i[overview new create]menu_item :board_view@@ -33,6 +34,25 @@ module ::Boardsdef new; end+ def create+ service_result = Boards::GlobalCreateService.new(user: User.current)+ .call(+ project: @project,+ name: board_grid_params[:name],+ attribute: board_grid_params[:attribute]+ )++ @board_grid = service_result.result++ if service_result.success?+ flash[:notice] = I18n.t(:notice_successful_create)+ redirect_to board_grid_path+ else+ @errors = service_result.errors+ render action: :new+ end+ end+privatedef authorize_work_package_permission@@ -40,5 +60,17 @@ module ::Boardsdeny_accessendend++ def build_board_grid+ @board_grid = Boards::Grid.new+ end++ def board_grid_params+ params.require(:boards_grid).permit(%i[name attribute])+ end++ def board_grid_path+ "/projects/#{@project.identifier}/boards/#{@board_grid.id}"+ endendenddiff --git a/modules/boards/app/services/boards/global_create_service.rb b/modules/boards/app/services/boards/global_create_service.rbnew file mode 100644index 00000000000..ea27540e118--- /dev/null+++ b/modules/boards/app/services/boards/global_create_service.rb@@ -0,0 +1,96 @@+# frozen_string_literal: true++module Boards+ class GlobalCreateService < ::Grids::CreateService+ def initialize(user:, contract_class: ::Boards::GlobalCreateContract, contract_options: nil)+ super+ end++ protected++ def instance(attributes)+ factory_attributes = set_attributes_params(attributes).merge(scope: scope(attributes))+ super(factory_attributes)+ end++ def before_perform(params, _service_result)+ create_query_result = create_query(params)++ super(params.merge(query_id: create_query_result.result.id), create_query_result)+ end++ def scope(params)+ Rails.application.routes.url_helpers.project_work_package_boards_path(params[:project])+ end++ def set_attributes_params(params)+ {}.tap do |grid_params|+ grid_params[:name] = params[:name]+ grid_params[:options] = options_for_grid(params)+ grid_params[:row_count] = 1+ grid_params[:column_count] = column_count_for_grid(params)+ grid_params[:widgets] = options_for_widgets(params)+ end+ end++ def attributes_service_class+ GlobalSetAttributesService+ end++ private++ def create_query(params)+ Queries::CreateService.new(user: User.current)+ .call(create_query_params(params))+ end++ def create_query_params(params)+ {+ project_id: params[:project].id,+ name: query_name(params),+ filters: query_filters(params)+ }+ end++ def query_name(params)+ {+ 'basic' => 'Unnamed list'+ }.fetch(params[:attribute])+ end++ def query_filters(params)+ {+ 'basic' => [{ manual_sort: { operator: 'ow', values: [] } }]+ }.fetch(params[:attribute])+ end++ def options_for_grid(params)+ {}.tap do |options|+ options[:attribute] = params[:attribute]+ options[:type] = params[:attribute] == 'basic' ? 'free' : 'action'+ end+ end++ def column_count_for_grid(_params)+ 4+ end++ def options_for_widgets(params)+ {+ 'basic' => [+ Grids::Widget.new(+ start_row: 1,+ start_column: 1,+ end_row: 2,+ end_column: 2,+ identifier: "work_package_query",+ options: {+ "queryId" => params[:query_id],+ "filters" => query_filters(params)+ }+ )+ ]+ }.fetch(params[:attribute])+ end+ end+enddiff --git a/modules/boards/app/services/boards/global_set_attributes_service.rb b/modules/boards/app/services/boards/global_set_attributes_service.rbnew file mode 100644index 00000000000..91ccfba6760--- /dev/null+++ b/modules/boards/app/services/boards/global_set_attributes_service.rb@@ -0,0 +1,6 @@+# frozen_string_literal: true++module Boards+ class GlobalSetAttributesService < Grids::SetAttributesService+ end+enddiff --git a/modules/boards/app/views/boards/boards/_form.html.erb b/modules/boards/app/views/boards/boards/_form.html.erbnew file mode 100644index 00000000000..7d360c361de--- /dev/null+++ b/modules/boards/app/views/boards/boards/_form.html.erb@@ -0,0 +1,71 @@+<%#-- copyright+OpenProject is an open source project management software.+Copyright (C) 2012-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.++++#%>++<%= error_messages_for_contract @board_grid, @errors %>++<section class="form--section">+ <div class="form--field -required">+ <%= f.text_field :name,+ label: t(:label_title),+ required: true,+ size: 60,+ container_class: '-wide' %>+ </div>++ <div class="form--field -required">+ <label class="form--label" for="project_id"><%= Query.human_attribute_name(:project) %>:</label>+ <div class="form--field-container">+ <%= angular_component_tag 'op-project-autocompleter',+ inputs: {+ apiFilters: [['user_action', '=', ['boards/create']]],+ name: 'project_id',+ value: @project,+ appendTo: 'body',+ },+ id: 'project_id',+ class: 'form--select-container -wide remote-field--input',+ data: {+ 'qa-selector': 'project_id'+ }+ %>+ </div>+ </div>++ <div class="form--field -required">+ <label class="form--label-with-radio-button" for="board_type"><%= t('boards.label_board_type') %>:</label>++ <div class="form--field">+ <%= f.label 'attribute', t('boards.board_type_attributes.basic'), value: 'basic' %>+ <%= styled_radio_button_tag 'boards_grid[attribute]',+ 'basic',+ no_label: true,+ container_class: '-wide'%>+ </div>+ </div>+</section>diff --git a/modules/boards/app/views/boards/boards/new.html.erb b/modules/boards/app/views/boards/boards/new.html.erbindex 6dda34e4adb..d7fad258621 100644--- a/modules/boards/app/views/boards/boards/new.html.erb+++ b/modules/boards/app/views/boards/boards/new.html.erb@@ -29,3 +29,9 @@ See COPYRIGHT and LICENSE files for more details.<% html_title t('boards.label_create_new_board') %><%= toolbar title: t('boards.label_create_new_board') %>+<%= labelled_tabular_form_for @board_grid, url: { controller: '/boards/boards', action: 'create' }, :html => {:id => 'board-form'} do |f| -%>+ <%= render :partial => 'form', :locals => {:f => f} %>+ <%= styled_button_tag t(:button_create), class: '-highlight' %>+ <%= link_to t(:button_cancel), { controller: 'boards/boards', action: 'overview' },+ class: 'button' %>+<% end %>diff --git a/modules/boards/config/locales/en.yml b/modules/boards/config/locales/en.ymlindex c9b6613ba32..b8306e55957 100644--- a/modules/boards/config/locales/en.yml+++ b/modules/boards/config/locales/en.yml@@ -8,6 +8,7 @@ en:label_board: "Board"label_boards: "Boards"label_create_new_board: "Create new board"+ label_board_type: "Board type"board_types:free: Basicaction: "Action board (%{attribute})"diff --git a/modules/boards/lib/open_project/boards/engine.rb b/modules/boards/lib/open_project/boards/engine.rbindex 5db32f429b2..acc9cdf88d8 100644--- a/modules/boards/lib/open_project/boards/engine.rb+++ b/modules/boards/lib/open_project/boards/engine.rb@@ -33,7 +33,7 @@ module OpenProject::Boardsdependencies: :view_work_packages,contract_actions: { boards: %i[read] }permission :manage_board_views,- { 'boards/boards': %i[index] },+ { 'boards/boards': %i[index new create] },dependencies: :manage_public_queries,contract_actions: { boards: %i[create update destroy] }enddiff --git a/modules/boards/spec/features/boards_global_create_spec.rb b/modules/boards/spec/features/boards_global_create_spec.rbnew file mode 100644index 00000000000..83c1e632e97--- /dev/null+++ b/modules/boards/spec/features/boards_global_create_spec.rb@@ -0,0 +1,68 @@+# frozen_string_literal: true++require 'spec_helper'+require_relative 'support/board_global_create_page'++RSpec.describe 'Boards',+ 'Creating a view from a Global Context',+ :js,+ :with_cuprite,+ with_ee: %i[board_view] do+ shared_let(:project) { create(:project, enabled_module_names: %i[work_package_tracking board_view]) }+ shared_let(:admin) { create(:admin) }++ shared_let(:status) { create(:default_status) }++ shared_let(:new_board_page) { Pages::NewBoard.new }++ before do+ login_as admin+ end++ context 'within the global index page' do+ before do+ visit boards_all_path+ end++ context 'when clicking on the create button' do+ before do+ new_board_page.navigate_by_create_button+ end++ it 'navigates to the global create form' do+ expect(page).to have_current_path new_work_package_board_path+ expect(page).to have_content I18n.t('boards.label_create_new_board')+ end+ end+ end++ context 'within the global create page' do+ before do+ new_board_page.visit!+ end++ context 'with all fields set' do+ before do+ wait_for_reload # Halt until the project autocompleter is ready++ new_board_page.set_title "Gotham Renewal Board"+ new_board_page.set_project project+ end++ context 'when creating a "Basic" board' do+ before do+ new_board_page.set_board_type 'Basic'+ new_board_page.click_on_submit++ wait_for_reload+ end++ it 'creates the board and redirects me to it' do+ expect(page).to have_text(I18n.t(:notice_successful_create))+ expect(page).to have_current_path("/projects/#{project.identifier}/boards/#{Boards::Grid.last.id}")+ expect(page).to have_text "Gotham Renewal Board"+ end+ end+ end+ end+enddiff --git a/modules/boards/spec/features/support/board_global_create_page.rb b/modules/boards/spec/features/support/board_global_create_page.rbnew file mode 100644index 00000000000..ffe90bf2f92--- /dev/null+++ b/modules/boards/spec/features/support/board_global_create_page.rb@@ -0,0 +1,40 @@+# frozen_string_literal: true++require 'support/pages/page'++module Pages+ class NewBoard < Page+ include ::Components::Autocompleter::NgSelectAutocompleteHelpers++ def visit!+ visit new_work_package_board_path+ end++ def navigate_by_create_button+ visit boards_all_path unless page.current_path == boards_all_path++ within '.toolbar-items' do+ click_link 'Board'+ end+ end++ def set_title(title)+ fill_in 'Title', with: title+ end++ def set_project(project)+ select_autocomplete(find('[data-qa-selector="project_id"]'),+ query: project,+ results_selector: 'body',+ wait_for_fetched_options: false)+ end++ def set_board_type(board_type)+ choose board_type+ end++ def click_on_submit+ click_on 'Create'+ end+ end+end