knitkit 2.1.9 → 2.1.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/app/controllers/knitkit/erp_app/desktop/image_assets_controller.rb +2 -2
  2. data/app/controllers/knitkit/online_document_sections_controller.rb +26 -16
  3. data/app/models/content.rb +52 -42
  4. data/app/models/documented_content.rb +57 -3
  5. data/app/models/online_document_section.rb +1 -1
  6. data/app/views/knitkit/online_document_sections/index.html.erb +175 -85
  7. data/app/views/layouts/knitkit/online_document_sections.html.erb +1 -1
  8. data/lib/knitkit/config.rb +3 -2
  9. data/lib/knitkit/version.rb +1 -1
  10. metadata +3 -123
  11. data/spec/dummy/db/data_migrations/20110109173616_create_capability_scope_types.erp_tech_svcs.rb +0 -15
  12. data/spec/dummy/db/data_migrations/20110509223702_add_publisher_role.knitkit.rb +0 -22
  13. data/spec/dummy/db/data_migrations/20110525001935_add_usd_currency.erp_base_erp_svcs.rb +0 -12
  14. data/spec/dummy/db/data_migrations/20110608185830_create_default_dynamic_models_and_forms.erp_forms.rb +0 -33
  15. data/spec/dummy/db/data_migrations/20110609150135_add_iso_codes.erp_base_erp_svcs.rb +0 -19
  16. data/spec/dummy/db/data_migrations/20110728201729_erp_app_setup.erp_app.rb +0 -252
  17. data/spec/dummy/db/data_migrations/20110728201733_update_preferences.erp_app.rb +0 -53
  18. data/spec/dummy/db/data_migrations/20110802200222_schedule_delete_expired_sessions_job.erp_tech_svcs.rb +0 -16
  19. data/spec/dummy/db/data_migrations/20110816153456_add_knitkit_application.knitkit.rb +0 -32
  20. data/spec/dummy/db/data_migrations/20110816161238_create_desktop_app_audit_log_viewer.erp_app.rb +0 -21
  21. data/spec/dummy/db/data_migrations/20110817160743_add_file_manager_application.erp_app.rb +0 -32
  22. data/spec/dummy/db/data_migrations/20110828190913_create_desktop_app_dynamic_forms.erp_forms.rb +0 -19
  23. data/spec/dummy/db/data_migrations/20110913145838_setup_compass_ae_instance.erp_base_erp_svcs.rb +0 -12
  24. data/spec/dummy/db/data_migrations/20111108183739_add_default_capabilities.erp_app.rb +0 -23
  25. data/spec/dummy/db/data_migrations/20111108183740_add_new_contact_widgets.erp_app.rb +0 -42
  26. data/spec/dummy/db/data_migrations/20111111144706_setup_audit_log_types.erp_tech_svcs.rb +0 -22
  27. data/spec/dummy/db/data_migrations/20111118182910_setup_knitkit_capabilities.knitkit.rb +0 -128
  28. data/spec/dummy/db/data_migrations/20120127144444_create_website_role_types.knitkit.rb +0 -14
  29. data/spec/dummy/db/data_migrations/20120127150505_create_website_default_configuration.knitkit.rb +0 -73
  30. data/spec/dummy/db/data_migrations/20120127150506_add_primary_host_to_website_configuration.knitkit.rb +0 -34
  31. data/spec/dummy/db/data_migrations/20120229160222_add_userinfo_widget.erp_app.rb +0 -29
  32. data/spec/dummy/db/data_migrations/20120316150424_add_is_template_to_default_website_config.knitkit.rb +0 -17
  33. data/spec/dummy/db/data_migrations/20120405193721_create_party_and_role_type_for_communication_events.erp_app.rb +0 -11
  34. data/spec/dummy/db/data_migrations/20120411180756_create_user_management_mobile_application.erp_app.rb +0 -19
  35. data/spec/dummy/db/data_migrations/20120418164215_create_configuration_management_desktop_application.erp_app.rb +0 -23
  36. data/spec/dummy/db/data_migrations/20120809020508_update_website_and_configuration.knitkit.rb +0 -78
  37. data/spec/dummy/db/data_migrations/20120824013449_create_ticket_form.erp_forms.rb +0 -67
  38. data/spec/dummy/db/data_migrations/20121026013449_update_ticket_form.erp_forms.rb +0 -65
  39. data/spec/dummy/db/data_migrations/20121026191738_update_contact_form.erp_forms.rb +0 -27
  40. data/spec/dummy/db/data_migrations/20121116155018_create_group_relationship_and_role_types.erp_tech_svcs.rb +0 -20
  41. data/spec/dummy/db/data_migrations/20121129185611_upgrade_website_role_iid.knitkit.rb +0 -21
  42. data/spec/dummy/db/data_migrations/20121130201859_upgrade_remove_system_mgmt_app.erp_app.rb +0 -16
  43. data/spec/dummy/db/data_migrations/20121130212146_note_capabilities.erp_tech_svcs.rb +0 -24
  44. data/spec/dummy/db/data_migrations/20121218175028_create_security_management_desktop_application.erp_app.rb +0 -23
  45. data/spec/dummy/db/data_migrations/20130422154409_upgrade_compass_ae_instances_data.erp_base_erp_svcs.rb +0 -19
  46. data/spec/dummy/db/data_migrations/20130422154410_add_guid_to_instances.erp_base_erp_svcs.rb +0 -10
  47. data/spec/dummy/db/data_migrations/20130422154411_create_job_tracker_desktop_application.erp_app.rb +0 -23
  48. data/spec/dummy/db/data_migrations/20130422154412_created_tracked_jobs.erp_app.rb +0 -15
  49. data/spec/dummy/db/data_migrations/20130422154413_add_job_tracker_mobile_app.erp_app.rb +0 -17
  50. data/spec/dummy/db/migrate/20130107153232_base_erp_services.erp_base_erp_svcs.rb +0 -461
  51. data/spec/dummy/db/migrate/20130107153233_base_tech_services.erp_tech_svcs.rb +0 -271
  52. data/spec/dummy/db/migrate/20130107153234_create_has_attribute_tables.erp_tech_svcs.rb +0 -39
  53. data/spec/dummy/db/migrate/20130107153235_create_groups.erp_tech_svcs.rb +0 -19
  54. data/spec/dummy/db/migrate/20130107153236_upgrade_security.erp_tech_svcs.rb +0 -54
  55. data/spec/dummy/db/migrate/20130107153237_upgrade_security2.erp_tech_svcs.rb +0 -270
  56. data/spec/dummy/db/migrate/20130107153238_base_app_framework.erp_app.rb +0 -276
  57. data/spec/dummy/db/migrate/20130107153239_dynamic_forms.erp_forms.rb +0 -95
  58. data/spec/dummy/db/migrate/20130107153240_create_tickets.erp_forms.rb +0 -19
  59. data/spec/dummy/db/migrate/20130107153241_upgrade_dynamic_forms_table.erp_forms.rb +0 -32
  60. data/spec/dummy/db/migrate/20130107153242_setup_knitkit.knitkit.rb +0 -316
  61. data/spec/dummy/db/migrate/20130422154401_add_txn_status.erp_base_erp_svcs.rb +0 -37
  62. data/spec/dummy/db/migrate/20130422154402_upgrade_compass_ae_instances.erp_base_erp_svcs.rb +0 -34
  63. data/spec/dummy/db/migrate/20130422154403_add_uuid_compass_ae_instance.erp_base_erp_svcs.rb +0 -17
  64. data/spec/dummy/db/migrate/20130422154404_add_long_lat_to_address.erp_base_erp_svcs.rb +0 -16
  65. data/spec/dummy/db/migrate/20130422154405_add_queue_to_delayed_jobs.erp_tech_svcs.rb +0 -14
  66. data/spec/dummy/db/migrate/20130422154406_add_job_tracker.erp_app.rb +0 -20
  67. data/spec/dummy/db/migrate/20130422154407_update_mobile_application.erp_app.rb +0 -28
  68. data/spec/dummy/db/migrate/20130422154408_add_use_markdown_to_section.knitkit.rb +0 -20
  69. data/spec/dummy/db/schema.rb +0 -1248
  70. data/spec/dummy/db/spec.sqlite3 +0 -0
