Commit dc2de209 authored by Chanelle Lunod's avatar Chanelle Lunod

initial commit

parents 20ac6df5 d5c4efc5
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
// Place all the styles related to the Comments controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
// Place all the styles related to the Orders controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
// Place all the styles related to the Supplies controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
......@@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base
def after_sign_in_path_for(resource)
if resource.is_a?(AdminUser)
authenticated_admin_user_root_url
elsif resource.is_a?(User)
else resource.is_a?(User)
authenticated_user_root_url
end
#authenticated_root_url
......@@ -14,12 +14,6 @@ class ApplicationController < ActionController::Base
end
def after_sign_out_path_for(resource)
if resource == :user
new_user_session_path
elsif resource == :admin_user
new_admin_user_session_path
else
root_path
end
end
end
\ No newline at end of file
class CommentsController < ApplicationController
def new
end
end
class OrdersController < ApplicationController
def new
@order = Order.new
end
def create
@order = Order.new(product_params)
if @order.save
redirect_to products_path, notice: "You have successfully placed a new order"
else
render 'new'
end
end
def show
if params [:status] == "activated"
@products = Product.activated
else
@products = Product.inactivated
end
end
end
......@@ -3,8 +3,6 @@ class ProductsController < ApplicationController
def index
@products = Product.all
#if @product.status == active
#else
end
def show
......@@ -39,6 +37,10 @@ class ProductsController < ApplicationController
end
end
def count
@products.count
end
private
def product_params
params.require(:product).permit!
......
class SuppliesController < ApplicationController
def index
if params [:status] == "activated"
@products = Product.activated
else
@products = Product.inactivated
end
end
def new
@supply = Supply.new
end
def create
@supply = Supply.new(product_params)
if @supply.save
redirect_to products_path, notice: "You have successfully added a new supply."
else
render 'new'
end
end
end
......@@ -6,7 +6,7 @@ class TransactionsController < ApplicationController
end
def display
@product = Product.find_by(id: params[:id])
@product = Product.find_by(product_id: params[:product_id])
end
def new
......
class UsersController < ApplicationController
before_action :authenticate_user!
def index
end
end
module CommentsHelper
end
module OrdersHelper
end
module SuppliesHelper
end
class Comment < ApplicationRecord
belongs_to :user
belongs_to :post
end
class Transaction < ApplicationRecord
belongs_to :product
belongs_to :user
end
......@@ -4,14 +4,14 @@ class User < ApplicationRecord
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# has_many :transactions
# has_many :comments
# def to_s
# if first_name && last_name
# "#{first_name} #{last_name}"
# else
# email
# end
# end
has_many :transactions
has_many :comments
def to_s
if first_name && last_name
"#{first_name} #{last_name}"
else
email
end
end
end
<h1>Comments#new</h1>
<p>Find me in app/views/comments/new.html.erb</p>
<h1>New Order</h1>
<%= simple_form_for @order do |f| %>
<%= f.input :name %>
<%= f.input :description, as: :text %>
<%= f.input :quantity, as: :integer %>
<%= f.button :submit, "Add Order", class: "btn btn-primary" %>
<%= link_to "Back", products_path, class: "btn btn-default" %>
<% end %>
......@@ -33,6 +33,9 @@
</td>
<td>
<%= time_ago_in_words(product.created_at) %> ago
</td>
<td>
<%= link_to "Add Comment", new_post_comment_path(post), class: "btn btn-info" %>
</td>
<td>
<%= link_to "Edit", edit_product_path(product), class: "btn btn-primary" %>
......
......@@ -5,7 +5,6 @@
<%= simple_form_for :admin_user, url: session_path(:admin_user) do |f| %>
<%= f.input :email %>
<%= f.input :password %>
<%= f.input :password_confirmation %>
<%= f.button :submit, "Log In" %>
<% end %>
</div>
......@@ -15,7 +14,6 @@
<%= simple_form_for :user, url: session_path(:user) do |f| %>
<%= f.input :email %>
<%= f.input :password %>
<%= f.input :password_confirmation %>
<%= f.button :submit, "Log In" %>
<%= link_to "Sign Up", new_user_registration_path, :class => 'navbar-link' %>
<% end %>
......
<h1>Supplies</h1>
<div>
<%= link_to "Add New Supply", new_supply_path, class: "btn btn-primary" %>
</div>
<br>
<% if @supplies.empty? %>
<small>
No supplies available.
</small>
<% else %>
<table class="table">
<thead>
<th>Name</th>
<th>Description</th>
<th>Date Added</th>
<th>Quantity</th>
<th colspan="4"></th>
</thead>
<tbody>
<% @supplies.each do |supply| %>
<tr>
<td>
<%= link_to supply.name, supply_path(supply) %>
</td>
<td>
<%= supply.description %>
</td>
<td>
<%= time_ago_in_words(supply.created_at) %> ago
</td>
<td>
<%= supply.quantity %>
</td>
<td>
<%= link_to "Edit", edit_product_path(product), class: "btn btn-primary" %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
<h1>New Supply</h1>
<%= simple_form_for @supply do |f| %>
<%= f.input :name %>
<%= f.input :description, as: :text %>
<%= f.input :quantity, as: :integer %>
<%= f.button :submit, "Add Supply", class: "btn btn-primary" %>
<%= link_to "Back", supplies_path, class: "btn btn-default" %>
<% end %>
<h1>Transactions</h1>
<% if @products.empty? %>
<small>
No products have been created.
</small>
<% elsif @products.status == active %>
<% else%>
<table class="table">
<thead>
<th>Name</th>
......@@ -29,12 +28,12 @@
<td>
<%= time_ago_in_words(product.created_at) %> ago
</td>
<td>
<!-- <td>
<%= link_to "Add Order", order_transaction_path(product), class: "btn btn-primary" %>
</td>
<td>
<%= link_to "Add Supply", supply_transaction_path(product), class: "btn btn-primary" %>
</td>
</td> -->
</tr>
<% end %>
</tbody>
......
Rails.application.routes.draw do
get 'users/index'
get 'orders/new'
get 'orders/create'
get 'supplies/index'
get 'supplies/new'
get 'supplies/create'
get 'comments/new'
devise_for :admin_users
devise_scope :admin_user do
authenticated :admin_user do
resources :products
root to: 'products#index', as: :authenticated_admin_user_root
end
end
devise_for :users
......@@ -14,8 +20,9 @@ Rails.application.routes.draw do
resources :products, only: [] do
resources :orders, only: [:new, :create]
resources :supplies, only: [:new, :create]
resources :comments, only: [:new, :create]
end
root to: 'transactions#index', as: :authenticated_user_root
root to: 'supplies#index', as: :authenticated_user_root
end
end
root to: 'publics#index'
......
class CreateTransactions < ActiveRecord::Migration[5.2]
def change
create_table :transactions do |t|
t.integer :product_id
t.integer :user_id
t.integer :quantity
t.string :mode
t.timestamps
end
end
end
class CreateComments < ActiveRecord::Migration[5.2]
def change
create_table :comments do |t|
t.text :comment
t.references :user, foreign_key: true
t.references :post, foreign_key: true
t.timestamps
end
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2018_07_12_181949) do
ActiveRecord::Schema.define(version: 2018_07_16_132511) do
create_table "admin_users", force: :cascade do |t|
t.string "email", default: "", null: false
......@@ -29,6 +29,16 @@ ActiveRecord::Schema.define(version: 2018_07_12_181949) do
t.index ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true
end
create_table "comments", force: :cascade do |t|
t.text "comment"
t.integer "user_id"
t.integer "post_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["post_id"], name: "index_comments_on_post_id"
t.index ["user_id"], name: "index_comments_on_user_id"
end
create_table "products", force: :cascade do |t|
t.string "name"
t.text "description"
......@@ -37,6 +47,15 @@ ActiveRecord::Schema.define(version: 2018_07_12_181949) do
t.datetime "updated_at", null: false
end
create_table "transactions", force: :cascade do |t|
t.integer "product_id"
t.integer "user_id"
t.integer "quantity"
t.string "mode"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
......
if AdminUser.count == 0
AdminUser.create!
({
email: 'andrea.dolendo@obf.ateneo.edu',
password: 'Andrea25',
password_confirmation:'Andrea25'
})
(
email: 'chanelle.lunod@obf.ateneo.edu',
password: 'December5',
password_confirmation:'December5'
)
end
\ No newline at end of file
require 'test_helper'
class CommentsControllerTest < ActionDispatch::IntegrationTest
test "should get new" do
get comments_new_url
assert_response :success
end
end
require 'test_helper'
class OrdersControllerTest < ActionDispatch::IntegrationTest
test "should get new" do
get orders_new_url
assert_response :success
end
test "should get create" do
get orders_create_url
assert_response :success
end
end
require 'test_helper'
class SuppliesControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get supplies_index_url
assert_response :success
end
test "should get new" do
get supplies_new_url
assert_response :success
end
test "should get create" do
get supplies_create_url
assert_response :success
end
end
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
comment: MyText
user: one
post: one
two:
comment: MyText
user: two
post: two
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
product_id: 1
user_id: 1
quantity: 1
mode: MyString
two:
product_id: 1
user_id: 1
quantity: 1
mode: MyString
require 'test_helper'
class CommentTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class TransactionTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment