From 3cf8d3c8964d9b1c4f18f6c0395be6c2ab5c8f5b Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Wed, 4 Mar 2015 20:48:24 +0100 Subject: [PATCH] ios support --- Gemfile | 3 +- Gemfile.lock | 15 +++++- Procfile | 4 +- .../controllers/section_controller.js.coffee | 16 +++---- .../supplier/app/mixins/drag_n_drop.js.coffee | 46 +++++++++++++++++++ .../templates/section/section-element.emblem | 2 +- .../views/section/section-element.js.coffee | 2 +- .../app/views/section/tables.js.coffee | 10 ++-- .../supplier/foundation1/application.js.erb | 5 +- .../foundation1/jquery.ui.touch-punch.min.js | 11 ----- .../supplier/foundation1/_qstructure.css.sass | 2 - .../components/_section_elements.css.sass | 1 + .../components/_section_tables.css.sass | 4 ++ app/controllers/application_controller.rb | 8 +++- .../suppliers/suppliers_controller.rb | 2 +- app/views/admin/svg_elements/index.html.slim | 2 +- bin/build_mobile_app.rb | 0 bin/bundle | 3 ++ bin/migrate_translations.rb | 0 bin/rails | 6 +-- bin/rake | 9 ++-- bin/setup | 29 ++++++++++++ 22 files changed, 127 insertions(+), 53 deletions(-) delete mode 100644 app/assets/javascripts/supplier/foundation1/jquery.ui.touch-punch.min.js mode change 100644 => 100755 bin/build_mobile_app.rb create mode 100755 bin/bundle mode change 100644 => 100755 bin/migrate_translations.rb create mode 100755 bin/setup diff --git a/Gemfile b/Gemfile index ca23ee19..2afbbe28 100644 --- a/Gemfile +++ b/Gemfile @@ -110,6 +110,8 @@ group :development do gem 'spring' gem 'spring-commands-rspec' gem 'web-console', '~> 2.0.0' + gem 'foreman' + gem 'thin' end group :test do @@ -128,7 +130,6 @@ end # Use unicorn as the app server # gem 'unicorn' -# gem 'foreman' # Deploy with Capistrano # gem 'capistrano' diff --git a/Gemfile.lock b/Gemfile.lock index df45a14d..048c0ce9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: git://github.com/bterkuile/cmtool.git - revision: b0491aa997cca6e791b7352f40e2adf90191a1cd + revision: 2b0d4816b82ca202728893d5800f2fc13a17b63b specs: cmtool (1.0.0) bourbon @@ -138,7 +138,7 @@ GEM climate_control (0.0.3) activesupport (>= 3.0) cliver (0.3.2) - cocaine (0.5.5) + cocaine (0.5.7) climate_control (>= 0.0.3, < 1.0) coderay (1.1.0) coffee-rails (4.1.0) @@ -157,6 +157,7 @@ GEM rest-client (~> 1.6.1) crack (0.4.2) safe_yaml (~> 1.0.0) + daemons (1.1.9) debug_inspector (0.0.2) devise (3.4.1) bcrypt (~> 3.0) @@ -168,6 +169,7 @@ GEM devise-i18n (0.11.3) diff-lcs (1.2.5) docile (1.1.5) + dotenv (1.0.2) em-http-request (1.1.2) addressable (>= 2.3.4) cookiejar @@ -226,6 +228,9 @@ GEM ffi (1.9.6) font-awesome-rails (4.3.0.0) railties (>= 3.2, < 5.0) + foreman (0.77.0) + dotenv (~> 1.0.2) + thor (~> 0.19.1) foundation-rails (5.5.1.0) railties (>= 3.1.0) sass (>= 3.3.0, < 3.5) @@ -427,6 +432,10 @@ GEM temple (0.7.5) test_squad (0.0.1) rails + thin (1.6.3) + daemons (~> 1.0, >= 1.0.9) + eventmachine (~> 1.0) + rack (~> 1.0) thor (0.19.1) thread_safe (0.3.4) tilt (1.4.1) @@ -487,6 +496,7 @@ DEPENDENCIES factory_girl_rails faye font-awesome-rails + foreman foundation-rails fuubar iso_country_codes @@ -519,6 +529,7 @@ DEPENDENCIES spring spring-commands-rspec test_squad + thin turnip uglifier (>= 1.0.3) web-console (~> 2.0.0) diff --git a/Procfile b/Procfile index 20e7e41f..29458073 100644 --- a/Procfile +++ b/Procfile @@ -4,4 +4,6 @@ # production: faye: thin start -d -R faye/config.ru -p 9296 #counters: bin/drb_counter.rb run -- development # production: conters: bin/drb_counter.rb start -server: bundle exec rails s -e production +counters: drb_counter/drb_counter.rb development +faye: thin start -R faye/config.ru -p 9296 +#server: bundle exec rails s -e production diff --git a/app/assets/javascripts/supplier/app/controllers/section_controller.js.coffee b/app/assets/javascripts/supplier/app/controllers/section_controller.js.coffee index 64ad6826..5376e4c3 100644 --- a/app/assets/javascripts/supplier/app/controllers/section_controller.js.coffee +++ b/app/assets/javascripts/supplier/app/controllers/section_controller.js.coffee @@ -6,20 +6,20 @@ App.SectionController = Ember.ObjectController.extend finishEditable: -> @set('editmode', false) @get('model').save() - @get('model.section_elements').forEach (section_element) -> section_element.save() - @get('model.section_areas').forEach (section_area) -> section_area.save() + @get('model.section_elements').filterProperty('isDirty').invoke 'save' + @get('model.section_areas').filterProperty('isDirty').invoke 'save' rollbackEditable: -> @get('model').rollback() @get('model.section_elements').forEach (section_element) -> - if section_element.get('id') - section_element.rollback() - else + if section_element.get('isNew') section_element.deleteRecord() - @get('model.section_areas').forEach (section_area) -> - if section_area.get('id') - section_area.rollback() else + section_element.rollback() + @get('model.section_areas').forEach (section_area) -> + if section_area.get('isNew') section_area.deleteRecord() + else + section_area.rollback() @set('editmode', false) addSection: -> @modal 'add_section', model: @get('model') addTables: -> @modal 'section_add_tables', model: @get('model') diff --git a/app/assets/javascripts/supplier/app/mixins/drag_n_drop.js.coffee b/app/assets/javascripts/supplier/app/mixins/drag_n_drop.js.coffee index 515c9e71..c75171da 100644 --- a/app/assets/javascripts/supplier/app/mixins/drag_n_drop.js.coffee +++ b/app/assets/javascripts/supplier/app/mixins/drag_n_drop.js.coffee @@ -28,7 +28,39 @@ DragNDrop.Draggable = Ember.Mixin.create @set 'targetObject.isDragging', false @set 'targetObject.controllers.application.isDragging', false localStorage.removeItem 'draggingView' if localStorage.getItem 'draggingView' + touchStart: (ev)-> + ev.preventDefault() + target = @$() + return unless target.prop 'draggable' + touch = ev.originalEvent.changedTouches[0] + @touchStartEvent = + left: parseFloat(target.css('left')) + top: parseFloat(target.css('top')) + pageX: touch.pageX + pageY: touch.pageY + touchMove: (ev)-> + ev.preventDefault() + target = @$() + return unless target.prop 'draggable' + if ev.originalEvent.changedTouches.length is 1 + touch = ev.originalEvent.changedTouches[0] + target.css + left: "#{@touchStartEvent.left + touch.pageX - @touchStartEvent.pageX}px" + top: "#{@touchStartEvent.top + touch.pageY - @touchStartEvent.pageY}px" + touchEnd: (ev)-> + ev.preventDefault() + touch = ev.originalEvent.changedTouches[0] + if Math.abs(@touchStartEvent.pageX - touch.pageX) < 2 and Math.abs(@touchStartEvent.pageY - touch.pageY) < 2 + # The preventDefaults are preventing the click action to fire, therefore we trigger it ourselves + # But do not trigger when a handle insed the element is clicked + unless $(ev.target).parents('.handles-inside-draggable') or $(ev.target).hasClass('handles-inside-draggable') + @click() if @click + else + $(ev.target).click() + + @touchStartEvent = null + this DragNDrop.Droppable = Ember.Mixin.create dragEnter: (e)-> if @dragEntered @@ -40,6 +72,20 @@ DragNDrop.Droppable = Ember.Mixin.create # DragNDrop.cancel(e) dragOver: DragNDrop.cancel # don't know why, but crucial for the current way of working with section tables # dragOver: (e)->(e.preventDefault(); false) + touchEnd: (ev)-> + ev.preventDefault() + view = ev.result + return unless view._parentView + target = view.$() + return unless target.prop 'draggable' + newX = parseFloat(target.css('left')) + newY = parseFloat(target.css('top')) + return unless newX? and newY? + position = + left: newX + top: newY + @dropped view, position if @dropped + this dragLeave: -> if @dragLeft @dragLeft() diff --git a/app/assets/javascripts/supplier/app/templates/section/section-element.emblem b/app/assets/javascripts/supplier/app/templates/section/section-element.emblem index 760be3e7..6921dfc6 100644 --- a/app/assets/javascripts/supplier/app/templates/section/section-element.emblem +++ b/app/assets/javascripts/supplier/app/templates/section/section-element.emblem @@ -1,6 +1,6 @@ = svg view.content.svg width=view.content.box_width height=view.content.box_height rotation=view.content.rotation if view.showHandles - .section-element-handles + .section-element-handles.handles-inside-draggable a.rotate-left{action "rotateLeft" view.content bubbles=false}: span.icon a.rotate-right{action "rotateRight" view.content bubbles=false}: span.icon a.remove-section-element{action "removeSectionElement" view.content bubbles=false}: span.icon diff --git a/app/assets/javascripts/supplier/app/views/section/section-element.js.coffee b/app/assets/javascripts/supplier/app/views/section/section-element.js.coffee index c1e3899a..5e9c147b 100644 --- a/app/assets/javascripts/supplier/app/views/section/section-element.js.coffee +++ b/app/assets/javascripts/supplier/app/views/section/section-element.js.coffee @@ -1,6 +1,6 @@ App.SectionElementView = Ember.View.extend DragNDrop.Draggable, templateName: 'section/section-element' - classNames: ['section-element'] + classNames: ['section-element-container'] attributeBindings: ['style'] show_handles: false classNameBindings: [ diff --git a/app/assets/javascripts/supplier/app/views/section/tables.js.coffee b/app/assets/javascripts/supplier/app/views/section/tables.js.coffee index 6ce472d6..9939cf86 100644 --- a/app/assets/javascripts/supplier/app/views/section/tables.js.coffee +++ b/app/assets/javascripts/supplier/app/views/section/tables.js.coffee @@ -1,11 +1,8 @@ App.SectionTablesView = Ember.View.extend DragNDrop.Droppable, classNames: ['well', 'section-tables-container', 'section-tables-active'] + classNameBindings: ['controller.editmode:editing'] templateName: 'section/tables' dpm: 1 - didInsertElement: -> - @$el = $(@get('element')) - height = @$el.width() * @get('controller.model.height') / @get('controller.model.width') - @$el.css('height', height) dropped: (view, position)-> view.positionChange(position, @content) observeSectionDimensions: (-> @@ -21,10 +18,9 @@ App.SectionTablesView = Ember.View.extend DragNDrop.Droppable, dpm = viewport_height / section_height @$el.css 'width', dpm * section_width @$el.css 'height', dpm * section_height - console.log "SECTION dpm #{dpm}" @set 'dpm', dpm ).observes('controller.model.height', 'controller.model.width') - tables: (->@get('content')).property('content') + tables: (->@get('content')).property('content.@each') didInsertElement: -> # the first observable event is triggered without the container having its dimensions - @get('controller.model').notifyPropertyChange('width').notifyPropertyChange('height') + @get('controller.model').notifyPropertyChange('width') #.notifyPropertyChange('height') diff --git a/app/assets/javascripts/supplier/foundation1/application.js.erb b/app/assets/javascripts/supplier/foundation1/application.js.erb index 237914de..bb26095f 100644 --- a/app/assets/javascripts/supplier/foundation1/application.js.erb +++ b/app/assets/javascripts/supplier/foundation1/application.js.erb @@ -2,17 +2,14 @@ //= require jquery //= require jquery_ujs //= require jquery-ui/sortable -//= require jquery.ui.touch-punch +// require ./im // require foundation FOUNDATION 5 JAVASCRIPT IMPLEMENTATIONS AND EMBER ARE NOT COMPATIBLE, FOUNDATION IS TOO SIMPLISTIC AT THE MOMENT AND DESTROYS DOM EVENTS //= require js-routes //= require moment //= require fullcalendar //= require translations -// require qwaiter -// require ./qsupplier //= require faye //= require ./base -// require qtip # was used for table actions in section view, now done by EMBER //= require pickdate //= require_directory . //= require_self diff --git a/app/assets/javascripts/supplier/foundation1/jquery.ui.touch-punch.min.js b/app/assets/javascripts/supplier/foundation1/jquery.ui.touch-punch.min.js deleted file mode 100644 index 33d6f97e..00000000 --- a/app/assets/javascripts/supplier/foundation1/jquery.ui.touch-punch.min.js +++ /dev/null @@ -1,11 +0,0 @@ -/* - * jQuery UI Touch Punch 0.2.2 - * - * Copyright 2011, Dave Furfero - * Dual licensed under the MIT or GPL Version 2 licenses. - * - * Depends: - * jquery.ui.widget.js - * jquery.ui.mouse.js - */ -(function(b){b.support.touch="ontouchend" in document;if(!b.support.touch){return;}var c=b.ui.mouse.prototype,e=c._mouseInit,a;function d(g,h){if(g.originalEvent.touches.length>1){return;}g.preventDefault();var i=g.originalEvent.changedTouches[0],f=document.createEvent("MouseEvents");f.initMouseEvent(h,true,true,window,1,i.screenX,i.screenY,i.clientX,i.clientY,false,false,false,false,0,null);g.target.dispatchEvent(f);}c._touchStart=function(g){var f=this;if(a||!f._mouseCapture(g.originalEvent.changedTouches[0])){return;}a=true;f._touchMoved=false;d(g,"mouseover");d(g,"mousemove");d(g,"mousedown");};c._touchMove=function(f){if(!a){return;}this._touchMoved=true;d(f,"mousemove");};c._touchEnd=function(f){if(!a){return;}d(f,"mouseup");d(f,"mouseout");if(!this._touchMoved){d(f,"click");}a=false;};c._mouseInit=function(){var f=this;f.element.bind("touchstart",b.proxy(f,"_touchStart")).bind("touchmove",b.proxy(f,"_touchMove")).bind("touchend",b.proxy(f,"_touchEnd"));e.call(f);};})(jQuery); \ No newline at end of file diff --git a/app/assets/stylesheets/supplier/foundation1/_qstructure.css.sass b/app/assets/stylesheets/supplier/foundation1/_qstructure.css.sass index d5deb5a2..7ec069e8 100644 --- a/app/assets/stylesheets/supplier/foundation1/_qstructure.css.sass +++ b/app/assets/stylesheets/supplier/foundation1/_qstructure.css.sass @@ -12,8 +12,6 @@ $side-spacing: 0px display: inline-block .location_picker_search float: left -.draggable - cursor: move !important .text-alert color: $alert-color .text-warning diff --git a/app/assets/stylesheets/supplier/foundation1/components/_section_elements.css.sass b/app/assets/stylesheets/supplier/foundation1/components/_section_elements.css.sass index e409378d..1e408983 100644 --- a/app/assets/stylesheets/supplier/foundation1/components/_section_elements.css.sass +++ b/app/assets/stylesheets/supplier/foundation1/components/_section_elements.css.sass @@ -6,6 +6,7 @@ margin-right: 10px margin-bottom: 10px width: 80px + max-height: 120px border: 2px outset #aaa &:hover border-color: $active-color diff --git a/app/assets/stylesheets/supplier/foundation1/components/_section_tables.css.sass b/app/assets/stylesheets/supplier/foundation1/components/_section_tables.css.sass index 6060cc5d..ae2b8de8 100644 --- a/app/assets/stylesheets/supplier/foundation1/components/_section_tables.css.sass +++ b/app/assets/stylesheets/supplier/foundation1/components/_section_tables.css.sass @@ -30,6 +30,10 @@ position: relative padding: 0 height: 400px + &.editing + background-color: rgba(240, 138, 36, 0.5) + .section-element-container, .section-area-container + cursor: pointer //background-image: image-url('textures/wood4.jpg') //background-color: rgba(0,0,0,0.4) .section-table diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 38ed4a63..9223903a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -15,7 +15,6 @@ class ApplicationController < ActionController::Base private - def allow_all_origins headers['Access-Control-Allow-Origin'] = '*' headers['Access-Control-Request-Method'] = '*' @@ -24,7 +23,11 @@ private end def authorize_cmtool - redirect_to '/', alert: t('general.unauthorized') unless current_user.present? && current_user.admin? + redirect_to new_administrator_session_path, alert: t('general.unauthorized') unless current_administrator.present? + end + + def cmtool_user + current_administrator end def cmtool_locale @@ -65,6 +68,7 @@ private def after_sign_in_path_for(resource) case resource when Employee then supplier_root_path + when Administrator then cmtool.root_path else root_path end end diff --git a/app/controllers/suppliers/suppliers_controller.rb b/app/controllers/suppliers/suppliers_controller.rb index 663b71c6..a2d9221a 100644 --- a/app/controllers/suppliers/suppliers_controller.rb +++ b/app/controllers/suppliers/suppliers_controller.rb @@ -6,7 +6,7 @@ module Suppliers def show [current_supplier].include_relations(sections: :tables, product_categories: :products) - render json: Suppliers::SupplierSerializer.new(current_supplier).as_json + render json: current_supplier, serializer: Suppliers::SupplierSerializer #.new(current_supplier).as_json end def update diff --git a/app/views/admin/svg_elements/index.html.slim b/app/views/admin/svg_elements/index.html.slim index 47579021..312f116d 100644 --- a/app/views/admin/svg_elements/index.html.slim +++ b/app/views/admin/svg_elements/index.html.slim @@ -1,5 +1,5 @@ - model_class = SvgElement -div.page-header= title :index, model_class +- title :index, model_class - if @svg_elements.any? table.table thead diff --git a/bin/build_mobile_app.rb b/bin/build_mobile_app.rb old mode 100644 new mode 100755 diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 00000000..66e9889e --- /dev/null +++ b/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/bin/migrate_translations.rb b/bin/migrate_translations.rb old mode 100644 new mode 100755 diff --git a/bin/rails b/bin/rails index 7feb6a30..5191e692 100755 --- a/bin/rails +++ b/bin/rails @@ -1,8 +1,4 @@ #!/usr/bin/env ruby -begin - load File.expand_path("../spring", __FILE__) -rescue LoadError -end -APP_PATH = File.expand_path('../../config/application', __FILE__) +APP_PATH = File.expand_path('../../config/application', __FILE__) require_relative '../config/boot' require 'rails/commands' diff --git a/bin/rake b/bin/rake index 0fb4e07e..17240489 100755 --- a/bin/rake +++ b/bin/rake @@ -1,7 +1,4 @@ #!/usr/bin/env ruby -begin - load File.expand_path("../spring", __FILE__) -rescue LoadError -end -require 'bundler/setup' -load Gem.bin_path('rake', 'rake') +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/bin/setup b/bin/setup new file mode 100755 index 00000000..acdb2c13 --- /dev/null +++ b/bin/setup @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'pathname' + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +Dir.chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file: + + puts "== Installing dependencies ==" + system "gem install bundler --conservative" + system "bundle check || bundle install" + + # puts "\n== Copying sample files ==" + # unless File.exist?("config/database.yml") + # system "cp config/database.yml.sample config/database.yml" + # end + + puts "\n== Preparing database ==" + system "bin/rake db:setup" + + puts "\n== Removing old logs and tempfiles ==" + system "rm -f log/*" + system "rm -rf tmp/cache" + + puts "\n== Restarting application server ==" + system "touch tmp/restart.txt" +end