-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Repro * Fix * Update signage * Create tagging system * Add tags to transaction imports * Build tagging UI * Cleanup * More cleanup
- Loading branch information
Showing
38 changed files
with
607 additions
and
90 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class Tags::DeletionsController < ApplicationController | ||
layout "with_sidebar" | ||
|
||
before_action :set_tag | ||
before_action :set_replacement_tag, only: :create | ||
|
||
def new | ||
end | ||
|
||
def create | ||
@tag.replace_and_destroy! @replacement_tag | ||
redirect_back_or_to tags_path, notice: t(".deleted") | ||
end | ||
|
||
private | ||
|
||
def set_tag | ||
@tag = Current.family.tags.find_by(id: params[:tag_id]) | ||
end | ||
|
||
def set_replacement_tag | ||
@replacement_tag = Current.family.tags.find_by(id: params[:replacement_tag_id]) | ||
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,36 @@ | ||
class TagsController < ApplicationController | ||
layout "with_sidebar" | ||
|
||
before_action :set_tag, only: %i[ edit update ] | ||
|
||
def index | ||
@tags = Current.family.tags.alphabetically | ||
end | ||
|
||
def new | ||
@tag = Current.family.tags.new color: Tag::COLORS.sample | ||
end | ||
|
||
def create | ||
Current.family.tags.create!(tag_params) | ||
redirect_to tags_path, notice: t(".created") | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def update | ||
@tag.update!(tag_params) | ||
redirect_to tags_path, notice: t(".updated") | ||
end | ||
|
||
private | ||
|
||
def set_tag | ||
@tag = Current.family.tags.find(params[:id]) | ||
end | ||
|
||
def tag_params | ||
params.require(:tag).permit(:name, :color) | ||
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,7 @@ | ||
module TagsHelper | ||
def null_tag | ||
Tag.new \ | ||
name: "Uncategorized", | ||
color: Tag::UNCATEGORIZED_COLOR | ||
end | ||
end |
4 changes: 2 additions & 2 deletions
4
...ntrollers/category_deletion_controller.js → ...script/controllers/deletion_controller.js
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class Tag < ApplicationRecord | ||
belongs_to :family | ||
has_many :taggings, dependent: :destroy | ||
has_many :transactions, through: :taggings, source: :taggable, source_type: "Transaction" | ||
|
||
validates :name, presence: true, uniqueness: { scope: :family } | ||
|
||
scope :alphabetically, -> { order(:name) } | ||
|
||
COLORS = %w[#e99537 #4da568 #6471eb #db5a54 #df4e92 #c44fe9 #eb5429 #61c9ea #805dee #6ad28a] | ||
|
||
UNCATEGORIZED_COLOR = "#737373" | ||
|
||
def replace_and_destroy!(replacement) | ||
transaction do | ||
raise ActiveRecord::RecordInvalid, "Replacement tag cannot be the same as the tag being destroyed" if replacement == self | ||
|
||
if replacement | ||
taggings.update_all tag_id: replacement.id | ||
end | ||
|
||
destroy! | ||
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,4 @@ | ||
class Tagging < ApplicationRecord | ||
belongs_to :tag | ||
belongs_to :taggable, polymorphic: true | ||
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<%# locals: (tag:) %> | ||
<% tag ||= null_category %> | ||
|
||
<span class="border text-sm font-medium px-2.5 py-1 rounded-full content-center" | ||
style=" | ||
background-color: color-mix(in srgb, <%= tag.color %> 5%, white); | ||
border-color: color-mix(in srgb, <%= tag.color %> 10%, white); | ||
color: <%= tag.color %>;"> | ||
<%= tag.name %> | ||
</span> |
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,38 @@ | ||
<%= form_with model: tag, data: { turbo: false } do |form| %> | ||
<div class="flex flex-col space-y-4 w-96" data-controller="color-select" data-color-select-selection-value="<%= tag.color %>"> | ||
<fieldset class="relative"> | ||
<span data-color-select-target="decoration" class="pointer-events-none absolute inset-y-3.5 left-3 flex items-center pl-1 block w-1 rounded-lg"></span> | ||
<%= form.text_field :name, | ||
value: tag.name, | ||
autofocus: "", | ||
required: true, | ||
placeholder: "Enter tag name", | ||
class: "rounded-lg w-full focus:ring-black focus:border-transparent placeholder:text-gray-500 pl-6" %> | ||
</fieldset> | ||
|
||
<fieldset> | ||
<%= form.hidden_field :color, data: { color_select_target: "input" } %> | ||
|
||
<ul role="radiogroup" class="flex justify-between items-center py-2"> | ||
<% Tag::COLORS.each do |color| %> | ||
<li tabindex="0" | ||
role="radio" | ||
data-action="click->color-select#select keydown.enter->color-select#select keydown.space->color-select#select" | ||
data-value="<%= color %>" | ||
class="flex shrink-0 justify-center items-center w-5 h-5 cursor-pointer hover:bg-gray-200 rounded-full"> | ||
</li> | ||
<% end %> | ||
</ul> | ||
</fieldset> | ||
|
||
<section> | ||
<%= hidden_field_tag :tag_id, params[:tag_id] %> | ||
|
||
<% if tag.persisted? %> | ||
<%= form.submit t(".update") %> | ||
<% else %> | ||
<%= form.submit t(".create") %> | ||
<% end %> | ||
</section> | ||
</div> | ||
<% 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,23 @@ | ||
<div id="<%= dom_id(tag) %>" class="flex justify-between mx-4 py-5 border-b last:border-b-0 border-alpha-black-50"> | ||
<%= render "badge", tag: tag %> | ||
|
||
<%= contextual_menu do %> | ||
<div class="w-48 p-1 text-sm leading-6 text-gray-900 bg-white shadow-lg shrink rounded-xl ring-1 ring-gray-900/5"> | ||
<%= link_to edit_tag_path(tag), | ||
class: "block w-full py-2 px-3 space-x-2 text-gray-900 hover:bg-gray-50 flex items-center rounded-lg", | ||
data: { turbo_frame: :modal } do %> | ||
<%= lucide_icon "pencil-line", class: "w-5 h-5 text-gray-500" %> | ||
|
||
<span><%= t(".edit") %></span> | ||
<% end %> | ||
|
||
<%= link_to new_tag_deletion_path(tag), | ||
class: "block w-full py-2 px-3 space-x-2 text-red-600 hover:bg-red-50 flex items-center rounded-lg", | ||
data: { turbo_frame: :modal } do %> | ||
<%= lucide_icon "trash-2", class: "w-5 h-5" %> | ||
|
||
<span><%= t(".delete") %></span> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
</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,33 @@ | ||
<%= modal do %> | ||
<article class="mx-auto p-4 w-screen max-w-md"> | ||
<div class="space-y-2"> | ||
<header class="flex justify-between"> | ||
<h2 class="font-medium text-xl"><%= t(".delete_tag") %></h2> | ||
<%= lucide_icon "x", class: "w-5 h-5 text-gray-500", data: { action: "click->modal#close" } %> | ||
</header> | ||
|
||
<p class="text-gray-500 font-light"> | ||
<%= t(".explanation", tag_name: @tag.name) %> | ||
</p> | ||
</div> | ||
|
||
<%= form_with url: tag_deletions_path(@tag), | ||
data: { | ||
turbo: false, | ||
controller: "deletion", | ||
deletion_dangerous_action_class: "form-field__submit bg-white text-red-600 border hover:bg-red-50", | ||
deletion_safe_action_class: "form-field__submit border border-transparent", | ||
deletion_submit_text_when_not_replacing_value: t(".delete_and_leave_uncategorized", tag_name: @tag.name), | ||
deletion_submit_text_when_replacing_value: t(".delete_and_recategorize", tag_name: @tag.name) } do |f| %> | ||
<%= f.collection_select :replacement_tag_id, | ||
Current.family.tags.alphabetically.without(@tag), | ||
:id, :name, | ||
{ prompt: t(".replacement_tag_prompt"), label: t(".tag") }, | ||
{ data: { deletion_target: "replacementField", action: "deletion#updateSubmitButton" } } %> | ||
|
||
<%= f.submit t(".delete_and_leave_uncategorized", tag_name: @tag.name), | ||
class: "form-field__submit bg-white text-red-600 border hover:bg-red-50", | ||
data: { deletion_target: "submitButton" } %> | ||
<% end %> | ||
</article> | ||
<% 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,10 @@ | ||
<%= modal do %> | ||
<article class="mx-auto w-full p-4 space-y-4"> | ||
<header class="flex justify-between"> | ||
<h2 class="font-medium text-xl"><%= t(".edit") %></h2> | ||
<%= lucide_icon "x", class: "w-5 h-5 text-gray-500", data: { action: "click->modal#close" } %> | ||
</header> | ||
|
||
<%= render "form", tag: @tag %> | ||
</article> | ||
<% end %> |
Oops, something went wrong.