This repository has been archived by the owner on Dec 23, 2019. It is now read-only.
forked from andrewjpage/freezer_tracking
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c28dc4a
commit 1a71a3b
Showing
36 changed files
with
443 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class RackReceptionsController < ApplicationController | ||
def index | ||
@reception = Reception::Rack::Base.new | ||
end | ||
|
||
def create | ||
@reception = Reception::Rack::Base.new(params[:reception]) | ||
|
||
respond_to do |format| | ||
if @reception.valid? | ||
@reception.save | ||
format.html { redirect_to( rack_receptions_path, :notice => 'Uploaded rack') } | ||
else | ||
format.html { redirect_to( rack_receptions_path, :notice => @reception.errors.full_messages.first) } | ||
end | ||
end | ||
end | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class RescanRacksController < ApplicationController | ||
def index | ||
@assets = Asset.where( :dirty_layout => true ).paginate(:page => params[:page]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,56 @@ | ||
class Asset < ActiveRecord::Base | ||
cattr_reader :per_page | ||
@@per_page = 384 | ||
|
||
belongs_to :storage_area | ||
belongs_to :map | ||
belongs_to :container, :class_name => "Asset" | ||
has_many :contained_assets, :class_name => "Asset", :foreign_key => :container_id | ||
has_many :asset_audits | ||
|
||
validates_presence_of :barcode | ||
validates_uniqueness_of :barcode | ||
|
||
attr_accessor :user_login | ||
|
||
acts_as_audited :except => [:created_at, :updated_at] | ||
|
||
before_save :decode_to_sanger_barcode, :if => :barcode_changed? | ||
before_save :container_layout_dirty, :if => :container_id_changed? | ||
after_save :audit_change | ||
|
||
scope :for_search_query, lambda { |search_terms| { :conditions => [ 'barcode IN (?) OR decoded_barcode_number in (?)', search_terms, search_terms ] } } | ||
|
||
|
||
def decode_to_sanger_barcode | ||
self.decoded_barcode_number, self.decoded_prefix = nil, nil | ||
return unless Barcode.valid_ean13_barcode?(barcode) | ||
prefix_number, self.decoded_barcode_number, _ = Barcode.split_barcode(barcode) | ||
self.decoded_prefix = Barcode.prefix_to_human(prefix_number) | ||
end | ||
|
||
|
||
def container_layout_dirty | ||
previous_container = Asset.find_by_id(container_id_was) | ||
return if previous_container.nil? | ||
previous_container.update_attributes!(:dirty_layout => true) | ||
end | ||
|
||
|
||
def audit_change | ||
action = 'Check in' | ||
action = 'Check out' if storage_area.nil? && container.nil? | ||
|
||
self.asset_audits.create!( | ||
:container_barcode => container.try(:barcode), | ||
:container_barcode => container.try(:barcode), | ||
:map_description => map.try(:description), | ||
:storage_area_name => storage_area.try(:name), | ||
:freezer_name => storage_area.try(:freezer).try(:name), | ||
:building_area_name => storage_area.try(:freezer).try(:building_area).try(:name), | ||
:user_login => user_login, | ||
:action => action | ||
) | ||
end | ||
|
||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,6 @@ | ||
# only checks into storage area not into container | ||
class Reception::Base | ||
include ActiveModel::Validations | ||
include Reception::Validations | ||
include Reception::Assets | ||
|
||
attr_reader :user_barcode, :storage_area_barcode, :asset_barcodes | ||
|
||
def initialize(attributes = {}) | ||
@user_barcode = attributes[:user_barcode] | ||
@storage_area_barcode = attributes[:storage_area_barcode] | ||
@asset_barcodes = attributes[:asset_barcodes] | ||
end | ||
|
||
def source_barcodes | ||
@source_barcodes ||= split_barcodes(self.asset_barcodes) | ||
end | ||
|
||
def split_barcodes(barcodes_string) | ||
return [] if barcodes_string.blank? | ||
barcodes_string.split(/\W/) | ||
end | ||
|
||
def user_login | ||
@user_name ||= UserBarcode::UserBarcode.find_username_from_barcode(self.user_barcode) | ||
end | ||
|
||
def storage_area | ||
@storage_area ||= StorageArea.find_by_barcode(storage_area_barcode) | ||
end | ||
|
||
def container | ||
@container ||= Asset.find_by_barcode(storage_area_barcode) | ||
end | ||
|
||
def check_in? | ||
return false if storage_area_barcode.blank? | ||
true | ||
end | ||
|
||
|
||
def save | ||
assets.each do |asset| | ||
asset.update_attributes!(:storage_area => storage_area, :container => container, :user_login => user_login) | ||
end | ||
end | ||
|
||
include Reception::User | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class Reception::Rack::Base < Reception::Base | ||
include Reception::Rack::Validations | ||
|
||
attr_reader :rack_layout_file, :rack_barcode | ||
|
||
def initialize(attributes = {}) | ||
super(attributes) | ||
@rack_layout_file = attributes[:rack_layout_file] | ||
@rack_barcode = attributes[:rack_barcode] | ||
end | ||
|
||
def container | ||
@container ||= Asset.find_or_create_by_barcode(:barcode => self.rack_barcode) | ||
end | ||
|
||
def rack_layout | ||
@rack_layout ||= Reception::Rack::Layout::Base.new(:file => rack_layout_file) | ||
end | ||
|
||
def save | ||
rack_layout.location_to_barcodes.each do |map, barcodes| | ||
Asset.find_or_create_by_barcode(:barcode => barcodes.first).update_attributes!(:storage_area => nil, :map => map, :container => container, :user_login => user_login) | ||
end | ||
|
||
container.update_attributes!(:dirty_layout => false) if container.dirty_layout | ||
|
||
true | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Reception::Rack::Layout::Base | ||
include ActiveModel::Validations | ||
include Reception::Rack::Layout::Parser | ||
include Reception::Rack::Layout::Validations | ||
|
||
attr_reader :uploaded_file | ||
|
||
def initialize(attributes = {}) | ||
@uploaded_file = attributes[:file] | ||
end | ||
|
||
def file | ||
@file ||= self.uploaded_file.read | ||
end | ||
|
||
def location_to_barcodes | ||
@location_to_barcodes ||= parse_spreadsheet(file) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Reception::Rack::Layout::Parser | ||
|
||
def parse_spreadsheet(spreadsheet_data) | ||
map_to_barcodes = {} | ||
CSV.parse(spreadsheet_data) do |row| | ||
map, barcode = parse_row(row) | ||
if map_to_barcodes[map] | ||
map_to_barcodes[map] << barcode | ||
else | ||
map_to_barcodes[map] = [barcode] | ||
end | ||
end | ||
map_to_barcodes | ||
end | ||
|
||
def parse_row(row) | ||
return nil if row.blank? | ||
map_description, barcode = row | ||
map = Map.find_or_create_by_description( :description => map_description ) | ||
|
||
[map, barcode.strip] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module Reception::Rack::Layout::Validations | ||
def self.included(base) | ||
base.class_eval do | ||
validates_presence_of :uploaded_file | ||
validate :file_format | ||
validate :one_barcode_per_location | ||
validate :no_duplicated_barcodes | ||
end | ||
end | ||
|
||
def file_format | ||
begin | ||
location_to_barcodes | ||
rescue | ||
invalid_format_error | ||
end | ||
end | ||
|
||
def one_barcode_per_location | ||
begin | ||
location_to_barcodes.each do |location, barcodes| | ||
if barcodes.size > 1 | ||
errors.add(:uploaded_file, "must have only one barcode per location") | ||
return | ||
end | ||
end | ||
rescue NoMethodError | ||
invalid_format_error | ||
end | ||
end | ||
|
||
def no_duplicated_barcodes | ||
begin | ||
barcodes = location_to_barcodes.values.flatten | ||
errors.add(:uploaded_file, "must not have duplicated barcodes") if barcodes.size != barcodes.uniq.size | ||
rescue NoMethodError | ||
invalid_format_error | ||
end | ||
end | ||
|
||
def invalid_format_error | ||
errors.add(:uploaded_file, "must be a valid format") | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Reception::Rack::Validations | ||
def self.included(base) | ||
base.class_eval do | ||
validates_presence_of :rack_barcode | ||
validates_presence_of :rack_layout_file | ||
validate :format_of_rack_layout_file | ||
end | ||
end | ||
|
||
def format_of_rack_layout_file | ||
unless rack_layout.valid? | ||
save_errors_to_base(rack_layout.errors) | ||
end | ||
end | ||
|
||
def save_errors_to_base(object_errors) | ||
object_errors.each do |key, message| | ||
self.errors.add(key, message) | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Reception::Standard::Asset | ||
def find_assets | ||
source_barcodes.map{ |barcode| Asset.find_or_create_by_barcode(:barcode => barcode) } | ||
end | ||
|
||
def assets | ||
@assets ||= find_assets | ||
end | ||
|
||
def save | ||
assets.each do |asset| | ||
asset.update_attributes!(:storage_area => storage_area, :container => container, :user_login => user_login) | ||
end | ||
|
||
true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class Reception::Standard::Base < Reception::Base | ||
include Reception::Standard::Validations | ||
include Reception::Standard::Asset | ||
|
||
attr_reader :storage_area_barcode, :asset_barcodes | ||
|
||
def initialize(attributes = {}) | ||
super(attributes) | ||
@storage_area_barcode = attributes[:storage_area_barcode] | ||
@asset_barcodes = attributes[:asset_barcodes] | ||
end | ||
|
||
def container | ||
@container ||= Asset.find_by_barcode(storage_area_barcode) | ||
end | ||
|
||
def check_in? | ||
return false if storage_area_barcode.blank? | ||
true | ||
end | ||
|
||
def storage_area | ||
@storage_area ||= StorageArea.find_by_barcode(storage_area_barcode) | ||
end | ||
|
||
def source_barcodes | ||
@source_barcodes ||= split_barcodes(self.asset_barcodes) | ||
end | ||
|
||
def split_barcodes(barcodes_string) | ||
return [] if barcodes_string.blank? | ||
barcodes_string.split(/\W/) | ||
end | ||
|
||
end | ||
|
Oops, something went wrong.