drg_cms 0.5.52.12 → 0.6.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +5 -5
  2. data/app/assets/javascripts/drg_cms/drg_cms.js +395 -120
  3. data/app/assets/javascripts/drg_cms/jstree.min.js +6 -6
  4. data/app/assets/javascripts/drg_cms_application.js +1 -1
  5. data/app/assets/stylesheets/drg_cms/drg_cms.css +476 -215
  6. data/app/assets/stylesheets/drg_cms/jstree.css +6 -12
  7. data/app/assets/stylesheets/drg_cms/select-multiple.css +19 -13
  8. data/app/assets/stylesheets/drg_cms_cms.css +1 -1
  9. data/app/controllers/cmsedit_controller.rb +474 -233
  10. data/app/controllers/dc_application_controller.rb +264 -41
  11. data/app/controllers/dc_common_controller.rb +75 -63
  12. data/app/{controllers → controls}/browse_models_control.rb +0 -0
  13. data/app/{controllers → controls}/dc_page_control.rb +24 -8
  14. data/app/controls/dc_poll_result_control.rb +88 -0
  15. data/app/controls/dc_report.rb +227 -0
  16. data/app/{controllers → controls}/design_element_settings_control.rb +0 -0
  17. data/app/forms/all_options.yml +70 -12
  18. data/app/forms/cms_menu.yml +26 -17
  19. data/app/forms/dc_ad.yml +11 -22
  20. data/app/forms/dc_big_table.yml +1 -0
  21. data/app/forms/dc_big_table_value.yml +1 -0
  22. data/app/forms/dc_design.yml +19 -16
  23. data/app/forms/dc_filter.yml +3 -6
  24. data/app/forms/dc_gallery.yml +53 -0
  25. data/app/forms/dc_json_ld.yml +59 -0
  26. data/app/forms/dc_key_value.yml +32 -0
  27. data/app/forms/dc_link.yml +16 -10
  28. data/app/forms/dc_menu_item.yml +6 -0
  29. data/app/forms/dc_page.yml +2 -7
  30. data/app/forms/dc_poll.yml +16 -9
  31. data/app/forms/dc_poll_item.yml +2 -1
  32. data/app/forms/dc_poll_result.yml +83 -0
  33. data/app/forms/dc_poll_result_export.yml +35 -0
  34. data/app/forms/dc_removed_url.yml +42 -0
  35. data/app/forms/dc_seo.yml +33 -0
  36. data/app/forms/dc_site.yml +2 -6
  37. data/app/forms/json_ld_schema.yml +168 -0
  38. data/app/helpers/cms_common_helper.rb +311 -0
  39. data/app/helpers/cms_edit_helper.rb +498 -0
  40. data/app/helpers/cms_helper.rb +230 -0
  41. data/app/helpers/cms_index_helper.rb +564 -0
  42. data/app/helpers/dc_application_helper.rb +195 -268
  43. data/app/models/{dc_dummy.rb → __dc_dummy.rb} +0 -0
  44. data/app/models/concerns/dc_page_concern.rb +31 -6
  45. data/app/models/concerns/dc_seo_concern.rb +66 -0
  46. data/app/models/concerns/dc_site_concern.rb +12 -1
  47. data/app/models/concerns/dc_user_concern.rb +5 -3
  48. data/app/models/dc_design.rb +2 -0
  49. data/app/models/dc_filter.rb +37 -20
  50. data/app/models/dc_gallery.rb +64 -0
  51. data/app/models/dc_json_ld.rb +152 -0
  52. data/app/models/dc_key_value.rb +48 -0
  53. data/app/models/dc_link.rb +1 -0
  54. data/app/models/dc_memory.rb +26 -4
  55. data/app/models/dc_page.rb +1 -2
  56. data/app/models/dc_permission.rb +30 -0
  57. data/app/models/dc_poll.rb +39 -19
  58. data/app/models/dc_poll_result.rb +46 -0
  59. data/app/models/dc_removed_url.rb +54 -0
  60. data/app/models/dc_temp.rb +140 -0
  61. data/app/models/drgcms_form_fields.rb +6 -1642
  62. data/app/models/drgcms_form_fields/action.rb +61 -0
  63. data/app/models/drgcms_form_fields/check_box.rb +72 -0
  64. data/app/models/drgcms_form_fields/comment.rb +53 -0
  65. data/app/models/drgcms_form_fields/date_picker.rb +104 -0
  66. data/app/models/drgcms_form_fields/date_select.rb +68 -0
  67. data/app/models/drgcms_form_fields/datetime_picker.rb +89 -0
  68. data/app/models/drgcms_form_fields/datetime_select.rb +73 -0
  69. data/app/models/drgcms_form_fields/drgcms_field.rb +287 -0
  70. data/app/models/drgcms_form_fields/embedded.rb +97 -0
  71. data/app/models/drgcms_form_fields/file_field.rb +52 -0
  72. data/app/models/drgcms_form_fields/file_select.rb +70 -0
  73. data/app/models/drgcms_form_fields/hash_field.rb +86 -0
  74. data/app/models/drgcms_form_fields/hidden_field.rb +52 -0
  75. data/app/models/drgcms_form_fields/html_field.rb +70 -0
  76. data/app/models/drgcms_form_fields/journal_diff.rb +60 -0
  77. data/app/models/drgcms_form_fields/link_to.rb +69 -0
  78. data/app/models/drgcms_form_fields/method.rb +65 -0
  79. data/app/models/drgcms_form_fields/multitext_autocomplete.rb +204 -0
  80. data/app/models/drgcms_form_fields/number_field.rb +92 -0
  81. data/app/models/drgcms_form_fields/password_field.rb +62 -0
  82. data/app/models/drgcms_form_fields/radio.rb +96 -0
  83. data/app/models/drgcms_form_fields/readonly.rb +79 -0
  84. data/app/models/drgcms_form_fields/select.rb +226 -0
  85. data/app/models/drgcms_form_fields/submit_tag.rb +58 -0
  86. data/app/models/drgcms_form_fields/text_area.rb +68 -0
  87. data/app/models/drgcms_form_fields/text_autocomplete.rb +155 -0
  88. data/app/models/drgcms_form_fields/text_field.rb +56 -0
  89. data/app/models/drgcms_form_fields/text_with_select.rb +95 -0
  90. data/app/models/drgcms_form_fields/tree_select.rb +169 -0
  91. data/app/{helpers → renderers}/dc_ad_renderer.rb +0 -0
  92. data/app/{helpers → renderers}/dc_big_menu_renderer.rb +1 -0
  93. data/app/{helpers → renderers}/dc_captcha_renderer.rb +0 -0
  94. data/app/{helpers → renderers}/dc_common_renderer.rb +0 -0
  95. data/app/renderers/dc_gallery_renderer.rb +95 -0
  96. data/app/{helpers → renderers}/dc_menu_renderer.rb +11 -4
  97. data/app/{helpers → renderers}/dc_page_renderer.rb +21 -3
  98. data/app/{helpers → renderers}/dc_part_renderer.rb +5 -4
  99. data/app/{helpers → renderers}/dc_piece_renderer.rb +1 -1
  100. data/app/{helpers → renderers}/dc_poll_renderer.rb +86 -51
  101. data/app/{helpers → renderers}/dc_renderer.rb +1 -0
  102. data/app/{helpers → renderers}/dc_simple_menu_renderer.rb +1 -0
  103. data/app/views/cmsedit/{remove_edit_stuff.js.erb → __remove_edit_stuff.js.erb} +0 -0
  104. data/app/views/cmsedit/{show.html.erb → __show.html.erb} +0 -0
  105. data/app/views/cmsedit/_edit_stuff.html.erb +4 -25
  106. data/app/views/cmsedit/_form.html.erb +4 -3
  107. data/app/views/cmsedit/_result.html.erb +2 -3
  108. data/app/views/cmsedit/edit.html.erb +2 -1
  109. data/app/views/cmsedit/index.html.erb +6 -1
  110. data/app/views/cmsedit/new.html.erb +1 -1
  111. data/config/locales/drgcms_en.yml +15 -3
  112. data/config/locales/drgcms_sl.yml +18 -6
  113. data/config/locales/models_en.yml +103 -19
  114. data/config/locales/models_sl.yml +102 -17
  115. data/drg_cms.gemspec +3 -3
  116. data/lib/drg_cms.rb +6 -2
  117. data/lib/drg_cms/version.rb +2 -2
  118. data/lib/generators/new_drg_form/new_drg_form_generator.rb +9 -2
  119. data/lib/tasks/database.rake +6 -56
  120. data/lib/tasks/dc_cleanup.rake +1 -1
  121. metadata +106 -61
  122. data/app/assets/stylesheets/drg_cms/__jquery-ui.css +0 -339
  123. data/app/helpers/application_helper.rb +0 -2
  124. data/app/helpers/cmsedit_helper.rb +0 -844
  125. data/test/fixtures/drg_cms_test_data.rb +0 -87
