bookingsync_portal 0.0.1

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.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +47 -0
  4. data/Rakefile +28 -0
  5. data/app/assets/javascripts/bookingsync_portal/admin/application.js +20 -0
  6. data/app/assets/javascripts/bookingsync_portal/admin/handle_remote_errors.js.coffee +3 -0
  7. data/app/assets/javascripts/bookingsync_portal/admin/live_updates.js.coffee +7 -0
  8. data/app/assets/javascripts/bookingsync_portal/admin/rentals.js.coffee +77 -0
  9. data/app/assets/javascripts/bookingsync_portal/admin/templates/rentals/connected_rental.hbs +8 -0
  10. data/app/assets/stylesheets/bookingsync_portal/admin/application.css.scss +120 -0
  11. data/app/controllers/bookingsync_portal/admin/base_controller.rb +19 -0
  12. data/app/controllers/bookingsync_portal/admin/remote_accounts_controller.rb +24 -0
  13. data/app/controllers/bookingsync_portal/admin/rentals_controller.rb +64 -0
  14. data/app/controllers/bookingsync_portal/admin_api/base_controller.rb +13 -0
  15. data/app/controllers/bookingsync_portal/admin_api/connections_controller.rb +6 -0
  16. data/app/controllers/bookingsync_portal/admin_api/remote_rentals_controller.rb +18 -0
  17. data/app/controllers/bookingsync_portal/admin_api/rentals_controller.rb +18 -0
  18. data/app/controllers/bookingsync_portal/application_controller.rb +4 -0
  19. data/app/helpers/bookingsync_portal/admin/rentals_helper.rb +34 -0
  20. data/app/models/bookingsync_portal/account.rb +10 -0
  21. data/app/models/bookingsync_portal/connection.rb +21 -0
  22. data/app/models/bookingsync_portal/remote_account.rb +9 -0
  23. data/app/models/bookingsync_portal/remote_rental.rb +27 -0
  24. data/app/models/bookingsync_portal/rental.rb +15 -0
  25. data/app/resources/bookingsync_portal/admin_api/connection_resource.rb +22 -0
  26. data/app/resources/bookingsync_portal/admin_api/remote_account_resource.rb +14 -0
  27. data/app/resources/bookingsync_portal/admin_api/remote_rental_resource.rb +14 -0
  28. data/app/resources/bookingsync_portal/admin_api/rental_resource.rb +14 -0
  29. data/app/views/bookingsync_portal/admin/remote_accounts/_form.html.erb +11 -0
  30. data/app/views/bookingsync_portal/admin/remote_accounts/_how_to_connect.html.erb +1 -0
  31. data/app/views/bookingsync_portal/admin/remote_accounts/new.html.erb +5 -0
  32. data/app/views/bookingsync_portal/admin/rentals/_connected_rental.html.erb +27 -0
  33. data/app/views/bookingsync_portal/admin/rentals/_remote_rental.html.erb +9 -0
  34. data/app/views/bookingsync_portal/admin/rentals/_rental.html.erb +17 -0
  35. data/app/views/bookingsync_portal/admin/rentals/index.html.erb +58 -0
  36. data/app/views/bookingsync_portal/admin/rentals/show.js.erb +6 -0
  37. data/app/views/layouts/bookingsync_portal/admin.html.erb +13 -0
  38. data/config/locales/en.yml +58 -0
  39. data/config/routes.rb +19 -0
  40. data/db/migrate/20150222172825_create_accounts.rb +13 -0
  41. data/db/migrate/20150222173413_create_rentals.rb +14 -0
  42. data/db/migrate/20150222173711_create_remote_accounts.rb +10 -0
  43. data/db/migrate/20150222174023_create_remote_rentals.rb +12 -0
  44. data/db/migrate/20150222174234_create_connections.rb +9 -0
  45. data/lib/bookingsync_portal.rb +77 -0
  46. data/lib/bookingsync_portal/engine.rb +9 -0
  47. data/lib/bookingsync_portal/mash_serializer.rb +9 -0
  48. data/lib/bookingsync_portal/version.rb +3 -0
  49. data/lib/generators/bookingsync_portal/install_generator.rb +15 -0
  50. data/lib/generators/templates/bookingsync_portal.rb +46 -0
  51. data/lib/tasks/bookingsync_portal_tasks.rake +4 -0
  52. metadata +374 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4efb80ba84be6c967724c03348f2bd52380dd577