@@ -94,9 +94,9 @@ module Knitkit
94
94
  @root_node = nil
95
95
 
96
96
  if @context == :website
97
- @root_node = File.join("public", "sites", @assets_model.iid, "images") unless @assets_model.nil?
97
+ @root_node = File.join(Rails.application.config.knitkit.images_path, "sites", @assets_model.iid, "images") unless @assets_model.nil?
98
98
  else
99
- @root_node = File.join("public", "images")
99
+ @root_node = File.join(Rails.application.config.knitkit.images_base_path, 'images')
100
100
  end
101
101
 
102
102
  @root_node
@@ -1,16 +1,33 @@
1
1
  module Knitkit
2
2
  class OnlineDocumentSectionsController < BaseController
3
+ include ActionView::Helpers::SanitizeHelper
4
+
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
11
+ @online_document = OnlineDocumentSection.find(params[:section_id])
12
+ @online_document = nil if @online_document.id == find_root.id
13
+ end
14
+
15
+ def search
16
+ html = ''
17
+ results = DocumentedContent.search({:query => params[:query].strip,
18
+ :content_type => 'OnlineDocumentSection',
19
+ :parent_id => params[:section_id],
20
+ :website_id => @website.id})
21
+
22
+ DocumentedContent.build_search_results(results).each do |result|
23
+ html << "<p><a href=\"javascript:findShowAndExpandNode('#{result[:internal_identifier]}');\">#{result[:title]}</a><p style='border:solid 2px #CCC;padding:2px;'>#{strip_tags(result[:content].body_html[0..500])}...</p></p>"
24
+ end
9
25
 