@@ -33,12 +33,11 @@ include Mongoid::Document
33
33
  include Mongoid::Timestamps
34
34
 
35
35
  field :subject, type: String, default: ''
36
- field :title, type: String
37
36
  field :subject_link, type: String, default: ''
38
37
  field :alt_link, type: String, default: ''
39
38
  field :sub_subject, type: String, default: ''
40
39
  field :picture, type: String
41
- field :gallery, type: String
40
+ field :gallery, type: Boolean, default: false
42
41
  field :body, type: String, default: ''
43
42
  field :css, type: String, default: ''
44
43
  field :script, type: String, default: ''
@@ -56,16 +55,19 @@ field :active, type: Boolean, default: true
56
55
  field :created_by, type: BSON::ObjectId
57
56
  field :updated_by, type: BSON::ObjectId
58
57
  field :kats, type: Array # Categories
59
-
58
+ # IFRAME
60
59
  field :if_url, type: String
61
60
  field :if_border, type: Integer, default: 0
62
61
  field :if_width, type: Integer
63
62
  field :if_height, type: Integer
64
63
  field :if_scroll, type: String
65
64
  field :if_id, type: String
66
- field :if_class, type: String
65
+ field :if_class, type: String
67
66
  field :if_params, type: String
68
67
 
68
+ # SEO
69
+ include DcSeoConcern
70
+
69
71
  field :policy_id, type: BSON::ObjectId
