-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
331 additions
and
70 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
module ApplicationHelper | ||
include Pagy::Frontend | ||
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,9 @@ | ||
module PaginationHelper | ||
def pagy_next(pagy) | ||
pagy_url_for(pagy, pagy.next, absolute: false) | ||
end | ||
|
||
def pagy_prev(pagy) | ||
pagy_url_for(pagy, pagy.prev, absolute: false) | ||
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,25 @@ | ||
# frozen_string_literal: true | ||
|
||
class ApplicationQuery | ||
def self.call(...) | ||
new(...).call | ||
end | ||
|
||
def default_order = asc_order | ||
|
||
def asc_order | ||
:created_at | ||
end | ||
|
||
def desc_order | ||
{ created_at: :desc } | ||
end | ||
|
||
def updated_at_asc_order | ||
:updated_at | ||
end | ||
|
||
def updated_at_desc_order | ||
{ updated_at: :desc } | ||
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,18 @@ | ||
# frozen_string_literal: true | ||
|
||
class OpportunitiesQuery < ApplicationQuery | ||
def initialize(relation = Job.all) | ||
@relation = relation | ||
end | ||
|
||
def call | ||
@relation.eager_load(*associations) | ||
# .order(desc_order) | ||
end | ||
|
||
private | ||
|
||
def associations | ||
%i[requirement company locations countries roles] | ||
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,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class ApplicationTask | ||
def self.call(...) | ||
new(...).call | ||
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,54 @@ | ||
# frozen_string_literal: true | ||
|
||
class OpportunitiesFetcher < ApplicationTask | ||
def initialize(opportunities, params) | ||
@opportunities = opportunities | ||
@params = params.to_h | ||
end | ||
|
||
def call | ||
return false unless processable | ||
|
||
process | ||
end | ||
|
||
private | ||
|
||
def processable | ||
true | ||
end | ||
|
||
def process | ||
# simple_query || full_search_query | ||
plain_query | ||
end | ||
|
||
def plain_query | ||
OpportunitiesQuery.call(@opportunities) | ||
end | ||
|
||
# def plain_query | ||
# filtered_jobs = JobFilter.new(@params, @opportunities).filter_and_sort | ||
|
||
# @jobs = filtered_jobs.eager_load(associated_tables) | ||
# .order(sort_order(params[:sort])) | ||
# # .page(params[:page]) | ||
# end | ||
|
||
# def associated_tables | ||
# %i[requirement company locations countries] | ||
# end | ||
|
||
# def sort_order(sort_param) | ||
# sort_options = { | ||
# 'title' => 'jobs.title ASC', | ||
# 'title_desc' => 'jobs.title DESC', | ||
# 'company' => 'companies.name ASC', | ||
# 'company_desc' => 'companies.name DESC', | ||
# 'created_at' => 'jobs.created_at DESC', | ||
# 'created_at_asc' => 'jobs.created_at ASC' | ||
# }.freeze | ||
|
||
# sort_options.fetch(sort_param, 'jobs.created_at DESC') | ||
# 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,98 @@ | ||
# frozen_string_literal: true | ||
|
||
class OpportunityFacetsBuilder < ApplicationTask | ||
def initialize(opportunities, params) | ||
@opportunities = opportunities | ||
@params = params.to_h | ||
end | ||
|
||
def call | ||
return false unless processable | ||
|
||
process | ||
end | ||
|
||
private | ||
|
||
def processable | ||
true | ||
end | ||
|
||
def process | ||
build_facets | ||
end | ||
|
||
def build_facets | ||
@facets = {} | ||
build_posted_array | ||
build_seniority_array | ||
build_location_array | ||
build_role_array | ||
build_employment_array | ||
@facets | ||
end | ||
|
||
def build_posted_array | ||
date_cutoffs = Constants::DateConversion::CONVERT_TO_DAYS.transform_values { |v| v.days.ago.beginning_of_day } | ||
results = date_cutoffs.map do |period, cutoff| | ||
period_id = period.downcase.gsub(/last |within a /, '').gsub(' ', '-') | ||
count = @opportunities.where(date_posted: cutoff..Date.today).count | ||
params = @params[:posted] ? @params[:posted].include?(period_id) : period == 'Any time' | ||
|
||
['radio', period, period_id, count, params] | ||
end.compact | ||
@facets['posted'] = results | ||
end | ||
|
||
def build_seniority_array | ||
results = @opportunities.group(:seniority).count.map do |seniority, count| | ||
next unless seniority | ||
|
||
seniority_id = seniority.downcase.split.first | ||
params = @params[:seniority]&.include?(seniority_id) | ||
|
||
['checkbox', seniority, seniority_id, count, params] | ||
end.compact | ||
@facets['seniority'] = sort_by_count_desc(results) | ||
end | ||
|
||
def build_location_array | ||
results = @opportunities.group(:'locations.city').count.map do |location, count| | ||
location_id = location ? location.downcase.gsub(' ', '_') : 'remote' | ||
params = location ? @params[:location]&.include?(location_id) : @params[:location]&.include?('remote') | ||
location ||= 'Remote' | ||
|
||
['checkbox', location, location_id, count, params] | ||
end.compact | ||
@facets['location'] = sort_by_count_desc(results) | ||
end | ||
|
||
def build_role_array | ||
results = @opportunities.group(:'roles.name').count.map do |role, count| | ||
next unless role | ||
|
||
role_id = role | ||
params = @params[:role]&.include?(role_id) | ||
role = role.titleize | ||
|
||
['checkbox', role, role_id, count, params] | ||
end.compact | ||
@facets['role'] = sort_by_count_desc(results) | ||
end | ||
|
||
def build_employment_array | ||
results = @opportunities.group(:employment_type).count.map do |employment, count| | ||
next unless employment | ||
|
||
employment_id = employment.downcase.gsub('-', '_') | ||
params = @params[:employment]&.include?(employment_id) | ||
|
||
['checkbox', employment, employment_id, count, params] | ||
end.compact | ||
@facets['employment'] = sort_by_count_desc(results) | ||
end | ||
|
||
def sort_by_count_desc(data) | ||
data.sort_by { |item| -item[3] } | ||
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
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,29 @@ | ||
<% social_links = [ | ||
{ | ||
sr_text: 'Follow us on X', | ||
icon_name: 'logos/x' | ||
}, | ||
{ | ||
sr_text: 'Follow us on Github', | ||
icon_name: 'logos/github' | ||
}, | ||
{ | ||
sr_text: 'Join our Discord server', | ||
icon_name: 'logos/discord' | ||
}, | ||
] %> | ||
<footer class="mx-auto w-full max-w-2xl space-y-10 pb-16 lg:max-w-5xl"> | ||
<div class="flex"> | ||
<div class="flex flex-col items-start gap-3"> | ||
<% if defined?(prev_options)%> | ||
<%= link_to prev_options[:link_path], class: button_klasses(theme: :zinc) do %> | ||
<%= inline_svg_tag('template/icons/left_arrow.svg') %> Previous | ||
<div class="flex flex-col items-center justify-between gap-5 border-t border-zinc-900/5 pt-8 sm:flex-row dark:border-white/5"> | ||
<p class="text-xs text-zinc-600 dark:text-zinc-400"> | ||
© Copyright 2024. All rights reserved. | ||
</p> | ||
<div class="flex gap-4"> | ||
<% social_links.each do |link| %> | ||
<%= link_to '#', class: 'group' do %> | ||
<span class="sr-only"><%= link[:sr_text] %></span> | ||
<%= inline_svg_tag("template/icons/#{link[:icon_name]}.svg") %> | ||
<% end %> | ||
<%= link_to prev_options[:title], prev_options[:link_path], tab_index: -1, aria_hidden: true, class: 'text-base font-semibold text-zinc-900 transition hover:text-zinc-600 dark:text-white dark:hover:text-zinc-300' %> | ||
<% end %> | ||
</div> | ||
<div class="ml-auto flex flex-col items-end gap-3"> | ||
<% if defined?(next_options) %> | ||
<%= link_to next_options[:link_path], class: button_klasses(theme: :zinc) do %> | ||
Next <%= inline_svg_tag('template/icons/right_arrow.svg') %> | ||
<% end %> | ||
<%= link_to next_options[:title], next_options[:link_path], tab_index: -1, aria_hidden: true, class: 'text-base font-semibold text-zinc-900 transition hover:text-zinc-600 dark:text-white dark:hover:text-zinc-300' %> | ||
<% end %> | ||
</div> | ||
</div> | ||
<%= render 'shared/template/small_print' %> | ||
</footer> |
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,27 @@ | ||
<nav class="flex items-center justify-between border-t border-gray-200 dark:border-gray-800 bg-white dark:bg-zinc-900 px-4 py-3 sm:px-6" aria-label="Pagination"> | ||
<div class="invisible md:visible sm:block"> | ||
<p class="text-sm text-gray-700 dark:text-gray-500"> | ||
Showing | ||
<!-- space --> | ||
<span class="font-medium"><%= pagy.from %></span> | ||
<!-- space --> | ||
to | ||
<!-- space --> | ||
<span class="font-medium"><%= pagy.to %></span> | ||
<!-- space --> | ||
of | ||
<!-- space --> | ||
<span class="font-medium"><%= pagy.count %></span> | ||
<!-- space --> | ||
results | ||
</p> | ||
</div> | ||
<div class="flex flex-2 justify-between sm:justify-end"> | ||
<%= link_to pagy_prev(pagy), class: button_klasses(theme: :zinc) do %> | ||
<%= inline_svg_tag('template/icons/left_arrow.svg') %> Previous | ||
<% end %> | ||
<%= link_to pagy_next(pagy), class: button_klasses(theme: :zinc) do %> | ||
Next <%= inline_svg_tag('template/icons/right_arrow.svg') %> | ||
<% end %> | ||
</div> | ||
</nav> |
File renamed without changes.
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
Oops, something went wrong.