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

Show vacancy to moderators #51

Open
wants to merge 3 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
/coverage
.idea
.ruby-version
.ruby-gemset
.env.dev
.env.development
1 change: 1 addition & 0 deletions apps/moderation/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Application < Hanami::Application
# When you add new directories, remember to add them here.
#
load_paths << %w[
helpers
controllers
views
]
Expand Down
2 changes: 2 additions & 0 deletions apps/moderation/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

root to: 'dashboard#index'

get 'vacancy/:id', to: 'dashboard#show'
Copy link
Author

Choose a reason for hiding this comment

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

Не очень уверен в правильности такого решения.
Просто как самая простая опция.


resources :vacancy_approve, only: %i[update]
resources :vacancy_disapprove, only: %i[update]
28 changes: 28 additions & 0 deletions apps/moderation/controllers/dashboard/show.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

module Moderation
module Controllers
module Dashboard
class Show
include Moderation::Action
include Dry::Monads::Result::Mixin
include Import[
operation: 'vacancies.operations.vacancy_for_moderation'
]

expose :vacancy

def call(params)
result = operation.call(id: params[:id])

case result
when Success
@vacancy = result.value!
when Failure
redirect_to routes.root_path
end
end
end
end
end
end
83 changes: 83 additions & 0 deletions apps/moderation/helpers/vacancy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# frozen_string_literal: true

module Moderation
module Helpers
module Vacancy
def approve_button(id)
html.form(action: routes.vacancy_approve_path(id), method: 'POST') do
input(type: 'hidden', name: '_method', value: 'PATCH')
input(type: 'submit', value: 'Принять', class: 'btn btn-success')
end
end

def disapprove_button(id)
html.form(action: routes.vacancy_disapprove_path(id), method: 'POST') do
input(type: 'hidden', name: '_method', value: 'PATCH')
input(type: 'submit', value: 'Отклонить', class: 'btn btn-warning')
end
end

def company_text(vacancy)
published_at = RelativeTime.in_words(vacancy.created_at, locale: :ru)
raw "Компания #{company_link(vacancy)} (#{vacancy.location}), опубликована #{published_at}"
end

def company_link(vacancy)
if vacancy.contact.site
link_to vacancy.contact.company, vacancy.contact.site
else
vacancy.contact.company
end
end

def remote_badge(vacancy)
return unless vacancy.remote_available

html.span(class: 'mr-2 badge badge-success') { 'Удаленно' }
end

def position_type_badge(vacancy)
html.span(class: 'mr-2 badge badge-info') { POSITION_TYPE_VALUES[vacancy.position_type] }
end

def vacancy_salary_information(vacancy)
currency = CURRENCY_VALUES[vacancy.salary_currency]
unit = UNIT_VALUES[vacancy.salary_unit]

html.span(class: 'salary') do
text 'от '
span(class: 'money') { vacancy.salary_min }
text ' до '
span(class: 'money') { vacancy.salary_max }
text " #{currency} #{unit}"
end
end

POSITION_TYPE_VALUES = {
'full_time' => 'Полная занятость',
'part_time' => 'Частичная занятость',
'contractor' => 'Работа по контракту',
'intern' => 'Интернатура',
'temp' => 'Временная работа',
'other' => 'Другое'
}.freeze

CURRENCY_VALUES = { 'rub' => 'рублей', 'usd' => 'долларов', 'eur' => 'евро' }.freeze

UNIT_VALUES = {
'monthly' => 'в месяц',
'yearly' => 'в год',
'by hour' => 'в час',
'per project' => 'за проект'
}.freeze

def vacancy_details(vacancy)
raw_body(vacancy.details)
end

def raw_body(body)
raw(body || '')
end
end
end
end
42 changes: 42 additions & 0 deletions apps/moderation/templates/dashboard/_vacancy.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
li.list-group-item
Copy link
Author

Choose a reason for hiding this comment

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

Опять же, вынес в партиал и использовал таким образом как самый простой вариант.

.row
.col-sm-8
h4 #{vacancy.position} (id: #{vacancy.id})
.col-sm-4
= vacancy_salary_information(vacancy)
.row
.col-sm-8
= company_text(vacancy)
.col-sm-4
= remote_badge(vacancy)
= position_type_badge(vacancy)

hr.mb-4.mt-4

.row
.col.vacancy_details
= vacancy_details(vacancy)

.row
.col
= vacancy.tags

hr.mb-4.mt-4

.row
.col
= vacancy.contact.email

.col
= vacancy.contact.full_name

hr.mb-4.mt-4

.row
.col.mb-4
= approve_button(vacancy.id)

.col.mb-4.btn-float-right
= disapprove_button(vacancy.id)

hr
43 changes: 1 addition & 42 deletions apps/moderation/templates/dashboard/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,4 @@ hr

