cms9 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +192 -0
  4. data/Rakefile +37 -0
  5. data/app/assets/config/cms9_manifest.js +2 -0
  6. data/app/assets/images/cms9/cms9_logo.png +0 -0
  7. data/app/assets/images/cms9/cms9_logo_readme.png +0 -0
  8. data/app/assets/images/cms9/favicon-128.png +0 -0
  9. data/app/assets/images/cms9/favicon-16.png +0 -0
  10. data/app/assets/images/cms9/favicon-32.png +0 -0
  11. data/app/assets/images/cms9/favicon-64.png +0 -0
  12. data/app/assets/images/cms9/iCheck/flat/blue.png +0 -0
  13. data/app/assets/images/cms9/iCheck/flat/blue@2x.png +0 -0
  14. data/app/assets/javascripts/cms9/admin_lte.js +763 -0
  15. data/app/assets/javascripts/cms9/application.js +18 -0
  16. data/app/assets/javascripts/cms9/cable.js +13 -0
  17. data/app/assets/javascripts/cms9/multiple_values_selection.js +70 -0
  18. data/app/assets/javascripts/cms9/post_fields.js +5 -0
  19. data/app/assets/javascripts/cms9/posts.js +37 -0
  20. data/app/assets/stylesheets/cms9/admin_lte.scss +4932 -0
  21. data/app/assets/stylesheets/cms9/admin_lte_skins.css +1770 -0
  22. data/app/assets/stylesheets/cms9/application.scss +7 -0
  23. data/app/assets/stylesheets/cms9/fields.scss +3 -0
  24. data/app/assets/stylesheets/cms9/post_definitions.scss +28 -0
  25. data/app/assets/stylesheets/cms9/posts.scss +3 -0
  26. data/app/assets/stylesheets/cms9/welcome.scss +20 -0
  27. data/app/controllers/cms9/application_controller.rb +34 -0
  28. data/app/controllers/cms9/fields_controller.rb +4 -0
  29. data/app/controllers/cms9/post_definitions_controller.rb +85 -0
  30. data/app/controllers/cms9/post_fields_controller.rb +108 -0
  31. data/app/controllers/cms9/posts_controller.rb +76 -0
  32. data/app/controllers/cms9/welcome_controller.rb +8 -0
  33. data/app/helpers/cms9/application_helper.rb +58 -0
  34. data/app/helpers/cms9/fields_helper.rb +4 -0
  35. data/app/helpers/cms9/post_definitions_helper.rb +4 -0
  36. data/app/helpers/cms9/post_fields_helper.rb +4 -0
  37. data/app/helpers/cms9/posts_helper.rb +4 -0
  38. data/app/helpers/cms9/welcome_helper.rb +4 -0
  39. data/app/jobs/cms9/application_job.rb +4 -0
  40. data/app/mailers/cms9/application_mailer.rb +6 -0
  41. data/app/models/ckeditor/asset.rb +9 -0
  42. data/app/models/ckeditor/attachment_file.rb +9 -0
  43. data/app/models/ckeditor/picture.rb +14 -0
  44. data/app/models/cms9/application_record.rb +5 -0
  45. data/app/models/cms9/event.rb +7 -0
  46. data/app/models/cms9/field.rb +20 -0
  47. data/app/models/cms9/post.rb +16 -0
  48. data/app/models/cms9/post_definition.rb +25 -0
  49. data/app/models/cms9/post_field.rb +23 -0
  50. data/app/views/cms9/fields/index.html.erb +0 -0
  51. data/app/views/cms9/post_definitions/edit.html.erb +81 -0
  52. data/app/views/cms9/post_definitions/index.html.erb +48 -0
  53. data/app/views/cms9/post_definitions/new.html.erb +41 -0
  54. data/app/views/cms9/post_fields/_field_form.html.erb +46 -0
  55. data/app/views/cms9/post_fields/_image_sizer.html.erb +2 -0
  56. data/app/views/cms9/post_fields/_select.html.erb +24 -0
  57. data/app/views/cms9/post_fields/_select_blank.html.erb +10 -0
  58. data/app/views/cms9/post_fields/edit.html.erb +14 -0
  59. data/app/views/cms9/post_fields/new.html.erb +14 -0
  60. data/app/views/cms9/posts/_post_form.html.erb +13 -0
  61. data/app/views/cms9/posts/edit.html.erb +14 -0
  62. data/app/views/cms9/posts/index.html.erb +42 -0
  63. data/app/views/cms9/posts/inputs/_date.html.erb +2 -0
  64. data/app/views/cms9/posts/inputs/_date_time.html.erb +2 -0
  65. data/app/views/cms9/posts/inputs/_image.html.erb +19 -0
  66. data/app/views/cms9/posts/inputs/_number.html.erb +2 -0
  67. data/app/views/cms9/posts/inputs/_select_multiple.html.erb +7 -0
  68. data/app/views/cms9/posts/inputs/_select_single.html.erb +2 -0
  69. data/app/views/cms9/posts/inputs/_text.html.erb +2 -0
  70. data/app/views/cms9/posts/inputs/_text_area.html.erb +2 -0
  71. data/app/views/cms9/posts/inputs/_time.html.erb +2 -0
  72. data/app/views/cms9/posts/new.html.erb +14 -0
  73. data/app/views/cms9/welcome/_post.html.erb +46 -0
  74. data/app/views/cms9/welcome/_post_definition.html.erb +36 -0
  75. data/app/views/cms9/welcome/index.html.erb +57 -0
  76. data/app/views/layouts/cms9/application.html.erb +100 -0
  77. data/config/initializers/assets.rb +4 -0
  78. data/config/initializers/ckeditor.rb +59 -0
  79. data/config/initializers/ckeditor_dragonfly.rb +19 -0
  80. data/config/initializers/ckeditor_init.rb +3 -0
  81. data/config/initializers/dragonfly.rb +26 -0
  82. data/config/routes.rb +11 -0
  83. data/db/migrate/cms9_create.rb +73 -0
  84. data/db/schema.rb +49 -0
  85. data/db/seeds.rb +7 -0
  86. data/lib/cms9.rb +24 -0
  87. data/lib/cms9/engine.rb +24 -0
  88. data/lib/cms9/version.rb +3 -0
  89. data/lib/events/cms9_events.rb +50 -0
  90. data/lib/generators/cms9/install/install_generator.rb +81 -0
  91. data/lib/generators/cms9/install/templates/ckeditor_config.js +14 -0
  92. data/lib/generators/cms9/install/templates/cms9_configurator.rb +4 -0
  93. data/lib/sdk/cms9.rb +138 -0
  94. data/lib/tasks/cms9_tasks.rake +4 -0
  95. metadata +423 -0
