ecm_courses2 1.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0dfc6e912f248798cf1e9e130eb64eaf4b7ebf02
4
- data.tar.gz: f00491ee08728287b419a2ed3332f03a849975cd
3
+ metadata.gz: 2cfb632553f3c624e4c94d9961d47bc958e9e8a7
4
+ data.tar.gz: 8da46502e8fb5b7672170588d3212749f3e04f00
5
5
  SHA512:
6
- metadata.gz: 16fa484f0ee0f796eefe4fd020e13803c8fe9ae3c49a210f8819a2955e098bae065229fc3d0c9a5a555352109e7826d05a7fa8dd0e27b74089b35801829c872a
7
- data.tar.gz: d4b2df587eb85e7aac20b640917a4eba8453f67b4949e3cf6377ddfc7ffbe789f9efb76f33ec492034542352caf5a6003a8b7e4913f6f76bd7238ac635108dcb
6
+ metadata.gz: 662f30155d99a49766c06f19a971142dacee6ddd79e9e687b150e0c4d6025f29b8ebd792bc9a4530070f6f819d7ed853f96d04acf0d61322e4cdc0dc72deffa1
7
+ data.tar.gz: 8869d2009c0823a02b5ad1016d308042406c215284443557c57f3abfb38dd40a5ee46b49f98e972d0258c9e15b726c409171653d19e7400db4be021ba116f545
@@ -1,6 +1,9 @@
1
1
  module Ecm
2
2
  module Courses
3
3
  module ApplicationHelper
4
+ def free_places_label_for(course)
5
+ render partial: 'ecm/courses/course_categories/free_seats', locals: { course: course }
6
+ end
4
7
  end
5
8
  end
6
9
  end
@@ -16,6 +16,47 @@ module Ecm::Courses
16
16
 
17
17
  include Icalendar
18
18
 
19
+ module Seats
20
+ extend ActiveSupport::Concern
21
+
22
+ included do
23
+ after_initialize :set_seats_defaults, if: :new_record?
24
+ before_validation :calculate_free_seats
25
+
26
+ validates :used_seats, numericality: { greater_than_or_equal_to: 0 }
27
+ end
28
+
29
+ def free_seats_percentage
30
+ percentage = free_seats.to_f / seats.to_f * 100
31
+ percentage.nan? ? 0 : percentage
32
+ end
33
+
34
+ def free_seats_level
35
+ Ecm::Courses::Configuration.free_seats_level_for(self)
36
+ end
37
+
38
+ def free_seats_level_properties
39
+ free_seats_level.values.first
40
+ end
41
+
42
+ def free_seats_level_range
43
+ free_seats_level.keys.first
44
+ end
45
+
46
+ private
47
+
48
+ def set_seats_defaults
49
+ self.seats ||= 0
50
+ self.free_seats ||= 0
51
+ end
52
+
53
+ def calculate_free_seats
54
+ self.free_seats = seats - used_seats
55
+ end
56
+ end
57
+
58
+ include Seats
59
+
19
60
  # acts as list
20
61
  acts_as_list scope: :course_category
21
62
 
@@ -0,0 +1,9 @@
1
+ = "#{course.class.human_attribute_name(:free_seats)}:"
2
+ %span{ class: "label label-#{course.free_seats_level_properties[:css_class]}" }
3
+ - if course.free_seats_level_range.last == 100
4
+ - percentage = number_to_percentage(course.free_seats_level_range.first, precision: 0)
5
+ = t('.less_than', percentage: percentage)
6
+
7
+ - else
8
+ - percentage = number_to_percentage(course.free_seats_level_range.last, precision: 0)
9
+ = t('.greater_than', percentage: percentage)
@@ -1,6 +1,9 @@
1
1
  .course{:id => "course-#{course.to_param}"}
2
2
  %span.course-title
3
3
  %h1= course.heading_name
4
+ - if Ecm::Courses::Configuration.show_free_places
5
+ .free-seats.bottom-margin-1
6
+ = free_places_label_for(course)
4
7
  - unless course.description.blank?
5
8
  .course-description
6
9
  %p= course.description
@@ -12,32 +12,48 @@ de:
12
12
  other: Kurse
13
13
  attributes:
14
14
  ecm/courses/course_category:
15
- description: Beschreibung
16
- courses_count: Kurse
15
+ children: Unterkategorien
16
+ created_at: Erstellt am
17
17
  courses: Kurse
18
+ courses_count: Kurse
19
+ created_at: Erstellt am
20
+ depth: Level
21
+ description: Beschreibung
22
+ lft: Links
18
23
  locale: Sprache
19
24
  name: Name
20
25
  parent: Überliegende Kategorie
21
26
  parent_id: Überliegende Kategorie
22
- created_at: Erstellt am
27
+ position: Position
28
+ rgt: Rechts
29
+ slug: Freundliche ID
23
30
  updated_at: Aktualisiert am
24
31
  ecm/courses/course_date:
32
+ created_at: Erstellt am
25
33
  description: Beschreibung
34
+ duration_in_minutes: Dauer
35
+ course_category: Kategorie
26
36
  course: Kurs
27
37
  course_id: Kurs
28
38
  end_at: Endet am
39
+ name: Name
29
40
  start_at: Beginnt am
30
- created_at: Erstellt am
31
41
  updated_at: Aktualisiert am
32
42
  ecm/courses/course:
33
- description: Beschreibung
34
43
  course_category: Kategorie
35
44
  course_category_id: Kategorie
45
+ course_dates: Termine
36
46
  course_dates_count: Termine
47
+ created_at: Erstellt am
48
+ description: Beschreibung
49
+ free_seats: Freie Plätze
37
50
  locale: Sprache
38
51
  name: Name
39
- created_at: Erstellt am
52
+ position: Position
53
+ seats: Plätze
54
+ slug: Freundliche ID
40
55
  updated_at: Aktualisiert am
56
+ used_seats: Belegte Plätze
41
57
  date:
42
58
  formats:
43
59
  month_with_year: '%B %Y'
@@ -47,6 +63,9 @@ de:
47
63
  show:
48
64
  back: 'Zurück'
49
65
  course_categories:
66
+ free_seats:
67
+ greater_than: "> %{percentage}"
68
+ less_than: "< %{percentage}"
50
69
  index:
51
70
  back: 'Zurück'
52
71
  show:
@@ -0,0 +1,86 @@
1
+ en:
2
+ activerecord:
3
+ models:
4
+ ecm/courses/course_category:
5
+ one: "course category"
6
+ other: "course_categories"
7
+ ecm/courses/course:
8
+ one: "Course"
9
+ other: "Courses"
10
+ ecm/courses/course_date:
11
+ one: "course date"
12
+ other: "course dates"
13
+ attributes:
14
+ ecm/courses/course_category:
15
+ children: sub categories
16
+ created_at: Created at
17
+ courses: Courses
18
+ courses_count: Courses
19
+ created_at: created at
20
+ depth: depth
21
+ description: description
22
+ lft: left
23
+ locale: language
24
+ name: name
25
+ parent: parent category
26
+ parent_id: parent cateogory
27
+ position: position
28
+ rgt: right
29
+ slug: friendly id
30
+ updated_at: updated at
31
+ ecm/courses/course_date:
32
+ created_at: created at
33
+ description: description
34
+ duration_in_minutes: duration
35
+ course_category: course category
36
+ course: course
37
+ course_id: course
38
+ end_at: end at
39
+ name: name
40
+ start_at: begin at
41
+ updated_at: updated at
42
+ ecm/courses/course:
43
+ course_category: category
44
+ course_category_id: category
45
+ course_dates: dates
46
+ course_dates_count: dates
47
+ created_at: created at
48
+ description: description
49
+ free_seats: Free seats
50
+ locale: language
51
+ name: name
52
+ position: position
53
+ seats: Seats
54
+ slug: friendly id
55
+ updated_at: updated at
56
+ used_seats: used seats
57
+ date:
58
+ formats:
59
+ month_with_year: '%B %Y'
60
+ ecm:
61
+ courses:
62
+ courses:
63
+ show:
64
+ back: 'Back'
65
+ course_categories:
66
+ free_seats:
67
+ greater_than: "> %{percentage}"
68
+ less_than: "< %{percentage}"
69
+ index:
70
+ back: 'Back'
71
+ show:
72
+ calendar_heading: 'Calendar for %{month}'
73
+ course_dates:
74
+ show:
75
+ back: Back
76
+ course_category:
77
+ actions:
78
+ back_to_index: 'Back'
79
+ pages:
80
+ course_categories:
81
+ index: Course categories
82
+ routes:
83
+ ecm_courses_engine: 'courses'
84
+ courses: 'courses'
85
+ course_categories: 'categories'
86
+ course_dates: 'dates'
@@ -0,0 +1,7 @@
1
+ class AddSeatsColumnsToEcmCoursesCourses < ActiveRecord::Migration[4.2]
2
+ def change
3
+ add_column :ecm_courses_courses, :seats, :integer
4
+ add_column :ecm_courses_courses, :used_seats, :integer
5
+ add_column :ecm_courses_courses, :free_seats, :integer
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ class InitializeSeatsColumnsInEcmCoursesCourses < ActiveRecord::Migration[4.2]
2
+ class Ecm::Courses::Courses < ActiveRecord::Base; end
3
+
4
+ def up
5
+ Ecm::Courses::Courses.update_all(seats: 0, used_seats: 0, free_seats: 0)
6
+ end
7
+
8
+ def down
9
+ Ecm::Courses::Courses.update_all(seats: nil, used_seats: nil, free_seats: nil)
10
+ end
11
+ end
@@ -6,6 +6,22 @@ module Ecm
6
6
  end
