From 32c9f9be04a081a43c5dc83a1799b2c93c885ec5 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Fri, 20 Jan 2017 17:02:50 +0800 Subject: [PATCH] first commit --- .gitignore | 8 + Gemfile | 15 + MIT-LICENSE | 20 + README.rdoc | 3 + Rakefile | 37 + app/assets/images/property_hire/.keep | 0 .../javascripts/property_hire/application.js | 13 + .../property_hire_calendar_frontend.js | 597 ++++++++++++++ .../property_hire_fullcalendar.min.js | 7 + .../stylesheets/property_hire/application.css | 15 + .../stylesheets/property_hire_calendar.scss | 741 ++++++++++++++++++ .../property_hire_fullcalendar.css | 579 ++++++++++++++ .../admin/property_hires_controller.rb | 147 ++++ app/controllers/property_hires_controller.rb | 211 +++++ app/helpers/admin/property_hires_helper.rb | 22 + app/models/p_hire.rb | 45 ++ app/models/property.rb | 111 +++ app/models/property_location.rb | 8 + app/views/admin/property_hires/_form.html.erb | 299 +++++++ .../property_hires/_location_form.html.erb | 14 + .../property_hires/add_location.html.erb | 3 + app/views/admin/property_hires/edit.html.erb | 5 + .../property_hires/edit_location.html.erb | 3 + app/views/admin/property_hires/index.html.erb | 42 + .../property_hires/manage_locations.html.erb | 75 ++ app/views/admin/property_hires/new.html.erb | 5 + app/views/admin/property_hires/show.html.erb | 46 ++ .../show_booking_details.html.erb | 48 ++ app/views/property_hires/hire.html.erb | 150 ++++ app/views/property_hires/index.html.erb | 1 + app/views/property_hires/show.html.erb | 1 + .../property_hires/view_calendar.html.erb | 56 ++ bin/rails | 12 + config/locales/en.yml | 43 + config/locales/zh_tw.yml | 43 + config/routes.rb | 25 + lib/property_hire.rb | 4 + lib/property_hire/engine.rb | 57 ++ lib/property_hire/version.rb | 3 + lib/tasks/property_hire_tasks.rake | 4 + property_hire.gemspec | 20 + test/dummy/README.rdoc | 28 + test/dummy/Rakefile | 6 + test/dummy/app/assets/images/.keep | 0 .../app/assets/javascripts/application.js | 13 + .../app/assets/stylesheets/application.css | 15 + .../app/controllers/application_controller.rb | 5 + test/dummy/app/controllers/concerns/.keep | 0 test/dummy/app/helpers/application_helper.rb | 2 + test/dummy/app/mailers/.keep | 0 test/dummy/app/models/.keep | 0 test/dummy/app/models/concerns/.keep | 0 .../app/views/layouts/application.html.erb | 14 + test/dummy/bin/bundle | 3 + test/dummy/bin/rails | 4 + test/dummy/bin/rake | 4 + test/dummy/bin/setup | 29 + test/dummy/config.ru | 4 + test/dummy/config/application.rb | 26 + test/dummy/config/boot.rb | 5 + test/dummy/config/database.yml | 25 + test/dummy/config/environment.rb | 5 + test/dummy/config/environments/development.rb | 41 + test/dummy/config/environments/production.rb | 79 ++ test/dummy/config/environments/test.rb | 42 + test/dummy/config/initializers/assets.rb | 11 + .../initializers/backtrace_silencers.rb | 7 + .../config/initializers/cookies_serializer.rb | 3 + .../initializers/filter_parameter_logging.rb | 4 + test/dummy/config/initializers/inflections.rb | 16 + test/dummy/config/initializers/mime_types.rb | 4 + .../config/initializers/session_store.rb | 3 + .../config/initializers/wrap_parameters.rb | 14 + test/dummy/config/locales/en.yml | 23 + test/dummy/config/routes.rb | 4 + test/dummy/config/secrets.yml | 22 + test/dummy/lib/assets/.keep | 0 test/dummy/log/.keep | 0 test/dummy/public/404.html | 67 ++ test/dummy/public/422.html | 67 ++ test/dummy/public/500.html | 66 ++ test/dummy/public/favicon.ico | 0 test/integration/navigation_test.rb | 8 + test/property_hire_test.rb | 7 + test/test_helper.rb | 21 + 85 files changed, 4235 insertions(+) create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 MIT-LICENSE create mode 100644 README.rdoc create mode 100644 Rakefile create mode 100644 app/assets/images/property_hire/.keep create mode 100644 app/assets/javascripts/property_hire/application.js create mode 100644 app/assets/javascripts/property_hire_calendar_frontend.js create mode 100644 app/assets/javascripts/property_hire_fullcalendar.min.js create mode 100644 app/assets/stylesheets/property_hire/application.css create mode 100644 app/assets/stylesheets/property_hire_calendar.scss create mode 100644 app/assets/stylesheets/property_hire_fullcalendar.css create mode 100644 app/controllers/admin/property_hires_controller.rb create mode 100644 app/controllers/property_hires_controller.rb create mode 100644 app/helpers/admin/property_hires_helper.rb create mode 100644 app/models/p_hire.rb create mode 100644 app/models/property.rb create mode 100644 app/models/property_location.rb create mode 100644 app/views/admin/property_hires/_form.html.erb create mode 100644 app/views/admin/property_hires/_location_form.html.erb create mode 100644 app/views/admin/property_hires/add_location.html.erb create mode 100644 app/views/admin/property_hires/edit.html.erb create mode 100644 app/views/admin/property_hires/edit_location.html.erb create mode 100644 app/views/admin/property_hires/index.html.erb create mode 100644 app/views/admin/property_hires/manage_locations.html.erb create mode 100644 app/views/admin/property_hires/new.html.erb create mode 100644 app/views/admin/property_hires/show.html.erb create mode 100644 app/views/admin/property_hires/show_booking_details.html.erb create mode 100644 app/views/property_hires/hire.html.erb create mode 100644 app/views/property_hires/index.html.erb create mode 100644 app/views/property_hires/show.html.erb create mode 100644 app/views/property_hires/view_calendar.html.erb create mode 100755 bin/rails create mode 100644 config/locales/en.yml create mode 100644 config/locales/zh_tw.yml create mode 100644 config/routes.rb create mode 100644 lib/property_hire.rb create mode 100644 lib/property_hire/engine.rb create mode 100644 lib/property_hire/version.rb create mode 100644 lib/tasks/property_hire_tasks.rake create mode 100644 property_hire.gemspec create mode 100644 test/dummy/README.rdoc create mode 100644 test/dummy/Rakefile create mode 100644 test/dummy/app/assets/images/.keep create mode 100644 test/dummy/app/assets/javascripts/application.js create mode 100644 test/dummy/app/assets/stylesheets/application.css create mode 100644 test/dummy/app/controllers/application_controller.rb create mode 100644 test/dummy/app/controllers/concerns/.keep create mode 100644 test/dummy/app/helpers/application_helper.rb create mode 100644 test/dummy/app/mailers/.keep create mode 100644 test/dummy/app/models/.keep create mode 100644 test/dummy/app/models/concerns/.keep create mode 100644 test/dummy/app/views/layouts/application.html.erb create mode 100755 test/dummy/bin/bundle create mode 100755 test/dummy/bin/rails create mode 100755 test/dummy/bin/rake create mode 100755 test/dummy/bin/setup create mode 100644 test/dummy/config.ru create mode 100644 test/dummy/config/application.rb create mode 100644 test/dummy/config/boot.rb create mode 100644 test/dummy/config/database.yml create mode 100644 test/dummy/config/environment.rb create mode 100644 test/dummy/config/environments/development.rb create mode 100644 test/dummy/config/environments/production.rb create mode 100644 test/dummy/config/environments/test.rb create mode 100644 test/dummy/config/initializers/assets.rb create mode 100644 test/dummy/config/initializers/backtrace_silencers.rb create mode 100644 test/dummy/config/initializers/cookies_serializer.rb create mode 100644 test/dummy/config/initializers/filter_parameter_logging.rb create mode 100644 test/dummy/config/initializers/inflections.rb create mode 100644 test/dummy/config/initializers/mime_types.rb create mode 100644 test/dummy/config/initializers/session_store.rb create mode 100644 test/dummy/config/initializers/wrap_parameters.rb create mode 100644 test/dummy/config/locales/en.yml create mode 100644 test/dummy/config/routes.rb create mode 100644 test/dummy/config/secrets.yml create mode 100644 test/dummy/lib/assets/.keep create mode 100644 test/dummy/log/.keep create mode 100644 test/dummy/public/404.html create mode 100644 test/dummy/public/422.html create mode 100644 test/dummy/public/500.html create mode 100644 test/dummy/public/favicon.ico create mode 100644 test/integration/navigation_test.rb create mode 100644 test/property_hire_test.rb create mode 100644 test/test_helper.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..de5d954 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.bundle/ +log/*.log +pkg/ +test/dummy/db/*.sqlite3 +test/dummy/db/*.sqlite3-journal +test/dummy/log/*.log +test/dummy/tmp/ +test/dummy/.sass-cache diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..20cb895 --- /dev/null +++ b/Gemfile @@ -0,0 +1,15 @@ +source 'https://rubygems.org' + +# Declare your gem's dependencies in property_hire.gemspec. +# Bundler will treat runtime dependencies like base dependencies, and +# development dependencies will be added by default to the :development group. +gemspec + +# Declare any dependencies that are still in development here instead of in +# your gemspec. These might include edge Rails or gems from your path or +# Git. Remember to move these dependencies to your gemspec before releasing +# your gem to rubygems.org. + +# To use a debugger +# gem 'byebug', group: [:development, :test] + diff --git a/MIT-LICENSE b/MIT-LICENSE new file mode 100644 index 0000000..d33f7d5 --- /dev/null +++ b/MIT-LICENSE @@ -0,0 +1,20 @@ +Copyright 2017 Harry Bomrah + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.rdoc b/README.rdoc new file mode 100644 index 0000000..cb63caf --- /dev/null +++ b/README.rdoc @@ -0,0 +1,3 @@ += PropertyHire + +This project rocks and uses MIT-LICENSE. \ No newline at end of file diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..69bdc0e --- /dev/null +++ b/Rakefile @@ -0,0 +1,37 @@ +begin + require 'bundler/setup' +rescue LoadError + puts 'You must `gem install bundler` and `bundle install` to run rake tasks' +end + +require 'rdoc/task' + +RDoc::Task.new(:rdoc) do |rdoc| + rdoc.rdoc_dir = 'rdoc' + rdoc.title = 'PropertyHire' + rdoc.options << '--line-numbers' + rdoc.rdoc_files.include('README.rdoc') + rdoc.rdoc_files.include('lib/**/*.rb') +end + +APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__) +load 'rails/tasks/engine.rake' + + +load 'rails/tasks/statistics.rake' + + + +Bundler::GemHelper.install_tasks + +require 'rake/testtask' + +Rake::TestTask.new(:test) do |t| + t.libs << 'lib' + t.libs << 'test' + t.pattern = 'test/**/*_test.rb' + t.verbose = false +end + + +task default: :test diff --git a/app/assets/images/property_hire/.keep b/app/assets/images/property_hire/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/javascripts/property_hire/application.js b/app/assets/javascripts/property_hire/application.js new file mode 100644 index 0000000..8913b40 --- /dev/null +++ b/app/assets/javascripts/property_hire/application.js @@ -0,0 +1,13 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. +// +// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require_tree . diff --git a/app/assets/javascripts/property_hire_calendar_frontend.js b/app/assets/javascripts/property_hire_calendar_frontend.js new file mode 100644 index 0000000..8fb74a1 --- /dev/null +++ b/app/assets/javascripts/property_hire_calendar_frontend.js @@ -0,0 +1,597 @@ +var Calendar = function(dom,property_id){ + + c = this; + this.title = $("#current_title"); + this.calendar = $(dom); + this.nextBtn = $("#next_month_btn"); + this.prevBtn = $("#prev_month_btn"); + this.todayBtn = $("#today_btn"); + this.modeBtns = $(".calendar_mode button"); + this.refreshBtn = $("#refresh_btn"); + this.dialog = new EventDialog(c); + this.loading = $('#calendar-loading'); + this.agenda_space = $("#calendar_agenda"); + this.currentView = "month"; + this.property_id = property_id; + this.navigation = $("#navigation"); + this.rangeSelection = $("#range_selection"); + var agendaView = new AgendaView(c); + var loadeventsonviewchange = false; + this.initialize = function(){ + var date = new Date(); + var d = date.getDate(); + var m = date.getMonth(); + var y = date.getFullYear(); + var dview = (c.currentView == "agenda" ? "month" : c.currentView); + c.calendar.fullCalendar({ + editable: false, + selectable: false, + events: "/xhr/property_hires/get_bookings?property_id="+c.property_id, + header: false, + default: dview, + height: $("body").height() - 141, + loading: function(bool) { + if (bool) c.loading.css("left",($(window).width()/2 - 60) + "px").show(); + else c.loading.hide(); + }, + windowResize : function(view){ + view.setHeight($("body").height() - 141); + c.calendar.fullCalendar("refetchEvents"); + }, + viewDisplay: function(view) { + c.title.html(view.title); + }, + eventClick: function(calEvent, e, view) { + c.dialog.dismiss(); + c.dialog.inflate(calEvent); + c.dialog.show({"x":e.originalEvent.clientX,"y":e.originalEvent.clientY}); + } + }); + + c.nextBtn.click(function(){ + c.dialog.dismiss(); + c.calendar.fullCalendar('next'); + }); + c.prevBtn.click(function(){ + c.dialog.dismiss(); + c.calendar.fullCalendar('prev'); + }); + c.todayBtn.click(function(){ + c.dialog.dismiss(); + c.calendar.fullCalendar('today'); + }); + c.modeBtns.click(function(){ + c.dialog.dismiss(); + toggleViews($(this).data("mode")); + }); + c.refreshBtn.click(function(){ + c.dialog.dismiss(); + if(c.currentView == "agenda") + agendaView.refresh(); + else + c.calendar.fullCalendar("refetchEvents"); + }); + + var toggleViews = function(view){ + c.modeBtns.removeClass("active"); + c.modeBtns.each(function(){ + if ($(this).data("mode") == view) + $(this).addClass("active"); + }) + if(view != "agenda"){ + if(c.currentView == "agenda"){ + // $("#sec1").addClass("span3").removeClass("span7"); + $("#sec2").show(); + // $("#sec3").addClass("span4").removeClass("span5"); + agendaView.hide(); + } + c.calendar.fullCalendar('changeView',view); + }else{ + // $("#sec1").addClass("span7").removeClass("span3"); + $("#sec2").hide(); + // $("#sec3").addClass("span5").removeClass("span4"); + agendaView.inflate(); + } + c.currentView = view; + if(loadeventsonviewchange){ + c.calendar.fullCalendar("refetchEvents"); + loadeventsonviewchange = false; + } + } + if(c.currentView == "agenda"){toggleViews("agenda");loadeventsonviewchange = true;} + + } + + this.renderEvent = function(eventStick){ + if(eventStick.recurring == true) + c.calendar.fullCalendar("refetchEvents"); + else + c.calendar.fullCalendar("renderEvent",eventStick); + } + + + $(document).ready(function() { + c.initialize(); + }); +} + +var EventDialog = function(calendar,event){ + _t = this; + var event_quick_view = null; + var template = ""; + var _this_event = null; + var month_names = ["Jan","Feb","March","April","May","June","July","Aug","Sep","Oct","Nov","Dec"]; + this.inflate = function(_event){ + if(!_event) throw new UserException("EventStick can't be null!"); + _this_event = _event; + var start_time = "", + end_time = "", + time_string = null; + + if(_event.allDay) { + start_time = $.fullCalendar.formatDate(_event._start,"MMM dd, yyyy"); + if(_event._end) + end_time = $.fullCalendar.formatDate(_event._end,"MMM dd, yyyy"); + time_string = (_event._start === _event._end || !_event._end ? "

