-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[#69068] Add support for Project template icons #21035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,38 @@ | ||||||||||||||||||||||
| # 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 Projects | ||||||||||||||||||||||
| module Settings | ||||||||||||||||||||||
| class IconForm < ApplicationForm | ||||||||||||||||||||||
| form do |f| | ||||||||||||||||||||||
| f.file_field name: :icon, label: attribute_name(:icon), accept: "foo", size: "15" | ||||||||||||||||||||||
|
Comment on lines
+33
to
+34
|
||||||||||||||||||||||
| form do |f| | |
| f.file_field name: :icon, label: attribute_name(:icon), accept: "foo", size: "15" | |
| # The size of the file input field for project icon uploads. | |
| ICON_FILE_FIELD_SIZE = 15 | |
| # Only allow SVG, PNG, and JPEG image uploads for project icons. | |
| ICON_FILE_ACCEPT_TYPES = "image/svg+xml,image/png,image/jpeg" | |
| form do |f| | |
| f.file_field name: :icon, label: attribute_name(:icon), accept: ICON_FILE_ACCEPT_TYPES, size: ICON_FILE_FIELD_SIZE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # 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 HasIcon | ||
| extend ActiveSupport::Concern | ||
|
|
||
| included do | ||
| has_one :icon, as: :iconifiable, dependent: :destroy | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # 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. | ||
| #++ | ||
| class CustomIcon < Icon | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class Icon < ApplicationRecord | ||
| end | ||
|
Comment on lines
+3
to
+4
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # 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. | ||
| #++ | ||
| class OcticonIcon < Icon | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # 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. | ||
| #++ | ||
| class CreateIcons < ActiveRecord::Migration[8.0] | ||
| def change | ||
| create_table :icons do |t| | ||
| t.string :type, null: false | ||
|
|
||
| t.string :octicon_name | ||
| t.string :custom_file | ||
|
|
||
| t.references :iconifiable, polymorphic: true, null: false | ||
| t.timestamps | ||
| end | ||
|
|
||
| add_check_constraint :icons, | ||
| "(octicon_name IS NOT NULL) <> (custom_file IS NOT NULL)", | ||
| name: "only_one_icon_source" | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| import './primer-file-field'; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,40 @@ | ||||||||||||||||||
| import { controller, target } from '@github/catalyst'; | ||||||||||||||||||
|
|
||||||||||||||||||
| @controller | ||||||||||||||||||
| class PrimerFileFieldElement extends HTMLElement { | ||||||||||||||||||
| @target inputElement:HTMLInputElement; | ||||||||||||||||||
|
|
||||||||||||||||||
| #abortController:AbortController | null; | ||||||||||||||||||
|
|
||||||||||||||||||
| @target button:HTMLElement; | ||||||||||||||||||
| @target label:HTMLElement; | ||||||||||||||||||
|
|
||||||||||||||||||
| connectedCallback() { | ||||||||||||||||||
| this.#abortController?.abort(); | ||||||||||||||||||
| const {signal} = (this.#abortController = new AbortController()); | ||||||||||||||||||
|
|
||||||||||||||||||
| this.inputElement.addEventListener('change', () => { | ||||||||||||||||||
| const files = this.inputElement.files!; | ||||||||||||||||||
| if (files.length === 0) { | ||||||||||||||||||
| this.label.textContent = 'no file selected'; | ||||||||||||||||||
|
||||||||||||||||||
| this.label.textContent = 'no file selected'; | |
| this.label.textContent = this.getAttribute('data-no-file-selected-label') || 'no file selected'; |
Copilot
AI
Nov 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented-out code should be removed. The custom element registration is essential for the component to work; if this code is needed, it should be uncommented and properly integrated. If it's handled elsewhere, the commented code should be deleted.
| // if (!window.customElements.get('primer-file-field')) { | |
| // window.PrimerFileFieldElement = PrimerFileFieldElement | |
| // window.customElements.define('primer-file-field', PrimerFileFieldElement) | |
| // } | |
| if (!window.customElements.get('primer-file-field')) { | |
| window.PrimerFileFieldElement = PrimerFileFieldElement | |
| window.customElements.define('primer-file-field', PrimerFileFieldElement) | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation method
validate_templated_presentis incorrect for the icon attribute. This validator checks ifmodel.templated.nil?and adds an error to:templated, but it's being used for the:iconattribute. This will validate the wrong attribute and produce confusing error messages. The icon validation should either validate icon-specific requirements or be removed if no validation is needed.