7
7
 
8
8
  mattr_accessor(:base_controller) { '::ApplicationController' }
9
+
10
+ mattr_accessor(:show_free_places) { false }
11
+
12
+ mattr_accessor(:free_seats_level_proc) do
13
+ lambda do |course|
14
+ {
15
+ 0..9 => { color: 'red' },
16
+ 10..69 => { color: 'yellow' },
17
+ 70..100 => { color: 'green' }
18
+ }
19
+ end
20
+ end
21
+
22
+ def self.free_seats_level_for(course)
23
+ free_seats_level_proc.call(course).select { |percentage| percentage === course.free_seats_percentage }
24
+ end
9
25
  end
10
26
  end
11
27
  end
@@ -1,5 +1,5 @@
1
1
  module Ecm
2
2
  module Courses
3
- VERSION = '1.0.3'.freeze
3
+ VERSION = '1.1.0'.freeze
4
4
  end
5
5
  end
@@ -6,8 +6,8 @@ module Ecm
6
6
 
7
7
  source_root File.expand_path('../templates', __FILE__)
8
8
 
9
- def generate_intializer
10
- copy_file "ecm_courses.rb", "config/initializers/ecm_courses.rb"
9
+ def generate_initializer
10
+ copy_file "initializer.rb", "config/initializers/ecm_courses.rb"
11
11
  end
12
12
 
13
13
  def generate_routes
@@ -4,4 +4,30 @@ Ecm::Courses.configure do |config|
4
4
  # Default: config.base_controller = '::ApplicationController'
5
5
  #
6
6
  config.base_controller = '::ApplicationController'
7
+
8
+ # Set the colours and thresholds for free seats.
9
+ #
10
+ # Default:
11
+ #
12
+ # config.free_seats_levels_proc = ->(course) do
13
+ # {
14
+ # 0..9 => { css_class: 'danger' },
15
+ # 10..69 => { css_class: 'warning' },
16
+ # 70..100 => { css_class: 'success' }
17
+ # }
18
+ # end
19
+ #
20
+ config.free_seats_level_proc = ->(course) do
21
+ {
22
+ 0..9 => { css_class: 'danger' },
23
+ 10..69 => { css_class: 'warning' },
24
+ 70..100 => { css_class: 'success' }
25
+ }
26
+ end
27
+
28
+ # Show the free places label when displaying a course.
29
+ #
30
+ # Default: config.show_free_places = false
31
+ #
32
+ config.show_free_places = true
7
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecm_courses2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Vasquez Angel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-23 00:00:00.000000000 Z
11
+ date: 2018-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -340,6 +340,7 @@ files:
340
340
  - app/models/ecm/courses/course_category.rb
341
341
  - app/models/ecm/courses/course_date.rb
342
342
  - app/views/ecm/courses/course_categories/_course_category.haml
343
+ - app/views/ecm/courses/course_categories/_free_seats.haml
343
344
  - app/views/ecm/courses/course_categories/index.haml
344
345
  - app/views/ecm/courses/course_categories/show.haml
345
346
  - app/views/ecm/courses/course_dates/_course_date.haml
@@ -351,11 +352,7 @@ files:
351
352
  - app/views/ecm/courses/courses/show.haml
352
353
  - app/views/layouts/ecm/courses/application.html.erb
353
354
  - config/locales/de.yml
354
- - config/locales/locales/ecm.courses.course.en.yml
355
- - config/locales/locales/ecm.courses.course_category.en.yml
356
- - config/locales/locales/ecm.courses.course_date.en.yml
357
- - config/locales/locales/ecm.courses.en.yml
358
- - config/locales/locales/ecm.courses.routes.en.yml
355
+ - config/locales/en.yml
359
356
  - config/routes.rb
360
357
  - db/migrate/001_create_ecm_courses_course_categories.rb
361
358
  - db/migrate/002_create_ecm_courses_courses.rb
@@ -364,6 +361,8 @@ files:
364
361
  - db/migrate/20160927142037_remove_ecm_courses_course_dates_count_from_ecm_courses_courses.rb
365
362
  - db/migrate/20160927142238_change_ecm_courses_course_category_id_to_course_category_id_on_ecm_courses_courses.rb
366
363
  - db/migrate/20160927142425_change_ecm_courses_course_id_to_course_id_on_ecm_courses_course_date.rb
364
+ - db/migrate/20180227204631_add_seats_columns_to_ecm_courses_courses.rb
365
+ - db/migrate/20180227210548_initialize_seats_columns_in_ecm_courses_courses.rb
367
366
  - lib/ecm/courses.rb
368
367
  - lib/ecm/courses/configuration.rb
