-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ab-noori/home
Home (Categories) page.
- Loading branch information
Showing
17 changed files
with
278 additions
and
9 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,34 @@ | ||
class CategoriesController < ApplicationController | ||
before_action :authenticate_user! | ||
|
||
def index | ||
@categories = Category.all | ||
end | ||
|
||
def show | ||
@category = Category.find(params[:id]) | ||
end | ||
|
||
def new | ||
@category = Category.new | ||
end | ||
|
||
def create | ||
@category = Category.new(category_params) | ||
@category.user = current_user | ||
|
||
if @category.save | ||
redirect_to categories_path, notice: 'Category created successfully.' | ||
else | ||
flash.now[:alert] = 'Error creating category:' | ||
flash.now[:alert_details] = @category.errors.full_messages.join(', ') | ||
render :new | ||
end | ||
end | ||
|
||
private | ||
|
||
def category_params | ||
params.require(:category).permit(:name, :icon) | ||
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
class SplashController < ApplicationController | ||
skip_before_action :authenticate_user!, only: [:index] | ||
|
||
def index; end | ||
def index | ||
redirect_to authenticated_root_path if user_signed_in? | ||
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,2 @@ | ||
module CategoriesHelper | ||
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
class Category < ApplicationRecord | ||
belongs_to :user | ||
has_many :expense_category_associations | ||
has_one_attached :icon, dependent: :destroy | ||
has_many :expenses, through: :expense_category_associations | ||
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,52 @@ | ||
<%= render partial: 'layouts/shared/navbar', locals: { back_destination: '', page_name: 'Categories', link: { destination: destroy_user_session_path, label: 'Log Out' } } %> | ||
<%= render partial: "layouts/shared/messages" %> | ||
|
||
<div class="container position-relative" style="min-height: 100vh;"> | ||
<div class="row"> | ||
<% @categories.each do |category| %> | ||
<div class="col-12"> | ||
<%= link_to category_path(category), class: "nav-link" do %> | ||
<div class="card"> | ||
<div class="row no-gutters align-items-center"> | ||
<div class="col-md-2 col-4"> | ||
<div class="card-body"> | ||
<% if category.icon.attached? %> | ||
<%= image_tag category.icon, style: 'width: 80px; height: 80px;', class: 'img-fluid rounded' %> | ||
<% else %> | ||
<div class="text-center"> | ||
No Icon Available | ||
</div> | ||
<% end %> | ||
</div> | ||
</div> | ||
<div class="col-md-8 col-5 p-0"> | ||
<div class="card-body text-secondary"> | ||
<h4 class="card-title"><%= category.name %></h4> | ||
<p class="mb-0"><%= category.created_at.strftime("%d %b %Y %H:%M") %></p> <!-- Formatted date --> | ||
</div> | ||
</div> | ||
<div class="col-md-2 col-3 text-md-center"> | ||
<div class="card-body text-dark font-weight-bold p-0 p-md-2"> | ||
<!-- Include the total for the category here --> | ||
<h5 class="text-nowrap">$1500</h5> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
</div> | ||
|
||
<div class="sticky-bottom mb-2"> | ||
<div class="container"> | ||
<div class="row"> | ||
<div class="col-md-6 offset-md-3"> | ||
<div class="d-grid gap-1"> | ||
<%= link_to "Add new category", new_category_path, class: "btn btn-success btn-lg mb-1" %> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</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,30 @@ | ||
<%= render partial: 'layouts/shared/navbar', locals: { back_destination: root_path, page_name: 'New Category', link: { destination: destroy_user_session_path, label: 'Log Out' } } %> | ||
|
||
<div class="container mt-4"> | ||
<div class="row justify-content-center"> | ||
<div class="col-md-6"> | ||
<div class="card"> | ||
<div class="card-header"> | ||
New Category | ||
</div> | ||
<div class="card-body"> | ||
<%= form_with(model: @category, url: categories_path, method: :post) do |form| %> | ||
<div class="mb-3"> | ||
<%= form.label :name, class: "form-label" %> | ||
<%= form.text_field :name, class: "form-control" %> | ||
</div> | ||
|
||
<div class="mb-3"> | ||
<%= form.label :icon, class: "form-label" %> | ||
<%= form.file_field :icon, class: "form-control" %> | ||
</div> | ||
|
||
<div class="text-center"> | ||
<%= form.submit 'Save', class: "btn btn-primary" %> | ||
</div> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</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 @@ | ||
<%= render partial: 'layouts/shared/navbar', locals: { back_destination: root_path, page_name: 'Transactions', link: { destination: destroy_user_session_path, label: 'Log Out' } } %> | ||
|
||
<div class="container"> | ||
<div class="row"> | ||
<div class="card"> | ||
<div class="row no-gutters align-items-center"> | ||
<div class="col-md-2 col-4"> | ||
<div class="card-body"> | ||
<% if @category.icon.attached? %> | ||
<%= image_tag @category.icon, style: 'width: 80px; height: 80px;', class: 'img-fluid rounded' %> | ||
<% else %> | ||
<div class="text-center"> | ||
No Icon Available | ||
</div> | ||
<% end %> | ||
</div> | ||
</div> | ||
<div class="col-md-8 col-5 p-0"> | ||
<div class="card-body text-secondary"> | ||
<h4 class="card-title"><%= @category.name %></h4> | ||
<p class="mb-0"><%= @category.created_at.strftime("%d %b %Y %H:%M") %></p> <!-- Formatted date --> | ||
</div> | ||
</div> | ||
<div class="col-md-2 col-3 text-md-center"> | ||
<div class="card-body text-dark font-weight-bold p-0 p-md-2"> | ||
<!-- Include the total for the category here --> | ||
<h5 class="text-nowrap">$1500</h5> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</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
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 |
---|---|---|
|
@@ -14,9 +14,8 @@ | |
</head> | ||
|
||
<body> | ||
<%= render partial: "layouts/shared/messages" %> | ||
<%= yield %> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script> | ||
</body> | ||
|
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,6 +1,13 @@ | ||
Rails.application.routes.draw do | ||
devise_for :users | ||
|
||
resources :users | ||
root "splash#index" | ||
resources :categories do | ||
resources :expenses | ||
end | ||
|
||
authenticated :user do | ||
root 'categories#index', as: :authenticated_root | ||
end | ||
|
||
root 'splash#index' | ||
end |
57 changes: 57 additions & 0 deletions
57
db/migrate/20230920122901_create_active_storage_tables.active_storage.rb
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,57 @@ | ||
# This migration comes from active_storage (originally 20170806125915) | ||
class CreateActiveStorageTables < ActiveRecord::Migration[5.2] | ||
def change | ||
# Use Active Record's configured type for primary and foreign keys | ||
primary_key_type, foreign_key_type = primary_and_foreign_key_types | ||
|
||
create_table :active_storage_blobs, id: primary_key_type do |t| | ||
t.string :key, null: false | ||
t.string :filename, null: false | ||
t.string :content_type | ||
t.text :metadata | ||
t.string :service_name, null: false | ||
t.bigint :byte_size, null: false | ||
t.string :checksum | ||
|
||
if connection.supports_datetime_with_precision? | ||
t.datetime :created_at, precision: 6, null: false | ||
else | ||
t.datetime :created_at, null: false | ||
end | ||
|
||
t.index [ :key ], unique: true | ||
end | ||
|
||
create_table :active_storage_attachments, id: primary_key_type do |t| | ||
t.string :name, null: false | ||
t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type | ||
t.references :blob, null: false, type: foreign_key_type | ||
|
||
if connection.supports_datetime_with_precision? | ||
t.datetime :created_at, precision: 6, null: false | ||
else | ||
t.datetime :created_at, null: false | ||
end | ||
|
||
t.index [ :record_type, :record_id, :name, :blob_id ], name: :index_active_storage_attachments_uniqueness, unique: true | ||
t.foreign_key :active_storage_blobs, column: :blob_id | ||
end | ||
|
||
create_table :active_storage_variant_records, id: primary_key_type do |t| | ||
t.belongs_to :blob, null: false, index: false, type: foreign_key_type | ||
t.string :variation_digest, null: false | ||
|
||
t.index [ :blob_id, :variation_digest ], name: :index_active_storage_variant_records_uniqueness, unique: true | ||
t.foreign_key :active_storage_blobs, column: :blob_id | ||
end | ||
end | ||
|
||
private | ||
def primary_and_foreign_key_types | ||
config = Rails.configuration.generators | ||
setting = config.options[config.orm][:primary_key_type] | ||
primary_key_type = setting || :primary_key | ||
foreign_key_type = setting || :bigint | ||
[primary_key_type, foreign_key_type] | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
require 'test_helper' | ||
|
||
class CategoriesControllerTest < ActionDispatch::IntegrationTest | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |