voluntary_recruiting 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 55641eb467512030495e3b1ba5ec426c2a6931c8
4
- data.tar.gz: d862958729d6ef4314c52131cae3a7e12870ff3f
3
+ metadata.gz: c15d4b2c1d7fc57914c9e1595fb99c484a4cff30
4
+ data.tar.gz: 443f3fe702622964d81122c9a1d37fc8c68fb272
5
5
  SHA512:
6
- metadata.gz: c6324e15b2116153d8238452a734d8cfe78149259831ce08d74a169ec74fec222751a9cdc15f0438241a42fb93ab9e2577d8abca87a99e1ef1b6206edd1d168d
7
- data.tar.gz: 5d8ffcd55f363825e16f6f7b498ff010021af1922303e59968d268fc5ee923d67e0c45afb6085f24bc5d626ba77397c9ec8931f53414b10582bfd6177a5de43a
6
+ metadata.gz: 1af84f578a3606ca7323d310a576a15dfa60a4f7e6d901587f485d3cdd34eeddd3ba23e9b1e87ce08d4223ef24b2eba7cf8ff291ee385a9f3269cbba64537cd3
7
+ data.tar.gz: 6472041859cf05dcd96559c421eed238ca481e68f68a4526ccea53c4d6c0864c8873406a738790d866cd9facdb0d7eab8815a27617eeca6fede4474e561d2c9b
@@ -34,6 +34,7 @@ class CandidaturesController < ApplicationController
34
34
  @candidature = Candidature.new(params[:candidature])
35
35
  @candidature.resource_type = 'User'
36
36
  @candidature.resource_id = current_user.id
37
+ @candidature.user_id = current_user.id
37
38
 
38
39
  if @candidature.save
39
40
  redirect_to @candidature, notice: t('general.form.successfully_created')
@@ -75,10 +76,10 @@ class CandidaturesController < ApplicationController
75
76
  private
76
77
 
77
78
  def find_candidature
78
- @candidature = Candidature.includes(:vacancy, :resource, :comments).friendly.find(params[:id])
79
+ @candidature = Candidature.includes(:vacancy, :resource, :comments).find(params[:id])
79
80
  end
80
81
 
81
82
  def find_vacancy
82
- @vacancy = params[:vacancy_id].present? ? Vacancy.friendly.find(params[:vacancy_id]) : nil
83
+ @vacancy = params[:vacancy_id].present? ? Vacancy.find(params[:vacancy_id]) : nil
83
84
  end
84
85
  end
@@ -10,7 +10,7 @@ class VacanciesController < ApplicationController
10
10
  respond_to :html, :js, :json
11
11
 
12
12
  def index
13
- @vacancies = @project ? @project.vacancies : Vacancy.all
13
+ @vacancies = @project ? @project.vacancies : Vacancy.where(type: nil).all
14
14
  end
15
15
 
16
16
  def show
@@ -25,6 +25,7 @@ class VacanciesController < ApplicationController
25
25
 
26
26
  def create
27
27
  @vacancy = Vacancy.new(params[:vacancy])
28
+ @vacancy.resource_type = 'User'
28
29
 
29
30
  if @vacancy.project.user_id == current_user.id
30
31
  @vacancy.do_open
@@ -41,11 +42,11 @@ class VacanciesController < ApplicationController
41
42
  end
42
43
 
43
44
  def edit
44
- @vacancy = Vacancy.friendly.find(params[:id])
45
+ @vacancy = Vacancy.find(params[:id])
45
46
  end
46
47
 
47
48
  def update
48
- @vacancy = Vacancy.friendly.find(params[:id])
49
+ @vacancy = Vacancy.find(params[:id])
49
50
 
50
51
  if @vacancy.update_attributes(params[:vacancy])
51
52
  redirect_to @vacancy, notice: t('general.form.successfully_updated')
@@ -55,7 +56,7 @@ class VacanciesController < ApplicationController
55
56
  end