4
+ data.tar.gz: 4f97a25ef1694c625c58e885b7050fc493b9f200
5
+ SHA512:
6
+ metadata.gz: 9445af97382d1e4600ab4d5c5dfa63cad255fc1df8fc1a0ce419fa81f3d0a0a8e77659727dec0b7fba091bb889f7d718ff99a9ecf3a2c09d477510eb43a2471c
7
+ data.tar.gz: c9c1850fbd37e547bcb21d048db01f683e14753e5ab0f7c0f6b32593b96e669a20e7ecdfb58fa38655a3385bfd2ea583a1d102554fab58847f635cf77c427db1
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Piotr Marciniak
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,47 @@
1
+ # BookingsyncPortal
2
+
3
+ * A common base for creating BookingSync portal applications.
4
+
5
+ # Setup
6
+
7
+ You will need to install the assets for each namespace:
8
+
9
+ in `/app/assets/javascripts/admin/application.js`:
10
+
11
+ ```javascript
12
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
13
+ // listed below.
14
+ //
15
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
16
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
17
+ //
18
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
19
+ // compiled file.
20
+ //
21
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
22
+ // about supported directives.
23
+ //
24
+ //= require bookingsync_portal/admin/application
25
+ //= require_tree .
26
+ ```
27
+
28
+ in `/app/assets/javascripts/admin/application.css.scss`:
29
+
30
+ ```scss
31
+ /*
32
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
33
+ * listed below.
34
+ *
35
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
36
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
37
+ *
38
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
39
+ * compiled file so the styles you add here take precedence over styles defined in any styles
40
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
41
+ * file per style scope.
42
+ *
43
+ *= require bookingsync_portal/admin/application
44
+ *= require_self
45
+ */
46
+
47
+ ```
@@ -0,0 +1,28 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'BookingsyncPortal'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
22
+ require 'rspec/core'
23
+ require 'rspec/core/rake_task'
24
+
25
+ desc 'Run all specs in spec directory (excluding plugin specs)'
26
+ RSpec::Core::RakeTask.new(spec: 'app:db:test:prepare')
27
+
28
+ task default: :spec
@@ -0,0 +1,20 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require jquery-ui/draggable
16
+ //= require jquery-ui/droppable
17
+ //= require handlebars.runtime
18
+ //= require message-bus
19
+ //= require_tree ./templates
20
+ //= require_tree .
@@ -0,0 +1,3 @@
1
+ $ ->
2
+ $(document).on "ajax:error", "[data-remote]", (e, xhr) ->
3
+ location.reload() if xhr.status == 401
@@ -0,0 +1,7 @@
1
+ $ ->
2
+ messagebus_channel = $("body").data("messagebus-channel")
3
+ MessageBus.start()
4
+ MessageBus.subscribe messagebus_channel, (data) ->
5
+ if data.refresh_from
6
+ $.get(data.refresh_from).fail (xhr) ->
7
+ location.reload() if xhr.status == 401
@@ -0,0 +1,77 @@
1
+ $ ->
2
+ $(".bookingsync-rental").draggable
3
+ revert: "invalid"
4
+ zIndex: 50
5
+ revertDuration: 100
6
+ cursor: "move"
7
+ containment: '.rentals-container'
8
+ appendTo: '.rentals-container'
9
+ helper: "clone"
10
+ scroll: false
11
+
12
+ start: (e, ui) ->
13
+ $(ui.helper).addClass "ui-draggable-helper"
14
+
15
+ $(".not-connected-remote-rental").droppable
16
+ accept: ".bookingsync-rental"
17
+ activeClass: "dropzone-active"
18
+ hoverClass: "dropzone-hover"
19
+ greedy: true
20
+ tolerance: "pointer"
21
+ drop: (event, ui) ->
22
+ rentalId = parseInt($(ui.draggable).attr("id").split("_")[1])
23
+ remoteRentalId = parseInt($(@).attr("id").split("_")[2])
24
+ remoteRentalUid = parseInt($(@).data("uid"))
25
+
26
+ $(@).replaceWith HandlebarsTemplates["rentals/connected_rental"]
27
+ rentalName: $(ui.draggable).children('.panel-heading').text()
28
+ rentalDescription: $(ui.draggable).children('.panel-body').html()
29
+ rentalId: rentalId
30
+ listingId: "Listing #" + remoteRentalUid
31
+ $(ui.draggable).remove()
32
+
33
+ connect_url = "/en/admin/rentals/" + rentalId + "/connect" +
34
+ "?remote_rental_id=" + remoteRentalId
35
+
36
+ $.ajax
37
+ url: connect_url
38
+ type: "PUT"
39
+ dataType: 'json'
40
+ beforeSend: ->
41
+ $(@).addClass('loading')
42
+ success: ->
43
+ $(@).removeClass('loading')
44
+
45
+ $(".remote-new-rental").droppable
46
+ accept: ".bookingsync-rental"
47
+ activeClass: "dropzone-active"
48
+ hoverClass: "dropzone-hover"
49
+ greedy: true
50
+ tolerance: "pointer"
51
+ drop: (event, ui) ->
52
+ rentalId = parseInt($(ui.draggable).attr("id").split("_")[1])
53
+ remoteAccountId = parseInt($(@).data("remote-account-id"))
54
+
55
+ newRental = HandlebarsTemplates["rentals/connected_rental"]
56
+ rentalName: $(ui.draggable).children('.panel-heading').text()
57
+ rentalDescription: $(ui.draggable).children('.panel-body').html()
58
+ rentalId: rentalId
59
+
60
+ rentalsScrollingList = $(@).closest(".rentals-list").find(".rentals-list-scroll")
61
+ $(newRental).appendTo(rentalsScrollingList).addClass('pending')
62
+ rentalsScrollingList.animate
63
+ scrollTop: rentalsScrollingList.prop("scrollHeight")
64
+
65
+ $(ui.draggable).remove()
66
+
67
+ new_connect_url = "/en/admin/rentals/" + rentalId + "/connect_to_new" +
68
+ "?remote_account_id=" + remoteAccountId
69
+
70
+ $.ajax
71
+ url: new_connect_url
72
+ type: "PUT"
73
+ dataType: 'json'
74
+ beforeSend: ->
75
+ $(@).addClass('loading')
76
+ success: ->
77
+ $(@).removeClass('loading')
@@ -0,0 +1,8 @@
1
+ <div class="panel panel-connected" id="rental_{{rentalId}}"}}>
2
+ <div class="panel-heading" title="{{listingId}}">{{rentalName}}
3
+ <a href="/en/admin/rentals/{{rentalId}}/disconnect"
4
+ class="btn btn-default btn-xs remove-connection"
5
+ data-method="put">Remove Connection</a>
6
+ </div>
7
+ <div class="panel-body"><i class="fa fa-spinner fa-spin"></i> Synchronizing...</div>
8
+ </div>
@@ -0,0 +1,120 @@
1
+ $dropzone-active-bg: #fbf9ee;
2
+
3
+ @import "font-awesome-sprockets";
4
+ @import "font-awesome";
5
+ @import "bootstrap-sprockets";
6
+ @import "bootstrap";
7
+
8
+ html, body {
9
+ height: 100%;
10
+ height: 100vh;
11
+ }
12
+
13
+ body > .footer {
14
+ padding-bottom: 20px;
15
+ clear: both;
16
+ }
17
+
18
+ #remote_account_uid {
19
+ text-align: center;
20
+ }
21
+
22
+ .rentals-container {
23
+ height: 100%;
24
+ }
25
+
26
+ .rentals-list {
27
+ height: 100%;
28
+ display: flex;
29
+ flex-direction: column;
30
+ }
31
+
32
+ .rentals-list-header, .rentals-list-footer {
33
+ flex: 0 0 auto;
34
+ }
35
+
36
+ .rentals-list-scroll {
37
+ flex: 1 1 auto;
38
+ overflow-y: auto;
39
+ }
40
+
41
+ .remote-rentals-list {
42
+ border: 1px solid transparent;
43
+
44
+ &.dropzone-active {
45
+ border: 1px dashed darken($dropzone-active-bg, 7%);
46
+ background-color: lighten($dropzone-active-bg, 2%);
47
+ }
48
+
49
+ &.dropzone-hover {
50
+ border: 1px solid darken($dropzone-active-bg, 7%);
51
+ background-color: $dropzone-active-bg;
52
+
53
+ .remote-new-rental {
54
+ border: 1px solid $btn-success-border;
55
+ }
56
+ }
57
+
58
+ .dropzone-active {
59
+ border: 1px dashed $btn-success-border;
60
+ }
61
+
62
+ .dropzone-hover {
63
+ border: 1px solid $btn-success-border;
64
+ }
65
+ }
66
+
67
+ .ui-draggable-helper {
68
+ opacity: 0.6;
69
+ }
70
+
71
+ .panel-body-grid {
72
+ display: flex;
73
+ }
74
+
75
+ .panel-body-grid-photo {
76
+ min-width: 96px;
77
+ flex-grow: 0;
78
+ }
79
+
80
+ .panel-body-grid-text {
81
+ padding: $padding-base-vertical $padding-base-horizontal;
82
+ flex-grow: 1;
83
+ }
84
+
85
+ .panel-bookingsync {
86
+ @extend .panel-info;
87
+ }
88
+
89
+ .panel-connected {
90
+ @extend .panel-success;
91
+
92
+ &.pending {
93
+ border-color: darken($dropzone-active-bg, 7%);
94
+
95
+ .panel-heading {
96
+ background-color: $dropzone-active-bg;
97
+ color: darken($dropzone-active-bg, 50%);
98
+ }
99
+ }
100
+
101
+ .panel-heading {
102
+ position: relative;
103
+ }
104
+
105
+ .remove-connection {
106
+ position: absolute;
107
+ right: 3px;
108
+ top: 8px;
109
+ }
110
+ }
111
+
112
+ .panel-remote {
113
+ @extend .panel-default;
114
+ }
115
+
116
+ .panel.ui-draggable {
117
+ &:hover {
118
+ cursor: move;
119
+ }
120
+ }
@@ -0,0 +1,19 @@
1
+ require 'bookingsync_application/admin/common_base_controller'
2
+
3
+ module BookingsyncPortal
4
+ module Admin
5
+ class BaseController < ApplicationController
6
+ layout 'bookingsync_portal/admin'
7
+ respond_to :html
8
+
9
+ include BookingsyncApplication::Admin::CommonBaseController
10
+
11
+ private
12
+
13
+ def messagebus_channel
14
+ "/account-#{current_account.id}"
15
+ end
16
+ helper_method :messagebus_channel
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ module BookingsyncPortal
2
+ module Admin
3
+ class RemoteAccountsController < Admin::BaseController
4
+ def new
5
+ @remote_account = scope.build
6
+ end
7
+
8
+ def create
9
+ @remote_account = scope.create(params_remote_account)
10
+ respond_with @remote_account, location: admin_rentals_url
11
+ end
12
+
13
+ private
14
+
15
+ def scope
16
+ current_account.remote_accounts
17
+ end
18
+
19
+ def params_remote_account
20
+ params.require(:remote_account).permit(:uid)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,64 @@
1
+ module BookingsyncPortal
2
+ module Admin
3
+ class RentalsController < Admin::BaseController
4
+ before_action :synchronize_rentals, only: :index
5
+ before_action :fetch_remote_rentals, only: :index
6
+
7
+ def index
8
+ @not_connected_rentals = current_account.rentals.ordered.not_connected
9
+ @remote_accounts = current_account.remote_accounts
10
+ @remote_rentals_by_account = current_account.remote_rentals.ordered
11
+ .includes(:remote_account).group_by(&:remote_account)
12
+ end
13
+
14
+ def show
15
+ rental
16
+ end
17
+
18
+ def connect
19
+ remote_rental = current_account.remote_rentals.find(params[:remote_rental_id])
20
+ connection = rental.build_connection(remote_rental: remote_rental)
21
+ connection.save
22
+
23
+ BookingsyncPortal.connection_created(connection)
24
+ redirect_or_js_response
25
+ end
26
+
27
+ def disconnect
28
+ connection = rental.connection
29
+ if rental.remote_rental.uid.blank? # was not yet created on HolidayLettings
30
+ rental.remote_rental.destroy
31
+ else
32
+ rental.remote_rental.update_attribute(:synchronized_at, nil)
33
+ connection.destroy
34
+ end
35
+
36
+ BookingsyncPortal.connection_destroyed(connection)
37
+ redirect_or_js_response
38
+ end
39
+
40
+ private
41
+
42
+ def synchronize_rentals
43
+ BookingsyncPortal.rental_model.constantize.synchronize(scope: current_account)
44
+ end
45
+
46
+ def fetch_remote_rentals
47
+ unless BookingsyncPortal.fetch_remote_rentals(current_account)
48
+ @remote_account_not_registered = true
49
+ end
50
+ end
51
+
52
+ def rental
53
+ @rental ||= current_account.rentals.find(params[:id])
54
+ end
55
+
56
+ def redirect_or_js_response
57
+ respond_to do |wants|
58
+ wants.html { redirect_to admin_rentals_path }
59
+ wants.json { head :ok }
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end