26
+ render :json => {:success => true, :html => html}
10
27
  end
11
28
 
12
29
  def build_tree
13
- render :inline => build_document_hash.to_json
30
+ render :json => @document_sections.collect { |document| build_document_hash(document) }
14
31
  end
15
32
 
16
33
  def get_content
@@ -27,27 +44,20 @@ module Knitkit
27
44
 
28
45
  protected
29
46
 
30
- def id_or_node
31
- (params[:node].to_i == 0) ? params[:section_id] : params[:node]
32
- end
33
-
34
47
  def find_root
35
- @root = OnlineDocumentSection.find(params[:section_id])
48
+ @root = OnlineDocumentSection.find(params[:section_id]).root
36
49
  end
37
50
 
38
51
  def find_document_sections
39
- @document_sections = OnlineDocumentSection.find(id_or_node).positioned_children
52
+ @document_sections = find_root.positioned_children
40
53
  end
41
54
 
42
- def build_document_hash
43
- [].tap do |documents|
44
- @document_sections.each do |section|
45
- documents << {:id => section.id,
46
- :title => section.title,
47
- :leaf => section.leaf,
48
- :iconCls => (section.leaf ? 'icon-documentation-document' : 'icon-documentation-multi-document')}
49
- end
50
- end
55
+ def build_document_hash(document_section)
56
+ {:id => document_section.internal_identifier,
57
+ :title => document_section.title,
58
+ :leaf => document_section.leaf,
59
+ :iconCls => (document_section.leaf ? 'icon-documentation-document' : 'icon-documentation-multi-document'),
60
+ :children => document_section.positioned_children.collect { |child_document_section| build_document_hash(child_document_section) }}
51
61
  end
52
62
 
53
63
  end
@@ -5,6 +5,7 @@ class Content < ActiveRecord::Base
5
5
 
6
6
  extend FriendlyId
7
7
  friendly_id :title, :use => [:slugged], :slug_column => :permalink
8
+
8
9
  def should_generate_new_friendly_id?
9
10
  new_record?
10
11
  end
@@ -13,7 +14,7 @@ class Content < ActiveRecord::Base
13
14
 
14
15
  acts_as_taggable
15
16
  acts_as_commentable
16
- acts_as_versioned :table_name => :content_versions
17
+ acts_as_versioned :table_name => :content_versions
17
18
  can_be_published
18
19
  has_relational_dynamic_attributes
19
20
 
