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 Users::AvatarComponent
Oliver Günthere3f28b9e0467
diff --git a/app/components/members/row_component.rb b/app/components/members/row_component.rbindex 18f40888c09..f32a8ba7a6e 100644--- a/app/components/members/row_component.rb+++ b/app/components/members/row_component.rb@@ -45,9 +45,7 @@ module Membersenddef name- icon = helpers.avatar principal, size: :mini-- icon + principal_link+ render Users::AvatarComponent.new(user: principal, size: :mini, link: true, show_name: true)enddef maildiff --git a/app/components/users/avatar_component.rb b/app/components/users/avatar_component.rbnew file mode 100644index 00000000000..a7fa40ac05d--- /dev/null+++ b/app/components/users/avatar_component.rb@@ -0,0 +1,59 @@+#-- 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.+#++++module Users+ class AvatarComponent < ApplicationComponent+ include ApplicationHelper+ include AvatarHelper+ include OpPrimer::ComponentHelpers++ def initialize(user:, show_name: true, link: true, size: 'default', title: nil)+ super++ @user = user+ @show_name = show_name+ @link = link+ @size = size+ @title = title+ end++ def render?+ @user.present?+ end++ def call+ helpers.avatar(+ @user,+ size: @size,+ link: @link,+ hide_name: !@show_name,+ title: @title+ )+ end+ end+enddiff --git a/frontend/src/app/shared/components/principal/principal-renderer.service.ts b/frontend/src/app/shared/components/principal/principal-renderer.service.tsindex 73edf8568c5..3869d8f4857 100644--- a/frontend/src/app/shared/components/principal/principal-renderer.service.ts+++ b/frontend/src/app/shared/components/principal/principal-renderer.service.ts@@ -69,7 +69,9 @@ export class PrincipalRendererService {avatar:AvatarOptions = { hide: false, size: 'default' },title:string|null = null,):void {- container.dataset.testSelector = 'op-principal';+ if (!container.dataset.testSelector) {+ container.dataset.testSelector = 'op-principal';+ }container.classList.add('op-principal');const type = typeFromHref(hrefFromPrincipal(principal)) as PrincipalType;@@ -145,7 +147,7 @@ export class PrincipalRendererService {principal:PrincipalLike|IPrincipal,type:PrincipalType,asLink = true,- title:string,+ title = '',) {if (asLink) {const link = document.createElement('a');diff --git a/frontend/src/app/shared/components/principal/principal-rendering.module.ts b/frontend/src/app/shared/components/principal/principal-rendering.module.tsindex b27d7146b44..f7386bd2b8a 100644--- a/frontend/src/app/shared/components/principal/principal-rendering.module.ts+++ b/frontend/src/app/shared/components/principal/principal-rendering.module.ts@@ -4,12 +4,6 @@ import { OpPrincipalComponent } from './principal.component';import { OpPrincipalListComponent } from './principal-list.component';import { PrincipalRendererService } from './principal-renderer.service';import { registerCustomElement } from 'core-app/shared/helpers/angular/custom-elements.helper';-import {- OpBasicSingleDatePickerComponent-} from 'core-app/shared/components/datepicker/basic-single-date-picker/basic-single-date-picker.component';-import {- OpBasicRangeDatePickerComponent-} from 'core-app/shared/components/datepicker/basic-range-date-picker/basic-range-date-picker.component';@NgModule({imports: [diff --git a/lookbook/previews/users/avatar_component_preview.rb b/lookbook/previews/users/avatar_component_preview.rbnew file mode 100644index 00000000000..00655e0a4b1--- /dev/null+++ b/lookbook/previews/users/avatar_component_preview.rb@@ -0,0 +1,21 @@+# frozen_string_literal: true++# @logical_path OpenProject+module Users+ class AvatarComponentPreview < Lookbook::Preview++ # Renders a user avatar using the OpenProject opce-principal web component+ # @param size select { choices: [default, medium, mini] }+ # @param link toggle+ # @param show_name toggle+ def default(size: :default, link: true, show_name: true)+ user = FactoryBot.build_stubbed(:user)+ render(Users::AvatarComponent.new(user:, size:, link:, show_name:))+ end++ def sizes+ user = FactoryBot.build_stubbed(:user)+ render_with_template(locals: { user: })+ end+ end+enddiff --git a/lookbook/previews/users/avatar_component_preview/sizes.html.erb b/lookbook/previews/users/avatar_component_preview/sizes.html.erbnew file mode 100644index 00000000000..3ed6fec8279--- /dev/null+++ b/lookbook/previews/users/avatar_component_preview/sizes.html.erb@@ -0,0 +1,12 @@+<p>+ <strong>Default</strong><br/>+ <%= render(Users::AvatarComponent.new(user: user, size: :default)) %>+</p>+<p>+ <strong>Medium</strong><br/>+ <%= render(Users::AvatarComponent.new(user: user, size: :medium)) %>+</p>+<p>+ <strong>Mini</strong><br/>+ <%= render(Users::AvatarComponent.new(user: user, size: :mini)) %>+</p>diff --git a/modules/avatars/app/helpers/avatar_helper.rb b/modules/avatars/app/helpers/avatar_helper.rbindex 0b079c817ba..1e35039197a 100644--- a/modules/avatars/app/helpers/avatar_helper.rb+++ b/modules/avatars/app/helpers/avatar_helper.rb@@ -99,12 +99,14 @@ module AvatarHelperid: user.id}- angular_component_tag 'op-principal',+ angular_component_tag 'opce-principal',class: tag_options[:class],inputs: {principal:,+ link: tag_options[:link],size: tag_options[:size],- hideName: tag_options[:hide_name]+ hideName: tag_options[:hide_name],+ title: tag_options.fetch(:title, '')}enddiff --git a/modules/avatars/spec/helpers/avatar_helper_spec.rb b/modules/avatars/spec/helpers/avatar_helper_spec.rbindex b0ecd824a2a..db43d485850 100644--- a/modules/avatars/spec/helpers/avatar_helper_spec.rb+++ b/modules/avatars/spec/helpers/avatar_helper_spec.rb@@ -31,10 +31,12 @@ RSpec.describe AvatarHelper, with_settings: { protocol: 'http' } doid: user.id}- angular_component_tag 'op-principal',+ angular_component_tag 'opce-principal',inputs: {principal:,hideName: true,+ link: nil,+ title: user.name,size: 'default'}end