Commit a53e92a3 authored by Chanelle Lunod's avatar Chanelle Lunod

Initial commit

parent 7f2ca038
...@@ -254,8 +254,5 @@ DEPENDENCIES ...@@ -254,8 +254,5 @@ DEPENDENCIES
uglifier (>= 1.3.0) uglifier (>= 1.3.0)
web-console (>= 3.3.0) web-console (>= 3.3.0)
RUBY VERSION
ruby 2.3.3p222
BUNDLED WITH BUNDLED WITH
1.14.6 1.14.6
# 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 Transactions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
protected protected
def after_sign_in_path_for(resource) def after_sign_in_path_for(resource)
# if resource.is_a?(AdminUser) if resource.is_a?(AdminUser)
# # Go to this page authenticated_admin_user_root_url
# elsif resource.is_a?(User) elsif resource.is_a?(User)
# # Go to this page instead authenticated_user_root_url
# end end
authenticated_root_url #authenticated_root_url
end end
def after_sign_up_path_for(resource) def after_sign_up_path_for(resource)
...@@ -14,6 +14,12 @@ class ApplicationController < ActionController::Base ...@@ -14,6 +14,12 @@ class ApplicationController < ActionController::Base
end end
def after_sign_out_path_for(resource) def after_sign_out_path_for(resource)
unauthenticated_root_url if resource == :user
new_user_session_path
elsif resource == :admin_user
new_admin_user_session_path
else
root_path
end
end end
end end
\ No newline at end of file
class ProductsController < ApplicationController class ProductsController < ApplicationController
before_action :authenticate_user! before_action :authenticate_admin_user!
def index def index
@products = Product.all @products = Product.all
#if @product.status == active
#else
end end
def show def show
...@@ -17,7 +19,7 @@ class ProductsController < ApplicationController ...@@ -17,7 +19,7 @@ class ProductsController < ApplicationController
@product = Product.new(product_params) @product = Product.new(product_params)
if @product.save if @product.save
redirect_to products_path, notice: "You have successfully created a new product." redirect_to products_path, notice: "You have successfully created a new product!"
else else
render 'new' render 'new'
end end
...@@ -31,18 +33,12 @@ class ProductsController < ApplicationController ...@@ -31,18 +33,12 @@ class ProductsController < ApplicationController
@product = Product.find_by(id: params[:id]) @product = Product.find_by(id: params[:id])
if @product.update(product_params) if @product.update(product_params)
redirect_to products_path, notice: "Product updated!" redirect_to products_path, notice: "#{@product.name} has been updated!"
else else
render 'edit' render 'edit'
end end
end end
def destroy
@product = Product.find_by(id: params[:id])
@product.destroy
redirect_to products_path, alert: "Product deleted!"
end
private private
def product_params def product_params
params.require(:product).permit! params.require(:product).permit!
......
class TransactionsController < ApplicationController
before_action :authenticate_user!
def index
end
def show
end
end
module TransactionsHelper
end
class AdminUser < ApplicationRecord class AdminUser < ApplicationRecord
# Include default devise modules. Others available are: # Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable # :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable
:recoverable, :rememberable, :trackable, :validatable
end end
class Product < ApplicationRecord class Product < ApplicationRecord
has_many :transactions
end end
...@@ -3,4 +3,15 @@ class User < ApplicationRecord ...@@ -3,4 +3,15 @@ class User < ApplicationRecord
# :confirmable, :lockable, :timeoutable and :omniauthable # :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable :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
end end
<h2>Resend confirmation instructions</h2>
<%= simple_form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>
<%= f.error_notification %>
<%= f.full_error :confirmation_token %>
<div class="form-inputs">
<%= f.input :email, required: true, autofocus: true %>
</div>
<div class="form-actions">
<%= f.button :submit, "Resend confirmation instructions" %>
</div>
<% end %>
<%= render "admin_users/shared/links" %>
<p>Welcome <%= @email %>!</p>
<p>You can confirm your account email through the link below:</p>
<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>
<p>Hello <%= @email %>!</p>
<% if @resource.try(:unconfirmed_email?) %>
<p>We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.</p>
<% else %>
<p>We're contacting you to notify you that your email has been changed to <%= @resource.email %>.</p>
<% end %>
<p>Hello <%= @resource.email %>!</p>
<p>We're contacting you to notify you that your password has been changed.</p>
<p>Hello <%= @resource.email %>!</p>
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
<p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>
<p>Hello <%= @resource.email %>!</p>
<p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>
<p>Click the link below to unlock your account:</p>
<p><%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %></p>
<h2>Change your password</h2>
<%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %>
<%= f.error_notification %>
<%= f.input :reset_password_token, as: :hidden %>
<%= f.full_error :reset_password_token %>
<div class="form-inputs">
<%= f.input :password, label: "New password", required: true, autofocus: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length) %>
<%= f.input :password_confirmation, label: "Confirm your new password", required: true %>
</div>
<div class="form-actions">
<%= f.button :submit, "Change my password" %>
</div>
<% end %>
<%= render "admin_users/shared/links" %>
<h2>Forgot your password?</h2>
<%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :email, required: true, autofocus: true %>
</div>
<div class="form-actions">
<%= f.button :submit, "Send me reset password instructions" %>
</div>
<% end %>
<%= render "admin_users/shared/links" %>
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :email, required: true, autofocus: true %>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<p>Currently waiting confirmation for: <%= resource.unconfirmed_email %></p>
<% end %>
<%= f.input :password, autocomplete: "off", hint: "leave it blank if you don't want to change it", required: false %>
<%= f.input :password_confirmation, required: false %>
<%= f.input :current_password, hint: "we need your current password to confirm your changes", required: true %>
</div>
<div class="form-actions">
<%= f.button :submit, "Update" %>
</div>
<% end %>
<h3>Cancel my account</h3>
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %></p>
<%= link_to "Back", :back %>
<h2>Sign up</h2>
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :email, required: true, autofocus: true %>
<%= f.input :password, required: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length) %>
<%= f.input :password_confirmation, required: true %>
</div>
<div class="form-actions">
<%= f.button :submit, "Sign up" %>
</div>
<% end %>
<%= render "admin_users/shared/links" %>
<h2>Log in</h2>
<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="form-inputs">
<%= f.input :email, required: false, autofocus: true %>
<%= f.input :password, required: false %>
<%= f.input :remember_me, as: :boolean if devise_mapping.rememberable? %>
</div>
<div class="form-actions">
<%= f.button :submit, "Log in" %>
</div>
<% end %>
<%= render "admin_users/shared/links" %>
<%- if controller_name != 'sessions' %>
<%= link_to "Log in", new_session_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
<%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %><br />
<% end -%>
<% end -%>
<h2>Resend unlock instructions</h2>
<%= simple_form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %>
<%= f.error_notification %>
<%= f.full_error :unlock_token %>
<div class="form-inputs">
<%= f.input :email, required: true, autofocus: true %>
</div>
<div class="form-actions">
<%= f.button :submit, "Resend unlock instructions" %>
</div>
<% end %>
<%= render "admin_users/shared/links" %>
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<body> <body>
<nav class="navbar navbar-expand-lg navbar-light bg-light"> <nav class="navbar navbar-expand-lg navbar-light bg-light">
<%= link_to "Products", root_path, class: "navbar-brand" %> <%= link_to "Main", root_path, class: "navbar-brand" %>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>
</button> </button>
...@@ -24,16 +24,17 @@ ...@@ -24,16 +24,17 @@
<span class="navbar-text"> <span class="navbar-text">
<% if user_signed_in? %> <% if user_signed_in? %>
Logged in as <strong><%= current_user.email %></strong>. Logged in as <strong><%= current_user.email %></strong>.
<%= link_to 'Edit profile', edit_user_registration_path, :class => 'navbar-link' %> | <%= link_to 'Edit Profile', edit_user_registration_path, :class => 'navbar-link' %> |
<%= link_to "Logout", destroy_user_session_path, method: :delete, :class => 'navbar-link' %> <%= link_to "Logout", destroy_user_session_path, method: :delete, :class => 'navbar-link' %>
<% else %> <% elsif admin_user_signed_in? %>
<%= link_to "Sign up", new_user_registration_path, :class => 'navbar-link' %> | <%= link_to "Logout", destroy_admin_user_session_path, method: :delete, :class => 'navbar-link' %>
<%= link_to "Login", new_user_session_path, :class => 'navbar-link' %>
<% end %> <% end %>
</span> </span>
</div> </div>
</nav> </nav>
<div class="container" id="container"> <div class="container" id="container">
<% if notice %> <% if notice %>
<p class="alert alert-success"><%= notice %></p> <p class="alert alert-success"><%= notice %></p>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<%= simple_form_for @product do |f| %> <%= simple_form_for @product do |f| %>
<%= f.input :name %> <%= f.input :name %>
<%= f.input :description, as: :text %> <%= f.input :description, as: :text %>
<%= f.input :status, as: :radio_buttons, collection: [['ACTIVE'], ['INACTIVE']], label_method: :first %> <%= f.input :status, as: :radio_buttons, collection: [['Active', 'Active'], ['Inactive', 'Inactive']], value_method: :first, label_method: :second %>
<%= f.button :submit, "Save", class: "btn btn-primary" %> <%= f.button :submit, "Save", class: "btn btn-primary" %>
<%= link_to "Back", products_path, class: "btn btn-default" %> <%= link_to "Back", products_path, class: "btn btn-default" %>
<% end %> <% end %>
<h1>Products</h1> <h1>Inventory System</h1>
<div> <div>
<%= link_to "Create new product", new_product_path, class: "btn btn-primary" %> <%= link_to "Create new product", new_product_path, class: "btn btn-primary" %>
...@@ -16,13 +16,14 @@ ...@@ -16,13 +16,14 @@
<th>Name</th> <th>Name</th>
<th>Description</th> <th>Description</th>
<th>Status</th> <th>Status</th>
<th>Time Created</th>
<th colspan="4"></th> <th colspan="4"></th>
</thead> </thead>
<tbody> <tbody>
<% @products.each do |product| %> <% @products.each do |product| %>
<tr> <tr>
<td> <td>
<%= product.name %> <%= link_to product.name, product_path(product) %>
</td> </td>
<td> <td>
<%= product.description %> <%= product.description %>
...@@ -36,12 +37,6 @@ ...@@ -36,12 +37,6 @@
<td> <td>
<%= link_to "Edit", edit_product_path(product), class: "btn btn-primary" %> <%= link_to "Edit", edit_product_path(product), class: "btn btn-primary" %>
</td> </td>
<td>
<%= link_to "Delete", product_path(product), method: :delete, class: "btn btn-danger", data: { confirm: "Are you sure?" } %>
</td>
<td>
<%= link_to "View", product_path(product) %>
</td>
</tr> </tr>
<% end %> <% end %>
</tbody> </tbody>
......
...@@ -2,9 +2,8 @@ ...@@ -2,9 +2,8 @@
<%= simple_form_for @product do |f| %> <%= simple_form_for @product do |f| %>
<%= f.input :name %> <%= f.input :name %>
<%= f.input :description %> <%= f.input :description, as: :text %>
<%= f.radio_button :status, 'ACTIVE' %> <%= f.input :status, as: :radio_buttons, collection: [['Active', 'Active'], ['Inactive', 'Inactive']], value_method: :first, label_method: :second %>
<%= f.radio_button :status, 'INACTIVE' %>
<%= f.button :submit, "Create Product", class: "btn btn-primary" %> <%= f.button :submit, "Create Product", class: "btn btn-primary" %>
<%= link_to "Back", products_path, class: "btn btn-default" %> <%= link_to "Back", products_path, class: "btn btn-default" %>
<% end %> <% end %>
<h1>Product #<%= @product.id %></h1> <h1><%= @product.name %></h1>
<h2>
<%= @product.name %>
</h2>
<p> <p>
<%= @product.description %> <%= @product.description %>
</p> </p>
<small>
<p>
Status: <%= @product.status %>
</p>
<p>
<small>
Created At: <%= @product.created_at.to_s :short %> Created At: <%= @product.created_at.to_s :short %>
</small> </small>
<small> <small>
Updated At: <%= @product.updated_at.to_s :long %> Updated At: <%= @product.updated_at.to_s :long %>
</small> </small>
</p>
<p>
<%= link_to "Back", products_path %>
</p>
<%= link_to "Back", products_path %>
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<h3>Sign Up</h3> <h3>Admin User Log In</h3>
<%= simple_form_for :user, url: registration_path(:user) do |f| %> <%= simple_form_for :admin_user, url: session_path(:admin_user) do |f| %>
<%= f.input :email %> <%= f.input :email %>
<%= f.input :password %> <%= f.input :password %>
<%= f.input :password_confirmation %> <%= f.input :password_confirmation %>
<%= f.button :submit, "Sign Up" %> <%= f.button :submit, "Log In" %>
<% end %> <% end %>
</div> </div>
<div class="col"> <div class="col">
<h3>Log In</h3> <h3>User Log In</h3>
<%= simple_form_for :user, url: session_path(:user) do |f| %> <%= simple_form_for :user, url: session_path(:user) do |f| %>
<%= f.input :email %> <%= f.input :email %>
<%= f.input :password %> <%= f.input :password %>
<%= f.input :password_confirmation %>
<%= f.button :submit, "Log In" %> <%= f.button :submit, "Log In" %>
<%= link_to "Sign Up", new_user_registration_path, :class => 'navbar-link' %>
<% end %> <% end %>
</div> </div>
</div> </div>
<h1>Transactions#index</h1>
<p>Find me in app/views/transactions/index.html.erb</p>
Rails.application.routes.draw do Rails.application.routes.draw do
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
unauthenticated :admin_user do
root to: 'publics#index', as: :unauthenticated_admin_user_root
end
end
devise_for :users devise_for :users
#devise_for :admin_users, path: 'admin_users', skip: :registrations
devise_scope :user do devise_scope :user do
authenticated :user do authenticated :user do
resources :products resources :products, only: [] do
root to: 'products#index', as: :authenticated_root resources :orders, only: [:new, :create]
resources :supplies, only: [:new, :create]
end
root to: 'transactions#index', as: :authenticated_user_root
end end
unauthenticated :user do unauthenticated :user do
root to: 'publics#index', as: :unauthenticated_root root to: 'publics#index', as: :unauthenticated_user_root
end end
end end
root to: 'publics#index' root to: 'publics#index'
......
# This file should contain all the record creation needed to seed the database with its default values. if AdminUser.count == 0
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). AdminUser.create!
# ({
# Examples: email: 'andrea.dolendo@obf.ateneo.edu',
# password: 'Andrea25',
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) password_confirmation:'Andrea25'
# Character.create(name: 'Luke', movie: movies.first) })
end
if AdminUser.valid?
admin.save()
# email: 'chanelle.lunod@obf.ateneo.edu',
# password: 'December5',
# password_confirmation:'December5'
\ No newline at end of file
require 'test_helper'
class TransactionsControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get transactions_index_url
assert_response :success
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