kms 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +30 -0
  4. data/app/assets/fonts/casper-webfont.eot +0 -0
  5. data/app/assets/fonts/casper-webfont.svg +278 -0
  6. data/app/assets/fonts/casper-webfont.ttf +0 -0
  7. data/app/assets/fonts/casper-webfont.woff +0 -0
  8. data/app/assets/fonts/casper-webfont.woff2 +0 -0
  9. data/app/assets/fonts/glyphicons-halflings-regular.eot +0 -0
  10. data/app/assets/fonts/glyphicons-halflings-regular.svg +229 -0
  11. data/app/assets/fonts/glyphicons-halflings-regular.ttf +0 -0
  12. data/app/assets/fonts/glyphicons-halflings-regular.woff +0 -0
  13. data/app/assets/javascripts/kms/application.js +49 -0
  14. data/app/assets/javascripts/kms/application/controllers/assets_controller.coffee +70 -0
  15. data/app/assets/javascripts/kms/application/controllers/help_controller.coffee +12 -0
  16. data/app/assets/javascripts/kms/application/controllers/pages_controller.coffee +95 -0
  17. data/app/assets/javascripts/kms/application/controllers/settings_controller.coffee +21 -0
  18. data/app/assets/javascripts/kms/application/controllers/sidebar_controller.coffee +26 -0
  19. data/app/assets/javascripts/kms/application/controllers/snippets_controller.coffee +44 -0
  20. data/app/assets/javascripts/kms/application/controllers/templates_controller.coffee +46 -0
  21. data/app/assets/javascripts/kms/application/controllers/users_controller.coffee +31 -0
  22. data/app/assets/javascripts/kms/application/module.coffee +24 -0
  23. data/app/assets/javascripts/kms/application/routes.coffee.erb +171 -0
  24. data/app/assets/javascripts/kms/application/services/errors_service.coffee +8 -0
  25. data/app/assets/javascripts/templates/assets/edit.html.slim +10 -0
  26. data/app/assets/javascripts/templates/assets/index.html.slim +31 -0
  27. data/app/assets/javascripts/templates/assets/new.html.slim +16 -0
  28. data/app/assets/javascripts/templates/help.html.slim +172 -0
  29. data/app/assets/javascripts/templates/help/filters.html.slim +51 -0
  30. data/app/assets/javascripts/templates/help/variables.html.slim +96 -0
  31. data/app/assets/javascripts/templates/pages/edit.html.slim +7 -0
  32. data/app/assets/javascripts/templates/pages/form.html.slim +32 -0
  33. data/app/assets/javascripts/templates/pages/index.html.slim +33 -0
  34. data/app/assets/javascripts/templates/pages/new.html.slim +5 -0
  35. data/app/assets/javascripts/templates/settings.html.slim +20 -0
  36. data/app/assets/javascripts/templates/snippets/edit.html.slim +5 -0
  37. data/app/assets/javascripts/templates/snippets/form.html.slim +10 -0
  38. data/app/assets/javascripts/templates/snippets/index.html.slim +22 -0
  39. data/app/assets/javascripts/templates/snippets/new.html.slim +5 -0
  40. data/app/assets/javascripts/templates/templates/edit.html.slim +7 -0
  41. data/app/assets/javascripts/templates/templates/form.html.slim +7 -0
  42. data/app/assets/javascripts/templates/templates/index.html.slim +22 -0
  43. data/app/assets/javascripts/templates/templates/new.html.slim +5 -0
  44. data/app/assets/javascripts/templates/users/form.html.slim +14 -0
  45. data/app/assets/javascripts/templates/users/index.html.slim +21 -0
  46. data/app/assets/javascripts/templates/users/new.html.slim +5 -0
  47. data/app/assets/stylesheets/kms/application.css +57 -0
  48. data/app/assets/stylesheets/kms/custom.css.scss +67 -0
  49. data/app/assets/stylesheets/kms/responsive_dashboard.css.less +9 -0
  50. data/app/controllers/kms/application_controller.rb +24 -0
  51. data/app/controllers/kms/assets_controller.rb +58 -0
  52. data/app/controllers/kms/kms_controller.rb +8 -0
  53. data/app/controllers/kms/pages_controller.rb +67 -0
  54. data/app/controllers/kms/public/pages_controller.rb +27 -0
  55. data/app/controllers/kms/public/search_controller.rb +18 -0
  56. data/app/controllers/kms/resources_controller.rb +9 -0
  57. data/app/controllers/kms/settings_controller.rb +24 -0
  58. data/app/controllers/kms/snippets_controller.rb +37 -0
  59. data/app/controllers/kms/templates_controller.rb +43 -0
  60. data/app/controllers/kms/users_controller.rb +36 -0
  61. data/app/controllers/users/confirmations_controller.rb +28 -0
  62. data/app/controllers/users/omniauth_callbacks_controller.rb +28 -0
  63. data/app/controllers/users/passwords_controller.rb +32 -0
  64. data/app/controllers/users/registrations_controller.rb +70 -0
  65. data/app/controllers/users/sessions_controller.rb +25 -0
  66. data/app/controllers/users/unlocks_controller.rb +28 -0
  67. data/app/helpers/kms/application_helper.rb +4 -0
  68. data/app/models/ability.rb +38 -0
  69. data/app/models/concerns/kms/compile_templates.rb +39 -0
  70. data/app/models/concerns/kms/permalinkable.rb +13 -0
  71. data/app/models/concerns/kms/update_stylesheets_text.rb +20 -0
  72. data/app/models/kms/asset.rb +83 -0
  73. data/app/models/kms/page.rb +61 -0
  74. data/app/models/kms/settings.rb +7 -0
  75. data/app/models/kms/snippet.rb +11 -0
  76. data/app/models/kms/template.rb +11 -0
  77. data/app/models/kms/user.rb +18 -0
  78. data/app/serializers/kms/settings_serializer.rb +5 -0
  79. data/app/serializers/kms/snippet_serializer.rb +5 -0
  80. data/app/services/kms/ability_service.rb +11 -0
  81. data/app/services/kms/externals_registry.rb +11 -0
  82. data/app/services/kms/form_customization_service.rb +14 -0
  83. data/app/services/kms/help_service.rb +13 -0
  84. data/app/services/kms/resource_service.rb +22 -0
  85. data/app/services/kms/search_service.rb +11 -0
  86. data/app/services/kms/settings_service.rb +13 -0
  87. data/app/uploaders/kms/asset_uploader.rb +61 -0
  88. data/app/views/devise/registrations/new.html.erb +21 -0
  89. data/app/views/devise/sessions/new.html.erb +17 -0
  90. data/app/views/devise/shared/_links.html.erb +25 -0
  91. data/app/views/layouts/kms/devise.html.erb +35 -0
  92. data/app/views/layouts/kms/kms.html.erb +139 -0
  93. data/config/initializers/bower_rails.rb +16 -0
  94. data/config/initializers/devise.rb +15 -0
  95. data/config/initializers/externals.rb +42 -0
  96. data/config/initializers/help.rb +1 -0
  97. data/config/initializers/liquor.rb +49 -0
  98. data/config/initializers/resources.rb +5 -0
  99. data/config/locales/devise.en.yml +59 -0
  100. data/config/locales/devise.ru.yml +63 -0
  101. data/config/locales/en.yml +172 -0
  102. data/config/locales/ru.yml +172 -0
  103. data/config/routes.rb +31 -0
  104. data/db/migrate/20141027065341_create_pages.rb +12 -0
  105. data/db/migrate/20141027083603_create_templates.rb +10 -0
  106. data/db/migrate/20141027083633_add_template_id_to_pages.rb +6 -0
  107. data/db/migrate/20141029145253_create_assets.rb +10 -0
  108. data/db/migrate/20141031125758_add_ancestry_to_pages.rb +6 -0
  109. data/db/migrate/20141031140308_devise_create_users.rb +42 -0
  110. data/db/migrate/20141119084306_add_fullpath_to_pages.rb +5 -0
  111. data/db/migrate/20141121112652_add_role_to_users.rb +5 -0
  112. data/db/migrate/20141127073902_add_templatable_fields_to_pages.rb +6 -0
  113. data/db/migrate/20141209132901_add_hidden_to_page.rb +5 -0
  114. data/db/migrate/20150209120632_add_position_to_kms_pages.rb +5 -0
  115. data/db/migrate/20160129100437_create_kms_snippets.rb +11 -0
  116. data/db/migrate/20160712094512_create_kms_settings.rb +9 -0
  117. data/lib/generators/kms/install/install_generator.rb +34 -0
  118. data/lib/generators/kms/install/templates/devise.rb +257 -0
  119. data/lib/generators/kms/install/templates/dragonfly.rb +35 -0
  120. data/lib/kms.rb +6 -0
  121. data/lib/kms/dependencies.rb +15 -0
  122. data/lib/kms/drops/page_drop.rb +24 -0
  123. data/lib/kms/drops/search_item_drop.rb +5 -0
  124. data/lib/kms/engine.rb +65 -0
  125. data/lib/kms/externals/bigdecimal.rb +5 -0
  126. data/lib/kms/externals/request.rb +4 -0
  127. data/lib/kms/functions/assets.rb +40 -0
  128. data/lib/kms/functions/currency.rb +21 -0
  129. data/lib/kms/search_item.rb +28 -0
  130. data/lib/kms/version.rb +3 -0
  131. data/lib/tasks/kms_tasks.rake +4 -0
  132. data/lib/tasks/precompile_hook.rake +42 -0
  133. data/spec/controllers/kms/snippets_controller_spec.rb +74 -0
  134. data/spec/factories/kms_settings.rb +6 -0
  135. data/spec/factories/snippets.rb +10 -0
  136. data/spec/factories/users.rb +7 -0
  137. data/spec/internal/Rakefile +2 -0
  138. data/spec/internal/config/database.yml +7 -0
  139. data/spec/internal/config/initializers/devise.rb +257 -0
  140. data/spec/internal/config/routes.rb +7 -0
  141. data/spec/internal/db/schema.rb +69 -0
  142. data/spec/internal/log/test.log +14998 -0
  143. data/spec/internal/public/favicon.ico +0 -0
  144. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/1XyAFYlYI0pK7WAgjR4PgXV6BgU6huJSviWmHetdCRs.cache +1 -0
  145. data/spec/models/kms/setting_spec.rb +7 -0
  146. data/spec/models/kms/snippet_spec.rb +14 -0
  147. data/spec/services/kms/help_service_spec.rb +8 -0
  148. data/spec/spec_helper.rb +27 -0
  149. data/spec/support/controller_macros.rb +11 -0
  150. data/spec/support/request_helpers.rb +7 -0
  151. metadata +521 -0
@@ -0,0 +1,5 @@
1
+ .row
2
+ .col-lg-12
3
+ form role="form" ng-submit="create()"
4
+ ng-include src="'pages/form.html'"
5
+ button.btn.btn-default type="submit" = I18n.t(:add_page)
@@ -0,0 +1,20 @@
1
+ .row
2
+ .col-lg-12
3
+ ul.nav.nav-tabs
4
+ - Kms::SettingsService.templates.each_with_index do |(engine_class, _),index|
5
+ li role="presentation" ng-class="{active: isActiveTab(#{index})}" ng-click="setActive(#{index})"
6
+ a href="##{engine_class.engine_name}" = engine_class.engine_name.humanize
7
+ div class="tab-content"
8
+ - if Kms::SettingsService.templates.present?
9
+ form role="form" ng-submit="update()"
10
+ - Kms::SettingsService.templates.each_with_index do |(engine_class, templates), index|
11
+ div role="tabpanel" class="tab-pane" ng-class="{active: isActiveTab(#{index})}" id=engine_class.engine_name
12
+ .widget
13
+ .widget-body.no-padding
14
+ - templates.each do |template|
15
+ .message
16
+ ng-include src="'#{template}'"
17
+ .btn-group
18
+ button.btn.btn-default type="submit" = I18n.t(:update_settings)
19
+ - else
20
+ = I18n.t(:no_settings)
@@ -0,0 +1,5 @@
1
+ .row
2
+ .col-lg-12
3
+ form role="form" ng-submit="update()"
4
+ ng-include src="'snippets/form.html'"
5
+ button.btn.btn-default type="submit" = I18n.t(:update_snippet)
@@ -0,0 +1,10 @@
1
+ .form-group
2
+ label for="name" = Kms::Snippet.human_attribute_name(:name)
3
+ input#name.form-control type="text" ng-model="snippet.name"
4
+ .form-group
5
+ label for="slug" = Kms::Snippet.human_attribute_name(:slug)
6
+ input#slug.form-control type="text" ng-model="snippet.slug"
7
+ .form-group
8
+ label for="content" = Kms::Snippet.human_attribute_name(:content)
9
+ textarea#content.form-control ng-model="snippet.content" rows="15" ui-codemirror="editorOptions"
10
+ small = I18n.t(:toggle_fullscreen_mode_instruction)
@@ -0,0 +1,22 @@
1
+ .row
2
+ .col-lg-12
3
+ .widget
4
+ .widget-header
5
+ i.fa.fa-bookmark
6
+ = Kms::Snippet.model_name.human(count: 1.1)
7
+ /a.pull-right href="#" Manage
8
+ a.btn.btn-sm.btn-primary.pull-right ui-sref="snippets.new" ng-show="currentUser.admin"
9
+ = I18n.t("add_snippet")
10
+ .widget-body.no-padding
11
+ .table-responsive
12
+ table.table
13
+ tbody
14
+ tr ng-repeat="snippet in snippets"
15
+ td style="width: 80%"
16
+ | {{ snippet.name }}
17
+ td
18
+ .btn-group.pull-right
19
+ a.btn.btn-sm.btn-info ui-sref="snippets.edit({id: snippet.id})" ng-show="currentUser.admin"
20
+ i.fa.fa-pencil
21
+ a.btn.btn-sm.btn-danger ng-click="destroy(snippet)" ng-show="currentUser.admin"
22
+ i.fa.fa-times
@@ -0,0 +1,5 @@
1
+ .row
2
+ .col-lg-12
3
+ form role="form" ng-submit="create()"
4
+ ng-include src="'snippets/form.html'"
5
+ button.btn.btn-default type="submit" = I18n.t(:add_snippet)
@@ -0,0 +1,7 @@
1
+ .row
2
+ .col-lg-12
3
+ form role="form"
4
+ ng-include src="'templates/form.html'"
5
+ .btn-group
6
+ button.btn.btn-default type="submit" data-redirect="true" ng-click="update($event)" = I18n.t(:update_template)
7
+ button.btn.btn-default type="submit" ng-click="update($event)" = I18n.t(:update_template_and_continue)
@@ -0,0 +1,7 @@
1
+ .form-group
2
+ label for="name" = Kms::Template.human_attribute_name(:name)
3
+ input#name.form-control type="text" ng-model="template.name"
4
+ .form-group
5
+ label for="content" = Kms::Template.human_attribute_name(:content)
6
+ textarea#content.form-control ng-model="template.content" rows="15" ui-codemirror="editorOptions"
7
+ small = I18n.t(:toggle_fullscreen_mode_instruction)
@@ -0,0 +1,22 @@
1
+ .row
2
+ .col-lg-12
3
+ .widget
4
+ .widget-header
5
+ i.fa.fa-support
6
+ = Kms::Template.model_name.human(count: 1.1)
7
+ /a.pull-right href="#" Manage
8
+ a.btn.btn-sm.btn-primary.pull-right ui-sref="templates.new" ng-show="currentUser.admin"
9
+ = I18n.t("add_template")
10
+ .widget-body.no-padding
11
+ .table-responsive
12
+ table.table
13
+ tbody
14
+ tr ng-repeat="template in templates"
15
+ td style="width: 80%"
16
+ | {{ template.name }}
17
+ td
18
+ .btn-group.pull-right
19
+ a.btn.btn-sm.btn-info ui-sref="templates.edit({id: template.id})" ng-show="currentUser.admin"
20
+ i.fa.fa-pencil
21
+ a.btn.btn-sm.btn-danger ng-click="destroy(template)" ng-show="currentUser.admin"
22
+ i.fa.fa-times
@@ -0,0 +1,5 @@
1
+ .row
2
+ .col-lg-12
3
+ form role="form" ng-submit="create()"
4
+ ng-include src="'templates/form.html'"
5
+ button.btn.btn-default type="submit" = I18n.t(:add_template)
@@ -0,0 +1,14 @@
1
+ .form-group
2
+ label for="email" = Kms::User.human_attribute_name(:email)
3
+ input#email.form-control type="email" ng-model="user.email" required=""
4
+ .form-group
5
+ label for="password" = Kms::User.human_attribute_name(:password)
6
+ input#password.form-control type="password" ng-model="user.password" required=""
7
+ .form-group
8
+ label for="password_confirmation" = Kms::User.human_attribute_name(:password_confirmation)
9
+ input#password_confirmation.form-control type="password" ng-model="user.password_confirmation" required=""
10
+ .form-group
11
+ label for="role" = Kms::User.human_attribute_name(:role)
12
+ select#role.form-control ng-model="user.role" required=""
13
+ - Kms::User::ROLES.each do |role|
14
+ option value=role.to_s = I18n.t("roles.#{role.to_s}")
@@ -0,0 +1,21 @@
1
+ .row
2
+ .col-lg-12
3
+ .widget
4
+ .widget-header
5
+ i.fa.fa-users
6
+ = Kms::User.model_name.human(count: 1.1)
7
+ /a.pull-right href="#" Manage
8
+ a.btn.btn-sm.btn-primary.pull-right ui-sref="users.new"
9
+ = I18n.t("add_user")
10
+ .widget-body.no-padding
11
+ .table-responsive
12
+ table.table
13
+ tbody
14
+ tr ng-repeat="user in users"
15
+ td style="width: 80%"
16
+ | {{ user.email }}
17
+ td
18
+ | {{ user.localized_role }}
19
+ td
20
+ a.btn.btn-sm.btn-danger ng-click="destroy(user)"
21
+ i.fa.fa-times
@@ -0,0 +1,5 @@
1
+ .row
2
+ .col-lg-12
3
+ form role="form" ng-submit="create()"
4
+ ng-include src="'users/form.html'"
5
+ button.btn.btn-default type="submit" = I18n.t(:add_user)
@@ -0,0 +1,57 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require bootstrap/dist/css/bootstrap
14
+ *= require font-awesome/less/font-awesome
15
+ *= require angular-ui-tree/dist/angular-ui-tree.min
16
+ *= require codemirror/lib/codemirror
17
+ *= require codemirror/addon/display/fullscreen
18
+ *= require angular-ui-select/dist/select
19
+ *= require angular-toggle-switch/angular-toggle-switch
20
+ *= require angular-toggle-switch/angular-toggle-switch-bootstrap
21
+ *= require angular-loading-bar/build/loading-bar
22
+ *= require alertify/themes/alertify.core
23
+ *= require alertify/themes/alertify.bootstrap
24
+ *= require angular-xeditable/dist/css/xeditable
25
+ *= require ng-sortable/dist/ng-sortable
26
+ *= require kms/responsive_dashboard
27
+ *= require kms/custom
28
+ *= require application
29
+ *= require_self
30
+ */
31
+ .angular-ui-tree-handle {
32
+ margin: 20px 10px;
33
+ height: 50px;
34
+ background-color: #f6f6f6;
35
+ border: 1px solid #dae2ea;
36
+ padding: 10px;
37
+ border-radius: 10px;
38
+ }
39
+
40
+ .angular-ui-tree-handle:hover {
41
+ background: #f4f6f7;
42
+ border-color: #dce2e8;
43
+ }
44
+
45
+ .angular-ui-tree-placeholder {
46
+ background: #f0f9ff;
47
+ border: 2px dashed #bed2db;
48
+ -webkit-box-sizing: border-box;
49
+ -moz-box-sizing: border-box;
50
+ box-sizing: border-box;
51
+ }
52
+
53
+
54
+ .group-title {
55
+ background-color: #687074 !important;
56
+ color: #FFF !important;
57
+ }
@@ -0,0 +1,67 @@
1
+ table td {
2
+ vertical-align: middle !important;
3
+ }
4
+ .wrapper {
5
+ margin-top: 80px;
6
+ margin-bottom: 80px;
7
+ }
8
+
9
+ .form-signin {
10
+ max-width: 380px;
11
+ padding: 15px 35px 45px;
12
+ margin: 0 auto;
13
+ background-color: #fff;
14
+ border: 1px solid rgba(0,0,0,0.1);
15
+
16
+ .form-signin-heading,
17
+ .checkbox {
18
+ margin-bottom: 30px;
19
+ }
20
+
21
+ .checkbox {
22
+ font-weight: normal;
23
+ }
24
+
25
+ .form-control {
26
+ position: relative;
27
+ font-size: 16px;
28
+ height: auto;
29
+ padding: 10px;
30
+ box-sizing: border-box;
31
+ -webkit-box-sizing: border-box;
32
+ -moz-box-sizing: border-box;
33
+
34
+
35
+ &:focus {
36
+ z-index: 2;
37
+ }
38
+ }
39
+
40
+ input[type="email"] {
41
+ margin-bottom: -1px;
42
+ border-bottom-left-radius: 0;
43
+ border-bottom-right-radius: 0;
44
+ }
45
+
46
+ input[type="password"] {
47
+ margin-bottom: 20px;
48
+ border-top-left-radius: 0;
49
+ border-top-right-radius: 0;
50
+ }
51
+ }
52
+ .not-published {
53
+ font-style: italic;
54
+ opacity: 0.8;
55
+ }
56
+ .as-sortable-item, .as-sortable-placeholder {
57
+ display: table-row;
58
+ }
59
+ #sidebar-wrapper {
60
+ z-index: 0;
61
+ }
62
+ .alertify-logs {
63
+ width: 350px;
64
+ }
65
+ .CodeMirror {
66
+ height: 500px;
67
+ }
@@ -0,0 +1,9 @@
1
+ @import "Responsive-Dashboard/src/less/dashboard/variables";
2
+ @import "Responsive-Dashboard/src/less/dashboard/mixins";
3
+ @import "Responsive-Dashboard/src/less/dashboard/main";
4
+ @import "Responsive-Dashboard/src/less/dashboard/loading";
5
+ @import "Responsive-Dashboard/src/less/dashboard/content";
6
+ @import "Responsive-Dashboard/src/less/dashboard/header";
7
+ @import "Responsive-Dashboard/src/less/dashboard/sidebar";
8
+ @import "Responsive-Dashboard/src/less/dashboard/widgets";
9
+ @import "Responsive-Dashboard/src/less/dashboard/hamburg";
@@ -0,0 +1,24 @@
1
+ module Kms
2
+ class ApplicationController < ActionController::Base
3
+ before_action :authenticate_kms_user!
4
+ # Prevent CSRF attacks by raising an exception.
5
+ # For APIs, you may want to use :null_session instead.
6
+ protect_from_forgery with: :exception
7
+
8
+ after_filter :set_csrf_cookie_for_ng
9
+
10
+ def set_csrf_cookie_for_ng
11
+ cookies['XSRF-TOKEN'] = form_authenticity_token if protect_against_forgery?
12
+ end
13
+
14
+ protected
15
+
16
+ def verified_request?
17
+ super || cookies['XSRF-TOKEN'] == request.headers['X-XSRF-TOKEN']
18
+ end
19
+
20
+ def current_ability
21
+ @current_ability ||= Ability.new(current_kms_user)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,58 @@
1
+ module Kms
2
+ class AssetsController < ApplicationController
3
+ load_and_authorize_resource
4
+ skip_before_action :verify_authenticity_token, only: :ckeditor
5
+
6
+ def index
7
+ render json: Asset.all.to_json(methods: [:filename, :url])
8
+ end
9
+
10
+ def create
11
+ @asset = Asset.new(asset_params)
12
+ if @asset.save
13
+ render json: {success: true, files: [@asset]}.to_json
14
+ else
15
+ render text: '', status: :unprocessable_entity
16
+ end
17
+ end
18
+
19
+ def ckeditor
20
+ @asset = Asset.new(file: params[:upload])
21
+ if @asset.save
22
+ render text: %Q"<script type='text/javascript'>
23
+ window.parent.CKEDITOR.tools.callFunction(#{params[:CKEditorFuncNum]}, '#{@asset.file.url}');
24
+ </script>"
25
+ else
26
+ render text: %Q"<script type='text/javascript'>
27
+ window.parent.CKEDITOR.tools.callFunction(#{params[:CKEditorFuncNum]}, null, '#{@asset.errors.full_messages.first}');
28
+ </script>"
29
+ end
30
+ end
31
+
32
+ def update
33
+ @asset = Asset.find(params[:id])
34
+ asset_params.merge!(text: params[:text], performing_plain_text: params[:performing_plain_text]) if params[:text]
35
+ @asset.update_attributes(asset_params)
36
+ render json: @asset.to_json
37
+ end
38
+
39
+ def show
40
+ @asset = Asset.find(params[:id])
41
+ attrs = {}
42
+ attrs.merge!(methods: [:text, :performing_plain_text]) if @asset.stylesheet_or_javascript?
43
+ render json: @asset.to_json(attrs)
44
+ end
45
+
46
+ def destroy
47
+ @asset = Asset.find(params[:id])
48
+ @asset.destroy
49
+ render json: @asset.to_json
50
+ end
51
+
52
+ protected
53
+
54
+ def asset_params
55
+ params.require(:asset).permit!
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,8 @@
1
+ module Kms
2
+ class KmsController < ApplicationController
3
+
4
+ def index
5
+ render "layouts/kms/kms"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,67 @@
1
+ module Kms
2
+ class PagesController < ApplicationController
3
+ load_and_authorize_resource
4
+ wrap_parameters :page, include: [:title, :slug, :content, :published, :template_id, :templatable,:templatable_type,:position,:hidden, :parent_id]
5
+
6
+ def index
7
+ #render json: Page.order("created_at asc").to_json(methods: :parent_id, except: :ancestry)
8
+ render json: Page.arrange_serializable(:order => :position).to_json
9
+ end
10
+
11
+ def create
12
+ @page = Page.new(page_params)
13
+ if @page.save
14
+ render json: @page.to_json
15
+ else
16
+ render json: @page.to_json(except: :ancestry, methods: :errors), status: :unprocessable_entity
17
+ end
18
+ end
19
+
20
+ def update
21
+ @page = Page.find(params[:id])
22
+ if @page.update_attributes(page_params)
23
+ render json: @page.to_json
24
+ else
25
+ render json: @page.to_json(except: :ancestry, methods: :errors), status: :unprocessable_entity
26
+ end
27
+ end
28
+
29
+ def show
30
+ @page = Page.find(params[:id])
31
+ render json: @page.to_json(methods: :parent_id, except: :ancestry)
32
+ end
33
+
34
+ def destroy
35
+ @page = Page.find(params[:id])
36
+ @page.destroy
37
+ render json: @page.to_json
38
+ end
39
+
40
+ def sorting
41
+ params["_json"].each_with_index do |page, index|
42
+ p = Page.find_by_id(page["id"])
43
+ p.update_attribute(:parent_id, nil)
44
+ p.update_attribute(:position, index)
45
+ sort(page["id"], page["children"]) if page["children"].present?
46
+ end
47
+ render json: Page.arrange_serializable.to_json
48
+ end
49
+
50
+ protected
51
+
52
+ def sort(id, pages)
53
+ pages.each_with_index do |page, index|
54
+ p = Page.find_by_id(page["id"])
55
+ p.update_attribute(:parent_id, id)
56
+ p.update_attribute(:position, index)
57
+ if page["children"].present?
58
+ sort(page["id"], page["children"])
59
+ end
60
+ end
61
+ end
62
+
63
+ def page_params
64
+ params.require(:page).permit!
65
+ end
66
+ end
67
+ end