diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 18c2638..a287797 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -15,30 +15,26 @@ */ .alert-notice { - display: none; + display: none; } -.alert-info { - display: none; -} - -.alert-info { - display: none; +.alert-alert { + 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; } diff --git a/app/controllers/employees_controller.rb b/app/controllers/employees_controller.rb index 9219255..3371420 100644 --- a/app/controllers/employees_controller.rb +++ b/app/controllers/employees_controller.rb @@ -14,15 +14,14 @@ def new end def create - @employee = Employee.new(employee_params) - respond_to do |format| - if @employee.save - format.html { redirect_to employees_url, notice: 'Employee was successfully created.' } - else - format.html { render :new } - end - end + @employee = Employee.new(employee_params) + if @employee.valid? + @employee.save! + redirect_to employees_path + else + redirect_to new_employee_path, alert: 'Verify all the fields' end + end def edit end @@ -30,7 +29,7 @@ def edit def update respond_to do |format| if @employee.update(employee_params) - format.html { redirect_to employees_url, info: 'Employee was successfully updated.' } + format.html { redirect_to employees_url, notice: 'Employee was successfully updated.' } else format.html { render :edit } end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index bba78b1..e76caa3 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 e69de29..33507b5 100644 --- a/app/javascript/packs/application.sass +++ b/app/javascript/packs/application.sass @@ -0,0 +1,2 @@ + +//@import "bootstrap"; diff --git a/app/models/employee.rb b/app/models/employee.rb index 1ed1e03..e3db441 100644 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -1,7 +1,6 @@ class Employee < ApplicationRecord - has_many :reports, dependent: :destroy + has_many :reports validates :name, presence: true validates :position, presence: true - validates :private_number, presence: true - validates :email, 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..646ee6e 100644 --- a/app/views/employees/new.html.erb +++ b/app/views/employees/new.html.erb @@ -18,6 +18,9 @@
<%= form_with model: @employee do |form| %>
+ <%= label_tag 'name', 'Name:'%> <%= form.text_field :name, class:'form-control'%>
@@ -34,9 +37,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 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 75ebd6a..ee6570e 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_12_180413) 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" @@ -33,10 +33,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| diff --git a/db/seeds.rb b/db/seeds.rb index b894034..554cb2b 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -8,10 +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 = Admin.new(user: 'Karina') -admin.password = "12345" -admin.password_confirmation = "12345" -admin.save - + 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")