ontologies_controller.rb revision ce7d1499be6f68b51252fb70a38c484515f8bd79
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano#
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano# Controller for ontologies
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano#
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcanoclass OntologiesController < InheritedResources::Base
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano respond_to :json, :xml
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano has_pagination
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano has_scope :search
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano load_and_authorize_resource :except => [:index, :show]
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano respond_to :json
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano def index
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano super do |format|
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano format.html do
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano @search = params[:search]
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano @search = nil if @search.blank?
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano end
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano end
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano end
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano def new
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano @ontology_version = build_resource.versions.build
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano @categories = Category.where :ancestry => nil
99e4008cad9e959b683c6f48411fcf15a92be3b5Michel Normand end
99e4008cad9e959b683c6f48411fcf15a92be3b5Michel Normand
10fba81b9d0221b8e47aa1e0b43236413b7d28dfMichel Normand def create
99e4008cad9e959b683c6f48411fcf15a92be3b5Michel Normand @version = build_resource.versions.first
99e4008cad9e959b683c6f48411fcf15a92be3b5Michel Normand @version.user = current_user
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano super
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano end
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano def show
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano respond_to do |format|
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano format.html do
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano redirect_to ontology_entities_path(resource, :kind => resource.entities.groups_by_kind.first.kind)
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano end
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano format.json do
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano respond_with resource
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano end
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano end
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano end
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano protected
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano def build_resource
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano return @ontology if @ontology
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano type = (params[:ontology] || {}).delete(:type)
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano clazz = type=='DistributedOntology' ? DistributedOntology : SingleOntology
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano @ontology = clazz.new params[:ontology]
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano end
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcanoend
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano