Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bulma #14

Merged
merged 22 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added app/assets/images/house-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
94 changes: 0 additions & 94 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,97 +13,3 @@
*= require_tree .
*= require_self
*/

* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
min-height: 100vh;
font-family: proxima-nova, sans-serif;
font-style: normal;
font-weight: 400;
}

.navbar {
background-color: #3778c2;
width: 100%;
position: fixed;
top: 0;
z-index: 2;
}

.nav-link {
color: white;
}

.form-control:focus {
-webkit-box-shadow: none;
box-shadow: none;
}

.main {
position: relative;
top: 5rem;
margin-bottom: 10rem;
}

.add-btn {
background-color: #5fb523;
color: white;
position: fixed;
bottom: 0;
}

.add-btn:hover {
background-color: #5fb523;
color: white;
}

.card-image {
width: 20%;
}

.card-title {
font-family: lobster, sans-serif;
font-size: 4rem;
}

.lobster {
font-family: lobster, sans-serif;
font-size: 4rem;
}

.regular {
font-family: proxima-nova, sans-serif;
font-style: normal;
font-weight: 400;
}

.alert_msg {
color: red;
}

.notice_msg {
color: blue;
}

@media only screen and (min-width: 650px) {
.card-image img {
width: 60%;
}
}

@media only screen and (min-width: 800px) {
.card-image img {
width: 40%;
}
}

@media only screen and (min-width: 1100px) {
.card-image img {
width: 25%;
}
}
9 changes: 1 addition & 8 deletions app/controllers/categories_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
class CategoriesController < ApplicationController
before_action :set_category, only: %i[show edit update destroy]
before_action :authenticate_customer!
load_and_authorize_resource

# GET /categories or /categories.json
def index
customer = current_customer
@categories = customer.categories.all.order(created_at: :desc)
@categories = current_customer.categories.all.order(created_at: :desc)
end

# GET /categories/new
Expand All @@ -28,11 +26,6 @@ def create

private

# Use callbacks to share common setup or constraints between actions.
def set_category
@category = Category.find(params[:id])
end

# Only allow a list of trusted parameters through.
def category_params
params.require(:category).permit(:name, :icon)
Expand Down
19 changes: 8 additions & 11 deletions app/controllers/deals_controller.rb
Original file line number Diff line number Diff line change
@@ -1,41 +1,38 @@
class DealsController < ApplicationController
before_action :set_deal, only: %i[show edit update destroy]
before_action :set_category
before_action :authenticate_customer!
load_and_authorize_resource

# GET /deals or /deals.json
def index
@category = current_customer.categories.find(params[:category_id])
@deals = @category.deals.order(created_at: :desc)
@deals = @category.deals.distinct.order(created_at: :desc)
end

# GET /deals/new
def new
@category = current_customer.categories.find(params[:category_id])
@deal = Deal.new
@other_categories = current_customer.categories.where.not(id: @category)
@other_categories = current_customer.categories.where.not(id: params[:category_id])
end

# POST /deals or /deals.json
def create
@category = current_customer.categories.find(params[:category_id])
@deal = Deal.new(deal_params)
@deal.author = current_customer
@other_categories = current_customer.categories.where.not(id: @category)
categories = Category.where(id: params[:category_ids])
categories = Category.where(id: params[:deal][:category_ids])
@deal.categories.push(categories)
@deal.amount /= categories.size if categories.size > 1
if @deal.save
redirect_to category_deals_url(@category), notice: 'Transaction was successfully created.'
else
redirect_to category_deals_url(@category), notice: 'Unprocessable transaction.'
render :new, status: :unprocessable_entity
end
end

private

# Use callbacks to share common setup or constraints between actions.
def set_deal
@deal = Deal.find(params[:id])
def set_category
@category = current_customer.categories.find(params[:category_id])
end

# Only allow a list of trusted parameters through.
Expand Down
7 changes: 0 additions & 7 deletions app/javascript/controllers/hello_controller.js

This file was deleted.

11 changes: 11 additions & 0 deletions app/javascript/controllers/stimulus_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Controller } from "@hotwired/stimulus"