@@ -21,53 +22,62 @@ class Content < ActiveRecord::Base
21
22
  has_many :website_sections, :through => :website_section_contents
22
23
  belongs_to :created_by, :class_name => "User"
23
24
  belongs_to :updated_by, :class_name => "User"
24
-
25
+
25
26
  validates :type, :presence => {:message => 'Type cannot be blank'}
26
27
  validates_uniqueness_of :internal_identifier, :case_sensitive => false
27
28
 
28
29
  def self.search(options = {})
29
- if options[:section_unique_name].nil? or options[:section_unique_name].empty?
30
- section_scope = ''
31
- else
32
- section_scope = "website_sections.internal_identifier = '#{options[:section_unique_name]}' AND"
30
+ predicate = Content.includes([:website_sections])
31
+
32
+ if options[:section_unique_name]
33
+ predicate = predicate.where("website_sections.internal_identifier = ?", options[:section_unique_name])
33
34
  end
34
35
 
35
- if options[:content_type].nil? or options[:content_type].empty?
36
- content_type_scope = ''
37
- else
38
- content_type_scope = "website_sections.type = '#{options[:content_type]}' AND"
36
+ if options[:parent_id]
37
+ predicate = predicate.where("website_sections.id" => WebsiteSection.find(options[:parent_id]).self_and_descendants.collect(&:id))
39
38
  end
