-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathlearning_paths_controller.rb
More file actions
113 lines (98 loc) · 3.71 KB
/
Copy pathlearning_paths_controller.rb
File metadata and controls
113 lines (98 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
class LearningPathsController < ApplicationController
before_action :ensure_feature_enabled
before_action :set_learning_path, only: [:show, :edit, :update, :destroy]
before_action :set_breadcrumbs
include SearchableIndex
def index
# @bioschemas = @learning_paths.flat_map(&:to_bioschemas)
respond_to do |format|
format.html
# format.json
# format.json_api { render({ json: @learning_paths }.merge(api_collection_properties)) }
end
end
def show
authorize @learning_path
# @bioschemas = @learning_path.to_bioschemas
respond_to do |format|
format.html
# format.json
# format.json_api { render json: @learning_path }
end
end
# GET /learning_paths/new
def new
authorize LearningPath
@learning_path = LearningPath.new
end
# GET /learning_paths/1/clone
def clone
authorize @learning_path
@learning_path = @learning_path.duplicate
render :new
end
# GET /learning_paths/1/edit
def edit
authorize @learning_path
end
# POST /learning_paths
# POST /learning_paths.json
def create
authorize LearningPath
@learning_path = LearningPath.new(learning_path_params)
@learning_path.user = current_user
@learning_path.space = current_space
respond_to do |format|
if @learning_path.save
@learning_path.create_activity :create, owner: current_user
format.html { redirect_to @learning_path, notice: 'Learning path was successfully created.' }
format.json { render :show, status: :created, location: @learning_path }
else
format.html { render :new }
format.json { render json: @learning_path.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /learning_paths/1
# PATCH/PUT /learning_paths/1.json
def update
authorize @learning_path
respond_to do |format|
if @learning_path.update(learning_path_params)
@learning_path.create_activity(:update, owner: current_user) if @learning_path.log_update_activity?
format.html { redirect_to @learning_path, notice: 'Learning path was successfully updated.' }
format.json { render :show, status: :ok, location: @learning_path }
else
format.html { render :edit }
format.json { render json: @learning_path.errors, status: :unprocessable_entity }
end
end
end
# DELETE /learning_paths/1
# DELETE /learning_paths/1.json
def destroy
authorize @learning_path
@learning_path.create_activity :destroy, owner: current_user
@learning_path.destroy
respond_to do |format|
format.html { redirect_to learning_paths_path, notice: 'Learning path was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_learning_path
@learning_path = LearningPath.friendly.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def learning_path_params
params.require(:learning_path).permit(:id, :title, :description, :licence, :doi,
:content_provider_id, :difficulty_level, :status,
:prerequisites, :syllabus, :learning_objectives,
{ contributors: [] }, { authors: [] }, { target_audience: [] },
{ keywords: [] },
{ scientific_topic_names: [] }, { scientific_topic_uris: [] },
{ node_ids: [] }, { node_names: [] },
{ topic_links_attributes: [:id, :topic_id, :order, :_destroy] }, :public)
end
end