Skip to content

Commit

Permalink
Add support for transparent background signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
andersonkrs committed Aug 3, 2024
1 parent 354fddd commit 6c23bb7
Show file tree
Hide file tree
Showing 21 changed files with 80 additions and 185 deletions.
4 changes: 4 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ html {
border: 1px #e1e4e8 solid;
}

.w-full {
width: 100%;
}

.about-section {
display: flex;
align-items: center;
Expand Down
4 changes: 0 additions & 4 deletions app/assets/stylesheets/users.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.user-avatar {
overflow-y: hidden;
}

.timeline .timeline-item {
padding-bottom: 0.5em;
position: relative;
Expand Down
10 changes: 9 additions & 1 deletion app/controllers/images/calendars_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
class Images::CalendarsController < ApplicationController
include UserScoped

before_action :check_deprecated_signature_image

def show
if small?
redirect_to @user.calendar_image.variant(:small)
else
redirect_to @user.calendar_image.variant(:large)
redirect_to @user.calendar_image
end
end

Expand All @@ -14,4 +16,10 @@ def show
def small?
params[:variant] == "small"
end

def check_deprecated_signature_image
return if @user.calendar_image.attached?

redirect_to @user.signature
end
end
7 changes: 0 additions & 7 deletions app/controllers/signatures_controller.rb

This file was deleted.

2 changes: 2 additions & 0 deletions app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class ApplicationJob < ActiveJob::Base
include UniqueJobs

retry_on(ActiveRecord::StatementInvalid, attempts: 3, wait: :polynomially_longer)
end
5 changes: 3 additions & 2 deletions app/jobs/user/periodic_mal_sync_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class User::PeriodicMALSyncJob < ApplicationJob
if user.legacy_account?
user.schedule_deactivation(reason: error.message)
Rails.logger.warn("Scheduled deactivation for user #{user.to_global_id}, reason: #{error}")
else
Rails.logger.error(error)
user.touch(:mal_synced_at)
end

Rails.error.report(error)
end

rescue_from MAL::Errors::CommunicationError do |exception|
Expand Down
1 change: 0 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class User < ApplicationRecord
include Mergeable
include Calendars
include CalendarImageable
include Signaturable
include Deactivatable
include Geolocatable

Expand Down
5 changes: 3 additions & 2 deletions app/models/user/calendar_imageable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ module User::CalendarImageable

included do
has_one_attached :calendar_image do |attachable|
attachable.variant :large, resize_to_limit: [1200, 180], preprocessed: true
attachable.variant :small, resize_to_limit: [600, 150], preprocessed: true
attachable.variant :small, resize_to_limit: [600, 150], saver: { quality: 100 }, preprocessed: true
end

has_one_attached :signature # Deprecated

after_create_commit :enqueue_calendar_images_generation
after_update_commit :enqueue_calendar_images_generation, if: -> { calendar_images.obsolete? }
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/user/calendar_images.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def obsolete?
class GenerateJob < ApplicationJob
retry_on(*BrowserSession::RETRYABLE_ERRORS, attempts: 10, wait: :polynomially_longer)

limits_concurrency to: 1, key: :screenshots, duration: 2.hours
limits_concurrency to: 2, key: :screenshots, duration: 2.hours

queue_as :screenshots

Expand Down
22 changes: 0 additions & 22 deletions app/models/user/signaturable.rb

This file was deleted.

82 changes: 0 additions & 82 deletions app/models/user/signaturable/signature_image.rb

This file was deleted.

11 changes: 6 additions & 5 deletions app/views/users/_bb_code.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<%# locals: (user:) -%>
<%# locals: (user:, label:, help:, variant: nil) -%>
<% template = "[URL=\"#{user_url(user)}\"][IMG]#{user_signature_url(user)}[/IMG][/URL]" %>
<% template = "[URL=\"#{user_url(user)}\"][IMG]#{user_images_calendar_url(user, variant: variant)}[/IMG][/URL]" %>

<div class="field is-horizontal" data-controller="clipboard">
<div class="is-half field is-vertical" data-controller="clipboard">
<div class="field-label is-normal has-text-left">
<%= label_tag(:bb_code, t(".label"), class: "label has-text-weight-medium") %>
<%= label_tag(:bb_code, label, class: "label has-text-weight-medium") %>
</div>
<div class="field-body">
<div class="field has-addons">
Expand All @@ -14,7 +14,7 @@
readonly: true,
class: "input signature-input",
data: { "clipboard-target" => "source" }) %>
<span class="icon is-small is-left"><i class="fas fa-code"></i></span>
<span class="icon is-small is-left"><i class="fas fa-code"></i></span>
</div>
<div class="control copy-signature">
<button class="button" data-action="clipboard#copy">
Expand All @@ -23,4 +23,5 @@
</div>
</div>
</div>
<p class="help is-secondary"><%= help %></p>
</div>
8 changes: 6 additions & 2 deletions app/views/users/_side_menu.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<nav class="panel is-primary">
<div class="panel-block is-flex-direction-column is-align-items-flex-start" style="row-gap: 5px">
<figure class="image is-64x64 is-align-self-center">
<img src="<%= Current.user.avatar_url %>" style="width: 100%; height: 100%; border-radius: 30px">
<figure class="image is-64x64 is-align-self-center has-text-centered">
<% if Current.user.avatar_url.present? %>
<%= image_tag Current.user.avatar_url, style: "object-fit: cover; width: 100%; height: 100%; border-radius: 30px" %>
<% else %>
<i class="fa fa-user-secret fa-3x mt-1" aria-hidden="true"></i>
<% end %>
</figure>
<span class="is-size-5"><%= Current.user.username %></span>
<span class="is-size-6"><i class="fa fa-map-marker" aria-hidden="true"></i> <%= Current.user.location.presence || _("Unknown") %></span>
Expand Down
37 changes: 19 additions & 18 deletions app/views/users/_user.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@
<% cache [user, calendar] do %>
<div class="columns is-multiline">
<div class="column is-full">
<article class="media">
<figure class="user-avatar media-left">
<p class="image is-96x96">
<img src="<%= user.avatar_url %>" alt="<%= _("User Avatar") %>">
</p>
</figure>
<div class="media-content">
<p>
<%= link_to(MAL::URLS.profile_url(user.username), target: "_blank", rel: "noopener noreferrer", class: "is-size-4") do %>
<%= user.username %>
<% end %>
</p>
<div class="bb-code pt-3">
<%= render partial: "users/bb_code", locals: { user: user } %>
</div>
</div>
</article>
<div class="column is-full p-0">
<div class="is-flex is-flex-direction-column is-justify-content-center is-align-content-center is-flex-wrap-wrap">
<%= link_to(MAL::URLS.profile_url(user.username), target: "_blank", rel: "noopener noreferrer", class: "image has-text-centered", style: "max-width: 255px; max-height: 350px; color: inherit") do %>
<% if user.avatar_url.present? %>
<%= image_tag user.avatar_url, style: "object-fit: cover;" %>
<% else %>
<i class="fa fa-user-secret fa-6x" aria-hidden="true"></i>
<% end %>
<% end %>
<%= link_to(MAL::URLS.profile_url(user.username), target: "_blank", rel: "noopener noreferrer", class: "is-size-4 has-text-centered") do %>
<%= user.username %>
<% end %>
</div>
</div>
<div class="column is-half">
<%= render partial: "users/bb_code", locals: { user: user, label: _("Large BB Code"), help: _("Ideal for profile page") } %>
</div>
<div class="column is-half">
<%= render partial: "users/bb_code", locals: { user: user, label: _("Small BB Code"), help: _("Ideal for forum signature"), variant: :small } %>
</div>
<%= turbo_frame_tag dom_id(user, :activities), class: "column is-full" do %>
<div class="columns is-multiline">
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<%= render partial: "shared/header", locals: { size: "sm" } %>

<div class="column is-full">
<div class="columns is-horizontal is-centered mt-6 is-variable">
<div class="columns is-horizontal is-centered mt-4 is-variable">
<% if signed_in? %>
<div class="column is-3">
<%= render partial: "users/side_menu" %>
Expand Down
7 changes: 3 additions & 4 deletions app/views/users/signature.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
.signature {
padding: 0.75em;
display: inline-grid;
background-color: transparent !important;
}
</style>
</head>
<body>
<div class="signature">
<%= render CalendarComponent.new(activities_amount_per_day: activities_amount_per_day) %>
</div>
<div class="signature">
<%= render CalendarComponent.new(activities_amount_per_day: activities_amount_per_day) %>
</div>
</body>
</html>
1 change: 0 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class Application < Rails::Application
config.action_dispatch.cookies_serializer = :json
config.filter_parameters += [:password]

config.cache_store = :solid_cache_store
config.session_store :cookie_store, expire_after: 1.week, key: "_malheatmap_session_v1"

config.crawler = config_for(:crawler)
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
get "/sessions/callback", to: "sessions#callback", as: "oauth_callback"

resources :users, only: :show, param: :username do
resource :signature, only: :show, on: :member
get "/signature", to: redirect("users/%{user_username}/images/calendar?variant=small")

resources :calendars, only: :show, on: :member, param: "year"
resources :timelines, only: :show, on: :member, param: "year"

Expand Down
12 changes: 0 additions & 12 deletions test/controllers/signatures_controller_test.rb

This file was deleted.

Loading

0 comments on commit 6c23bb7

Please sign in to comment.