-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from Prozak8/job_create
RSC can create a new job
- Loading branch information
Showing
24 changed files
with
203 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
class JobsController < ApplicationController | ||
def index | ||
@jobs = Job.all | ||
end | ||
|
||
def create | ||
job = Job.create(job_params) | ||
if job.persisted? | ||
redirect_to root_path, notice: 'The job was successfully created' | ||
else | ||
errors = job.errors.full_messages | ||
render json: { message: errors }, status: 422 | ||
end | ||
end | ||
|
||
def job_params | ||
params.require(:job).permit(:name, :profession, :hospital, :department, :license, :caretype, :scope, :working_hours, :date_start, :date_finish) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
class UsersController < ApplicationController | ||
def index | ||
end | ||
|
||
def new | ||
end | ||
def index; end | ||
|
||
def new; end | ||
|
||
def create | ||
user = User.create(user_params.merge(password: Devise.friendly_token[0, 20])) | ||
if user.persisted? | ||
redirect_to root_path, notice: "RSC user #{User.last.email} created, currently logged in as #{current_user.email}." | ||
message = " Currently logged in as #{current_user.email}" if user_signed_in? | ||
redirect_to root_path, notice: "RSC user #{User.last.email} created. #{message}." | ||
else | ||
redirect_to root_path, notice: "Invalid Email" | ||
errors = user.errors.full_messages | ||
render json: { message: errors }, status: 422 | ||
end | ||
end | ||
|
||
private | ||
|
||
def user_params | ||
params.require(:user).permit(:email) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
- content_for :modal_content do | ||
.card | ||
.inner-card | ||
.card-title | ||
%h1.text-center.mt-6 Create New Job | ||
= form_with scope: :job, url: jobs_path, id: :create_job do |form| | ||
#error_messages | ||
= form.label :name | ||
= form.text_field :name, placeholder: "Name", class: "add-field-placeholder" | ||
= form.label :profession | ||
= form.text_field :profession, placeholder: "Profession", class: "add-field-placeholder" | ||
= form.label :hospital | ||
= form.text_field :hospital, placeholder: "Hospital", class: "add-field-placeholder" | ||
= form.label :department | ||
= form.text_field :department, placeholder: "Department", class: "add-field-placeholder" | ||
= form.label :license | ||
= form.text_field :license, placeholder: "License/s", class: "add-field-placeholder" | ||
= form.label :caretype | ||
= form.text_field :caretype, placeholder: "Caretype", class: "add-field-placeholder" | ||
= form.label :scope | ||
= form.text_field :scope, placeholder: "Scope", class: "add-field-placeholder" | ||
= form.label :working_hours | ||
= form.text_field :working_hours, placeholder: "hours", class: "add-field-placeholder" | ||
= form.label :date_start | ||
= form.text_field :date_start, placeholder: "y/d/m", class: "add-field-placeholder" | ||
= form.label :date_finish | ||
= form.text_field :date_finish, placeholder: "y/d/m", class: "add-field-placeholder" | ||
= form.submit value: "Submit", class: "bg-blue hover:bg-blue-dark text-white font-bold py-2 px-4 my-4 rounded focus:outline-none focus:shadow-outline" | ||
= button_tag 'Cancel', id: 'cancel_modal', class: 'signup-button' | ||
= render partial: 'partials/modal' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
var modalContent = '<%= escape_javascript(render partial: 'new') %>' | ||
App.mainContent.style.visibility = "hidden"; | ||
App.tempContent.innerHTML = modalContent | ||
closeModalListener('cancel_modal') | ||
|
||
var form = document.getElementById('create_job') | ||
|
||
form.addEventListener('ajax:error', (event) => { | ||
let errorMessageDisplayElement = document.getElementById('error_messages') | ||
let message = event.detail[0].message | ||
errorMessageDisplayElement.innerHTML = message | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,9 +18,9 @@ | |
#content | ||
#temp_content | ||
#main_content | ||
= notice | ||
= alert | ||
= flash[:error] | ||
#messages | ||
= notice | ||
= alert | ||
= yield | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,22 @@ | ||
|
||
console.log('registration') | ||
|
||
var modalContent = '<%= escape_javascript(render partial: 'new') %>' | ||
App.mainContent.style.visibility = "hidden"; | ||
App.tempContent.innerHTML = modalContent | ||
closeModalListener('cancel_modal') | ||
closeModalListener('cancel_modal') | ||
|
||
|
||
var form = document.getElementById('create_user') | ||
|
||
form.addEventListener('ajax:error', (event) => { | ||
let errorMessageDisplayElement = document.getElementById('error_messages') | ||
let message = event.detail[0].message | ||
errorMessageDisplayElement.innerHTML = message | ||
}) | ||
|
||
form.addEventListener('ajax:success', (event) => { | ||
let errorMessageDisplayElement = document.getElementById('messages') | ||
let message = event.detail[0].message | ||
let model = document.getElementById('modal') | ||
errorMessageDisplayElement.innerHTML = message | ||
closeModal(modal) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddProfessionToJobs < ActiveRecord::Migration[5.2] | ||
def change | ||
add_column :jobs, :profession, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddHospitalToJobs < ActiveRecord::Migration[5.2] | ||
def change | ||
add_column :jobs, :hospital, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddDepartmentToJobs < ActiveRecord::Migration[5.2] | ||
def change | ||
add_column :jobs, :department, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddLicenseToJobs < ActiveRecord::Migration[5.2] | ||
def change | ||
add_column :jobs, :license, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddCaretypeToJobs < ActiveRecord::Migration[5.2] | ||
def change | ||
add_column :jobs, :caretype, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddScopeToJobs < ActiveRecord::Migration[5.2] | ||
def change | ||
add_column :jobs, :scope, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddWorkingHoursToJobs < ActiveRecord::Migration[5.2] | ||
def change | ||
add_column :jobs, :working_hours, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddDateStartToJobs < ActiveRecord::Migration[5.2] | ||
def change | ||
add_column :jobs, :date_start, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddDateFinishToJobs < ActiveRecord::Migration[5.2] | ||
def change | ||
add_column :jobs, :date_finish, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
@javascript | ||
Feature: Rsc can add new job | ||
As a RSC, | ||
In order to create jobs, | ||
I would like to click on the “+” button and fill in the jobs information. | ||
|
||
Background: Landing page, clicking new and being on form page | ||
Given I am on the landing page | ||
And I click on "Add New Job" | ||
|
||
Scenario: RSC creates a new job | ||
Then I should see "Create New Job" | ||
And I fill in job form | ||
And I click on "Submit" | ||
Then I should see "The job was successfully created" | ||
And I should see "Heart Surgeon" | ||
|
||
Scenario: RSC fills out form incorrectly | ||
And I fill in "Name" with " " | ||
And I click on "Submit" | ||
Then I should see "Name can't be blank" | ||
|
||
Scenario: RSC wants to add new job but decides not to | ||
And I click on "Cancel" | ||
Then I should be on the landing page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters