constructor-cms 0.6.4 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -3
- data/Gemfile +9 -0
- data/README.md +2 -2
- data/constructor-cms.gemspec +0 -1
- data/core/config/initializers/devise.rb +8 -8
- data/core/config/locales/devise.en.yml +37 -37
- data/core/config/locales/devise.fr.yml +74 -0
- data/core/config/locales/devise.ru.yml +40 -40
- data/core/config/locales/en.yml +14 -14
- data/core/config/locales/fr.yml +15 -0
- data/core/config/locales/ru.yml +20 -20
- data/core/lib/constructor_core/version.rb +1 -1
- data/pages/app/controllers/constructor_pages/fields_controller.rb +7 -11
- data/pages/app/models/constructor_pages/page.rb +70 -40
- data/pages/app/views/constructor_pages/fields/_form.haml +2 -1
- data/pages/config/locales/en.yml +57 -54
- data/pages/config/locales/fr.yml +65 -0
- data/pages/config/locales/ru.yml +48 -44
- data/pages/spec/features/constructor_pages/fields_controller_spec.rb +217 -0
- data/pages/spec/features/constructor_pages/pages_controller_spec.rb +4 -1
- data/pages/spec/features/constructor_pages/templates_controller_spec.rb +4 -0
- data/pages/spec/helpers/constructor_pages/.keep +0 -0
- data/pages/spec/models/constructor_pages/page_model_spec.rb +97 -0
- data/pages/spec/models/constructor_pages/template_model_spec.rb +5 -0
- data/pages/spec/models/constructor_pages/types/boolean_type_model_spec.rb +21 -0
- data/pages/spec/models/constructor_pages/types/date_type_model_spec.rb +21 -0
- data/pages/spec/models/constructor_pages/types/float_type_model_spec.rb +21 -0
- data/pages/spec/models/constructor_pages/types/html_type_model_spec.rb +63 -0
- data/pages/spec/models/constructor_pages/types/integer_type_model_spec.rb +24 -0
- data/pages/spec/models/constructor_pages/types/string_type_model_spec.rb +21 -0
- data/pages/spec/models/constructor_pages/types/text_type_model_spec.rb +63 -0
- data/pages/spec/routing/constructor_pages/.keep +0 -0
- data/spec/spec_helper.rb +2 -0
- metadata +19 -20
@@ -3,13 +3,11 @@
|
|
3
3
|
module ConstructorPages
|
4
4
|
class FieldsController < ApplicationController
|
5
5
|
def new
|
6
|
-
@field = Field.new
|
7
|
-
@field.template = Template.find(params[:template_id])
|
6
|
+
@field = Field.new.tap {|f| f.template = Template.find(params[:template_id])}
|
8
7
|
end
|
9
8
|
|
10
9
|
def edit
|
11
|
-
@field = Field.find(params[:id])
|
12
|
-
@field.template = Template.find(params[:template_id])
|
10
|
+
@field = Field.find(params[:id]).tap {|f| f.template = Template.find(params[:template_id])}
|
13
11
|
end
|
14
12
|
|
15
13
|
def create
|
@@ -18,7 +16,7 @@ module ConstructorPages
|
|
18
16
|
if @field.save
|
19
17
|
redirect_to edit_template_path(@field.template_id), notice: t(:field_success_added, name: @field.name)
|
20
18
|
else
|
21
|
-
render :
|
19
|
+
render action: :new, template_id: @field.template_id
|
22
20
|
end
|
23
21
|
end
|
24
22
|
|
@@ -26,10 +24,9 @@ module ConstructorPages
|
|
26
24
|
@field = Field.find params[:id]
|
27
25
|
|
28
26
|
if @field.type_value != params[:field][:type_value]
|
29
|
-
@field.type_class.where(:
|
27
|
+
@field.type_class.where(field_id: @field.id).each do |field|
|
30
28
|
new_field = "constructor_pages/types/#{params[:field][:type_value]}_type".classify.constantize.new(
|
31
|
-
:
|
32
|
-
:page_id => field.page_id)
|
29
|
+
field_id: @field.id, page_id: field.page_id)
|
33
30
|
|
34
31
|
if @field.type_value != 'image' \
|
35
32
|
and params[:field][:type_value] != 'image' \
|
@@ -45,14 +42,13 @@ module ConstructorPages
|
|
45
42
|
if @field.update field_params
|
46
43
|
redirect_to edit_template_url(@field.template.id), notice: t(:field_success_updated, name: @field.name)
|
47
44
|
else
|
48
|
-
render :
|
45
|
+
render action: :edit
|
49
46
|
end
|
50
47
|
end
|
51
48
|
|
52
49
|
def destroy
|
53
50
|
@field = Field.find(params[:id])
|
54
|
-
name = @field.name
|
55
|
-
template = @field.template.id
|
51
|
+
name, template = @field.name, @field.template.id
|
56
52
|
@field.destroy
|
57
53
|
redirect_to edit_template_url(template), notice: t(:field_success_removed, name: name)
|
58
54
|
end
|
@@ -5,9 +5,7 @@ module ConstructorPages
|
|
5
5
|
class Page < ActiveRecord::Base
|
6
6
|
# Adding has_many for all field types
|
7
7
|
Field::TYPES.each do |t|
|
8
|
-
class_eval %{
|
9
|
-
has_many :#{t}_types, dependent: :destroy, class_name: 'Types::#{t.titleize}Type'
|
10
|
-
}
|
8
|
+
class_eval %{ has_many :#{t}_types, dependent: :destroy, class_name: 'Types::#{t.titleize}Type'}
|
11
9
|
end
|
12
10
|
|
13
11
|
has_many :fields, through: :template
|
@@ -24,45 +22,83 @@ module ConstructorPages
|
|
24
22
|
|
25
23
|
acts_as_nested_set
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
class << self
|
26
|
+
# Used for find page by request. It return first page if no request given or request is home page
|
27
|
+
# @param request for example <tt>'/conditioners/split-systems/zanussi'</tt>
|
28
|
+
def find_by_request_or_first(request = nil)
|
29
|
+
request == nil || '/' ? Page.first : Page.find_by(full_url: request)
|
30
|
+
end
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
# Generate full_url from parent id and url
|
33
|
+
# @param parent_id integer
|
34
|
+
# @param url should looks like <tt>'hello-world-page'</tt> without leading slash
|
35
|
+
def full_url_generate(parent_id, url = '')
|
36
|
+
'/' + Page.find(parent_id).self_and_ancestors.map(&:url).append(url).join('/')
|
37
|
+
end
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
39
|
+
# Check code_name for field and template.
|
40
|
+
# When missing method Page find field or page in branch with plural and singular code_name so
|
41
|
+
# field and template code_name should be uniqueness for page methods
|
42
|
+
def check_code_name(code_name)
|
43
|
+
[code_name, code_name.pluralize, code_name.singularize].each do |name|
|
44
|
+
return false if Page.instance_methods.include?(name.to_sym)
|
45
|
+
end
|
46
|
+
|
47
|
+
true
|
46
48
|
end
|
47
49
|
|
48
|
-
|
50
|
+
def search(what_search = nil)
|
51
|
+
if @where_search
|
52
|
+
if @where_search.is_a?(String)
|
53
|
+
_page = Page.find_by full_url: @where_search
|
54
|
+
elsif @where_search.is_a?(Page)
|
55
|
+
_page = @where_search
|
56
|
+
end
|
57
|
+
|
58
|
+
@result = _page ? _page.descendants : []
|
59
|
+
else
|
60
|
+
@result = Page.all
|
61
|
+
end
|
62
|
+
|
63
|
+
if what_search
|
64
|
+
_template = Template.find_by code_name: what_search.to_s.singularize.downcase
|
65
|
+
@result = _template ? @result.where(template: _template) : []
|
66
|
+
end
|
67
|
+
|
68
|
+
if @params_search
|
69
|
+
@params_search.each_pair do |k, v|
|
70
|
+
@result = @result.select { |p| p.send(k) == v }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
@where_search = @params_search = nil
|
75
|
+
|
76
|
+
@result
|
77
|
+
end
|
78
|
+
|
79
|
+
def in(where_search = nil); tap {@where_search = where_search} end
|
80
|
+
def by(params_search = nil); tap {@params_search = params_search} end
|
81
|
+
|
82
|
+
def search_in(where_search = nil); self.in(where_search).search end
|
83
|
+
def search_by(params_search = nil); self.by(params_search).search end
|
49
84
|
end
|
50
85
|
|
86
|
+
def search(what_search = nil); Page.in(self).search(what_search) end
|
87
|
+
def search_by(params_search = nil); Page.by(params_search).in(self).search end
|
88
|
+
|
51
89
|
# Get field by code_name
|
52
90
|
def field(code_name)
|
53
|
-
Field.
|
91
|
+
Field.find_by code_name: code_name, template_id: template_id
|
54
92
|
end
|
55
93
|
|
56
94
|
# Get value of field by code_name
|
57
95
|
def get_field_value(code_name)
|
58
|
-
field
|
59
|
-
field.get_value_for(self) if field
|
96
|
+
field(code_name).tap {|f| return f.get_value_for(self) if f}
|
60
97
|
end
|
61
98
|
|
62
99
|
# Set value of field by code_name and value
|
63
100
|
def set_field_value(code_name, value)
|
64
|
-
field
|
65
|
-
field.set_value_for(self, value) if field
|
101
|
+
field(code_name).tap {|f| f.set_value_for(self, value) if f}
|
66
102
|
end
|
67
103
|
|
68
104
|
# Update all fields values with given params.
|
@@ -78,18 +114,14 @@ module ConstructorPages
|
|
78
114
|
|
79
115
|
if _type_object
|
80
116
|
_type_object.value = 0 if field.type_value == 'boolean' and reset_booleans
|
81
|
-
|
82
|
-
if value
|
83
|
-
_type_object.value = value
|
84
|
-
end
|
85
|
-
|
117
|
+
_type_object.value = value if value
|
86
118
|
_type_object.save
|
87
119
|
end
|
88
120
|
end
|
89
121
|
end
|
90
122
|
|
91
123
|
# Create fields values
|
92
|
-
def create_fields_values; fields.each {|
|
124
|
+
def create_fields_values; fields.each {|f| f.create_type_object(self) } end
|
93
125
|
|
94
126
|
# Remove all fields values
|
95
127
|
def remove_fields_values
|
@@ -105,12 +137,12 @@ module ConstructorPages
|
|
105
137
|
# It determines if code_name is singular or nor
|
106
138
|
# @param code_name template code name
|
107
139
|
def find_page_in_branch(code_name)
|
108
|
-
_template = Template.
|
140
|
+
_template = Template.find_by code_name: code_name.singularize
|
109
141
|
|
110
142
|
if _template
|
111
143
|
result = []
|
112
144
|
result = descendants.where(template_id: _template.id) if code_name == code_name.pluralize
|
113
|
-
result = ancestors.
|
145
|
+
result = ancestors.find_by(template_id: _template.id) if result.empty?
|
114
146
|
result
|
115
147
|
end
|
116
148
|
end
|
@@ -126,13 +158,11 @@ module ConstructorPages
|
|
126
158
|
# Default attributes are name and title. Options param allows to add more.
|
127
159
|
# @param options default merge name and title page attributes
|
128
160
|
def as_json(options = {})
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
161
|
+
{name: self.name, title: self.title}.merge(options).tap do |options|
|
162
|
+
fields.each do |f|
|
163
|
+
options.merge!({f.code_name.to_sym => f.get_value_for(self)})
|
164
|
+
end
|
133
165
|
end
|
134
|
-
|
135
|
-
options
|
136
166
|
end
|
137
167
|
|
138
168
|
# Check if link specified
|
@@ -25,4 +25,5 @@
|
|
25
25
|
.span12
|
26
26
|
.form-actions
|
27
27
|
= f.submit class: 'btn btn-primary'
|
28
|
-
= link_to t(:cancel), edit_template_url(@field.template), class: 'btn'
|
28
|
+
= link_to t(:cancel), edit_template_url(@field.template), class: 'btn'
|
29
|
+
= link_to t(:delete_field), @field, method: :delete, data: {confirm: t(:are_you_sure?)}, class: 'btn btn-danger pull-right' unless @field.new_record?
|
data/pages/config/locales/en.yml
CHANGED
@@ -1,57 +1,56 @@
|
|
1
1
|
en:
|
2
|
-
structure:
|
3
|
-
templates:
|
4
|
-
settings:
|
5
|
-
new_field:
|
6
|
-
edit_field:
|
7
|
-
seo:
|
8
|
-
display_in:
|
9
|
-
help:
|
10
|
-
edit:
|
11
|
-
delete:
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
template_error_delete_pages: 'Delete pages with this template before'
|
2
|
+
structure: Structure
|
3
|
+
templates: Templates
|
4
|
+
settings: Settings
|
5
|
+
new_field: New field
|
6
|
+
edit_field: Edit field
|
7
|
+
seo: SEO
|
8
|
+
display_in: Display in
|
9
|
+
help: Help
|
10
|
+
edit: Edit
|
11
|
+
delete: Delete
|
12
|
+
|
13
|
+
code_name_already_in_use: This code name is already in use.
|
14
|
+
field_success_added: Field «%{name}» added successfully.
|
15
|
+
field_success_updated: Field «%{name}» updated successfully.
|
16
|
+
field_success_removed: Field «%{name}» removed successfully.
|
17
|
+
field_success_moved: Field «%{name} moved successfully.
|
18
|
+
delete_field: Delete field
|
19
|
+
|
20
|
+
string: String
|
21
|
+
integer: Integer
|
22
|
+
float: Float
|
23
|
+
boolean: Boolean
|
24
|
+
date: Date
|
25
|
+
text: Text
|
26
|
+
html: HTML
|
27
|
+
image: Image
|
28
|
+
|
29
|
+
menu: Menu
|
30
|
+
breadcrumbs: Breadcrumbs
|
31
|
+
|
32
|
+
are_you_sure?: Are you sure?
|
33
|
+
|
34
|
+
page_not_found: Page not found
|
35
|
+
|
36
|
+
new_page: New page
|
37
|
+
edit_page: Edit page
|
38
|
+
delete_page: Delete page
|
39
|
+
|
40
|
+
page_success_added: Page «%{name}» added successfully.
|
41
|
+
page_success_updated: Page «%{name}» updated successfully.
|
42
|
+
page_success_removed: Page «%{name}» removed successfully.
|
43
|
+
|
44
|
+
template: Template
|
45
|
+
new_template: New template
|
46
|
+
edit_template: Edit template
|
47
|
+
delete_template: Delete template
|
48
|
+
|
49
|
+
template_success_added: Template «%{name}» added successfully.
|
50
|
+
template_success_updated: Template «%{name}» updated successfully.
|
51
|
+
template_success_removed: Template «%{name}» removed successfully.
|
52
|
+
|
53
|
+
template_error_delete_pages: Delete pages with this template before
|
55
54
|
|
56
55
|
activerecord:
|
57
56
|
errors:
|
@@ -59,4 +58,8 @@ en:
|
|
59
58
|
constructor_pages/template:
|
60
59
|
attributes:
|
61
60
|
base:
|
62
|
-
code_name_already_in_use:
|
61
|
+
code_name_already_in_use: Code name has already been taken
|
62
|
+
constructor_pages/field:
|
63
|
+
attributes:
|
64
|
+
base:
|
65
|
+
code_name_already_in_use: Code name has already been taken
|
@@ -0,0 +1,65 @@
|
|
1
|
+
fr:
|
2
|
+
structure: Structure
|
3
|
+
templates: Modèles
|
4
|
+
settings: Réglages
|
5
|
+
new_field: Nouveau champ
|
6
|
+
edit_field: Champ dédition
|
7
|
+
seo: SEO
|
8
|
+
display_in: Montrer
|
9
|
+
help: Aider
|
10
|
+
edit: Èditer
|
11
|
+
delete: Supprimer
|
12
|
+
|
13
|
+
code_name_already_in_use: Ce nom de code est déjà utilisé
|
14
|
+
field_success_added: Champ %{name} a ajouté avec succès
|
15
|
+
field_success_updated: Champ %{name} mis à jour
|
16
|
+
field_success_removed: Champ %{name} supprimé avec succès
|
17
|
+
field_success_moved: Champ %{name} passé avec succès
|
18
|
+
delete_field: Supprimer le champ
|
19
|
+
|
20
|
+
string: String
|
21
|
+
integer: Entier
|
22
|
+
float: Flotter
|
23
|
+
boolean: Booléen
|
24
|
+
date: Date
|
25
|
+
text: Texte
|
26
|
+
html: HTML
|
27
|
+
image: Image
|
28
|
+
|
29
|
+
menu: Menu
|
30
|
+
breadcrumbs: Chapelure
|
31
|
+
|
32
|
+
are_you_sure?: Etes-vous sûr?
|
33
|
+
|
34
|
+
page_not_found: Page introuvable
|
35
|
+
|
36
|
+
new_page: Nouvelle page
|
37
|
+
edit_page: Modifier cette page
|
38
|
+
delete_page: Supprimer page
|
39
|
+
|
40
|
+
page_success_added: Page %{name} a ajouté avec succès
|
41
|
+
page_success_updated: Page %{name} mis à jour avec succès
|
42
|
+
page_success_removed: Page %{name} supprimé avec succès
|
43
|
+
|
44
|
+
template: Modèle
|
45
|
+
new_template: Nouveau modèle
|
46
|
+
edit_template: Modifier le modèle
|
47
|
+
delete_template: Supprimer le modèle
|
48
|
+
|
49
|
+
template_success_added: Modèle %{name} a ajouté avec succès
|
50
|
+
template_success_updated: Modèle %{name} mis à jour
|
51
|
+
template_success_removed: Modèle %{name} supprimé avec succès.
|
52
|
+
|
53
|
+
template_error_delete_pages: Supprimer les pages avec ce modèle avant
|
54
|
+
|
55
|
+
activerecord:
|
56
|
+
errors:
|
57
|
+
models:
|
58
|
+
constructor_pages/template:
|
59
|
+
attributes:
|
60
|
+
base:
|
61
|
+
code_name_already_in_use: Nom de code a déjà été prise
|
62
|
+
constructor_pages/field:
|
63
|
+
attributes:
|
64
|
+
base:
|
65
|
+
code_name_already_in_use: Nom de code a déjà été prise
|
data/pages/config/locales/ru.yml
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
ru:
|
2
|
-
structure:
|
3
|
-
templates:
|
4
|
-
settings:
|
5
|
-
new_field:
|
6
|
-
edit_field:
|
7
|
-
seo:
|
8
|
-
are_you_sure?:
|
9
|
-
display_in:
|
10
|
-
delete:
|
2
|
+
structure: Структура
|
3
|
+
templates: Шаблоны
|
4
|
+
settings: Настройки
|
5
|
+
new_field: Новое поле
|
6
|
+
edit_field: Редактирование поля
|
7
|
+
seo: Поисковая оптимизация
|
8
|
+
are_you_sure?: Вы уверены?
|
9
|
+
display_in: Отображать в
|
10
|
+
delete: Удалить
|
11
11
|
|
12
|
-
menu:
|
13
|
-
breadcrumbs:
|
14
|
-
code_name_already_in_use:
|
15
|
-
template:
|
16
|
-
new_template:
|
17
|
-
edit_template:
|
18
|
-
delete_template:
|
12
|
+
menu: Меню
|
13
|
+
breadcrumbs: Хлебные крошки
|
14
|
+
code_name_already_in_use: Такое кодовое имя уже используется
|
15
|
+
template: Шаблон
|
16
|
+
new_template: Создать шаблон
|
17
|
+
edit_template: Редактирование шаблона
|
18
|
+
delete_template: Удалить шаблон
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
code_name_already_in_use: Такое имя уже используется.
|
21
|
+
field_success_added: Поле «%{name}» успешно добавлено.
|
22
|
+
field_success_updated: Поле «%{name}» успешно обновлено.
|
23
|
+
field_success_removed: Поле «%{name}» успешно удалено.
|
24
|
+
field_success_moved: Поле «%{name}» успешно перемещено.
|
25
|
+
delete_field: Удалить поле
|
26
26
|
|
27
|
-
string:
|
28
|
-
integer:
|
29
|
-
float:
|
30
|
-
boolean:
|
31
|
-
date:
|
32
|
-
text:
|
33
|
-
html:
|
34
|
-
image:
|
35
|
-
help:
|
36
|
-
edit:
|
27
|
+
string: Строка
|
28
|
+
integer: Целое число
|
29
|
+
float: Дробное число
|
30
|
+
boolean: Булево
|
31
|
+
date: Дата
|
32
|
+
text: Текст
|
33
|
+
html: HTML
|
34
|
+
image: Изображение
|
35
|
+
help: Помощь
|
36
|
+
edit: Редактировать
|
37
37
|
|
38
|
-
page_not_found:
|
38
|
+
page_not_found: Страница не найдена
|
39
39
|
|
40
|
-
new_page:
|
41
|
-
edit_page:
|
42
|
-
delete_page:
|
40
|
+
new_page: Создать страницу
|
41
|
+
edit_page: Редактирование страницы
|
42
|
+
delete_page: Удалить страницу
|
43
43
|
|
44
|
-
page_success_added:
|
45
|
-
page_success_updated:
|
46
|
-
page_success_removed:
|
44
|
+
page_success_added: Страница «%{name}» успешно добавлена.
|
45
|
+
page_success_updated: Страница «%{name}» успешно обновлена.
|
46
|
+
page_success_removed: Страница «%{name}» успешно удалена.
|
47
47
|
|
48
|
-
template_success_added:
|
49
|
-
template_success_updated:
|
50
|
-
template_success_removed:
|
48
|
+
template_success_added: Шаблон «%{name}» успешно добавлен.
|
49
|
+
template_success_updated: Шаблон «%{name}» успешно обновлен.
|
50
|
+
template_success_removed: Шаблон «%{name}» успешно удален.
|
51
51
|
|
52
|
-
template_error_delete_pages:
|
52
|
+
template_error_delete_pages: Удалите страницы с данным шаблоном
|
53
53
|
|
54
54
|
activerecord:
|
55
55
|
attributes:
|
@@ -93,4 +93,8 @@ ru:
|
|
93
93
|
constructor_pages/template:
|
94
94
|
attributes:
|
95
95
|
base:
|
96
|
-
code_name_already_in_use:
|
96
|
+
code_name_already_in_use: Такое кодовое имя уже используется
|
97
|
+
constructor_pages/field:
|
98
|
+
attributes:
|
99
|
+
base:
|
100
|
+
code_name_already_in_use: Такое кодовое имя уже используется
|