From 575abf01e5792a7b8e3a003c70f7d4886060ddf4 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Fri, 6 Jan 2017 06:43:38 -0600 Subject: [PATCH] pin carrier wave in web --- ruby/lib/jam_ruby/models/lesson_booking.rb | 5 ++ ruby/lib/jam_ruby/models/lesson_session.rb | 18 +++--- ruby/lib/jam_ruby/models/retailer.rb | 16 ++++++ web/Gemfile | 2 +- .../AccountRetailerScreen.js.jsx.coffee | 56 ++++++++++++++++++- .../AccountRetailerScreen.scss | 6 ++ web/app/controllers/artifacts_controller.rb | 4 +- web/app/views/api_retailers/show.rabl | 2 +- 8 files changed, 95 insertions(+), 14 deletions(-) diff --git a/ruby/lib/jam_ruby/models/lesson_booking.rb b/ruby/lib/jam_ruby/models/lesson_booking.rb index 0d4007550..d2090c41d 100644 --- a/ruby/lib/jam_ruby/models/lesson_booking.rb +++ b/ruby/lib/jam_ruby/models/lesson_booking.rb @@ -799,6 +799,11 @@ module JamRuby lesson_booking.school = lesson_booking.teacher.teacher.school end + # copy payment settings from retailer into lesson booking + if lesson_booking.teacher && lesson_booking.teacher.teacher.retailer + lesson_booking.payment = lesson_booking.teacher.teacher.retailer.payment_details.to_json + end + if user lesson_booking.same_school = !!(lesson_booking.school && user.school && (lesson_booking.school.id == user.school.id)) if lesson_booking.same_school diff --git a/ruby/lib/jam_ruby/models/lesson_session.rb b/ruby/lib/jam_ruby/models/lesson_session.rb index f21bceee7..0a50b74e0 100644 --- a/ruby/lib/jam_ruby/models/lesson_session.rb +++ b/ruby/lib/jam_ruby/models/lesson_session.rb @@ -220,16 +220,18 @@ module JamRuby if success && lesson_booking.requires_teacher_distribution?(self) - is_education_school_on_school = lesson_booking.school_on_school_payment? - self.teacher_distributions << TeacherDistribution.create_for_lesson(self, false) - if is_education_school_on_school - self.teacher_distributions << TeacherDistribution.create_for_lesson(self, true) + if lesson_booking.payment + # if there is a payment object, it will describe how everything gets doled out + + else + is_education_school_on_school = lesson_booking.school_on_school_payment? + + self.teacher_distributions << TeacherDistribution.create_for_lesson(self, false) + if is_education_school_on_school + self.teacher_distributions << TeacherDistribution.create_for_lesson(self, true) + end end - - # this is a bit of a hack, in how the code is structured. - # but basically, the distributions calculated are too dynamic for the above code. - # if this is a retailer end if self.save diff --git a/ruby/lib/jam_ruby/models/retailer.rb b/ruby/lib/jam_ruby/models/retailer.rb index 50185e5eb..84b11be82 100644 --- a/ruby/lib/jam_ruby/models/retailer.rb +++ b/ruby/lib/jam_ruby/models/retailer.rb @@ -65,6 +65,13 @@ module JamRuby self.city = params[:city] self.state = params[:state] self.slug = params[:slug] if params[:slug].present? + if params[:split] + split = params[:split] + if split[:teacher] && split[:teacher].is_a?(Number) && split[:retailer] && split[:retailer].is_a?(Number) + self.payment = split.to_json + end + + end if params[:password].present? self.should_validate_password = true @@ -74,6 +81,15 @@ module JamRuby self.save end + # should be of form {teacher: 0-100, retailer: 0-100} + def payment_details + if self.payment + JSON.parse(self.payment) + else + {"teacher" => 75, "retailer" => 25} + end + end + def owner user end diff --git a/web/Gemfile b/web/Gemfile index a622780a4..f9a12477a 100644 --- a/web/Gemfile +++ b/web/Gemfile @@ -72,7 +72,7 @@ gem 'filepicker-rails', '0.1.0' gem 'aws-sdk', '~> 1' gem 'aasm' #, '3.0.16' gem 'carmen' -gem 'carrierwave' #, '0.9.0' +gem 'carrierwave', '0.11.2' #, '0.9.0' gem 'carrierwave_direct' gem 'fog' #gem 'jquery-payment-rails', github: 'sethcall/jquery-payment-rails' diff --git a/web/app/assets/javascripts/react-components/AccountRetailerScreen.js.jsx.coffee b/web/app/assets/javascripts/react-components/AccountRetailerScreen.js.jsx.coffee index e4d31e1be..9305e682f 100644 --- a/web/app/assets/javascripts/react-components/AccountRetailerScreen.js.jsx.coffee +++ b/web/app/assets/javascripts/react-components/AccountRetailerScreen.js.jsx.coffee @@ -92,6 +92,7 @@ profileUtils = context.JK.ProfileUtils selected: 'account', updateErrors: null, retailerName: null, + teacherSplit: null, teacherInvitations: null, updating: false } @@ -121,18 +122,24 @@ profileUtils = context.JK.ProfileUtils city = @root.find('select[name="cities"]').val() password = @root.find('input[type="password"]').val() + teacherSplit = @teacherSplit() + + retailerSplit = (100 - teacherSplit).toFixed(2) + @setState(updating: true) rest.updateRetailer({ id: this.state.retailer.id, name: name, state: region, city: city, - password:password + password:password, + split: {teacher: teacherSplit, retailer: retailerSplit} }).done((response) => @onUpdateDone(response)).fail((jqXHR) => @onUpdateFail(jqXHR)) + onUpdateDone: (response) -> - @setState({retailer: response, retailerName: null, updateErrors: null, updating: false}) + @setState({retailer: response, retailerName: null, teacherSplit: null, updateErrors: null, updating: false}) @app.layout.notify({title: "update success", text: "Your retailer information has been successfully updated"}) @@ -262,6 +269,40 @@ profileUtils = context.JK.ProfileUtils logger.debug("handleLocationChange #{country} #{region} ${city}") @setState({city: city, region: region}) + teacherSplitCurrent: () -> + if this.state.teacherSplit? + this.state.teacherSplit + else + this.state.retailer.payment_details.teacherSplit + + teacherSplitValue: () -> + @teacherSplitCurrent() + + retailerSplitValue: () -> + teacherSplit = @teacherSplitCurrent() + return (100 - teacherSplit).toFixed(2) + + onTeacherBlur: () -> + teacherSplit = @root.find('input[name="teacher-split"]').val() + teacherSplit = Number(teacherSplit) + if teacherSplit != teacherSplit #NaN? + @setState({teacherSplit: null}) + + + teacherSplit: () -> + teacherSplit = @root.find('input[name="teacher-split"]').val() + if teacherSplit + teacherSplit = Number(teacherSplit) + if !teacherSplit + teacherSplit = 75 + teacherSplit + + onTeacherSplitChange: (e) -> + $target = $(e.target) + + teacherSplit = @teacherSplit() + @setState({teacherSplit: teacherSplit}) + account: () -> nameErrors = context.JK.reactSingleFieldErrors('name', @state.updateErrors) @@ -313,6 +354,17 @@ profileUtils = context.JK.ProfileUtils +
+
+ + +
+
+ + +
+
+
CANCEL UPDATE diff --git a/web/app/assets/stylesheets/client/react-components/AccountRetailerScreen.scss b/web/app/assets/stylesheets/client/react-components/AccountRetailerScreen.scss index 58134ce83..1573570bf 100644 --- a/web/app/assets/stylesheets/client/react-components/AccountRetailerScreen.scss +++ b/web/app/assets/stylesheets/client/react-components/AccountRetailerScreen.scss @@ -280,4 +280,10 @@ font-size:12px; margin:0; } + + .split-input { + :after { + content: '%'; + } + } } diff --git a/web/app/controllers/artifacts_controller.rb b/web/app/controllers/artifacts_controller.rb index b7eeb7776..9602dd565 100644 --- a/web/app/controllers/artifacts_controller.rb +++ b/web/app/controllers/artifacts_controller.rb @@ -10,10 +10,10 @@ class ArtifactsController < ApiController if is_jamblaster # check and see if there is a build just for this JB - clients = ArtifactUpdate.where('product ilike ? and environment = ?', "JamClient/#{params[:type]}%", params[:serialno]).order(:product) + clients = ArtifactUpdate.where('product ilike ? and environment = ?', "JamClient/#{params[:type]}", params[:serialno]).order(:product) if clients.count == 0 # if not, then fine, give back the default environment - clients = ArtifactUpdate.where('product ilike ? and environment = ?', "JamClient/#{params[:type]}%", ArtifactUpdate::DEFAULT_ENVIRONMENT).order(:product) + clients = ArtifactUpdate.where('product ilike ? and environment = ?', "JamClient/#{params[:type]}", ArtifactUpdate::DEFAULT_ENVIRONMENT).order(:product) end else clients = ArtifactUpdate.where("product like '%JamClient%' and environment = '#{ArtifactUpdate::DEFAULT_ENVIRONMENT}'").order(:product) diff --git a/web/app/views/api_retailers/show.rabl b/web/app/views/api_retailers/show.rabl index e8b5da7f3..1c9cd75e9 100644 --- a/web/app/views/api_retailers/show.rabl +++ b/web/app/views/api_retailers/show.rabl @@ -1,6 +1,6 @@ object @retailer -attributes :id, :user_id, :name, :enabled, :original_fpfile, :cropped_fpfile, :crop_selection, :photo_url, :slug, :state, :city +attributes :id, :user_id, :name, :enabled, :original_fpfile, :cropped_fpfile, :crop_selection, :photo_url, :slug, :state, :city, :payment_details child :owner => :owner do attributes :id, :email, :photo_url, :name, :first_name, :last_name