56
57
 
57
58
  def destroy
58
- @vacancy = Vacancy.friendly.find(params[:id])
59
+ @vacancy = Vacancy.find(params[:id])
59
60
  @vacancy.destroy
60
61
  redirect_to vacancies_url, notice: t('general.form.destroyed')
61
62
  end
@@ -79,7 +80,7 @@ class VacanciesController < ApplicationController
79
80
 
80
81
  @vacancy = Vacancy
81
82
  @vacancy = @vacancy.includes(:project, :candidatures, :comments) if action_name == 'show'
82
- @vacancy = @vacancy.friendly.find(params[:id])
83
+ @vacancy = @vacancy.find(params[:id])
83
84
  end
84
85
 
85
86
  def find_project
@@ -11,14 +11,11 @@ class Candidature < ActiveRecord::Base
11
11
 
12
12
  validates :vacancy_id, presence: true
13
13
  validates :offeror_id, presence: true
14
- validates :resource_id, presence: true, uniqueness: { scope: [:resource_type, :vacancy_id] }
14
+ validates :resource_id, presence: true, uniqueness: { scope: [:resource_type, :vacancy_id] }, if: 'validate_resource_id?'
15
15
  #validates :name, presence: true, uniqueness: { scope: :vacancy_id }
16
16
 
17
17
  attr_accessible :vacancy, :vacancy_id, :name, :text
18
18
 
19
- extend FriendlyId
20
- friendly_id :name, use: :slugged
21
-
22
19
  before_validation :set_offeror
23
20
 
24
21
  # association shortcuts
@@ -30,6 +27,12 @@ class Candidature < ActiveRecord::Base
30
27
  project.product
31
28
  end
32
29
 
30
+ protected
31
+
32
+ def validate_resource_id?
33
+ true
34
+ end
35
+
33
36
  private
34
37
 
35
38
  def set_offeror
@@ -30,12 +30,14 @@ module StateMachines::Candidature
30
30
  after_transition do |object, transition|
31
31
  case transition.to
32
32
  when 'accepted'
33
- ProjectUser.find_or_create_by_project_id_and_vacancy_id_and_user_id!(
34
- project_id: object.vacancy.project_id, vacancy_id: object.vacancy_id,
35
- user_id: object.resource_id
36
- )
33
+ if object.vacancy.create_project_user?
34
+ ProjectUser.find_or_create_by_project_id_and_vacancy_id_and_user_id!(
35
+ project_id: object.vacancy.project_id, vacancy_id: object.vacancy_id,
36
+ user_id: object.resource_id
37
+ )
38
+ end
37
39
 
38
- if object.vacancy.limit == object.vacancy.candidatures.accepted.count
40
+ if object.vacancy.limit == object.vacancy.calculate_accepted_candidatures_amount
39
41
  object.vacancy.close! unless object.vacancy.closed?
40
42
  end
41
43
  when 'denied'
@@ -48,7 +50,7 @@ module StateMachines::Candidature
48
50
 
49
51
  # state validations
50
52
  def candidatures_limit_not_reached
51
- if vacancy.limit == vacancy.candidatures.where(state: 'accepted').count
53
+ if vacancy.limit == vacancy.calculate_accepted_candidatures_amount
52
54
  errors[:state] << I18n.t('activerecord.errors.models.vacancy.attributes.limit.reached')
53
55
  end
54
56
  end
@@ -13,23 +13,77 @@ class Vacancy < ActiveRecord::Base
13
13
  accepts_nested_attributes_for :candidatures, allow_destroy: true, reject_if: ->(t) { t['name'].blank? }
14
14
  scope :open, -> { where(state: 'open') }
15
15
 
16
-
16
+ validates :resource_type, presence: true
17
17
  validates :project_id, presence: true
18
18
  validates :offeror_id, presence: true
19
- validates :name, presence: true, uniqueness: { scope: :project_id }
20
- validates :text, presence: true
21
- validates :limit, presence: true
22
-
23
- attr_accessible :project_id, :name, :text, :limit, :candidatures_attributes
24
-
25
- extend FriendlyId
19
+ validates :name, presence: true
26
20
 
27
- friendly_id :name, use: :slugged
21
+ attr_accessible :project_id, :name, :text, :limit, :timezone, :from_raw, :to_raw, :resource_type, :candidatures_attributes
28
22
 
29
23
  before_validation :set_defaults
30
24
 
31
25
  def candidatures_left
32
- limit - candidatures.accepted.count
26
+ if limit
27
+ limit - candidatures.accepted.count
28
+ else
29
+ '∞'
30
+ end
31
+ end
32
+
33
+ def from_raw
34
+ timezone && from ? from.in_time_zone(timezone).strftime('%Y-%m-%d %H:%M:%S') : ''
35
+ end
36
+
37
+ def from_raw=(value)
38
+ if timezone && value.present?
39
+ datetime = Time.zone.parse(value)
40
+ args = [
41
+ datetime.strftime('%Y').to_i, datetime.strftime('%m').to_i, datetime.strftime('%d').to_i,
42
+ datetime.strftime('%H').to_i, datetime.strftime('%M').to_i, datetime.strftime('%S').to_i
43
+ ]
44
+ timezone_was = Time.zone
45
+ Time.zone = timezone
46
+ self.from = Time.zone.local *args
47
+ end
48
+ end
49
+
50
+ def to_raw
51
+ timezone && to ? to.in_time_zone(timezone).strftime('%Y-%m-%d %H:%M:%S') : ''
52
+ end
53
+
54
+ def to_raw=(value)
55
+ if timezone && value.present?
56
+ datetime = Time.zone.parse(value)
57
+ args = [
58
+ datetime.strftime('%Y').to_i, datetime.strftime('%m').to_i, datetime.strftime('%d').to_i,
59
+ datetime.strftime('%H').to_i, datetime.strftime('%M').to_i, datetime.strftime('%S').to_i
60
+ ]
61
+ timezone_was = Time.zone
62
+ Time.zone = timezone
63
+ self.to = Time.zone.local *args
64
+ end
65
+ end
66
+
67
+ def ended?
68
+ if from.present? && Time.now < from
69
+ false
70
+ elsif from.blank? && to.present? && Time.now < to
71
+ false
72
+ elsif from.blank? && to.present?
73
+ true
74
+ elsif from.blank?
75
+ false
76
+ else
77
+ true
78
+ end
79
+ end
80
+
81
+ def calculate_accepted_candidatures_amount
82
+ candidatures.accepted.count
83
+ end
84
+
85
+ def create_project_user?
86
+ true
33
87
  end
34
88
 
35
89
  protected
@@ -1,13 +1,11 @@
1
1
  <%= simple_form_for(@candidature) do |f| %>
2
2
  <%= render partial: 'shared/form/error_messages', locals: { resource: @candidature } %>
3
3
 
4
- <div class="form-inputs">
5
- <%= @candidature.vacancy ? f.hidden_field(:vacancy_id) : f.association(:vacancy) %>
6
- <%= f.input :name %>
7
- <%= f.input :text, input_html: {style: 'width: 500px; height:300px;'} %>
8
- </div>
4
+ <%= @candidature.vacancy ? f.hidden_field(:vacancy_id) : f.association(:vacancy) %>
5
+ <%= f.input :name %>
6
+ <%= f.input :text, input_html: {style: 'width: 500px; height:300px;'} %>
9
7
 
10
- <div class="form-actions">
8
+ <div class="form-group">
11
9
  <%= f.button :submit %>
12
10
  </div>
13
11
  <% end %>
@@ -1,15 +1,58 @@
1
- <%= simple_form_for(@vacancy, html: {class: 'form-horizontal'}) do |f| %>
1
+ <%= simple_form_for(@vacancy, html: { class: 'form-horizontal' }, wrapper: :horizontal_form) do |f| %>
2
2
  <%= render partial: 'shared/form/error_messages', locals: { resource: @vacancy } %>
3
3
 
4
- <div class="form-inputs">
5
- <%= @vacancy.project ? f.hidden_field(:project_id) : f.association(:project) %>
6
-
7
- <%= f.input :name %>
8
- <%= f.input :text, input_html: {style: 'width: 500px; height:300px;'} %>
9
- <%= f.input :limit %>
4
+ <%= @vacancy.project ? f.hidden_field(:project_id) : f.association(:project) %>
5
+
6
+ <%= f.input :name %>
7
+ <%= f.input :text, input_html: {style: 'width: 500px; height:300px;'} %>
8
+ <%= f.input :limit %>
9
+
10
+ <div class="form-group string optional vacancy_timezone">
11
+ <label class="string optional control-label col-sm-3 control-label" for="vacancy_timezone">
12
+ <%= t('attributes.timezone') %>
13
+ </label>
14
+ <div class="col-sm-9">
15
+ <%= time_zone_select @vacancy, :timezone, nil, {}, id: 'vacancy_timezone', name: 'vacancy[timezone]', class: 'form-control' %>
16
+ </div>
10
17
  </div>
11
18
 
12
- <div class="form-actions">
13
- <%= f.button :submit %>
19
+ <div class="form-group string optional vacancy_from">
20
+ <label class="string optional control-label col-sm-3 control-label" for="vacancy_from">
21
+ <%= t('activerecord.attributes.vacancy.from') %>
22
+ </label>
23
+ <div class="col-sm-9">
24
+ <div class="datetime_picker" class="input-append date">
25
+ <%= text_field_tag :from_raw, @vacancy.from_raw, name: 'vacancy[from_raw]', 'data-format' => 'yyyy-MM-dd hh:mm:ss' %>
26
+ <span class="add-on">
27
+ <i data-time-icon="icon-time" data-date-icon="icon-calendar">
28
+ </i>
29
+ </span>
30
+ </div>
31
+ </div>
32
+ </div>
33
+
34
+ <div class="form-group string optional vacancy_to">
35
+ <label class="string optional control-label col-sm-3 control-label" for="vacancy_to">
36
+ <%= t('activerecord.attributes.vacancy.to') %>
37
+ </label>
38
+ <div class="col-sm-9">
39
+ <div class="datetime_picker" class="input-append date">
40
+ <%= text_field_tag :to_raw, @vacancy.to_raw, name: 'vacancy[to_raw]', 'data-format' => 'yyyy-MM-dd hh:mm:ss' %>
41
+ <span class="add-on">
42
+ <i data-time-icon="icon-time" data-date-icon="icon-calendar">
43
+ </i>
44
+ </span>
45
+ </div>
46
+ </div>
47
+ </div>
48
+
49
+ <div class="form-group">
50
+ <div class="col-sm-offset-3 col-sm-9">
51
+ <%= f.button :submit %>
52
+ </div>
14
53
  </div>
15
54
  <% end %>
55
+
56
+ <% content_for :document_ready do %>
57
+ $('#vacancy_timezone').val('<%= @vacancy.timezone %>')
58
+ <% end %>
@@ -5,7 +5,7 @@
5
5
 
6
6
  <dl class="dl-horizontal">
7
7
  <%= show_associations :project %>
8
- <%= show_attribute :limit, value: "#{@vacancy.candidatures_left} / #{@vacancy.limit}" %>
8
+ <%= show_attribute :limit, value: "#{@vacancy.calculate_accepted_candidatures_amount} / #{@vacancy.limit ? @vacancy.limit : '∞'}" %>
9
9
  <%= show_attribute :state %>
10
10
  <%= show_actions %>
11
11
  </dl>
