From f2d5cc96c090f81cfac3c3dba211e94cf184e45f Mon Sep 17 00:00:00 2001 From: Karina Delgado Date: Thu, 19 Nov 2020 20:31:37 -0600 Subject: [PATCH 1/8] input disabled and number generated randomly Co-athored-by: danielasotomayor99 --- app/controllers/employees_controller.rb | 4 ++++ app/views/employees/new.html.erb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/employees_controller.rb b/app/controllers/employees_controller.rb index 4c2a467..645b36e 100644 --- a/app/controllers/employees_controller.rb +++ b/app/controllers/employees_controller.rb @@ -11,6 +11,10 @@ def show def new @employee = Employee.new + @private_number = rand(111111..999999) + if Employee.exists?(private_number: @private_number) + @private_number = rand(111111..999999) + end end def create diff --git a/app/views/employees/new.html.erb b/app/views/employees/new.html.erb index 7658de5..21a8310 100644 --- a/app/views/employees/new.html.erb +++ b/app/views/employees/new.html.erb @@ -21,7 +21,7 @@
<%= label_tag 'private_number', 'Private Number:'%> - <%= form.text_field :private_number, class:'form-control'%> + <%= form.text_field :private_number, class:'form-control', value: @private_number, disabled: true%>
<%= submit_tag "Add Employee", class:"btn btn-outline-success"%> From 20c1d9ae4be1649c82f607bcaaea30e4df8243b5 Mon Sep 17 00:00:00 2001 From: Karina Delgado Date: Mon, 23 Nov 2020 00:02:22 -0600 Subject: [PATCH 2/8] Fixed migrations and add new admin to login --- db/migrate/20201102021904_fix_column_name.rb | 5 ----- db/schema.rb | 2 +- db/seeds.rb | 2 +- 3 files changed, 2 insertions(+), 7 deletions(-) delete mode 100644 db/migrate/20201102021904_fix_column_name.rb diff --git a/db/migrate/20201102021904_fix_column_name.rb b/db/migrate/20201102021904_fix_column_name.rb deleted file mode 100644 index 1427e0a..0000000 --- a/db/migrate/20201102021904_fix_column_name.rb +++ /dev/null @@ -1,5 +0,0 @@ -class FixColumnName < ActiveRecord::Migration[6.0] - def change - rename_column :admins, :password, :password_digest - end -end diff --git a/db/schema.rb b/db/schema.rb index 5fa8194..0c8fdab 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -34,7 +34,7 @@ t.string "name" t.string "email" t.string "position" - t.string "private_number" + t.integer "private_number" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.boolean "status", default: true diff --git a/db/seeds.rb b/db/seeds.rb index 23d0abe..554cb2b 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -8,6 +8,6 @@ # Employee.create(name: 'Karina Delgado', email: 'karina@hotmail.com', position: 'QA', private_number: 123, status: 'active') # Employee.create(name: 'Daniela Sotomayor', email: 'dany@hotmail.com', position: 'Developer', private_number: 321, status: 'active') -# Admin.create(user: 'Karina', password_digest: '123') + Admin.create(user: 'admin', password_digest: 'admin') # Branch.create(name: 'HR', address: '3rd Floor') # Report.create(check: 'check in', check_time: "2016-11-01 17:00:13", employee_id: "1") From 4f3e06e6b136ffd13608ab48d3dcffa6f777f95a Mon Sep 17 00:00:00 2001 From: Karina Delgado Date: Mon, 23 Nov 2020 00:04:25 -0600 Subject: [PATCH 3/8] Add validations for private number Co-authored-by: danielasotomayor99 --- app/controllers/employees_controller.rb | 33 +++++++++++++++++-------- app/models/employee.rb | 3 +++ app/views/employees/edit.html.erb | 14 +++++++++++ app/views/employees/new.html.erb | 15 ++++++++++- 4 files changed, 54 insertions(+), 11 deletions(-) diff --git a/app/controllers/employees_controller.rb b/app/controllers/employees_controller.rb index 645b36e..be31e2c 100644 --- a/app/controllers/employees_controller.rb +++ b/app/controllers/employees_controller.rb @@ -1,6 +1,7 @@ class EmployeesController < ApplicationController before_action :current_employee, only: [:show, :edit, :update] + before_action :validate_private_num, only: [:create] def index @employees = Employee.all @@ -11,25 +12,29 @@ def show def new @employee = Employee.new - @private_number = rand(111111..999999) - if Employee.exists?(private_number: @private_number) - @private_number = rand(111111..999999) - end end def create - employee = Employee.create(employee_params) - - redirect_to employees_path + @employee = Employee.new(employee_params) + if @employee.valid? + @employee.save! + redirect_to employees_path + else + redirect_to new_employee_path, alert: 'Private number already exist' + end end def edit end def update - @employee.update(employee_params) - - redirect_to employee_path(@employee) + respond_to do |format| + if @employee.update(employee_params) + format.html { redirect_to employees_url, notice: 'Employee was successfully updated.' } + else + format.html { render :edit } + end + end end private @@ -41,4 +46,12 @@ def employee_params def current_employee @employee = Employee.find(params[:id]) end + + def validate_private_num + @pnumber = params[:private_number] + if Employee.exists?(private_number: @pnumber) == true + flash[:alert] = "Private number already exist" + end + end + end diff --git a/app/models/employee.rb b/app/models/employee.rb index 9da2ae3..ad9b1b3 100644 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -1,3 +1,6 @@ class Employee < ApplicationRecord has_many :reports +validates :name, presence: true +validates :position, presence: true +validates :private_number, presence: true, length: { is: 6 }, numericality: { only_integer: true }, uniqueness: true end diff --git a/app/views/employees/edit.html.erb b/app/views/employees/edit.html.erb index 19c4871..8c455d8 100644 --- a/app/views/employees/edit.html.erb +++ b/app/views/employees/edit.html.erb @@ -2,6 +2,20 @@

Update Employee

+<% if @employee.errors.any? %> +
+ +
<%= pluralize(@employee.errors.count, "error") %> prohibited this check from being saved:
+
+
    + <% @employee.errors.full_messages.each do |message| %> +
  • <%= message %>
  • + <% end %> +
+
+<% end %> + +
<%= form_with model: @employee do |form| %>
diff --git a/app/views/employees/new.html.erb b/app/views/employees/new.html.erb index 21a8310..4dc460c 100644 --- a/app/views/employees/new.html.erb +++ b/app/views/employees/new.html.erb @@ -2,6 +2,19 @@

New Employee

+<% if @employee.errors.any? %> +
+ +
<%= pluralize(@employee.errors.count, "error") %> prohibited this check from being saved:
+
+
    + <% @employee.errors.full_messages.each do |message| %> +
  • <%= message %>
  • + <% end %> +
+
+<% end %> +
<%= form_with model: @employee do |form| %>
@@ -21,7 +34,7 @@
<%= label_tag 'private_number', 'Private Number:'%> - <%= form.text_field :private_number, class:'form-control', value: @private_number, disabled: true%> + <%= form.text_field :private_number, class:'form-control'%>
<%= submit_tag "Add Employee", class:"btn btn-outline-success"%> From 2a6c34da25054d490109b13e2bc6fc7e24663872 Mon Sep 17 00:00:00 2001 From: Karina Delgado Date: Mon, 23 Nov 2020 00:06:03 -0600 Subject: [PATCH 4/8] Checking some issues with login and bootstrap Co-authored-by: danielasotomayor99 --- app/controllers/sessions_controller.rb | 2 +- app/javascript/packs/application.sass | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 2cfa3b6..8ff3a7c 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -7,7 +7,7 @@ def new def create @admin = Admin.find_by(user: params[:user]) - if @admin && @admin.authenticate(params[:password]) + if @admin || @admin.authenticate(params[:password]) session[:admin_id] = @admin.id redirect_to '/welcome', success: "You have singed in successfully!" else diff --git a/app/javascript/packs/application.sass b/app/javascript/packs/application.sass index c36a09b..74e29e8 100644 --- a/app/javascript/packs/application.sass +++ b/app/javascript/packs/application.sass @@ -1,2 +1,2 @@ -@import "bootstrap"; \ No newline at end of file +//@import "bootstrap"; \ No newline at end of file From e5d79a80b3acf770976e02abe27c756655ed347e Mon Sep 17 00:00:00 2001 From: Karina Delgado Date: Mon, 23 Nov 2020 13:37:47 -0600 Subject: [PATCH 5/8] Alerts for employees#new fixed Co-authored-by: danielasotomayor99 --- app/assets/stylesheets/application.css | 6 +++++- app/controllers/employees_controller.rb | 11 +---------- app/models/employee.rb | 8 ++++---- app/views/employees/new.html.erb | 23 ++++++++++------------- 4 files changed, 20 insertions(+), 28 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index ade9f04..f777a4f 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -14,7 +14,11 @@ *= require_self */ -.alert-notice{ +.alert-notice { + display: none; +} + +.alert-alert { display: none; } diff --git a/app/controllers/employees_controller.rb b/app/controllers/employees_controller.rb index be31e2c..3371420 100644 --- a/app/controllers/employees_controller.rb +++ b/app/controllers/employees_controller.rb @@ -1,7 +1,6 @@ class EmployeesController < ApplicationController before_action :current_employee, only: [:show, :edit, :update] - before_action :validate_private_num, only: [:create] def index @employees = Employee.all @@ -20,7 +19,7 @@ def create @employee.save! redirect_to employees_path else - redirect_to new_employee_path, alert: 'Private number already exist' + redirect_to new_employee_path, alert: 'Verify all the fields' end end @@ -46,12 +45,4 @@ def employee_params def current_employee @employee = Employee.find(params[:id]) end - - def validate_private_num - @pnumber = params[:private_number] - if Employee.exists?(private_number: @pnumber) == true - flash[:alert] = "Private number already exist" - end - end - end diff --git a/app/models/employee.rb b/app/models/employee.rb index ad9b1b3..e3db441 100644 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -1,6 +1,6 @@ class Employee < ApplicationRecord -has_many :reports -validates :name, presence: true -validates :position, presence: true -validates :private_number, presence: true, length: { is: 6 }, numericality: { only_integer: true }, uniqueness: true + has_many :reports + validates :name, presence: true + validates :position, presence: true + validates :private_number, presence: true, length: { is: 6 }, numericality: { only_integer: true }, uniqueness: true end diff --git a/app/views/employees/new.html.erb b/app/views/employees/new.html.erb index 4dc460c..8fb8a1d 100644 --- a/app/views/employees/new.html.erb +++ b/app/views/employees/new.html.erb @@ -2,22 +2,12 @@