// Connects to data-controller="stimulus"
export default class extends Controller {
burger() {
const burger = document.querySelector(".navbar-burger");
const nav = document.querySelector("#"+burger.dataset.target);
burger.classList.toggle("is-active");
nav.classList.toggle("is-active");
}
}
24 changes: 12 additions & 12 deletions app/views/categories/_category.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<div class="card m-3">
<div class="d-flex justify-content-between align-items-center mx-2">
<div>
<%= image_tag(category.icon, alt: category.name, width: "50") %>
</div>
<div>
<div class="card-body p-0">
<h5 class="card-title"><%= link_to category.name, category_deals_path(category.id), class: "text-decoration-none align-middle fs-4 regular" %></h5>
<div class="card column is-one-fifth m-2">
<div class="card-content">
<div class="media">
<div class="media-left">
<figure class="image is-48x48">
<%= image_tag(category.icon, alt: category.name, width: "50") %>
</figure>
</div>
</div>
<div>
<div class="card-body p-0">
<p class="card-text fs-5 regular"><%= number_to_currency(category.deals.sum('amount'), unit: '$', precision: 2) %></p>
<div class="media-content">
<div>
<%= link_to category.name, category_deals_path(category.id), class: "title is-4" %>
</div>
<div class="subtitle is-6"><%= number_to_currency(category.deals.sum('amount'), unit: '$', precision: 2) %></div>
</div>
</div>
</div>
Expand Down
53 changes: 24 additions & 29 deletions app/views/categories/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,33 @@
'trekking', 'wedding', 'workspace', 'yoga'] %>

<%= form_with(model: category) do |form| %>
<nav class="navbar navbar-expand text-white px-3 mb-3 justify-content-between">
<div class="collapse navbar-collapse" id="navbarNav">
<div class="navbar-nav">
<%= link_to '&larr;'.html_safe, categories_path, class: "text-decoration-none text-white fs-2" %>
<%= form.submit "Save", class:"nav-link bg-transparent border-0 text-decoration-none mx-2" %>
</div>
</div>
<span class="navbar-brand mb-0 fs-4 text-white mx-3">ADD A CATEGORY</span>
</nav>

<div class="main">
<% if category.errors.any? %>
<div style="color: red">
<h2><%= pluralize(category.errors.count, "error") %> prohibited this category from being saved:</h2>
<% if category.errors.any? %>
<div style="color: red">
<h2><%= pluralize(category.errors.count, "error") %> prohibited this category from being saved:</h2>

<ul>
<% category.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="form-group">
<%= form.text_field :name, class: "form-control border-0 border-bottom rounded-0 mx-3 px-0 w-100", placeholder: "Category name" %>
<div class="form-check form-check-inline m-3">
<% icons.each do |icon| %>
<%= form.radio_button :icon, "#{icon}.png" %>
<%= form.label icon, image_tag("#{icon}.png", alt: icon, width: "50"), class: "form-check-label" %>
<ul>
<% category.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</div>
</ul>
</div>
<% end %>

<div class="field">
<%= form.label :name, class: "label" %>
<div class="control">
<%= form.text_field :name, class: "input", autofocus: true, autocomplete: "name" %>
</div>
</div>
<div class="field">
<% icons.each do |icon| %>
<%= form.radio_button :icon, "#{icon}.png" %>
<%= form.label :icon, image_tag("#{icon}.png", alt: icon, width: "50"), class: "form-check-label" %>
<% end %>
</div>

<div class="control actions buttons">
<%= form.submit "Save", class: "button is-link is-light" %>
<%= link_to "Back", categories_path, class: "button is-link is-light" %>
</div>
<% end %>
9 changes: 0 additions & 9 deletions app/views/categories/_header.html.erb

This file was deleted.

6 changes: 1 addition & 5 deletions app/views/categories/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<%= render "header" %>

<div class="main">
<div class="columns is-multiline">
<% @categories.each do |category| %>
<%= render category %>
<% end %>
</div>

<%= link_to "Add a new category", new_category_path, class: "btn add-btn rounded-0 p-3 w-100" %>
25 changes: 15 additions & 10 deletions app/views/deals/_deal.html.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
<div class="card m-3">
<div class="d-flex justify-content-between px-2">
<div>
<div class="card-body p-0">
<p class="card-title text-primary regular fs-4"><%= deal.name %></p>
<p class="card-text"><small class="text-muted"><%= deal.created_at.strftime('%d %b %Y') %></small></p>
<div class="card column is-one-fifth m-2">
<div class="card-content">
<div class="media">
<div class="media-content">
<div class="title is-4"><%= deal.name %></div>
<div class="subtitle is-6"><%= deal.created_at.strftime('%d %b %Y') %></div>
</div>
</div>
<div class="align-self-center">
<div class="card-body p-0">
<p class="card-text regular fs-5"><%= number_to_currency(deal.amount, unit: '$', precision: 2) %></p>
</div>

<div>
<% deal.categories.distinct.each do |category| %>
<%= image_tag(category.icon, width: "25") %>
<% end %>
</div>

<div class="content">
<%= number_to_currency(deal.amount, unit: '$', precision: 2) %>
</div>
</div>
</div>
Loading