Skip to content

Commit

Permalink
Merge pull request #6 from Zilola-Nazarova/views
Browse files Browse the repository at this point in the history
Views
  • Loading branch information
Zilola-Nazarova authored Nov 20, 2023
2 parents a964a7d + 291c092 commit 0cfd41c
Show file tree
Hide file tree
Showing 14 changed files with 3,389 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@

# Ignore master key for decrypting credentials and more.
/config/master.key

/node_modules/
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ gem 'devise'
# For authorization
gem 'cancancan'

# For inline_svg_tag
gem 'inline_svg'

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem 'database_cleaner'
Expand Down
10 changes: 10 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ GEM
ruby2_keywords
erubi (1.12.0)
ffi (1.16.3)
font-awesome-rails (4.7.0.8)
railties (>= 3.2, < 8.0)
font-awesome-sass (6.4.2)
sassc (~> 2.0)
globalid (1.2.1)
activesupport (>= 6.1)
i18n (1.14.1)
Expand All @@ -129,6 +133,9 @@ GEM
actionpack (>= 6.0.0)
activesupport (>= 6.0.0)
railties (>= 6.0.0)
inline_svg (1.9.0)
activesupport (>= 3.0)
nokogiri (>= 1.6)
io-console (0.6.0)
irb (1.9.0)
rdoc
Expand Down Expand Up @@ -321,7 +328,10 @@ DEPENDENCIES
database_cleaner
debug
devise
font-awesome-rails
font-awesome-sass (~> 6.4.2)
importmap-rails
inline_svg
jbuilder
jwt
pg (~> 1.1)
Expand Down
3 changes: 3 additions & 0 deletions app/assets/images/chevron_left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@
*= require_tree .
*= require_self
*/

.chevron {
width: 2rem;
height: 2rem;
color: black;
}
11 changes: 9 additions & 2 deletions app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class GroupsController < ApplicationController
def index; end
def index
@groups = current_user.groups
end

def show; end

Expand All @@ -9,5 +11,10 @@ def edit; end

def update; end

def delete; end
def destroy
@group = Group.find(params[:id])
@group.destroy!
flash[:success] = 'Category was deleted successfully!'
redirect_to groups_url
end
end
16 changes: 13 additions & 3 deletions app/controllers/purchases_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
class PurchasesController < ApplicationController
def index; end
def index
@group = Group.find(params[:group_id])
@purchases = @group.purchases.order(id: :desc)
end

def show; end
def show
@purchase = Purchase.find(params[:id])
end

def new; end

def edit; end

def update; end

def delete; end
def destroy
@purchase = Purchase.find(params[:id])
@purchase.destroy!
flash[:success] = 'Transaction was deleted successfully!'
redirect_to group_purchases_url(params[:group_id])
end
end
5 changes: 5 additions & 0 deletions app/helpers/group_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module GroupHelper
def total_amount(group)
group.purchases.sum(:amount)
end
end
5 changes: 5 additions & 0 deletions app/views/devise/registrations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= render "devise/shared/error_messages", resource: resource %>

<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name, autofocus: true, autocomplete: "name" %>
</div>

<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>
Expand Down
24 changes: 23 additions & 1 deletion app/views/groups/index.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
<h1>List groups</h1>
<section>
<h1>categories</h1>
</section>

<section>
<ul>
<% @groups.each do |group| %>
<% total_amount = total_amount(group) %>
<li>
<%= link_to group_purchases_url(group) do %>
<%= image_tag(group.icon, height: '32', width: '32', class: 'icon', alt: 'group_icon') %>
<span><%= group.name %></span>
<br>
<span>Transactions: <%= total_amount %></span>
<% end %>
</li>
<% end %>
</ul>
</section>

<section>
<%= link_to "add category", new_group_path %>
</section>
33 changes: 32 additions & 1 deletion app/views/purchases/index.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
<h1>List purchases</h1>
<section>
<%= link_to groups_path do %>
<%= inline_svg_tag "chevron_left.svg", class: "chevron" %>
<% end %>
<h1>transactions</h1>
</section>

<section>
<div>
<span><%= @group.name %></span>
<span>Total amount: <%= total_amount(@group) %> </span>
</div>

<% if @purchases.empty? %>
<%= button_to "delete", {:controller => :groups, :action => 'destroy', :id => @group.id }, :method => :delete %>
<% end %>

<ul>
<% @purchases.each do |purchase| %>
<li>
<%= link_to group_purchase_url(@group, purchase) do %>
<span><%= purchase.name %></span>
<span><%= purchase.amount %></span>
<% end %>
</li>
<% end %>
</ul>
</section>

<section>
<%= link_to "add transaction", new_group_purchase_path %>
</section>
16 changes: 15 additions & 1 deletion app/views/purchases/show.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
<h1>Show purchase details</h1>
<section>
<%= link_to group_purchases_path(params[:group_id]) do %>
<%= inline_svg_tag "chevron_left.svg", class: "chevron" %>
<% end %>
<h1>details</h1>
</section>

<section>
<span><%= @purchase.name %></span>
<span><%= @purchase.amount %></span>

<section>
<%= link_to "edit", edit_group_purchase_path(params[:group_id], @purchase) %>
<%= button_to "delete", {:controller => :purchases, :action => 'destroy'}, method: :delete %>
</section>
Loading

0 comments on commit 0cfd41c

Please sign in to comment.