40
-
41
- Content.includes([:website_sections]).where("#{content_type_scope} #{section_scope}
42
- website_sections.website_id = #{options[:website_id]} AND
43
- (UPPER(contents.title) LIKE UPPER('%#{options[:query]}%')
39
+
40
+ if options[:content_type]
41
+ predicate = predicate.where("website_sections.type = ?", options[:content_type])
42
+ end
43
+
44
+ if options[:website_id]
45
+ predicate = predicate.where("website_sections.website_id = ?", options[:website_id])
46
+ end
47
+
48
+ predicate = predicate.where("(UPPER(contents.title) LIKE UPPER('%#{options[:query]}%')
44
49
  OR UPPER(contents.excerpt_html) LIKE UPPER('%#{options[:query]}%')
45
- OR UPPER(contents.body_html) LIKE UPPER('%#{options[:query]}%') )").order("contents.created_at DESC").paginate(:page => options[:page], :per_page => options[:per_page])
50
+ OR UPPER(contents.body_html) LIKE UPPER('%#{options[:query]}%') )").order("contents.created_at DESC")
51
+ if options[:page]
52
+ predicate.paginate(:page => options[:page], :per_page => options[:per_page])
53
+ else
54
+ predicate.all
55
+ end
46
56
  end
47
57
 
48
- def self.do_search(options = {})
58
+ def self.do_search(options = {})
49
59
  @results = Content.search(options)
50
60
 
51
- @search_results = build_search_results(@results)
52
-
61
+ @search_results = build_search_results(@results)
62
+
53
63
  @page_results = WillPaginate::Collection.create(options[:page], options[:per_page], @results.total_entries) do |pager|
54
64
  pager.replace(@search_results)
55
65
  end
56
-
57
- return @page_results
66
+
67
+ @page_results
58
68
  end
59
-
60
- def self.find_by_section_id( website_section_id )
69
+
70
+ def self.find_by_section_id(website_section_id)
61
71
  Content.joins(:website_section_contents).where('website_section_id = ?', website_section_id).order("website_section_contents.position ASC, website_section_contents.created_at DESC").all
62
72
  end
63
73
 
64
- def self.find_by_section_id_filtered_by_id( website_section_id, id_filter_list )
74
+ def self.find_by_section_id_filtered_by_id(website_section_id, id_filter_list)
65
75
  Content.joins(:website_section_contents).where("website_section_id = ? AND contents.id IN (#{id_filter_list.join(',')})", website_section_id).all
66
76
  end
67
77
 
68
78
  def self.find_published_by_section(active_publication, website_section)
69
79
  published_content = []
70
- contents = self.find_by_section_id( website_section.id )
80
+ contents = self.find_by_section_id(website_section.id)
71
81
  contents.each do |content|
72
82
  content = get_published_version(active_publication, content)
73
83
  published_content << content unless content.nil?
@@ -77,9 +87,9 @@ class Content < ActiveRecord::Base
77
87
  end
78
88
 
79
89
  def self.find_published_by_section_with_tag(active_publication, website_section, tag)
80
- published_content = []
81
- id_filter_list = self.tagged_with(tag.name).collect{|t| t.id }
82
- contents = self.find_by_section_id_filtered_by_id( website_section.id, id_filter_list )
90
+ published_content = []
91
+ id_filter_list = self.tagged_with(tag.name).collect { |t| t.id }
92
+ contents = self.find_by_section_id_filtered_by_id(website_section.id, id_filter_list)
83
93
  contents.each do |content|
84
94
  content = get_published_version(active_publication, content)
85
95
  published_content << content unless content.nil?
@@ -88,11 +98,11 @@ class Content < ActiveRecord::Base
88
98
  published_content
89
99
  end
90
100
 
91
- def find_website_sections_by_site_id( website_id )
92
- self.website_sections.where('website_id = ?',website_id).all
101
+ def find_website_sections_by_site_id(website_id)
102
+ self.website_sections.where('website_id = ?', website_id).all
93
103
  end
94
104
 
95
- def position( website_section_id )
105
+ def position(website_section_id)
96
106
  position = self.website_section_contents.find_by_website_section_id(website_section_id).position
97
107
  position
98
108
  end
@@ -102,7 +112,7 @@ class Content < ActiveRecord::Base
102
112
  end
103
113
 
104
114
  def update_content_area_and_position_by_section(section, content_area, position)
105
- website_section_content = WebsiteSectionContent.where('content_id = ? and website_section_id = ?',self.id, section.id).first
115
+ website_section_content = WebsiteSectionContent.where('content_id = ? and website_section_id = ?', self.id, section.id).first
106
116
  unless website_section_content.nil?
107
117
  website_section_content.content_area = content_area
108
118
  website_section_content.position = position
@@ -112,16 +122,16 @@ class Content < ActiveRecord::Base
112
122
 
113
123
  def content_area_by_website_section(section)
114
124
  content_area = nil
115
- unless WebsiteSectionContent.where('content_id = ? and website_section_id = ?',self.id, section.id).first.nil?
116
- content_area = WebsiteSectionContent.where('content_id = ? and website_section_id = ?',self.id, section.id).first.content_area
125
+ unless WebsiteSectionContent.where('content_id = ? and website_section_id = ?', self.id, section.id).first.nil?
126
+ content_area = WebsiteSectionContent.where('content_id = ? and website_section_id = ?', self.id, section.id).first.content_area
117
127
  end
118
128
  content_area
119
129
  end
120
130
 
121
131
  def position_by_website_section(section)
122
132
  position = nil
123
- unless WebsiteSectionContent.where('content_id = ? and website_section_id = ?',self.id, section.id).first.nil?
124
- position = WebsiteSectionContent.where('content_id = ? and website_section_id = ?',self.id, section.id).first.position
133
+ unless WebsiteSectionContent.where('content_id = ? and website_section_id = ?', self.id, section.id).first.nil?
134
+ position = WebsiteSectionContent.where('content_id = ? and website_section_id = ?', self.id, section.id).first.position
125
135
  end
126
136
  position
127
137
  end
@@ -129,18 +139,18 @@ class Content < ActiveRecord::Base
129
139
  def assign_attribute_on_save
130
140
  super
131
141
 
132
- Article.find_by_internal_identifier(self.internal_identifier) ? attribute_type_description = "updated_by_role" : attribute_type_description = "created_by_role"
142
+ Article.find_by_internal_identifier(self.internal_identifier) ? attribute_type_description = "updated_by_role" : attribute_type_description = "created_by_role"
133
143
 
134
144
  if attribute_type_description == "created_by_role"
135
145
  user = self.created_by
136
146
  else
137
- user = User.find(self.versions.sort_by {|version| version.version}.reverse[0].created_by_id)
147
+ user = User.find(self.versions.sort_by { |version| version.version }.reverse[0].created_by_id)
138
148
  end
139
-
149
+
140
150
  if user
141
151
  #keep only the attributes related to the most recent change for each attribute_type
142
152
  self.destroy_values_of_type attribute_type_description
143
-
153
+
144
154
  attribute_type = AttributeType.find_by_internal_identifier(attribute_type_description)
145
155
  attribute_type = AttributeType.create(:description => attribute_type_description, :data_type => "Text") unless attribute_type
146
156
 
@@ -156,9 +166,9 @@ class Content < ActiveRecord::Base
156
166
  def is_published?
157
167
  !PublishedElement.where('published_element_record_id = ? and published_element_record_type = ? and published_elements.version = ?', self.id, 'Content', self.version).first.nil?
158
168
  end
159
-
169
+
160
170
  protected
161
-
171
+
162
172
  def self.build_search_results(results)
163
173
  # and if it is a blog get the article link and title
164
174
  results_array = []
@@ -178,7 +188,7 @@ class Content < ActiveRecord::Base
178
188
 
179
189
  results_array << results_hash
180
190
  end
181
-
191
+
182
192
  results_array
183
193
  end
184
194
 
@@ -9,11 +9,11 @@ class DocumentedContent < Content
9
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
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)
18
18
  published_content = []
