constructor-pages 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/constructor_pages/fields_controller.rb +2 -8
- data/app/controllers/constructor_pages/pages_controller.rb +12 -34
- data/app/controllers/constructor_pages/templates_controller.rb +7 -23
- data/app/helpers/constructor_pages/move_helper.rb +14 -0
- data/app/models/constructor_pages/field.rb +17 -15
- data/app/models/constructor_pages/page.rb +16 -0
- data/app/models/constructor_pages/template.rb +9 -0
- data/config/locales/en.yml +5 -1
- data/config/locales/ru.yml +4 -0
- data/spec/features/constructor_pages/pages_controller_spec.rb +2 -1
- data/spec/models/constructor_pages/page_model_spec.rb +4 -1
- metadata +5 -5
- data/app/views/constructor_pages/pages/error_404.haml +0 -24
@@ -2,10 +2,6 @@
|
|
2
2
|
|
3
3
|
module ConstructorPages
|
4
4
|
class FieldsController < ConstructorCore::ApplicationController
|
5
|
-
before_filter :authenticate_user!
|
6
|
-
|
7
|
-
layout 'constructor_core/application_admin'
|
8
|
-
|
9
5
|
def new
|
10
6
|
@field = Field.new
|
11
7
|
@field.template = Template.find(params[:template_id])
|
@@ -30,7 +26,7 @@ module ConstructorPages
|
|
30
26
|
@field = Field.find params[:id]
|
31
27
|
|
32
28
|
if @field.type_value != params[:field][:type_value]
|
33
|
-
|
29
|
+
@field.type_model.where(:field_id => @field.id).each do |field|
|
34
30
|
new_field = "constructor_pages/types/#{params[:field][:type_value]}_type".classify.constantize.new(
|
35
31
|
:field_id => @field.id,
|
36
32
|
:page_id => field.page_id)
|
@@ -61,9 +57,7 @@ module ConstructorPages
|
|
61
57
|
redirect_to edit_template_url(template), notice: t(:field_success_removed, name: name)
|
62
58
|
end
|
63
59
|
|
64
|
-
|
65
|
-
|
66
|
-
def move_down; move_to :down end
|
60
|
+
%w{up down}.each {|m| define_method "move_#{m}" do move_to m.to_sym end}
|
67
61
|
|
68
62
|
private
|
69
63
|
|
@@ -2,37 +2,24 @@
|
|
2
2
|
|
3
3
|
module ConstructorPages
|
4
4
|
class PagesController < ConstructorCore::ApplicationController
|
5
|
-
|
6
|
-
|
5
|
+
include MoveHelper
|
7
6
|
caches_page :show
|
8
7
|
|
9
8
|
before_filter {@roots = Page.roots}
|
10
|
-
|
11
|
-
before_filter :cache, :only => [:create, :update, :destroy, :move_up, :move_down]
|
9
|
+
before_filter :cache, only: [:create, :update, :destroy, :move_up, :move_down]
|
12
10
|
|
13
11
|
def new
|
14
12
|
@page, @template_id, @multipart = Page.new, Template.first.id, false
|
15
13
|
|
16
|
-
if params[:page]
|
17
|
-
|
18
|
-
|
19
|
-
if _parent
|
20
|
-
if _parent.template.child_id.nil? and !_parent.template.leaf?
|
21
|
-
@template_id = _parent.template.children.first.id
|
22
|
-
else
|
23
|
-
@template_id = _parent.template.child_id
|
24
|
-
end
|
25
|
-
end
|
14
|
+
if params[:page] and (@page.parent = Page.find(params[:page]))
|
15
|
+
@template_id = @page.parent.template.child.id
|
26
16
|
end
|
27
17
|
end
|
28
18
|
|
29
19
|
def show
|
30
|
-
@page =
|
20
|
+
@page = Page.find_by_request_or_first params[:all]
|
31
21
|
|
32
|
-
if @page.nil? or !@page.active
|
33
|
-
render action: 'error_404', layout: false
|
34
|
-
return
|
35
|
-
end
|
22
|
+
error_404 and return if @page.nil? or !@page.active?
|
36
23
|
|
37
24
|
redirect_to @page.link if @page.redirect?
|
38
25
|
|
@@ -118,13 +105,13 @@ module ConstructorPages
|
|
118
105
|
@page = Page.find params[:id]
|
119
106
|
|
120
107
|
if @page.template.id != params[:page][:template_id].to_i
|
121
|
-
@page.
|
108
|
+
@page.remove_fields_values
|
122
109
|
end
|
123
110
|
|
124
111
|
if @page.update_attributes params[:page]
|
125
|
-
@page.
|
112
|
+
@page.update_fields_values params[:fields]
|
126
113
|
|
127
|
-
redirect_to
|
114
|
+
redirect_to pages_url, notice: t(:page_success_updated, name: @page.name)
|
128
115
|
else
|
129
116
|
render action: :edit
|
130
117
|
end
|
@@ -137,21 +124,12 @@ module ConstructorPages
|
|
137
124
|
redirect_to pages_url, notice: t(:page_success_removed, name: _name)
|
138
125
|
end
|
139
126
|
|
140
|
-
|
141
|
-
|
142
|
-
def move_down; move_to :down end
|
127
|
+
%w{up down}.each {|m| define_method "move_#{m}" do move_to :page, m.to_sym end}
|
143
128
|
|
144
129
|
private
|
145
130
|
|
146
|
-
def
|
147
|
-
|
148
|
-
to_sibling = to == :up ? from.left_sibling : from.right_sibling
|
149
|
-
|
150
|
-
if not to_sibling.nil? and from.move_possible?(to_sibling)
|
151
|
-
to == :up ? from.move_left : from.move_right
|
152
|
-
end
|
153
|
-
|
154
|
-
redirect_to :back
|
131
|
+
def error_404
|
132
|
+
render file: "#{Rails.root}/public/404", layout: false, status: 404
|
155
133
|
end
|
156
134
|
|
157
135
|
def cache
|
@@ -2,10 +2,9 @@
|
|
2
2
|
|
3
3
|
module ConstructorPages
|
4
4
|
class TemplatesController < ConstructorCore::ApplicationController
|
5
|
-
|
5
|
+
include MoveHelper
|
6
6
|
|
7
7
|
before_filter {@roots = Template.roots}
|
8
|
-
layout 'constructor_core/application_admin'
|
9
8
|
|
10
9
|
def new
|
11
10
|
@template = Template.new
|
@@ -24,9 +23,9 @@ module ConstructorPages
|
|
24
23
|
@template = Template.new params[:template]
|
25
24
|
|
26
25
|
if @template.save
|
27
|
-
redirect_to templates_url, :
|
26
|
+
redirect_to templates_url, notice: t(:template_success_added, name: @template.name)
|
28
27
|
else
|
29
|
-
render :
|
28
|
+
render action: :new
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
@@ -34,9 +33,9 @@ module ConstructorPages
|
|
34
33
|
@template = Template.find params[:id]
|
35
34
|
|
36
35
|
if @template.update_attributes params[:template]
|
37
|
-
redirect_to templates_url, :
|
36
|
+
redirect_to templates_url, notice: t(:template_success_updated, name: @template.name)
|
38
37
|
else
|
39
|
-
render :
|
38
|
+
render action: :edit
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
@@ -44,24 +43,9 @@ module ConstructorPages
|
|
44
43
|
@template = Template.find(params[:id])
|
45
44
|
name = @template.name
|
46
45
|
@template.destroy
|
47
|
-
redirect_to templates_url, :
|
46
|
+
redirect_to templates_url, notice: t(:template_success_removed, name: name)
|
48
47
|
end
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
def move_down; move_to :down end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
def move_to(to)
|
57
|
-
from = Template.find(params[:id])
|
58
|
-
to_sibling = to == :up ? from.left_sibling : from.right_sibling
|
59
|
-
|
60
|
-
if not to_sibling.nil? and from.move_possible?(to_sibling)
|
61
|
-
to == :up ? from.move_left : from.move_right
|
62
|
-
end
|
63
|
-
|
64
|
-
redirect_to :back
|
65
|
-
end
|
49
|
+
%w{up down}.each {|m| define_method "move_#{m}" do move_to :template, m.to_sym end}
|
66
50
|
end
|
67
51
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module ConstructorPages
|
2
|
+
module MoveHelper
|
3
|
+
def move_to(what, to)
|
4
|
+
from = ('constructor_pages/'+what.to_s).classify.constantize.find(params[:id])
|
5
|
+
to_sibling = to == :up ? from.left_sibling : from.right_sibling
|
6
|
+
|
7
|
+
if not to_sibling.nil? and from.move_possible?(to_sibling)
|
8
|
+
to == :up ? from.move_left : from.move_right
|
9
|
+
end
|
10
|
+
|
11
|
+
redirect_to :back
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -32,25 +32,27 @@ module ConstructorPages
|
|
32
32
|
def remove_values_for(page); type_model.destroy_all field_id: id, page_id: page.id end
|
33
33
|
|
34
34
|
def update_value(page, params)
|
35
|
-
|
35
|
+
_type_model = type_model.where(field_id: id, page_id: page.id).first_or_create
|
36
36
|
|
37
|
-
if params
|
38
|
-
|
37
|
+
update_type_model(_type_model, type_value, params) if params
|
38
|
+
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
else
|
45
|
-
_type_value.value = params[type_value][id.to_s]
|
46
|
-
end
|
47
|
-
end
|
40
|
+
private
|
41
|
+
|
42
|
+
def update_type_model(type_model, type_value, params)
|
43
|
+
type_model.value = 0 if type_value == 'boolean'
|
48
44
|
|
49
|
-
|
45
|
+
if params[type_value]
|
46
|
+
if type_value == 'date'
|
47
|
+
value = params[type_value][id.to_s]
|
48
|
+
type_model.value = Date.new(value['date(1i)'].to_i, value['date(2i)'].to_i, value['date(3i)'].to_i).to_s
|
49
|
+
else
|
50
|
+
type_model.value = params[type_value][id.to_s]
|
51
|
+
end
|
50
52
|
end
|
51
|
-
end
|
52
53
|
|
53
|
-
|
54
|
+
type_model.save
|
55
|
+
end
|
54
56
|
|
55
57
|
def method_uniqueness
|
56
58
|
if Page.first.respond_to?(code_name) \
|
@@ -67,7 +69,7 @@ module ConstructorPages
|
|
67
69
|
%w{create destroy_all}.each do |m|
|
68
70
|
class_eval %{
|
69
71
|
def #{m}_page_fields
|
70
|
-
pages.each {|page| type_model.#{m} page_id: page.id, field_id: id}
|
72
|
+
template.pages.each {|page| type_model.#{m} page_id: page.id, field_id: id}
|
71
73
|
end
|
72
74
|
}
|
73
75
|
end
|
@@ -27,11 +27,17 @@ module ConstructorPages
|
|
27
27
|
|
28
28
|
acts_as_nested_set
|
29
29
|
|
30
|
+
def self.find_by_request_or_first(request)
|
31
|
+
request.nil? ? Page.first : Page.find_by_full_url('/' + request)
|
32
|
+
end
|
33
|
+
|
30
34
|
# generate full_url from parent page and url
|
31
35
|
def self.full_url_generate(parent_id, url = '')
|
32
36
|
Page.find(parent_id).self_and_ancestors.map {|c| c.url}.append(url).join('/')
|
33
37
|
end
|
34
38
|
|
39
|
+
def active?; active end
|
40
|
+
|
35
41
|
def field(code_name, meth = 'value')
|
36
42
|
field = Field.find_by_code_name_and_template_id code_name, template_id
|
37
43
|
|
@@ -56,6 +62,16 @@ module ConstructorPages
|
|
56
62
|
options
|
57
63
|
end
|
58
64
|
|
65
|
+
# remove all type fields
|
66
|
+
def remove_fields_values
|
67
|
+
fields.each {|f| f.remove_values_for self}
|
68
|
+
end
|
69
|
+
|
70
|
+
# update all type fields
|
71
|
+
def update_fields_values(params)
|
72
|
+
fields.each {|f| f.update_value(self, params)}
|
73
|
+
end
|
74
|
+
|
59
75
|
def method_missing(name, *args, &block)
|
60
76
|
name = name.to_s
|
61
77
|
|
@@ -16,6 +16,15 @@ module ConstructorPages
|
|
16
16
|
|
17
17
|
acts_as_nested_set
|
18
18
|
|
19
|
+
# return child corresponding child_id or children first
|
20
|
+
def child
|
21
|
+
if child_id.nil? and !leaf?
|
22
|
+
children.first
|
23
|
+
else
|
24
|
+
Template.find child_id
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
19
28
|
private
|
20
29
|
|
21
30
|
def method_uniqueness
|
data/config/locales/en.yml
CHANGED
@@ -43,4 +43,8 @@ en:
|
|
43
43
|
template: 'Template'
|
44
44
|
new_template: 'New template'
|
45
45
|
edit_template: 'Edit template'
|
46
|
-
delete_template: 'Delete template'
|
46
|
+
delete_template: 'Delete template'
|
47
|
+
|
48
|
+
template_success_added: 'Template «%{name}» added successfully.'
|
49
|
+
template_success_updated: 'Template «%{name}» updated successfully.'
|
50
|
+
template_success_removed: 'Template «%{name}» removed successfully.'
|
data/config/locales/ru.yml
CHANGED
@@ -45,6 +45,10 @@ ru:
|
|
45
45
|
page_success_updated: 'Страница «%{name}» успешно обновлена.'
|
46
46
|
page_success_removed: 'Страница «%{name}» успешно удалена.'
|
47
47
|
|
48
|
+
template_success_added: 'Шаблон «%{name}» успешно добавлен.'
|
49
|
+
template_success_updated: 'Шаблон «%{name}» успешно обновлен.'
|
50
|
+
template_success_removed: 'Шаблон «%{name}» успешно удален.'
|
51
|
+
|
48
52
|
activerecord:
|
49
53
|
attributes:
|
50
54
|
constructor_pages/field:
|
@@ -169,7 +169,10 @@ module ConstructorPages
|
|
169
169
|
end
|
170
170
|
|
171
171
|
describe 'create_fields' do
|
172
|
-
it 'should create type_fields after update page'
|
172
|
+
it 'should create type_fields after update page' do
|
173
|
+
page = Page.create name: 'Hello fields'
|
174
|
+
|
175
|
+
end
|
173
176
|
end
|
174
177
|
end
|
175
178
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: constructor-pages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: constructor-core
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - '='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.5.
|
21
|
+
version: 0.5.5
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - '='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.5.
|
29
|
+
version: 0.5.5
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: dragonfly
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,6 +156,7 @@ files:
|
|
156
156
|
- app/controllers/constructor_pages/pages_controller.rb
|
157
157
|
- app/controllers/constructor_pages/templates_controller.rb
|
158
158
|
- app/helpers/constructor_pages/fields_helper.rb
|
159
|
+
- app/helpers/constructor_pages/move_helper.rb
|
159
160
|
- app/helpers/constructor_pages/pages_helper.rb
|
160
161
|
- app/helpers/constructor_pages/templates_helper.rb
|
161
162
|
- app/models/constructor_pages/field.rb
|
@@ -185,7 +186,6 @@ files:
|
|
185
186
|
- app/views/constructor_pages/pages/_menu.haml
|
186
187
|
- app/views/constructor_pages/pages/_submenu.haml
|
187
188
|
- app/views/constructor_pages/pages/edit.haml
|
188
|
-
- app/views/constructor_pages/pages/error_404.haml
|
189
189
|
- app/views/constructor_pages/pages/index.haml
|
190
190
|
- app/views/constructor_pages/pages/new.haml
|
191
191
|
- app/views/constructor_pages/pages/show.haml
|
@@ -1,24 +0,0 @@
|
|
1
|
-
!!!
|
2
|
-
%html{'class' => 'no-js', 'lang' => 'en'}
|
3
|
-
%head
|
4
|
-
%meta{'charset' => 'utf-8'}/
|
5
|
-
%meta{'http-equiv' => 'X-UA-Compatible', 'content' => 'IE=edge,chrome=1'}/
|
6
|
-
%title=t :page_not_found
|
7
|
-
|
8
|
-
= stylesheet_link_tag 'styles'
|
9
|
-
= csrf_meta_tag
|
10
|
-
= favicon_link_tag
|
11
|
-
|
12
|
-
%style
|
13
|
-
body { font-family: 'Arial', sans-serif; }
|
14
|
-
|
15
|
-
%body
|
16
|
-
.b-error-404
|
17
|
-
%h1.b-error-404__h1
|
18
|
-
=t :error
|
19
|
-
404
|
20
|
-
%p
|
21
|
-
= link_to t(:homepage), '/', :class => "b-error-404__link-home"
|
22
|
-
%br/
|
23
|
-
= link_to t(:sitemap), "/sitemap"
|
24
|
-
|