udongo 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/backend/flexible_content.js +33 -0
  3. data/app/assets/javascripts/backend/sortable.js +1 -1
  4. data/app/assets/stylesheets/backend/pages/_flexible_content.scss +61 -0
  5. data/app/controllers/backend/admins_controller.rb +7 -7
  6. data/app/controllers/backend/content/rows/columns_controller.rb +7 -15
  7. data/app/controllers/backend/content/rows/images_controller.rb +1 -1
  8. data/app/controllers/backend/content/rows/texts_controller.rb +1 -1
  9. data/app/controllers/backend/content/rows_controller.rb +4 -13
  10. data/app/controllers/backend/email_templates_controller.rb +4 -4
  11. data/app/controllers/backend/emails_controller.rb +3 -3
  12. data/app/controllers/backend/forms/base_controller.rb +14 -0
  13. data/app/controllers/backend/forms/submissions_controller.rb +8 -0
  14. data/app/controllers/backend/forms_controller.rb +7 -0
  15. data/app/controllers/backend/navigation/items_controller.rb +8 -5
  16. data/app/controllers/backend/navigations_controller.rb +1 -1
  17. data/app/controllers/backend/pages_controller.rb +5 -5
  18. data/app/controllers/backend/redirects_controller.rb +4 -4
  19. data/app/controllers/backend/sessions_controller.rb +1 -1
  20. data/app/controllers/backend/snippets_controller.rb +6 -5
  21. data/app/controllers/backend/tagbox_controller.rb +4 -4
  22. data/app/controllers/backend_controller.rb +3 -3
  23. data/app/controllers/catch_all_controller.rb +1 -1
  24. data/app/controllers/redirects_controller.rb +1 -1
  25. data/app/decorators/application_decorator.rb +5 -0
  26. data/app/decorators/content_image_decorator.rb +1 -1
  27. data/app/decorators/content_row_decorator.rb +9 -0
  28. data/app/decorators/content_text_decorator.rb +1 -1
  29. data/app/decorators/form_decorator.rb +16 -0
  30. data/app/decorators/form_submission_decorator.rb +3 -0
  31. data/app/decorators/navigation_item_decorator.rb +2 -2
  32. data/app/decorators/page_decorator.rb +2 -2
  33. data/app/decorators/pagination_decorator.rb +4 -0
  34. data/app/decorators/redirect_decorator.rb +1 -1
  35. data/app/decorators/snippet_decorator.rb +1 -1
  36. data/app/forms/backend/snippet_form.rb +4 -18
  37. data/app/helpers/backend/pagination_helper.rb +1 -11
  38. data/app/helpers/icon_helper.rb +1 -1
  39. data/app/helpers/snippet_helper.rb +1 -1
  40. data/app/models/concerns/storable/collection.rb +48 -26
  41. data/app/models/concerns/translatable.rb +1 -1
  42. data/app/models/content_row.rb +4 -0
  43. data/app/models/form.rb +1 -0
  44. data/app/models/store_with_file.rb +2 -0
  45. data/app/views/backend/content/_image.html.erb +1 -8
  46. data/app/views/backend/content/_rows.html.erb +52 -49
  47. data/app/views/backend/emails/index.html.erb +2 -10
  48. data/app/views/backend/forms/index.html.erb +27 -0
  49. data/app/views/backend/forms/submissions/_filter.html.erb +16 -0
  50. data/app/views/backend/forms/submissions/index.html.erb +34 -0
  51. data/app/views/backend/redirects/index.html.erb +2 -10
  52. data/app/views/layouts/backend/_top_navigation.html.erb +1 -0
  53. data/changelog.md +14 -1
  54. data/config/locales/en_backend.yml +5 -5
  55. data/config/locales/nl_backend.yml +10 -10
  56. data/config/routes.rb +6 -6
  57. data/db/migrate/20160711114156_add_description_to_forms.rb +5 -0
  58. data/lib/generators/udongo/form/form_generator.rb +1 -1
  59. data/lib/tasks/udongo_tasks.rake +1 -1
  60. data/lib/udongo/config.rb +2 -1
  61. data/lib/udongo/configs/forms.rb +14 -0
  62. data/lib/udongo/flexible_content/column_width_calculator.rb +32 -0
  63. data/lib/udongo/form.rb +36 -0
  64. data/lib/udongo/forms/config.rb +11 -0
  65. data/lib/udongo/forms/submission_datagrid.rb +29 -0
  66. data/lib/udongo/forms/submission_filter.rb +33 -0
  67. data/lib/udongo/notification.rb +19 -0
  68. data/lib/udongo/object_path.rb +0 -2
  69. data/lib/udongo/version.rb +1 -1
  70. data/lib/udongo/will_paginate/options.rb +40 -0
  71. data/lib/udongo/will_paginate/renderer.rb +8 -4
  72. data/lib/udongo.rb +4 -11
  73. data/readme.md +145 -49
  74. metadata +24 -2
