Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4 0 stable #95

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3ac7362
updated the view of sidebar
usmanriaz111 Nov 15, 2019
b24092d
Updated the images for vendors many
usmanriaz111 Nov 20, 2019
b962fba
Updated the update function of images
usmanriaz111 Nov 20, 2019
406c9dd
Updated the drop down for category
usmanriaz111 Nov 20, 2019
85dce0c
Rename the image controller
usmanriaz111 Nov 22, 2019
0e1e670
Multiple images for vuctions
usmanriaz111 Nov 22, 2019
252b5bd
many to many relation for vendor and calendar
usmanriaz111 Nov 22, 2019
8eda612
Updated the create and update function for auction-images
usmanriaz111 Nov 26, 2019
26f4fcf
Commented commission
usmanriaz111 Nov 26, 2019
22508d4
Auction edit function of images updated
usmanriaz111 Nov 26, 2019
5111916
Updated the edit of auction images
usmanriaz111 Nov 26, 2019
9ecdca5
Updated the calender to calenders
usmanriaz111 Nov 26, 2019
e171bc9
Updated many auctions line in vendor.rb
usmanriaz111 Nov 28, 2019
5137061
Updated the scope Ajmal did
usmanriaz111 Dec 3, 2019
f3ab70c
add available vendors scope
Ajmal-hassan Dec 9, 2019
eaa3518
Merge pull request #2 from Ajmal-hassan/add_available_vendors_scope
usmanriaz111 Dec 9, 2019
4cf02cf
Update admin.rb
usmanriaz111 Dec 13, 2019
ffc2f24
Merge branch 'updated_admin_sidebar' of
yaseeniqbal Dec 13, 2019
9bd1e5d
add delete link for admin auction
YaseenIqbal75 Dec 16, 2019
97b8e32
update create method for vendors controller
YaseenIqbal75 Dec 30, 2019
4bc9c99
modify check in vendors controller
YaseenIqbal75 Dec 30, 2019
4f2c565
Update vendors_controller.rb
Ajmal-hassan Dec 30, 2019
8de96e3
Merge pull request #1 from Ajmal-hassan/patch-1
YaseenIqbal75 Dec 31, 2019
c6e38c2
add redirect check on create
YaseenIqbal75 Dec 31, 2019
673e487
update w.r.t redirect route
YaseenIqbal75 Jan 1, 2020
1bb3230
copy destroy from resource controller for redirect route
YaseenIqbal75 Jan 1, 2020
c58197a
add active tab to vendors listing in url
YaseenIqbal75 Jan 1, 2020
a121777
revert dropit admin redirection
YaseenIqbal75 Jan 6, 2020
a1d1610
add supper to create and update method
YaseenIqbal75 Jan 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
246 changes: 246 additions & 0 deletions app/controllers/spree/admin/images_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
module Spree
module Admin
class ImagesController < ResourceController
before_action :load_edit_data, except: :index
before_action :load_index_data, only: :index

create.before :set_viewable
update.before :set_viewable

def edit
if params[:vendor_id].present?
@vendor = Spree::Vendor.friendly.find(params[:vendor_id])
render 'edit_vendor'
elsif params[:auction_id].present?
@auction = Spree::Auction.find(params[:auction_id])
render "edit_auction"
else
respond_with(@object) do |format|
format.html { render layout: !request.xhr? }
format.js { render layout: false } if request.xhr?
end
end
end

def update
invoke_callbacks(:update, :before)
if @object.update(permitted_resource_params)
invoke_callbacks(:update, :after)
if params[:vendor_id].present?
@vendor = Spree::Vendor.friendly.find(params[:vendor_id])
redirect_vendor_image
elsif params[:auction_id].present?
@auction = Spree::Auction.find(params[:auction_id])
render "auction_index"
else
respond_with(@object) do |format|
format.html do
flash[:success] = flash_message_for(@object, :successfully_updated)
redirect_to location_after_save
end
format.js { render layout: false }
end
end

else
invoke_callbacks(:update, :fails)
if params[:vendor_id].present?
@vendor = Spree::Vendor.friendly.find(params[:vendor_id])
redirect_vendor_image
elsif params[:auction_id].present?
render "auction_index"
else
respond_with(@object) do |format|
format.html { render action: :edit }
format.js { render layout: false }
end
end

end
end

