Skip to content

Commit

Permalink
Merge branch '1.1'
Browse files Browse the repository at this point in the history
Conflicts:
	.travis.yml
	app/controllers/inter_library_loans_controller.rb
	app/models/inter_library_loan.rb
	app/models/inter_library_loan_state_machine.rb
	app/models/inter_library_loan_transition.rb
	db/migrate/20140607100507_create_inter_library_loan_transitions.rb
	enju_inter_library_loan.gemspec
	lib/enju_inter_library_loan/engine.rb
	lib/enju_inter_library_loan/version.rb
	spec/dummy/app/models/user.rb
	spec/dummy/db/migrate/002_devise_create_users.rb
	spec/dummy/db/migrate/006_create_items.rb
	spec/dummy/db/migrate/035_create_reserves.rb
	spec/dummy/db/migrate/20081028083208_create_resource_import_files.rb
	spec/dummy/db/migrate/20110627035057_create_series_statement_merges.rb
	spec/dummy/db/migrate/20130221154434_add_additional_attributes_to_user.rb
	spec/dummy/db/schema.rb
	spec/factories/user.rb
	spec/fixtures/users.yml
  • Loading branch information
nabeta committed Jan 9, 2015
2 parents 849e9e4 + e56c3b5 commit 1971939
Show file tree
Hide file tree
Showing 153 changed files with 1,298 additions and 1,214 deletions.
21 changes: 16 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
language: ruby
cache: bundler
rvm:
- 1.9.3
- 2.0.0
- 2.1.2
before_script: "bundle exec rake db:migrate"
- 2.1.5
- 2.2.0
before_script:
- mysql -e 'create database enju_test'
- psql -c 'create database enju_test;' -U postgres
- bundle exec rake db:migrate
services:
- elasticsearch
- redis-server
env:
- DB=sqlite
- DB=mysql
- DB=postgresql
notifications:
slack:
secure: H47CWe0kjyXGsaSOtjt22kVvJ8ixbMrvF9imV2nxCUzqK7oens8xNE6VqB3JQ2Rb5n6NMZHpR2cCcG8jcSRm9ZmGgOHLaUdxRxVqTJ1dgD64j1/wNlpNGUp3eAo8XurarmF+06DBOLgiNG65mNmcQ2HFxDC0Vbhxwt4F1IvTlLU=
sudo: false
22 changes: 12 additions & 10 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source "https://rubygems.org"
source 'https://rubygems.org'

# Declare your gem's dependencies in enju_inter_library_loan.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
Expand All @@ -9,13 +9,15 @@ gemspec
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.
gem "enju_biblio", github: "next-l/enju_biblio"
gem "enju_library", github: "next-l/enju_library"
gem "enju_leaf", github: "next-l/enju_leaf"
gem "enju_manifestation_viewer", github: "next-l/enju_manifestation_viewer"
gem "enju_circulation", github: "next-l/enju_circulation"
gem "enju_event", github: "next-l/enju_event"
gem "enju_message", github: "next-l/enju_message"
gem "jquery-rails"
gem "enju_leaf", github: "next-l/enju_leaf", branch: "master"
gem "enju_biblio", github: "next-l/enju_biblio", branch: "master"
gem "enju_library", github: "next-l/enju_library", branch: "master"
gem "enju_message", github: "next-l/enju_message", branch: "master"
gem "enju_circulation", github: "next-l/enju_circulation", branch: "master"
gem "enju_event", github: "next-l/enju_event", branch: "master"
gem "enju_manifestation_viewer", github: "next-l/enju_manifestation_viewer", branch: "master"
gem "coveralls", require: false, group: :test

