solidus_product_attachments 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +26 -0
  3. data/README.md +42 -0
  4. data/Rakefile +32 -0
  5. data/app/assets/javascripts/spree/backend/attachments/attachment_upload.js.coffee +65 -0
  6. data/app/assets/javascripts/spree/backend/attachments/extensions.js.coffee +10 -0
  7. data/app/assets/javascripts/spree/backend/attachments/index.js.coffee +7 -0
  8. data/app/assets/javascripts/spree/backend/attachments/upload.js.coffee +26 -0
  9. data/app/assets/javascripts/spree/backend/attachments/upload_zone.js.coffee +38 -0
  10. data/app/assets/javascripts/spree/backend/solidus_product_attachments.js +2 -0
  11. data/app/assets/javascripts/spree/backend/templates/products/upload_progress.hbs +12 -0
  12. data/app/assets/javascripts/spree/frontend/solidus_product_attachments.js +2 -0
  13. data/app/assets/stylesheets/spree/backend/attachments/attachments.scss +17 -0
  14. data/app/assets/stylesheets/spree/backend/solidus_product_attachments.css +4 -0
  15. data/app/assets/stylesheets/spree/frontend/solidus_product_attachments.css +4 -0
  16. data/app/controllers/spree/admin/attachments_controller.rb +31 -0
  17. data/app/controllers/spree/api/attachments_controller.rb +19 -0
  18. data/app/helpers/spree/admin/attachments_helper.rb +11 -0
  19. data/app/models/spree/attachment.rb +16 -0
  20. data/app/models/spree/product_decorator.rb +13 -0
  21. data/app/models/spree/variant_decorator.rb +11 -0
  22. data/app/overrides/product_tabs.rb +5 -0
  23. data/app/views/spree/admin/attachments/_attachment_row.html.erb +38 -0
  24. data/app/views/spree/admin/attachments/_form.html.erb +22 -0
  25. data/app/views/spree/admin/attachments/_new.html.erb +12 -0
  26. data/app/views/spree/admin/attachments/create.js.erb +8 -0
  27. data/app/views/spree/admin/attachments/edit.html.erb +27 -0
  28. data/app/views/spree/admin/attachments/index.html.erb +71 -0
  29. data/app/views/spree/admin/attachments/new.html.erb +1 -0
  30. data/app/views/spree/api/attachments/_attachment.json.jbuilder +5 -0
  31. data/app/views/spree/api/attachments/show.json.jbuilder +1 -0
  32. data/app/views/spree/shared/_product_documents_tab.html.erb +5 -0
  33. data/config/locales/de.yml +16 -0
  34. data/config/locales/en.yml +16 -0
  35. data/config/routes.rb +17 -0
  36. data/lib/generators/solidus_product_attachments/install/install_generator.rb +30 -0
  37. data/lib/solidus_product_attachments.rb +6 -0
  38. data/lib/solidus_product_attachments/engine.rb +20 -0
  39. data/lib/solidus_product_attachments/version.rb +3 -0
  40. metadata +277 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8d3e8694beb9ca466ba023cddf22150ddcef1a8e