" + start_time + "

" : " " + start_time + " " + end_time + ""); + } else { + var sh = _event._start.getHours() > 12 ? _event._start.getHours() - 12 : _event._start.getHours(), + eh = _event._end.getHours() > 12 ? _event._end.getHours() - 12 : _event._end.getHours(), + sm = _event._start.getMinutes() < 10 ? '0' + _event._start.getMinutes() : _event._start.getMinutes(), + em = _event._end.getMinutes() < 10 ? '0' + _event._end.getMinutes() : _event._end.getMinutes(), + stime = _event._start.getHours() > 12 ? sh + ':' + sm + " PM" : sh + ':' + sm + " AM", + etime = _event._end.getHours() > 12 ? eh + ':' + em + " PM" : eh + ':' + em + " AM", + same = (_event._start.getDate() == _event._end.getDate() && _event._start.getMonth() == _event._end.getMonth() && _event._start.getFullYear() == _event._end.getFullYear()); + start_time = month_names[_event._start.getMonth()] + " " + _event._start.getDate() + ", " + _event._start.getFullYear(); + end_time = month_names[_event._end.getMonth()] + " " + _event._end.getDate() + ", " + _event._end.getFullYear(); + + time_string = (same ? "

" + start_time + "

" + stime + " " + etime : "

" + start_time + "" + stime + "

" + end_time + "" + etime + "

"); + } + event_quick_view = $(''); + template = '