@@ -2,6 +2,7 @@ nl:
2
2
  b:
3
3
  actions: Acties
4
4
  add: Toevoegen
5
+ admin: Beheerder
5
6
  admins: Beheerders
6
7
  advanced: Geavanceerd
7
8
  cancel: Annuleren
@@ -20,11 +21,13 @@ nl:
20
21
  email_templates: E-mail templates
21
22
  enabled?: Ingeschakeld?
22
23
  extra: Extra
24
+ filter: Filter
23
25
  first_name: Voornaam
24
26
  flexible_content: Flexibele inhoud
25
27
  forms: Formulieren
26
28
  from: Van
27
29
  general: Algemeen
30
+ house_number: Huisnummer
28
31
  html_content: HTML inhoud
29
32
  last_name: Achternaam
30
33
  locale: Taal
@@ -33,6 +36,7 @@ nl:
33
36
  move: Verplaatsen
34
37
  name: Naam
35
38
  navigation: Navigatie
39
+ navigation_item: Navigatie-item
36
40
  new: Nieuw
37
41
  none: Geen
38
42
  not_yet_sent: Nog niet verzonden
@@ -56,6 +60,7 @@ nl:
56
60
  status_code: Statuscode
57
61
  subject: Onderwerp
58
62
  tags: Tags
63
+ telephone: Telefoonnummer
59
64
  title: Titel
60
65
  to: Naar
61
66
  up: Omhoog
@@ -64,19 +69,17 @@ nl:
64
69
  view: Bekijk
65
70
 
66
71
  msg:
67
- added: '%s werd toegevoegd.'
72
+ added: '%{actor} werd toegevoegd.'
68
73
  admins:
69
74
  account_details: Accountgegevens
70
- added: De admin werd toegevoegd.
71
- deleted: De admin werd verwijderd.
72
75
  personal_details: Persoonlijke gegevens
73
76
  changes_saved: De wijzigingen werden opgeslagen.
74
77
  confirm: Ben je zeker?
75
78
  content_types:
76
79
  image: Afbeelding
77
80
  text: Tekst
78
- deleted: '%s werd verwijderd.'
79
- edited: '%s werd gewijzigd.'
81
+ deleted: '%{actor} werd verwijderd.'
82
+ edited: '%{actor} werd gewijzigd.'
80
83
  flexible_content:
81
84
  add_column: Kolom toevoegen
82
85
  add_row: Rij toevoegen
@@ -85,18 +88,15 @@ nl:
85
88
  edit_column: Kolom bewerken
86
89
  edit_image: Afbeelding bewerken
87
90
  edit_text: Tekst bewerken
88
- explanation: Met module kan je flexibele responsive inhoud toevoegen. Klik op onderstaande knop om een eerste rij toe te voegen.
91
+ explanation: Met deze module kan je flexibele, responsive inhoud toevoegen. Klik op onderstaande knop om een eerste rij toe te voegen.
89
92
  forgot_password: Wachtwoord vergeten?
