Skip to content

Commit

Permalink
Merge branch 'develop' into transit-system
Browse files Browse the repository at this point in the history
  • Loading branch information
tykealy committed Sep 14, 2023
2 parents b4ee78b + 63f41ec commit 4ccfbd7
Show file tree
Hide file tree
Showing 36 changed files with 296 additions and 79 deletions.
22 changes: 11 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ GEM
async (>= 1.25)
auto_strip_attributes (2.6.0)
activerecord (>= 4.0)
autoprefixer-rails (10.4.13.0)
autoprefixer-rails (10.4.15.0)
execjs (~> 2)
awesome_nested_set (3.5.0)
activerecord (>= 4.0.0, < 7.1)
awesome_print (1.9.2)
aws-eventstream (1.2.0)
aws-partitions (1.813.0)
aws-partitions (1.818.0)
aws-sdk-core (3.181.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.651.0)
Expand Down Expand Up @@ -289,7 +289,7 @@ GEM
zeitwerk (~> 2.6)
ecma-re-validator (0.4.0)
regexp_parser (~> 2.2)
elastic-transport (8.2.2)
elastic-transport (8.2.3)
faraday (< 3)
multi_json
elasticsearch (8.9.0)
Expand Down Expand Up @@ -350,8 +350,8 @@ GEM
octokit (~> 4.6)
rainbow (>= 2.2.1)
rake (>= 10.0)
globalid (1.1.0)
activesupport (>= 5.0)
globalid (1.2.1)
activesupport (>= 6.1)
glyphicons (1.0.2)
googleauth (1.7.0)
faraday (>= 0.17.3, < 3.a)
Expand Down Expand Up @@ -441,7 +441,7 @@ GEM
mini_magick (4.12.0)
mini_mime (1.1.5)
mini_portile2 (2.8.4)
minitest (5.19.0)
minitest (5.20.0)
monetize (1.12.0)
money (~> 6.12)
money (6.16.0)
Expand Down Expand Up @@ -479,7 +479,7 @@ GEM
parser (3.2.2.3)
ast (~> 2.4.1)
racc
pg (1.5.3)
pg (1.5.4)
phonelib (0.8.3)
polyglot (0.3.5)
popper_js (1.16.1)
Expand Down Expand Up @@ -542,7 +542,7 @@ GEM
i18n
redis (5.0.7)
redis-client (>= 0.9.0)
redis-client (0.16.0)
redis-client (0.17.0)
connection_pool
regexp_parser (2.8.1)
responders (3.1.0)
Expand Down Expand Up @@ -617,13 +617,13 @@ GEM
activemodel (>= 6.1)
hashie
select2-rails (4.0.13)
selenium-webdriver (4.11.0)
selenium-webdriver (4.12.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
shoulda-matchers (5.3.0)
activesupport (>= 5.2.0)
signet (0.17.0)
signet (0.18.0)
addressable (~> 2.8)
faraday (>= 0.17.5, < 3.a)
jwt (>= 1.5, < 3.0)
Expand Down Expand Up @@ -719,7 +719,7 @@ GEM
spree_backend (>= 4.3.0.rc1)
spree_emails (>= 4.3.0.rc1)
spree_extension
sprockets (4.2.0)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
sprockets-rails (3.4.2)
Expand Down
28 changes: 20 additions & 8 deletions app/controllers/spree/admin/taxons_controller_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@ module Spree
module Admin
module TaxonsControllerDecorator
def self.prepended(base)
base.before_action :build_category_icon, only: %i[create update]
base.before_action :build_assets, only: %i[create update]
end

def remove_category_icon
if @taxon.category_icon.destroy
remove_asset(@taxon.category_icon)
end

def remove_app_banner
remove_asset(@taxon.app_banner)
end

def remove_web_banner
remove_asset(@taxon.web_banner)
end

private

def remove_asset(asset)
if asset.destroy
flash[:success] = Spree.t('notice_messages.icon_removed')
redirect_to spree.edit_admin_taxonomy_taxon_url(@taxonomy.id, @taxon.id)
else
Expand All @@ -15,12 +29,10 @@ def remove_category_icon
end
end

private

def build_category_icon
return unless permitted_resource_params[:category_icon]

@taxon.build_category_icon(attachment: permitted_resource_params.delete(:category_icon))
def build_assets
@taxon.build_category_icon(attachment: permitted_resource_params.delete(:category_icon)) if permitted_resource_params[:category_icon]
@taxon.build_app_banner(attachment: permitted_resource_params.delete(:app_banner)) if permitted_resource_params[:app_banner]
@taxon.build_web_banner(attachment: permitted_resource_params.delete(:web_banner)) if permitted_resource_params[:web_banner]
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class NotificationsController < Spree::Api::V2::ResourceController
before_action :require_spree_current_user

def collection
spree_current_user.notifications.newest_first
spree_current_user.notifications.newest_first.user_notifications
end

def serialize_collection(collection)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module Spree
module Api
module V2
module Storefront
class OrderRequestNotificationsController < Spree::Api::V2::ResourceController
before_action :require_spree_current_user

def collection
spree_current_user.notifications.top_3_request_notifications
end

def serialize_collection(collection)
options_data = collection_options(collection).merge(params: serializer_params)
options_data[:meta][:unread_count] = SpreeCmCommissioner::Notification.select(&:unread?).count

collection_serializer.new(
collection,
options_data
).serializable_hash
end

def collection_serializer
Spree::V2::Storefront::NotificationSerializer
end

def show
notification = SpreeCmCommissioner::Notification.find(params[:id])
SpreeCmCommissioner::NotificationReader.call(notification: notification)
render_serialized_payload { serialize_resource(notification) }
end

def resource_serializer
Spree::V2::Storefront::NotificationSerializer
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/spree/transit/branches_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module Spree
module Transit
class BranchesController < Spree::Transit::BaseController

def new
@branch = SpreeCmCommissioner::Branch.new
super
end

def collection
return @collection if defined?(@collection)

current_vendor.branches

@search = current_vendor.branches.ransack(params[:q])
Expand Down
9 changes: 3 additions & 6 deletions app/controllers/spree/transit/stops_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@ def index
@stops = SpreeCmCommissioner::Stop.order(:name)
end

def new
def new; end

end

def edit

end
def edit; end

def collection
load_location
return [] if current_vendor.blank?
return @collection if defined?(@collection)

@search = @locations.ransack(params[:q])
@collection = @search.result
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module SpreeCmCommissioner
class OrderRequestedNotificationSender < BaseInteractor
def call
notification = SpreeCmCommissioner::OrderRequestedNotification.with(
order: context.order
).deliver_later(context.order.user)

context.notification = notification
end
end
end
24 changes: 24 additions & 0 deletions app/models/concerns/spree_cm_commissioner/order_requestable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module OrderRequestable

included do
after_save :update_request_state_to_requested, if: :need_confirmation?
after_commit :send_order_requested_notification, if: :request_order?

state_machine :request_state, initial: nil, use_transactions: false do
event :request do
Expand All @@ -12,19 +13,42 @@ module OrderRequestable
event :accept do
transition from: :requested, to: :accepted
end
after_transition to: :accepted, do: :send_order_accepted_notification

event :reject do
transition from: :requested, to: :rejected
end
after_transition to: :rejected, do: :send_order_rejected_notification
end

def update_request_state_to_requested
request!
end

def send_order_requested_notification
SpreeCmCommissioner::OrderRequestedNotificationSender.call(order: self)
end

def send_order_accepted_notification
SpreeCmCommissioner::OrderAcceptedNotificationSender.call(order: self)
end

def send_order_rejected_notification
SpreeCmCommissioner::OrderRejectedNotificationSender.call(order: self)
end

def requested_state?
request_state == 'requested'
end

def request_order?
need_confirmation? && state_changed_to_complete?
end

def state_changed_to_complete?
saved_change_to_state? && state == 'complete'
end

def need_confirmation?
line_items.any?(&:need_confirmation?)
end
Expand Down
2 changes: 0 additions & 2 deletions app/models/spree_cm_commissioner/branch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class Branch < SpreeCmCommissioner::Place
belongs_to :state, class_name: 'Spree::State', optional: true
belongs_to :vendor, class_name: 'Spree::Vendor'

validates :vendor_id, presence: true

def validate_reference?
false
end
Expand Down
15 changes: 13 additions & 2 deletions app/models/spree_cm_commissioner/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@ module SpreeCmCommissioner
class Notification < SpreeCmCommissioner::Base
include Noticed::Model

scope :top_3_request_notifications, lambda {
where(
type: %w[order_requested_notification order_rejected_notification order_accepted_notification],
read_at: nil
).newest_first.limit(3)
}

scope :user_notifications, lambda {
where(
type: %w[order_complete_notification customer_notification]
)
}

belongs_to :recipient, polymorphic: true
belongs_to :notificable, polymorphic: true

validates :recipient_id, uniqueness: { scope: %i[notificable_id notificable_type] }
end
end
4 changes: 0 additions & 4 deletions app/models/spree_cm_commissioner/order_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ def associate_customer
def send_order_complete_notification
SpreeCmCommissioner::OrderCompleteNotificationSender.call(order: self)
end

def state_changed_to_complete?
saved_change_to_state? && state == 'complete'
end
end
end

Expand Down
2 changes: 2 additions & 0 deletions app/models/spree_cm_commissioner/product_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def self.prepended(base)
order('spree_variants.position, spree_variants.id, currency')
}, source: :prices, through: :variants_including_master

