Class: CollectionsController
Instance Method Summary
collapse
Methods included from Sortable
#apply_sort_order, #current_ordering, #remember_ordering
#sync
#find_caber_subjects
#generate_tag_list, #split_key_value_tags
Methods included from Filterable
#get_filters
Instance Method Details
#cover ⇒ Object
121
122
123
124
|
# File 'app/controllers/collections_controller.rb', line 121
def cover
authorize @collection
send_file_content @collection.cover, disposition: :inline
end
|
#create ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'app/controllers/collections_controller.rb', line 68
def create
authorize Collection
@collection = Collection.create(collection_params.merge(owner: current_user))
respond_to do |format|
format.html do
if @collection.valid?
if flash[:return_after_new]
redirect_to flash[:return_after_new] + "?new_collection=#{@collection.to_param}", notice: t(".success")
else
redirect_to collections_path, notice: t(".success")
end
else
render :new, status: :unprocessable_content
end
end
format.manyfold_api_v0 do
if @collection.valid?
render json: ManyfoldApi::V0::CollectionSerializer.new(@collection).serialize, status: :created, location: collection_path(@collection)
else
render json: @collection.errors.to_json, status: :unprocessable_content
end
end
end
end
|
#destroy ⇒ Object
113
114
115
116
117
118
119
|
# File 'app/controllers/collections_controller.rb', line 113
def destroy
@collection.destroy
respond_to do |format|
format.html { redirect_to collections_path, notice: t(".success") }
format.manyfold_api_v0 { head :no_content }
end
end
|
#edit ⇒ Object
65
66
|
# File 'app/controllers/collections_controller.rb', line 65
def edit
end
|
#index ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'app/controllers/collections_controller.rb', line 14
def index
@models = policy_scope(Model).all
@collections = policy_scope(Collection).all
if @filter.any?
@models = @filter.models(@models)
@collections = @filter.collections(@collections)
end
@tags, @unrelated_tag_count = generate_tag_list(@models, @filter.tags)
@tags, @kv_tags = split_key_value_tags(@tags)
@unrelated_tag_count = nil unless @filter.any?
@collections = apply_sort_order(@collections)
page = params[:page] || 1
@collections = @collections.page(page).per(helpers.["per_page"])
@collections = @collections.includes :collections, :collection, :links
@filter_in_place = true
@unassigned_count = policy_scope(Model).where.missing(:collections).count
set_indexable @collections
respond_to do |format|
format.html { render layout: "card_list_page" }
format.manyfold_api_v0 { render json: ManyfoldApi::V0::CollectionListSerializer.new(@collections).serialize }
end
end
|
#new ⇒ Object
58
59
60
61
62
63
|
# File 'app/controllers/collections_controller.rb', line 58
def new
authorize Collection
@collection = Collection.new
@title = t("collections.general.new")
flash.keep(:return_after_new)
end
|
#show ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'app/controllers/collections_controller.rb', line 45
def show
respond_to do |format|
format.html do
@models = policy_scope(@collection.models)
prepare_model_list
@additional_filters = {collection: @collection}
render layout: "card_list_page"
end
format.oembed { render json: OEmbed::CollectionSerializer.new(@collection, helpers.oembed_params).serialize }
format.manyfold_api_v0 { render json: ManyfoldApi::V0::CollectionSerializer.new(@collection).serialize }
end
end
|
#update ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'app/controllers/collections_controller.rb', line 93
def update
@collection.update(collection_params)
respond_to do |format|
format.html do
if @collection.valid?
redirect_to collections_path, notice: t(".success")
else
render :edit, status: :unprocessable_content
end
end
format.manyfold_api_v0 do
if @collection.valid?
render json: ManyfoldApi::V0::CollectionSerializer.new(@collection).serialize
else
render json: @collection.errors.to_json, status: :unprocessable_content
end
end
end
end
|