19
19
  documented_item = DocumentedItem.where(["online_document_section_id = ?", website_section.id]).first
@@ -25,5 +25,59 @@ class DocumentedContent < Content
25
25
 
26
26
  published_content.first
27
27
  end
28
-
28
+
29
+ def self.search(options = {})
30
+ predicate = self.joins('inner join documented_items on documented_items.documented_content_id = contents.id')
31
+ .joins('inner join website_sections on website_sections.id = documented_items.online_document_section_id')
32
+
33
+ if options[:section_unique_name]
34
+ predicate = predicate.where("website_sections.internal_identifier = ?", options[:section_unique_name])
35
+ end
36
+
37
+ if options[:parent_id]
38
+ predicate = predicate.where("website_sections.id" => WebsiteSection.find(options[:parent_id]).descendants.collect(&:id))
39
+ end
40
+
41
+ if options[:content_type]
42
+ predicate = predicate.where("website_sections.type = ?", options[:content_type])
43
+ end
44
+
45
+ if options[:website_id]
46
+ predicate = predicate.where("website_sections.website_id = ?", options[:website_id])
47
+ end
48
+
49
+ predicate = predicate.where("(UPPER(contents.title) LIKE UPPER('%#{options[:query]}%')
50
+ OR UPPER(contents.excerpt_html) LIKE UPPER('%#{options[:query]}%')
51
+ OR UPPER(contents.body_html) LIKE UPPER('%#{options[:query]}%') )").order("contents.created_at DESC")
52
+ if options[:page]
53
+ predicate.paginate(:page => options[:page], :per_page => options[:per_page])
54
+ else
55
+ predicate.all
56
+ end
57
+ end
58
+
59
+ def self.build_search_results(results)
60
+ # and if it is a blog get the article link and title
61
+ results_array = []
62
+ results.each do |content|
63
+ section = DocumentedItem.find_by_documented_content_id(content.id).online_document_section
64
+
65
+ results_hash = {}
66
+ results_hash[:internal_identifier] = section.internal_identifier
67
+ if section.attributes['type'] == 'Blog'
68
+ results_hash[:link] = section.path + '/' + content.permalink
69
+ results_hash[:title] = content.title
70
+ else
71
+ results_hash[:link] = section.path
72
+ results_hash[:title] = section.title
73
+ end
74
+ results_hash[:section] = section
75
+ results_hash[:content] = content
76
+
77
+ results_array << results_hash
78
+ end
79
+
80
+ results_array
81
+ end
82
+
29
83
  end
@@ -2,7 +2,7 @@ class OnlineDocumentSection < WebsiteSection
2
2
  has_one :documented_item, :dependent => :destroy
3
3
  delegate :content, :to => :documented_item, :prefix => true
4
4
  delegate :published_content, :to => :documented_item, :prefix => true
5
-
5
+
6
6
  def documented_item_content_html
7
7
  documented_item_content.body_html
8
8
  rescue