2023-03-20 17:18:55 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
#-- copyright
|
|
|
|
|
# OpenProject is an open source project management software.
|
2024-07-30 13:42:36 +02:00
|
|
|
# Copyright (C) the OpenProject GmbH
|
2023-03-20 17:18:55 +01:00
|
|
|
#
|
|
|
|
|
# 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 Enumerations
|
|
|
|
|
class TableComponent < ::TableComponent
|
2025-01-28 17:41:27 +01:00
|
|
|
attr_reader :enumeration
|
|
|
|
|
|
|
|
|
|
def initialize(enumeration:, rows: [], **)
|
|
|
|
|
super(rows: rows, **)
|
|
|
|
|
@enumeration = enumeration
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-20 17:18:55 +01:00
|
|
|
def columns
|
2025-01-28 17:41:27 +01:00
|
|
|
headers.map(&:first)
|
2023-03-20 17:18:55 +01:00
|
|
|
end
|
|
|
|
|
|
2023-11-23 11:26:58 +01:00
|
|
|
def sortable?
|
|
|
|
|
false
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-20 17:18:55 +01:00
|
|
|
def headers
|
2025-01-28 17:41:27 +01:00
|
|
|
@headers ||= [
|
2023-03-20 17:18:55 +01:00
|
|
|
["name", { caption: Enumeration.human_attribute_name(:name) }],
|
2025-01-28 17:41:27 +01:00
|
|
|
enumeration.can_have_default_value? ? ["is_default", { caption: Enumeration.human_attribute_name(:is_default) }] : nil,
|
2023-03-20 17:18:55 +01:00
|
|
|
["active", { caption: Enumeration.human_attribute_name(:active) }],
|
2025-01-28 17:41:27 +01:00
|
|
|
with_colors ? ["color", { caption: Enumeration.human_attribute_name(:color) }] : nil,
|
2023-03-20 17:18:55 +01:00
|
|
|
["sort", { caption: I18n.t(:label_sort) }]
|
2025-01-28 17:41:27 +01:00
|
|
|
].compact
|
2023-03-20 17:18:55 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def with_colors
|
|
|
|
|
rows.colored?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def inline_create_link
|
|
|
|
|
link_to new_enumeration_path(type: rows.name),
|
|
|
|
|
aria: { label: t(:label_enumeration_new) },
|
|
|
|
|
class: "wp-inline-create--add-link",
|
2023-09-12 15:50:01 +02:00
|
|
|
data: { "test-selector": "create-enumeration-#{rows.name.underscore.dasherize}" },
|
2023-03-20 17:18:55 +01:00
|
|
|
title: t(:label_enumeration_new) do
|
|
|
|
|
helpers.op_icon("icon icon-add")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|