knitkit 2.1.3 → 2.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/knitkit/base_controller.rb +1 -0
- data/app/controllers/knitkit/erp_app/desktop/app_controller.rb +2 -0
- data/app/controllers/knitkit/erp_app/desktop/content_controller.rb +2 -2
- data/app/controllers/knitkit/erp_app/desktop/website_nav_controller.rb +17 -7
- data/app/controllers/knitkit/erp_app/desktop/website_section_controller.rb +8 -1
- data/app/controllers/knitkit/online_document_sections_controller.rb +25 -17
- data/app/models/documented_content.rb +3 -3
- data/app/models/online_document_section.rb +1 -0
- data/app/models/published_website.rb +18 -11
- data/app/models/website.rb +49 -28
- data/app/models/website_nav_item.rb +12 -0
- data/app/models/website_section.rb +1 -3
- data/app/views/knitkit/online_document_sections/index.html.erb +77 -46
- data/app/views/layouts/knitkit/online_document_sections.html.erb +13 -14
- data/app/widgets/login/base.rb +1 -1
- data/config/routes.rb +1 -1
- data/db/migrate/20110211002317_setup_knitkit.rb +1 -0
- data/db/migrate/20130405184234_add_use_markdown_to_section.rb +19 -0
- data/lib/knitkit/extensions/railties/action_view/helpers/knitkit_helper.rb +1 -1
- data/lib/knitkit/extensions/railties/action_view/helpers/menu_helper.rb +0 -1
- data/lib/knitkit/version.rb +1 -1
- data/public/javascripts/erp_app/desktop/applications/knitkit/articles_grid_panel.js +1 -0
- data/public/javascripts/erp_app/desktop/applications/knitkit/center_region.js +109 -26
- data/public/javascripts/erp_app/desktop/applications/knitkit/section_articles_grid_panel.js +60 -61
- data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/document.js +26 -0
- data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/menu.js +3 -2
- data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/section.js +9 -24
- data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/website_nav_items.js +232 -248
- data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/west_region.js +33 -43
- metadata +19 -3
- data/public/stylesheets/knitkit/documentation.css +0 -50
@@ -33,6 +33,7 @@ module Knitkit
|
|
33
33
|
@website_section = WebsiteSection.find(params[:section_id])
|
34
34
|
if @website_section.protected_with_capability?(:view)
|
35
35
|
if !current_user and @website_section.path != @login_path
|
36
|
+
session[:return_to_url] = @website_section.path
|
36
37
|
redirect_to @login_path
|
37
38
|
elsif current_user and !current_user.has_capability?(:view, @website_section)
|
38
39
|
redirect_to Knitkit::Config.unauthorized_url
|
@@ -90,6 +90,7 @@ module Knitkit
|
|
90
90
|
:canAddMenuItems => true,
|
91
91
|
:websiteId => website.id,
|
92
92
|
:isSecured => item.is_secured?,
|
93
|
+
:roles => item.roles.collect{|item| item.internal_identifier},
|
93
94
|
:linkedToId => linked_to_item_id,
|
94
95
|
:websiteNavItemId => item.id,
|
95
96
|
:url => url,
|
@@ -114,6 +115,7 @@ module Knitkit
|
|
114
115
|
:roles => website_section.roles.collect{|item| item.internal_identifier},
|
115
116
|
:isSection => website_section.is_section?,
|
116
117
|
:isDocument => website_section.is_document_section?,
|
118
|
+
:useMarkdown => website_section.use_markdown,
|
117
119
|
:inMenu => website_section.in_menu,
|
118
120
|
:renderWithBaseLayout => website_section.render_base_layout?,
|
119
121
|
:hasLayout => !website_section.layout.blank?,
|
@@ -13,7 +13,7 @@ module Knitkit
|
|
13
13
|
content.body_html = html
|
14
14
|
|
15
15
|
if content.save
|
16
|
-
|
16
|
+
unless params[:site_id].blank?
|
17
17
|
website = Website.find(params[:site_id])
|
18
18
|
content.publish(website, 'Auto Publish', content.version, current_user) if website.publish_on_save?
|
19
19
|
end
|
@@ -40,7 +40,7 @@ module Knitkit
|
|
40
40
|
content.excerpt_html = html
|
41
41
|
|
42
42
|
if content.save
|
43
|
-
|
43
|
+
unless params[:site_id].blank?
|
44
44
|
website = Website.find(params[:site_id])
|
45
45
|
content.publish(website, 'Auto Publish', content.version, current_user) if website.publish_on_save?
|
46
46
|
end
|
@@ -93,6 +93,7 @@ module Knitkit
|
|
93
93
|
:websiteId => website_nav.website.id,
|
94
94
|
:url => url,
|
95
95
|
:isSecure => false,
|
96
|
+
:roles => [],
|
96
97
|
:canAddMenuItems => true,
|
97
98
|
:websiteNavItemId => website_nav_item.id,
|
98
99
|
:iconCls => 'icon-document',
|
@@ -155,18 +156,27 @@ module Knitkit
|
|
155
156
|
if current_user.has_capability?('secure', 'WebsiteNavItem') or current_user.has_capability?('unsecure', 'WebsiteNavItem')
|
156
157
|
website_nav_item = WebsiteNavItem.find(params[:id])
|
157
158
|
|
158
|
-
|
159
|
-
|
160
|
-
|
159
|
+
roles = []
|
160
|
+
|
161
|
+
#get roles
|
162
|
+
params.each do |k, v|
|
163
|
+
if v == 'on'
|
164
|
+
roles.push(k)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
if roles.empty?
|
169
|
+
website_nav_item.remove_capability(:view)
|
170
|
+
else
|
171
|
+
capability = website_nav_item.add_capability(:view)
|
172
|
+
capability.remove_all_roles
|
161
173
|
roles.each do |r|
|
162
174
|
role = SecurityRole.find_by_internal_identifier(r)
|
163
|
-
role.add_capability(
|
175
|
+
role.add_capability(capability)
|
164
176
|
end
|
165
|
-
else
|
166
|
-
website_nav_item.remove_capability(:view)
|
167
177
|
end
|
168
178
|
|
169
|
-
render :json => {:success => true}
|
179
|
+
render :json => {:success => true, :secured => website_nav_item.is_secured?, :roles => website_nav_item.roles.collect{|item| item.internal_identifier}}
|
170
180
|
else
|
171
181
|
render :json => {:success => false, :message => "User does not have capability."}
|
172
182
|
end
|
@@ -14,7 +14,6 @@ module Knitkit
|
|
14
14
|
result = {:success => false, :message => 'Blog can not be the title of a Blog'}
|
15
15
|
else
|
16
16
|
website_section = WebsiteSection.new
|
17
|
-
website_section.website_id = website.id
|
18
17
|
website_section.in_menu = params[:in_menu] == 'yes'
|
19
18
|
website_section.title = params[:title]
|
20
19
|
website_section.render_base_layout = params[:render_with_base_layout] == 'yes'
|
@@ -26,6 +25,8 @@ module Knitkit
|
|
26
25
|
if params[:website_section_id]
|
27
26
|
parent_website_section = WebsiteSection.find(params[:website_section_id])
|
28
27
|
website_section.move_to_child_of(parent_website_section)
|
28
|
+
else
|
29
|
+
website_section.website_id = website.id
|
29
30
|
end
|
30
31
|
|
31
32
|
if params[:type] == "OnlineDocumentSection"
|
@@ -104,6 +105,12 @@ module Knitkit
|
|
104
105
|
@website_section.render_base_layout = params[:render_with_base_layout] == 'yes'
|
105
106
|
@website_section.internal_identifier = params[:internal_identifier]
|
106
107
|
|
108
|
+
|
109
|
+
#check if this is a OnlineDocumentSection if so set markdown
|
110
|
+
if @website_section.is_a?(OnlineDocumentSection) || @website_section.type == 'OnlineDocumentSection'
|
111
|
+
@website_section.use_markdown = (params[:use_markdown] == 'yes')
|
112
|
+
end
|
113
|
+
|
107
114
|
website = @website_section.website
|
108
115
|
if @website_section.save
|
109
116
|
@website_section.publish(website, 'Auto Publish', @website_section.version, current_user) if website.publish_on_save?
|
@@ -1,45 +1,53 @@
|
|
1
|
+
require 'github/markdown'
|
2
|
+
|
1
3
|
module Knitkit
|
2
4
|
class OnlineDocumentSectionsController < BaseController
|
3
5
|
layout 'knitkit/online_document_sections'
|
4
|
-
|
6
|
+
|
5
7
|
before_filter :find_root
|
6
8
|
before_filter :find_document_sections, :only => :build_tree
|
7
9
|
|
8
10
|
def index
|
9
|
-
|
11
|
+
|
10
12
|
end
|
11
|
-
|
13
|
+
|
12
14
|
def build_tree
|
13
15
|
render :inline => build_document_hash.to_json
|
14
16
|
end
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
|
18
|
+
def get_content
|
19
|
+
document_section = OnlineDocumentSection.find(params[:document_section_id])
|
20
|
+
content = document_section.documented_item_published_content(@active_publication)
|
21
|
+
if document_section.use_markdown and content
|
22
|
+
html = GitHub::Markdown.render_gfm(content.body_html)
|
23
|
+
else
|
24
|
+
html = content ? content.body_html : ''
|
25
|
+
end
|
26
|
+
|
27
|
+
render :json => {:success => true, :html => html}
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
18
32
|
def id_or_node
|
19
33
|
(params[:node].to_i == 0) ? params[:section_id] : params[:node]
|
20
34
|
end
|
21
|
-
|
35
|
+
|
22
36
|
def find_root
|
23
37
|
@root = OnlineDocumentSection.find(params[:section_id])
|
24
|
-
if @root.documented_item_published_content(@active_publication)
|
25
|
-
@root_content = @root.documented_item_published_content(@active_publication).body_html.gsub(/\n/, '<br/>')
|
26
|
-
else
|
27
|
-
@root_content = ""
|
28
|
-
end
|
29
38
|
end
|
30
|
-
|
39
|
+
|
31
40
|
def find_document_sections
|
32
41
|
@document_sections = OnlineDocumentSection.find(id_or_node).positioned_children
|
33
42
|
end
|
34
|
-
|
43
|
+
|
35
44
|
def build_document_hash
|
36
45
|
[].tap do |documents|
|
37
46
|
@document_sections.each do |section|
|
38
|
-
documents <<
|
39
|
-
:leaf => section.leaf, :documented_item_published_content_html => section.documented_item_published_content_html(@active_publication)}
|
47
|
+
documents << {:id => section.id, :title => section.title, :leaf => section.leaf}
|
40
48
|
end
|
41
49
|
end
|
42
50
|
end
|
43
|
-
|
51
|
+
|
44
52
|
end
|
45
53
|
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
class DocumentedContent < Content
|
2
2
|
|
3
|
-
before_save :
|
3
|
+
before_save :check_internal_identifier
|
4
4
|
|
5
5
|
def to_param
|
6
6
|
permalink
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
9
|
+
def check_internal_identifier
|
10
10
|
self.internal_identifier = self.permalink if self.internal_identifier.blank?
|
11
11
|
end
|
12
12
|
|
13
13
|
def content_hash
|
14
|
-
{:id => self.id, :title => self.title, :body_html => self.body_html}
|
14
|
+
{:id => self.id, :title => self.title, :body_html => self.body_html}
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.find_published_by_section(active_publication, website_section)
|
@@ -3,7 +3,7 @@ class PublishedWebsite < ActiveRecord::Base
|
|
3
3
|
|
4
4
|
belongs_to :website
|
5
5
|
belongs_to :published_by, :class_name => "User"
|
6
|
-
has_many
|
6
|
+
has_many :published_elements, :dependent => :destroy
|
7
7
|
|
8
8
|
def published_by_username
|
9
9
|
self.published_by.username rescue ''
|
@@ -16,7 +16,7 @@ class PublishedWebsite < ActiveRecord::Base
|
|
16
16
|
published_website.active = false
|
17
17
|
published_website.save
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
#activate
|
21
21
|
published_website = self.where(:website_id => website.id).where(:version => version).first
|
22
22
|
published_website.active = true
|
@@ -30,18 +30,25 @@ class PublishedWebsite < ActiveRecord::Base
|
|
30
30
|
|
31
31
|
#get a publish sections
|
32
32
|
website_sections = new_publication.website.website_sections
|
33
|
-
website_sections = website_sections | website_sections.collect{|section| section.descendants}.flatten
|
33
|
+
website_sections = website_sections | website_sections.collect { |section| section.descendants }.flatten
|
34
34
|
website_sections.each do |website_section|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
35
|
+
#get nested elements too
|
36
|
+
website_section.self_and_descendants.each do |website_section|
|
37
|
+
if new_publication.published_elements.where('published_element_record_id = ? and (published_element_record_type = ? or published_element_record_type = ?)', website_section.id, website_section.class.to_s, website_section.class.superclass.to_s).first.nil?
|
38
|
+
published_element = PublishedElement.new
|
39
|
+
published_element.published_website = new_publication
|
40
|
+
published_element.published_element_record = website_section
|
41
|
+
published_element.version = website_section.version
|
42
|
+
published_element.published_by = current_user
|
43
|
+
published_element.save
|
44
|
+
end
|
42
45
|
end
|
43
46
|
|
44
|
-
|
47
|
+
if website_section.is_a?(OnlineDocumentSection)
|
48
|
+
elements = elements | [website_section.documented_item.content]
|
49
|
+
else
|
50
|
+
elements = elements | website_section.contents
|
51
|
+
end
|
45
52
|
end
|
46
53
|
|
47
54
|
#make sure all elements have published_element objects
|
data/app/models/website.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
class Website < ActiveRecord::Base
|
2
2
|
attr_protected :created_at, :updated_at
|
3
3
|
|
4
|
-
after_destroy
|
5
|
-
|
4
|
+
after_destroy :remove_sites_directory, :remove_website_role
|
5
|
+
before_destroy :destroy_sections
|
6
|
+
after_create :setup_website
|
6
7
|
|
7
8
|
protected_with_capabilities
|
8
9
|
has_file_assets
|
@@ -24,7 +25,7 @@ class Website < ActiveRecord::Base
|
|
24
25
|
where('role_type_id = ?', RoleType.website_owner)
|
25
26
|
end
|
26
27
|
end
|
27
|
-
has_many :website_sections, :
|
28
|
+
has_many :website_sections, :order => :lft do
|
28
29
|
def paths
|
29
30
|
collect { |website_section| website_section.paths }.flatten
|
30
31
|
end
|
@@ -53,6 +54,18 @@ class Website < ActiveRecord::Base
|
|
53
54
|
|
54
55
|
alias :sections :website_sections
|
55
56
|
alias :hosts :website_hosts
|
57
|
+
|
58
|
+
#We only want to destroy parent sections as better nested set will destroy children for us
|
59
|
+
def destroy_sections
|
60
|
+
parents = []
|
61
|
+
website_sections.each do |section|
|
62
|
+
unless section.child?
|
63
|
+
parents << section
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
parents.each {|parent| parent.destroy}
|
68
|
+
end
|
56
69
|
|
57
70
|
def to_label
|
58
71
|
self.name
|
@@ -208,7 +221,7 @@ class Website < ActiveRecord::Base
|
|
208
221
|
setup_hash[:website_navs] = website_navs.collect do |website_nav|
|
209
222
|
{
|
210
223
|
:name => website_nav.name,
|
211
|
-
:items => website_nav.items.positioned.map { |website_nav_item| build_menu_item_hash
|
224
|
+
:items => website_nav.items.positioned.map { |website_nav_item| website_nav_item.build_menu_item_hash }
|
212
225
|
}
|
213
226
|
end
|
214
227
|
|
@@ -260,7 +273,8 @@ class Website < ActiveRecord::Base
|
|
260
273
|
end
|
261
274
|
|
262
275
|
online_document_sections.each do |online_documented_section|
|
263
|
-
|
276
|
+
extension = online_documented_section.use_markdown == true ? 'md' : 'html'
|
277
|
+
File.open(File.join(documented_contents_path, "#{online_documented_section.internal_identifier}.#{extension}"), 'wb+') { |f| f.puts(online_documented_section.documented_item_published_content_html(active_publication)) }
|
264
278
|
end
|
265
279
|
|
266
280
|
self.files.where("directory like '%/sites/#{self.iid}/images%'").all.each do |image_asset|
|
@@ -452,9 +466,16 @@ class Website < ActiveRecord::Base
|
|
452
466
|
child_website_item = build_menu_item(item)
|
453
467
|
child_website_item.move_to_child_of(website_item)
|
454
468
|
end
|
455
|
-
|
456
|
-
|
457
|
-
|
469
|
+
|
470
|
+
#handle security
|
471
|
+
unless hash[:roles].empty?
|
472
|
+
capability = website_item.add_capability(:view)
|
473
|
+
hash[:roles].each do |role_iid|
|
474
|
+
role = SecurityRole.find_by_internal_identifier(role_iid)
|
475
|
+
role.add_capability(capability)
|
476
|
+
end
|
477
|
+
end
|
478
|
+
|
458
479
|
website_item
|
459
480
|
end
|
460
481
|
|
@@ -497,23 +518,38 @@ class Website < ActiveRecord::Base
|
|
497
518
|
end
|
498
519
|
end
|
499
520
|
if section.is_a? OnlineDocumentSection
|
500
|
-
|
521
|
+
section.use_markdown = hash[:use_markdown]
|
522
|
+
section.save
|
523
|
+
extension_type = hash[:use_markdown] ? 'md' : 'html'
|
524
|
+
entry_data = entries.find { |entry| entry[:type] == 'documented contents' and entry[:name] == "#{section.internal_identifier}.#{extension_type}" }[:data]
|
501
525
|
documented_content = DocumentedContent.create(:title => section.title, :body_html => entry_data)
|
502
526
|
DocumentedItem.create(:documented_content_id => documented_content.id, :online_document_section_id => section.id)
|
503
527
|
end
|
504
528
|
if hash[:online_document_sections]
|
505
529
|
hash[:online_document_sections].each do |section_hash|
|
506
530
|
child_section = build_section(section_hash, entries, website, current_user)
|
531
|
+
child_section.use_markdown = section_hash[:use_markdown]
|
532
|
+
child_section.save
|
507
533
|
child_section.move_to_child_of(section)
|
508
534
|
# CREATE THE DOCUMENTED CONTENT HERE
|
509
|
-
|
535
|
+
extension_type = section_hash[:use_markdown] ? 'md' : 'html'
|
536
|
+
entry_data = entries.find { |entry| entry[:type] == 'documented contents' and entry[:name] == "#{child_section.internal_identifier}.#{extension_type}" }[:data]
|
510
537
|
documented_content = DocumentedContent.create(:title => child_section.title, :body_html => entry_data)
|
511
538
|
DocumentedItem.create(:documented_content_id => documented_content.id, :online_document_section_id => child_section.id)
|
512
539
|
end
|
513
540
|
end
|
514
|
-
|
515
|
-
|
516
|
-
|
541
|
+
|
542
|
+
#handle security
|
543
|
+
if hash[:roles] #if this is a OnlineDocumentSection will not have roles
|
544
|
+
unless hash[:roles].empty?
|
545
|
+
capability = section.add_capability(:view)
|
546
|
+
hash[:roles].each do |role_iid|
|
547
|
+
role = SecurityRole.find_by_internal_identifier(role_iid)
|
548
|
+
role.add_capability(capability)
|
549
|
+
end
|
550
|
+
end
|
551
|
+
end
|
552
|
+
|
517
553
|
section
|
518
554
|
end
|
519
555
|
|
@@ -522,19 +558,4 @@ class Website < ActiveRecord::Base
|
|
522
558
|
def website_role_iid
|
523
559
|
"website_#{self.iid}_access"
|
524
560
|
end
|
525
|
-
|
526
|
-
private
|
527
|
-
|
528
|
-
def build_menu_item_hash(menu_item)
|
529
|
-
{
|
530
|
-
:title => menu_item.title,
|
531
|
-
:url => menu_item.url,
|
532
|
-
:is_secured => menu_item.is_secured?,
|
533
|
-
:linked_to_item_type => menu_item.linked_to_item_type,
|
534
|
-
:linked_to_item_path => menu_item.linked_to_item.nil? ? nil : menu_item.linked_to_item.path,
|
535
|
-
:position => menu_item.position,
|
536
|
-
:items => menu_item.children.collect { |child| build_menu_item_hash(child) }
|
537
|
-
}
|
538
|
-
end
|
539
|
-
|
540
561
|
end
|
@@ -25,4 +25,16 @@ class WebsiteNavItem < ActiveRecord::Base
|
|
25
25
|
self.protected_with_capability?('view')
|
26
26
|
end
|
27
27
|
|
28
|
+
def build_menu_item_hash
|
29
|
+
{
|
30
|
+
:title => self.title,
|
31
|
+
:url => self.url,
|
32
|
+
:roles => self.roles.collect(&:internal_identifier),
|
33
|
+
:linked_to_item_type => self.linked_to_item_type,
|
34
|
+
:linked_to_item_path => self.linked_to_item.nil? ? nil : self.linked_to_item.path,
|
35
|
+
:position => self.position,
|
36
|
+
:items => self.children.collect { |child| child.build_menu_item_hash }
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
28
40
|
end
|
@@ -141,7 +141,7 @@ class WebsiteSection < ActiveRecord::Base
|
|
141
141
|
:type => self.class.to_s,
|
142
142
|
:in_menu => self.in_menu,
|
143
143
|
:articles => [],
|
144
|
-
:
|
144
|
+
:roles => self.roles.collect(&:internal_identifier),
|
145
145
|
:path => self.path,
|
146
146
|
:permalink => self.permalink,
|
147
147
|
:internal_identifier => self.internal_identifier,
|
@@ -191,8 +191,6 @@ class WebsiteSection < ActiveRecord::Base
|
|
191
191
|
self.internal_identifier = self.permalink if self.internal_identifier.blank?
|
192
192
|
end
|
193
193
|
|
194
|
-
|
195
|
-
|
196
194
|
private
|
197
195
|
|
198
196
|
def self.get_published_version(active_publication, content)
|