New Employee

-<% if @employee.errors.any? %> -
- -
<%= pluralize(@employee.errors.count, "error") %> prohibited this check from being saved:
-
-
    - <% @employee.errors.full_messages.each do |message| %> -
  • <%= message %>
  • - <% end %> -
-
-<% end %> -
<%= form_with model: @employee do |form| %>
+ <%= label_tag 'name', 'Name:'%> <%= form.text_field :name, class:'form-control'%>
@@ -34,9 +24,16 @@
<%= label_tag 'private_number', 'Private Number:'%> +

<%= form.text_field :private_number, class:'form-control'%> +
<%= submit_tag "Add Employee", class:"btn btn-outline-success"%> + <% end %>
\ No newline at end of file From ee3f767b40229b11d21d01cf57592d823cabd9c6 Mon Sep 17 00:00:00 2001 From: Karina Delgado Date: Mon, 30 Nov 2020 19:00:06 -0600 Subject: [PATCH 6/8] Identation fixed --- app/assets/stylesheets/application.css | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index f777a4f..a287797 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -15,26 +15,26 @@ */ .alert-notice { - display: none; + display: none; } .alert-alert { - display: none; + display: none; } .notif { - position: absolute !important; - right: 1rem; - top: 1rem; + position: absolute !important; + right: 1rem; + top: 1rem; } #clock { - max-width: 256px; - max-height: 256px; + max-width: 256px; + max-height: 256px; } #error_explanation { - position: absolute; - top: 1rem; - right: 1rem; + position: absolute; + top: 1rem; + right: 1rem; } From 1c651ae9a397f33e1d196c4a760062094fda0a0d Mon Sep 17 00:00:00 2001 From: Karina Delgado Date: Mon, 30 Nov 2020 19:02:17 -0600 Subject: [PATCH 7/8] Private number column re-added --- db/migrate/20201105185421_add_active_to_branches.rb | 1 + db/migrate/20201130195540_remove_private_number_employees.rb | 5 +++++ db/migrate/20201130195654_add_private_number_to_employees.rb | 5 +++++ db/schema.rb | 4 ++-- 4 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20201130195540_remove_private_number_employees.rb create mode 100644 db/migrate/20201130195654_add_private_number_to_employees.rb diff --git a/db/migrate/20201105185421_add_active_to_branches.rb b/db/migrate/20201105185421_add_active_to_branches.rb index 56287fe..d7792e0 100644 --- a/db/migrate/20201105185421_add_active_to_branches.rb +++ b/db/migrate/20201105185421_add_active_to_branches.rb @@ -3,3 +3,4 @@ def change add_column :branches, :active, :boolean end end + diff --git a/db/migrate/20201130195540_remove_private_number_employees.rb b/db/migrate/20201130195540_remove_private_number_employees.rb new file mode 100644 index 0000000..53d6aa0 --- /dev/null +++ b/db/migrate/20201130195540_remove_private_number_employees.rb @@ -0,0 +1,5 @@ +class RemovePrivateNumberEmployees < ActiveRecord::Migration[6.0] + def change + remove_column :employees, :private_number + end +end diff --git a/db/migrate/20201130195654_add_private_number_to_employees.rb b/db/migrate/20201130195654_add_private_number_to_employees.rb new file mode 100644 index 0000000..ee6201f --- /dev/null +++ b/db/migrate/20201130195654_add_private_number_to_employees.rb @@ -0,0 +1,5 @@ +class AddPrivateNumberToEmployees < ActiveRecord::Migration[6.0] + def change + add_column :employees, :private_number, :int + end +end diff --git a/db/schema.rb b/db/schema.rb index 0c8fdab..11356c7 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: 2020_11_07_234808) do +ActiveRecord::Schema.define(version: 2020_11_30_195654) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -34,10 +34,10 @@ t.string "name" t.string "email" t.string "position" - t.integer "private_number" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.boolean "status", default: true + t.integer "private_number" end create_table "reports", force: :cascade do |t| From a5db09955f306a87c1c52273e60f986095edd238 Mon Sep 17 00:00:00 2001 From: Karina Delgado Date: Tue, 1 Dec 2020 11:08:13 -0600 Subject: [PATCH 8/8] Comment removed --- db/schema.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 031c6e8..ee6570e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -33,10 +33,6 @@ t.string "name" t.string "email" t.string "position" -<<<<<<< HEAD -======= - t.integer "private_number" ->>>>>>> 7a0f3000b243c4f7c5373bb3968c353e105b09ca t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.boolean "status", default: true