constructor-pages 0.8.5 → 0.8.6
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.
- checksums.yaml +4 -4
- data/app/controllers/constructor_pages/pages_controller.rb +6 -11
- data/app/controllers/constructor_pages/templates_controller.rb +1 -2
- data/app/helpers/constructor_pages/treeview_helper.rb +3 -1
- data/app/models/constructor_pages/field.rb +3 -0
- data/app/models/constructor_pages/page.rb +1 -1
- data/app/models/constructor_pages/template.rb +1 -1
- data/app/views/constructor_pages/fields/types/_image.haml +2 -2
- data/app/views/constructor_pages/pages/index.haml +0 -6
- data/app/views/constructor_pages/templates/_form.haml +1 -6
- data/config/locales/en.yml +1 -0
- data/config/locales/ru.yml +2 -0
- data/config/routes.rb +2 -6
- data/db/migrate/14_remove_child_id_from_templates.rb +9 -0
- data/spec/features/constructor_pages/pages_spec.rb +3 -32
- data/spec/features/constructor_pages/templates_spec.rb +1 -2
- data/spec/features/constructor_pages/types/image_type_spec.rb +41 -0
- data/spec/models/constructor_pages/field_spec.rb +13 -0
- data/spec/models/constructor_pages/template_spec.rb +0 -13
- metadata +7 -5
- data/app/views/constructor_pages/pages/new_child.haml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27f76c8e1756acf621e7a34dae4b7b798feb78f8
|
4
|
+
data.tar.gz: 046ce61e61f77fea4d4d79e845cc2532443db873
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35da98b6fb19281f2805672469f3d3ce5bda0cfaaa36177c8ba54ff777b6e266e6a051e63265fed720786e42dbaf119912ac4a8187c9d9d137e6726dfc39a747
|
7
|
+
data.tar.gz: cc53c47824bc38ca8b93dea6595116a9de302faf124be0abb50681e9b4b182b32d467d36732723780d23ae59b0b72159c2ff3e3f70f82212bc1453829e4a30e2
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module ConstructorPages
|
4
4
|
class PagesController < ApplicationController
|
5
|
-
layout 'constructor_core/application_core', except: [:show
|
5
|
+
layout 'constructor_core/application_core', except: [:show]
|
6
6
|
|
7
7
|
movable :page
|
8
8
|
|
@@ -10,7 +10,7 @@ module ConstructorPages
|
|
10
10
|
|
11
11
|
def index
|
12
12
|
@pages = Page.includes(:template).load
|
13
|
-
@pages_cache = Digest::MD5.hexdigest(@pages.map{|p| [p.name, p.full_url, p.in_url, p.lft, p.template_id]}.join)
|
13
|
+
@pages_cache = Digest::MD5.hexdigest(@pages.map{|p| [p.name, p.full_url, p.in_url, p.template.lft, p.lft, p.template_id]}.join)
|
14
14
|
@template_exists = Template.count != 0
|
15
15
|
flash[:notice] = 'Create at least one template' unless @template_exists
|
16
16
|
end
|
@@ -19,22 +19,17 @@ module ConstructorPages
|
|
19
19
|
@page = Page.new
|
20
20
|
end
|
21
21
|
|
22
|
-
def new_child
|
23
|
-
@page, @parent_id = Page.new, params[:id]
|
24
|
-
@template_id = Page.find(@parent_id).try(:template).try(:child).try(:id)
|
25
|
-
end
|
26
|
-
|
27
22
|
def show
|
28
23
|
@page = Page.find_by_request_or_first("/#{params[:all]}")
|
29
24
|
error_404 and return unless @page.try(:published?)
|
30
25
|
redirect_to @page.link if @page.redirect?
|
31
26
|
_code_name = @page.template.code_name
|
32
27
|
instance_variable_set('@'+_code_name, @page)
|
33
|
-
|
28
|
+
|
34
29
|
respond_to do |format|
|
35
|
-
format.html { render "#{_code_name}/show" }
|
36
|
-
format.json { render "#{_code_name}/show.json", layout: false rescue render json: @page }
|
37
|
-
format.xml { render "#{_code_name}/show.xml", layout: false rescue render xml: @page }
|
30
|
+
format.html { render "#{_code_name.pluralize}/show" rescue render "templates/#{_code_name}"}
|
31
|
+
format.json { render "#{_code_name.pluralize}/show.json", layout: false rescue render json: @page }
|
32
|
+
format.xml { render "#{_code_name.pluralize}/show.xml", layout: false rescue render xml: @page }
|
38
33
|
end
|
39
34
|
end
|
40
35
|
|
@@ -6,10 +6,9 @@ module ConstructorPages
|
|
6
6
|
|
7
7
|
movable :template
|
8
8
|
|
9
|
-
before_filter -> {@
|
9
|
+
before_filter -> {@templates = Template.all}, only: [:index, :new, :edit, :update, :create]
|
10
10
|
|
11
11
|
def index
|
12
|
-
@templates = Template.all
|
13
12
|
@templates_cache = Digest::MD5.hexdigest(@templates.map{|t| [t.name, t.lft]}.join)
|
14
13
|
end
|
15
14
|
|
@@ -17,7 +17,9 @@ module ConstructorPages
|
|
17
17
|
def for_select(items, full_url = false)
|
18
18
|
result = []
|
19
19
|
items && items.each do |i|
|
20
|
-
|
20
|
+
arr = ["#{'--'*i.level} #{i.name}", i.id]
|
21
|
+
arr << {'data-full_url' => i.full_url} if full_url
|
22
|
+
result.push(arr)
|
21
23
|
end
|
22
24
|
result
|
23
25
|
end
|
@@ -33,6 +33,9 @@ module ConstructorPages
|
|
33
33
|
# Create object of type_value by page
|
34
34
|
def create_type_object(page); type_class.create(field_id: id, page_id: page.id) end
|
35
35
|
|
36
|
+
# Find or create type object by page
|
37
|
+
def find_or_create_type_object(page); find_type_object(page) || create_type_object(page) end
|
38
|
+
|
36
39
|
# Remove all type_fields values for specified page
|
37
40
|
def remove_type_object(page); find_type_object(page).destroy end
|
38
41
|
|
@@ -129,7 +129,7 @@ module ConstructorPages
|
|
129
129
|
def update_fields_values(params, reset_booleans = true)
|
130
130
|
params || return
|
131
131
|
|
132
|
-
fields.each {|f| f.
|
132
|
+
fields.each {|f| f.find_or_create_type_object(self).tap {|t| t || next
|
133
133
|
t.value = 0 if f.type_value == 'boolean' && reset_booleans
|
134
134
|
params[f.code_name.to_sym].tap {|v| v && t.value = v}
|
135
135
|
t.save }}
|
@@ -26,12 +26,6 @@
|
|
26
26
|
=t :edit
|
27
27
|
= page.template.to_accusative
|
28
28
|
|
29
|
-
- if page.template.child
|
30
|
-
= link_to new_child_page_path(page), class: 'btn btn-success btn-mini' do
|
31
|
-
%i.icon-chevron-down
|
32
|
-
=t :add
|
33
|
-
= page.template.child.to_accusative
|
34
|
-
|
35
29
|
= link_to page, method: :delete, class: 'btn btn-danger btn-mini pull-right', data: {confirm: t(:are_you_sure?)} do
|
36
30
|
%i.icon-remove
|
37
31
|
=t :delete
|
@@ -18,12 +18,7 @@
|
|
18
18
|
.control-group
|
19
19
|
= f.label :parent_id, class: 'control-label'
|
20
20
|
.controls
|
21
|
-
= f.select :parent_id, options_for_select(for_select(@
|
22
|
-
|
23
|
-
.control-group
|
24
|
-
= f.label :child_id, class: 'control-label'
|
25
|
-
.controls
|
26
|
-
= f.select :child_id, options_for_select(for_select(@roots), selected: @template.child_id), include_blank: t(:no)
|
21
|
+
= f.select :parent_id, options_for_select(for_select(@templates), selected: @template.parent_id), disabled: @template.self_and_descendants.map(&:id), include_blank: t(:no)
|
27
22
|
|
28
23
|
- unless @template.new_record?
|
29
24
|
.control-group
|
data/config/locales/en.yml
CHANGED
data/config/locales/ru.yml
CHANGED
@@ -8,6 +8,7 @@ ru:
|
|
8
8
|
are_you_sure?: Вы уверены?
|
9
9
|
display_in: Отображать в
|
10
10
|
delete: Удалить
|
11
|
+
url: "Адрес"
|
11
12
|
|
12
13
|
menu: Меню
|
13
14
|
breadcrumbs: Хлебные крошки
|
@@ -74,6 +75,7 @@ ru:
|
|
74
75
|
in_menu: "Меню"
|
75
76
|
in_nav: "Хлебные крошки"
|
76
77
|
in_map: "Карта сайта"
|
78
|
+
in_url: "Адрес"
|
77
79
|
parent: "Родитель"
|
78
80
|
parent_id: "Родительская страница"
|
79
81
|
link: "Ссылка"
|
data/config/routes.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
ConstructorPages::Engine.routes.draw do
|
2
2
|
scope '/admin' do
|
3
|
-
resources :pages, except: [:show]
|
4
|
-
get :new_child, on: :member
|
5
|
-
end
|
6
|
-
|
3
|
+
resources :pages, except: [:show]
|
7
4
|
resources :templates, except: [:show] do
|
8
5
|
resources :fields, except: [:show, :index]
|
9
6
|
end
|
@@ -17,6 +14,5 @@ ConstructorPages::Engine.routes.draw do
|
|
17
14
|
|
18
15
|
root :to => 'pages#show'
|
19
16
|
|
20
|
-
get '*all.:format' => 'pages#show'
|
21
|
-
get '*all' => 'pages#show'
|
17
|
+
get '*all(.:format)' => 'pages#show', format: /(html|json|xml)/
|
22
18
|
end
|
@@ -74,19 +74,6 @@ module ConstructorPages
|
|
74
74
|
visit pages.pages_path
|
75
75
|
page.should have_link 'Delete', pages.page_path(_page)
|
76
76
|
end
|
77
|
-
|
78
|
-
it 'should has Add child if child exists' do
|
79
|
-
_template = Template.create name: 'Child', code_name: 'child_page', parent: @template
|
80
|
-
_page = Page.create name: 'Zanussi', template: @template
|
81
|
-
visit pages.pages_path
|
82
|
-
page.should have_link 'Add child', pages.new_page_path(_page)
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'should not has if child not exists' do
|
86
|
-
_page = Page.create name: 'Zanussi', template: @template
|
87
|
-
visit pages.pages_path
|
88
|
-
page.should have_no_link 'Add'
|
89
|
-
end
|
90
77
|
end
|
91
78
|
|
92
79
|
describe 'Show' do
|
@@ -164,22 +151,6 @@ module ConstructorPages
|
|
164
151
|
end
|
165
152
|
end
|
166
153
|
|
167
|
-
it 'should has child template of parent page' do
|
168
|
-
_template = Template.create name: 'Child', code_name: 'child_page', parent: @template
|
169
|
-
_page = Page.create name: 'Zanussi', template: @template
|
170
|
-
visit pages.pages_path
|
171
|
-
click_link 'Add child'
|
172
|
-
current_path.should == pages.new_child_page_path(_page)
|
173
|
-
page.should have_select 'Template', selected: '-- Child'
|
174
|
-
end
|
175
|
-
|
176
|
-
it 'should edit with page view if no view found' do
|
177
|
-
_template = Template.create name: 'Hello', code_name: 'hello'
|
178
|
-
_page = Page.create name: 'Hello', template: _template
|
179
|
-
visit pages.new_child_page_path(_page)
|
180
|
-
page.should_not have_content 'This page show new with template'
|
181
|
-
end
|
182
|
-
|
183
154
|
it 'should has published checkbox' do
|
184
155
|
visit pages.new_page_path
|
185
156
|
page.should have_checked_field 'Active'
|
@@ -266,7 +237,7 @@ module ConstructorPages
|
|
266
237
|
page.should have_text 'updated successfully'
|
267
238
|
end
|
268
239
|
|
269
|
-
describe '
|
240
|
+
describe 'regenerate descendants' do
|
270
241
|
before :each do
|
271
242
|
_template = Template.create name: 'Another page', code_name: 'another_page'
|
272
243
|
_page_first = Page.create name: 'First', template: _template
|
@@ -282,7 +253,7 @@ module ConstructorPages
|
|
282
253
|
end
|
283
254
|
|
284
255
|
it 'should regenerate full_url of descendants without url if full_url or in_url changed' do
|
285
|
-
|
256
|
+
uncheck 'URL'
|
286
257
|
click_button 'Update Page'
|
287
258
|
|
288
259
|
page.should have_link('First', '/first')
|
@@ -291,7 +262,7 @@ module ConstructorPages
|
|
291
262
|
end
|
292
263
|
|
293
264
|
it 'should regenerate full_url of descendants with url if full_url or in_url changed' do
|
294
|
-
|
265
|
+
uncheck 'URL'
|
295
266
|
click_button 'Update Page'
|
296
267
|
|
297
268
|
page.should have_link('First', '/first')
|
@@ -133,10 +133,9 @@ module ConstructorPages
|
|
133
133
|
page.should have_field 'Code name'
|
134
134
|
end
|
135
135
|
|
136
|
-
it 'should has parent
|
136
|
+
it 'should has parent select' do
|
137
137
|
visit pages.new_template_path
|
138
138
|
page.should have_select 'Parent'
|
139
|
-
page.should have_select 'Child'
|
140
139
|
end
|
141
140
|
|
142
141
|
it 'should not has link new field' do
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module ConstructorPages
|
6
|
+
describe 'Image type field' do
|
7
|
+
before :all do
|
8
|
+
ConstructorCore::User.delete_all
|
9
|
+
@user = ConstructorCore::User.create email: 'ivanzotov@gmail.com', password: '123qweASD'
|
10
|
+
end
|
11
|
+
|
12
|
+
before :each do
|
13
|
+
Page.delete_all
|
14
|
+
Field.delete_all
|
15
|
+
Template.delete_all
|
16
|
+
|
17
|
+
Field::TYPES.each do |t|
|
18
|
+
"constructor_pages/types/#{t}_type".classify.constantize.delete_all
|
19
|
+
end
|
20
|
+
|
21
|
+
@template = Template.create name: 'Brand', code_name: 'brand'
|
22
|
+
|
23
|
+
login_as @user
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should upload image' do
|
27
|
+
field = Field.create name: 'Logo', code_name: 'logo', type_value: 'image', template: @template
|
28
|
+
_page = Page.create name: 'Zanussi'
|
29
|
+
|
30
|
+
visit pages.edit_page_path(_page)
|
31
|
+
page.should have_content('Logo')
|
32
|
+
attach_file('Logo', Rails.root.to_s+'/app/assets/images/upload_image.png')
|
33
|
+
click_button 'Update Page'
|
34
|
+
_page.reload
|
35
|
+
_page.logo.should_not be_nil
|
36
|
+
visit pages.edit_page_path(_page)
|
37
|
+
save_and_open_page
|
38
|
+
page.should have_selector('img[alt="Upload image"]')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -72,6 +72,19 @@ module ConstructorPages
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
+
describe '#find_or_create_type_object' do
|
76
|
+
it 'should find or create object of type_value by page' do
|
77
|
+
field = Field.create name: 'Logo', code_name: 'logo', template: @template, type_value: 'image'
|
78
|
+
page = Page.create name: 'Page', template: @template
|
79
|
+
image_type = field.find_type_object(page)
|
80
|
+
image_type.should be_nil
|
81
|
+
image_type = field.find_or_create_type_object(page)
|
82
|
+
image_type.should be_an_instance_of(Types::ImageType)
|
83
|
+
image_type.page_id.should == page.id
|
84
|
+
image_type.field_id.should == field.id
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
75
88
|
describe '#remove_type_object' do
|
76
89
|
it 'should remote object of type_value by page' do
|
77
90
|
field = Field.create name: 'Content', code_name: 'content', template: @template, type_value: 'text'
|
@@ -17,18 +17,5 @@ module ConstructorPages
|
|
17
17
|
_template = Template.create name: 'Page', code_name: 'get_field_value'
|
18
18
|
_template.valid?.should be_false
|
19
19
|
end
|
20
|
-
|
21
|
-
describe '#child' do
|
22
|
-
it 'should return child corresponding child_id or children first' do
|
23
|
-
_brand = Template.create name: 'Brand', code_name: 'brand'
|
24
|
-
_series = Template.create name: 'Series', code_name: 'series', parent: _brand
|
25
|
-
_brand.reload
|
26
|
-
|
27
|
-
_brand.child.should == _series
|
28
|
-
_brand.child_id = _brand.id
|
29
|
-
|
30
|
-
_brand.child.should == _brand
|
31
|
-
end
|
32
|
-
end
|
33
20
|
end
|
34
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: constructor-pages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Zotov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: constructor-core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.8.
|
19
|
+
version: 0.8.6
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.8.
|
26
|
+
version: 0.8.6
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: dragonfly
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -173,7 +173,6 @@ files:
|
|
173
173
|
- app/views/constructor_pages/pages/edit.haml
|
174
174
|
- app/views/constructor_pages/pages/index.haml
|
175
175
|
- app/views/constructor_pages/pages/new.haml
|
176
|
-
- app/views/constructor_pages/pages/new_child.haml
|
177
176
|
- app/views/constructor_pages/templates/_form.haml
|
178
177
|
- app/views/constructor_pages/templates/edit.haml
|
179
178
|
- app/views/constructor_pages/templates/index.haml
|
@@ -188,6 +187,7 @@ files:
|
|
188
187
|
- db/migrate/11_create_image_types.rb
|
189
188
|
- db/migrate/12_add_default_template.rb
|
190
189
|
- db/migrate/13_add_in_url_to_pages.rb
|
190
|
+
- db/migrate/14_remove_child_id_from_templates.rb
|
191
191
|
- db/migrate/1_create_pages.rb
|
192
192
|
- db/migrate/2_create_templates.rb
|
193
193
|
- db/migrate/3_create_fields.rb
|
@@ -203,6 +203,7 @@ files:
|
|
203
203
|
- spec/features/constructor_pages/fields_spec.rb
|
204
204
|
- spec/features/constructor_pages/pages_spec.rb
|
205
205
|
- spec/features/constructor_pages/templates_spec.rb
|
206
|
+
- spec/features/constructor_pages/types/image_type_spec.rb
|
206
207
|
- spec/helpers/constructor_pages/.keep
|
207
208
|
- spec/models/constructor_pages/field_spec.rb
|
208
209
|
- spec/models/constructor_pages/page_spec.rb
|
@@ -243,6 +244,7 @@ test_files:
|
|
243
244
|
- spec/features/constructor_pages/fields_spec.rb
|
244
245
|
- spec/features/constructor_pages/pages_spec.rb
|
245
246
|
- spec/features/constructor_pages/templates_spec.rb
|
247
|
+
- spec/features/constructor_pages/types/image_type_spec.rb
|
246
248
|
- spec/helpers/constructor_pages/.keep
|
247
249
|
- spec/models/constructor_pages/field_spec.rb
|
248
250
|
- spec/models/constructor_pages/page_spec.rb
|