def destroy
invoke_callbacks(:destroy, :before)
if @object.destroy
if params[:vendor_id].present?
@vendor = Spree::Vendor.friendly.find(params[:vendor_id])
# redirect_vendor_image
respond_with(@vendor) do |format|
format.html {render :js => "window.location.href='"+request.referer+"'" }
format.js { render :js => "window.location.href='"+request.referer+"'" }
end
return
elsif params[:auction_id].present?
@auction = Spree::Auction.find(params[:auction_id])
respond_with(@auction) do |format|
format.html {render :js => "window.location.href='"+request.referer+"'" }
format.js { render :js => "window.location.href='"+request.referer+"'" }
end
return
else
invoke_callbacks(:destroy, :after)
flash[:success] = flash_message_for(@object, :successfully_removed)
end

else
if params[:vendor_id].present?
@vendor = Spree::Vendor.friendly.find(params[:vendor_id])
# redirect_vendor_image
respond_with(@vendor) do |format|
format.html {render :js => "window.location.href='"+request.referer+"'" }
format.js { render :js => "window.location.href='"+request.referer+"'" }
end
return
elsif params[:auction_id].present?
@auction = Spree::Auction.find(params[:auction_id])
respond_with(@auction) do |format|
format.html {render :js => "window.location.href='"+request.referer+"'" }
format.js { render :js => "window.location.href='"+request.referer+"'" }
end
return
else
invoke_callbacks(:destroy, :fails)
flash[:error] = @object.errors.full_messages.join(', ')
end

end

end

def create
invoke_callbacks(:create, :before)
@object.attributes = permitted_resource_params
if @object.save
if params[:vendor_id].present?
@vendor = Spree::Vendor.friendly.find(params[:vendor_id])
redirect_vendor_image
elsif params[:auction_id].present?
@auction = Spree::Auction.find(params[:auction_id])
render "auction_index"
else
invoke_callbacks(:create, :after)
flash[:success] = flash_message_for(@object, :successfully_created)
respond_with(@object) do |format|
format.html { redirect_to location_after_save }
format.js { render layout: false }
end
end

else
if params[:vendor_id].present?
redirect_vendor_image
elsif params[:auction_id].present?
render "auction_index"
end
invoke_callbacks(:create, :fails)
respond_with(@object) do |format|
format.html { render action: :new }
format.js { render layout: false }
end
end
end

def redirect_vendor_image
render "vendor_index"
end

private

def location_after_destroy
admin_product_images_url(@product)
end

def location_after_save
admin_product_images_url(@product)
end

def load_index_data
if params[:vendor_id].present?
@vendor = Vendor.friendly.find(params[:vendor_id])
render "vendor_index"
elsif params[:auction_id].present?
@auction = Auction.find(params[:auction_id])
render "auction_index"
else
@product = Product.friendly.includes(*variant_index_includes).find(params[:product_id])
end
end

def load_edit_data
if params[:vendor_id].present?
load_edit_data_vendors
if params[:action] == "new"
render "spree/admin/images/new_vendor"
end
elsif params[:auction_id].present?
load_edit_data_auctions
if params[:action] == "new"
render "spree/admin/images/new_auction"
end
else
load_edit_data_products
end
end

def load_edit_data_products
@product = Product.friendly.includes(*variant_edit_includes).find(params[:product_id])
root_taxon = get_root_taxon
@taxons = root_taxon.present? ? root_taxon.taxons.where(name: "product").first.children : nil
@variants = @product.variants.map do |variant|
[variant.sku_and_options_text, variant.id]
end
@variants.insert(0, [Spree.t(:all), @product.master.id])
end

def load_edit_data_vendors
@vendors = Vendor.friendly.find(params[:vendor_id])
# @taxons = Spree::Taxonomy.includes(root: :children).find_by(name: 'Image_Category').taxons.select{|s|s.children.empty?}
root_taxon = get_root_taxon
@taxons = root_taxon.present? ? root_taxon.taxons.where(name: "vendor").first.children : nil
end

def load_edit_data_auctions
@auctions = Auction.find(params[:auction_id])
root_taxon = get_root_taxon
@taxons = root_taxon.present? ? root_taxon.taxons.where(name: "auction").first.children : nil
end

def get_root_taxon
Spree::Taxonomy.includes(root: :children).find_by(name: 'Image')
end

def set_viewable
if params[:vendor_id].present?
@image.viewable_type = 'Spree::Vendor'
@image.viewable_id = Spree::Vendor.friendly.find(params[:vendor_id]).id
# @taxons = Spree::Taxonomy.includes(root: :children).find_by(name: 'Image_Category').taxons.select{|s|s.children.empty?}
@taxons = Spree::Taxonomy.includes(root: :children).find_by(name: 'Image').taxons.where(name: "vendor").first.children
# render "new_vendor"
elsif params[:auction_id].present?
@image.viewable_type = 'Spree::Auction'
@image.viewable_id = Spree::Auction.find(params[:auction_id]).id