90
93
  help_texts:
91
94
  status_code: Meer info over het gebruik van status codes
92
95
  incorrect_login: Ongeldige login gegevens.
93
96
  navigation:
94
- added: Het navigatie item werd toegevoegd.
95
97
  custom: Op maat
96
- deleted: Het navigatie item werd verwijderd.
97
98
  no_items: Er zijn geen items.
98
-
99
- saved: '%s werd bewaard.'
99
+ saved: '%{actor} werd bewaard.'
100
100
  seo: SEO
101
101
  status_codes:
102
102
  '301': 301 (Moved Permanently)
data/config/routes.rb CHANGED
@@ -24,6 +24,10 @@ Rails.application.routes.draw do
24
24
  member { post :tree_drag_and_drop }
25
25
  end
26
26
 
27
+ resources :forms do
28
+ resources :submissions, controller: 'forms/submissions'
29
+ end
30
+
27
31
  resources :navigations, only: [:index] do
28
32
  scope module: 'navigation' do
29
33
  resources :items, except: [:index, :show] do
@@ -57,15 +61,11 @@ Rails.application.routes.draw do
57
61
 
58
62
  namespace :content do
59
63
  resources :rows, only: [:index, :new, :destroy] do
60
- member do
61
- get 'move_up', 'move_down'
62
- end
64
+ concerns :positionable
63
65
 
64
66
  scope module: 'rows' do
65
67
  resources :columns do
66
- member do
67
- get 'move_up', 'move_down'
68
- end
68
+ concerns :positionable
69
69
  end
70
70
  end
71
71
  end
@@ -0,0 +1,5 @@
1
+ class AddDescriptionToForms < ActiveRecord::Migration
2
+ def change
3
+ add_column :forms, :description, :string, after: :identifier
4
+ end
5
+ end
@@ -24,7 +24,7 @@ class Udongo::FormGenerator < Rails::Generators::Base
24
24
  end
25
25
 
26
26
  def create_database_records
27
- f = ::Form.create!(locales: Udongo.config.locales, identifier: name)
27
+ f = Form.create!(locales: Udongo.config.locales, identifier: name)
28
28
 
29
29
  @fields.each do |field|
30
30
  field_object = f.fields.create!(locales: Udongo.config.locales, name: field.name, field_type: field.type)
@@ -16,7 +16,7 @@ namespace :udongo do
16
16
  namespace :content_images do
17
17
  desc 'Regenerate all the image versions.'
18
18
  task regenerate: :environment do
19
- ::ContentImage.find_each do |i|
19
+ ContentImage.find_each do |i|
20
20
  if i.file?
21
21
  i.file.recreate_versions!
22
22
  i.save!
data/lib/udongo/config.rb CHANGED
@@ -2,7 +2,7 @@ module Udongo
2
2
  class Config
3
3
  attr_accessor :default_locale, :locales, :prefix_routes_with_locale, :host,
4
4
  :time_zone, :allow_new_tags, :flexible_content_types,
5
- :project_name
5
+ :project_name, :forms
6
6
 
7
7
  def initialize
8
8
  @default_locale = :nl
@@ -13,6 +13,7 @@ module Udongo
13
13
  @allow_new_tags = true
14
14
  @flexible_content_types = %w(text image)
15
15
  @project_name = 'Udongo'
16
+ @forms = Udongo::Configs::Forms.new
16
17
  end
17
18
 
18
19
  def prefix_routes_with_locale?
