riddler_admin 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/riddler_admin/application.js +0 -1
- data/app/assets/javascripts/riddler_admin/preview_contexts.js +2 -0
- data/app/assets/javascripts/riddler_admin/publish_requests.js +2 -0
- data/app/assets/javascripts/riddler_admin/steps.js +36 -22
- data/app/assets/stylesheets/riddler_admin/application.scss +3 -0
- data/app/assets/stylesheets/riddler_admin/preview_contexts.css +4 -0
- data/app/assets/stylesheets/riddler_admin/publish_requests.css +4 -0
- data/app/controllers/riddler_admin/application_controller.rb +24 -2
- data/app/controllers/riddler_admin/dashboard_controller.rb +8 -0
- data/app/controllers/riddler_admin/elements_controller.rb +6 -2
- data/app/controllers/riddler_admin/preview_contexts_controller.rb +60 -0
- data/app/controllers/riddler_admin/publish_requests_controller.rb +90 -0
- data/app/controllers/riddler_admin/slugs_controller.rb +67 -0
- data/app/controllers/riddler_admin/steps_controller.rb +73 -20
- data/app/helpers/riddler_admin/application_helper.rb +19 -0
- data/app/helpers/riddler_admin/preview_contexts_helper.rb +4 -0
- data/app/helpers/riddler_admin/publish_requests_helper.rb +4 -0
- data/app/models/riddler_admin/application_record.rb +4 -4
- data/app/models/riddler_admin/content_definition.rb +87 -0
- data/app/models/riddler_admin/element.rb +52 -10
- data/app/models/riddler_admin/elements/heading.rb +6 -0
- data/app/models/riddler_admin/elements/image.rb +18 -0
- data/app/models/riddler_admin/elements/link.rb +18 -0
- data/app/models/riddler_admin/elements/{copy.rb → text.rb} +7 -1
- data/app/models/riddler_admin/elements/variant.rb +19 -0
- data/app/models/riddler_admin/preview_context.rb +83 -0
- data/app/models/riddler_admin/publish_request.rb +57 -0
- data/app/models/riddler_admin/slug.rb +90 -0
- data/app/models/riddler_admin/step.rb +66 -4
- data/app/models/riddler_admin/steps/variant.rb +19 -0
- data/app/validators/parseable_predicate_validator.rb +8 -0
- data/app/views/layouts/riddler_admin/application.html.erb +11 -4
- data/app/views/riddler_admin/_element.html.erb +14 -10
- data/app/views/riddler_admin/_element_container.html.erb +11 -0
- data/app/views/riddler_admin/_navbar.html.erb +29 -0
- data/app/views/riddler_admin/_preview_step.html.erb +39 -0
- data/app/views/riddler_admin/_step.html.erb +35 -0
- data/app/views/riddler_admin/_step_container.html.erb +11 -0
- data/app/views/riddler_admin/dashboard/index.html.erb +44 -0
- data/app/views/riddler_admin/elements/_form.html.erb +37 -0
- data/app/views/riddler_admin/elements/_new.html.erb +41 -8
- data/app/views/riddler_admin/elements/_show.html.erb +3 -1
- data/app/views/riddler_admin/elements/edit.js.erb +2 -0
- data/app/views/riddler_admin/elements/heading/_detail.html.erb +0 -0
- data/app/views/riddler_admin/elements/heading/_form.html.erb +8 -2
- data/app/views/riddler_admin/elements/image/_detail.html.erb +0 -0
- data/app/views/riddler_admin/elements/image/_form.html.erb +12 -0
- data/app/views/riddler_admin/elements/link/_detail.html.erb +0 -0
- data/app/views/riddler_admin/elements/link/_form.html.erb +12 -0
- data/app/views/riddler_admin/elements/show.js.erb +2 -2
- data/app/views/riddler_admin/elements/text/_detail.html.erb +0 -0
- data/app/views/riddler_admin/elements/text/_form.html.erb +4 -0
- data/app/views/riddler_admin/elements/variant/_detail.html.erb +6 -0
- data/app/views/riddler_admin/elements/variant/_form.html.erb +1 -0
- data/app/views/riddler_admin/preview_contexts/_form.html.erb +44 -0
- data/app/views/riddler_admin/preview_contexts/edit.html.erb +10 -0
- data/app/views/riddler_admin/preview_contexts/index.html.erb +43 -0
- data/app/views/riddler_admin/preview_contexts/new.html.erb +10 -0
- data/app/views/riddler_admin/preview_contexts/show.html.erb +45 -0
- data/app/views/riddler_admin/publish_requests/_actions.html.erb +19 -0
- data/app/views/riddler_admin/publish_requests/_form.html.erb +53 -0
- data/app/views/riddler_admin/publish_requests/approve.js.erb +2 -0
- data/app/views/riddler_admin/publish_requests/edit.html.erb +10 -0
- data/app/views/riddler_admin/publish_requests/index.html.erb +62 -0
- data/app/views/riddler_admin/publish_requests/new.html.erb +10 -0
- data/app/views/riddler_admin/publish_requests/publish.js.erb +2 -0
- data/app/views/riddler_admin/publish_requests/show.html.erb +25 -0
- data/app/views/riddler_admin/slugs/_form.html.erb +48 -0
- data/app/views/riddler_admin/slugs/edit.html.erb +10 -0
- data/app/views/riddler_admin/slugs/index.html.erb +44 -0
- data/app/views/riddler_admin/slugs/new.html.erb +10 -0
- data/app/views/riddler_admin/slugs/show.html.erb +18 -0
- data/app/views/riddler_admin/steps/_definition.html.erb +11 -0
- data/app/views/riddler_admin/steps/_form.html.erb +45 -17
- data/app/views/riddler_admin/steps/_new_sub_step.html.erb +56 -0
- data/app/views/riddler_admin/steps/_visual_preview.html.erb +24 -0
- data/app/views/riddler_admin/steps/content/_show.html.erb +53 -25
- data/app/views/riddler_admin/steps/edit.html.erb +15 -4
- data/app/views/riddler_admin/steps/index.html.erb +24 -10
- data/app/views/riddler_admin/steps/internal_preview.js.erb +5 -0
- data/app/views/riddler_admin/steps/new.html.erb +10 -5
- data/app/views/riddler_admin/steps/new.js.erb +3 -0
- data/app/views/riddler_admin/steps/preview.json.erb +1 -0
- data/app/views/riddler_admin/steps/show.html.erb +26 -11
- data/app/views/riddler_admin/steps/show.js.erb +4 -0
- data/app/views/riddler_admin/steps/variant/_show.html.erb +59 -0
- data/config/routes.rb +20 -1
- data/db/migrate/20181124201519_riddler_admin_genesis.rb +72 -0
- data/lib/riddler_admin.rb +29 -2
- data/lib/riddler_admin/configuration.rb +44 -0
- data/lib/riddler_admin/version.rb +1 -1
- metadata +75 -30
- data/app/views/riddler_admin/elements/copy/_class.html.erb +0 -3
- data/app/views/riddler_admin/elements/copy/_form.html.erb +0 -2
- data/app/views/riddler_admin/elements/heading/_class.html.erb +0 -3
- data/app/views/riddler_admin/steps/_preview.html.erb +0 -5
- data/db/migrate/20181124201519_create_riddler_admin_steps.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fbe7363be1d7d9cf092e6b2975ac881b0ff97a84422027ec805f4bfe2aaa691
|
4
|
+
data.tar.gz: b6cf8b5a66cef3385193c6a1fc4e977ab90f6afedf1f5b57157e79ee0d1dc791
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 602a2498403c370eb45442fc6aa9a48b7c967f5839736306b92279677e6057311f901c659879c4590ef3eaede5ace1b8f6ef8eaf585e675756d7dff8a55eccff
|
7
|
+
data.tar.gz: e110592d9e29ed2297d59ac06f246e130f5e607f78423f5efefa8fdc2726809d43b4246af3601f99b7ed17d17413ca2851e63d05f32b76ccaeb4b349aad528ce
|
@@ -1,42 +1,56 @@
|
|
1
1
|
// Place all the behaviors and hooks related to the matching controller here.
|
2
2
|
// All this logic will automatically be available in application.js.
|
3
3
|
$(document).ready(function(){
|
4
|
+
$('.step-context-preview').on('click', function(evt) {
|
5
|
+
var stepId = $(this).data('stepId'),
|
6
|
+
pctxId = $(this).data('pctxId')
|
4
7
|
|
5
|
-
|
8
|
+
var url = window.riddler_admin_path + "steps/" + stepId + "/internal_preview?pctx_id=" + pctxId
|
9
|
+
|
10
|
+
Rails.ajax({
|
11
|
+
type: "GET",
|
12
|
+
url: url,
|
13
|
+
success: function(data){
|
14
|
+
eval(data);
|
15
|
+
}
|
16
|
+
})
|
17
|
+
});
|
18
|
+
|
19
|
+
$(".element-container").sortable({
|
6
20
|
revert: 50,
|
7
21
|
opacity: 0.5,
|
22
|
+
handle: ".handle",
|
8
23
|
cursor: "move",
|
24
|
+
containment: "parent",
|
9
25
|
forcePlaceholderSize: true,
|
10
26
|
update: function(event, ui) {
|
11
27
|
element_ids = $(this).sortable("toArray", { attribute: "data-id" })
|
12
28
|
|
29
|
+
var url = window.riddler_admin_path + "elements/sort"
|
13
30
|
Rails.ajax({
|
14
31
|
type: "PUT",
|
15
|
-
url:
|
32
|
+
url: url,
|
16
33
|
data: $.param({ element_order: element_ids })
|
17
34
|
})
|
18
|
-
},
|
19
|
-
|
20
|
-
|
21
|
-
old_update: function(event, ui) {
|
22
|
-
params = {
|
23
|
-
type: ui.item.data("klass"),
|
24
|
-
step_id: ui.item.parent().data("stepId")
|
25
|
-
}
|
26
|
-
$.get("/riddler_admin/elements/new", params, function(data) {
|
27
|
-
ui.item.removeAttr("style");
|
28
|
-
ui.item.html(data);
|
29
|
-
});
|
30
35
|
}
|
31
36
|
})
|
32
37
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
$(".step-container").sortable({
|
39
|
+
revert: 50,
|
40
|
+
opacity: 0.5,
|
41
|
+
handle: ".handle",
|
42
|
+
cursor: "move",
|
43
|
+
containment: "parent",
|
44
|
+
forcePlaceholderSize: true,
|
45
|
+
update: function(event, ui) {
|
46
|
+
step_ids = $(this).sortable("toArray", { attribute: "data-id" })
|
41
47
|
|
48
|
+
url = window.riddler_admin_path + "steps/sort"
|
49
|
+
Rails.ajax({
|
50
|
+
type: "PUT",
|
51
|
+
url: url,
|
52
|
+
data: $.param({ step_order: step_ids })
|
53
|
+
})
|
54
|
+
}
|
55
|
+
})
|
42
56
|
})
|
@@ -1,5 +1,27 @@
|
|
1
1
|
module RiddlerAdmin
|
2
|
-
class ApplicationController <
|
3
|
-
|
2
|
+
class ApplicationController < ::RiddlerAdmin.config.base_controller
|
3
|
+
before_action :authorize_riddler_admin
|
4
|
+
helper_method :riddler_current_user, :riddler_user_can_approve?, :riddler_user_can_deploy?
|
5
|
+
|
6
|
+
def riddler_current_user
|
7
|
+
self.send ::RiddlerAdmin.config.current_user_method
|
8
|
+
end
|
9
|
+
|
10
|
+
def riddler_user_can_approve?
|
11
|
+
return true if ::RiddlerAdmin.config.user_can_approve_block.nil?
|
12
|
+
::RiddlerAdmin.config.user_can_approve_block.call riddler_current_user
|
13
|
+
end
|
14
|
+
|
15
|
+
def riddler_user_can_deploy?
|
16
|
+
return true if ::RiddlerAdmin.config.user_can_deploy_block.nil?
|
17
|
+
::RiddlerAdmin.config.user_can_deploy_block.call riddler_current_user
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def authorize_riddler_admin
|
23
|
+
return true if ::RiddlerAdmin.config.controller_authorization_block.nil?
|
24
|
+
::RiddlerAdmin.config.controller_authorization_block.call self
|
25
|
+
end
|
4
26
|
end
|
5
27
|
end
|
@@ -8,9 +8,13 @@ module RiddlerAdmin
|
|
8
8
|
# GET /elements/new
|
9
9
|
def new
|
10
10
|
hash = {}
|
11
|
+
|
11
12
|
if step = Step.find_by_id(params["step_id"])
|
12
13
|
hash[:container] = step
|
14
|
+
elsif element = RiddlerAdmin::Element.find_by_id(params[:element_id])
|
15
|
+
hash[:container] = element
|
13
16
|
end
|
17
|
+
|
14
18
|
@element = @element_class.new hash
|
15
19
|
end
|
16
20
|
|
@@ -68,12 +72,12 @@ module RiddlerAdmin
|
|
68
72
|
|
69
73
|
# Only allow a trusted parameter "white list" through.
|
70
74
|
def element_create_params
|
71
|
-
params.require(:element).permit(:id, :name, :type, :text, :container_type, :container_id)
|
75
|
+
params.require(:element).permit(:id, :name, :type, :text, :container_type, :container_id, :url, :include_predicate)
|
72
76
|
end
|
73
77
|
|
74
78
|
# Only allow a trusted parameter "white list" through.
|
75
79
|
def element_params
|
76
|
-
params.require(:element).permit(:name, :text)
|
80
|
+
params.require(:element).permit(:name, :text, :url, :include_predicate)
|
77
81
|
end
|
78
82
|
end
|
79
83
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require_dependency "riddler_admin/application_controller"
|
2
|
+
|
3
|
+
module RiddlerAdmin
|
4
|
+
class PreviewContextsController < ApplicationController
|
5
|
+
before_action :set_preview_context, only: [:show, :edit, :update, :destroy]
|
6
|
+
|
7
|
+
def index
|
8
|
+
@preview_contexts = PreviewContext.all
|
9
|
+
end
|
10
|
+
|
11
|
+
def show
|
12
|
+
end
|
13
|
+
|
14
|
+
def new
|
15
|
+
@preview_context = PreviewContext.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def create
|
19
|
+
@preview_context = PreviewContext.new preview_context_params
|
20
|
+
|
21
|
+
if @preview_context.save
|
22
|
+
@preview_context.refresh_data input_headers: request.headers.to_h
|
23
|
+
|
24
|
+
redirect_to @preview_context, notice: "Preview context was successfully created."
|
25
|
+
else
|
26
|
+
render :new
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def edit
|
31
|
+
end
|
32
|
+
|
33
|
+
def update
|
34
|
+
if @preview_context.update preview_context_params
|
35
|
+
@preview_context.refresh_data input_headers: request.headers.to_h
|
36
|
+
|
37
|
+
redirect_to @preview_context, notice: "Preview context was successfully updated."
|
38
|
+
else
|
39
|
+
render :edit
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def destroy
|
44
|
+
@preview_context.destroy
|
45
|
+
redirect_to preview_contexts_url, notice: "Preview context was successfully destroyed."
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
# Use callbacks to share common setup or constraints between actions.
|
51
|
+
def set_preview_context
|
52
|
+
@preview_context = PreviewContext.find params[:id]
|
53
|
+
end
|
54
|
+
|
55
|
+
# Only allow a trusted parameter "white list" through.
|
56
|
+
def preview_context_params
|
57
|
+
params.require(:preview_context).permit(:title, :params, :headers)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require_dependency "riddler_admin/application_controller"
|
2
|
+
|
3
|
+
module RiddlerAdmin
|
4
|
+
class PublishRequestsController < ApplicationController
|
5
|
+
before_action :set_publish_request, only: [:show, :edit, :update, :destroy, :approve, :publish]
|
6
|
+
before_action :check_approval_ability, only: :approve
|
7
|
+
|
8
|
+
def index
|
9
|
+
@publish_requests = PublishRequest.all
|
10
|
+
end
|
11
|
+
|
12
|
+
def show
|
13
|
+
@preview_contexts = ::RiddlerAdmin::PreviewContext.all
|
14
|
+
end
|
15
|
+
|
16
|
+
def approve
|
17
|
+
@publish_request.approve riddler_current_user
|
18
|
+
end
|
19
|
+
|
20
|
+
def publish
|
21
|
+
@publish_request.publish
|
22
|
+
end
|
23
|
+
|
24
|
+
def new
|
25
|
+
hash = {}
|
26
|
+
|
27
|
+
if step = Step.find_by_id(params["step_id"])
|
28
|
+
hash[:content] = step
|
29
|
+
@publish_request = PublishRequest.new hash
|
30
|
+
@definition = step.definition_hash.to_yaml
|
31
|
+
else
|
32
|
+
redirect_to publish_requests_path, notice: "Content must be provided in step_id"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def create
|
37
|
+
@publish_request = PublishRequest.new publish_request_params
|
38
|
+
|
39
|
+
if @publish_request.save
|
40
|
+
redirect_to @publish_request, notice: "Publish request was successfully created."
|
41
|
+
else
|
42
|
+
render :new
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def edit
|
47
|
+
if @publish_request.approved? || @publish_request.published?
|
48
|
+
redirect_to @publish_request, notice: "Editing of approved requests is not allowed"
|
49
|
+
end
|
50
|
+
|
51
|
+
@definition = @publish_request.content.definition_hash.to_yaml
|
52
|
+
end
|
53
|
+
|
54
|
+
def update
|
55
|
+
if @publish_request.approved? || @publish_request.published?
|
56
|
+
redirect_to @publish_request, notice: "Editing of approved requests is not allowed"
|
57
|
+
|
58
|
+
elsif @publish_request.update publish_request_params
|
59
|
+
redirect_to @publish_request, notice: "Publish request was successfully updated."
|
60
|
+
else
|
61
|
+
render :edit
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def destroy
|
66
|
+
@publish_request.destroy
|
67
|
+
redirect_to publish_requests_url, notice: "Publish request was successfully destroyed."
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def check_approval_ability
|
73
|
+
if !riddler_user_can_approve?
|
74
|
+
redirect_to publish_requests_url, notice: "Approval not allowed"
|
75
|
+
return false
|
76
|
+
end
|
77
|
+
true
|
78
|
+
end
|
79
|
+
|
80
|
+
# Use callbacks to share common setup or constraints between actions.
|
81
|
+
def set_publish_request
|
82
|
+
@publish_request = PublishRequest.find params[:id]
|
83
|
+
end
|
84
|
+
|
85
|
+
# Only allow a trusted parameter "white list" through.
|
86
|
+
def publish_request_params
|
87
|
+
params.require(:publish_request).permit(:title, :description, :content_type, :content_id, :definition)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require_dependency "riddler_admin/application_controller"
|
2
|
+
|
3
|
+
module RiddlerAdmin
|
4
|
+
class SlugsController < ApplicationController
|
5
|
+
before_action :set_slug, only: [:show, :edit, :update, :destroy, :toggle_status, :publish]
|
6
|
+
before_action :check_deploy_ability, only: [:create, :update]
|
7
|
+
|
8
|
+
def index
|
9
|
+
@slugs = Slug.all
|
10
|
+
end
|
11
|
+
|
12
|
+
def show
|
13
|
+
end
|
14
|
+
|
15
|
+
def new
|
16
|
+
@slug = Slug.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def create
|
20
|
+
@slug = Slug.new slug_params
|
21
|
+
|
22
|
+
if @slug.save
|
23
|
+
redirect_to slugs_url, notice: "Slug was successfully created."
|
24
|
+
else
|
25
|
+
render :new
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def edit
|
30
|
+
end
|
31
|
+
|
32
|
+
def update
|
33
|
+
if @slug.update slug_params
|
34
|
+
redirect_to slugs_url, notice: "Slug was successfully updated."
|
35
|
+
else
|
36
|
+
render :edit
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def destroy
|
41
|
+
raise "Destroying slugs is not currently supported"
|
42
|
+
@slug.destroy
|
43
|
+
redirect_to slugs_url, notice: "Slug was successfully destroyed."
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def check_deploy_ability
|
49
|
+
if !riddler_user_can_deploy?
|
50
|
+
redirect_to slugs_url, notice: "Slug creation/modification not allowed"
|
51
|
+
return false
|
52
|
+
end
|
53
|
+
true
|
54
|
+
end
|
55
|
+
|
56
|
+
# Use callbacks to share common setup or constraints between actions.
|
57
|
+
def set_slug
|
58
|
+
@slug = Slug.find params[:id]
|
59
|
+
end
|
60
|
+
|
61
|
+
# Only allow a trusted parameter "white list" through.
|
62
|
+
def slug_params
|
63
|
+
params.require(:slug).permit :name, :status, :content_definition_id,
|
64
|
+
:persist_interaction, :interaction_identity, :target_predicate
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -2,7 +2,7 @@ require_dependency "riddler_admin/application_controller"
|
|
2
2
|
|
3
3
|
module RiddlerAdmin
|
4
4
|
class StepsController < ApplicationController
|
5
|
-
before_action :set_step, only: [:show, :edit, :update, :destroy, :preview]
|
5
|
+
before_action :set_step, only: [:show, :edit, :update, :destroy, :internal_preview, :preview, :toggle]
|
6
6
|
before_action :set_step_class
|
7
7
|
|
8
8
|
# GET /steps
|
@@ -12,24 +12,76 @@ module RiddlerAdmin
|
|
12
12
|
|
13
13
|
# GET /steps/1
|
14
14
|
def show
|
15
|
-
step_definition = @step.definition_hash
|
15
|
+
@step_definition = @step.definition_hash
|
16
|
+
@preview_contexts = ::RiddlerAdmin::PreviewContext.all
|
16
17
|
end
|
17
18
|
|
18
19
|
# GET /steps/new
|
19
20
|
def new
|
20
|
-
|
21
|
+
hash = {}
|
22
|
+
|
23
|
+
if step = Step.find_by_id(params["step_id"])
|
24
|
+
hash[:stepable] = step
|
25
|
+
end
|
26
|
+
|
27
|
+
@step = @step_class.new hash
|
21
28
|
end
|
22
29
|
|
23
30
|
# GET /steps/1/edit
|
24
31
|
def edit
|
25
32
|
end
|
26
33
|
|
34
|
+
# Should always comes from the admin tool
|
35
|
+
def internal_preview
|
36
|
+
@preview_context = ::RiddlerAdmin::PreviewContext.find_by_id params["pctx_id"]
|
37
|
+
if @preview_context.nil?
|
38
|
+
render(status: 400, json: {message: "Invalid pctx_id"}) and return
|
39
|
+
end
|
40
|
+
|
41
|
+
@use_case = ::Riddler::UseCases::AdminPreviewStep.new @step.definition_hash,
|
42
|
+
preview_context_data: @preview_context.data
|
43
|
+
|
44
|
+
@preview_hash = @use_case.process
|
45
|
+
end
|
46
|
+
|
47
|
+
def sort
|
48
|
+
step_order = params.fetch "step_order"
|
49
|
+
|
50
|
+
step_order.each_with_index do |step_id, index|
|
51
|
+
step = Step.find_by_id step_id
|
52
|
+
step.update_attribute :position, index+1
|
53
|
+
end
|
54
|
+
|
55
|
+
head :no_content
|
56
|
+
end
|
57
|
+
|
58
|
+
# POST /steps/1/preview
|
59
|
+
def preview
|
60
|
+
if @step.preview_enabled
|
61
|
+
request_headers = PreviewContext.convert_headers request.headers.to_h
|
62
|
+
definition = @step.definition_hash
|
63
|
+
|
64
|
+
use_case = ::Riddler::UseCases::PreviewStep.new definition,
|
65
|
+
params: params.to_unsafe_h,
|
66
|
+
headers: request_headers
|
67
|
+
|
68
|
+
render json: use_case.process
|
69
|
+
else
|
70
|
+
render json: {status: "disabled"}
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def toggle
|
75
|
+
@step.update_attributes(preview_enabled: !@step.preview_enabled)
|
76
|
+
redirect_to @step
|
77
|
+
end
|
78
|
+
|
27
79
|
# POST /steps
|
28
80
|
def create
|
29
81
|
@step = @step_class.new(step_params)
|
30
82
|
|
31
83
|
if @step.save
|
32
|
-
redirect_to @step, notice:
|
84
|
+
redirect_to @step, notice: "Step was successfully created."
|
33
85
|
else
|
34
86
|
render :new
|
35
87
|
end
|
@@ -38,7 +90,7 @@ module RiddlerAdmin
|
|
38
90
|
# PATCH/PUT /steps/1
|
39
91
|
def update
|
40
92
|
if @step.update(step_params)
|
41
|
-
redirect_to @step, notice:
|
93
|
+
redirect_to @step, notice: "Step was successfully updated."
|
42
94
|
else
|
43
95
|
render :edit
|
44
96
|
end
|
@@ -47,26 +99,27 @@ module RiddlerAdmin
|
|
47
99
|
# DELETE /steps/1
|
48
100
|
def destroy
|
49
101
|
@step.destroy
|
50
|
-
redirect_to steps_url, notice:
|
102
|
+
redirect_to steps_url, notice: "Step was successfully destroyed."
|
51
103
|
end
|
52
104
|
|
53
105
|
private
|
54
|
-
# Use callbacks to share common setup or constraints between actions.
|
55
|
-
def set_step
|
56
|
-
@step = Step.find(params[:id])
|
57
|
-
end
|
58
106
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
107
|
+
# Use callbacks to share common setup or constraints between actions.
|
108
|
+
def set_step
|
109
|
+
@step = Step.find(params[:id])
|
110
|
+
end
|
63
111
|
|
64
|
-
|
65
|
-
|
112
|
+
def set_step_class
|
113
|
+
class_name = params.fetch(:step, {}).delete(:type) ||
|
114
|
+
params.delete(:type)
|
115
|
+
class_name = RiddlerAdmin::Step.default_class.name if class_name.blank?
|
66
116
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
117
|
+
@step_class = class_name.constantize
|
118
|
+
end
|
119
|
+
|
120
|
+
# Only allow a trusted parameter "white list" through.
|
121
|
+
def step_params
|
122
|
+
params.require(:step).permit(:title, :name, :type, :stepable_type, :stepable_id, :include_predicate)
|
123
|
+
end
|
71
124
|
end
|
72
125
|
end
|