Skip to content

Commit

Permalink
Add 'new version' function to plan files and survey files
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Soltys committed Jun 12, 2013
1 parent d06e040 commit 7e6d897
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 5 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ gem 'devise'
gem 'passenger'
gem 'mysql2'
gem 'rails3-jquery-autocomplete', :git => 'https://github.com/crowdint/rails3-jquery-autocomplete'
gem 'debugger'

# Gems used only for assets and not required
# in production environments by default.
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.6.2)
columnize (0.3.6)
daemon_controller (1.1.2)
debugger (1.6.0)
columnize (>= 0.3.1)
debugger-linecache (~> 1.2.0)
debugger-ruby_core_source (~> 1.2.1)
debugger-linecache (1.2.0)
debugger-ruby_core_source (1.2.2)
devise (2.2.3)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.1)
Expand Down Expand Up @@ -139,6 +146,7 @@ PLATFORMS
DEPENDENCIES
active_scaffold!
coffee-rails (~> 3.2.1)
debugger
devise
jquery-rails
mysql2
Expand Down
12 changes: 8 additions & 4 deletions app/controllers/plan_files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class PlanFilesController < ApplicationController
config.show.link = false
config.update.link = false

# config.action_links.add 'subrecord', :label => 'Subrecords', :type => :member
config.action_links.add 'new_version', :label => 'New Version', :page => true, :type => :member, :inline => true, :position => :after
config.action_links.add 'show', :label => 'Print', :page => true, :type => :member, :html_options => { :class => 'print' }
active_scaffold_config.columns = active_scaffold_config.columns._inheritable
end
Expand All @@ -62,8 +62,12 @@ def format_plan_number
params[:record][:plan_number] = params[:record][:prefix] + params[:record][:plan_number]
end

def subrecord
parent = PlanFile.find(params[:id])
children = parent.plan_number
def new_version
record = PlanFile.find(params[:id])
dup = record.dup
params[:id] = dup.id
dup.plan_number = record.latest_version
dup.save!
redirect_to :controller => 'plan_files', :action => 'index'
end
end
10 changes: 10 additions & 0 deletions app/controllers/survey_files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ def self.condition_for_date_type(column, value, like_pattern)
config.search.link = false
config.update.link = false

config.action_links.add 'new_version', :label => 'New Version', :page => true, :type => :member, :inline => true, :position => :after
config.action_links.add 'show', :label => 'Print', :page => true, :type => :member, :html_options => { :class => 'print' }
end

def new_version
record = SurveyFile.find(params[:id])
dup = record.dup
dup.survey_file = SurveyFile.where("survey_file LIKE '%?%'", record.survey_file.truncate).maximum("survey_file") + 0.01
params[:id] = dup.id
dup.save!
redirect_to :controller => 'survey_files', :action => 'index'
end
end
9 changes: 9 additions & 0 deletions app/models/plan_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def base_number
r.nil? ? '' : r[1]
end

def decimal
r = /.*\.(.*)/.match(plan_number)
r.nil? ? '' : r[1]
end

def drawing_description
nil
end
Expand All @@ -41,4 +46,8 @@ def self.latest(prefix)
.select(%q{max(cast(substr(plan_number,} + prefix.length.to_s + %q{) as decimal(10,2))) as latest})
.where("plan_number like ?", prefix).first.latest
end

def latest_version
base_number + '.' + ((PlanFile.where('plan_number like ?', base_number + '%').collect{ |p| p.decimal }).max.to_i + 1).to_s.rjust(2, '0')
end
end
1 change: 1 addition & 0 deletions app/views/survey_files/new_version.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render :partial => 'create_form' -%>
5 changes: 4 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
resources :marine_files do as_routes end
resources :plan_files do
collection do
get 'subrecord'
get 'new_version'
get 'latest'
end
as_routes
Expand All @@ -21,6 +21,9 @@
resources :survey_files do
as_routes
get :autocomplete_survey_file_survey_file, :on => :collection
collection do
get 'new_version'
end
end
resources :surveyors do as_routes end

Expand Down

0 comments on commit 7e6d897

Please sign in to comment.