70
72
 
71
73
  embeds_many :dc_parts
@@ -80,6 +82,7 @@ index alt_link: 1
80
82
  before_save :do_before_save
81
83
 
82
84
  validates :publish_date, presence: true
85
+ validate :validate_images_alt_present
83
86
 
84
87
  ######################################################################
85
88
  # Will return subject_link. Field name link should be common for all documents
@@ -88,7 +91,15 @@ validates :publish_date, presence: true
88
91
  def link
89
92
  subject_link
90
93
  end
91
-
94
+
95
+ ######################################################################
96
+ # Will return validation error if all images in body field do not have
97
+ # alt attribute pressent.
98
+ ######################################################################
99
+ def validate_images_alt_present
100
+ errors.add('body', I18n.t('drgcms.img_alt_not_present')) unless DcPage.images_alt_present?(self.body)
101
+ end
102
+
92
103
  protected
93
104
 
94
105
  ######################################################################
@@ -109,7 +120,7 @@ end
109
120
  # than link size is not larger than 100 chars.
110
121
  ######################################################################
111
122
  def self.clear_link(link)
112
- link.gsub!(/\.|\?|\!\&|»|«|\,|\"|\'|\:/,'')
123
+ link.gsub!(/\.|\?|\!\&|\||»|«|\,|\"|\'|\:/,'')
113
124
  link.gsub!('<br>','')
114
125
  link.gsub!('–','-')
115
126
  link.gsub!(' ','-')
@@ -144,6 +155,20 @@ def self.dc_filters
144
155
  'field' => 'dc_site_id', 'value' => '@current_site'}
145
156
  end
146
157
 
158
+ ######################################################################
159
+ # Clears subject link of chars that shouldn't be there and also takes care
160
+ # than link size is not larger than 100 chars.
161
+ ######################################################################
162
+ def self.images_alt_present?(text)
163
+ return true if text.blank?
164
+ #
165
+ document = Nokogiri::HTML.parse(text)
166
+ document.xpath('//img').each do |image|
167
+ return false if !image.attributes['alt'] or image.attributes['alt'].text.blank?
168
+ end
169
+ true
170
+ end
171
+
147
172
  end
148
173
 
149
174
  end
@@ -0,0 +1,66 @@
1
+ #--
2
+ # Copyright (c) 2019+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ ##########################################################################
25
+ # dc_seo_concern, ads SEO optimization fields to any model.
26
+ #
27
+ # title String Browser title. Optimization for SEO.
28
+ # meta_description String SEO optimised page description
29
+ # meta_additional String Additional meta page data. Enter as meta_name=meta data
30
+ # dc_json_lds Embedded:DcJsonLd Page structure data
31
+ #
32
+ # If you want to add SEO optimization data to your document add:
33
+ #
34
+ # "include DcSeoConcern" to your model definition
35
+ #
36
+ # and
37
+ #
38
+ # "include: dc_seo" option to top of DRGCMS edit form for your document.
39
+ ##########################################################################
40
+ module DcSeoConcern
41
+ extend ActiveSupport::Concern
42
+
43
+ included do
44
+ field :title, type: String
45
+ field :meta_description, type: String
46
+ field :canonical_link, type: String
47
+ embeds_many :dc_json_lds # JSON-LD structure
48
+
49
+ ######################################################################
50
+ # Will return JSON LD data if defined for the page
51
+ ######################################################################
52
+ def get_json_ld()
53
+ parent_data = {'datePublished' => self.created_at, 'dateModified' => self.updated_at}
54
+ data = []
55
+ if dc_json_lds.size > 0
56
+ dc_json_lds.where(active: true).each do |element|
57
+ dta = element.get_json_ld(parent_data)
58
+ data << dta if dta.size > 0
59
+ end
60
+ end
61
+ data
62
+ end
63
+ end
64
+
65
+
66
+ end
@@ -86,7 +86,7 @@ end
86
86
  # Returns class object of menu collection name
87
87
  ########################################################################
88
88
  def menu_klass()
89
- (self.menu_class.blank? ? 'DcMenu' : self.menu_class).classify.constantize
89
+ (menu_class.blank? ? 'DcMenu' : menu_class).classify.constantize
90
90
  end
91
91
 
92
92
  ########################################################################
@@ -106,5 +106,16 @@ def self.choices4_policies
106
106
  [['a','b']]
107
107
  end
108
108
 
109
+ ########################################################################
110
+ # Return choices for selecting policies for the site
111
+ ########################################################################
112
+ def self.choices_for_menu(menu_class)
113
+ return [] if menu_class.blank?
114
+ menu = menu_class.classify.constantize
115
+ menu.where(active: true).inject([]) do |r, a_menu|
116
+ r << [a_menu.description, a_menu.id]
117
+ end
118
+ end
119
+
109
120
  end
110
121
  end
@@ -92,7 +92,9 @@ def do_before_save
92
92
  end
93
93
 
94
94
  ##########################################################################
95
- # Checks if user has role 'role_id' defined in his roles
95
+ # Checks if user has role 'role_id' defined in his roles.
96
+ #
97
+ # Role may be passed as BSON id or as String like role name.
96
98
  ##########################################################################
97
99
  def has_role?(role_id)
98
100
  return false unless role_id
@@ -101,8 +103,8 @@ def has_role?(role_id)
101
103
  role = DcPolicyRole.get_role(role_id)
102
104
  role_id = role.id if role
103
105
  end
104
- role = self.dc_user_roles.where(dc_policy_role_id: role_id)
105
- (role && role.active?)
106
+ role = self.dc_user_roles.where(dc_policy_role_id: role_id).first
107
+ (role && role.active)
106
108
  end
107
109
 
108
110
  ##########################################################################
@@ -31,6 +31,7 @@
31
31
  # updated_at Time updated_at
32
32
  # description String Short description of design
33
33
  # body String Body of design which will be rendered like any Rails view
34
+ # params String Parameters used by design
34
35
  # css String CSS for design
35
36
  # rails_view String Rails view (file) name which will be used to render design
36
37
  # author String Creater if design
@@ -94,6 +95,7 @@ class DcDesign
94
95
  field :css, type: String, default: ''
95
96
  field :rails_view, type: String, default: ''
96
97
  field :control, type: String, default: ''
98
+ field :params, type: String, default: ''
97
99
  field :control_method, type: String, default: ''
98
100
  field :author, type: String
99
101
  field :active, type: Boolean, default: true
@@ -55,10 +55,14 @@ def self.get_filter(filter)
55
55
  yaml = YAML.load(filter) rescue nil
56
56
  return yaml if yaml.nil?
57
57
  return nil if yaml['table'].nil? # old data
58
- #
58
+ #
59
59
  model = yaml['table'].classify.constantize
60
60
  field = yaml['field'] == 'id' ? '_id' : yaml['field'] # must be
61
- # if empty required
61
+ # evaluate
62
+ if yaml['operation'] == 'eval' and model.respond_to?(yaml['field'])
63
+ return model.send( yaml['field'] )
64
+ end
65
+ # if empty
62
66
  if yaml['operation'] == 'empty'
63
67
  return model.in(field => [nil,''])
64
68
  end
@@ -106,45 +110,54 @@ def self.get_filter_field(parent)
106
110
  return '' if parent.session[ parent.form['table'] ].nil?
107
111
  filter = parent.session[ parent.form['table'] ][:filter]
108
112
  return '' if filter.nil?
109
- #
113
+
110
114
  filter = YAML.load(filter) rescue nil
111
115
  return '' if filter.nil?
112
- #
116
+
113
117
  field = get_field_form_definition(filter['field'], parent)
114
118
  return '' if field.nil? and filter['input'].nil?
115
119
  field = {} if field.nil?
116
- # If field has choices available in labels, use them. This is most likely select input field.
120
+ # If field has choices available in labels, use them. This is most likely select input field.
117
121
  if field['name']
118
122
  choices = parent.t('helpers.label.' + parent.form['table'] + '.choices4_' + field['name'] )
119
123
  unless choices.match( 'translation missing' ) or choices.match('helpers.label')
120
124
  field['choices'] = choices
121
125
  end
122
126
  end
123
- # field redefined with input keyword. Name must start with _
127
+ # field redefined with input keyword. Name must start with _
124
128
  field['name'] = '_filter_field'
125
129
  field['type'] = filter['input'] if filter['input'].to_s.size > 5
126
130
  field['type'] ||= 'text_field'
127
131
  field['readonly'] = false # must be
128
132
  field['html'] ||= {}
129
133
  field['html']['size'] = 20
130
- # Start with last entered value
131
- field['html']['value'] = filter['value'] unless filter['value'] == '#NIL'
134
+ # Start with last entered value
135
+ field['html']['value'] = filter['value'] unless filter['value'] == '#NIL'
132
136
  field['html']['selected'] = field['html']['value'] # for select field
133
- # url for filter ON action
137
+ # url for filter ON action
134
138
  field['html']['data-url'] = parent.url_for(
135
139
  controller: 'cmsedit',action: :index, filter: 'on',
136
- table: parent.form['table'], form_name: parent.form['form_name'])
140
+ table: parent.form['table'], form_name: parent.params['form_name'])
137
141
  url = field['html']['data-url']
