Skip to content

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

Add methods to extract board type and attribute

Klaus Zanders63cce16ed94f
diff --git a/modules/boards/app/models/boards/grid.rb b/modules/boards/app/models/boards/grid.rb
index 228c606ca67..9a6832d1908 100644
--- a/modules/boards/app/models/boards/grid.rb
+++ b/modules/boards/app/models/boards/grid.rb
@@ -49,6 +49,16 @@ module Boards
"#{I18n.t('boards.label_board')} '#{name}'"
end
+ def board_type
+ options.with_indifferent_access[:type]&.to_sym || :free
+ end
+
+ def board_type_attribute
+ return nil unless board_type == :action
+
+ options.with_indifferent_access[:attribute]
+ end
+
private
def delete_queries
diff --git a/modules/boards/config/locales/en.yml b/modules/boards/config/locales/en.yml
index 40966ce4dad..893ca755275 100644
--- a/modules/boards/config/locales/en.yml
+++ b/modules/boards/config/locales/en.yml
@@ -2,8 +2,18 @@
en:
permission_show_board_views: "View boards"
permission_manage_board_views: "Manage boards"
-
project_module_board_view: "Boards"
+
boards:
label_board: "Board"
label_boards: "Boards"
+ board_types:
+ free: Basic
+ action: "Action board (%{attribute})"
+ board_type_attributes:
+ assignee: Assignee
+ status: Status
+ version: Version
+ subproject: Subproject
+ subtasks: Parent-child
+ basic: Basic
diff --git a/modules/boards/spec/models/boards/grid_spec.rb b/modules/boards/spec/models/boards/grid_spec.rb
index b3b3a641323..7757b44534a 100644
--- a/modules/boards/spec/models/boards/grid_spec.rb
+++ b/modules/boards/spec/models/boards/grid_spec.rb
@@ -32,7 +32,7 @@ describe Boards::Grid do
let(:instance) { described_class.new }
let(:project) { build_stubbed(:project) }
- context 'attributes' do
+ describe 'attributes' do
it '#project' do
instance.project = project
expect(instance.project)
@@ -48,5 +48,39 @@ describe Boards::Grid do
instance.name = 'foo'
expect(instance).to be_valid
end
+
+ describe '#board_type' do
+ it 'extracts correct, symbolized type when it is stored as a symbol key' do
+ instance.options[:type] = 'action'
+
+ expect(instance.board_type).to eq(:action)
+ end
+
+ it 'extracts correct, symbolized type when it is stored as a string key' do
+ instance.options['type'] = 'action'
+
+ expect(instance.board_type).to eq(:action)
+ end
+
+ it 'defaults to :free type' do
+ instance.options = {}
+
+ expect(instance.board_type).to eq(:free)
+ end
+ end
+
+ describe '#board_type_attribute' do
+ it 'returns nil for a board that is not of type action' do
+ instance.options = { type: 'free', attribute: 'status' }
+
+ expect(instance.board_type_attribute).to be_nil
+ end
+
+ it 'returns attribute for a board that is of type action' do
+ instance.options = { type: 'action', attribute: 'status' }
+
+ expect(instance.board_type_attribute).to eq('status')
+ end
+ end
end
end