insight_rails 0.1.1

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.
Files changed (48) hide show
  1. data/README.md +43 -0
  2. data/Rakefile +15 -0
  3. data/VERSION +1 -0
  4. data/app/controllers/help/categories_controller.rb +11 -0
  5. data/app/controllers/help/comments_controller.rb +22 -0
  6. data/app/controllers/help/issues_controller.rb +53 -0
  7. data/app/controllers/help/sessions_controller.rb +40 -0
  8. data/app/controllers/help_controller.rb +10 -0
  9. data/app/controllers/insight_controller.rb +32 -0
  10. data/app/controllers/knowledge/article_categories_controller.rb +13 -0
  11. data/app/controllers/knowledge/articles_controller.rb +11 -0
  12. data/app/helpers/help/issues_helper.rb +15 -0
  13. data/app/models/article.rb +11 -0
  14. data/app/models/article_category.rb +11 -0
  15. data/app/models/category.rb +11 -0
  16. data/app/models/category_issue.rb +10 -0
  17. data/app/models/comment.rb +26 -0
  18. data/app/models/insight_user.rb +19 -0
  19. data/app/models/issue.rb +30 -0
  20. data/app/models/lead.rb +15 -0
  21. data/app/views/help/categories/index.html.erb +29 -0
  22. data/app/views/help/comments/_form.html.erb +25 -0
  23. data/app/views/help/index.html.erb +0 -0
  24. data/app/views/help/issues/_form.html.erb +43 -0
  25. data/app/views/help/issues/index.html.erb +42 -0
  26. data/app/views/help/issues/new.html.erb +3 -0
  27. data/app/views/help/issues/show.html.erb +39 -0
  28. data/app/views/help/sessions/new.html.erb +20 -0
  29. data/app/views/knowledge/article_categories/index.html.erb +16 -0
  30. data/app/views/knowledge/articles/show.html.erb +3 -0
  31. data/app/views/layouts/_insight_footer.html.erb +25 -0
  32. data/app/views/layouts/insight_layout.html.erb +56 -0
  33. data/config/routes.rb +42 -0
  34. data/generators/insight/insight_generator.rb +26 -0
  35. data/generators/insight/lib/insert_commands.rb +33 -0
  36. data/generators/insight/templates/README +0 -0
  37. data/generators/insight/templates/insight.rake +26 -0
  38. data/generators/insight/templates/insight.rb +7 -0
  39. data/generators/insight/templates/insight.sass +284 -0
  40. data/generators/insight/templates/migrations/link_users_to_crm_contacts.rb +13 -0
  41. data/lib/insight/configuration.rb +28 -0
  42. data/lib/insight/crm/callbacks/account.rb +39 -0
  43. data/lib/insight/crm/callbacks/user.rb +53 -0
  44. data/lib/insight/crm/models/account.rb +17 -0
  45. data/lib/insight/crm/models/contact.rb +17 -0
  46. data/lib/insight/multi_pass_attributes.rb +32 -0
  47. data/lib/insight.rb +3 -0
  48. metadata +140 -0
