knitkit 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. data/README.md +22 -0
  2. data/app/controllers/knitkit/base_controller.rb +15 -2
  3. data/app/controllers/knitkit/blogs_controller.rb +4 -4
  4. data/app/controllers/knitkit/erp_app/desktop/app_controller.rb +16 -2
  5. data/app/controllers/knitkit/erp_app/desktop/articles_controller.rb +198 -57
  6. data/app/controllers/knitkit/erp_app/desktop/content_controller.rb +25 -11
  7. data/app/controllers/knitkit/erp_app/desktop/file_assets_controller.rb +123 -44
  8. data/app/controllers/knitkit/erp_app/desktop/image_assets_controller.rb +83 -9
  9. data/app/controllers/knitkit/erp_app/desktop/online_document_sections_controller.rb +38 -0
  10. data/app/controllers/knitkit/erp_app/desktop/position_controller.rb +15 -6
  11. data/app/controllers/knitkit/erp_app/desktop/theme_controller.rb +185 -98
  12. data/app/controllers/knitkit/erp_app/desktop/versions_controller.rb +38 -16
  13. data/app/controllers/knitkit/erp_app/desktop/website_controller.rb +126 -68
  14. data/app/controllers/knitkit/erp_app/desktop/website_nav_controller.rb +154 -107
  15. data/app/controllers/knitkit/erp_app/desktop/website_section_controller.rb +113 -54
  16. data/app/controllers/knitkit/online_document_sections_controller.rb +45 -0
  17. data/app/controllers/knitkit/unauthorized_controller.rb +5 -0
  18. data/app/controllers/knitkit/website_sections_controller.rb +8 -9
  19. data/app/mailers/document_mailer.rb +10 -0
  20. data/app/models/article.rb +1 -1
  21. data/app/models/content.rb +35 -3
  22. data/app/models/document.rb +8 -0
  23. data/app/models/document_type.rb +3 -0
  24. data/app/models/documented_content.rb +29 -0
  25. data/app/models/documented_item.rb +31 -0
  26. data/app/models/extensions/configuration.rb +5 -0
  27. data/app/models/extensions/party.rb +13 -0
  28. data/app/models/online_document_section.rb +40 -0
  29. data/app/models/theme.rb +22 -26
  30. data/app/models/valid_document.rb +4 -0
  31. data/app/models/website.rb +158 -119
  32. data/app/models/website_inquiry.rb +7 -2
  33. data/app/models/website_inquiry_mailer.rb +4 -3
  34. data/app/models/website_party_role.rb +5 -0
  35. data/app/models/website_section.rb +76 -38
  36. data/app/views/document_mailer/email_document.html.erb +12 -0
  37. data/app/views/knitkit/blogs/_add_comment.html.erb +2 -2
  38. data/app/views/knitkit/online_document_sections/index.html.erb +149 -0
  39. data/app/views/knitkit/website_sections/index.html.erb +0 -1
  40. data/app/views/layouts/knitkit/base.html.erb +4 -2
  41. data/app/views/layouts/knitkit/online_document_sections.html.erb +59 -0
  42. data/app/views/menus/knitkit/_default_menu.html.erb +1 -1
  43. data/app/views/menus/knitkit/_default_section_menu.html.erb +1 -1
  44. data/app/views/menus/knitkit/_default_sub_menu.html.erb +2 -2
  45. data/app/views/menus/knitkit/_default_sub_section_menu.html.erb +1 -1
  46. data/app/widgets/contact_us/base.rb +5 -5
  47. data/app/widgets/contact_us/javascript/contact_us.js +2 -1
  48. data/app/widgets/google_map/base.rb +0 -4
  49. data/app/widgets/google_map/javascript/google_map.js +4 -3
  50. data/app/widgets/login/base.rb +0 -5
  51. data/app/widgets/login/javascript/login.js +155 -153
  52. data/app/widgets/login/views/index.html.erb +3 -3
  53. data/app/widgets/login/views/reset_password.html.erb +2 -2
  54. data/app/widgets/manage_profile/base.rb +46 -67
  55. data/app/widgets/manage_profile/javascript/manage_profile.js +2 -1
  56. data/app/widgets/manage_profile/views/_user_information_form.html.erb +5 -1
  57. data/app/widgets/reset_password/base.rb +4 -6
  58. data/app/widgets/reset_password/javascript/reset_password.js +2 -1
  59. data/app/widgets/reset_password/views/index.html.erb +4 -3
  60. data/app/widgets/search/base.rb +1 -5
  61. data/app/widgets/search/javascript/search.js +2 -1
  62. data/app/widgets/search/views/show.html.erb +2 -2
  63. data/app/widgets/signup/base.rb +7 -6
  64. data/app/widgets/signup/javascript/signup.js +2 -1
  65. data/app/widgets/signup/views/error.html.erb +1 -1
  66. data/config/routes.rb +6 -2
  67. data/db/data_migrations/20110509223702_add_publisher_role.rb +10 -0
  68. data/db/data_migrations/20111118182910_setup_knitkit_capabilities.rb +84 -0
  69. data/db/data_migrations/20120127144444_create_website_role_types.rb +13 -0
  70. data/db/data_migrations/20120127150505_create_website_default_configuration.rb +72 -0
  71. data/db/data_migrations/20120127150506_add_primary_host_to_website_configuration.rb +33 -0
  72. data/db/data_migrations/20120316150424_add_is_template_to_default_website_config.rb +16 -0
  73. data/db/data_migrations/upgrade/20120210195616_add_website_configs.rb +19 -0
  74. data/db/data_migrations/upgrade/20120213205519_populate_website_iids.rb +17 -0
  75. data/db/migrate/20110211002317_setup_knitkit.rb +22 -5
  76. data/db/migrate/20111207161928_create_documented_items_table.rb +13 -0
  77. data/db/migrate/20111208180539_add_document_id_to_documented_item.rb +9 -0
  78. data/db/migrate/20120315163736_add_document.rb +32 -0
  79. data/db/migrate/20120503183431_create_valid_documents.rb +16 -0
  80. data/db/migrate/upgrade/20120116201510_add_render_base_layout_flag.rb +13 -0
  81. data/db/migrate/upgrade/20120127143745_create_website_party_roles.rb +24 -0
  82. data/db/migrate/upgrade/20120213184509_add_iid_to_websites.rb +14 -0
  83. data/lib/knitkit.rb +2 -0
  84. data/lib/knitkit/config.rb +31 -0
  85. data/lib/knitkit/engine.rb +12 -3
  86. data/lib/knitkit/extensions.rb +1 -3
  87. data/lib/knitkit/extensions/action_controller/theme_support/acts_as_themed_controller.rb +2 -3
  88. data/lib/knitkit/extensions/active_record/acts_as_document.rb +63 -0
  89. data/lib/knitkit/extensions/active_record/acts_as_publishable.rb +5 -4
  90. data/lib/knitkit/extensions/compass_ae/widgets/base.rb +70 -0
  91. data/lib/knitkit/extensions/railties/action_view.rb +22 -10
  92. data/lib/knitkit/extensions/railties/theme_support/asset_tag_helper.rb +3 -3
  93. data/lib/knitkit/extensions/railties/theme_support/theme_file_resolver.rb +8 -3
  94. data/lib/knitkit/routing_filter/section_router.rb +16 -6
  95. data/lib/knitkit/version.rb +7 -1
  96. data/public/images/check.png +0 -0
  97. data/public/images/credit_card.png +0 -0
  98. data/public/images/knitkit/tooltip.gif +0 -0
  99. data/public/javascripts/ajax_pagination.js +33 -0
  100. data/public/javascripts/datepicker.js +6 -1
  101. data/public/javascripts/erp_app/desktop/applications/knitkit/articles_grid_panel.js +731 -258
  102. data/public/javascripts/erp_app/desktop/applications/knitkit/center_region.js +289 -238
  103. data/public/javascripts/erp_app/desktop/applications/knitkit/comments_grid_panel.js +2 -4
  104. data/public/javascripts/erp_app/desktop/applications/knitkit/east_region.js +29 -3
  105. data/public/javascripts/erp_app/desktop/applications/knitkit/file_assets_panel.js +193 -21
  106. data/public/javascripts/erp_app/desktop/applications/knitkit/image_assets_data_view.js +27 -26
  107. data/public/javascripts/erp_app/desktop/applications/knitkit/image_assets_panel.js +167 -20
  108. data/public/javascripts/erp_app/desktop/applications/knitkit/inquiries_grid_panel.js +1 -2
  109. data/public/javascripts/erp_app/desktop/applications/knitkit/module.js +5 -1
  110. data/public/javascripts/erp_app/desktop/applications/knitkit/publish_window.js +2 -2
  111. data/public/javascripts/erp_app/desktop/applications/knitkit/published_grid_panel.js +20 -11
  112. data/public/javascripts/erp_app/desktop/applications/knitkit/section_articles_grid_panel.js +279 -228
  113. data/public/javascripts/erp_app/desktop/applications/knitkit/themes_tree_panel.js +40 -40
  114. data/public/javascripts/erp_app/desktop/applications/knitkit/versions_grid_panel.js +83 -76
  115. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region.js +1961 -1397
  116. data/public/javascripts/erp_app/desktop/applications/knitkit/widgets_panel.js +47 -43
  117. data/public/javascripts/knitkit/helpers.js +26 -0
  118. data/public/stylesheets/erp_app/desktop/applications/knitkit/knitkit.css +1 -2
  119. data/public/stylesheets/knitkit/documentation.css +50 -0
  120. data/public/stylesheets/knitkit/style.css +23 -1
  121. data/spec/controllers/knitkit/erp_app/desktop/articles_controller_spec.rb +8 -0
  122. data/spec/controllers/knitkit/erp_app/desktop/website_controller_spec.rb +396 -0
  123. data/spec/controllers/knitkit/erp_app/desktop/website_nav_controller_spec.rb +260 -0
  124. data/spec/controllers/knitkit/erp_app/desktop/website_section_controller_spec.rb +222 -0
  125. data/spec/dummy/Rakefile +7 -0
  126. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  127. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  128. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  129. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  130. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  131. data/spec/dummy/config.ru +4 -0
  132. data/spec/dummy/config/application.rb +43 -0
  133. data/spec/dummy/config/boot.rb +10 -0
  134. data/spec/dummy/config/database.yml +8 -0
  135. data/spec/dummy/config/environment.rb +5 -0
  136. data/spec/dummy/config/environments/spec.rb +27 -0
  137. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  138. data/spec/dummy/config/initializers/inflections.rb +10 -0
  139. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  140. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  141. data/spec/dummy/config/initializers/session_store.rb +8 -0
  142. data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
  143. data/spec/dummy/config/locales/en.yml +5 -0
  144. data/spec/dummy/config/routes.rb +4 -0
  145. data/spec/dummy/config/workflow.yml +1 -0
  146. data/spec/dummy/public/404.html +26 -0
  147. data/spec/dummy/public/422.html +26 -0
  148. data/spec/dummy/public/500.html +26 -0
  149. data/spec/dummy/public/favicon.ico +0 -0
  150. data/spec/dummy/script/rails +6 -0
  151. data/spec/factories/article.rb +4 -0
  152. data/spec/factories/basic.rb +3 -0
  153. data/spec/factories/blog.rb +5 -0
  154. data/spec/factories/documented_content.rb +4 -0
  155. data/spec/factories/documented_item.rb +4 -0
  156. data/spec/factories/online_document_section.rb +6 -0
  157. data/spec/factories/published_website.rb +4 -0
  158. data/spec/factories/theme.rb +6 -0
  159. data/spec/factories/website.rb +5 -0
  160. data/spec/factories/website_host.rb +4 -0
  161. data/spec/factories/website_nav.rb +5 -0
  162. data/spec/factories/website_nav_item.rb +4 -0
  163. data/spec/factories/website_section.rb +5 -0
  164. data/spec/models/article_spec.rb +35 -0
  165. data/spec/models/attribute_type_spec.rb +55 -0
  166. data/spec/models/attribute_value_spec.rb +114 -0
  167. data/spec/models/blog_spec.rb +16 -0
  168. data/spec/models/comment_spec.rb +11 -0
  169. data/spec/models/content_spec.rb +187 -0
  170. data/spec/models/documented_item_spec.rb +29 -0
  171. data/spec/models/online_document_section_spec.rb +34 -0
  172. data/spec/models/published_element_spec.rb +11 -0
  173. data/spec/models/published_website_spec.rb +11 -0
  174. data/spec/models/theme_spec.rb +12 -0
  175. data/spec/models/website_host_spec.rb +11 -0
  176. data/spec/models/website_inquiry_spec.rb +24 -0
  177. data/spec/models/website_nav_item_spec.rb +11 -0
  178. data/spec/models/website_nav_spec.rb +11 -0
  179. data/spec/models/website_section_content_spec.rb +11 -0
  180. data/spec/models/website_section_spec.rb +49 -0
  181. data/spec/models/website_spec.rb +146 -0
  182. data/spec/spec_helper.rb +61 -0
  183. metadata +391 -154
  184. data/app/controllers/knitkit/articles_controller.rb +0 -7
  185. data/lib/knitkit/extensions/compass/widgets/base.rb +0 -53