142
+ # remove if present
143
+ field['with_new'] = nil if field['with_new']
138
144
  # create input field object
139
145
  klas_string = field['type'].camelize
140
146
  klas = DrgcmsFormFields::const_get(klas_string) rescue nil
141
147
  return '' if klas.nil?
142
148
  # return data from object and create html code to display field
143
- object = klas.new(parent, nil, field).render
144
- js = object.js
145
- "<span class=\"filter_field\" data-url=\"#{url}\">#{object.html} " <<
146
- parent.fa_icon('filter lg', class: 'record_filter_field_icon dc-link-icon dc-animate') <<
147
- (js.size > 2 ? parent.javascript_tag(js) : '') << '</span>'
149
+ object = klas.new(parent, nil, field).render rescue nil
150
+ # Error. Forget filter and return
151
+ if object.nil?
152
+ parent.session[ parent.form['table'] ][:filter] = nil
153
+ return ''
154
+ end
155
+ js = object.js.blank? ? '' : parent.javascript_tag(object.js)
156
+ %Q[<li class="no-background">
157
+ <span class="filter_field" data-url="#{url}">#{object.html}
158
+ #{parent.fa_icon('search lg', class: 'record_filter_field_icon')}
159
+ #{js}</span>
160
+ </li>]
148
161
  end
