bookable 0.0.5 → 0.0.45
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -2
- data/README.md +5 -31
- data/bookable.gemspec +0 -1
- data/lib/bookable/generators/bookable/booking_model_generator.rb +17 -1
- 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: 7a58c14ce9383b8054b73927e8bea2fb235384d6
|
4
|
+
data.tar.gz: 5500b9c3e27bbf9a88c60acad6f2c2c5450c039f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 752169119fde34464bc58466d233e335cc1bad675b616a958c48917acdc9ac6729bb46e4378dd0704a5c7094aa47e08a5f855276dd066f30e76a3c80608d4f4c
|
7
|
+
data.tar.gz: 5513d63944df081145362e0a700347ebf3e875b4ca4bfffe97e6ccb7589523111e03391b0d01907efd8a82228b0b606a65cb01e6112407adef37123bb31378d3
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -20,36 +20,24 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
After you've installed the gem, you need to run the generator:
|
22
22
|
|
23
|
-
|
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
|
23
|
+
rails generate bookable:install
|
28
24
|
|
29
25
|
The generator will create the file structure you need to implement booking functionality into your app:
|
30
26
|
<ul>
|
31
27
|
<li>controllers</li>
|
32
|
-
<li>models - resource
|
28
|
+
<li>models - resource and booking</li>
|
33
29
|
<li>views</li>
|
34
30
|
<li>javascript - which uses the jquery fullcalendar plugin</li>
|
35
31
|
<li>css - some basic css is provided which you may want to override</li>
|
36
32
|
</ul>
|
37
|
-
The necessary routes will be applied to your routes file
|
38
|
-
|
39
|
-
$ rake db:migrate
|
33
|
+
The necessary routes will be applied to your routes file.
|
40
34
|
|
41
35
|
## Validations
|
42
36
|
|
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,
|
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>
|
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, please review the test files.
|
50
38
|
|
51
39
|
## Contributing
|
52
|
-
There are a number of desired features we hope to implement in the future.
|
40
|
+
There are a number of desired features we hope to implement in the future. Please consider contributing in the following manner.
|
53
41
|
|
54
42
|
1. Fork it
|
55
43
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
@@ -57,20 +45,6 @@ There are a number of desired features we hope to implement in the future. If yo
|
|
57
45
|
4. Push to the branch (`git push origin my-new-feature`)
|
58
46
|
5. Create new Pull Request
|
59
47
|
|
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
|
-
|
74
48
|
## License
|
75
49
|
|
76
50
|
Bookable is released under the <a href="https://github.com/kunks001/bookable/blob/master/LICENSE.txt">MIT License</a>.
|
data/bookable.gemspec
CHANGED
@@ -11,13 +11,29 @@ 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
|
14
|
+
generate "migration CreateBookings start_time:datetime end_time:datetime length:integer #{resource_name_underscore}: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
|
+
|
21
37
|
private
|
22
38
|
|
23
39
|
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
|
8
|
+
template "resource.rb", "app/models/#{resource_name_underscore}.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+)\/booking/)[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%>
|
5
5
|
|
6
6
|
def index
|
7
|
-
@bookings = Booking.where("<%=resource_name
|
7
|
+
@bookings = Booking.where("<%=resource_name%>_id = ? AND end_time >= ?", @<%=resource_name%>.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
|
12
|
+
@booking = Booking.new(<%=resource_name%>_id: @<%=resource_name%>.id)
|
13
13
|
end
|
14
14
|
|
15
15
|
def create
|
16
|
-
@booking = Booking.new(params[:booking].permit(:<%=resource_name
|
17
|
-
@booking.<%=resource_name
|
16
|
+
@booking = Booking.new(params[:booking].permit(:<%=resource_name%>_id, :start_time, :length))
|
17
|
+
@booking.<%=resource_name%> = @<%=resource_name%>
|
18
18
|
if @booking.save
|
19
|
-
redirect_to <%=resource_name
|
19
|
+
redirect_to <%=resource_name%>_bookings_path(@<%=resource_name%>, 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
|
33
|
+
redirect_to <%=resource_name%>_bookings_path(@<%=resource_name%>)
|
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
|
47
|
+
if @booking.update(params[:booking].permit(:<%=resource_name%>_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
|
53
|
+
redirect_to <%=resource_name%>_bookings_path(@<%=resource_name%>)
|
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
|
65
|
+
redirect_to <%=resource_name%>_booking_path(@<%=resource_name%>, @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
|
73
|
-
@<%=resource_name
|
71
|
+
def find_<%=resource_name%>
|
72
|
+
if params[:<%=resource_name%>_id]
|
73
|
+
@<%=resource_name%> = <%=resource_name_camelize%>.find_by_id(params[:<%=resource_name%>_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
|
8
|
+
@<%=resource_name_underscore%> = <%=resource_name_camelize.singularize%>.new
|
9
9
|
end
|
10
10
|
|
11
11
|
def create
|
12
|
-
@<%=resource_name_underscore
|
13
|
-
if @<%=resource_name_underscore
|
14
|
-
name = @<%=resource_name_underscore
|
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
|
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
|
19
|
+
flash[:error] = "Unable to create <%=resource_name_underscore%>. Please try again"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
def destroy
|
24
|
-
@<%=resource_name_underscore
|
25
|
-
@<%=resource_name_underscore
|
24
|
+
@<%=resource_name_underscore%> = <%= resource_name_camelize.singularize%>.find(params[:id])
|
25
|
+
@<%=resource_name_underscore%>.destroy
|
26
26
|
redirect_to <%=resource_name_underscore.pluralize%>_path
|
27
27
|
end
|
28
28
|
|
29
29
|
def edit
|
30
|
-
@<%=resource_name_underscore
|
30
|
+
@<%=resource_name_underscore%> = <%=resource_name_camelize.singularize%>.find(params[:id])
|
31
31
|
end
|
32
32
|
|
33
33
|
def update
|
34
|
-
@<%=resource_name_underscore
|
35
|
-
@<%=resource_name_underscore
|
36
|
-
if @<%=resource_name_underscore
|
37
|
-
flash[:notice] = "Your <%=resource_name_underscore.
|
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"
|
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
|
47
|
-
params.require(:<%=resource_name_underscore
|
46
|
+
def <%=resource_name_underscore%>_params
|
47
|
+
params.require(:<%=resource_name_underscore%>).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%>
|
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
|
59
|
-
<%=resource_name_underscore
|
60
|
-
<%=resource_name_underscore
|
61
|
-
<%=resource_name_underscore
|
62
|
-
<%=resource_name_underscore
|
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)
|
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
|
3
|
+
<%% @<%=bookable_views_name.pluralize%>.each do |<%=bookable_views_name%>| %>
|
4
|
+
<div class="<%=bookable_views_name%>">
|
5
|
+
<%%= <%=bookable_views_name%>.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.45
|
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-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|