ontology_versions_controller.rb revision c1d8e2d429e199cfca7964aedbdb16c6b170f9ee
5f5870385cff47efd2f58e7892f251cf13761528Timo Sirainen#
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen# Displays versions of a ontology
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen#
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainenclass OntologyVersionsController < InheritedResources::Base
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen defaults :collection_name => :versions, :finder => :find_by_number!
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen actions :index, :show, :new, :create
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen belongs_to :ontology
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen respond_to :json, :xml
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen before_filter :check_changeable, only: [:new, :create]
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen # TODO Needs testing !!!
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen def show
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen file = resource.raw_file
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen send_file file.current_path, filename: file.identifier
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen rescue Errno::ENOENT, NoMethodError => e
9ddd3d7d8651985e373a6c48e0ddc76b8a4ef1c7Timo Sirainen redirect_to collection_path, flash: { error: "The file was not found: #{e.message}" }
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen end
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen def new
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen build_resource.source_url = collection.latest.first.source_url
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen end
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen def create
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen build_resource.user = current_user
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen super do |success, failure|
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen success.html { redirect_to collection_path }
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen end
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen end
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen def oops
d03a871a77f8ec36f48f5fea98d810e51b186fdbTimo Sirainen resource.build_request.save!
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen flash[:notice] = "Your request is send to OOPS!"
d03a871a77f8ec36f48f5fea98d810e51b186fdbTimo Sirainen redirect_to :back
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen end
38505846b6d083e19f0a7d1373761bdda5d9a5a9Timo Sirainen
38505846b6d083e19f0a7d1373761bdda5d9a5a9Timo Sirainenprotected
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen def check_changeable
d8702d15ee7721ed1fcfc8f00a589970bd6b3598Timo Sirainen unless parent.changeable?
d8702d15ee7721ed1fcfc8f00a589970bd6b3598Timo Sirainen redirect_to collection_path, flash: { error: 'There are pending ontology versions.' }
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen end
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen end
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainenend
f016dec9837e6a41867708e4b89ca5308dedab05Timo Sirainen