From be21d2b4fdfcf3cf46d28f93272441f085ff63ef Mon Sep 17 00:00:00 2001 From: Josh Brown Date: Thu, 25 Apr 2024 15:32:45 +0100 Subject: [PATCH] Refactor placeholder logo into common controller (#673) This can be updated to redirect/pull from third party sources in future, with the option of always falling back to the placeholder if there are any failures. --- app/controllers/accounts/logos_controller.rb | 10 +++++++++ app/helpers/accounts_helper.rb | 22 +++++++++++-------- app/views/accounts/logos/show.svg.erb | 21 ++++++++++++++++++ app/views/accounts/show.html.erb | 4 +--- app/views/pages/_account_group_disclosure.erb | 4 +--- app/views/pages/dashboard.html.erb | 12 +++------- config/routes.rb | 1 + 7 files changed, 50 insertions(+), 24 deletions(-) create mode 100644 app/controllers/accounts/logos_controller.rb create mode 100644 app/views/accounts/logos/show.svg.erb diff --git a/app/controllers/accounts/logos_controller.rb b/app/controllers/accounts/logos_controller.rb new file mode 100644 index 00000000..8e8c5092 --- /dev/null +++ b/app/controllers/accounts/logos_controller.rb @@ -0,0 +1,10 @@ +class Accounts::LogosController < ApplicationController + def show + @account = Current.family.accounts.find(params[:account_id]) + render_placeholder + end + + def render_placeholder + render formats: :svg + end +end diff --git a/app/helpers/accounts_helper.rb b/app/helpers/accounts_helper.rb index 0e8b2643..0907f0ac 100644 --- a/app/helpers/accounts_helper.rb +++ b/app/helpers/accounts_helper.rb @@ -19,18 +19,22 @@ module AccountsHelper class_mapping(accountable_type)[:bg_transparent] end + def accountable_color(accountable_type) + class_mapping(accountable_type)[:hex] + end + private def class_mapping(accountable_type) { - "Account::Credit" => { text: "text-red-500", bg: "bg-red-500", bg_transparent: "bg-red-500/10", fill: "fill-red-500" }, - "Account::Loan" => { text: "text-fuchsia-500", bg: "bg-fuchsia-500", bg_transparent: "bg-fuchsia-500/10", fill: "fill-fuchsia-500" }, - "Account::OtherLiability" => { text: "text-gray-500", bg: "bg-gray-500", bg_transparent: "bg-gray-500/10", fill: "fill-gray-500" }, - "Account::Depository" => { text: "text-violet-500", bg: "bg-violet-500", bg_transparent: "bg-violet-500/10", fill: "fill-violet-500" }, - "Account::Investment" => { text: "text-blue-600", bg: "bg-blue-600", bg_transparent: "bg-blue-600/10", fill: "fill-blue-600" }, - "Account::OtherAsset" => { text: "text-green-500", bg: "bg-green-500", bg_transparent: "bg-green-500/10", fill: "fill-green-500" }, - "Account::Property" => { text: "text-cyan-500", bg: "bg-cyan-500", bg_transparent: "bg-cyan-500/10", fill: "fill-cyan-500" }, - "Account::Vehicle" => { text: "text-pink-500", bg: "bg-pink-500", bg_transparent: "bg-pink-500/10", fill: "fill-pink-500" } - }.fetch(accountable_type, { text: "text-gray-500", bg: "bg-gray-500", bg_transparent: "bg-gray-500/10", fill: "fill-gray-500" }) + "Account::Credit" => { text: "text-red-500", bg: "bg-red-500", bg_transparent: "bg-red-500/10", fill: "fill-red-500", hex: "#F13636" }, + "Account::Loan" => { text: "text-fuchsia-500", bg: "bg-fuchsia-500", bg_transparent: "bg-fuchsia-500/10", fill: "fill-fuchsia-500", hex: "#D444F1" }, + "Account::OtherLiability" => { text: "text-gray-500", bg: "bg-gray-500", bg_transparent: "bg-gray-500/10", fill: "fill-gray-500", hex: "#737373" }, + "Account::Depository" => { text: "text-violet-500", bg: "bg-violet-500", bg_transparent: "bg-violet-500/10", fill: "fill-violet-500", hex: "#875BF7" }, + "Account::Investment" => { text: "text-blue-600", bg: "bg-blue-600", bg_transparent: "bg-blue-600/10", fill: "fill-blue-600", hex: "#1570EF" }, + "Account::OtherAsset" => { text: "text-green-500", bg: "bg-green-500", bg_transparent: "bg-green-500/10", fill: "fill-green-500", hex: "#12B76A" }, + "Account::Property" => { text: "text-cyan-500", bg: "bg-cyan-500", bg_transparent: "bg-cyan-500/10", fill: "fill-cyan-500", hex: "#06AED4" }, + "Account::Vehicle" => { text: "text-pink-500", bg: "bg-pink-500", bg_transparent: "bg-pink-500/10", fill: "fill-pink-500", hex: "#F23E94" } + }.fetch(accountable_type, { text: "text-gray-500", bg: "bg-gray-500", bg_transparent: "bg-gray-500/10", fill: "fill-gray-500", hex: "#737373" }) end end diff --git a/app/views/accounts/logos/show.svg.erb b/app/views/accounts/logos/show.svg.erb new file mode 100644 index 00000000..19186e26 --- /dev/null +++ b/app/views/accounts/logos/show.svg.erb @@ -0,0 +1,21 @@ + diff --git a/app/views/accounts/show.html.erb b/app/views/accounts/show.html.erb index e77469ef..f2b041df 100644 --- a/app/views/accounts/show.html.erb +++ b/app/views/accounts/show.html.erb @@ -2,9 +2,7 @@
-
- <%= @account.name[0].upcase %> -
+ <%= image_tag account_logo_url(@account), class: "w-8 h-8" %>

<%= @account.name %>

diff --git a/app/views/pages/_account_group_disclosure.erb b/app/views/pages/_account_group_disclosure.erb index 28e08489..6fc6f7e9 100644 --- a/app/views/pages/_account_group_disclosure.erb +++ b/app/views/pages/_account_group_disclosure.erb @@ -25,9 +25,7 @@ <% accountable_group.children.map do |account_value_node| %>
-
- <%= account_value_node.name[0].upcase %> -
+ <%= image_tag account_logo_url(account_value_node.original), class: "w-8 h-8" %>

<%= account_value_node.name %>

diff --git a/app/views/pages/dashboard.html.erb b/app/views/pages/dashboard.html.erb index 8d1d1937..53d658f4 100644 --- a/app/views/pages/dashboard.html.erb +++ b/app/views/pages/dashboard.html.erb @@ -54,9 +54,7 @@
<% @top_earners.first(3).each do |account| %> <%= link_to account, class: "border border-alpha-black-25 rounded-full p-1 pr-2 flex items-center gap-1 text-xs text-gray-900 font-medium hover:bg-gray-25" do %> -
- <%= account.name[0].upcase %> -
+ <%= image_tag account_logo_url(account), class: "w-5 h-5" %> +<%= Money.new(account.income, account.currency) %> <% end %> <% end %> @@ -88,9 +86,7 @@
<% @top_spenders.first(3).each do |account| %> <%= link_to account, class: "border border-alpha-black-25 rounded-full p-1 pr-2 flex items-center gap-1 text-xs text-gray-900 font-medium hover:bg-gray-25" do %> -
- <%= account.name[0].upcase %> -
+ <%= image_tag account_logo_url(account), class: "w-5 h-5" %> -<%= Money.new(account.spending, account.currency) %> <% end %> <% end %> @@ -123,9 +119,7 @@
<% @top_savers.first(3).each do |account| %> <%= link_to account, class: "border border-alpha-black-25 rounded-full p-1 pr-2 flex items-center gap-1 text-xs text-gray-900 font-medium hover:bg-gray-25" do %> -
- <%= account.name[0].upcase %> -
+ <%= image_tag account_logo_url(account), class: "w-5 h-5" %> <%= account.savings_rate > 0 ? "+" : "-" %><%= number_to_percentage(account.savings_rate.abs * 100, precision: 2) %> <% end %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index dd3407c2..4e17db3c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -35,6 +35,7 @@ Rails.application.routes.draw do resources :accounts, shallow: true do get :summary, on: :collection post :sync, on: :member + resource :logo, only: %i[show], module: :accounts resources :valuations end