149
162
 
150
163
  ######################################################################
@@ -155,7 +168,8 @@ def self.menu_filter(parent)
155
168
  table = parent.form['table']
156
169
  documents = self.where(table: table, active: true).to_a
157
170
  documents.each do |document|
158
- html << "<li data-filter=\"\">#{document.description}</li>"
171
+ description = document.description.match('.') ? I18n.t(document.description) : document.description
172
+ html << "<li data-filter=\"#{document.id}\">#{description}</li>"
159
173
  end
160
174
 
161
175
  # add filters defined in model
@@ -176,7 +190,6 @@ def self.menu_filter(parent)
176
190
  end
177
191
  # divide standard and custom filter options
178
192
  html << '<hr>' if html.size > 30 #
179
- # html << '<li onclick="$(\'#drgcms_filter\').toggle(300);">' + I18n.t('drgcms.filter_set') + '</li>'
180
193
  html << '<li id="open_drgcms_filter">' + I18n.t('drgcms.filter_set') + '</li>'
181
194
  html << '</ul>'
182
195
  end
@@ -189,10 +202,14 @@ def self.title4_filter_off(filter_yaml)
189
202
  filter = YAML.load(filter_yaml)
190
203
  operations = I18n.t('drgcms.choices4_filter_operators').chomp.split(',').inject([]) {|r,v| r << v.split(':') }