@@ -0,0 +1,14 @@
1
+ module Udongo
2
+ module Configs
3
+ class Forms
4
+ def initialize
5
+ @submission_datagrids = {}
6
+ end
7
+
8
+ def method_missing(method, *args, &block)
9
+ form = ::Form.find_by!(identifier: method)
10
+ @submission_datagrids[form.identifier.to_sym] ||= OpenStruct.new(datagrid_fields: [], filter_fields: [])
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,32 @@
1
+ module Udongo
2
+ module FlexibleContent
3
+ class ColumnWidthCalculator
4
+ attr_reader :row
5
+
6
+ COLUMNS = %w(width_xs width_sm width_md width_lg width_xl)
7
+
8
+ def initialize(row)
9
+ @row = row
10
+ end
11
+
12
+ def calculate(field)
13
+ difference = 12 - total(field)
14
+ return 12 if difference.zero?
15
+ difference
16
+ end
17
+
18
+ def hashed_values
19
+ COLUMNS.inject({}) do |result, column|
20
+ result[column.to_sym] = calculate(column.to_sym)
21
+ result
22
+ end
23
+ end
24
+
25
+ def total(field)
26
+ sum = row.columns.sum(field.to_sym).to_i
27
+ return 12 if sum > 12
28
+ sum
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ module Udongo
2
+ class Form
3
+ include ActiveModel::Model
4
+ include Virtus.model
5
+
6
+ def initialize(params = {})
7
+ attributes.keys.each { |k| send("#{k}=", params[k]) } if params.any?
8
+ end
9
+
10
+ def persisted?
11
+ false
12
+ end
13
+
14
+ def save(params)
15
+ attributes.keys.each { |k| send("#{k}=", params[k]) }
16
+
17
+ if valid?
18
+ save_object
19
+ true
20
+ else
21
+ false
22
+ end
23
+ end
24
+
25
+ # This method only exists so the related factory tests pass
26
+ def save!
27
+ valid?
28
+ end
29
+
30
+ private
31
+
32
+ # Written in the subclass
33
+ def save_object
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,11 @@
1
+ module Udongo
2
+ module Forms
3
+ module Config
4
+ attr_reader :form
5
+
6
+ def config
7
+ Udongo.config.forms.send(form.identifier.to_sym)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,29 @@
1
+ module Udongo
2
+ module Forms
3
+ class SubmissionDatagrid
4
+ include Udongo::Forms::Config
5
+ include ActionView::Helpers::TagHelper
6
+
7
+ def initialize(form)
8
+ @form = form
9
+ end
10
+
11
+ def column_values(submission)
12
+ map_fields { |field| content_tag(:td, submission.data_object.send(field)) }
13
+ end
14
+
15
+ def column_headers(filter)
16
+ map_fields { |field| content_tag(:th, I18n.t("b.#{field}")) }
17
+ end
18
+
19
+ def fields
20
+ return [] if config.nil?
21
+ config.datagrid_fields
22
+ end
23
+
24
+ def map_fields(&block)
25
+ fields.map { |field| yield(field) }.join("\n").html_safe
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,33 @@
1
+ module Udongo
2
+ module Forms
3
+ class SubmissionFilter
4
+ include Udongo::Forms::Config
5
+ attr_reader :params
6
+
7
+ def initialize(form, params = {})
8
+ @form = form
9
+ @params = params || {}
10
+ end
11
+
12
+ def fields
13
+ return [] if config.nil?
14
+ config.filter_fields
15
+ end
16
+
17
+ def result
18
+ data = FormSubmissionData.all
19
+
20
+ params.each do |key,value|
21
+ next if value.blank?
22
+ data = data.where(name: key).where('value REGEXP ?', value)
23
+ end
24
+
25
+ FormSubmission.where(id: data.pluck(:submission_id).uniq)
26
+ end
27
+
28
+ def self.search(*args)
29
+ new(*args)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,19 @@
1
+ class Udongo::Notification
2
+ def initialize(notice)
3
+ @notice = notice
4
+ end
5
+
6
+ def build_hash(actor)
7
+ { actor: I18n.t("b.#{actor}") }
8
+ end
9
+
10
+ def label
11
+ "b.msg.#{@notice}"
12
+ end
13
+
14
+ def translate(vars = nil)
15
+ return I18n.t(label) if vars.blank?
16
+ vars = build_hash(vars) unless vars.is_a?(Hash)
17
+ I18n.t(label, vars)
18
+ end
19
+ end
@@ -14,8 +14,6 @@ class Udongo::ObjectPath
14
14
  object.select { |o| !o.is_a?(Symbol) }
