wip plugin
This commit is contained in:
parent
78da4feafe
commit
f9229034de
13 changed files with 100 additions and 0 deletions
1
Gemfile
1
Gemfile
|
@ -64,6 +64,7 @@ gem 'rswag-ui'
|
|||
gem 'acts_as_versioned', git: 'https://github.com/technoweenie/acts_as_versioned.git'
|
||||
gem 'foodsoft_wiki', path: 'plugins/wiki'
|
||||
gem 'foodsoft_messages', path: 'plugins/messages'
|
||||
gem 'foodsoft_bnn_upload', path: 'plugins/bnn_upload'
|
||||
gem 'foodsoft_documents', path: 'plugins/documents'
|
||||
gem 'foodsoft_discourse', path: 'plugins/discourse'
|
||||
gem 'foodsoft_links', path: 'plugins/links'
|
||||
|
|
|
@ -16,6 +16,13 @@ GIT
|
|||
acts_as_versioned (0.6.0)
|
||||
activerecord (>= 3.0.9)
|
||||
|
||||
PATH
|
||||
remote: plugins/bnn_upload
|
||||
specs:
|
||||
foodsoft_bnn_upload (0.0.1)
|
||||
deface (~> 1.0)
|
||||
rails
|
||||
|
||||
PATH
|
||||
remote: plugins/discourse
|
||||
specs:
|
||||
|
@ -618,6 +625,7 @@ DEPENDENCIES
|
|||
exception_notification
|
||||
factory_bot_rails
|
||||
faker
|
||||
foodsoft_bnn_upload!
|
||||
foodsoft_discourse!
|
||||
foodsoft_documents!
|
||||
foodsoft_links!
|
||||
|
|
14
plugins/bnn_upload/app/controllers/orders_controller.rb
Normal file
14
plugins/bnn_upload/app/controllers/orders_controller.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
class OrdersController < ApplicationController
|
||||
# Send a order to the supplier.
|
||||
def send_result_to_supplier
|
||||
order = Order.find(params[:id])
|
||||
options = { file_formats: params[:file_formats] }
|
||||
order.send_to_supplier!(@current_user, options)
|
||||
redirect_to order, notice: I18n.t('orders.send_to_supplier.notice')
|
||||
rescue => error
|
||||
redirect_to order, alert: I18n.t('errors.general_msg', :msg => error.message)
|
||||
end
|
||||
def send_result_to_supplier_modal
|
||||
@order = Order.find(params[:id])
|
||||
end
|
||||
end
|
8
plugins/bnn_upload/app/mailers/mailer.rb
Normal file
8
plugins/bnn_upload/app/mailers/mailer.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
class Mailer
|
||||
# attaches files to mail sent to supplier
|
||||
def add_order_result_attachments(order, options = {})
|
||||
attachments['order.pdf'] = OrderFax.new(order, options).to_pdf if options[:file_formats][:pdf].present?
|
||||
attachments['order.csv'] = OrderCsv.new(order, options).to_csv if options[:file_formats][:csv].present?
|
||||
attachments['order.bnn'] = OrderBnn.new(order, options).to_bnn if options[:file_formats][:bnn].present?
|
||||
end
|
||||
end
|
8
plugins/bnn_upload/app/models/order.rb
Normal file
8
plugins/bnn_upload/app/models/order.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
class Order
|
||||
def send_to_supplier!(user, options = {})
|
||||
Mailer.deliver_now_with_default_locale do
|
||||
Mailer.order_result_supplier(user, self, options)
|
||||
end
|
||||
update!(last_sent_mail: Time.now)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
/ replace 'erb:contains("send_result_to_supplier")'
|
||||
- if FoodsoftBnnUpload.enabled?
|
||||
- raise
|
||||
= link_to t('.send_to_supplier'), send_result_to_supplier_modal_order_path(@order), remote: true,
|
||||
class: "btn#{' btn-primary' unless @order.last_sent_mail}",
|
||||
data: {confirm: @order.last_sent_mail && t('.confirm_send_to_supplier', when: format_time(@order.last_sent_mail)) }
|
|
@ -0,0 +1,12 @@
|
|||
= form_with url: send_result_to_supplier_path(@order) do |f|
|
||||
.modal-header
|
||||
= close_button :modal
|
||||
.h3="Choose file formats that will be attached to your Email"
|
||||
.modal-body
|
||||
= f.check_box 'file_formats[pdf]'
|
||||
= f.label 'file_formats[pdf]', "PDF"
|
||||
.modal-footer
|
||||
= link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'}
|
||||
= f.submit class: 'btn btn-primary'
|
||||
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
$('#modalContainer').html('#{j(render("send_to_supplier_modal"))}');
|
||||
$('#modalContainer').modal();
|
||||
$('#modalContainer').submit(function() {$('#modalContainer').modal('hide');});
|
5
plugins/bnn_upload/config/routes.rb
Normal file
5
plugins/bnn_upload/config/routes.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
Rails.application.routes.draw do
|
||||
scope '/:foodcoop' do
|
||||
get '/order/send_result_to_supplier_modal' => 'orders#send_result_to_supplier_modal'
|
||||
end
|
||||
end
|
18
plugins/bnn_upload/foodsoft_bnn_upload.gemspec
Normal file
18
plugins/bnn_upload/foodsoft_bnn_upload.gemspec
Normal file
|
@ -0,0 +1,18 @@
|
|||
$:.push File.expand_path("../lib", __FILE__)
|
||||
|
||||
# Maintain your gem's version:
|
||||
require "foodsoft_bnn_upload/version"
|
||||
|
||||
# Describe your gem and declare its dependencies:
|
||||
Gem::Specification.new do |s|
|
||||
s.name = "foodsoft_bnn_upload"
|
||||
s.version = FoodsoftBnnUpload::VERSION
|
||||
s.authors = ["fgu, viehlieb"]
|
||||
s.email = ["foodsoft@local-it.org"]
|
||||
s.summary = "Manually choose file to send to supplier. BNN file for NaturkostNord supported."
|
||||
|
||||
s.files = Dir["{app,config,db,lib}/**/*"] + ["Rakefile", "README.md"]
|
||||
|
||||
s.add_dependency "rails"
|
||||
s.add_dependency "deface", "~> 1.0"
|
||||
end
|
7
plugins/bnn_upload/lib/foodsoft_bnn_upload.rb
Normal file
7
plugins/bnn_upload/lib/foodsoft_bnn_upload.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require 'foodsoft_bnn_upload/engine'
|
||||
|
||||
module FoodsoftBnnUpload
|
||||
def self.enabled?
|
||||
FoodsoftConfig[:use_bnn_upload]
|
||||
end
|
||||
end
|
7
plugins/bnn_upload/lib/foodsoft_bnn_upload/engine.rb
Normal file
7
plugins/bnn_upload/lib/foodsoft_bnn_upload/engine.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
module FoodsoftBnnUpload
|
||||
class Engine < ::Rails::Engine
|
||||
def default_foodsoft_config(cfg)
|
||||
cfg[:use_bnn_upload] = true
|
||||
end
|
||||
end
|
||||
end
|
3
plugins/bnn_upload/lib/foodsoft_bnn_upload/version.rb
Normal file
3
plugins/bnn_upload/lib/foodsoft_bnn_upload/version.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
module FoodsoftBnnUpload
|
||||
VERSION = "0.0.1"
|
||||
end
|
Loading…
Reference in a new issue