vesr 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ class EsrFilesController < AuthorizedController
2
+ end
@@ -1,5 +1,7 @@
1
1
  class EsrFile < ActiveRecord::Base
2
- has_attachment :storage => :file_system
2
+ # File upload
3
+ mount_uploader :file, EsrFileUploader
4
+
3
5
  has_many :esr_records, :dependent => :destroy
4
6
 
5
7
  def to_s(format = :default)
@@ -19,7 +21,7 @@ class EsrFile < ActiveRecord::Base
19
21
 
20
22
  private
21
23
  def create_records
22
- File.new(full_filename).each {|line|
24
+ File.new(file.current_path).each {|line|
23
25
  self.esr_records << EsrRecord.new.parse(line) unless line[0..2] == '999'
24
26
  }
25
27
  end
@@ -4,10 +4,10 @@ class EsrRecord < ActiveRecord::Base
4
4
  belongs_to :booking, :dependent => :destroy
5
5
  belongs_to :invoice
6
6
 
7
- named_scope :valid, :conditions => "state = 'valid'"
8
- named_scope :missing, :conditions => "state = 'missing'"
9
- named_scope :bad, :conditions => "state = 'bad'"
10
- named_scope :invalid, :conditions => "state != 'valid'"
7
+ scope :valid, where(:state => 'valid')
8
+ scope :missing, where(:state => 'missing')
9
+ scope :bad, where(:state => 'bad')
10
+ scope :invalid, where(:state => 'valid')
11
11
 
12
12
  private
13
13
  def parse_date(value)
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ class EsrFileUploader < CarrierWave::Uploader::Base
4
+ # Choose what kind of storage to use for this uploader:
5
+ storage :file
6
+
7
+ # Override the directory where uploaded files will be stored.
8
+ # This is a sensible default for uploaders that are meant to be mounted:
9
+ def store_dir
10
+ "system/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
11
+ end
12
+ end
@@ -1,8 +1,13 @@
1
1
  <div class="contextual">
2
- <%= link_to "VESR Liste", esr_bookings_path, :class => "icon icon-book" %>
2
+ <%= link_to "VESR Liste", esr_files_path, :class => "icon icon-book" %>
3
3
  </div>
4
4
  <h2>VESR Datei einlesen</h2>
5
- <% form_for :esr_file, :url => esr_bookings_path, :html => { :multipart => true } do |esr_file| %>
6
- Datei: <%= esr_file.file_field :uploaded_data %>
7
- <%= esr_file.submit 'Einlesen' %>
5
+ <% semantic_form_for :esr_file do |esr_file| %>
6
+ <%= esr_file.inputs do %>
7
+ <%= esr_file.input :file %>
8
+ <%= esr_file.input :file_cache, :as => :hidden %>
9
+ <%- end %>
10
+ <%= esr_file.buttons do %>
11
+ <%= esr_file.commit_button %>
12
+ <%- end %>
8
13
  <% end %>
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ resources :esr_files
3
+ end
@@ -0,0 +1,13 @@
1
+ class PortToCarrierwave < ActiveRecord::Migration
2
+ def up
3
+ rename_column :esr_files, :filename, :file
4
+ remove_column :esr_files, :content_type
5
+ remove_column :esr_files, :size
6
+ end
7
+
8
+ def down
9
+ add_column :esr_files, :size, :integer
10
+ add_column :esr_files, :content_type, :string
11
+ rename_column :esr_files, :file, :filename
12
+ end
13
+ end
@@ -1,4 +1,3 @@
1
- require 'prawn/measurement_extensions'
2
1
  require 'action_view/helpers/translation_helper'
3
2
  require 'action_view/helpers'
4
3
 
@@ -1,3 +1,3 @@
1
1
  module Vesr
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vesr
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 4
10
- version: 0.1.4
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Roman Simecek
@@ -32,9 +32,10 @@ extra_rdoc_files:
32
32
  - README.rdoc
33
33
  - LICENSE.txt
34
34
  files:
35
- - app/controllers/esr_bookings_controller.rb
35
+ - app/controllers/esr_files_controller.rb
36
36
  - app/models/esr_file.rb
37
37
  - app/models/esr_record.rb
38
+ - app/uploaders/esr_file_uploader.rb
38
39
  - app/views/esr_bookings/_form.html.erb
39
40
  - app/views/esr_bookings/_item.html.erb
40
41
  - app/views/esr_bookings/_list_footer.html.erb
@@ -44,7 +45,9 @@ files:
44
45
  - app/views/esr_bookings/_sidebar.html.erb
45
46
  - app/views/esr_bookings/list.html.erb
46
47
  - app/views/esr_bookings/show.html.erb
48
+ - config/routes.rb
47
49
  - db/migrate/1_create_vesr_tables.rb
50
+ - db/migrate/2_port_to_carrierwave.rb
48
51
  - lib/vesr.rb
49
52
  - lib/vesr/prawn.rb
50
53
  - lib/vesr/prawn/esr_recipe.rb
@@ -1,62 +0,0 @@
1
- require 'action_controller/test_process.rb'
2
-
3
- class EsrBookingsController < ApplicationController
4
- # GET /esr_bookings
5
- def index
6
- @esr_files = EsrFile.paginate(:page => params['page'], :per_page => 20, :order => 'updated_at DESC')
7
-
8
- respond_to do |format|
9
- format.html {
10
- render :action => 'list'
11
- }
12
- end
13
- end
14
-
15
- # GET /esr_bookings/new
16
- def new
17
- @esr_file = EsrFile.new
18
-
19
- respond_to do |format|
20
- format.html {
21
- render :partial => 'form', :layout => 'application'
22
- }
23
- format.js { }
24
- end
25
- end
26
-
27
- # POST /esr_bookings
28
- def create
29
- # if :filename param is set, file exists
30
- if params[:filename]
31
- vesr_path = params[:filename]
32
-
33
- @esr_file = EsrFile.new(:uploaded_data => ActionController::TestUploadedFile.new(vesr_path))
34
- else
35
- @esr_file = EsrFile.new(params[:esr_file])
36
- end
37
-
38
- if @esr_file.save
39
- # Delete file if saved as attachment
40
- File.delete(vesr_path) if vesr_path
41
- end
42
-
43
- respond_to do |format|
44
- format.html {
45
- redirect_to :action => 'show', :id => @esr_file
46
- }
47
- format.js { }
48
- end
49
- end
50
-
51
- # GET /esr_bookings/1
52
- def show
53
- @esr_file = EsrFile.find(params[:id])
54
-
55
- respond_to do |format|
56
- format.html {
57
- render :action => 'show'
58
- }
59
- format.js { }
60
- end
61
- end
62
- end