Commit a53e92a3 authored by Chanelle Lunod's avatar Chanelle Lunod

Initial commit

parent 7f2ca038
......@@ -254,8 +254,5 @@ DEPENDENCIES
uglifier (>= 1.3.0)
web-console (>= 3.3.0)
RUBY VERSION
ruby 2.3.3p222
BUNDLED WITH
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
protected
def after_sign_in_path_for(resource)
# if resource.is_a?(AdminUser)
# # Go to this page
# elsif resource.is_a?(User)
# # Go to this page instead
# end
authenticated_root_url
if resource.is_a?(AdminUser)
authenticated_admin_user_root_url
elsif resource.is_a?(User)
authenticated_user_root_url
end
#authenticated_root_url
end
def after_sign_up_path_for(resource)
......@@ -14,6 +14,12 @@ class ApplicationController < ActionController::Base
end
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
\ No newline at end of file
class ProductsController < ApplicationController
before_action :authenticate_user!
before_action :authenticate_admin_user!
def index
@products = Product.all
#if @product.status == active
#else
end
def show
......@@ -17,7 +19,7 @@ class ProductsController < ApplicationController
@product = Product.new(product_params)
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
render 'new'
end
......@@ -31,18 +33,12 @@ class ProductsController < ApplicationController
@product = Product.find_by(id: params[:id])
if @product.update(product_params)
redirect_to products_path, notice: "Product updated!"
redirect_to products_path, notice: "#{@product.name} has been updated!"
else
render 'edit'
end
end
def destroy
@product = Product.find_by(id: params[:id])
@product.destroy
redirect_to products_path, alert: "Product deleted!"
end
private
def product_params
params.require(:product).permit!
......
class TransactionsController < ApplicationController
before_action :authenticate_user!
def index
end
def show
end
end
module TransactionsHelper
end
class AdminUser < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable,
:recoverable, :rememberable, :trackable, :validatable
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable
end
class Product < ApplicationRecord
has_many :transactions
end
......@@ -3,4 +3,15 @@ class User < ApplicationRecord
# :confirmable, :lockable, :timeoutable and :omniauthable
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
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 @@
<body>
<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">
<span class="navbar-toggler-icon"></span>
</button>
......@@ -24,16 +24,17 @@
<span class="navbar-text">
<% if user_signed_in? %>
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' %>
<% else %>
<%= link_to "Sign up", new_user_registration_path, :class => 'navbar-link' %> |
<%= link_to "Login", new_user_session_path, :class => 'navbar-link' %>
<% elsif admin_user_signed_in? %>
<%= link_to "Logout", destroy_admin_user_session_path, method: :delete, :class => 'navbar-link' %>
<% end %>
</span>
</div>
</nav>
<div class="container" id="container">
<% if notice %>
<p class="alert alert-success"><%= notice %></p>
......
......@@ -3,7 +3,7 @@
<%= simple_form_for @product do |f| %>
<%= f.input :name %>
<%= 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" %>
<%= link_to "Back", products_path, class: "btn btn-default" %>
<% end %>
<h1>Products</h1>
<h1>Inventory System</h1>
<div>
<%= link_to "Create new product", new_product_path, class: "btn btn-primary" %>
......@@ -16,13 +16,14 @@
<th>Name</th>
<th>Description</th>
<th>Status</th>
<th>Time Created</th>
<th colspan="4"></th>
</thead>
<tbody>
<% @products.each do |product| %>
<tr>
<td>
<%= product.name %>
<%= link_to product.name, product_path(product) %>
</td>
<td>
<%= product.description %>
......@@ -36,12 +37,6 @@
<td>
<%= link_to "Edit", edit_product_path(product), class: "btn btn-primary" %>
</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>
<% end %>
</tbody>
......
......@@ -2,9 +2,8 @@
<%= simple_form_for @product do |f| %>
<%= f.input :name %>
<%= f.input :description %>
<%= f.radio_button :status, 'ACTIVE' %>
<%= f.radio_button :status, 'INACTIVE' %>
<%= f.input :description, as: :text %>
<%= f.input :status, as: :radio_buttons, collection: [['Active', 'Active'], ['Inactive', 'Inactive']], value_method: :first, label_method: :second %>
<%= f.button :submit, "Create Product", class: "btn btn-primary" %>
<%= link_to "Back", products_path, class: "btn btn-default" %>
<% end %>
<h1>Product #<%= @product.id %></h1>
<h2>
<%= @product.name %>
</h2>
<h1><%= @product.name %></h1>
<p>
<%= @product.description %>
</p>
<small>
<p>
Status: <%= @product.status %>
</p>
<p>
<small>
Created At: <%= @product.created_at.to_s :short %>
</small>
<small>
</small>
<small>
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="col">
<h3>Sign Up</h3>
<%= simple_form_for :user, url: registration_path(:user) do |f| %>
<h3>Admin User Log In</h3>
<%= 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, "Sign Up" %>
<%= f.button :submit, "Log In" %>
<% end %>
</div>
<div class="col">
<h3>Log In</h3>
<h3>User Log In</h3>
<%= 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 %>
</div>
</div>
<h1>Transactions#index</h1>
<p>Find me in app/views/transactions/index.html.erb</p>
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 :admin_users, path: 'admin_users', skip: :registrations
devise_scope :user do
authenticated :user do
resources :products
root to: 'products#index', as: :authenticated_root
resources :products, only: [] do
resources :orders, only: [:new, :create]
resources :supplies, only: [:new, :create]
end
root to: 'transactions#index', as: :authenticated_user_root
end
unauthenticated :user do
root to: 'publics#index', as: :unauthenticated_root
root to: 'publics#index', as: :unauthenticated_user_root
end
end
root to: 'publics#index'
......
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
if AdminUser.count == 0
AdminUser.create!
({
email: 'andrea.dolendo@obf.ateneo.edu',
password: 'Andrea25',
password_confirmation:'Andrea25'
})
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