ul.list-group
- vacancies.each do |vacancy|
li.list-group-item
.row
.col-sm-8
h4 #{vacancy.position} (id: #{vacancy.id})
.col-sm-4
= vacancy_salary_information(vacancy)
.row
.col-sm-8
= company_text(vacancy)
.col-sm-4
= remote_badge(vacancy)
= position_type_badge(vacancy)

hr.mb-4.mt-4

.row
.col.vacancy_details
= vacancy_details(vacancy)

.row
.col
= vacancy.tags

hr.mb-4.mt-4

.row
.col
= vacancy.contact.email

.col
= vacancy.contact.full_name

hr.mb-4.mt-4

.row
.col.mb-4
= approve_button(vacancy.id)

.col.mb-4.btn-float-right
= disapprove_button(vacancy.id)

hr
= render partial: 'vacancy', locals: {vacancy: vacancy}
5 changes: 5 additions & 0 deletions apps/moderation/templates/dashboard/show.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
h1 Moderation

hr

= render partial: 'vacancy'
77 changes: 1 addition & 76 deletions apps/moderation/views/dashboard/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,82 +5,7 @@ module Views
module Dashboard
class Index
include Moderation::View

def approve_button(id)
html.form(action: routes.vacancy_approve_path(id), method: 'POST') do
input(type: 'hidden', name: '_method', value: 'PATCH')
input(type: 'submit', value: 'Принять', class: 'btn btn-success')
end
end

def disapprove_button(id)
html.form(action: routes.vacancy_disapprove_path(id), method: 'POST') do
input(type: 'hidden', name: '_method', value: 'PATCH')
input(type: 'submit', value: 'Отклонить', class: 'btn btn-warning')
end
end

def company_text(vacancy)
published_at = RelativeTime.in_words(vacancy.created_at, locale: :ru)
raw "Компания #{company_link(vacancy)} (#{vacancy.location}), опубликована #{published_at}"
end

def company_link(vacancy)
if vacancy.contact.site
link_to vacancy.contact.company, vacancy.contact.site
else
vacancy.contact.company
end
end

def remote_badge(vacancy)
return unless vacancy.remote_available

html.span(class: 'mr-2 badge badge-success') { 'Удаленно' }
end

def position_type_badge(vacancy)
html.span(class: 'mr-2 badge badge-info') { POSITION_TYPE_VALUES[vacancy.position_type] }
end

def vacancy_salary_information(vacancy)
currency = CURRENCY_VALUES[vacancy.salary_currency]
unit = UNIT_VALUES[vacancy.salary_unit]

html.span(class: 'salary') do
text 'от '
span(class: 'money') { vacancy.salary_min }
text ' до '
span(class: 'money') { vacancy.salary_max }
text " #{currency} #{unit}"
end
end

POSITION_TYPE_VALUES = {
'full_time' => 'Полная занятость',
'part_time' => 'Частичная занятость',
'contractor' => 'Работа по контракту',
'intern' => 'Интернатура',
'temp' => 'Временная работа',
'other' => 'Другое'
}.freeze

CURRENCY_VALUES = { 'rub' => 'рублей', 'usd' => 'долларов', 'eur' => 'евро' }.freeze

UNIT_VALUES = {
'monthly' => 'в месяц',
'yearly' => 'в год',
'by hour' => 'в час',
'per project' => 'за проект'
}.freeze

def vacancy_details(vacancy)
raw_body(vacancy.details)
end

def raw_body(body)
raw(body || '')
end
include Moderation::Helpers::Vacancy
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions apps/moderation/views/dashboard/show.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module Moderation
module Views
module Dashboard
class Show
include Moderation::View
include Moderation::Helpers::Vacancy
end
end
end
end
20 changes: 15 additions & 5 deletions lib/core/repositories/vacancy_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def disapprove_by_pk(id)
end

def all_for_moderation
aggregate(:contact).where(
published: false,
archived: false,
deleted_at: nil
).map_to(Vacancy).to_a
for_modertion.map_to(Vacancy).to_a
end

def find_for_moderation(id)
for_modertion.by_pk(id).map_to(Vacancy).one
end

def find_with_contact(id)
Expand All @@ -33,4 +33,14 @@ def find_with_contact(id)
deleted_at: nil
).by_pk(id).map_to(Vacancy).one
end

private

def for_modertion
Copy link
Contributor

Choose a reason for hiding this comment

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

for_moderation, typo :-)

aggregate(:contact).where(
published: false,
archived: false,
deleted_at: nil
)
end
end
16 changes: 16 additions & 0 deletions lib/vacancies/operations/vacancy_for_moderation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Vacancies
module Operations
class VacancyForModeration < ::Libs::Operation
include Import[
vacancy_repo: 'repositories.vacancy'
]

def call(id:)
vacancy = vacancy_repo.find_for_moderation(id)
vacancy ? Success(vacancy) : Failure(:not_found)
end
end
end
end
Loading