@@ -0,0 +1,25 @@
1
+ <div id="footer">
2
+ <div class="latest-discussions">
3
+ <div class="latest discussions">
4
+ <h3>Latest Discussions</h3>
5
+ <ul>
6
+ <% Issue.find(:all, :from => :latest).each do |issue| %>
7
+ <li>
8
+ <span><%= issue.created_at.strftime("%d %b %H:%H") %></span> <%= link_to(issue.title, help_issue_path(issue)) %>
9
+ </li>
10
+ <% end %>
11
+ </ul>
12
+ </div>
13
+
14
+ <div class="latest articles">
15
+ <h3>Latest Knowledge Base Articles</h3>
16
+ <ul>
17
+ <% Article.find(:all, :from => :latest).each do |article| %>
18
+ <li>
19
+ <%= link_to(article.title, knowledge_article_path(article)) %>
20
+ </li>
21
+ <% end %>
22
+ </ul>
23
+ </div>
24
+ </div>
25
+ </div>
@@ -0,0 +1,56 @@
1
+ <!DOCTYPE>
2
+ <html>
3
+ <head>
4
+ <title>Help &amp; Support</title>
5
+
6
+ <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.3.0/build/reset-fonts-grids/reset-fonts-grids.css">
7
+ <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.3.0/build/base/base-min.css">
8
+
9
+ <%= stylesheet_link_tag 'insight' %>
10
+ </head>
11
+ <body>
12
+ <div id="header">
13
+ <div class="section">
14
+ <div class="top-nav">
15
+ <ul class="nav">
16
+ <li>
17
+ <%= link_to("Support Home", help_path) %>
18
+ </li>
19
+ <li>
20
+ <%= link_to("Return to App", "/") %>
21
+ </li>
22
+ <% if logged_in? %>
23
+ <li>
24
+ <%= link_to("Logout", help_logout_path) %>
25
+ </li>
26
+ <% else %>
27
+ <li>
28
+ <%= link_to("Login", help_login_path) %>
29
+ </li>
30
+ <% end %>
31
+ </ul>
32
+ </div>
33
+ </div>
34
+ <h1>Help &amp; Support</h1>
35
+ <div class="nav-bar">
36
+ <ul class="nav">
37
+ <li>
38
+ <%= link_to("Start a Discussion", new_help_issue_path) %>
39
+ </li>
40
+ <li>
41
+ <%= link_to("Browse Discussions", help_browse_path) %>
42
+ </li>
43
+ <li>
44
+ <%= link_to("Knowledge Base", knowledge_path) %>
45
+ </li>
46
+ </ul>
47
+ </div>
48
+ </div>
49
+ <div id="wrapper">
50
+ <div id="content">
51
+ <%= yield %>
52
+ </div>
53
+ <%= render :partial => "layouts/insight_footer" %>
54
+ </div>
55
+ </body>
56
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,42 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+
3
+ map.knowledge "/knowledge",
4
+ :controller => "knowledge/article_categories",
5
+ :action => "index"
6
+
7
+ map.namespace :knowledge do |kb|
8
+ kb.resources :categories, :controller => "article_categories"
9
+ kb.resources :articles, :only => [ :index, :show ]
10
+ end
11
+
12
+ map.help "/help",
13
+ :controller => "help",
14
+ :action => "index"
15
+
16
+ map.namespace :help do |help|
17
+ help.browse "/browse",
18
+ :controller => "categories",
19
+ :action => "index"
20
+
21
+ help.login "/login",
22
+ :controller => "sessions",
23
+ :action => "new"
24
+
25
+ help.logout "/logout",
26
+ :controller => "sessions",
27
+ :action => "destroy"
28
+
29
+ help.resource :sessions
30
+
31
+ help.resources :categories do |category|
32
+ category.resources :issues
33
+ end
34
+
35
+ help.resources :issues,
36
+ :collection => { :my => :get },
37
+ :except => [ :destroy ] do |issue|
38
+ issue.resources :comments, :except => [ :destroy ]
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,26 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
2
+
3
+ class InsightGenerator < Rails::Generator::Base
4
+
5
+ def manifest
6
+ record do |m|
7
+ m.directory File.join("config", "initializers")
8
+ m.file "insight.rb", "config/initializers/insight.rb"
9
+
10
+ m.migration_template "migrations/link_users_to_crm_contacts.rb",
11
+ "db/migrate",
12
+ :migration_file_name => "link_users_to_crm_contacts"
13
+
14
+ m.insert_into "app/models/user.rb", "include Insight::CRM::Callbacks::User"
15
+ m.insert_into "app/models/account.rb", "include Insight::CRM::Callbacks::Account"
16
+
17
+ m.file "insight.rake", "lib/tasks/insight.rake"
18
+
19
+ m.directory File.join("public", "stylesheets", "sass")
20
+ m.file "insight.sass", "public/stylesheets/sass/insight.sass"
21
+
22
+ m.readme "README"
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,33 @@
1
+ # Mostly pinched from http://github.com/ryanb/nifty-generators/tree/master
2
+
3
+ Rails::Generator::Commands::Base.class_eval do
4
+ def file_contains?(relative_destination, line)
5
+ File.read(destination_path(relative_destination)).include?(line)
6
+ end
7
+ end
8
+
9
+ Rails::Generator::Commands::Create.class_eval do
10
+ def insert_into(file, line)
11
+ logger.insert "#{line} into #{file}"
12
+ unless options[:pretend] || file_contains?(file, line)
13
+ gsub_file file, /^(class|module|.*Routes).*$/ do |match|
14
+ "#{match}\n #{line}"
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ Rails::Generator::Commands::Destroy.class_eval do
21
+ def insert_into(file, line)
22
+ logger.remove "#{line} from #{file}"
23
+ unless options[:pretend]
24
+ gsub_file file, "\n #{line}", ''
25
+ end
26
+ end
27
+ end
28
+
29
+ Rails::Generator::Commands::List.class_eval do
30
+ def insert_into(file, line)
31
+ logger.insert "#{line} into #{file}"
32
+ end
33
+ end
File without changes
@@ -0,0 +1,26 @@
1
+ namespace :insight do
2
+
3
+ desc "Generate CRM Accounts"
4
+ task :generate_crm_accounts => :environment do
5
+ Account.find_each do |account|
6
+ name = (account.respond_to?(:name) ? account.name + " " + account.id.to_s : account.site_name + " " + account.id.to_s)
7
+ crm_account = Insight::CRM::Models::Account.new(:name => name)
8
+ crm_account.save
9
+ account.update_attribute(:crm_id, crm_account.id)
10
+
11
+ account.users.each do |user|
12
+ crm_user = Insight::CRM::Models::Contact.new
13
+ crm_user.title = user.title if user.respond_to?(:title)
14
+ crm_user.first_name = user.firstname if user.respond_to?(:firstname)
15
+ crm_user.first_name = user.first_name if user.respond_to?(:first_name)
16
+ crm_user.last_name = user.lastname if user.respond_to?(:lastname)
17
+ crm_user.last_name = user.last_name if user.respond_to?(:last_name)
18
+ crm_user.email = user.email if user.respond_to?(:email)
19
+ crm_user.save
20
+
21
+ user.update_attribute(:crm_id, crm_user.id)
22
+ end
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,7 @@
1
+ Insight.configure do |config|
2
+ config.fat_free_url = "http://localhost:3000/api"
3
+ config.api_key = nil
4
+ config.layout = "insight_layout"
5
+ config.recaptcha_public_key = nil
6
+ config.recaptcha_private_key = nil
7
+ end
@@ -0,0 +1,284 @@
1
+ /* ========================================================================= */
2
+ /* = Colours = */
3
+ /* ========================================================================= */
4
+
5
+ $shadow: #333
6
+ $blue: #0C3569
7
+ $header_background: #006FBB
8
+ $gray: #c1c1c1
9
+
10
+ $table_header: #006FBB
11
+ $table_border: #c1c1c1
12
+ $table_link: #006FBB
13
+
14
+ $odd: #f1f1f1
15
+
16
+ $article_text: #ADADAD
17
+ $article_background: #181818
18
+ $article_date: #555
19
+
20
+ /* ========================================================================= */
21
+ /* = Variables = */
22
+ /* ========================================================================= */
23
+
24
+ $layout: 960px
25
+
26
+ $label_width: 150px
27
+ $input_width: 350px
28
+
29
+ /* ========================================================================= */
30
+ /* = Mixins = */
31
+ /* ========================================================================= */
32
+
33
+ $radius: 5px
34
+ @mixin rounded_corner
35
+ -webkit-border-radius: $radius
36
+ -moz-border-radius: $radius
37
+ border-radius: $radius
38
+
39
+ /* ========================================================================= */
40
+ /* = General = */
41
+ /* ========================================================================= */
42
+
43
+ body
44
+ font-family: Verdana, Tahoma
45
+ text-align: left
46
+
47
+ .button
48
+ @include rounded_corner
49
+ background: #000
50
+ padding: 8px
51
+ color: #fff
52
+ text-decoration: none
53
+ display: inline-block
54
+ &:hover
55
+ background: #006FBB
56
+
57
+ /* ========================================================================= */
58
+ /* = Typography = */
59
+ /* ========================================================================= */
60
+
61
+ #header h1
62
+ text-align: center
63
+ color: #fff
64
+ text-shadow: 2px 2px 2px $shadow
65
+ font-size: 24px
66
+
67
+ h1
68
+ font-size: 18px
69
+ font-weight: normal
70
+
71
+ h2, h3
72
+ text-align: left
73
+ font-weight: normal
74
+
75
+ h3
76
+ font-weight: bold
77
+
78
+ /* ========================================================================= */
79
+ /* = Navigation = */
80
+ /* ========================================================================= */
81
+
82
+ ul.nav
83
+ margin: 0 0 20px 0
84
+ margin: 0
85
+ overflow: hidden
86
+ margin-left: -10px
87
+ li
88
+ float: left
89
+ margin-left: 10px
90
+ line-height: 30px
91
+ list-style-type: none
92
+ a
93
+ color: #fff
94
+
95
+ .top-nav
96
+ width: $layout
97
+ margin: 0 auto
98
+ .nav
99
+ float: right
100
+ display: block
101
+ a
102
+ @include rounded_corner
103
+ text-decoration: none
104
+ padding: 5px
105
+ &:hover
106
+ background: rgba(34, 34, 34, 0.597656)
107
+
108
+ .nav-bar
109
+ margin-left: -10px
110
+ background: #000
111
+ padding: 5px 0
112
+ margin-bottom: 40px
113
+ .nav
114
+ width: $layout
115
+ margin: 0 auto
116
+ line-height: 35px
117
+
118
+ /* ========================================================================= */
119
+ /* = Layout = */
120
+ /* ========================================================================= */
121
+
122
+ #wrapper
123
+ width: $layout
124
+ margin: 0 auto
125
+
126
+ #header
127
+ background: $header_background
128
+ .section
129
+ width: 100%
130
+ padding: 5px 0
131
+ background: rgba(34, 34, 34, 0.496094)
132
+ overflow: hidden
133
+
134
+ #content
135
+ overflow: hidden
136
+
137
+ .issue
138
+ width: 600px
139
+ float: left
140
+ h2
141
+ margin-top: 0
142
+ .author
143
+ overflow: hidden
144
+ padding-bottom: 10px
145
+ img
146
+ float: left
147
+ margin-right: 10px
148
+ p
149
+ float: left
150
+ border-bottom: 1px solid $gray
151
+ .body
152
+ margin: 10px 0
153
+
154
+ .comments
155
+ margin: 0
156
+ li
157
+ list-style-type: none
158
+ overflow: hidden
159
+ .who
160
+ background: #f1f1f1
161
+ line-height: 20px
162
+ margin-bottom: 5px
163
+ .gravatar
164
+ float: left
165
+ margin: 0 10px 10px 0
166
+ .said
167
+ float: left
168
+
169
+ .issue-status
170
+ width: 300px
171
+ float: right
172
+ border: 10px solid #e1e1e1
173
+ background: #f1f1f1
174
+ padding: 10px
175
+
176
+ .articles
177
+ margin-left: -40px
178
+ overflow: hidden
179
+ .category
180
+ width: 460px
181
+ float: left
182
+ overflow: hidden
183
+ margin-left: 40px
184
+ h2
185
+ font-weight: bold
186
+ ul
187
+ margin: 0
188
+ li
189
+ list-style-type: none
190
+ padding: 8px 0
191
+ border-bottom: 1px dashed #c1c1c1
192
+ a
193
+ color: #0C3569
194
+
195
+ #footer
196
+ border-top: 1px solid #c1c1c1
197
+ padding-top: 40px
198
+ margin: 40px 0
199
+
200
+ .latest-discussions
201
+ @include rounded_corner
202
+ background: $article_background
203
+ color: $article_text
204
+ padding: 15px 25px
205
+ overflow: hidden
206
+ width: 910px
207
+ .latest
208
+ float: left
209
+ width: 435px
210
+ &.articles
211
+ margin-left: 40px
212
+ h3
213
+ font-weight: bold
214
+ margin-top: 0
215
+ ul
216
+ margin: 0
217
+ li
218
+ padding: 8px 0
219
+ border-bottom: 1px dashed #f1f1f1
220
+ list-style-type: none
221
+ span
222
+ color: $article_date
223
+ a
224
+ color: inherit
225
+
226
+ /* ========================================================================= */
227
+ /* = Forms = */
228
+ /* ========================================================================= */
229
+
230
+ form
231
+ fieldset.inputs
232
+ ol
233
+ margin: 0
234
+ li
235
+ list-style-type: none
236
+ margin: 5px 0
237
+ label
238
+ width: $label_width
239
+ float: left
240
+ font-weight: bold
241
+ line-height: 28px
242
+ &.string, &.text
243
+ input, textarea
244
+ padding: 5px
245
+ border: 1px solid $gray
246
+ &.string input
247
+ width: $input_width
248
+ &.text textarea
249
+ width: $label_width + $input_width
250
+ height: 200px
251
+ &.select
252
+ select
253
+ margin: 5px 0
254
+
255
+ /* ========================================================================= */
256
+ /* = Tables = */
257
+ /* ========================================================================= */
258
+
259
+ table
260
+ width: 100%
261
+ margin: 10px 0
262
+ th
263
+ border: 1px solid $table_header
264
+ font-size: 14px
265
+ td
266
+ border: 1px solid $table_border
267
+ thead
268
+ th
269
+ text-align: left
270
+ background: $table_header
271
+ color: #fff
272
+ padding: 10px 5px
273
+
274
+ td
275
+ h2
276
+ margin: 5px 0
277
+ font-weight: normal
278
+ a
279
+ text-decoration: none
280
+ td a
281
+ color: $table_link
282
+
283
+ tr.even td
284
+ background: $odd
@@ -0,0 +1,13 @@
1
+ class LinkUsersToCRMContacts < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ add_column :users, :crm_id, :integer
5
+ add_column :accounts, :crm_id, :integer
6
+ end
7
+
8
+ def self.down
9
+ remove_column :users, :crm_id
10
+ remove_column :accounts, :crm_id
11
+ end
12
+
13
+ end
@@ -0,0 +1,28 @@
1
+ module Insight
2
+
3
+ class Configuration
4
+
5
+ attr_accessor :fat_free_url, :api_key, :layout, :recaptcha_public_key, :recaptcha_private_key
6
+
7
+ def initialize
8
+ @fat_free_url = "http://localhost"
9
+ @api_key = nil
10
+ @layout = "support_layout"
11
+ @recaptcha_public_key = nil
12
+ @recaptcha_private_key = nil
13
+ end
14
+
15
+ end
16
+
17
+ class << self
18
+
19
+ attr_accessor :configuration
20
+
21
+ def configure
22
+ self.configuration ||= Configuration.new
23
+ yield(configuration)
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,39 @@
1
+ module Insight
2
+
3
+ module CRM
4
+
5
+ module Callbacks
6
+
7
+ module Account
8
+
9
+ def self.included(base)
10
+ base.class_eval do
11
+ after_create :create_crm_account
12
+ # after_update :update_crm_account
13
+ end
14
+
15
+ protected
16
+
17
+ def create_crm_account
18
+ account = CRM::Models::Account.new
19
+ account.name = name
20
+ account.user_id = 1
21
+ account.save
22
+ self.update_attribute(:crm_id, account.id)
23
+ end
24
+
25
+ def update_crm_account
26
+ account = CRM::Models::Account.find(crm_id)
27
+ account.name = name
28
+ account.save
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,53 @@
1
+ module Insight
2
+
3
+ module CRM
4
+
5
+ module Callbacks
6
+
7
+ module User
8
+
9
+ def self.included(base)
10
+ base.class_eval do
11
+ after_create :create_crm_contact
12
+ # after_update :update_crm_contact, :unless => :recording_last_activity?
13
+ end
14
+
15
+ protected
16
+
17
+ def create_crm_contact
18
+ contact = CRM::Models::Contact.new
19
+ contact.attributes = crm_attributes
20
+ contact.user_id = 1
21
+ contact.save
22
+ self.update_attribute(:crm_id, contact.id)
23
+ end
24
+
25
+ def update_crm_contact
26
+ contact = CRM::Models::Contact.find(crm_id)
27
+ contact.attributes = crm_attributes
28
+ contact.save
29
+ end
30
+
31
+ def crm_attributes
32
+ a = {}
33
+ a[:title] = title if respond_to?(:title)
34
+ a[:first_name] = firstname if respond_to?(:firstname)
35
+ a[:last_name] = lastname if respond_to?(:lastname)
36
+ a[:email] = email if respond_to?(:email)
37
+ a[:username] = username if respond_to?(:username)
38
+ a
39
+ end
40
+
41
+ def recording_last_activity?
42
+ respond_to?(:last_activity) && last_activity_changed?
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
53
+ end
@@ -0,0 +1,17 @@
1
+ module Insight
2
+
3
+ module CRM
4
+
5
+ module Models
6
+
7
+ class Account < ActiveResource::Base
8
+
9
+ self.site = Insight.configuration.fat_free_url
10
+
11
+ end
12
+
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,17 @@
1
+ module Insight
2
+
3
+ module CRM
4
+
5
+ module Models
6
+
7
+ class Contact < ActiveResource::Base
8
+
9
+ self.site = Insight.configuration.fat_free_url
10
+
11
+ end
12
+
13
+ end
14
+
15
+ end
16
+
17
+ end