From a5e543d298f7b41f82ad452b2cc7dad88e65a90c Mon Sep 17 00:00:00 2001 From: Adrian Hinz Date: Mon, 3 Oct 2016 14:50:49 +0200 Subject: [PATCH] Signed-off-by: Adrian Hinz --- app/assets/stylesheets/styles.css | 22 +++--- app/controllers/customers_controller.rb | 7 +- app/models/customer.rb | 1 + app/models/product.rb | 1 + app/models/user.rb | 4 ++ app/views/customers/_form.html.erb | 72 +++++++++++-------- app/views/customers/edit.html.erb | 17 +++-- app/views/customers/new.html.erb | 17 +++-- app/views/devise/sessions/new.html.erb | 37 ++++------ app/views/layouts/devise.html.erb | 31 ++++++++ .../20161003103254_add_user_to_products.rb | 5 ++ .../20161003103325_add_user_to_customers.rb | 5 ++ db/schema.rb | 8 ++- 13 files changed, 153 insertions(+), 74 deletions(-) create mode 100644 app/views/layouts/devise.html.erb create mode 100644 db/migrate/20161003103254_add_user_to_products.rb create mode 100644 db/migrate/20161003103325_add_user_to_customers.rb diff --git a/app/assets/stylesheets/styles.css b/app/assets/stylesheets/styles.css index e8fc682..b1a2c66 100644 --- a/app/assets/stylesheets/styles.css +++ b/app/assets/stylesheets/styles.css @@ -224,7 +224,7 @@ footer .copy{ border-left:1px solid #eee; border-top:1px solid #eee; border-right:2px solid #eee; - border-bottom:2px solid #eee; + border-bottom:2px solid #eee; } .content-box-large { @@ -420,6 +420,7 @@ body { font-size: 18px; font-weight: 600; } +.login-wrapper .box input[type="email"], .login-wrapper .box input[type="text"], .login-wrapper .box input[type="password"] { font-size: 15px; @@ -429,6 +430,7 @@ body { padding-left: 12px; } .login-wrapper .box input[type="text"]:focus, +.login-wrapper .box input[type="email"]:focus, .login-wrapper .box input[type="password"]:focus { border: 1px solid #28a0e5; outline: none; @@ -486,8 +488,8 @@ body { background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6887c4), color-stop(100%,#4566a9)); background: -webkit-linear-gradient(top, #6887c4 0%,#4566a9 100%); background: -o-linear-gradient(top, #6887c4 0%,#4566a9 100%); - background: -ms-linear-gradient(top, #6887c4 0%,#4566a9 100%); - background: linear-gradient(to bottom, #6887c4 0%,#4566a9 100%); + background: -ms-linear-gradient(top, #6887c4 0%,#4566a9 100%); + background: linear-gradient(to bottom, #6887c4 0%,#4566a9 100%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6887c4', endColorstr='#4566a9',GradientType=0 ); border: 1px solid #3B4868; border-radius: 3px 3px 3px 3px; @@ -504,8 +506,8 @@ body { background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6887c4), color-stop(100%,#5773AC)); background: -webkit-linear-gradient(top, #6887c4 0%,#5773AC 100%); background: -o-linear-gradient(top, #6887c4 0%,#5773AC 100%); - background: -ms-linear-gradient(top, #6887c4 0%,#5773AC 100%); - background: linear-gradient(to bottom, #6887c4 0%,#5773AC 100%); + background: -ms-linear-gradient(top, #6887c4 0%,#5773AC 100%); + background: linear-gradient(to bottom, #6887c4 0%,#5773AC 100%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6887c4', endColorstr='#5773AC',GradientType=0 ); } .login-wrapper .box .social a.face_login span.face_icon{ @@ -595,7 +597,7 @@ body { .header{ height:auto; padding:15px 0px; - } + } .header .logo{ text-align:center; padding-bottom:10px; @@ -615,7 +617,7 @@ body { .header{ height:auto; padding:15px 0px; - } + } .header .logo{ text-align:center; padding-bottom:10px; @@ -628,7 +630,7 @@ body { width:100%; float:none; position:relative; - } + } .mainy{ margin-left: 0px; } @@ -648,5 +650,5 @@ body { border-bottom:0px; box-shadow:0px 0px 1px #0fa6bc; border-radius:10px; - } -} \ No newline at end of file + } +} diff --git a/app/controllers/customers_controller.rb b/app/controllers/customers_controller.rb index 76ae92b..6d6f369 100644 --- a/app/controllers/customers_controller.rb +++ b/app/controllers/customers_controller.rb @@ -1,7 +1,7 @@ class CustomersController < ApplicationController - + def index - @customers = Customer.all + @customers = Customer.where(user_id: current_user.id) end def new @@ -10,6 +10,7 @@ class CustomersController < ApplicationController def create @customer = Customer.new(customer_params) + @customer.user_id = current_user.id if @customer.save redirect_to customers_path else @@ -23,7 +24,7 @@ class CustomersController < ApplicationController def update @customer = Customer.find(params[:id]) - + @customer.user_id = current_user.id if @customer.update(customer_params) redirect_to customers_path else diff --git a/app/models/customer.rb b/app/models/customer.rb index 7c0e402..5d47d3e 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -5,6 +5,7 @@ class Customer < ApplicationRecord validates :city, presence: true, length: { minimum: 3 } validates :nip, presence: true, length: {minimum: 13} + belongs_to :user def adress self.street + "; " + self.postcode + " " + self.city diff --git a/app/models/product.rb b/app/models/product.rb index e72d315..f00671a 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,3 +1,4 @@ class Product < ApplicationRecord belongs_to :vat + belongs_to :user end diff --git a/app/models/user.rb b/app/models/user.rb index b2091f9..8fb58bd 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,4 +3,8 @@ class User < ApplicationRecord # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable + + has_many :user_firms + has_many :products + has_many :customers end diff --git a/app/views/customers/_form.html.erb b/app/views/customers/_form.html.erb index e217424..317132d 100644 --- a/app/views/customers/_form.html.erb +++ b/app/views/customers/_form.html.erb @@ -1,4 +1,5 @@ -<%= form_for @customer do |f| %> + +<%= form_for @customer, html: {class: "form-horizontal"} do |f| %> <% if @customer.errors.any? %>

@@ -12,32 +13,45 @@

<% end %> -

- <%= f.label :name %>
- <%= f.text_field :name %> -

-

- <%= f.label :street %>
- <%= f.text_field :street %> -

-

- <%= f.label :postcode %>
- <%= f.text_field :postcode %> -

-

- <%= f.label :city %>
- <%= f.text_field :city %> -

-

- <%= f.label :nip %>
- <%= f.text_field :nip %> -

-

- <%= f.label :regon %>
- <%= f.text_field :regon %> -

- -

- <%= f.submit %> -

+
+ <%= f.label :name, class: "col-sm-2 control-label" %> +
+ <%= f.text_field :name, class: "form-control", placeholder: 'Nazwa' %> +
+
+
+ <%= f.label :street, class: "col-sm-2 control-label" %> +
+ <%= f.text_field :street, class: "form-control", placeholder: 'Ulica' %> +
+
+
+ <%= f.label :postcode, class: "col-sm-2 control-label" %> +
+ <%= f.text_field :postcode, class: "form-control", placeholder: 'Kod pocztowy' %> +
+
+
+ <%= f.label :city, class: "col-sm-2 control-label" %> +
+ <%= f.text_field :city, class: "form-control", placeholder: 'Miasto' %> +
+
+
+ <%= f.label :nip, class: "col-sm-2 control-label" %> +
+ <%= f.text_field :nip, class: "form-control", placeholder: 'NIP' %> +
+
+
+ <%= f.label :regon, class: "col-sm-2 control-label" %> +
+ <%= f.text_field :regon, class: "form-control", placeholder: 'Regon' %> +
+
+
+
+ <%= f.submit 'Zapisz', class: "btn btn-primary" %> +
+
<% end %> diff --git a/app/views/customers/edit.html.erb b/app/views/customers/edit.html.erb index ac378ff..0a22014 100644 --- a/app/views/customers/edit.html.erb +++ b/app/views/customers/edit.html.erb @@ -1,4 +1,13 @@ -

Edycja klienta

-<%= link_to 'Powrot', customers_path %>
- -<%= render 'form' %> +
+
+
+
Edycja klienta
+
+ <%= link_to raw(" Powrot"), customers_path, title: 'Powrot' %> +
+
+
+ <%= render 'form' %> +
+
+
diff --git a/app/views/customers/new.html.erb b/app/views/customers/new.html.erb index 1a09382..4b4e5a9 100644 --- a/app/views/customers/new.html.erb +++ b/app/views/customers/new.html.erb @@ -1,4 +1,13 @@ -

Nowy klient

-<%= link_to 'Powrot', customers_path %>
- -<%= render 'form' %> +
+
+
+
Nowy klient
+
+ <%= link_to raw(" Powrot"), customers_path, title: 'Powrot' %> +
+
+
+ <%= render 'form' %> +
+
+
diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index b261cfd..4960c33 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -1,26 +1,17 @@ -

Log in

- +<%# render "devise/shared/links" %> <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> -
- <%= f.label :email %>
- <%= f.email_field :email, autofocus: true %> -
- -
- <%= f.label :password %>
- <%= f.password_field :password, autocomplete: "off" %> -
- - <% if devise_mapping.rememberable? -%> -
- <%= f.check_box :remember_me %> - <%= f.label :remember_me %> -
- <% end -%> - -
- <%= f.submit "Log in" %> +
+
<% end %> - -<%= render "devise/shared/links" %> diff --git a/app/views/layouts/devise.html.erb b/app/views/layouts/devise.html.erb new file mode 100644 index 0000000..ff3d609 --- /dev/null +++ b/app/views/layouts/devise.html.erb @@ -0,0 +1,31 @@ + + + + FireStorm - Faktury + + <%= csrf_meta_tags %> + + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> + <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + + +
+
+
+ +
+
+
+ +
+
+ <%= yield %> +
+
+ + diff --git a/db/migrate/20161003103254_add_user_to_products.rb b/db/migrate/20161003103254_add_user_to_products.rb new file mode 100644 index 0000000..f517cc9 --- /dev/null +++ b/db/migrate/20161003103254_add_user_to_products.rb @@ -0,0 +1,5 @@ +class AddUserToProducts < ActiveRecord::Migration[5.0] + def change + add_reference :products, :user, foreign_key: true + end +end diff --git a/db/migrate/20161003103325_add_user_to_customers.rb b/db/migrate/20161003103325_add_user_to_customers.rb new file mode 100644 index 0000000..030de5d --- /dev/null +++ b/db/migrate/20161003103325_add_user_to_customers.rb @@ -0,0 +1,5 @@ +class AddUserToCustomers < ActiveRecord::Migration[5.0] + def change + add_reference :customers, :user, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 52cef7c..d86cee1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161003081718) do +ActiveRecord::Schema.define(version: 20161003103325) do create_table "customers", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci" do |t| t.string "name" @@ -21,6 +21,8 @@ ActiveRecord::Schema.define(version: 20161003081718) do t.string "regon" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "user_id" + t.index ["user_id"], name: "index_customers_on_user_id", using: :btree end create_table "products", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci" do |t| @@ -30,6 +32,8 @@ ActiveRecord::Schema.define(version: 20161003081718) do t.string "qnt_name" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "user_id" + t.index ["user_id"], name: "index_products_on_user_id", using: :btree t.index ["vat_id"], name: "index_products_on_vat_id", using: :btree end @@ -75,6 +79,8 @@ ActiveRecord::Schema.define(version: 20161003081718) do t.datetime "updated_at", null: false end + add_foreign_key "customers", "users" + add_foreign_key "products", "users" add_foreign_key "products", "vats" add_foreign_key "user_firms", "users" end