Skip to content

Commit

Permalink
Merge pull request #13259 from opf/implementation/47989-create-boards…
Browse files Browse the repository at this point in the history
…-outside-of-a-project

[#47989] Create Boards outside of a Project
  • Loading branch information
aaron-contreras authored Jul 27, 2023
2 parents 64b8d16 + 90f4d4a commit 6f0f016
Show file tree
Hide file tree
Showing 35 changed files with 1,554 additions and 18 deletions.
7 changes: 7 additions & 0 deletions frontend/src/global_styles/content/_forms.sass
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ fieldset.form--fieldset
&.-visible-overflow .form--field-container
overflow: visible

&.-align-start
align-items: start

&.-vertical,
.form.-vertical &
@include grid-orient(vertical)
Expand Down Expand Up @@ -450,6 +453,10 @@ fieldset.form--fieldset
> *:last-child
margin-right: auto

&.-enterprise-restricted
flex-direction: column
align-items: start

.form--field.-visible-overflow &
overflow: visible

Expand Down
1 change: 1 addition & 0 deletions frontend/src/global_styles/content/_index.sass
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@import custom_logo
@import toast
@import toast_mobile
@import tiles
@import links
@import loading_indicator
@import enterprise
Expand Down
83 changes: 83 additions & 0 deletions frontend/src/global_styles/content/_tiles.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//-- 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.
//++
.op-tile-block
$block: &
display: grid
grid-template-rows: repeat(minmax(200px, auto))
grid-template-columns: auto auto
grid-gap: 1rem

&--tile
border-radius: 10px
display: grid
grid-template: auto / 1fr auto
grid-row-gap: 5px
justify-items: left
background: #f7fafc
min-height: 150px
padding: 1rem
border: 1px solid var(--button--border-color)

&:disabled
background: #fafafa

&:hover
text-decoration: none
border: 1px solid grey
border-radius: 10px !important
cursor: pointer

&.-disabled
@include button-disabled

&--content
display: flex
column-gap: 0.75rem

.form--radio-button
margin-top: 0.75rem

&--image
display: block
margin-top: auto
margin-bottom: auto

&--title
padding-top: 0
padding-bottom: 5px
color: var(--primary-color-dark)
display: block
text-align: left
font-weight: bolder
font-size: large

&--description
text-align: left
width: 90%
font-weight: normal
3 changes: 3 additions & 0 deletions lib/open_project/static/links.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ def static_links
attribute_highlighting: {
href: 'https://www.openproject.org/docs/user-guide/work-packages/work-package-table-configuration/#attribute-highlighting-enterprise-add-on'
},
boards: {
href: 'https://www.openproject.org/docs/user-guide/agile-boards/#action-boards-enterprise-add-on'
},
custom_field_projects: {
href: 'https://www.openproject.org/docs/system-admin-guide/custom-fields/custom-fields-projects/'
},
Expand Down
54 changes: 54 additions & 0 deletions modules/boards/app/components/boards/add_button_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

# -- copyright
# OpenProject is an open source project management software.
# Copyright (C) 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.
# ++
#

module Boards
class AddButtonComponent < ::AddButtonComponent
def render?
User.current.allowed_to_globally?(:manage_board_views)
end

def dynamic_path
new_work_package_board_path
end

def id
'add-board-button'
end

def accessibility_label_text
I18n.t('boards.label_create_new_board')
end

def label_text
I18n.t('boards.label_board')
end
end
end
14 changes: 14 additions & 0 deletions modules/boards/app/contracts/boards/create_contract.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Boards
class CreateContract < ::Grids::CreateContract
private

def validate_allowed
unless edit_allowed?
# "project" is what is exposed to the user in the global form, not "scope"
errors.add(:project, :blank)
end
end
end
end
60 changes: 59 additions & 1 deletion modules/boards/app/controllers/boards/boards_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module ::Boards
class BoardsController < BaseController
before_action :find_optional_project
before_action :build_board_grid, only: %i[new]

with_options only: [:index] do
# The boards permission alone does not suffice
Expand All @@ -9,7 +10,8 @@ class BoardsController < BaseController
before_action :authorize_work_package_permission
end

before_action :authorize_global, only: :overview
before_action :authorize_global, only: %i[overview new create]
before_action :ensure_board_type_not_restricted, only: %i[create]

menu_item :board_view

Expand All @@ -31,12 +33,68 @@ def overview
:boards
end

def new; end

def create
service_result = service_call

@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

private

def authorize_work_package_permission
unless current_user.allowed_to?(:view_work_packages, @project, global: @project.nil?)
deny_access
end
end

def build_board_grid
@board_grid = Boards::Grid.new
end

def ensure_board_type_not_restricted
render_403 if restricted_board_type?
end

def restricted_board_type?
!EnterpriseToken.allows_to?(:board_view) && board_grid_params[:attribute] != 'basic'
end

def service_call
service_class.new(user: User.current)
.call(
project: @project,
name: board_grid_params[:name],
attribute: board_grid_params[:attribute]
)
end

def service_class
{
'basic' => Boards::BasicBoardCreateService,
'status' => Boards::StatusBoardCreateService,
'assignee' => Boards::AssigneeBoardCreateService,
'version' => Boards::VersionBoardCreateService,
'subproject' => Boards::SubprojectBoardCreateService,
'subtasks' => Boards::SubtasksBoardCreateService
}.fetch(board_grid_params[:attribute])
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}"
end
end
end
28 changes: 28 additions & 0 deletions modules/boards/app/helpers/boards_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

module BoardsHelper
BoardTypeAttributes = Struct.new(:radio_button_value,
:title,
:description,
:image_path,
:disabled?)

def board_types
[
build_board_type_attributes('basic', 'lists', false),
build_board_type_attributes('status', 'status'),
build_board_type_attributes('assignee', 'assignees'),
build_board_type_attributes('version', 'version'),
build_board_type_attributes('subproject', 'subproject'),
build_board_type_attributes('subtasks', 'parent-child')
]
end

def build_board_type_attributes(type_name, image_name, disabled = !EnterpriseToken.allows_to?(:board_view))
BoardTypeAttributes.new(type_name,
I18n.t("boards.board_type_attributes.#{type_name}"),
I18n.t("boards.board_type_descriptions.#{type_name}"),
"assets/images/board_creation_modal/#{image_name}.svg",
disabled)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module Boards
class AssigneeBoardCreateService < BaseCreateService
private

def no_widgets_initially?
true
end
end
end
Loading

0 comments on commit 6f0f016

Please sign in to comment.