Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature#37 add private number #44

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
17 changes: 8 additions & 9 deletions app/controllers/employees_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,22 @@ 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

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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/javascript/packs/application.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

//@import "bootstrap";
5 changes: 2 additions & 3 deletions app/models/employee.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions app/views/employees/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<div class="container p-3 my-3 border">
<%= form_with model: @employee do |form| %>
<div class="form-group">
<div class="alert alert-primary" role="alert">
All fields are required
</div>
<%= label_tag 'name', 'Name:'%>
<%= form.text_field :name, class:'form-control'%>
</div>
Expand All @@ -34,9 +37,16 @@

<div class="form-group">
<%= label_tag 'private_number', 'Private Number:'%>
<div class="alert alert-primary" role="alert">
Private Number should be:
<p class="mb-0">- Numeric</p>
<p class="mb-0">- 6 digits long</p>
<p class="mb-0">- Unique </div></p>
<%= form.text_field :private_number, class:'form-control'%>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think manually setting the employee number is good. Why not automatically assign an employee number using a generator?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We thought about that and we had a lot of trouble and because of time decided to implement it manually.


</div>

<%= submit_tag "Add Employee", class:"btn btn-outline-success"%>

<% end %>
</div>
1 change: 1 addition & 0 deletions db/migrate/20201105185421_add_active_to_branches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ def change
add_column :branches, :active, :boolean
end
end

5 changes: 5 additions & 0 deletions db/migrate/20201130195540_remove_private_number_employees.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemovePrivateNumberEmployees < ActiveRecord::Migration[6.0]
def change
remove_column :employees, :private_number
end
end
5 changes: 5 additions & 0 deletions db/migrate/20201130195654_add_private_number_to_employees.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPrivateNumberToEmployees < ActiveRecord::Migration[6.0]
def change
add_column :employees, :private_number, :int
end
end
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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|
Expand Down
6 changes: 1 addition & 5 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

# Employee.create(name: 'Karina Delgado', email: '[email protected]', position: 'QA', private_number: 123, status: 'active')
# Employee.create(name: 'Daniela Sotomayor', email: '[email protected]', 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')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you verify this seeds to be creating valid users?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we had mentorship for that

# Branch.create(name: 'HR', address: '3rd Floor')
# Report.create(check: 'check in', check_time: "2016-11-01 17:00:13", employee_id: "1")