Change users to table, fix seeds and remove name and lastname from users
This commit is contained in:
parent
6ec27acaf8
commit
a4245c1331
16 changed files with 74 additions and 78 deletions
|
@ -103,3 +103,7 @@ table {
|
|||
.product_dagschotel {
|
||||
height: 34px;
|
||||
}
|
||||
|
||||
#users-table td {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
def configure_permitted_parameters
|
||||
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(
|
||||
:nickname, :name, :last_name, :password, :password_confirmation,
|
||||
:nickname, :password, :password_confirmation,
|
||||
:avatar
|
||||
) }
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ class OrdersController < ApplicationController
|
|||
end
|
||||
|
||||
def overview
|
||||
@users = User.members.order(:name)
|
||||
@users = User.members.order(:nickname)
|
||||
end
|
||||
|
||||
def quickpay
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
# Table name: users
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# name :string
|
||||
# last_name :string
|
||||
# debt_cents :integer default("0"), not null
|
||||
# nickname :string
|
||||
# created_at :datetime
|
||||
|
@ -33,25 +31,19 @@ class User < ActiveRecord::Base
|
|||
|
||||
has_paper_trail only: [:debt_cents, :admin, :orders_count, :koelkast]
|
||||
|
||||
has_attached_file :avatar, styles: { large: "150x150>", medium: "100x100>" }, default_style: :medium
|
||||
has_attached_file :avatar, styles: { large: "150x150>", medium: "100x100>", small: "40x40>" }, default_style: :medium
|
||||
|
||||
has_many :orders, -> { includes :products }
|
||||
has_many :products, through: :orders
|
||||
belongs_to :dagschotel, class_name: 'Product'
|
||||
|
||||
validates :nickname, presence: true, uniqueness: true
|
||||
validates :name, presence: true
|
||||
validates :last_name, presence: true
|
||||
validates_attachment :avatar,
|
||||
presence: true,
|
||||
content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }
|
||||
|
||||
scope :members, -> { where koelkast: false }
|
||||
|
||||
def full_name
|
||||
"#{name} #{last_name}"
|
||||
end
|
||||
|
||||
def debt
|
||||
self.debt_cents / 100.0
|
||||
end
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
<%= f.error_messages %>
|
||||
|
||||
<%= f.text_field :nickname %>
|
||||
<%= f.text_field :name %>
|
||||
<%= f.text_field :last_name %>
|
||||
|
||||
<%= f.password_field :password %>
|
||||
<%= f.password_field :password_confirmation %>
|
||||
|
|
14
app/views/products/_links.html.erb
Normal file
14
app/views/products/_links.html.erb
Normal file
|
@ -0,0 +1,14 @@
|
|||
<%- if controller_name == 'products' && current_user && current_user.admin? %>
|
||||
<%= link_to "Edit", edit_product_path(product), class: "btn btn-default" %>
|
||||
<%= link_to "Delete", product_path(product), method: :delete, class: "btn btn-danger", data: {confirm: 'Are you sure?'} %>
|
||||
<% end -%>
|
||||
|
||||
<%- if controller_name == 'users' %>
|
||||
<div class="product_dagschotel">
|
||||
<% if current_user.dagschotel != product %>
|
||||
<%= link_to "Make dagschotel", user_dagschotel_path(current_user, product), class: "btn btn-default" %>
|
||||
<% else %>
|
||||
<%= link_to "Huidige dagschotel", user_dagschotel_path(current_user, product), class: "btn btn-success", disabled: true %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end -%>
|
|
@ -7,22 +7,7 @@
|
|||
<h4><%= product.name %></h4>
|
||||
<h3><%= euro(product.price) %></h3>
|
||||
<h6>(In stock: <%= product.stock %>)</h6>
|
||||
<%- if controller_name == 'products' && current_user && current_user.admin? %>
|
||||
<p>
|
||||
<%= link_to "Edit", edit_product_path(product), class: "btn btn-default" %>
|
||||
<%= link_to "Delete", product_path(product), method: :delete, class: "btn btn-danger", data: {confirm: 'Are you sure?'} %>
|
||||
</p>
|
||||
<% end -%>
|
||||
|
||||
<%- if controller_name == 'users' %>
|
||||
<div class="product_dagschotel">
|
||||
<% if current_user.dagschotel != product %>
|
||||
<%= link_to "Make dagschotel", user_dagschotel_path(current_user, product), class: "btn btn-default" %>
|
||||
<% else %>
|
||||
<%= link_to "Huidige dagschotel", user_dagschotel_path(current_user, product), class: "btn btn-success", disabled: true %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end -%>
|
||||
<%= render 'products/links', product: product %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
<ul>
|
||||
<li><%=(pluralize(product.count, product.name)) %></li>
|
||||
</ul>
|
|
@ -1,20 +1,19 @@
|
|||
<div class="col-md-3">
|
||||
<div class="thumbnail monopoly">
|
||||
<h3 class="header" style="background-color: #<%= get_color(user)%>;" ><%= link_to user.full_name, user %></h3>
|
||||
<div class="caption">
|
||||
<%= image_tag(user.avatar , class: "img-circle avatar") %>
|
||||
<p><strong>Name:</strong> <%= user.name %></p>
|
||||
<p><strong>Last name:</strong> <%= user.last_name %></p>
|
||||
<p><strong>Nickname:</strong> <%= user.nickname %></p>
|
||||
<p><strong>Debt:</strong> <%= euro(user.debt) %></p>
|
||||
</div>
|
||||
<% if current_user.admin? %>
|
||||
<div class="footer">
|
||||
<p>
|
||||
<%= link_to "Delete", user_path(user), method: :delete, class: "btn btn-danger", data: {confirm: 'Are you sure?'} %>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<tr>
|
||||
<td>
|
||||
<%= user.id %>
|
||||
</td>
|
||||
<td>
|
||||
<%= image_tag user.avatar(:small) %>
|
||||
</td>
|
||||
<td>
|
||||
<%= user.nickname %>
|
||||
</td>
|
||||
<td>
|
||||
<%= euro(user.debt) %>
|
||||
</td>
|
||||
<% if current_user.admin? %>
|
||||
<td>
|
||||
<%= link_to "Delete", user_path(user), method: :delete, class: "btn btn-danger", data: { confirm: "Are you sure?" } %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
<h1>All users</h1>
|
||||
<%= render partial: 'flash' %>
|
||||
|
||||
<div class="row users">
|
||||
<div class="col-md-12">
|
||||
<%= render @users %>
|
||||
<div class="col-md-8 col-md-offset-2">
|
||||
<h1>All users</h1>
|
||||
<%= render partial: 'flash' %>
|
||||
|
||||
<table id="users-table" class="table table-striped">
|
||||
<%= render @users %>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<%= link_to "[Edit dagschotel]" , user_edit_dagschotel_path(@user) if current_user == @user %>
|
||||
<%= link_to "[Edit profile]" , edit_user_registration_path if current_user == @user %>
|
||||
</h5>
|
||||
<h2><%= @user.nickname %> (<%= @user.full_name %>)</h2>
|
||||
<h2><%= @user.nickname %></h2>
|
||||
<%= button_to "PLACE ORDER!", new_user_order_path(@user), method: :get if current_user == @user %>
|
||||
<div class="debt">DEBT: <%= euro(@user.debt) %></div>
|
||||
</div>
|
||||
|
@ -16,7 +16,9 @@
|
|||
Total: <br/><ul><li><%= @categories.map{|c| pluralize(c.count, c.category)}.join(", ")%></li></ul>
|
||||
<br/>
|
||||
Specifics:<br/>
|
||||
<%= render partial: "products/product_row", collection: @products, as: :product %>
|
||||
<ul>
|
||||
<%= @products.map{ |p| content_tag(:li, pluralize(p.count, p.name)) }.join("\n").html_safe %>
|
||||
</ul>
|
||||
|
||||
<h4>All orders (<%= @user.orders_count %>)</h4>
|
||||
<table class="orders"><%= render @orders %></table>
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
class RemoveNameAndLastNameFromUsers < ActiveRecord::Migration
|
||||
def change
|
||||
remove_column :users, :name, :string
|
||||
remove_column :users, :last_name, :string
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20150319141248) do
|
||||
ActiveRecord::Schema.define(version: 20150319154236) do
|
||||
|
||||
create_table "order_items", force: :cascade do |t|
|
||||
t.integer "order_id"
|
||||
|
@ -44,8 +44,6 @@ ActiveRecord::Schema.define(version: 20150319141248) do
|
|||
end
|
||||
|
||||
create_table "users", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "last_name"
|
||||
t.integer "debt_cents", default: 0, null: false
|
||||
t.string "nickname"
|
||||
t.datetime "created_at"
|
||||
|
|
27
db/seeds.rb
27
db/seeds.rb
|
@ -38,43 +38,46 @@ end
|
|||
users = [
|
||||
{
|
||||
nickname: 'admin',
|
||||
name: 'A.',
|
||||
last_name: 'Admin',
|
||||
avatar: File.new('public/seeds/users/admin.jpg', 'r'),
|
||||
admin: true
|
||||
},
|
||||
{
|
||||
nickname: 'koelkast',
|
||||
name: 'K.',
|
||||
last_name: 'Koelkast',
|
||||
avatar: File.new('public/seeds/users/admin.jpg', 'r'),
|
||||
koelkast: true
|
||||
},
|
||||
{
|
||||
nickname: 'benji',
|
||||
name: 'Benjamin',
|
||||
last_name: 'Cousaert',
|
||||
avatar: File.new('public/seeds/users/benji.jpg', 'r'),
|
||||
dagschotel: Product.first
|
||||
},
|
||||
{
|
||||
nickname: 'don',
|
||||
name: 'Lorin',
|
||||
last_name: 'Werthen',
|
||||
avatar: File.new('public/seeds/users/don.jpg', 'r')
|
||||
},
|
||||
{
|
||||
nickname: 'silox',
|
||||
name: 'Tom',
|
||||
last_name: 'Naessens',
|
||||
avatar: File.new('public/seeds/users/silox.jpg', 'r')
|
||||
}
|
||||
]
|
||||
|
||||
users.each do |attr|
|
||||
User.create nickname: attr[:nickname], name: attr[:name], last_name: attr[:last_name], avatar: attr[:avatar], dagschotel: attr[:dagschotel], password: DEFAULT_PASSWORD, password_confirmation: DEFAULT_PASSWORD, admin: attr[:admin] || false, koelkast: attr[:koelkast] || false
|
||||
User.create(
|
||||
nickname: attr[:nickname],
|
||||
avatar: attr[:avatar],
|
||||
dagschotel: attr[:dagschotel],
|
||||
password: DEFAULT_PASSWORD,
|
||||
password_confirmation: DEFAULT_PASSWORD,
|
||||
admin: attr[:admin] || false,
|
||||
koelkast: attr[:koelkast] || false
|
||||
)
|
||||
end
|
||||
|
||||
50.times do |i|
|
||||
User.create nickname: "TestUser#{i}", name: "Test", last_name: "User", avatar: users[0][:avatar], password: DEFAULT_PASSWORD, password_confirmation: DEFAULT_PASSWORD
|
||||
User.create(
|
||||
nickname: "TestUser#{i}",
|
||||
avatar: users[0][:avatar],
|
||||
password: DEFAULT_PASSWORD,
|
||||
password_confirmation: DEFAULT_PASSWORD
|
||||
)
|
||||
end
|
||||
|
|
2
test/fixtures/users.yml
vendored
2
test/fixtures/users.yml
vendored
|
@ -3,8 +3,6 @@
|
|||
# Table name: users
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# name :string
|
||||
# last_name :string
|
||||
# debt_cents :integer default("0"), not null
|
||||
# nickname :string
|
||||
# created_at :datetime
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
# Table name: users
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# name :string
|
||||
# last_name :string
|
||||
# debt_cents :integer default("0"), not null
|
||||
# nickname :string
|
||||
# created_at :datetime
|
||||
|
|
Loading…
Reference in a new issue