base.has_one :default_state, through: :vendor

base.scope :min_price, lambda { |vendor|
joins(:prices_including_master)
.where(vendor_id: vendor.id, product_type: vendor.primary_product_type)
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree_cm_commissioner/stop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ def validate_reference?
false
end
end
end
end
12 changes: 12 additions & 0 deletions app/models/spree_cm_commissioner/taxon_app_banner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module SpreeCmCommissioner
class TaxonAppBanner < Asset
# 16x9
def asset_styles
{
mini: '160x90>',
small: '480x270>',
medium: '960x540>'
}
end
end
end
1 change: 0 additions & 1 deletion app/models/spree_cm_commissioner/taxon_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module TaxonDecorator
def self.prepended(base)
base.has_one :category_icon, as: :viewable, dependent: :destroy, class_name: 'SpreeCmCommissioner::TaxonCategoryIcon'

## use in trending category card
base.has_one :web_banner, as: :viewable, dependent: :destroy, class_name: 'SpreeCmCommissioner::TaxonWebBanner'
base.has_one :app_banner, as: :viewable, dependent: :destroy, class_name: 'SpreeCmCommissioner::TaxonAppBanner'

Expand Down
9 changes: 4 additions & 5 deletions app/models/spree_cm_commissioner/taxon_web_banner.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
module SpreeCmCommissioner
class TaxonWebBanner < Asset
# 10x2
def asset_styles
{
mini: '85x85>',
extra_small: '170x170>',
small: '250x250',
medium: '340x340>',
large: '680x680>'
mini: '160x32>',
small: '720x90>',
medium: '1440x180>'
}
end
end
Expand Down
3 changes: 2 additions & 1 deletion app/models/spree_cm_commissioner/user_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def ensure_unique_database_delivery_method(attributes)
options = {
recipient_id: recipient.id,
notificable_id: attributes[:notificable].id,
notificable_type: attributes[:notificable].class.to_s
notificable_type: attributes[:notificable].class.to_s,
type: attributes[:type]
}

notification = recipient.notifications.where(options).first_or_initialize
Expand Down
Loading

0 comments on commit 4ccfbd7

Please sign in to comment.