4
+ data.tar.gz: cc78667eef480432f33e7f32451039fb7a1ccbef
5
+ SHA512:
6
+ metadata.gz: 1ee69cc748c6a2bb2c47a28095f1f52b173387bc6b6348ae9439aa6bfbfa2addaf7b8e5aaf857c26cd56d3ade5bbb757f1dae63fa022ff23142f2f63abbc4630
7
+ data.tar.gz: f92b0fe59af83e798bcc903534de0a68c9c1801666bba119cb0f6db17c2c5a13145001b3791e6ff2778ab959709ed56b1f5623d02fe78b514b780135f69ba6ba
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2019 [name of plugin creator]
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Spree nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,42 @@
1
+ SolidusProductAttachments
2
+ =========================
3
+
4
+ Allows the administrator to add attachments to a product/variant.
5
+
6
+ [![Build Status](https://semaphoreci.com/api/v1/projects/c5f055f7-da80-440c-9f7b-c9c6c4a87bfa/2535219/shields_badge.svg)](https://semaphoreci.com/renuo/solidus_product_attachments)
7
+
8
+
9
+ Installation
10
+ ------------
11
+
12
+ Add solidus_product_attachments to your Gemfile:
13
+
14
+ ```ruby
15
+ gem 'solidus_product_attachments'
16
+ ```
17
+
18
+ Bundle your dependencies and run the installation generator:
19
+
20
+ ```shell
21
+ bundle
22
+ bundle exec rails g solidus_product_attachments:install
23
+ ```
24
+
25
+ Testing
26
+ -------
27
+
28
+ First bundle your dependencies, then run `rake`. `rake` will default to building the dummy app if it does not exist, then it will run specs, and [Rubocop](https://github.com/bbatsov/rubocop) static code analysis. The dummy app can be regenerated by using `rake test_app`.
29
+
30
+ ```shell
31
+ bundle
32
+ bundle exec rake
33
+ ```
34
+
35
+ When testing your applications integration with this extension you may use it's factories.
36
+ Simply add this require statement to your spec_helper:
37
+
38
+ ```ruby
39
+ require 'solidus_product_attachments/factories'
40
+ ```
41
+
42
+ Copyright (c) 2019 [Renuo AG](https://www.renuo.ch/en), released under the New BSD License
@@ -0,0 +1,32 @@
1
+ require 'bundler'
2
+
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ begin
6
+ require 'spree/testing_support/extension_rake'
7
+ # require 'rubocop/rake_task'
8
+ require 'rspec/core/rake_task'
9
+
10
+ RSpec::Core::RakeTask.new(:spec)
11
+
12
+ # TODO enable
13
+ # RuboCop::RakeTask.new
14
+
15
+ # task default: %i(first_run rubocop spec)
16
+ task default: %i(first_run spec)
17
+ rescue LoadError
18
+ # no rspec available
19
+ end
20
+
21
+ task :first_run do
22
+ if Dir['spec/dummy'].empty?
23
+ Rake::Task[:test_app].invoke
24
+ Dir.chdir('../../')
25
+ end
26
+ end
27
+
28
+ desc 'Generates a dummy app for testing'
29
+ task :test_app do
30
+ ENV['LIB_NAME'] = 'solidus_product_attachments'
31
+ Rake::Task['extension:test_app'].invoke
32
+ end
@@ -0,0 +1,65 @@
1
+ Spree.Models.AttachmentUpload = Backbone.Model.extend(
2
+ initialize: ->
3
+ file = @get('file')
4
+ @set
5
+ filename: file.name
6
+ size: if file.size then (file.size / 1024 | 0) + 'K' else ''
7
+ return
8
+
9
+ defaults: ->
10
+ {
11
+ file: null
12
+ attachmentSrc: ''
13
+ progress: 0
14
+ serverError: false
15
+ filename: ''
16
+ size: ''
17
+ }
18
+
19
+ acceptedTypes: 'application/pdf': true
20
+
21
+ previewFile: ->
22
+ file = @get('file')
23
+ that = this
24
+ if FileReader and @acceptedTypes[file.type] == true
25
+ reader = new FileReader
26
+
27
+ reader.onload = (event) ->
28
+ that.set attachmentSrc: event.target.result
29
+ return
30
+
31
+ reader.readAsDataURL file
32
+ return
33
+
34
+ uploadFile: ->
35
+ formData = new FormData
36
+ that = this
37
+
38
+ formData.append 'attachment[attachment]', @get('file')
39
+ formData.append 'attachment[viewable_id]', @get('variant_id')
40
+ formData.append 'upload_id', @cid
41
+
42
+ Spree.ajax(
43
+ url: window.location.pathname
44
+ type: 'POST'
45
+ dataType: 'script'
46
+ data: formData
47
+ processData: false
48
+ contentType: false
49
+ xhr: ->
50
+ xhr = $.ajaxSettings.xhr()
51
+ if xhr.upload
52
+ xhr.upload.onprogress = (event) ->
53
+ if event.lengthComputable
54
+ complete = event.loaded / event.total * 100 | 0
55
+ that.set progress: complete
56
+ return
57
+ xhr
58
+ ).done(->
59
+ that.set progress: 100
60
+ return
61
+ ).error (jqXHR, textStatus, errorThrown) ->
62
+ that.set serverError: true
63
+ return
64
+ return
65
+ );
@@ -0,0 +1,10 @@
1
+ # namespaces.js
2
+ Spree.Views.Attachments = {}
3
+
4
+ # editable_table.js
5
+ Spree.Views.Tables.EditableTable.append_attachment = (html) ->
6
+ $row = $(html)
7
+ $('#attachments-table').removeClass('hidden').find('tbody').append $row
8
+ $row.find('.select2').select2()
9
+ $('.no-objects-found').hide()
10
+ @add $row
@@ -0,0 +1,7 @@
1
+ Spree.ready ->
2
+ $('#new_attachment_link').click (event) ->
3
+ event.preventDefault()
4
+ $(this).hide()
5
+ $('#new_attachment').show()
6
+ return
7
+ return
@@ -0,0 +1,26 @@
1
+ Spree.prepareAttachmentUploader = ->
2
+ uploadZone = document.getElementById('attachment-upload-zone')
3
+ if !uploadZone
4
+ return
5
+
6
+ attachmentUploads = new (Backbone.Collection)
7
+ progressZone = document.getElementById('progress-zone')
8
+ variantId = document.querySelector('input[name="attachment[viewable_id]"]').value
9
+
10
+ new (Spree.Views.Attachments.UploadZone)(
11
+ el: uploadZone
12
+ collection: attachmentUploads
13
+ )
14
+
15
+ attachmentUploads.on 'add', (progressModel) ->
16
+ progressModel.set variant_id: variantId
17
+
18
+ progressView = new (Spree.Views.Images.UploadProgress)(model: progressModel)
19
+ progressZone.appendChild progressView.render().el
20
+ return
21
+
22
+ return
23
+
24
+ Spree.ready ->
25
+ Spree.prepareAttachmentUploader()
26
+ return
@@ -0,0 +1,38 @@
1
+ Spree.Views.Attachments.UploadZone = Backbone.View.extend(
2
+ events:
3
+ 'dragover': 'onDragOver'
4
+ 'dragleave': 'onDragLeave'
5
+ 'drop': 'onDrop'
6
+ 'change input[type="file"]': 'onFileBrowserSelect'
7
+
8
+ upload: (file) ->
9
+ progressModel = new (Spree.Models.AttachmentUpload)(file: file)
10
+
11
+ @collection.add progressModel
12
+
13
+ progressModel.previewFile()
14
+ progressModel.uploadFile()
15
+ return
16
+
17
+ dragClass: 'with-attachments'
18
+
19
+ onDragOver: (e) ->
20
+ @el.classList.add @dragClass
21
+ e.preventDefault()
22
+ return
23
+
24
+ onDragLeave: ->
25
+ @el.classList.remove @dragClass
26
+ return
27
+
28
+ onDrop: (e) ->
29
+ @el.classList.remove @dragClass
30
+ e.preventDefault()
31
+
32
+ _.each e.originalEvent.dataTransfer.files, @upload, this
33
+ return
34
+
35
+ onFileBrowserSelect: (e) ->
36
+ _.each e.target.files, @upload, this
37
+ return
38
+ )
@@ -0,0 +1,2 @@
1
+ // Placeholder manifest file.
2
+ // the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/backend/all.js'
@@ -0,0 +1,12 @@
1
+ <div class="card progress-card">
2
+ <div class="card-block">
3
+ <div class="progress">
4
+ <div class="progress-bar progress-bar-animated" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
5
+ </div>
6
+
7
+ <div class="filename">{{ filename }}</div>
8
+ <div class="size">{{ size }}B</div>
9
+
10
+ <error class="text-danger {{#unless serverError}} hidden {{/unless}}">{{t 'admin.attachments.index.attachment_process_failed' }}</error>
11
+ </div>
12
+ </div>
@@ -0,0 +1,2 @@
1
+ // Placeholder manifest file.
2
+ // the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/frontend/all.js'
@@ -0,0 +1,17 @@
1
+ @import 'spree/backend/spree_admin';
2
+
3
+ .upload-zone {
4
+ border: 2px dashed $color-border;
5
+ padding: 2rem 5rem;
6
+ text-align: center;
7
+ margin: 1rem auto;
8
+ width: 70%;
9
+
10
+ .upload {
11
+ display: block;
12
+ }
13
+
14
+ &.with-attachments {
15
+ border-color: theme-color('success');
16
+ }
17
+ }
@@ -0,0 +1,4 @@
1
+ /*
2
+ *= require_self
3
+ *= require_tree .
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Placeholder manifest file.
3
+ the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/frontend/all.css'
4
+ */
@@ -0,0 +1,31 @@
1
+ module Spree
2
+ module Admin
3
+ class AttachmentsController < ResourceController
4
+ protect_from_forgery
5
+
6
+ before_action :load_data
7
+
8
+ create.before :set_viewable
9
+ update.before :set_viewable
10
+
11
+ private
12
+
13
+ def load_data
14
+ @product = Spree::Product.friendly.find(params[:product_id])
15
+ end
16
+
17
+ def location_after_destroy
18
+ admin_product_attachments_url(@product)
19
+ end
20
+
21
+ def location_after_save
22
+ admin_product_attachments_url(@product)
23
+ end
24
+
25
+ def set_viewable
26
+ @attachment.viewable_type = 'Spree::Variant'
27
+ @attachment.viewable_id = params[:attachment][:viewable_id]
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ module Spree
2
+ module Api
3
+ class AttachmentsController < Spree::Api::BaseController
4
+ protect_from_forgery
5
+
6
+ def update
7
+ @attachment = Spree::Attachment.accessible_by(current_ability, :update).find(params[:id])
8
+ @attachment.update(attachment_params)
9
+ respond_with(@attachment, default_template: :show)
10
+ end
11
+
12
+ private
13
+
14
+ def attachment_params
15
+ params.require(:attachment).permit(Spree::Attachment::PERMITTED_ATTACHMENT_ATTRIBUTES)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ module Spree
2
+ module Admin
3
+ module AttachmentsHelper
4
+ def variants_sku_and_options_for(product)
5
+ product.variants.map do |variant|
6
+ [variant.sku_and_options_text, variant.id]
7
+ end.insert(0, [I18n.t('spree.all'), product.master.id])
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ module Spree
2
+ class Attachment < Spree::Asset
3
+ ATTACHMENT_ATTRIBUTES = %i[alt attachment_content_type attachment_file_name
4
+ attachment_updated_at id position type].freeze
5
+ PERMITTED_ATTACHMENT_ATTRIBUTES = %i[alt attachment position viewable_id viewable_type].freeze
6
+
7
+ has_attached_file :attachment
8
+
9
+ validate :no_attachment_errors
10
+ validates_attachment :attachment, content_type: { content_type: 'application/pdf' }
11
+
12
+ def no_attachment_errors
13
+ errors.add :attachment, "Paperclip returned errors for file #{attachment_file_name}" if attachment.errors.any?
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module Spree
2
+ module ProductDecorator
3
+ def self.included(base)
4
+ base.class_eval do
5
+ delegate :attachments, to: :find_or_build_master
6
+ has_many :variant_attachments, -> { order(:position) }, source: :attachments,
7
+ through: :variants_including_master
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+ Spree::Product.include Spree::ProductDecorator
@@ -0,0 +1,11 @@
1
+ module Spree
2
+ module VariantDecorator
3
+ def self.included(base)
4
+ base.class_eval do
5
+ has_many :attachments, as: :viewable, dependent: :destroy, inverse_of: :viewable
6
+ end
7
+ end
8
+ end
9
+ end
10
+
11
+ Spree::Variant.include Spree::VariantDecorator
@@ -0,0 +1,5 @@
1
+ Deface::Override.new(virtual_path: 'spree/admin/shared/_product_tabs',
2
+ name: 'product_documents_tab',
3
+ insert_bottom: '[data-hook=\'admin_product_tabs\']',
4
+ partial: 'spree/shared/product_documents_tab',
5
+ original: 'bd07670f06a2976ef953f76c465c21b014b17bea')
@@ -0,0 +1,38 @@
1
+ <tr id="<%= spree_dom_id attachment %>" data-hook="attachments_row'">
2
+ <td>
3
+ <% if can?(:update_positions, Spree::Attachment) %>
4
+ <span class="handle"></span>
5
+ <% end %>
6
+ </td>
7
+
8
+ <td><%= attachment.attachment_file_name %></td>
9
+
10
+ <% if @product.has_variants? %>
11
+ <td>
12
+ <%= fields_for attachment do |f| %>
13
+ <%= f.select :viewable_id, options_for_select(variants_sku_and_options_for(@product), attachment.viewable_id),
14
+ {}, class: 'select2 fullwidth', autocomplete: 'off' %>
15
+ <% end %>
16
+ </td>
17
+ <% end %>
18
+
19
+ <td>
20
+ <%= fields_for attachment do |f| %>
21
+ <%= f.text_field :alt %>
22
+ <% end %>
23
+ </td>
24
+
25
+ <td class="actions">
26
+ <% if can?(:update, attachment) %>
27
+ <%= link_to_with_icon 'check', t('spree.actions.save'), api_variant_attachment_path(@product, attachment),
28
+ no_text: true, data: { action: :save } %>
29
+ <%= link_to_with_icon 'cancel', t('spree.actions.cancel'), nil, no_text: true, data: { action: :cancel } %>
30
+ <%= link_to_with_icon 'edit', t('spree.actions.edit'), edit_admin_product_attachment_path(@product, attachment),
31
+ no_text: true, data: { action: :edit } %>
32
+ <% end %>
33
+
34
+ <% if can?(:destroy, attachment) %>
35
+ <%= link_to_delete attachment, url: admin_product_attachment_path(@product, attachment), no_text: true %>
36
+ <% end %>
37
+ </td>
38
+ </tr>
@@ -0,0 +1,22 @@
1
+ <div data-hook="admin_attachment_form_fields">
2
+ <div class="row">
3
+ <div class="col-3">
4
+ <div class="field" data-hook="file">
5
+ <%= f.label :attachment, t('spree.admin.attachments.new.file') %>
6
+ <%= f.file_field :attachment %>
7
+ </div>
8
+
9
+ <div class="field" data-hook="variant">
10
+ <%= f.label :viewable_id, Spree::Variant.model_name.human %>
11
+ <%= f.select :viewable_id, variants_sku_and_options_for(@product), {}, class: 'custom-select fullwidth' %>
12
+ </div>
13
+ </div>
14
+
15
+ <div class="field col-4" data-hook="alt">
16
+ <%= f.label :alt, t('spree.admin.attachments.index.label') %>
17
+ <%= f.text_field :alt, rows: 4, class: 'fullwidth' %>
18
+ </div>
19
+ </div>
20
+ </div>
21
+
22
+ <div class="clear"></div>
@@ -0,0 +1,12 @@
1
+ <%= form_for [:admin, product, attachment], html: { multipart: true } do |f| %>
2
+ <fieldset data-hook="new_attachment">
3
+ <legend align="center'"><%= t('spree.admin.attachments.index.new_attachment') %></legend>
4
+
5
+ <%= render partial: 'form', locals: { f: f } %>
6
+
7
+ <div class="form-buttons filter-actions actions" data-hook="buttons">
8
+ <%= button_tag t('spree.actions.update') %>
9
+ <%= link_to t('spree.actions.cancel'), admin_product_attachments_url(@product), id: 'cancel_link', class: 'button' %>
10
+ </div>
11
+ </fieldset>
12
+ <% end %>
@@ -0,0 +1,8 @@
1
+ var uploadEl = $('[data-upload-id="<%= params[:upload_id] %>"]');
2
+
3
+ <% if @attachment.persisted? %>
4
+ uploadEl.trigger('clear');
5
+ Spree.Views.Tables.EditableTable.append_attachment('<%= j render "attachment_row", attachment: @attachment %>');
6
+ <% else %>
7
+ uploadEl.find('error').removeClass('hidden').html('<%= j @attachment.errors.full_messages.join("<br>").html_safe %>');
8
+ <% end %>
@@ -0,0 +1,27 @@
1
+ <%= render partial: 'spree/admin/shared/product_tabs', locals: { current: 'Documents' } %>
2
+ <%= render partial: 'spree/shared/error_messages', locals: { target: @attachment } %>
3
+
4
+ <% admin_breadcrumb(link_to(plural_resource_name(Spree::Attachment), admin_product_attachments_path(@product))) %>
5
+ <% admin_breadcrumb(@attachment.attachment_file_name) %>
6
+
7
+ <% content_for :page_actions do %>
8
+ <li><%= button_to t('spree.admin.attachments.edit.back_to_attachments_list'),
9
+ admin_product_attachments_url(@product) %></li>
10
+ <% end %>
11
+
12
+ <%= form_for [:admin, @product, @attachment], html: { multipart: true } do |f| %>
13
+ <fieldset data-hook="edit_attachment">
14
+ <legend align="center"><%= @attachment.attachment_file_name %></legend>
15
+
16
+ <div class="row">
17
+ <div class="col">
18
+ <%= render partial: 'form', locals: { f: f } %>
19
+ </div>
20
+ </div>
21
+
22
+ <div class="form-buttons filter-actions actions" data-hook="buttons">
23
+ <%= button_tag t('spree.actions.update') %>
24
+ <%= link_to t('spree.actions.cancel'), admin_product_attachments_url(@product), id: 'cancel-link', class: 'button' %>
25
+ </div>
26
+ </fieldset>
27
+ <% end %>
@@ -0,0 +1,71 @@
1
+ <%= render partial: 'spree/admin/shared/product_tabs', locals: { current: 'Documents' } %>
2
+
3
+ <% admin_breadcrumb(t('spree.admin.attachments.title')) %>
4
+ <% content_for :page_actions do %>
5
+ <% if can?(:create, Spree::Attachment) %>
6
+ <li><%= link_to_with_icon('plus', t('spree.admin.attachments.index.new_attachment'),
7
+ new_admin_product_attachment_url(@product), id: 'new_attachment_link', class: 'button') %></li>
8
+ <% end %>
9
+ <% end %>
10
+
11
+ <div id="new_attachment" class="hidden">
12
+ <%= render 'new', product: @product, attachment: Spree::Attachment.new(viewable: @product) %>
13
+ </div>
14
+
15
+ <fieldset class="no-border-bottom">
16
+ <legend align="center"><%= t('spree.admin.attachments.index.upload_attachment') %></legend>
17
+
18
+ <div id="attachment-upload-zone" class="upload-zone">
19
+ <%= form_for [:admin, @product, Spree::Attachment.new], html: { multipart: true, id: 'upload-form' } do |f| %>
20
+ <label class="upload">
21
+ <i class="fa fa-5x fa-cloud-upload"></i>
22
+ <p>
23
+ <span class="button"><%= t('spree.admin.images.index.choose_files') %></span>
24
+ </p>
25
+ <p><%= t('spree.admin.images.index.drag_and_drop') %></p>
26
+
27
+ <%= f.file_field :attachment, multiple: '', class: 'hidden' %>
28
+ <%= f.hidden_field :viewable_id, value: @product.master.id %>
29
+ </label>
30
+ <% end %>
31
+ </div>
32
+
33
+ <div id="progress-zone" class="row"></div>
34
+ </fieldset>
35
+
36
+ <% no_attachments = @product.attachments.empty? && @product.variant_attachments.empty? %>
37
+
38
+ <table id="attachments-table" class="index sortable inline-editable-table" <%= 'hidden' if no_attachments %>
39
+ data-hook='attachments_table' data-sortable-link="<%= update_positions_admin_product_attachments_url(@product) %>">
40
+ <colgroup>
41
+ <col style="width: 5%">
42
+ <col style="width: 10%">
43
+ <% if @product.has_variants? %>
44
+ <col style="width: 40%">
45
+ <% end %>
46
+ <col style="width: 30%">
47
+ <col style="width: 15%">
48
+ </colgroup>
49
+
50
+ <thead>
51
+ <tr data-hook="attachments-header">
52
+ <th></th>
53
+ <th><%= t('spree.admin.attachments.index.file_name') %></th>
54
+ <% if @product.has_variants? %>
55
+ <th><%= Spree::Variant.model_name.human %></th>
56
+ <% end %>
57
+ <th><%= t('spree.admin.attachments.index.label') %></th>
58
+ <th class="actions"></th>
59
+ </tr>
60
+ </thead>
61
+
62
+ <tbody>
63
+ <%= render partial: 'attachment_row', collection: @product.variant_attachments, as: :attachment %>
64
+ </tbody>
65
+ </table>
66
+
67
+ <% if no_attachments %>
68
+ <div class="no-objects-found">
69
+ <%= t('spree.admin.attachments.index.no_attachments_found') %>
70
+ </div>
71
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= render 'new', product: @product, attachment: @attachment %>
@@ -0,0 +1,5 @@
1
+ json.call(attachment, *Spree::Attachment::ATTACHMENT_ATTRIBUTES)
2
+ json.call(attachment, :viewable_type, :viewable_id)
3
+ Spree::Attachment.attachment_definitions[:attachment].each do |k, _v|
4
+ json.set! "#{k}_url", attachment.attachment.url(k)
5
+ end
@@ -0,0 +1 @@
1
+ json.partial!('spree/api/attachments/attachment', attachment: @attachment)
@@ -0,0 +1,5 @@
1
+ <% if can?(:admin, Spree::Attachment) && !@product.deleted? %>
2
+ <%= content_tag :li, class: ('active' if current == 'Documents') do %>
3
+ <%= link_to t('spree.admin.attachments.title'), admin_product_attachments_url(@product) %>
4
+ <% end %>
5
+ <% end %>
@@ -0,0 +1,16 @@
1
+ de:
2
+ spree:
3
+ admin:
4
+ attachments:
5
+ edit:
6
+ back_to_attachments_list: 'Zurück zu den Dokumenten'
7
+ index:
8
+ attachment_process_failed: 'Dokumentverarbeitung fehlgeschlagen'
9
+ file_name: 'Dateiname'
10
+ label: 'Beschriftung'
11
+ new_attachment: 'Neues Dokument'
12
+ no_attachments_found: 'Keine Dokumente verfügbar'
13
+ upload_attachment: 'Dokumente hochladen'
14
+ new:
15
+ file: 'Datei'
16
+ title: 'Dokumente'
@@ -0,0 +1,16 @@
1
+ en:
2
+ spree:
3
+ admin:
4
+ attachments:
5
+ edit:
6
+ back_to_attachments_list: 'Back to the documents'
7
+ index:
8
+ attachment_process_failed: 'Attachment processing failed'
9
+ file_name: 'File name'
10
+ label: 'Label'
11
+ new_attachment: 'New document'
12
+ no_attachments_found: 'No documents found'
13
+ upload_attachment: 'Upload documents'
14
+ new:
15
+ file: 'File'
16
+ title: 'Documents'
@@ -0,0 +1,17 @@
1
+ Spree::Core::Engine.routes.draw do
2
+ namespace :admin do
3
+ resources :products do
4
+ resources :attachments, except: :show do
5
+ collection do
6
+ post :update_positions
7
+ end
8
+ end
9
+ end
10
+ end
11
+
12
+ namespace :api, defaults: { format: :json } do
13
+ resources :variants do
14
+ resources :attachments, only: :update
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ module SolidusProductAttachments
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ class_option :auto_run_migrations, type: :boolean, default: false
5
+
6
+ def add_javascripts
7
+ append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_product_attachments\n"
8
+ append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_product_attachments\n"
9
+ end
10
+
11
+ def add_stylesheets
12
+ inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_product_attachments\n", before: /\*\//, verbose: true
13
+ inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_product_attachments\n", before: /\*\//, verbose: true
14
+ end
15
+
16
+ def add_migrations
17
+ run 'bundle exec rake railties:install:migrations FROM=solidus_product_attachments'
18
+ end
19
+
20
+ def run_migrations
21
+ run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
22
+ if run_migrations
23
+ run 'bundle exec rake db:migrate'
24
+ else
25
+ puts 'Skipping rake db:migrate, don\'t forget to run it!'
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,6 @@
1
+ require 'solidus_backend'
2
+ require 'solidus_core'
3
+ require 'solidus_support'
4
+ require 'solidus_product_attachments/engine'
5
+ require 'solidus_product_attachments/version'
6
+ require 'deface'
@@ -0,0 +1,20 @@
1
+ module SolidusProductAttachments
2
+ class Engine < Rails::Engine
3
+ require 'spree/core'
4
+ isolate_namespace Spree
5
+ engine_name 'solidus_product_attachments'
6
+
7
+ # use rspec for tests
8
+ config.generators do |g|
9
+ g.test_framework :rspec
10
+ end
11
+
12
+ def self.activate
13
+ Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
14
+ Rails.configuration.cache_classes ? require(c) : load(c)
15
+ end
16
+ end
17
+
18
+ config.to_prepare(&method(:activate).to_proc)
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module SolidusProductAttachments
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,277 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: solidus_product_attachments
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Renuo AG
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-02-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: deface
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: solidus_backend
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: solidus_support
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: capybara
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coffee-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: factory_bot
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: puma
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-rails
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: '0.65'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: '0.65'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '='
144
+ - !ruby/object:Gem::Version
145
+ version: 1.32.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '='
151
+ - !ruby/object:Gem::Version
152
+ version: 1.32.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: sass-rails
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: selenium-webdriver
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: simplecov
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: sqlite3
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - '='
200
+ - !ruby/object:Gem::Version
201
+ version: 1.3.9
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - '='
207
+ - !ruby/object:Gem::Version
208
+ version: 1.3.9
209
+ description: A gem to attach files to a product / variant
210
+ email: info@renuo.ch
211
+ executables: []
212
+ extensions: []
213
+ extra_rdoc_files: []
214
+ files:
215
+ - LICENSE
216
+ - README.md
217
+ - Rakefile
218
+ - app/assets/javascripts/spree/backend/attachments/attachment_upload.js.coffee
219
+ - app/assets/javascripts/spree/backend/attachments/extensions.js.coffee
220
+ - app/assets/javascripts/spree/backend/attachments/index.js.coffee
221
+ - app/assets/javascripts/spree/backend/attachments/upload.js.coffee
222
+ - app/assets/javascripts/spree/backend/attachments/upload_zone.js.coffee
223
+ - app/assets/javascripts/spree/backend/solidus_product_attachments.js
224
+ - app/assets/javascripts/spree/backend/templates/products/upload_progress.hbs
225
+ - app/assets/javascripts/spree/frontend/solidus_product_attachments.js
226
+ - app/assets/stylesheets/spree/backend/attachments/attachments.scss
227
+ - app/assets/stylesheets/spree/backend/solidus_product_attachments.css
228
+ - app/assets/stylesheets/spree/frontend/solidus_product_attachments.css
229
+ - app/controllers/spree/admin/attachments_controller.rb
230
+ - app/controllers/spree/api/attachments_controller.rb
231
+ - app/helpers/spree/admin/attachments_helper.rb
232
+ - app/models/spree/attachment.rb
233
+ - app/models/spree/product_decorator.rb
234
+ - app/models/spree/variant_decorator.rb
235
+ - app/overrides/product_tabs.rb
236
+ - app/views/spree/admin/attachments/_attachment_row.html.erb
237
+ - app/views/spree/admin/attachments/_form.html.erb
238
+ - app/views/spree/admin/attachments/_new.html.erb
239
+ - app/views/spree/admin/attachments/create.js.erb
240
+ - app/views/spree/admin/attachments/edit.html.erb
241
+ - app/views/spree/admin/attachments/index.html.erb
242
+ - app/views/spree/admin/attachments/new.html.erb
243
+ - app/views/spree/api/attachments/_attachment.json.jbuilder
244
+ - app/views/spree/api/attachments/show.json.jbuilder
245
+ - app/views/spree/shared/_product_documents_tab.html.erb
246
+ - config/locales/de.yml
247
+ - config/locales/en.yml
248
+ - config/routes.rb
249
+ - lib/generators/solidus_product_attachments/install/install_generator.rb
250
+ - lib/solidus_product_attachments.rb
251
+ - lib/solidus_product_attachments/engine.rb
252
+ - lib/solidus_product_attachments/version.rb
253
+ homepage: https://www.renuo.ch
254
+ licenses:
255
+ - BSD-3-Clause
256
+ metadata: {}
257
+ post_install_message:
258
+ rdoc_options: []
259
+ require_paths:
260
+ - lib
261
+ required_ruby_version: !ruby/object:Gem::Requirement
262
+ requirements:
263
+ - - ">="
264
+ - !ruby/object:Gem::Version
265
+ version: '0'
266
+ required_rubygems_version: !ruby/object:Gem::Requirement
267
+ requirements:
268
+ - - ">="
269
+ - !ruby/object:Gem::Version
270
+ version: '0'
271
+ requirements: []
272
+ rubyforge_project:
273
+ rubygems_version: 2.6.13
274
+ signing_key:
275
+ specification_version: 4
276
+ summary: A gem to attach files to a product
277
+ test_files: []