Commit cd4fd2f1 by Tô Ngọc Ánh

Apply decorator pattern for applied_job created_at

parent 4be6e76a
Pipeline #1078 failed with stages
in 0 seconds
...@@ -72,4 +72,5 @@ gem 'devise' ...@@ -72,4 +72,5 @@ gem 'devise'
gem 'carrierwave', '~> 2.0' gem 'carrierwave', '~> 2.0'
gem 'rsolr' gem 'rsolr'
gem 'settingslogic' gem 'settingslogic'
gem 'draper'
## ##
...@@ -29,6 +29,10 @@ GEM ...@@ -29,6 +29,10 @@ GEM
globalid (>= 0.3.6) globalid (>= 0.3.6)
activemodel (5.2.4.3) activemodel (5.2.4.3)
activesupport (= 5.2.4.3) activesupport (= 5.2.4.3)
activemodel-serializers-xml (1.0.2)
activemodel (> 5.x)
activesupport (> 5.x)
builder (~> 3.1)
activerecord (5.2.4.3) activerecord (5.2.4.3)
activemodel (= 5.2.4.3) activemodel (= 5.2.4.3)
activesupport (= 5.2.4.3) activesupport (= 5.2.4.3)
...@@ -92,6 +96,12 @@ GEM ...@@ -92,6 +96,12 @@ GEM
dotenv-rails (2.7.6) dotenv-rails (2.7.6)
dotenv (= 2.7.6) dotenv (= 2.7.6)
railties (>= 3.2) railties (>= 3.2)
draper (4.0.1)
actionpack (>= 5.0)
activemodel (>= 5.0)
activemodel-serializers-xml (>= 1.0)
activesupport (>= 5.0)
request_store (>= 1.0)
erubi (1.9.0) erubi (1.9.0)
execjs (2.7.0) execjs (2.7.0)
faraday (1.0.1) faraday (1.0.1)
...@@ -177,6 +187,8 @@ GEM ...@@ -177,6 +187,8 @@ GEM
rb-inotify (0.10.1) rb-inotify (0.10.1)
ffi (~> 1.0) ffi (~> 1.0)
regexp_parser (1.7.1) regexp_parser (1.7.1)
request_store (1.5.0)
rack (>= 1.4)
responders (3.0.1) responders (3.0.1)
actionpack (>= 5.0) actionpack (>= 5.0)
railties (>= 5.0) railties (>= 5.0)
...@@ -250,6 +262,7 @@ DEPENDENCIES ...@@ -250,6 +262,7 @@ DEPENDENCIES
coffee-rails (~> 4.2) coffee-rails (~> 4.2)
devise devise
dotenv-rails dotenv-rails
draper
jbuilder (~> 2.5) jbuilder (~> 2.5)
kaminari kaminari
listen (>= 3.0.5, < 3.2) listen (>= 3.0.5, < 3.2)
......
...@@ -11,7 +11,7 @@ class UsersController < ApplicationController ...@@ -11,7 +11,7 @@ class UsersController < ApplicationController
return unless current_user.admin return unless current_user.admin
get_data_search_bar get_data_search_bar
@applied_jobs = AppliedJob.includes(:job).order(created_at: :desc).page(params[:page]) @applied_jobs = AppliedJob.includes(:job).order(created_at: :desc).page(params[:page]).decorate
end end
private private
......
class ApplicationDecorator < Draper::Decorator
# Define methods for all decorated objects.
# Helpers are accessed through `helpers` (aka `h`). For example:
#
# def percent_amount
# h.number_to_percentage object.amount, precision: 2
# end
end
class AppliedJobDecorator < Draper::Decorator
delegate_all
# Define presentation-specific methods here. Helpers are accessed through
# `helpers` (aka `h`). You can override attributes, for example:
#
# def created_at
# helpers.content_tag :span, class: 'time' do
# object.created_at.strftime("%a %m/%d/%y")
# end
# end
def self.collection_decorator_class
PaginatingDecorator
end
def created_at
object.created_at.localtime.strftime('%d/%m/%y - %H:%M')
end
end
class PaginatingDecorator < Draper::CollectionDecorator
delegate :current_page, :total_pages, :limit_value, :entry_name, :total_count, :offset_value, :last_page?
end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<div class = "col-lg-2"> <div class = "col-lg-2">
<div class="card-body"> <div class="card-body">
<p><strong>Applied at: </strong></p> <p><strong>Applied at: </strong></p>
<span><%= applied_job.created_at.localtime.strftime('%d/%m/%y - %H:%M') %></span> <span><%= applied_job.created_at %></span>
</div> </div>
</div> </div>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment