slices 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +3 -0
- data/README.md +51 -0
- data/Rakefile +9 -0
- data/app/assets/images/slices/ajax-loader.gif +0 -0
- data/app/assets/images/slices/asset-background.png +0 -0
- data/app/assets/images/slices/asset-spinner.gif +0 -0
- data/app/assets/images/slices/bg_header.gif +0 -0
- data/app/assets/images/slices/black-Linen.png +0 -0
- data/app/assets/images/slices/calendar.svg +68 -0
- data/app/assets/images/slices/chosen-sprite.png +0 -0
- data/app/assets/images/slices/drag-handle.svg +9 -0
- data/app/assets/images/slices/icon_admins.png +0 -0
- data/app/assets/images/slices/icon_app.png +0 -0
- data/app/assets/images/slices/icon_assets.png +0 -0
- data/app/assets/images/slices/icon_collapse.png +0 -0
- data/app/assets/images/slices/icon_drag.png +0 -0
- data/app/assets/images/slices/icon_files.png +0 -0
- data/app/assets/images/slices/icon_generic_file.png +0 -0
- data/app/assets/images/slices/icon_images.png +0 -0
- data/app/assets/images/slices/icon_padlock.png +0 -0
- data/app/assets/images/slices/icon_page.png +0 -0
- data/app/assets/images/slices/icon_search.png +0 -0
- data/app/assets/images/slices/icon_set-link.png +0 -0
- data/app/assets/images/slices/icon_set.png +0 -0
- data/app/assets/images/slices/icon_sitemap.png +0 -0
- data/app/assets/images/slices/icon_snippets.png +0 -0
- data/app/assets/images/slices/icon_template.jpg +0 -0
- data/app/assets/images/slices/icon_upload_happy.png +0 -0
- data/app/assets/images/slices/icon_upload_sad.png +0 -0
- data/app/assets/images/slices/icon_upload_thinking.png +0 -0
- data/app/assets/images/slices/noise.png +0 -0
- data/app/assets/images/slices/sitemap_icon_ghost.png +0 -0
- data/app/assets/images/slices/sitemap_icon_home.png +0 -0
- data/app/assets/images/slices/sitemap_icon_page.png +0 -0
- data/app/assets/images/slices/sitemap_icon_set_page.png +0 -0
- data/app/assets/images/slices/sitemap_icon_virtual_page.png +0 -0
- data/app/assets/images/slices/sitemap_overlay.png +0 -0
- data/app/assets/images/slices/spinner.gif +0 -0
- data/app/assets/images/slices/trash.png +0 -0
- data/app/assets/javascripts/admin.js.erb +18 -0
- data/app/assets/javascripts/slices/app/backbones/admins.js +114 -0
- data/app/assets/javascripts/slices/app/backbones/entries.js +172 -0
- data/app/assets/javascripts/slices/app/backbones/generic.js +101 -0
- data/app/assets/javascripts/slices/app/backbones/snippets.js +113 -0
- data/app/assets/javascripts/slices/app/helpers/assets.js +61 -0
- data/app/assets/javascripts/slices/app/helpers/breadcrumbs.js +30 -0
- data/app/assets/javascripts/slices/app/helpers/composer.js +26 -0
- data/app/assets/javascripts/slices/app/helpers/date_field.js +16 -0
- data/app/assets/javascripts/slices/app/helpers/get_value.js +31 -0
- data/app/assets/javascripts/slices/app/helpers/icon_upload_names.js.erb +5 -0
- data/app/assets/javascripts/slices/app/helpers/layout.js +20 -0
- data/app/assets/javascripts/slices/app/helpers/sitemap.js +150 -0
- data/app/assets/javascripts/slices/app/helpers/slice_preview.js +48 -0
- data/app/assets/javascripts/slices/app/helpers/tagging.js +73 -0
- data/app/assets/javascripts/slices/app/helpers/token_field.js +17 -0
- data/app/assets/javascripts/slices/app/helpers/upload_icons.js.erb +5 -0
- data/app/assets/javascripts/slices/app/helpers/uploader.js +127 -0
- data/app/assets/javascripts/slices/app/models/asset.js +29 -0
- data/app/assets/javascripts/slices/app/models/asset_collection.js +41 -0
- data/app/assets/javascripts/slices/app/models/attachment.js +29 -0
- data/app/assets/javascripts/slices/app/models/attachment_collection.js +7 -0
- data/app/assets/javascripts/slices/app/models/composer_item.js +1 -0
- data/app/assets/javascripts/slices/app/models/composer_item_collection.js +3 -0
- data/app/assets/javascripts/slices/app/models/file.js +103 -0
- data/app/assets/javascripts/slices/app/models/page.js +186 -0
- data/app/assets/javascripts/slices/app/models/s3_file.js +64 -0
- data/app/assets/javascripts/slices/app/slices.js +661 -0
- data/app/assets/javascripts/slices/app/views/asset_editor_view.js.erb +209 -0
- data/app/assets/javascripts/slices/app/views/asset_library_view.js +720 -0
- data/app/assets/javascripts/slices/app/views/asset_thumb_view.js.erb +191 -0
- data/app/assets/javascripts/slices/app/views/attachment_composer_view.js +350 -0
- data/app/assets/javascripts/slices/app/views/attachment_view.js +101 -0
- data/app/assets/javascripts/slices/app/views/calendar_view.js +198 -0
- data/app/assets/javascripts/slices/app/views/composer_item_view.js +54 -0
- data/app/assets/javascripts/slices/app/views/composer_view.js +130 -0
- data/app/assets/javascripts/slices/app/views/date_field_view.js +177 -0
- data/app/assets/javascripts/slices/app/views/file_view.js +142 -0
- data/app/assets/javascripts/slices/app/views/token_field_view.js +253 -0
- data/app/assets/javascripts/slices/lib/freeze.js +14 -0
- data/app/assets/javascripts/slices/lib/human_file_size.js +16 -0
- data/app/assets/javascripts/slices/lib/json_patch.js +9 -0
- data/app/assets/javascripts/slices/lib/moment.js +47 -0
- data/app/assets/javascripts/slices/lib/plugins.js +101 -0
- data/app/assets/javascripts/slices/lib/sortable.js +14 -0
- data/app/assets/javascripts/slices/slices.js +27 -0
- data/app/assets/javascripts/slices/vendor/autoscroll.js +188 -0
- data/app/assets/javascripts/slices/vendor/backbone.js +38 -0
- data/app/assets/javascripts/slices/vendor/handlebars.js +1920 -0
- data/app/assets/javascripts/slices/vendor/jqmodal.js +69 -0
- data/app/assets/javascripts/slices/vendor/jquery-ui.js +274 -0
- data/app/assets/javascripts/slices/vendor/jquery-ui_nested-sortable.js +357 -0
- data/app/assets/javascripts/slices/vendor/jquery.ajaxprogress.js +76 -0
- data/app/assets/javascripts/slices/vendor/jquery.js +2 -0
- data/app/assets/javascripts/slices/vendor/livefield.js +459 -0
- data/app/assets/javascripts/slices/vendor/moment.js +6 -0
- data/app/assets/javascripts/slices/vendor/rails.js +315 -0
- data/app/assets/javascripts/slices/vendor/underscore-string.js +1 -0
- data/app/assets/javascripts/slices/vendor/underscore.js +5 -0
- data/app/assets/stylesheets/admin.css +1 -0
- data/app/assets/stylesheets/slices/admin.css.erb +2237 -0
- data/app/assets/stylesheets/slices/reset_html5.css +106 -0
- data/app/assets/stylesheets/slices/slices.css +7 -0
- data/app/controllers/admin/admin_controller.rb +10 -0
- data/app/controllers/admin/admins_controller.rb +76 -0
- data/app/controllers/admin/assets_controller.rb +53 -0
- data/app/controllers/admin/auth/omniauth_callbacks_controller.rb +15 -0
- data/app/controllers/admin/auth/passwords_controller.rb +4 -0
- data/app/controllers/admin/auth/sessions_controller.rb +4 -0
- data/app/controllers/admin/entries_controller.rb +88 -0
- data/app/controllers/admin/page_search_controller.rb +12 -0
- data/app/controllers/admin/pages_controller.rb +103 -0
- data/app/controllers/admin/site_maps_controller.rb +15 -0
- data/app/controllers/admin/snippets_controller.rb +33 -0
- data/app/controllers/application_controller.rb +4 -0
- data/app/controllers/pages_controller.rb +45 -0
- data/app/controllers/slices_controller.rb +63 -0
- data/app/controllers/static_assets_controller.rb +52 -0
- data/app/helpers/admin/admin_helper.rb +63 -0
- data/app/helpers/admin/assets_helper.rb +36 -0
- data/app/helpers/admin/entries_helper.rb +13 -0
- data/app/helpers/admin/site_maps_helper.rb +104 -0
- data/app/helpers/assets_helper.rb +64 -0
- data/app/helpers/navigation_helper.rb +195 -0
- data/app/helpers/pages_helper.rb +119 -0
- data/app/models/admin.rb +34 -0
- data/app/models/asset.rb +211 -0
- data/app/models/attachment.rb +11 -0
- data/app/models/layout.rb +44 -0
- data/app/models/page.rb +214 -0
- data/app/models/placeholder_slice.rb +8 -0
- data/app/models/set_page.rb +12 -0
- data/app/models/set_slice.rb +57 -0
- data/app/models/site_map.rb +24 -0
- data/app/models/slice.rb +80 -0
- data/app/models/snippet.rb +21 -0
- data/app/observers/asset_observer.rb +6 -0
- data/app/observers/page_observer.rb +37 -0
- data/app/presenters/entry_presenter.rb +17 -0
- data/app/presenters/page_presenter.rb +67 -0
- data/app/presenters/presenter.rb +9 -0
- data/app/presenters/set_page_presenter.rb +2 -0
- data/app/views/admin/admins/index.html.erb +26 -0
- data/app/views/admin/admins/show.html.erb +27 -0
- data/app/views/admin/assets/index.html.erb +1 -0
- data/app/views/admin/auth/passwords/edit.html.erb +20 -0
- data/app/views/admin/auth/passwords/new.html.erb +14 -0
- data/app/views/admin/auth/sessions/_form.html.erb +35 -0
- data/app/views/admin/auth/sessions/new.html.erb +14 -0
- data/app/views/admin/entries/index.html.erb +32 -0
- data/app/views/admin/pages/_breadcrumbs.html.erb +32 -0
- data/app/views/admin/pages/_slices.html.erb +27 -0
- data/app/views/admin/pages/new.html.erb +14 -0
- data/app/views/admin/pages/show.html.erb +50 -0
- data/app/views/admin/shared/_asset_storage.html.erb +17 -0
- data/app/views/admin/shared/_custom_links.html.erb +1 -0
- data/app/views/admin/shared/_custom_navigation.html.erb +1 -0
- data/app/views/admin/shared/_navigation.html.erb +5 -0
- data/app/views/admin/site_maps/_page_li.html.erb +20 -0
- data/app/views/admin/site_maps/_set_page_li.html.erb +23 -0
- data/app/views/admin/site_maps/index.html.erb +29 -0
- data/app/views/admin/snippets/form.html.erb +12 -0
- data/app/views/admin/snippets/index.html.erb +20 -0
- data/app/views/admin/snippets/update.html.erb +0 -0
- data/app/views/layouts/admin.html.erb +72 -0
- data/lib/ext/file_store_cache.rb +18 -0
- data/lib/generators/humans/USAGE +8 -0
- data/lib/generators/humans/humans_generator.rb +10 -0
- data/lib/generators/humans/templates/humans.txt +6 -0
- data/lib/generators/slice/USAGE +28 -0
- data/lib/generators/slice/slice_generator.rb +123 -0
- data/lib/generators/slice/templates/main_fields.hbs +11 -0
- data/lib/generators/slice/templates/meta_fields.hbs +11 -0
- data/lib/generators/slice/templates/page.rb +19 -0
- data/lib/generators/slice/templates/presenter.rb +53 -0
- data/lib/generators/slice/templates/set.html.erb +8 -0
- data/lib/generators/slice/templates/set_slice.rb +14 -0
- data/lib/generators/slice/templates/set_slice_fields.hbs +5 -0
- data/lib/generators/slice/templates/show.html.erb +48 -0
- data/lib/generators/slice/templates/show_slice.rb +20 -0
- data/lib/generators/slice/templates/slice.rb +58 -0
- data/lib/generators/slice/templates/slice_fields.hbs +74 -0
- data/lib/generators/templates/slices.rb +211 -0
- data/lib/mongo_search.rb +84 -0
- data/lib/paperclip_validator.rb +5 -0
- data/lib/rack_utf8_fix.rb +10 -0
- data/lib/sRGB.icc +0 -0
- data/lib/set_link_renderer.rb +31 -0
- data/lib/slices.rb +68 -0
- data/lib/slices/asset/maker.rb +55 -0
- data/lib/slices/asset/rename.rb +67 -0
- data/lib/slices/available_slices.rb +43 -0
- data/lib/slices/cms_form_builder.rb +42 -0
- data/lib/slices/config.rb +93 -0
- data/lib/slices/container_parser.rb +70 -0
- data/lib/slices/generator_macros.rb +36 -0
- data/lib/slices/has_attachments.rb +111 -0
- data/lib/slices/has_slices.rb +88 -0
- data/lib/slices/i18n.rb +6 -0
- data/lib/slices/i18n/backend.rb +32 -0
- data/lib/slices/i18n_backend.rb +24 -0
- data/lib/slices/paperclip.rb +13 -0
- data/lib/slices/position_helper.rb +98 -0
- data/lib/slices/renderer.rb +52 -0
- data/lib/slices/slices_engine.rb +51 -0
- data/lib/slices/split_date_time_field.rb +14 -0
- data/lib/slices/tasks/assets.rake +35 -0
- data/lib/slices/tasks/db.rake +50 -0
- data/lib/slices/tasks/seeds.rake +93 -0
- data/lib/slices/tasks/validate.rake +62 -0
- data/lib/slices/tree.rb +306 -0
- data/lib/slices/version.rb +4 -0
- data/lib/slices/will_paginate.rb +12 -0
- data/lib/slices/will_paginate_mongoid.rb +45 -0
- data/lib/standard_tree.rb +193 -0
- metadata +483 -0
@@ -0,0 +1,106 @@
|
|
1
|
+
/*
|
2
|
+
html5doctor.com Reset Stylesheet
|
3
|
+
v1.4
|
4
|
+
2009-07-27
|
5
|
+
Author: Richard Clark - http://richclarkdesign.com
|
6
|
+
*/
|
7
|
+
|
8
|
+
html, body, div, span, object, iframe,
|
9
|
+
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
|
10
|
+
abbr, address, cite, code,
|
11
|
+
del, dfn, em, img, ins, kbd, q, samp,
|
12
|
+
small, strong, sub, sup, var,
|
13
|
+
b, i,
|
14
|
+
dl, dt, dd, ol, ul, li,
|
15
|
+
fieldset, form, label, legend,
|
16
|
+
table, caption, tbody, tfoot, thead, tr, th, td,
|
17
|
+
article, aside, dialog, figure, footer, header,
|
18
|
+
hgroup, menu, nav, section, menu,
|
19
|
+
time, mark, audio, video {
|
20
|
+
margin:0;
|
21
|
+
padding:0;
|
22
|
+
border:0;
|
23
|
+
outline:0;
|
24
|
+
font-size:100%;
|
25
|
+
vertical-align:baseline;
|
26
|
+
background:transparent;
|
27
|
+
}
|
28
|
+
body {
|
29
|
+
line-height:1;
|
30
|
+
}
|
31
|
+
|
32
|
+
article, aside, dialog, figure, footer, header,
|
33
|
+
hgroup, nav, section {
|
34
|
+
display:block;
|
35
|
+
}
|
36
|
+
|
37
|
+
nav ul {
|
38
|
+
list-style:none;
|
39
|
+
}
|
40
|
+
|
41
|
+
blockquote, q {
|
42
|
+
quotes:none;
|
43
|
+
}
|
44
|
+
|
45
|
+
blockquote:before, blockquote:after,
|
46
|
+
q:before, q:after {
|
47
|
+
content:'';
|
48
|
+
content:none;
|
49
|
+
}
|
50
|
+
|
51
|
+
a {
|
52
|
+
margin:0;
|
53
|
+
padding:0;
|
54
|
+
border:0;
|
55
|
+
font-size:100%;
|
56
|
+
vertical-align:baseline;
|
57
|
+
background:transparent;
|
58
|
+
}
|
59
|
+
|
60
|
+
ins {
|
61
|
+
background-color:#ff9;
|
62
|
+
color:#000;
|
63
|
+
text-decoration:none;
|
64
|
+
}
|
65
|
+
|
66
|
+
mark {
|
67
|
+
background-color:#ff9;
|
68
|
+
color:#000;
|
69
|
+
font-style:italic;
|
70
|
+
font-weight:bold;
|
71
|
+
}
|
72
|
+
|
73
|
+
del {
|
74
|
+
text-decoration: line-through;
|
75
|
+
}
|
76
|
+
|
77
|
+
abbr[title], dfn[title] {
|
78
|
+
border-bottom:1px dotted #000;
|
79
|
+
cursor:help;
|
80
|
+
}
|
81
|
+
|
82
|
+
table {
|
83
|
+
border-collapse:collapse;
|
84
|
+
border-spacing:0;
|
85
|
+
}
|
86
|
+
|
87
|
+
hr {
|
88
|
+
display:block;
|
89
|
+
height:1px;
|
90
|
+
border:0;
|
91
|
+
border-top:1px solid #cccccc;
|
92
|
+
margin:1em 0;
|
93
|
+
padding:0;
|
94
|
+
}
|
95
|
+
|
96
|
+
input, select {
|
97
|
+
vertical-align:middle;
|
98
|
+
}
|
99
|
+
|
100
|
+
/*added to original HTML5 reset by JSD 24/8/09*/
|
101
|
+
|
102
|
+
html, body {
|
103
|
+
height: 100%;
|
104
|
+
margin: 0;
|
105
|
+
padding: 0;
|
106
|
+
}
|
@@ -0,0 +1,76 @@
|
|
1
|
+
class Admin::AdminsController < Admin::AdminController
|
2
|
+
layout 'admin'
|
3
|
+
|
4
|
+
respond_to :json, :html
|
5
|
+
|
6
|
+
def index
|
7
|
+
admins = Admin.all
|
8
|
+
if params.has_key?(:search) && params[:search].present?
|
9
|
+
admins = admins.text_search(params[:search])
|
10
|
+
end
|
11
|
+
|
12
|
+
respond_to do |format|
|
13
|
+
format.html
|
14
|
+
format.json do
|
15
|
+
params[:per_page] = 50 unless params.include?(:per_page)
|
16
|
+
params[:per_page] = params[:per_page].to_i
|
17
|
+
render json: jsonify_with_current_admin(admins.paginate(params))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def new
|
23
|
+
@admin = Admin.new
|
24
|
+
render action: :show
|
25
|
+
end
|
26
|
+
|
27
|
+
def create
|
28
|
+
@admin = Admin.new(params[:admin])
|
29
|
+
if @admin.save
|
30
|
+
redirect_to admin_admins_path
|
31
|
+
else
|
32
|
+
render action: :show
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def show
|
37
|
+
@admin = Admin.find(params[:id])
|
38
|
+
respond_with(@admin)
|
39
|
+
end
|
40
|
+
|
41
|
+
def update
|
42
|
+
admin_params = params[:admin]
|
43
|
+
if admin_params[:password].blank?
|
44
|
+
admin_params.delete(:password)
|
45
|
+
admin_params.delete(:password_confirmation)
|
46
|
+
end
|
47
|
+
@admin = Admin.find(params[:id])
|
48
|
+
@admin.update_attributes(admin_params)
|
49
|
+
if @admin.valid?
|
50
|
+
redirect_to admin_admin_path(@admin)
|
51
|
+
else
|
52
|
+
render action: :show
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def destroy
|
57
|
+
admin = Admin.find(params[:id])
|
58
|
+
if admin == current_admin
|
59
|
+
render text: '', status: 409
|
60
|
+
else
|
61
|
+
admin.destroy
|
62
|
+
respond_to do |format|
|
63
|
+
format.html { redirect_to admin_admins_path }
|
64
|
+
format.json { render json: true }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def jsonify_with_current_admin(paginated_admins)
|
72
|
+
paginated_admins.as_json.tap do |json|
|
73
|
+
json[:items] = json[:items].as_json(current_admin: current_admin)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class Admin::AssetsController < Admin::AdminController
|
2
|
+
layout 'admin'
|
3
|
+
respond_to :json, :html
|
4
|
+
|
5
|
+
def index
|
6
|
+
respond_to do |format|
|
7
|
+
format.html {}
|
8
|
+
format.json do
|
9
|
+
params[:per_page] = 50 unless params.include?(:per_page)
|
10
|
+
@assets = Asset.search_for(params[:search]).paginate(params)
|
11
|
+
render json: @assets.as_json
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def create
|
17
|
+
@asset = Asset.make asset_attrs
|
18
|
+
|
19
|
+
respond_with do |format|
|
20
|
+
format.json { render json: @asset }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def update
|
25
|
+
@asset = Asset.find params[:id]
|
26
|
+
@asset.update_attributes asset_attrs
|
27
|
+
|
28
|
+
respond_with @asset do |format|
|
29
|
+
format.json { render json: @asset }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def destroy
|
34
|
+
asset = Asset.find(params[:id])
|
35
|
+
asset.soft_destroy!
|
36
|
+
respond_to do |format|
|
37
|
+
format.html { redirect_to admin_assets_path }
|
38
|
+
format.json { render json: true }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def asset_attrs
|
45
|
+
attrs = params[:asset] || {}
|
46
|
+
if file = params[:file]
|
47
|
+
file = URI(file.gsub(' ', '+')) if file.is_a?(String)
|
48
|
+
attrs[:file] = file
|
49
|
+
end
|
50
|
+
attrs
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Admin::Auth::OmniauthCallbacksController < ::Devise::OmniauthCallbacksController
|
2
|
+
layout 'admin'
|
3
|
+
helper 'admin/admin'
|
4
|
+
|
5
|
+
def google_apps
|
6
|
+
domain = Slices::Config.google_apps_domain
|
7
|
+
@admin = Admin.find_for_domain(domain)
|
8
|
+
|
9
|
+
if @admin.persisted?
|
10
|
+
sign_in_and_redirect @admin, event: :authentication
|
11
|
+
else
|
12
|
+
redirect_to new_admin_session_path
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
class Admin::EntriesController < Admin::AdminController
|
2
|
+
layout 'admin'
|
3
|
+
|
4
|
+
respond_to :json, :html
|
5
|
+
|
6
|
+
def index
|
7
|
+
@page = Page.find_by_id! params[:page_id]
|
8
|
+
|
9
|
+
respond_to do |format|
|
10
|
+
format.html do
|
11
|
+
@columns = entry_presenter_class.columns
|
12
|
+
@options = {
|
13
|
+
sort_field: sort_field,
|
14
|
+
sort_direction: sort_direction
|
15
|
+
}
|
16
|
+
end
|
17
|
+
format.json do
|
18
|
+
render json: fetch_entries.as_json
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def fetch_entries
|
27
|
+
presented paginated searched sorted raw_entries
|
28
|
+
end
|
29
|
+
|
30
|
+
def presented entries
|
31
|
+
entries.dup.tap do |entries|
|
32
|
+
entries.each_with_index do |entry, index|
|
33
|
+
entries[index] = entry_presenter_class.new entry
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def paginated entries
|
39
|
+
if sort_field != :position
|
40
|
+
params[:per_page] = 50 unless params.include?(:per_page)
|
41
|
+
params[:per_page] = params[:per_page].to_i
|
42
|
+
|
43
|
+
entries.paginate params
|
44
|
+
else
|
45
|
+
entries.paginate per_page: entry_class.count
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def searched entries
|
50
|
+
if params[:search].present?
|
51
|
+
entries.text_search params[:search]
|
52
|
+
else
|
53
|
+
entries
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def sorted entries
|
58
|
+
entries.send sort_direction, sort_field
|
59
|
+
end
|
60
|
+
|
61
|
+
def raw_entries
|
62
|
+
entry_class.entries
|
63
|
+
end
|
64
|
+
|
65
|
+
def sort_direction
|
66
|
+
set_slice.sort_direction
|
67
|
+
end
|
68
|
+
|
69
|
+
def sort_field
|
70
|
+
set_slice.sort_field
|
71
|
+
end
|
72
|
+
|
73
|
+
def entry_class
|
74
|
+
entry_type.to_s.camelize.constantize
|
75
|
+
end
|
76
|
+
|
77
|
+
def entry_type
|
78
|
+
@page.entry_types.first
|
79
|
+
end
|
80
|
+
|
81
|
+
def set_slice
|
82
|
+
@page.sets.first
|
83
|
+
end
|
84
|
+
|
85
|
+
def entry_presenter_class
|
86
|
+
presenter_class entry_class
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Admin::PageSearchController < Admin::AdminController
|
2
|
+
layout 'admin'
|
3
|
+
|
4
|
+
respond_to :json, only: [:show]
|
5
|
+
|
6
|
+
def show
|
7
|
+
@query = params[:query]
|
8
|
+
@pages = Page.where(name: Regexp.new(@query, true), role: nil).limit(5)
|
9
|
+
render json: @pages.uniq.as_json
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
class Admin::PagesController < Admin::AdminController
|
2
|
+
layout 'admin'
|
3
|
+
|
4
|
+
respond_to :html, only: [:new, :show, :create]
|
5
|
+
respond_to :json, only: [:show, :update, :destroy]
|
6
|
+
respond_to :text, only: [:show]
|
7
|
+
|
8
|
+
before_filter :find_all_slices, only: :update
|
9
|
+
after_filter :expire_fragments, only: [:update, :create, :destroy]
|
10
|
+
|
11
|
+
def new
|
12
|
+
@page = Page.new(parent_id: params[:parent_id]) # TODO: change parent_id to path
|
13
|
+
@layouts = Layout.all
|
14
|
+
respond_with(:admin, @page) do |format|
|
15
|
+
format.html { render layout: !request.xhr? }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def create
|
20
|
+
@page = new_page_class.make(params[:page])
|
21
|
+
@layouts = [['Default', 'default']]
|
22
|
+
respond_with(:admin, @page) do |format|
|
23
|
+
format.html { redirect_to admin_page_path(@page) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def show
|
28
|
+
page = Page.find_by_id!(params[:id])
|
29
|
+
@page = presenter_class(page.class).new(page)
|
30
|
+
@layout = Layout.new(page.layout)
|
31
|
+
|
32
|
+
respond_with(:admin, @page) do |format|
|
33
|
+
format.json do
|
34
|
+
render json: as_json_for_page(page)
|
35
|
+
end
|
36
|
+
format.hbs do
|
37
|
+
hbs_path = if params[:slice]
|
38
|
+
File.join(params[:slice], 'templates', params[:template])
|
39
|
+
else
|
40
|
+
params[:template]
|
41
|
+
end
|
42
|
+
render hbs_path
|
43
|
+
end
|
44
|
+
end
|
45
|
+
rescue Page::NotFound
|
46
|
+
redirect_to admin_site_maps_path
|
47
|
+
end
|
48
|
+
|
49
|
+
def update
|
50
|
+
@page = Page.find_by_id!(params[:id])
|
51
|
+
if entry_page?
|
52
|
+
params[:page][:set_slices] = params[:page].delete(:slices)
|
53
|
+
end
|
54
|
+
|
55
|
+
@page.update_attributes(params[:page])
|
56
|
+
|
57
|
+
if @page.valid?
|
58
|
+
render json: as_json_for_page(@page)
|
59
|
+
else
|
60
|
+
render json: @page.errors.as_json, status: 422
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def destroy
|
65
|
+
@page = Page.find_by_id!(params[:id])
|
66
|
+
@page.destroy
|
67
|
+
respond_to do |format|
|
68
|
+
format.html { redirect_to admin_site_maps_path }
|
69
|
+
format.json { head :no_content }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
def new_page_class
|
75
|
+
params[:type].nil? ? Page : Object.const_get(params[:type].camelize)
|
76
|
+
end
|
77
|
+
|
78
|
+
def as_json_for_page(page)
|
79
|
+
json_options = {}
|
80
|
+
if entry_page?
|
81
|
+
json_options[:only] = :slices
|
82
|
+
json_options[:slice_embed] = :set_slices
|
83
|
+
end
|
84
|
+
page.as_json(json_options)
|
85
|
+
end
|
86
|
+
|
87
|
+
def entry_page?
|
88
|
+
params.has_key?(:entries)
|
89
|
+
end
|
90
|
+
|
91
|
+
def expire_fragments
|
92
|
+
record = @page
|
93
|
+
type = record.class.to_s.underscore
|
94
|
+
id = record.id.to_s
|
95
|
+
expire_fragment(/.*#{type}.*/)
|
96
|
+
expire_fragment(/.*#{id}.*/)
|
97
|
+
end
|
98
|
+
|
99
|
+
def find_all_slices
|
100
|
+
Slices::AvailableSlices.all
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|