data/README.md CHANGED
@@ -4,3 +4,25 @@ Knitkit is an application that sits on top of the Compass AE framework that adds
4
4
 
5
5
  ![Logo](http://development.compassagile.com/sites/site-1/images/knitkit.png?1323038265)
6
6
 
7
+ ##Initializer Options
8
+
9
+ - unauthorized\_url
10
+ - Url to redirect to when user attempts to navigate to a page they are not authorized to view.
11
+ - Default : '/unauthorized'
12
+ - ignored\_prefix\_paths
13
+ - Array of paths for Knitkit to ignore.
14
+ - Default : []
15
+ - file\_assets\_location
16
+ - Location, in respect to Rails.root, that you want files to upload to and created in within knikit.
17
+ - Default : 'knitkit_assets'
18
+
19
+ ### Override Initializer
20
+
21
+ To override these settings simple create a knikit.rb file in your initializers and override the config options you want
22
+
23
+ Rails.application.config.knitkit.configure do |config|
24
+ config.unauthorized_url = '/unauthorized'
25
+ config.ignored_prefix_paths = []
26
+ config.file_assets_location = 'knitkit_assets'
27
+ end
28
+ Rails.application.config.knitkit.configure!
@@ -1,7 +1,7 @@
1
1
  module Knitkit
2
2
  class BaseController < ::ErpApp::ApplicationController
3
- before_filter :set_website
4
- before_filter :set_active_publication, :load_sections, :set_section, :except => [:view_current_publication]
3
+ before_filter :set_website, :clear_widget_params
4
+ before_filter :set_login_path, :set_active_publication, :load_sections, :set_section, :except => [:view_current_publication]
5
5
  acts_as_themed_controller :current_themes => lambda {|c| c.website.themes.active if c.website }
6
6
 
7
7
  layout 'knitkit/base'
@@ -23,15 +23,28 @@ module Knitkit
23
23
  def load_sections
24
24
  @website_sections = @website.website_sections.positioned
25
25
  end
26
+
27
+ def clear_widget_params
28
+ session[:widgets] = {}
29
+ end
26
30
 
27
31
  def set_section
28
32
  unless params[:section_id].nil?
29
33
  @website_section = WebsiteSection.find(params[:section_id])
34
+ if (current_user === false and !@website_section.has_access?(current_user)) and @website_section.path != @login_path
35
+ redirect_to @login_path
36
+ elsif !@website_section.has_access?(current_user)
37
+ redirect_to Rails.application.config.knitkit.unauthorized_url
38
+ end
30
39
  else
31
40
  raise "No Id set"
32
41
  end
33
42
  end
34
43
 
44
+ def set_login_path
45
+ @login_path = @website.configurations.first.get_configuration_item(ConfigurationItemType.find_by_internal_identifier('login_url')).options.first.value
46
+ end
47
+
35
48
  def set_active_publication
36
49
  @active_publication = @website.active_publication
37
50
  if !session[:website_version].blank? && !session[:website_version].empty?
@@ -1,16 +1,16 @@
1
1
  module Knitkit
2
- class BlogsController < ArticlesController
2
+ class BlogsController < BaseController
3
3
  PER_PAGE = 10
4
4
 
5
5
  def index
6
- @blog = Blog.find(params[:section_id])
6
+ @blog = Blog.find(@website_section.id)
7
7
  params[:use_route] = 'blogs'
8
8
 
9
9
  @contents = @blog.find_published_blog_posts(@active_publication).paginate(:page => params[:page], :per_page => PER_PAGE)
10
10
  end
11
11
 
12
12
  def tag
13
- @blog = Blog.find(params[:section_id])
13
+ @blog = Blog.find(@website_section.id)
14
14
  @tag = ActsAsTaggableOn::Tag.find(params[:tag_id])
15
15
  params[:use_route] = 'blog_tag'
16
16
 
@@ -20,7 +20,7 @@ module Knitkit
20
20
  end
21
21
 
22
22
  def show
23
- @blog = Blog.find(params[:section_id])
23
+ @blog = Blog.find(@website_section.id)
24
24
  @published_content = @blog.find_published_blog_post(@active_publication, params[:id])
25
25
  end
26
26
  end
@@ -5,13 +5,14 @@ module Knitkit
5
5
  KNIT_KIT_ROOT = Knitkit::Engine.root.to_s
6
6
 
7
7
  def websites
8
- websites = Website.all
8
+ websites = Website.order('name ASC').all
9
9
 
10
10
  tree = []
11
11
 
12
12
  websites.each do |website|
13
13
  website_hash = {
14
14
  :text => website.name,
15
+ :configurationId => website.configurations.first.id,
15
16
  :iconCls => 'icon-globe_disconnected',
16
17
  :id => "website_#{website.id}",
17
18
  :leaf => false,
@@ -104,17 +105,26 @@ module Knitkit
104
105
  def build_section_hash(website_section, website)
105
106
  website_section_hash = {
106
107
  :text => website_section.title,
108
+ :path => website_section.path,
107
109
  :siteName => website.name,
108
110
  :siteId => website.id,
109
111
  :type => website_section.type,
110
112
  :isSecured => !website_section.roles.empty?,
111
- :isSection => true,
113
+ :isSection => website_section.is_section?,
114
+ :isDocument => website_section.is_document_section?,
112
115
  :inMenu => website_section.in_menu,
116
+ :renderWithBaseLayout => website_section.render_base_layout?,
113
117
  :hasLayout => !website_section.layout.blank?,
114
118
  :id => "section_#{website_section.id}",
115
119
  :url => "http://#{website.hosts.first.attributes['host']}#{website_section.path}",
116
120
  :internal_identifier => website_section.internal_identifier
117
121
  }
122
+ if (website_section.is_a?(OnlineDocumentSection) || website_section.type == 'OnlineDocumentSection')
123
+ document_section = OnlineDocumentSection.find(website_section.id)
124
+ if document_section.documented_item and document_section.documented_item_content
125
+ website_section_hash[:contentInfo] = document_section.documented_item_content.content_hash
126
+ end
127
+ end
118
128
 
119
129
  if website_section.is_a?(Blog) || website_section.type == 'Blog'
120
130
  website_section_hash[:isBlog] = true
@@ -125,6 +135,10 @@ module Knitkit
125
135
  website_section_hash[:children] = website_section.positioned_children.map {|child| build_section_hash(child, website)}
126
136
  website_section_hash[:isSecured] ? website_section_hash[:iconCls] = 'icon-document_lock' : website_section_hash[:iconCls] = 'icon-document'
127
137
  end
138
+
139
+ if (website_section.is_a?(OnlineDocumentSection) || website_section.type == 'OnlineDocumentSection')
140
+ website_section_hash[:iconCls] = 'icon-document_info'
141
+ end
128
142
 
129
143
  website_section_hash
130
144
  end
@@ -2,68 +2,96 @@ module Knitkit
2
2
  module ErpApp
3
3
  module Desktop
4
4
  class ArticlesController < Knitkit::ErpApp::Desktop::AppController
5
+ @@datetime_format = "%m/%d/%Y %l:%M%P"
5
6
 
6
7
  def new
7
- result = {}
8
- website_section_id = params[:section_id]
9
- article = Article.new
10
-
11
- article.tag_list = params[:tags].split(',').collect{|t| t.strip() } unless params[:tags].blank?
12
- article.title = params[:title]
13
- article.internal_identifier = params[:internal_identifier]
14
- article.display_title = params[:display_title] == 'yes'
15
- article.created_by = current_user
16
-
17
- if article.save
18
- unless website_section_id.blank?
19
- website_section = WebsiteSection.find(website_section_id)
20
- article.website_sections << website_section
21
- article.update_content_area_and_position_by_section(website_section, params['content_area'], params['position'])
22
- end
8
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
9
+ begin
10
+ current_user.with_capability(model, 'create', 'Article') do
11
+ result = {}
12
+ website_section_id = params[:section_id]
13
+ article = Article.new
23
14
 
24
- result[:success] = true
25
- else
26
- result[:success] = false
27
- end
15
+ article.tag_list = params[:tags].split(',').collect{|t| t.strip() } unless params[:tags].blank?
16
+ article.title = params[:title]
17
+ article.internal_identifier = params[:internal_identifier]
18
+ article.display_title = params[:display_title] == 'yes'
19
+ article.created_by = current_user
28
20
 
21
+ if article.save
22
+ unless website_section_id.blank?
23
+ website_section = WebsiteSection.find(website_section_id)
24
+ article.website_sections << website_section
25
+ article.update_content_area_and_position_by_section(website_section, params['content_area'], params['position'])
26
+ end
29
27
 
30
- render :json => result
28
+ result[:success] = true
29
+ else
30
+ result[:success] = false
31
+ end
32
+
33
+ render :json => result
34
+ end
35
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
36
+ render :json => {:success => false, :message => ex.message}
37
+ end
31
38
  end
32
39
 
33
40
  def update
34
- result = {}
35
- website_section_id = params[:section_id]
36
- article = Article.find(params[:id])
37
-
38
- article.tag_list = params[:tags].split(',').collect{|t| t.strip() } unless params[:tags].blank?
39
- article.title = params[:title]
40
- article.internal_identifier = params[:internal_identifier]
41
- article.display_title = params[:display_title] == 'yes'
42
- article.updated_by = current_user
43
-
44
- if article.save
45
- unless website_section_id.blank?
46
- website_section = WebsiteSection.find(website_section_id)
47
- article.update_content_area_and_position_by_section(website_section, params['content_area'], params['position'])
48
- end
41
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
42
+ begin
43
+ current_user.with_capability(model, 'edit', 'Article') do
44
+ result = {}
45
+ website_section_id = params[:section_id]
46
+ article = Article.find(params[:id])
49
47
 
50
- result[:success] = true
51
- else
52
- result[:success] = false
53
- end
48
+ article.tag_list = params[:tags].split(',').collect{|t| t.strip() } unless params[:tags].blank?
49
+ article.title = params[:title]
50
+ article.internal_identifier = params[:internal_identifier]
51
+ article.display_title = params[:display_title] == 'yes'
52
+ article.updated_by = current_user
53
+
54
+ if article.save
55
+ unless website_section_id.blank?
56
+ website_section = WebsiteSection.find(website_section_id)
57
+ article.update_content_area_and_position_by_section(website_section, params['content_area'], params['position'])
58
+ end
59
+
60
+ result[:success] = true
61
+ else
62
+ result[:success] = false
63
+ end
54
64
 
55
- render :json => result
65
+ render :json => result
66
+ end
67
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
68
+ render :json => {:success => false, :message => ex.message}
69
+ end
56
70
  end
57
71
 
58
72
  def delete
59
- render :json => Article.destroy(params[:id]) ? {:success => true} : {:success => false}
73
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
74
+ begin
75
+ current_user.with_capability(model, 'delete', 'Article') do
76
+ render :json => Article.destroy(params[:id]) ? {:success => true} : {:success => false}
77
+ end
78
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
79
+ render :json => {:success => false, :message => ex.message}
80
+ end
60
81
  end
61
82
 
62
83
  def add_existing
63
- website_section = WebsiteSection.find(params[:section_id])
64
- website_section.contents << Article.find(params[:article_id])
84
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
85
+ begin
86
+ current_user.with_capability(model, 'add_existing', 'Article') do
87
+ website_section = WebsiteSection.find(params[:section_id])
88
+ website_section.contents << Article.find(params[:article_id])
65
89
 
66
- render :json => {:success => true}
90
+ render :json => {:success => true}
91
+ end
92
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
93
+ render :json => {:success => false, :message => ex.message}
94
+ end
67
95
  end
68
96
 
69
97
  def existing_articles
@@ -71,15 +99,26 @@ module Knitkit
71
99
  end
72
100
 
73
101
  def get
102
+ website_section_id = params[:section_id]
103
+ section = WebsiteSection.find(website_section_id)
104
+
105
+ if section.type == 'Blog'
106
+ sort_default = 'created_at'
107
+ dir_default = 'DESC'
108
+ else
109
+ sort_default = 'title'
110
+ dir_default = 'ASC'
111
+ end
112
+
74
113
  sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
75
- sort = sort_hash[:property] || 'created_at'
76
- dir = sort_hash[:direction] || 'DESC'
114
+ sort = sort_hash[:property] || sort_default
115
+ dir = sort_hash[:direction] || dir_default
77
116
  limit = params[:limit] || 10
78
117
  start = params[:start] || 0
79
118
 
80
- website_section_id = params[:section_id]
81
- articles = Article.joins("INNER JOIN website_section_contents ON website_section_contents.content_id = contents.id").where("website_section_id = #{website_section_id}").order("contents.#{sort} #{dir}").limit(limit).offset(start)
82
- total_count = Article.joins("INNER JOIN website_section_contents ON website_section_contents.content_id = contents.id").where("website_section_id = #{website_section_id}").count
119
+ articles = Article.joins("INNER JOIN website_section_contents ON website_section_contents.content_id = contents.id").where("website_section_id = #{website_section_id}")
120
+ total_count = articles.count
121
+ articles = articles.order("#{sort} #{dir}").limit(limit).offset(start)
83
122
 
84
123
  Article.class_exec(website_section_id) do
85
124
  @@website_section_id = website_section_id
@@ -100,22 +139,28 @@ module Knitkit
100
139
  articles_hash[:internal_identifier] = a.internal_identifier
101
140
  articles_hash[:display_title] = a.display_title
102
141
  articles_hash[:position] = a.position(website_section_id)
142
+ articles_hash[:created_at] = a.created_at.getlocal.strftime(@@datetime_format)
143
+ articles_hash[:updated_at] = a.updated_at.getlocal.strftime(@@datetime_format)
103
144
  articles_array << articles_hash
104
145
  end
105
146
 
106
- render :inline => "{totalCount:#{total_count},data:#{articles_array.to_json(:only => [:content_area, :id, :title, :tag_list, :body_html, :excerpt_html, :position, :internal_identifier, :display_title], :methods => [:website_section_position])}}"
147
+ render :inline => "{total:#{total_count},data:#{articles_array.to_json}}"
107
148
  end
108
149
 
109
150
  def all
110
151
  Article.include_root_in_json = false
111
152
  sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
112
- sort = sort_hash[:property] || 'created_at'
113
- dir = sort_hash[:direction] || 'DESC'
114
- limit = params[:limit] || 40
153
+ sort = sort_hash[:property] || 'title'
154
+ dir = sort_hash[:direction] || 'ASC'
155
+ limit = params[:limit] || 20
115
156
  start = params[:start] || 0
116
157
 
117
- articles = params[:iid].blank? ? Article.order( "contents.#{sort} #{dir}").limit(limit).offset(start).all : Article.where('internal_identifier like ?', "%#{params[:iid]}%").order("contents.#{sort} #{dir}").limit(limit).offset(start)
118
- total_count = Article.all.count
158
+ articles = Article.includes(:website_section_contents)
159
+ articles = articles.where( :website_section_contents => { :content_id => nil } ) if params[:show_orphaned] == 'true'
160
+ articles = articles.where('internal_identifier like ?', "%#{params[:iid]}%") unless params[:iid].blank?
161
+ articles = articles.order("contents.#{sort} #{dir}")
162
+ total_count = articles.count
163
+ articles = articles.limit(limit).offset(start)
119
164
 
120
165
  articles_array = []
121
166
  articles.each do |a|
@@ -130,11 +175,107 @@ module Knitkit
130
175
  articles_hash[:excerpt_html] = a.excerpt_html
131
176
  articles_hash[:created_by] = a.created_by.login rescue ''
132
177
  articles_hash[:last_update_by] = a.updated_by.login rescue ''
178
+ articles_hash[:created_at] = a.created_at.getlocal.strftime(@@datetime_format)
179
+ articles_hash[:updated_at] = a.updated_at.getlocal.strftime(@@datetime_format)
180
+
133
181
 
134
182
  articles_array << articles_hash
135
183
  end
136
184
 
137
- render :inline => "{totalCount:#{total_count},data:#{articles_array.to_json(:only => [:content_area, :id, :title, :tag_list, :body_html, :excerpt_html, :sections, :internal_identifier, :display_title, :created_by, :last_update_by])}}"
185
+ render :inline => "{total:#{total_count},data:#{articles_array.to_json}}"
186
+ end
187
+
188
+ def article_attributes
189
+ sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
190
+ sort = sort_hash[:property] || 'created_at'
191
+ dir = sort_hash[:direction] || 'DESC'
192
+ limit = params[:limit] || 40
193
+ start = params[:start] || 0
194
+
195
+ article = Article.find(params[:article_id])
196
+ attributes = article.attribute_values
197
+ attributes = attributes.slice(start.to_i, limit.to_i)
198
+
199
+ if dir == "DESC"
200
+ if sort == "data_type" or sort == "description"
201
+ attributes = attributes.sort {|x,y| x.attribute_type.send(sort) <=> y.attribute_type.send(sort)}
202
+ else
203
+ attributes = attributes.sort {|x,y| x.send(sort) <=> y.send(sort)}
204
+ end
205
+ else
206
+ if sort == "data_type" or sort == "description"
207
+ attributes = attributes.sort {|x,y| y.attribute_type.send(sort) <=> x.attribute_type.send(sort)}
208
+ else
209
+ attributes = attributes.sort {|x,y| y.send(sort) <=> x.send(sort)}
210
+ end
211
+ end
212
+
213
+ attributes_array = []
214
+ attributes.each do |attribute|
215
+ attributes_hash = {}
216
+ attributes_hash[:id] = attribute.id
217
+ attributes_hash[:description] = attribute.attribute_type.description
218
+ attributes_hash[:data_type] = attribute.attribute_type.data_type
219
+ attributes_hash[:value] = attribute.value
220
+
221
+ attributes_array << attributes_hash
222
+ end
223
+
224
+ render :inline => "{data:#{attributes_array.to_json(:only => [:id, :description, :data_type, :value])}}"
225
+ end
226
+
227
+ def attribute_types
228
+ attribute_types = AttributeType.find(:all)
229
+ attribute_types_array = []
230
+ attribute_types_array << {:description => 'Search By Article', :iid => 'search_by_article'}
231
+ attribute_types.each do |attribute_type|
232
+ attribute_types_hash = {}
233
+ attribute_types_hash[:description] = attribute_type.description
234
+ attribute_types_hash[:iid] = attribute_type.internal_identifier
235
+
236
+ attribute_types_array << attribute_types_hash
237
+ end
238
+
239
+ render :inline => "{data:#{attribute_types_array.to_json(:only => [:description, :iid])}}"
240
+ end
241
+
242
+ def delete_attribute
243
+ render :json => AttributeValue.destroy(params[:id]) ? {:success => true} : {:success => false}
244
+ end
245
+
246
+ def new_attribute
247
+ result = {:success => true}
248
+ article = Article.find(params[:article_id])
249
+ attribute_type = AttributeType.find_by_iid_with_description(params[:description])
250
+
251
+ if attribute_type == nil
252
+ attribute_type = AttributeType.new
253
+ attribute_type.description = params[:description]
254
+ attribute_type.data_type = params[:data_type]
255
+ result[:success] = false unless attribute_type.save
256
+
257
+ attribute_value = AttributeValue.new
258
+ attribute_value.value = params[:value]
259
+
260
+ attribute_type.attribute_values << attribute_value
261
+ article.attribute_values << attribute_value
262
+
263
+ result[:success] = false unless attribute_value.save
264
+ else
265
+ if attribute_type.data_type == params[:data_type]
266
+ attribute_value = AttributeValue.new
267
+ attribute_value.value = params[:value]
268
+
269
+ attribute_type.attribute_values << attribute_value
270
+ article.attribute_values << attribute_value
271
+
272
+ result[:sucess] = false unless attribute_value.save
273
+ else
274
+ result[:success] = false
275
+ end
276
+ end
277
+
278
+ render :json => result
138
279
  end
139
280
 
140
281
  end#ArticlesController