369
368
  - lib/ecm/courses/engine.rb
@@ -372,7 +371,6 @@ files:
372
371
  - lib/generators/ecm/courses/install/install_generator.rb
373
372
  - lib/generators/ecm/courses/install/templates/ecm_courses.rb
374
373
  - lib/generators/ecm/courses/install/templates/routes.source
375
- - lib/generators/ecm/courses/locales/locales_generator.rb
376
374
  - lib/tasks/ecm/courses_tasks.rake
377
375
  - spec/factories/ecm/courses/course_category_factories.rb
378
376
  - spec/factories/ecm/courses/course_date_factories.rb
@@ -1,25 +0,0 @@
1
- ---
2
- en:
3
- activerecord:
4
- attributes:
5
- ecm/courses/course:
6
- created_at: created at
7
- description: description
8
- ecm_courses_course_category: course category
9
- ecm_courses_course_category_id: course category
10
- ecm_courses_course_dates_count: course dates
11
- ecm_courses_course_dates: course dates
12
- locale: language
13
- name: name
14
- position: position
15
- slug: friendly id
16
- updated_at: updated at
17
- models:
18
- ecm/courses/course:
19
- one: "Course"
20
- other: "Courses"
21
- formtastic:
22
- hints:
23
- ecm/courses/course:
24
- name: "i.e. Cooking for beginners"
25
-
@@ -1,25 +0,0 @@
1
- ---
2
- en:
3
- activerecord:
4
- attributes:
5
- ecm/courses/course_category:
6
- children: "sub categories"
7
- created_at: created at
8
- depth: depth
9
- description: description
10
- ecm_courses_courses_count: courses
11
- ecm_courses_courses: courses
12
- lft: left
13
- locale: language
14
- name: name
15
- parent_id: parent cateogory
16
- parent: parent category
17
- position: position
18
- rgt: right
19
- slug: friendly id
20
- updated_at: updated at
21
- models:
22
- ecm/courses/course_category:
23
- one: "course category"
24
- other: "course_categories"
25
-
@@ -1,20 +0,0 @@
1
- ---
2
- en:
3
- activerecord:
4
- attributes:
5
- ecm/courses/course_date:
6
- created_at: created at
7
- description: description
8
- duration_in_minutes: duration
9
- ecm_courses_course_category: course category
10
- ecm_courses_course: course
11
- ecm_courses_course_id: course
12
- end_at: end at
13
- name: name
14
- start_at: begin at
15
- updated_at: updated at
16
- models:
17
- ecm/courses/course_date:
18
- one: "course date"
19
- other: "course dates"
20
-
@@ -1,18 +0,0 @@
1
- en:
2
- date:
3
- formats:
4
- month_with_year: %B %Y
5
- ecm:
6
- courses:
7
- active_admin:
8
- menu: "courses"
9
- course:
10
- messages:
11
- not_found: "Course \"%{name}\" not found."
12
- course_category:
13
- actions:
14
- back_to_index: "Back to the index"
15
- messages:
16
- not_found: "Course category \"%{name}\" not found."
17
- no_courses_available: "There are now courses in this category."
18
-
@@ -1,6 +0,0 @@
1
- en:
2
- resources:
3
- courses: "courses"
4
- course_categories: "course-categories"
5
- course_dates: "course-dates"
6
-
@@ -1,29 +0,0 @@
1
- module Ecm
2
- module Courses
3
- module Generators
4
- class LocalesGenerator < Rails::Generators::Base
5
- desc "Copies the locale files to your application"
6
-
7
- source_root File.expand_path('../../../../../../config/locales', __FILE__)
8
-
9
- def generate_locales
10
- copy_file "ecm.courses.en.yml", "config/locales/ecm.courses.en.yml"
11
- copy_file "ecm.courses.de.yml", "config/locales/ecm.courses.de.yml"
12
-
13
- copy_file "ecm.courses.course.en.yml", "config/locales/ecm.courses.course.en.yml"
14
- copy_file "ecm.courses.course.de.yml", "config/locales/ecm.courses.course.de.yml"
15
-
16
- copy_file "ecm.courses.course_category.en.yml", "config/locales/ecm.courses.course_category.en.yml"
17
- copy_file "ecm.courses.course_category.de.yml", "config/locales/ecm.courses.course_category.de.yml"
18
-
19
- copy_file "ecm.courses.course_date.en.yml", "config/locales/ecm.courses.course_date.en.yml"
20
- copy_file "ecm.courses.course_date.de.yml", "config/locales/ecm.courses.course_date.de.yml"
21
-
22
- copy_file "ecm.courses.routes.en.yml", "config/locales/ecm.courses.routes.en.yml"
23
- copy_file "ecm.courses.routes.de.yml", "config/locales/ecm.courses.routes.de.yml"
24
- end
25
- end
26
- end
27
- end
28
- end
29
-