15
15
  end
16
16
 
17
- private
18
-
19
17
  def self.cleanup(value)
20
18
  value.to_s.gsub('_decorator', '')
21
19
  end
@@ -1,3 +1,3 @@
1
1
  module Udongo
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  end
@@ -0,0 +1,40 @@
1
+ module Udongo
2
+ module WillPaginate
3
+ class Options
4
+ include ActionView::Helpers::TagHelper
5
+
6
+ def initialize(options = {})
7
+ @options = options || {}
8
+ end
9
+
10
+ def defaults
11
+ {
12
+ class: 'pagination',
13
+ inner_window: 1,
14
+ outer_window: 0,
15
+ renderer: Udongo::WillPaginate::Renderer,
16
+ previous_label: previous_label,
17
+ next_label: next_label
18
+ }
19
+ end
20
+
21
+ def next_label
22
+ nav_label('&rarr;', 'next_label')
23
+ end
24
+
25
+ def previous_label
26
+ nav_label('&larr;', 'previous_label')
27
+ end
28
+
29
+ def nav_label(default_value, sr_only_value)
30
+ string = content_tag(:span, default_value.html_safe, aria: { hidden: true })
31
+ string += content_tag(:span, I18n.t("will_paginate.#{sr_only_value}"), class: 'sr-only')
32
+ string.html_safe
33
+ end
34
+
35
+ def values
36
+ @options.reverse_merge!(defaults)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -7,19 +7,23 @@ module Udongo
7
7
  protected
8
8
 
9
9
  def page_number(page)
10
- tag :li, link(page, page, rel: rel_value(page)), class: ('current' if page == current_page)
10
+ list_classes = 'page-item'
11
+ list_classes += ' active' if page == current_page
12
+ tag(:li, link(page, page, class: 'page-link', rel: rel_value(page)), class: list_classes)
11
13
  end
12
14
 
13
15
  def previous_or_next_page(page, text, classname)
14
- tag :li, link(text, page || '#'), class: [classname[0..3], classname, ('unavailable' unless page)].join(' ')
16
+ list_classes = [classname[0..3], classname, 'page-item']
17
+ list_classes.push('disabled') unless page
18
+ tag(:li, link(text, page || '#', class: 'page-link'), class: list_classes.join(' '))
15
19
  end
16
20
 
17
21
  def html_container(html)
18
- tag :ul, html, container_attributes
22
+ tag(:nav, tag(:ul, html, container_attributes))
19
23
  end
20
24
 
21
25
  def gap
22
- tag :li, link(super, '#'), class: 'unavailable'
26
+ tag(:li, link(super, '#', class: 'page-link'), class: 'page-item disabled')
23
27
  end
24
28
  end
25
29
  end
data/lib/udongo.rb CHANGED
@@ -1,14 +1,3 @@
1
- require 'udongo/engine'
2
- require 'udongo/config'
3
- require 'udongo/breadcrumb'
4
- require 'udongo/meta_info'
5
- require 'udongo/object_path'
6
- require 'udongo/crypt'
7
- require 'udongo/cryptography'
8
- require 'udongo/active_model_simulator'
9
- require 'udongo/email_vars_parser'
10
- require 'udongo/email_vars/form_submission'
11
- require 'udongo/email_vars/address'
12
1
  require 'jquery-rails'
13
2
  require 'jquery-ui-rails'
14
3
  require 'simple_form'
@@ -27,6 +16,10 @@ module Udongo
27
16
 
28
17
  class << self
29
18
  attr_writer :config
19
+
20
+ Dir.glob("#{PATH}/lib/udongo/**/*.rb").each do |file|
21
+ require file
22
+ end
30
23
  end
31
24
 
32
25
  def self.config