@@ -18,8 +18,7 @@
18
18
  <%= render partial: 'shared/collection/table', locals: {
19
19
  type: 'candidatures', collection: @candidatures[state],
20
20
  columns: {
21
- 'project_id' => 'vacancy.project', 'vacancy_id' => '', 'name' => 'user.name',
22
- 'resource_id' => ''
21
+ 'project_id' => 'vacancy.project', 'vacancy_id' => '', 'resource_id' => ''
23
22
  },
24
23
  options: {show_title: false, append_new_link: false }
25
24
  } %>
@@ -15,4 +15,9 @@ en:
15
15
  events:
16
16
  accept: Accept
17
17
  deny: Deny
18
- quit: Quit
18
+ quit: Quit
19
+
20
+ activerecord:
21
+ attributes:
22
+ candidature:
23
+ resource_id: Resource
@@ -20,10 +20,15 @@ en:
20
20
  close: Close
21
21
  reopen: Reopen
22
22
 
23
- activerecord:
23
+ activerecord:
24
+ models:
25
+ vacancy: Vacancy
26
+
24
27
  attributes:
25
28
  vacancy:
26
29
  limit: Limit
30
+ from: From
31
+ to: To
27
32
 
28
33
  errors:
29
34
  models:
@@ -0,0 +1,19 @@
1
+ class AddTimespanToVacancy < ActiveRecord::Migration
2
+ def up
3
+ add_column :vacancies, :timezone, :string
4
+ add_column :vacancies, :from, :datetime
5
+ add_column :vacancies, :to, :datetime
6
+ remove_index :vacancies, name: 'index_vacancies_on_project_id_and_name'
7
+ add_column :candidatures, :user_id, :integer
8
+
9
+ Candidature.where(resource_type: 'User').update_all('user_id = resource_id')
10
+ end
11
+
12
+ def down
13
+ remove_column :vacancies, :timezone
14
+ remove_column :vacancies, :from
15
+ remove_column :vacancies, :to
16
+ add_index :vacancies, [:project_id, :name], unique: true
17
+ remove_column :candidatures, :user_id
18
+ end
19
+ end
@@ -15,7 +15,15 @@ module VoluntaryRecruiting
15
15
  # eval("@#{controller}[state] = current_user.offeror_#{controller}.where(state: state).limit(5)")
16
16
  collection = controller.to_s.classify.constantize.where(
17
17
  query, user_id: current_user.id, state: state
18
- ).order('created_at DESC').limit(5)
18
+ )
19
+
20
+ if controller == :vacancies
21
+ collection = collection.where(type: nil)
22
+ elsif controller == :candidatures
23
+ collection = collection.where(resource_type: 'User')
24
+ end
25
+
26
+ collection.order('created_at DESC').limit(10)
19
27
  eval("@#{controller}[state] = collection")
20
28
  end
21
29
  end
@@ -1,3 +1,3 @@
1
1
  module VoluntaryRecruiting
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voluntary_recruiting
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathias Gawlista
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-03 00:00:00.000000000 Z
11
+ date: 2015-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: voluntary
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.4.0
19
+ version: '0.7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.4.0
26
+ version: '0.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: letter_opener
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -262,7 +262,7 @@ dependencies:
262
262
  - - "~>"
263
263
  - !ruby/object:Gem::Version
264
264
  version: 0.7.1
265
- description: Recruiting plugin for voluntary gem.
265
+ description: "#Crowdsourcing gem voluntary's recruiting plugin: http://bit.ly/vrec-0-1-0"
266
266
  email:
267
267
  - gawlista@gmail.com
268
268
  executables: []
@@ -298,6 +298,7 @@ files:
298
298
  - config/locales/resources/vacancy/en.yml
299
299
  - config/routes.rb
300
300
  - db/migrate/20150711124651_add_recruiting.rb
301
+ - db/migrate/20151012141951_add_timespan_to_vacancy.rb
301
302
  - lib/tasks/voluntary_recruiting_tasks.rake
302
303
  - lib/voluntary_recruiting.rb
303
304
  - lib/voluntary_recruiting/ability.rb