else
@image.viewable_type = 'Spree::Variant'
@image.viewable_id = params[:image][:viewable_id]
end

end

def variant_index_includes
[
variant_images: [viewable: { option_values: :option_type }]
]
end

def variant_edit_includes
[
variants_including_master: { option_values: :option_type, images: :viewable }
]
end
def permitted_resource_params
params[resource.object_name].present? ? params.require(resource.object_name).permit! : ActionController::Parameters.new
end
end
end
end
8 changes: 7 additions & 1 deletion app/models/spree/vendor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class Vendor < Spree::Base
if Spree.version.to_f >= 3.6
validates_associated :image
end

validates :notification_email, email: true, allow_blank: true
has_many :auctions, class_name: 'Spree::Auction'

with_options dependent: :destroy do
if Spree.version.to_f >= 3.6
Expand All @@ -30,7 +30,13 @@ class Vendor < Spree::Base
has_many :stock_locations
has_many :variants
has_many :vendor_users
has_many :images, -> { order(:position) }, as: :viewable, dependent: :destroy, class_name: 'Spree::Image'
has_many :vendor_calenders
has_many :calenders, through: :vendor_calenders
end

scope :from_collection, -> (vendors_arr) {where("spree_vendors.id IN (?)", vendors_arr)}
scope :available_vendors, -> {pluck(:id, :name)}

has_many :users, through: :vendor_users

Expand Down
6 changes: 3 additions & 3 deletions app/overrides/spree/admin/layouts/admin.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Deface::Override.new(
virtual_path: 'spree/layouts/admin',
name: 'vendors_main_menu_tabs',
insert_bottom: '#main-sidebar',
insert_bottom: '#custom_vendor_tab',
text: <<-HTML
<% if current_spree_user.respond_to?(:has_spree_role?) && current_spree_user.has_spree_role?(:admin) %>
<ul class="nav nav-sidebar">
<ul class="nav nav-sidebar border-bottom">
<%= tab plural_resource_name(Spree::Vendor), url: admin_vendors_path, icon: 'money' %>
</ul>
<% end %>
<% if defined?(current_spree_vendor) && current_spree_vendor %>
<ul class="nav nav-sidebar">
<ul class="nav nav-sidebar border-bottom">
<%= tab Spree::Vendor.model_name.human, url: admin_vendor_settings_path, icon: 'money' %>
</ul>
<% end %>
Expand Down
22 changes: 11 additions & 11 deletions app/views/spree/admin/vendors/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
options_for_select(Spree::Vendor.state_machines[:state].states.collect { |s| [Spree.t("vendor_states.#{s.name}"), s.value] }, selected: @vendor.state),
{}, class: 'select2' %>
<% end %>
<% if Spree.version.to_f >= 3.6 %>
<%= f.field_container :image do %>
<%= f.label :image %>
<%= f.file_field :image %>
<%= image_tag main_app.url_for(@vendor.image.url(:small)) if @vendor.image %>
<% end %>
<% end %>
<%= f.field_container :commission_rate do %>
<%= f.label :commission_rate %>
<%= f.number_field :commission_rate, step: '0.01', class: 'form-control' %>
<% end %>
<%# if Spree.version.to_f >= 3.6 %>
<%#= f.field_container :image do %>
<%#= f.label :image %>
<%#= f.file_field :image %>
<%#= image_tag main_app.url_for(@vendor.image.url(:small)) if @vendor.image %>
<%# end %>
<%# end %>
<%#= f.field_container :commission_rate do %>
<%#= f.label :commission_rate %>
<%#= f.number_field :commission_rate, step: '0.01', class: 'form-control' %>
<%# end %>
<%= f.field_container :notification_email do%>
<%= f.label :notification_email %>
<%= f.email_field :notification_email, class: 'form-control' %>
Expand Down
3 changes: 3 additions & 0 deletions app/views/spree/admin/vendors/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<button class="btn btn-primary btn-success">
<%= link_to 'Add Images', spree.admin_vendor_images_url(@vendor) %>
</button>
<% content_for :page_title do %>
<%= link_to plural_resource_name(Spree::Vendor), spree.admin_vendors_url %> /
<%= @vendor.name %>
Expand Down
1 change: 1 addition & 0 deletions app/views/spree/admin/vendors/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
</td>
<td class="actions actions-2 text-right">
<%= link_to_edit vendor, no_text: true, class: 'edit' if can?(:edit, vendor) %>
<%= link_to_delete vendor, no_text: true %>
</td>
</tr>
<% end %>
Expand Down