191
204
  operation = ''
192
- operations.each{|a| (operation = a.first; break) if a.last == filter['operation']}
205
+ if filter['operation'] == 'eval'
206
+ filter['field']
207
+ else
208
+ operations.each{|a| (operation = a.first; break) if a.last == filter['operation']}
193
209
  #
194
- '[ ' + I18n.t("helpers.label.#{filter['table']}.#{filter['field']}") +
195
- " ] #{operation} [ #{filter['value'].to_s} ] : #{I18n.t('drgcms.filter_off')}"
210
+ '[ ' + I18n.t("helpers.label.#{filter['table']}.#{filter['field']}") +
211
+ " ] #{operation} [ #{filter['value'].to_s} ] : #{I18n.t('drgcms.filter_off')}"
212
+ end
196
213
  end
197
214
 
198
215
  end
@@ -0,0 +1,64 @@
1
+ #--
2
+ # Copyright (c) 2019+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ #########################################################################
25
+ # == Schema information
26
+ #
27
+ # Collection name: dc_gallery : Pictures gallery
28
+ #
29
+ # _id BSON::ObjectId _id
30
+ # doc_id BSON::ObjectId Document id of the gallery
31
+ # title String Title name for picture
32
+ # description String Short description
33
+ # picture String Picture filename
34
+ # thumbnail String Picture thumbnail
35
+ #
36
+ # active Mongoid::Boolean Picture is active
37
+ # created_by BSON::ObjectId created_by
38
+ # updated_by BSON::ObjectId updated_by
39
+ # created_at Time created_at
40
+ # updated_at Time updated_at
41
+ #
42
+ # Picture gallery collection holds data about picture galleries for
43
+ # different types of documents.
44
+ #########################################################################
45
+ class DcGallery
46
+ include Mongoid::Document
47
+ include Mongoid::Timestamps
48
+
49
+ field :title, type: String
50
+ field :description, type: String
51
+ field :picture, type: String
52
+ field :thumbnail, type: String
53
+ field :doc_id, type: BSON::ObjectId
54
+ field :order, type: Integer, default: 10
55
+
56
+ field :active, type: Boolean, default: true
57
+ field :created_by, type: BSON::ObjectId
58
+ field :updated_by, type: BSON::ObjectId
59
+
60
+ index doc_id: 1
61
+
62
+ validates :picture, presence: true
63
+ validates :doc_id, presence: true
64
+ end
@@ -0,0 +1,152 @@
1
+ #--
2
+ # Copyright (c) 2019+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ ########################################################################
25
+ # == Schema information
26
+ #
27
+ # Collection name: dc_json_ld : JSON_LD data for site optimization
28
+ #
29
+ # _id BSON::ObjectId _id
30
+ # type String Type of structure
31
+ # data String Structure data in YAML
32
+ # dc_json_lds Object Can embed substructure
33
+ # created_at Time created_at
34
+ # updated_at Time Last updated at
35
+ # created_by BSON::ObjectId created_by
36
+ # updated_by BSON::ObjectId Last updated by
37
+ #
38
+ ########################################################################
39
+ class DcJsonLd
40
+ include Mongoid::Document
41
+ include Mongoid::Timestamps
42
+
43
+ field :name, type: String
44
+ field :type, type: String
45
+ field :data, type: String
46
+ field :active, type: Boolean, default: true
47
+
48
+ embeds_many :dc_json_lds, :cyclic => true
49
+
50
+ field :created_by, type: BSON::ObjectId
51
+ field :updated_by, type: BSON::ObjectId
52
+
53
+ validates :name, presence: true
54
+ validates :type, presence: true
55
+
56
+ ##########################################################################
57
+ # Returns JSON LD data as YAML
58
+ ##########################################################################
59
+ def get_json_ld(parent_data)
60
+ yaml = (YAML.load(self.data) rescue nil) || {}
61
+ yaml['@type'] = self.type if yaml.size > 0
62
+ if dc_json_lds.size > 0
63
+ dc_json_lds.where(active: true).each do |element|
64
+ yml = element.get_json_ld(parent_data)
65
+ if yml.size > 0
66
+ yaml[element.name] ||= []
67
+ yaml[element.name] << yml
68
+ end
69
+ end
70
+ end
71
+ yaml
72
+ end
73
+
74
+ ########################################################################
75
+ # Searches forms path for file_name and returns full file name or nil if not found.
76
+ #
77
+ # @param [String] Form file name. File name can be passed as gem_name.filename. This can
78
+ # be useful when you are extending form but want to retain same name as original form
79
+ # For example. You are extending dc_user form from drg_cms gem and want to
80
+ # retain same dc_user name. This can be done by setting drg_cms.dc_user to extend option.
81
+ #
82
+ # @return [String] Form file name including path or nil if not found.
83
+ ########################################################################
84
+ def self.dc_find_form_file(form_file)
85
+ form_path=nil
86
+ if form_file.match(/\.|\//)
87
+ form_path,form_file=form_file.split(/\.|\//)
88
+ end
89
+ DrgCms.paths(:forms).reverse.each do |path|
90
+ f = "#{path}/#{form_file}.yml"
91
+ return f if File.exist?(f) and (form_path.nil? or path.to_s.match(/\/#{form_path}\//i))
92
+ end
93
+ p "Form file #{form_file} not found!"
94
+ nil
95
+ end
96
+
97
+ ########################################################################
98
+ # Find document by ids when document are embedded into main d even if embedded
99
+ #
100
+ # @param [tables] Tables parameter as send in url. Tables are separated by ;
101
+ # @param [ids] ids as send in url. ids are separated by ;
102
+ #
103
+ # @return [Document]
104
+ ########################################################################
105
+ def self.find_document_by_ids(tables, ids)
106
+ collection = tables.split(';').first.classify.constantize
107
+ ar_ids = ids.split(';')
108
+ # Find top document
109
+ document = collection.find(ar_ids.shift)
110
+ # Search for embedded document
111
+ ar_ids.each {|id| document = document.dc_json_lds.find(id) }
112
+ document
113
+ end
114
+
115
+ #########################################################################
116
+ # Returns possible options for type select field on form.
117
+ #########################################################################
118
+ def self.choices4_type()
119
+ yaml = YAML.load_file( dc_find_form_file('json_ld_schema') )
120
+
121
+ yaml.inject([]) {|result, schema_name| result << schema_name.first }
122
+ end
123
+
124
+ #########################################################################
125
+ # Create menu to add schema element. Called from DRGCMS Form action.
126
+ #########################################################################
127
+ def self.add_schema_menu(parent)
128
+ yaml = YAML.load_file( dc_find_form_file('json_ld_schema') )
129
+ if (level = parent.params['ids'].split(';').size) == 1
130
+ # select only top level elements
131
+ yaml.delete_if { |schema_name, schema_data| schema_data['level'].nil? }
132
+ else
133
+ # select only elemets which are subelements of type
134
+ parent_type = self.find_document_by_ids(parent.params['table'],parent.params['ids']).type
135
+ _yaml = []
136
+ yaml[parent_type].each do |name, data|
137
+ next unless data.class == Hash
138
+ _yaml << [data['type'], yaml[data['type']] ] if data['type'] and yaml[data['type']]
139
+ end
140
+ yaml = _yaml
141
+ end
142
+ # create menu code
143
+ html = '<ul>'
144
+ yaml.each do |schema_name, schema_data|
145
+ next if level == 1 and schema_data['level'].nil?
146
+ url = "/dc_common/add_json_ld_schema?table=#{parent.params['table']}&ids=#{parent.params['ids']}&schema=#{schema_name}&url=#{parent.request.url}"
147
+ html << %Q[<li class="dc-link-ajax dc-animate" data-url="#{url}">#{schema_name}</li>]
148
+ end
149
+ html << '</ul>'
150
+ end
151
+
152
+ end