bookable 0.0.45 → 0.0.51
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/README.md +31 -5
- data/bookable.gemspec +1 -0
- data/lib/bookable/generators/bookable/booking_model_generator.rb +1 -17
- data/lib/bookable/generators/bookable/resource_model_generator.rb +1 -1
- data/lib/bookable/generators/bookable/templates/assets/javascript/custom.js +1 -1
- data/lib/bookable/generators/bookable/templates/controllers/booking_controller.rb +13 -13
- data/lib/bookable/generators/bookable/templates/controllers/resource_controller.rb +14 -14
- data/lib/bookable/generators/bookable/templates/models/bookable.rb +6 -6
- data/lib/bookable/generators/bookable/templates/models/resource.rb +1 -1
- data/lib/bookable/generators/bookable/templates/views/index.html.erb +3 -3
- data/lib/bookable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79e2fdf99990adf8071dd35e3075beaacd802c9e
|
4
|
+
data.tar.gz: aa97dc5d583f0fb90681a1bae7adf8288cdf599b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cd39e6b6d34e246f1490c46f61bc5e4ae4a67b4b53a17cd7ba9de6c9fe3f645b2a67fa52cd812ef9169de81f1872006cb01db0b2b3a3545c6759d2de7b83a61
|
7
|
+
data.tar.gz: ee2f8cf61189fd9542d15cce90ad9c5e385e2cb48e65dfc2a3b65b65b9149ccb61dae4f8ca1967b0f52ad979d5d18a8d7ad348c5a072a69df684544513ad286a
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -20,24 +20,36 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
After you've installed the gem, you need to run the generator:
|
22
22
|
|
23
|
-
rails generate bookable:install
|
23
|
+
$ rails generate bookable:install
|
24
|
+
|
25
|
+
Alternatively you can specify a named resource by providing an argument to the rails generate command e.g.
|
26
|
+
|
27
|
+
$ rails generate bookable:install tennis_court
|
24
28
|
|
25
29
|
The generator will create the file structure you need to implement booking functionality into your app:
|
26
30
|
<ul>
|
27
31
|
<li>controllers</li>
|
28
|
-
<li>models - resource and booking</li>
|
32
|
+
<li>models - resource(tennis_court) and booking</li>
|
29
33
|
<li>views</li>
|
30
34
|
<li>javascript - which uses the jquery fullcalendar plugin</li>
|
31
35
|
<li>css - some basic css is provided which you may want to override</li>
|
32
36
|
</ul>
|
33
|
-
The necessary routes will be applied to your routes file
|
37
|
+
The necessary routes will be applied to your routes file and you will need to run
|
38
|
+
|
39
|
+
$ rake db:migrate
|
34
40
|
|
35
41
|
## Validations
|
36
42
|
|
37
|
-
Validations have been created for the models to ensure that a bookable resource is created with a unique name and bookings are created in the future and resources are not double booked. For further information,
|
43
|
+
Validations have been created for the models to ensure that a bookable resource is created with a unique name and bookings are created in the future and resources are not double booked. For further information, refer to the tests and for an example of how the gem is used, visit <a href="">this site</a>.
|
44
|
+
|
45
|
+
## Known Bugs
|
46
|
+
<ul>
|
47
|
+
<li>Front end Date validation, for example 30th February is not a valid date but is permitted by the calendar view. </li>
|
48
|
+
<li>Implement server side date validation for above - currently if a booking for 30th February is entered, the booking will be created for 2nd March.</li>
|
49
|
+
</ul>
|
38
50
|
|
39
51
|
## Contributing
|
40
|
-
There are a number of desired features we hope to implement in the future.
|
52
|
+
There are a number of desired features we hope to implement in the future. If you wish to contribute please do so in the following manner.
|
41
53
|
|
42
54
|
1. Fork it
|
43
55
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
@@ -45,6 +57,20 @@ There are a number of desired features we hope to implement in the future. Pleas
|
|
45
57
|
4. Push to the branch (`git push origin my-new-feature`)
|
46
58
|
5. Create new Pull Request
|
47
59
|
|
60
|
+
## Desired Features
|
61
|
+
<ul>
|
62
|
+
<li>optional description attribute for booking and resource models</li>
|
63
|
+
<li>implement show route for bookings</li>
|
64
|
+
<li>provide fix for Known Bugs</li>
|
65
|
+
</ul>
|
66
|
+
|
67
|
+
## Contributors
|
68
|
+
<ul>
|
69
|
+
<li><a href="https://github.com/kunks001">Srikanth Kunkalugunta</a></li>
|
70
|
+
<li><a href="https://github.com/chewymeister">Jon Tsang</a></li>
|
71
|
+
<li><a href="https://github.com/margOnline">Margo Urey</a></li>
|
72
|
+
</ul>
|
73
|
+
|
48
74
|
## License
|
49
75
|
|
50
76
|
Bookable is released under the <a href="https://github.com/kunks001/bookable/blob/master/LICENSE.txt">MIT License</a>.
|
data/bookable.gemspec
CHANGED
@@ -11,29 +11,13 @@ module Bookable
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def create_booking_migration
|
14
|
-
generate "migration CreateBookings start_time:datetime end_time:datetime length:integer #{resource_name_underscore}:belongs_to"
|
14
|
+
generate "migration CreateBookings start_time:datetime end_time:datetime length:integer #{resource_name_underscore.singularize}:belongs_to"
|
15
15
|
end
|
16
16
|
|
17
17
|
def generate_datetime_initializer
|
18
18
|
copy_file "datetime.rb", "config/initializers/datetime.rb"
|
19
19
|
end
|
20
20
|
|
21
|
-
# private
|
22
|
-
|
23
|
-
# def migration
|
24
|
-
# "class CreateBookings < ActiveRecord::Migration\n"\
|
25
|
-
# "\tdef change\n"\
|
26
|
-
# "\t\tcreate_table :bookings do |t|\n"\
|
27
|
-
# "\t\t\tt.datetime :start_time\n"\
|
28
|
-
# "\t\t\tt.datetime :end_time\n"\
|
29
|
-
# "\t\t\tt.integer :length\n"\
|
30
|
-
# "\t\t\tt.integer :resource_id\n"\
|
31
|
-
# "\t\t\tt.timestamps\n"\
|
32
|
-
# "\t\tend\n"\
|
33
|
-
# "\tend\n"\
|
34
|
-
# "end"
|
35
|
-
# end
|
36
|
-
|
37
21
|
private
|
38
22
|
|
39
23
|
def resource_name_underscore
|
@@ -5,7 +5,7 @@ module Bookable
|
|
5
5
|
argument :resource_name, :type => :string, :default => "resource"
|
6
6
|
|
7
7
|
def generate_resource_model
|
8
|
-
template "resource.rb", "app/models/#{resource_name_underscore}.rb"
|
8
|
+
template "resource.rb", "app/models/#{resource_name_underscore.singularize}.rb"
|
9
9
|
end
|
10
10
|
|
11
11
|
def create_resource_migration
|
@@ -12,7 +12,7 @@ var calendar = function(){
|
|
12
12
|
// page is now ready, initialize the calendar...
|
13
13
|
|
14
14
|
var current_resource = function(){
|
15
|
-
return window.location.href.match(/<%=bookable_name%>\/(\d+)\/
|
15
|
+
return window.location.href.match(/<%=bookable_name%>\/(\d+)\/bookings/)[1];
|
16
16
|
};
|
17
17
|
|
18
18
|
var today_or_later = function(){
|
@@ -1,22 +1,22 @@
|
|
1
1
|
class BookingsController < ApplicationController
|
2
2
|
respond_to :html, :xml, :json
|
3
3
|
|
4
|
-
before_action :find_<%=resource_name_underscore%>
|
4
|
+
before_action :find_<%=resource_name_underscore.singularize%>
|
5
5
|
|
6
6
|
def index
|
7
|
-
@bookings = Booking.where("<%=resource_name%>_id = ? AND end_time >= ?", @<%=resource_name%>.id, Time.now).order(:start_time)
|
7
|
+
@bookings = Booking.where("<%=resource_name.singularize%>_id = ? AND end_time >= ?", @<%=resource_name.singularize%>.id, Time.now).order(:start_time)
|
8
8
|
respond_with @bookings
|
9
9
|
end
|
10
10
|
|
11
11
|
def new
|
12
|
-
@booking = Booking.new(<%=resource_name%>_id: @<%=resource_name%>.id)
|
12
|
+
@booking = Booking.new(<%=resource_name.singularize%>_id: @<%=resource_name.singularize%>.id)
|
13
13
|
end
|
14
14
|
|
15
15
|
def create
|
16
|
-
@booking = Booking.new(params[:booking].permit(:<%=resource_name%>_id, :start_time, :length))
|
17
|
-
@booking.<%=resource_name%> = @<%=resource_name%>
|
16
|
+
@booking = Booking.new(params[:booking].permit(:<%=resource_name.singularize%>_id, :start_time, :length))
|
17
|
+
@booking.<%=resource_name.singularize%> = @<%=resource_name.singularize%>
|
18
18
|
if @booking.save
|
19
|
-
redirect_to <%=resource_name%>_bookings_path(@<%=resource_name%>, method: :get)
|
19
|
+
redirect_to <%=resource_name.singularize%>_bookings_path(@<%=resource_name.singularize%>, method: :get)
|
20
20
|
else
|
21
21
|
render 'new'
|
22
22
|
end
|
@@ -30,7 +30,7 @@ class BookingsController < ApplicationController
|
|
30
30
|
@booking = Booking.find(params[:id]).destroy
|
31
31
|
if @booking.destroy
|
32
32
|
flash[:notice] = "Booking: #{@booking.start_time.strftime('%e %b %Y %H:%M%p')} to #{@booking.end_time.strftime('%e %b %Y %H:%M%p')} deleted"
|
33
|
-
redirect_to <%=resource_name%>_bookings_path(@<%=resource_name%>)
|
33
|
+
redirect_to <%=resource_name.singularize%>_bookings_path(@<%=resource_name.singularize%>)
|
34
34
|
else
|
35
35
|
render 'index'
|
36
36
|
end
|
@@ -44,13 +44,13 @@ class BookingsController < ApplicationController
|
|
44
44
|
@booking = Booking.find(params[:id])
|
45
45
|
# @booking.<%=resource_name%> = @<%=resource_name%>
|
46
46
|
|
47
|
-
if @booking.update(params[:booking].permit(:<%=resource_name%>_id, :start_time, :length))
|
47
|
+
if @booking.update(params[:booking].permit(:<%=resource_name.singularize%>_id, :start_time, :length))
|
48
48
|
flash[:notice] = 'Your booking was updated succesfully'
|
49
49
|
|
50
50
|
if request.xhr?
|
51
51
|
render json: {status: :success}.to_json
|
52
52
|
else
|
53
|
-
redirect_to <%=resource_name%>_bookings_path(@<%=resource_name%>)
|
53
|
+
redirect_to <%=resource_name.singularize%>_bookings_path(@<%=resource_name.singularize%>)
|
54
54
|
end
|
55
55
|
else
|
56
56
|
render 'edit'
|
@@ -62,15 +62,15 @@ class BookingsController < ApplicationController
|
|
62
62
|
def save booking
|
63
63
|
if @booking.save
|
64
64
|
flash[:notice] = 'booking added'
|
65
|
-
redirect_to <%=resource_name%>_booking_path(@<%=resource_name%>, @booking)
|
65
|
+
redirect_to <%=resource_name.singularize%>_booking_path(@<%=resource_name.singularize%>, @booking)
|
66
66
|
else
|
67
67
|
render 'new'
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
def find_<%=resource_name%>
|
72
|
-
if params[:<%=resource_name%>_id]
|
73
|
-
@<%=resource_name%> = <%=resource_name_camelize%>.find_by_id(params[:<%=resource_name%>_id])
|
71
|
+
def find_<%=resource_name.singularize%>
|
72
|
+
if params[:<%=resource_name.singularize%>_id]
|
73
|
+
@<%=resource_name.singularize%> = <%=resource_name_camelize.singularize%>.find_by_id(params[:<%=resource_name.singularize%>_id])
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -5,36 +5,36 @@ class <%=resource_name_camelize.singularize.pluralize%>Controller < ApplicationC
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def new
|
8
|
-
@<%=resource_name_underscore%> = <%=resource_name_camelize.singularize%>.new
|
8
|
+
@<%=resource_name_underscore.singularize%> = <%=resource_name_camelize.singularize%>.new
|
9
9
|
end
|
10
10
|
|
11
11
|
def create
|
12
|
-
@<%=resource_name_underscore%> = <%=resource_name_camelize.singularize%>.create(<%=resource_name_underscore%>_params)
|
13
|
-
if @<%=resource_name_underscore%>.save
|
14
|
-
name = @<%=resource_name_underscore%>.name
|
12
|
+
@<%=resource_name_underscore.singularize%> = <%=resource_name_camelize.singularize%>.create(<%=resource_name_underscore.singularize%>_params)
|
13
|
+
if @<%=resource_name_underscore.singularize%>.save
|
14
|
+
name = @<%=resource_name_underscore.singularize%>.name
|
15
15
|
redirect_to <%=resource_name_underscore.pluralize%>_path
|
16
16
|
flash[:notice] = "#{name} created"
|
17
17
|
else
|
18
18
|
render 'new'
|
19
|
-
flash[:error] = "Unable to create <%=resource_name_underscore%>. Please try again"
|
19
|
+
flash[:error] = "Unable to create <%=resource_name_underscore.singularize.gsub(/(_)/, ' ')%>. Please try again"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
def destroy
|
24
|
-
@<%=resource_name_underscore%> = <%= resource_name_camelize.singularize%>.find(params[:id])
|
25
|
-
@<%=resource_name_underscore%>.destroy
|
24
|
+
@<%=resource_name_underscore.singularize%> = <%= resource_name_camelize.singularize%>.find(params[:id])
|
25
|
+
@<%=resource_name_underscore.singularize%>.destroy
|
26
26
|
redirect_to <%=resource_name_underscore.pluralize%>_path
|
27
27
|
end
|
28
28
|
|
29
29
|
def edit
|
30
|
-
@<%=resource_name_underscore%> = <%=resource_name_camelize.singularize%>.find(params[:id])
|
30
|
+
@<%=resource_name_underscore.singularize%> = <%=resource_name_camelize.singularize%>.find(params[:id])
|
31
31
|
end
|
32
32
|
|
33
33
|
def update
|
34
|
-
@<%=resource_name_underscore%> = <%=resource_name_camelize.singularize%>.find(params[:id])
|
35
|
-
@<%=resource_name_underscore%>.update <%=resource_name_underscore%>_params
|
36
|
-
if @<%=resource_name_underscore%>.save
|
37
|
-
flash[:notice] = "Your <%=resource_name_underscore.gsub(/(_)/, ' ')%> was updated succesfully"
|
34
|
+
@<%=resource_name_underscore.singularize%> = <%=resource_name_camelize.singularize%>.find(params[:id])
|
35
|
+
@<%=resource_name_underscore.singularize%>.update <%=resource_name_underscore.singularize%>_params
|
36
|
+
if @<%=resource_name_underscore.singularize%>.save
|
37
|
+
flash[:notice] = "Your <%=resource_name_underscore.singularize.gsub(/(_)/, ' ')%> was updated succesfully"
|
38
38
|
redirect_to root_path
|
39
39
|
else
|
40
40
|
render 'edit'
|
@@ -43,8 +43,8 @@ class <%=resource_name_camelize.singularize.pluralize%>Controller < ApplicationC
|
|
43
43
|
|
44
44
|
private
|
45
45
|
|
46
|
-
def <%=resource_name_underscore%>_params
|
47
|
-
params.require(:<%=resource_name_underscore%>).permit(:name, :delete)
|
46
|
+
def <%=resource_name_underscore.singularize%>_params
|
47
|
+
params.require(:<%=resource_name_underscore.singularize%>).permit(:name, :delete)
|
48
48
|
end
|
49
49
|
|
50
50
|
end
|
@@ -2,7 +2,7 @@ module Bookable
|
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
4
|
included do
|
5
|
-
belongs_to :<%=resource_name_underscore%>
|
5
|
+
belongs_to :<%=resource_name_underscore.singularize%>
|
6
6
|
|
7
7
|
validates :start_time, presence: true
|
8
8
|
validates :length, presence: true, numericality: { greater_than: 0 }
|
@@ -55,11 +55,11 @@ module Bookable
|
|
55
55
|
|
56
56
|
def overlaps
|
57
57
|
overlapping_bookings = [
|
58
|
-
<%=resource_name_underscore%>.bookings.end_during(start_time, end_time),
|
59
|
-
<%=resource_name_underscore%>.bookings.start_during(start_time, end_time),
|
60
|
-
<%=resource_name_underscore%>.bookings.happening_during(start_time, end_time),
|
61
|
-
<%=resource_name_underscore%>.bookings.enveloping(start_time, end_time),
|
62
|
-
<%=resource_name_underscore%>.bookings.identical(start_time, end_time)
|
58
|
+
<%=resource_name_underscore.singularize%>.bookings.end_during(start_time, end_time),
|
59
|
+
<%=resource_name_underscore.singularize%>.bookings.start_during(start_time, end_time),
|
60
|
+
<%=resource_name_underscore.singularize%>.bookings.happening_during(start_time, end_time),
|
61
|
+
<%=resource_name_underscore.singularize%>.bookings.enveloping(start_time, end_time),
|
62
|
+
<%=resource_name_underscore.singularize%>.bookings.identical(start_time, end_time)
|
63
63
|
].flatten
|
64
64
|
|
65
65
|
overlapping_bookings.delete self
|
@@ -1,8 +1,8 @@
|
|
1
1
|
<h3><%=bookable_views_name.pluralize.gsub(/(_)/,' ')%></h3>
|
2
2
|
|
3
|
-
<%% @<%=bookable_views_name.pluralize%>.each do |<%=bookable_views_name%>| %>
|
4
|
-
<div class="<%=bookable_views_name%>">
|
5
|
-
<%%= <%=bookable_views_name%>.name %>
|
3
|
+
<%% @<%=bookable_views_name.pluralize%>.each do |<%=bookable_views_name.singularize%>| %>
|
4
|
+
<div class="<%=bookable_views_name.singularize%>">
|
5
|
+
<%%= <%=bookable_views_name.singularize%>.name %>
|
6
6
|
<%%= link_to "Show all bookings", <%=bookable_views_name.singularize%>_bookings_path(<%=bookable_views_name.singularize%>) %>
|
7
7
|
<%%= link_to "Delete", <%=bookable_views_name.singularize%>_path(<%=bookable_views_name.singularize%>), data: { confirm: 'Are you sure?' }, method: :delete %>
|
8
8
|
<%%= link_to "Edit", edit_<%=bookable_views_name.singularize%>_path(<%=bookable_views_name.singularize%>) %>
|
data/lib/bookable/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bookable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.51
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Srikanth
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-11-
|
13
|
+
date: 2013-11-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|