-
-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: profile and cover photos (#2722)
Co-authored-by: Paul Bob <paul.ionut.bob@gmail.com>
- Loading branch information
1 parent
439292f
commit 99bfd50
Showing
28 changed files
with
358 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,6 @@ Lint/UselessAssignment: | |
|
||
Layout/FirstArgumentIndentation: | ||
Enabled: false | ||
|
||
Layout/ArgumentAlignment: | ||
Enabled: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
contact_links: | ||
- name: Priority Support | ||
url: https://avohq.io/support | ||
about: Get fast support from the authors of Avo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="related w-full -mt-4 md:-mt-4 lg:-mt-6 mb-2 flex flex-col"> | ||
<%= image_tag helpers.main_app.url_for(@cover_photo.value), class: class_names("w-full object-cover", size_class), data: {component: self.class.to_s.underscore} %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class Avo::CoverPhotoComponent < ViewComponent::Base | ||
def initialize(cover_photo:) | ||
@cover_photo = cover_photo | ||
@size = cover_photo&.size | ||
end | ||
|
||
# aspect-cover-sm | ||
# aspect-cover-md | ||
# aspect-cover-lg | ||
def size_class | ||
"aspect-cover-#{@size}" | ||
end | ||
|
||
def render? | ||
@cover_photo.present? && @cover_photo.visible_in_current_view? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<div class="text-2xl tracking-normal font-semibold text-gray-800 items-center flex flex-1" data-target="title"> | ||
<span><%= link_to_if @url.present?, @name, @url, target: @target, class: class_names("text-gray-800", @classes) %></span> | ||
<span class="block w-full text-center sm:text-left"><%= link_to_if @url.present?, @name, @url, target: @target, class: class_names("text-gray-800", @classes) %></span> | ||
<%= body %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<%= image_tag helpers.main_app.url_for(@profile_photo.value), class: class_names( | ||
"relative rounded-full object-cover aspect-square border-4 border-application", | ||
"has-cover-photo:sm:ml-8 sm:mr-2", | ||
"self-center sm:self-start", | ||
"size-24 has-cover-photo:size-36 has-cover-photo:sm:size-48 has-cover-photo:-mt-12", | ||
), data: {component: self.class.to_s.underscore} %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class Avo::ProfilePhotoComponent < ViewComponent::Base | ||
def initialize(profile_photo:) | ||
@profile_photo = profile_photo | ||
end | ||
|
||
def render? | ||
@profile_photo.present? && @profile_photo.visible_in_current_view? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Adds the ability to set the visibility of an item in the execution context. | ||
module Avo | ||
module Concerns | ||
module HasCoverPhoto | ||
extend ActiveSupport::Concern | ||
|
||
class_methods do | ||
# Add class property to capture the settings | ||
attr_accessor :cover_photo | ||
end | ||
|
||
# Add instance property to compute the options | ||
def cover_photo | ||
Avo::CoverPhoto.new resource: self | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Adds the ability to set the visibility of an item in the execution context. | ||
module Avo | ||
module Concerns | ||
module HasProfilePhoto | ||
extend ActiveSupport::Concern | ||
|
||
class_methods do | ||
# Add class property to capture the settings | ||
attr_accessor :profile_photo | ||
end | ||
|
||
# Add instance property to compute the options | ||
def profile_photo | ||
ProfilePhoto.new resource: self | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
module Avo | ||
class CoverPhoto < PhotoObject | ||
def key = :cover_photo | ||
|
||
def size | ||
options.fetch(:size, :md) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# frozen_string_literal: true | ||
|
||
class Avo::PhotoObject | ||
def initialize(resource:) | ||
@resource = resource | ||
end | ||
|
||
delegate :record, to: :@resource | ||
delegate :view, to: :@resource | ||
|
||
def options | ||
@options ||= if @resource.class&.send(key).present? | ||
@resource.class&.send(key) | ||
else | ||
{} | ||
end | ||
end | ||
|
||
def value | ||
return unless options.fetch(:source, nil).present? | ||
|
||
if options[:source].is_a?(Symbol) | ||
record.send(options[:source]) | ||
elsif options[:source].respond_to?(:call) | ||
Avo::ExecutionContext.new(target: options[:source], record:, resource: @resource, view:).handle | ||
end | ||
end | ||
|
||
def visible_on | ||
@visible_on ||= Array.wrap(options[:visible_on] || [:show, :forms]) | ||
end | ||
|
||
def visible_in_current_view? | ||
send(:"visible_on_#{view}?") | ||
end | ||
|
||
def present? | ||
value.present? | ||
end | ||
|
||
def visible_on_index? = visible_in_either?(:index, :display) | ||
|
||
def visible_on_show? = visible_in_either?(:show, :display) | ||
|
||
def visible_on_edit? = visible_in_either?(:edit, :forms) | ||
|
||
def visible_on_new? = visible_in_either?(:new, :forms) | ||
|
||
private | ||
|
||
def visible_in_either?(*options) | ||
options.map do |option| | ||
visible_on.include?(option) | ||
end.uniq.first.eql?(true) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
module Avo | ||
class ProfilePhoto < PhotoObject | ||
def key = :profile_photo | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.