Class: CollectionsController
Overview
Copyright 2011 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Instance Method Summary
collapse
Instance Method Details
#create ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'app/controllers/collections_controller.rb', line 64
def create
authorize! :create, Iqvoc::Collection.base_class
@collection = Iqvoc::Collection.base_class.new(params[:concept])
if @collection.save
flash[:notice] = I18n.t("txt.controllers.collections.save.success")
redirect_to collection_path(:id => @collection)
else
flash.now[:error] = I18n.t("txt.controllers.collections.save.error")
render :new
end
end
|
#destroy ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'app/controllers/collections_controller.rb', line 109
def destroy
@collection = Iqvoc::Collection.base_class.by_origin(params[:id]).last
raise ActiveRecord::RecordNotFound.new("Could not find Collection for id '#{params[:id]}'") unless @collection
authorize! :destroy, @collection
if @collection.destroy
flash[:notice] = I18n.t("txt.controllers.collections.destroy.success")
redirect_to collections_path
else
flash.now[:error] = I18n.t("txt.controllers.collections.destroy.error")
render :action => :show
end
end
|
#edit ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'app/controllers/collections_controller.rb', line 78
def edit
@collection = Iqvoc::Collection.base_class.by_origin(params[:id]).last
raise ActiveRecord::RecordNotFound.new("Could not find Collection for id '#{params[:id]}'") unless @collection
authorize! :update, @collection
ActiveRecord::Associations::Preloader.new(@collection, [
:pref_labels,
{:subcollections => :pref_labels},
{:concepts => [:pref_labels] + Iqvoc::Concept.base_class.default_includes}]).run
build_note_relations
end
|
#index ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'app/controllers/collections_controller.rb', line 20
def index
authorize! :read, Iqvoc::Collection.base_class
respond_to do |format|
format.html do
@top_collections = Iqvoc::Collection.base_class.
with_pref_labels.
tops.
sort { |a, b| a.pref_label.to_s <=> b.pref_label.to_s }
ActiveRecord::Associations::Preloader.new(@collections, [:subcollections]).run
end
format.json do @collections = Iqvoc::Collection.base_class.with_pref_labels.merge(Label::Base.by_query_value("#{params[:query]}%"))
response = []
@collections.each { |c| response << collection_widget_data(c) }
render :json => response
end
end
end
|
#new ⇒ Object
57
58
59
60
61
62
|
# File 'app/controllers/collections_controller.rb', line 57
def new
authorize! :create, Iqvoc::Collection.base_class
@collection = Iqvoc::Collection.base_class.new
build_note_relations
end
|
#show ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'app/controllers/collections_controller.rb', line 43
def show
@collection = Iqvoc::Collection.base_class.by_origin(params[:id]).last
raise ActiveRecord::RecordNotFound.new("Could not find Collection for id '#{params[:id]}'") unless @collection
authorize! :read, @collection
ActiveRecord::Associations::Preloader.new(@collection,
[:pref_labels,
{:subcollections => [:pref_labels, :subcollections]},
{:concepts => [:pref_labels] + Iqvoc::Concept.base_class.default_includes}]).run
end
|
#update ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'app/controllers/collections_controller.rb', line 94
def update
@collection = Iqvoc::Collection.base_class.by_origin(params[:id]).last
raise ActiveRecord::RecordNotFound.new("Could not find Collection for id '#{params[:id]}'") unless @collection
authorize! :update, @collection
if @collection.update_attributes(params[:concept])
flash[:notice] = I18n.t("txt.controllers.collections.save.success")
redirect_to collection_path(:id => @collection)
else
flash.now[:error] = I18n.t("txt.controllers.collections.save.error")
render :edit
end
end
|