# To use debugger
# gem 'debugger'
# To use a debugger
# gem 'byebug', group: [:development, :test]
9 changes: 8 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
= EnjuInterLibraryLoan
{<img src="https://secure.travis-ci.org/next-l/enju_inter_library_loan.png?branch=1.1" alt="Build Status" />}[http://travis-ci.org/next-l/enju_inter_library_loan]
{<img src="https://coveralls.io/repos/next-l/enju_inter_library_loan/badge.png?branch=1.1" alt="Coverage Status" />}[https://coveralls.io/r/next-l/enju_inter_library_loan?branch=1.1]
{<img src="https://hakiri.io/github/next-l/enju_inter_library_loan/1.1.svg" alt="security" />}[https://hakiri.io/github/next-l/enju_inter_library_loan/1.1]

This project rocks and uses MIT-LICENSE.
This project rocks and uses MIT-LICENSE.

== 製作者・貢献者 (Authors and contributors)
* {TANABE, Kosuke}[https://github.com/nabeta] ({@nabeta}[https://twitter.com/nabeta])
* {Project Next-L}[http://www.next-l.jp] ({@ProjectNextL}[https://twitter.com/ProjectNextL])
47 changes: 16 additions & 31 deletions app/controllers/inter_library_loans_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
class InterLibraryLoansController < ApplicationController
before_action :set_inter_library_loan, only: [:show, :edit, :update, :destroy]
before_action :get_item
before_action :store_page, only: :index
after_action :verify_authorized
load_and_authorize_resource
before_filter :get_item
before_filter :store_page, :only => :index

# GET /inter_library_loans
# GET /inter_library_loans.json
def index
authorize InterLibraryLoan
if @item
@inter_library_loans = @item.inter_library_loans.page(params[:page])
else
Expand All @@ -17,7 +15,7 @@ def index
respond_to do |format|
format.html # index.html.erb
format.json { render json: @inter_library_loans }
format.rss { render layout: false }
format.rss { render :layout => false }
format.atom
end
end
Expand All @@ -37,9 +35,7 @@ def show
# GET /inter_library_loans/new.json
def new
@inter_library_loan = InterLibraryLoan.new
authorize @inter_library_loan
@libraries = LibraryGroup.first.real_libraries
@libraries.to_a.reject!{|library| library == current_user.library}
@libraries = Library.where('id != ?', current_user.profile.try(:library_id))

respond_to do |format|
format.html # new.html.erb
Expand All @@ -50,29 +46,26 @@ def new
# GET /inter_library_loans/1/edit
def edit
@inter_library_loan = InterLibraryLoan.find(params[:id])
@libraries = LibraryGroup.first.real_libraries
@libraries.to_a.reject!{|library| library == current_user.library}
@libraries = Library.where('id != ?', current_user.profile.try(:library_id))
end

# POST /inter_library_loans
# POST /inter_library_loans.json
def create
@inter_library_loan = InterLibraryLoan.new(inter_library_loan_params)
authorize @inter_library_loan
@inter_library_loan = InterLibraryLoan.new(params[:inter_library_loan])
item = Item.where(:item_identifier => params[:inter_library_loan][:item_identifier]).first
@inter_library_loan.item = item

respond_to do |format|
if @inter_library_loan.save
@inter_library_loan.sm_request!
flash[:notice] = t('controller.successfully_created', model: t('activerecord.models.inter_library_loan'))
flash[:notice] = t('controller.successfully_created', :model => t('activerecord.models.inter_library_loan'))
format.html { redirect_to(@inter_library_loan) }
format.json { render json: @inter_library_loan, status: :created, location: @inter_library_loan }
format.json { render json: @inter_library_loan, :status => :created, :location => @inter_library_loan }
else
@libraries = LibraryGroup.first.real_libraries
@libraries.reject!{|library| library == current_user.library}
@libraries = Library.where('id != ?', current_user.profile.try(:library_id))
format.html { render action: "new" }
format.json { render json: @inter_library_loan.errors, status: :unprocessable_entity }
format.json { render json: @inter_library_loan.errors, :status => :unprocessable_entity }
end
end
end
Expand All @@ -96,16 +89,15 @@ def update
end

respond_to do |format|
if @inter_library_loan.update_attributes(inter_library_loan_params)
flash[:notice] = t('controller.successfully_updated', model: t('activerecord.models.inter_library_loan'))
if @inter_library_loan.update_attributes(params[:inter_library_loan])
flash[:notice] = t('controller.successfully_updated', :model => t('activerecord.models.inter_library_loan'))
format.html { redirect_to(@inter_library_loan) }
format.json { head :no_content }
else
@inter_library_loan.item = @item
@libraries = LibraryGroup.first.real_libraries
@libraries.reject!{|library| library == current_user.library}
@libraries = Library.where('id != ?', current_user.profile.try(:library_id))
format.html { render action: "edit" }
format.json { render json: @inter_library_loan.errors, status: :unprocessable_entity }
format.json { render json: @inter_library_loan.errors, :status => :unprocessable_entity }
end
end
end
Expand All @@ -128,14 +120,7 @@ def destroy
end

private
def set_inter_library_loan
@inter_library_loan = InterLibraryLoan.find(params[:id])
authorize @inter_library_loan
end

def inter_library_loan_params
params.require(:inter_library_loan).permit(
:item_id, :borrowing_library_id
)
params.require(:inter_library_loan).permit(:item_id, :borrowing_library_id)
end
end
55 changes: 35 additions & 20 deletions app/models/inter_library_loan.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class InterLibraryLoan < ActiveRecord::Base
include Statesman::Adapters::ActiveRecordQueries
scope :completed, -> {in_state(:return_received)}
scope :processing, lambda {|item, borrowing_library| where('item_id = ? AND borrowing_library_id = ?', item.id, borrowing_library.id)}

Expand All @@ -10,56 +11,72 @@ class InterLibraryLoan < ActiveRecord::Base
validates_associated :item, :borrowing_library
validate :check_library, on: :create

attr_accessor :item_identifier

paginates_per 10

def state_machine
InterLibraryLoanStateMachine.new(self, transition_class: InterLibraryLoanTransition)
end

has_many :inter_library_loan_transitions

delegate :can_transition_to?, :transition_to!, :transition_to, :current_state,
to: :state_machine

def check_library
if self.item and self.borrowing_library
unless InterLibraryLoan.processing(self.item, self.borrowing_library).blank?
if item and borrowing_library
unless InterLibraryLoan.processing(item, borrowing_library).blank?
errors.add(:borrowing_library)
errors.add(:item_identifier)
end
end
end

def self.per_page
10
end

attr_accessor :item_identifier

def do_request
InterLibraryLoan.transaction do
self.item.update_attributes({:circulation_status => CirculationStatus.where(name: 'Recalled').first})
self.update_attributes({:requested_at => Time.zone.now})
item.update_attributes({:circulation_status => CirculationStatus.where(:name => 'Recalled').first})
update_attributes({:requested_at => Time.zone.now})
end
end

def ship
InterLibraryLoan.transaction do
self.item.update_attributes({:circulation_status => CirculationStatus.where(name: 'In Transit Between Library Locations').first})
self.update_attributes({:shipped_at => Time.zone.now})
item.update_attributes({:circulation_status => CirculationStatus.where(:name => 'In Transit Between Library Locations').first})
update_attributes({:shipped_at => Time.zone.now})
end
end

def receive
InterLibraryLoan.transaction do
self.item.update_attributes({:circulation_status => CirculationStatus.where(name: 'In Process').first})
self.update_attributes({:received_at => Time.zone.now})
item.update_attributes({:circulation_status => CirculationStatus.where(:name => 'In Process').first})
update_attributes({:received_at => Time.zone.now})
end
end

def return_ship
InterLibraryLoan.transaction do
self.item.update_attributes({:circulation_status => CirculationStatus.where(name: 'In Transit Between Library Locations').first})
self.update_attributes({:return_shipped_at => Time.zone.now})
item.update_attributes({:circulation_status => CirculationStatus.where(:name => 'In Transit Between Library Locations').first})
update_attributes({:return_shipped_at => Time.zone.now})
end
end

def return_receive
InterLibraryLoan.transaction do
# TODO: 'Waiting To Be Reshelved'
self.item.update_attributes({:circulation_status => CirculationStatus.where(name: 'Available On Shelf').first})
self.update_attributes({:return_received_at => Time.zone.now})
item.update_attributes({:circulation_status => CirculationStatus.where(:name => 'Available On Shelf').first})
update_attributes({:return_received_at => Time.zone.now})
end
end

private
def self.transition_class
InterLibraryLoanTransition
end

def self.initial_state
OrderStateMachine.initial_state
end
end

# == Schema Information
Expand All @@ -75,8 +92,6 @@ def return_receive
# return_shipped_at :datetime
# return_received_at :datetime
# deleted_at :datetime
# state :string(255)
# created_at :datetime not null
# updated_at :datetime not null
#

8 changes: 4 additions & 4 deletions app/models/inter_library_loan_state_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ class InterLibraryLoanStateMachine
transition from: :received, to: :return_shipped
transition from: :return_shipped, to: :return_received

before_transiton(to: :shipped) do |inter_library_loan|
before_transition(to: :shipped) do |inter_library_loan|
inter_library_loan.ship
end

before_transiton(to: :received) do |inter_library_loan|
before_transition(to: :received) do |inter_library_loan|
inter_library_loan.do_receive
end

before_transiton(to: :return_shipped) do |inter_library_loan|
before_transition(to: :return_shipped) do |inter_library_loan|
inter_library_loan.do_return_ship
end

before_transiton(to: :return_received) do |inter_library_loan|
before_transition(to: :return_received) do |inter_library_loan|
inter_library_loan.do_return_receive
end
end
14 changes: 14 additions & 0 deletions app/models/inter_library_loan_transition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,18 @@ class InterLibraryLoanTransition < ActiveRecord::Base


belongs_to :inter_library_loan, inverse_of: :inter_library_loan_transitions
#attr_accessible :to_state, :sort_key, :metadata
end

# == Schema Information
#
# Table name: inter_library_loan_transitions
#
# id :integer not null, primary key
# to_state :string(255)
# metadata :text default("{}")
# sort_key :integer
# inter_library_loan_id :integer
# created_at :datetime not null
# updated_at :datetime not null
#
10 changes: 5 additions & 5 deletions app/views/inter_library_loans/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div id="content_detail" class="ui-corner-all ui-widget-content">
<h1 class="title"><%= t('page.editing', model: t('activerecord.models.inter_library_loan')) -%></h1>
<h1 class="title"><%= t('page.editing', :model => t('activerecord.models.inter_library_loan')) -%></h1>
<div id="content_list">

<%= form_for(@inter_library_loan) do |f| -%>
Expand Down Expand Up @@ -31,7 +31,7 @@
<%= f.datetime_select :shipped_at -%>
</div>
<div class="actions">
<%= f.submit data: {confirm: t('page.are_you_sure')} -%>
<%= f.submit :data => {:confirm => t('page.are_you_sure')} -%>
</div>
<%- end -%>
<%- when 'shipped' -%>
Expand All @@ -51,7 +51,7 @@
<%= f.datetime_select :received_at -%>
</div>
<div class="actions">
<%= f.submit data: {confirm: t('page.are_you_sure')} -%>
<%= f.submit :data => {:confirm => t('page.are_you_sure')} -%>
</div>
<%- end -%>
<%- when 'received' -%>
Expand All @@ -76,7 +76,7 @@
<%= f.datetime_select :return_shipped_at -%>
</div>
<div class="actions">
<%= f.submit data: {confirm: t('page.are_you_sure')} -%>
<%= f.submit :data => {:confirm => t('page.are_you_sure')} -%>
</div>
<%- end -%>
<%- when 'return_shipped' -%>
Expand Down Expand Up @@ -106,7 +106,7 @@
<%= f.datetime_select :return_received_at -%>
</div>
<div class="actions">
<%= f.submit data: {confirm: t('page.are_you_sure')} -%>
<%= f.submit :data => {:confirm => t('page.are_you_sure')} -%>
</div>
<%- end -%>
<%- when 'return_received' -%>
Expand Down
4 changes: 2 additions & 2 deletions app/views/inter_library_loans/index.atom.builder
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
atom_feed(url: inter_library_loans_url(format: :atom)) do |feed|
feed.title t('inter_library_loan.library_group_inter_library_loan', library_group_name: @library_group.display_name.localize)
atom_feed(:url => inter_library_loans_url(:format => :atom)) do |feed|
feed.title t('inter_library_loan.library_group_inter_library_loan', :library_group_name => @library_group.display_name.localize)
feed.updated(@inter_library_loans.first ? @inter_library_loans.first.created_at : Time.zone.now)

@inter_library_loans.each do |inter_library_loan|
Expand Down
Loading

0 comments on commit 1971939

Please sign in to comment.