Skip to content

Commit

Permalink
Merge pull request #207 from Ches-ctrl/2024-07-01/bug_fixes
Browse files Browse the repository at this point in the history
Application Bug Fixes & Code Cleanup
  • Loading branch information
Ches-ctrl authored Jul 4, 2024
2 parents 08364a1 + 33c9277 commit e20a6ca
Show file tree
Hide file tree
Showing 44 changed files with 404 additions and 637 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,4 @@ doc/**
# Ignore DB backup
latest.dump

/app/assets/builds/*
!/app/assets/builds/.keep
/app/assets/builds/*
2 changes: 1 addition & 1 deletion app/assets/builds/tailwind.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/config/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
//= link_tree ../../../vendor/javascript .js
//= link popper.js
//= link bootstrap.min.js
//= link_tree ../builds
//= link_tree ../builds
8 changes: 7 additions & 1 deletion app/controllers/application_processes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ def build_application_process

def build_job_applications
@job_applications = job_applications_params[:job_ids].map do |job_id|
@application_process.job_applications.new(job_id:, additional_info: { email: @application_process.user.user_detail.email })
@application_process.job_applications.new(job_id:, additional_info: { email: @application_process.user.user_detail.email }, resume: last_resume)
end
end

def last_resume
return unless @application_process.user.user_detail.resumes.attached?

@application_process.user.user_detail.resumes.last.blob
end

def load_application_process
@application_process = ApplicationProcessesQuery.call(application_process_scope)
.find_by(id: application_process_id)
Expand Down
29 changes: 29 additions & 0 deletions app/controllers/attachments_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class AttachmentsController < ApplicationController
def destroy
load_attachment
destroy_attachment
end

private

def destroy_attachment
if @attachment.present?
@attachment.purge
success_redirect_to_referrer
else
error_redirect_to_referrer
end
end

def load_attachment
@attachment = ActiveStorage::Attachment.find(params.permit(:id)[:id])
end

def success_redirect_to_referrer
redirect_to request.referrer, notice: 'Attachment successfully removed!'
end

def error_redirect_to_referrer
redirect_to request.referrer, alert: 'Something went wrong, please try again'
end
end
42 changes: 41 additions & 1 deletion app/controllers/job_applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ def update
load_application_process
load_job_application
assign_job_application_params
assign_status
persist_job_application
end

def destroy
load_application_process
load_job_application
build_saved_job
destroy_job_application
end

private

def application_process_scope
Expand All @@ -21,6 +29,33 @@ def assign_job_application_params
@job_application.assign_attributes(job_application_params)
end

def assign_status
required_attributes = required_attributes(@job_application.job.application_criteria)
non_empty_or_null_attributes = non_empty_or_null_attributes(@job_application.additional_info)
status = (required_attributes - non_empty_or_null_attributes).empty? ? "completed" : "uncompleted"
@job_application.status = status
end

def non_empty_or_null_attributes(hash)
hash.select { |_key, value| !value.nil? && !value.empty? }.keys
end

def required_attributes(hash)
hash.select { |_key, value| value["required"] }.map { |_key, value| value["locators"] }
end

def build_saved_job
@saved_job = current_user.saved_jobs.new(job_id: @job_application.job_id)
end

def destroy_job_application
if @job_application.destroy && @saved_job.save
success_destroy_job_application_path
else
error_redirect_to_referrer
end
end

def load_application_process
@application_process = ApplicationProcessesQuery.call(application_process_scope)
.find(params[:application_process_id])
Expand All @@ -31,7 +66,8 @@ def load_job_application
end

def job_application_params
params.require(:job_application).permit(:application_process_id, :id, { additional_info: {} })
params.require(:job_application)
.permit(:application_process_id, :id, :resume, :cover_letter, { additional_info: {} })
end

def next_step_path
Expand All @@ -54,4 +90,8 @@ def persist_job_application
end

def save_job_application = @job_application.save

def success_destroy_job_application_path
redirect_to in_progress_jobs_path, notice: 'Job Application successfully removed!'
end
end
2 changes: 1 addition & 1 deletion app/controllers/opportunities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def load_opportunities
end

def opportunity_params
params.permit(:page, :posted, :query, :sort, { employment: [], location: [], role: [], seniority: [], ats: [] })
params.permit(:id, :page, :posted, :query, :sort, { employment: [], location: [], role: [], seniority: [], ats: [] })
end

# policy_scope(Job)
Expand Down
12 changes: 10 additions & 2 deletions app/controllers/user_details_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def update
load_user_detail
assign_user_detail_params
persist_user_detail
# attach_documents
end

private
Expand All @@ -15,8 +16,13 @@ def assign_user_detail_params
@user_detail.assign_attributes(user_detail_params)
end

def attach_documents
@user_detail.resumes.attach(user_detail_params[:resumes])
end

def load_user_detail
@user_detail = UserDetail.find_or_initialize_by(user_id: current_user.id)
@user_detail = UserDetail.with_attached_resumes
.find_or_initialize_by(user_id: current_user.id)
end

def persist_user_detail
Expand All @@ -30,6 +36,8 @@ def persist_user_detail
def save_user_detail = @user_detail.save

def user_detail_params
params.require(:user_detail).permit(UserDetail::FREQUENT_ASKED_INFO_ATTRIBUTES)
params.require(:user_detail)
.permit(UserDetail::FREQUENT_ASKED_INFO_ATTRIBUTES)
.merge(resumes: params.require(:user_detail)[:resumes])
end
end
6 changes: 6 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ def request_referrer_path
referrer_uri = URI(request.referrer)
referrer_uri.path
end

def filesize_in_mb(file)
file_size_in_bytes = file.byte_size
file_size_in_mb = (file_size_in_bytes.to_f / 1_048_576).round(2)
"#{file_size_in_mb}mb"
end
end
6 changes: 6 additions & 0 deletions app/helpers/application_processes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ def application_step_unstarted?(_step_id)
true
end

def job_application_by_job(jobs, job)
current_application_process(jobs)
.job_applications
.find_by('job_applications.job_id': job.id)
end

def first_job_application(jobs)
ApplicationProcess.find_by(id: current_application_process(jobs).id)
.job_applications.first
Expand Down
30 changes: 30 additions & 0 deletions app/helpers/job_applications_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module JobApplicationsHelper
def attachment_required_but_absent?(application_criteria, attachment)
application_criteria.required && !attachment.attached?
end

def mandatory_field(application_criteria)
application_criteria.required ? "* " : ""
end

def mandatory_fields_only_label(job_application)
total = job_application.job.application_criteria.count
optionals = optional_fields(job_application.job.application_criteria).count
"(#{optionals} out of #{total})"
end

def optional_fields(application_criteria)
application_criteria.reject do |attribute, criteria_hash|
application_criteria = ApplicationCriteria.new(criteria_hash.merge(attribute:))
application_criteria.required
end
end

def mandatory_fields_only_disability(job_application)
'disabled' if optional_fields(job_application.job.application_criteria).none?
end

def mandatory_fields_only_disability_cursor_class(job_application)
'!cursor-not-allowed ' if optional_fields(job_application.job.application_criteria).none?
end
end
5 changes: 1 addition & 4 deletions app/helpers/opportunity_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ def opportunity_days_remaining(opportunity)
end

def seniority_css(opportunity, seniority)
# TODO: Fix this once seniority is already defined (at the moment this manages nil values)
return nil unless opportunity.seniority&.include?(seniority)

' text-gray-300 dark:text-gray-700'
' text-gray-300 dark:text-gray-700' unless opportunity.seniority&.include?(seniority)
end
end
9 changes: 2 additions & 7 deletions app/helpers/payload_application_processes_helper.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
# Helper for building the payload page with reference JSON outputs
module PayloadApplicationProcessesHelper
def transformed_data(job_application)
# translator = ApiFormatTranslators::BaseAtsTranslator.create_translator(job_application)
# if translator
# translator.translate
# else
# "#{job_application.job.applicant_tracking_system.name} translator not found!"
# end

transformed_criteria = {}
job_application.job.application_criteria.each do |attribute, criteria_hash|
value = job_application.additional_info.fetch(criteria_hash['locators'], 'not_found')
value = job_application.resume.url if attribute.eql?('resume') && job_application.resume.attached?
value = job_application.cover_letter.url if attribute.include?('cover_letter') && job_application.cover_letter.attached?
transformed_criteria[attribute] = criteria_hash.merge(value:)
end
transformed_criteria.to_json
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import "@popperjs/core"
import "bootstrap"
import "tom-select"
import "canvas-confetti"
import "@rails/actioncable"
import "@rails/actioncable"
2 changes: 1 addition & 1 deletion app/javascript/controllers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ application.debug = false
window.Stimulus = application
window.process = { env: { NODE_ENV: "PRODUCTION" } }; // otherwise autocomplete.js doesn't load

export { application }
export { application }
33 changes: 33 additions & 0 deletions app/javascript/controllers/mandatory_fields_only_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Controller } from "@hotwired/stimulus"
import TomSelect from "tom-select"

// Connects to data-controller="select-university"
export default class extends Controller {
static targets = [ "button", "form", "field", "innerRound" ]

toggleHidden(event) {
const hidden = this.buttonTarget.getAttribute("aria-checked") === "false";
this.fieldTargets.forEach((field) => {
const isOptional = field.dataset.requiredValue === "false"; // Check for "false"

if (isOptional) {
field.hidden = hidden;
}
});

// Update button label based on hidden state (optional)
if (hidden) {
this.buttonTarget.classList.remove("bg-gray-200");
this.buttonTarget.classList.add("bg-indigo-600");
this.innerRoundTarget.classList.remove("translate-x-0");
this.innerRoundTarget.classList.add("translate-x-5");
this.buttonTarget.setAttribute("aria-checked", "true");
} else {
this.buttonTarget.classList.remove("bg-indigo-600");
this.buttonTarget.classList.add("bg-gray-200");
this.innerRoundTarget.classList.remove("translate-x-5");
this.innerRoundTarget.classList.add("translate-x-0");
this.buttonTarget.setAttribute("aria-checked", "false");
}
}
}
27 changes: 13 additions & 14 deletions app/javascript/controllers/template/basket_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ export default class extends Controller {
static targets = ["form", "mainCheckbox", "applyButton", "checkbox"];

connect() {
// Set up event listener for the main checkbox
this.mainCheckboxTarget.addEventListener("change", (event) => {
this.handleMainCheckboxChange(event);
});

// Set up event listeners on all checkboxes (including main checkbox)
this.checkboxTargets.forEach(checkbox => {
// checkbox.addEventListener("change", this.handleCheckboxChange);
checkbox.addEventListener("change", (event) => {
this.handleCheckboxChange(event);
});
});
// Set initial state of apply button (likely disabled)
// this.applyButtonTarget.disabled = true;
if (this.hasMainCheckboxTarget) {
// Set up event listener for the main checkbox
this.mainCheckboxTarget.addEventListener("change", (event) => {
this.handleMainCheckboxChange(event);
});

// Set up event listeners on all checkboxes (including main checkbox)
this.checkboxTargets.forEach(checkbox => {
checkbox.addEventListener("change", (event) => {
this.handleCheckboxChange(event);
});
});
}
}

handleCheckboxChange(event) {
Expand Down
9 changes: 6 additions & 3 deletions app/models/application_criteria.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ def initialize(criteria_hash)
# == Relationships ========================================================
# == Scopes ===============================================================
# == Validations ==========================================================

def checkbox? = interaction.eql?("checkbox")
def cover_letter? = attribute.include?("cover_letter")
def input? = interaction.eql?("input")
def upload? = interaction.eql?("upload")
def radiogroup? = interaction.eql?("radiogroup")
def resume? = attribute.eql?("resume")
def select? = interaction.eql?("select")
def textarea? = interaction.eql?("textarea")
def radiogroup? = interaction.eql?("radiogroup")
def checkbox? = interaction.eql?("checkbox")
def upload? = interaction.eql?("upload")

def value(json)
json&.dig(locators)
Expand Down
10 changes: 2 additions & 8 deletions app/models/concerns/ats/greenhouse/application_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,11 @@ def get_application_criteria(job, _data)
},
city: {
interaction: :input,
locators: 'job_application[location]',
required: true,
locators: 'location',
required: false,
label: 'Location (City)',
core_field: true
},
location_click: {
interaction: :listbox,
locators: 'ul#location_autocomplete-items-popup',
label: 'location_click',
core_field: true
},
resume: {
interaction: :upload,
locators: 'button[aria-describedby="resume-allowable-file-types"',
Expand Down
Loading

0 comments on commit e20a6ca

Please sign in to comment.