@@ -0,0 +1,7 @@
1
+ @import "bootstrap-sprockets";
2
+ @import "bootstrap";
3
+ @import "font-awesome";
4
+ @import "welcome";
5
+ @import "post_definitions";
6
+ @import "admin_lte";
7
+ @import "admin_lte_skins"
@@ -0,0 +1,3 @@
1
+ // Place all the styles related to the Fields controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,28 @@
1
+ .required-field-icons {
2
+ .fa-check {
3
+ color: green;
4
+ }
5
+ .fa-times {
6
+ color: red;
7
+ }
8
+ }
9
+
10
+ #upload-image-field {
11
+ margin-top: 10px;
12
+ margin-bottom: 10px;
13
+ }
14
+
15
+ .post-image {
16
+ display: block;
17
+ border-radius: 3px;
18
+ max-width: 250px;
19
+ margin-top: 20px;
20
+ margin-bottom: 20px;
21
+ &.loaded {
22
+ border: 1px solid #ccc;
23
+ }
24
+ }
25
+
26
+ .remove-picture-block {
27
+ color: red;
28
+ }
@@ -0,0 +1,3 @@
1
+ // Place all the styles related to the Posts controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,20 @@
1
+ // Place all the styles related to the Welcome controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Sass (SCSS) here: http://sass-lang.com/
4
+
5
+ .fr-toolbar {
6
+ border-top: 5px solid #EB5E28 !important;
7
+ }
8
+
9
+ .custom-alert {
10
+ position: fixed;
11
+ bottom: 0;
12
+ right: 10px;
13
+ z-index: 999;
14
+ }
15
+
16
+ .user-block-name {
17
+ color: #999;
18
+ padding: 10px;
19
+ font-size: 12px;
20
+ }
@@ -0,0 +1,34 @@
1
+ module Cms9
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ helper_method :current_user, :user_logout
5
+
6
+ before_action :authorize
7
+
8
+ def current_user
9
+ current_user_ident = Cms9.configuration.current_user || :current_user
10
+ parent = ::ApplicationController.new
11
+ parent.request = request
12
+
13
+ if parent.respond_to?(current_user_ident)
14
+ parent.send(current_user_ident)
15
+ end
16
+ end
17
+
18
+ def user_logout
19
+ logout_ident = Cms9.configuration.destroy_user_session || :destroy_user_session
20
+ parent = ::ApplicationController.new
21
+ parent.request = request
22
+
23
+ if parent.respond_to?(logout_ident)
24
+ parent.send(logout_ident)
25
+ end
26
+ end
27
+
28
+ def authorize
29
+ unless current_user.try(:cms9_admin?)
30
+ raise 'Implement cms9_admin? method in current_user context. See https://github.com/klikaba/cms9'
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,4 @@
1
+ module Cms9
2
+ class FieldsController < Cms9::ApplicationController
3
+ end
4
+ end
@@ -0,0 +1,85 @@
1
+ module Cms9
2
+ class PostDefinitionsController < Cms9::ApplicationController
3
+ def index
4
+ @posts = PostDefinition.order('created_at desc').page(params[:page]).per(20)
5
+ end
6
+
7
+ def new
8
+ @post = PostDefinition.new
9
+ end
10
+
11
+ def edit
12
+ @post = PostDefinition.find(params[:id])
13
+ end
14
+
15
+ def create
16
+ @post = PostDefinition.new(post_definition_params)
17
+
18
+ @post.user_id = current_user.id
19
+
20
+ if PostDefinition.where(name: @post[:name]).blank?
21
+
22
+ if @post.save
23
+ @field = PostField.new({
24
+ 'name': 'Title',
25
+ 'field_type': 'text',
26
+ 'required': true,
27
+ 'post_definition_id': @post.id,
28
+ 'user_id': current_user.id
29
+ })
30
+ if @field.save
31
+ Cms9Events.new.create_event('post_definition', @post.id, params[:action], current_user, nil)
32
+
33
+ redirect_to edit_post_definition_path(@post.id)
34
+ end
35
+ else
36
+ render :new
37
+ end
38
+
39
+ else
40
+ @post.errors.add(:name, " Post Type already exist")
41
+ render :new
42
+ end
43
+
44
+ end
45
+
46
+ def update
47
+ @post = PostDefinition.find(params[:id])
48
+ @post.user_id = current_user.id
49
+
50
+ field = PostDefinition.where(name: params[:post_definition][:name].downcase)
51
+
52
+ if field.blank? || @post.name == params[:post_definition][:name]
53
+
54
+ if @post.update(post_definition_params)
55
+ Cms9Events.new.create_event('post_definition', @post.id, params[:action], current_user, nil)
56
+
57
+ redirect_to edit_post_definition_path(@post.id)
58
+ else
59
+ render :edit
60
+ end
61
+
62
+ else
63
+ @post.errors.add(:name, " Post Type already exist")
64
+ render :edit
65
+ end
66
+ end
67
+
68
+ def destroy
69
+ @post_def = PostDefinition.find(params[:id])
70
+ @post_def.destroy
71
+
72
+ Cms9Events.new.create_event('post_definition', @post_def.id, params[:action], current_user, @post_def.name)
73
+
74
+ @posts = Post.where(post_definition_id: params[:id])
75
+ @posts.destroy_all
76
+
77
+ redirect_to post_definitions_path
78
+ end
79
+
80
+ private
81
+ def post_definition_params
82
+ params.require(:post_definition).permit(:name)
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,108 @@
1
+ module Cms9
2
+ class PostFieldsController < Cms9::ApplicationController
3
+ def new
4
+ @field = PostField.new
5
+ @field.post_definition_id = params[:post_definition_id]
6
+ end
7
+
8
+ def create
9
+ @field = PostField.new(post_field_params)
10
+ @field.user_id = current_user.id
11
+
12
+ if PostField.where(name: @field[:name], post_definition_id: @field[:post_definition_id]).blank?
13
+ if @field[:field_type] == 'select_single' || @field[:field_type] == 'select_multiple'
14
+ @field.metadata = ''
15
+ values = params[:multi_values]
16
+
17
+ values.each_with_index do |value, index|
18
+ if value != ''
19
+ if index == 0
20
+ @field.metadata = value
21
+ elsif
22
+ @field.metadata = @field.metadata + ',' + value
23
+ end
24
+ end
25
+ end
26
+ elsif @field[:field_type] != 'select_single' && @field[:field_type] != 'select_multiple' && @field[:field_type] != 'image'
27
+ @field.metadata = nil
28
+ end
29
+
30
+ if @field.save
31
+ Cms9Events.new.create_event('post_definition', @field[:post_definition_id], 'update', current_user, nil)
32
+ redirect_to edit_post_definition_path(id: @field.post_definition_id)
33
+ else
34
+ render :new
35
+ end
36
+ else
37
+ @field.errors.add(:name, "of field already exist")
38
+ render :new
39
+ end
40
+ end
41
+
42
+ def edit
43
+ @field = PostField.find(params[:id])
44
+ @post_name = params[:post]
45
+
46
+ if PostField.all_types.index(params[:type]) != nil
47
+ @field.field_type = params[:type]
48
+ end
49
+
50
+ if params[:field_name] != nil
51
+ @field.name = params[:field_name]
52
+ end
53
+ end
54
+
55
+ def update
56
+ @field = PostField.find(params[:id])
57
+ @field.user_id = current_user.id
58
+
59
+ field = PostField.where(name: post_field_params[:name], post_definition_id: @field[:post_definition_id])
60
+
61
+ if field.blank? || field.pluck(:id)[0].to_s == params[:id]
62
+ if @field[:field_type] == 'select_single' || @field[:field_type] == 'select_multiple'
63
+ @field.metadata = ''
64
+ values = params[:multi_values]
65
+
66
+ values.each_with_index do |value, index|
67
+ if value != ''
68
+ if index == 0
69
+ @field.metadata = value
70
+ elsif
71
+ @field.metadata = @field.metadata + ',' + value
72
+ end
73
+ end
74
+ end
75
+
76
+ params[:post_field][:metadata] = @field.metadata
77
+
78
+ elsif @field[:field_type] != 'select_single' && @field[:field_type] != 'select_multiple' && @field[:field_type] != 'image'
79
+ @field.metadata = nil
80
+ end
81
+
82
+ if @field.update(post_field_params)
83
+ Cms9Events.new.create_event('post_definition', @field[:post_definition_id], 'update', current_user, nil)
84
+ redirect_to edit_post_definition_path(id: @field.post_definition_id)
85
+ else
86
+ render :edit
87
+ end
88
+ else
89
+ @field.errors.add(:name, "of field already exist")
90
+ render :edit
91
+ end
92
+ end
93
+
94
+ def destroy
95
+ @field = PostField.find(params[:id])
96
+ @field.destroy
97
+
98
+ Cms9Events.new.create_event('post_definition', @field[:post_definition_id], 'update', current_user, nil)
99
+
100
+ redirect_to request.referrer
101
+ end
102
+
103
+ private
104
+ def post_field_params
105
+ params.require(:post_field).permit(:name, :field_type, :post_definition_id, :required, :metadata)
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,76 @@
1
+ module Cms9
2
+ class PostsController < Cms9::ApplicationController
3
+ def index
4
+ @post_definition = Cms9::PostDefinition.find(params[:post_definition_id])
5
+ @posts = Post.where(post_definition: @post_definition)
6
+ .order('created_at desc')
7
+ .page(params[:page])
8
+ .per(20)
9
+ end
10
+
11
+ def new
12
+ @post = Post.new
13
+ @post.post_definition_id = params[:post_definition_id]
14
+
15
+ @post.post_definition.post_fields.each do |post_field|
16
+ @post.fields.build(post_field: post_field)
17
+ end
18
+ end
19
+
20
+ def create
21
+ @post = Post.new(post_params)
22
+
23
+ @post.user_id = current_user.id
24
+
25
+ if @post.save
26
+ Cms9Events.new.create_event('post', @post.id, params[:action], current_user, nil)
27
+ redirect_to posts_path(post_definition_id: @post.post_definition.id)
28
+ else
29
+ render :new
30
+ end
31
+ end
32
+
33
+ def edit
34
+ @post = Post.find(params[:id])
35
+
36
+ @post.post_definition.post_fields.each do |post_field|
37
+ if @post.fields.where(post_field_id: post_field[:id]).blank?
38
+ @post.fields.build(post_field: post_field)
39
+ end
40
+ end
41
+ end
42
+
43
+ def update
44
+ @post = Post.find(params[:id])
45
+
46
+ @post.user_id = current_user.id
47
+
48
+ if @post.update(post_params)
49
+ Cms9Events.new.create_event('post', @post.id, params[:action], current_user, nil)
50
+ redirect_to posts_path(post_definition_id: @post.post_definition.id)
51
+ else
52
+ render :edit
53
+ end
54
+ end
55
+
56
+ def destroy
57
+ @post = Post.find(params[:id])
58
+ post_definition_id = @post.post_definition.id
59
+
60
+ post_name = Field.where(post_field_id: @post.post_definition.post_fields[0].id, post_id: @post.id)[0]
61
+ Cms9Events.new.create_event('post', @post.id, params[:action], current_user, post_name)
62
+
63
+ @post.destroy
64
+
65
+ redirect_to posts_path(post_definition_id: post_definition_id)
66
+ end
67
+
68
+ private
69
+ def post_params
70
+ params.require(:post).permit(:post_definition_id, fields_attributes:
71
+ [:id, :post_id, :post_field_id, :value, { :value => [] },
72
+ :image, :image_uid, :image_name, :remove_image, :image_custom_size])
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,8 @@
1
+ module Cms9
2
+ class WelcomeController < Cms9::ApplicationController
3
+ def index
4
+ limit = params[:limit] ? params[:limit] : 10
5
+ @events = Cms9Events.new.timeline_events(limit)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,58 @@
1
+ module Cms9
2
+ module ApplicationHelper
3
+
4
+ def cms9_field(field, options={})
5
+ if field.present?
6
+ case field.post_field.field_type
7
+ when 'text', 'number', 'select_single', 'date', 'time', 'date_time'
8
+ return field.value.blank? ? '' : cms9_text_tag(field)
9
+ when 'text_area'
10
+ return field.value.blank? ? '' : cms9_text_area_tag(field)
11
+ when 'select_multiple'
12
+ return field.value.blank? ? '' : cms9_multiple_choice(field)
13
+ when 'image'
14
+ return field.blank? ? '' : cms9_image_tag(field, options)
15
+ else
16
+ return '<unsupported type>'
17
+ end
18
+ end
19
+ end
20
+
21
+ def cms9_text_tag(model)
22
+ return model.to_s
23
+ end
24
+
25
+ def cms9_text_area_tag(model)
26
+ return raw(model.to_s)
27
+ end
28
+
29
+ def cms9_multiple_choice(model)
30
+ @m = model.value.to_s.split("\' ")[0]
31
+ return "#{@m}"
32
+ end
33
+
34
+ def cms9_image_tag(model, options={})
35
+ return image_tag(model.image.url, options)
36
+ end
37
+
38
+ def cms9_number_tag(model)
39
+ return model.to_s
40
+ end
41
+
42
+ def cms9_select_single_tag(model)
43
+ return model.to_s
44
+ end
45
+
46
+ def cms9_date_tag(model)
47
+ return model.to_s
48
+ end
49
+
50
+ def cms9_time_tag(model)
51
+ return model.to_s
52
+ end
53
+
54
+ def cms9_date_time_tag(model)
55
+ return model.to_s
56
+ end
57
+ end
58
+ end