graph_starter 0.16.1 → 0.16.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71ee67c9edb905bcbcaf00196df32fd59506342c
4
- data.tar.gz: e47a621be011732358cbeff0dd1e446d59208997
3
+ metadata.gz: 0d2e2e8b0afb79a398d41320fef3cd0a88e96ee9
4
+ data.tar.gz: 0e289c3ba5e588e43e02786f50a3447fb05439e5
5
5
  SHA512:
6
- metadata.gz: 7be608b9b5cce0023d3c25feca90fe866170f06f1fb465aff71b0c667a226909af149ba3a6b2ebaf03c86f710a2b04f4796941567406613d14bfb4c26494f092
7
- data.tar.gz: bbe6be6272fd21abc23a747c796abc707e48713d136b72d0601bc802d251158d1ef77de7ead6dee71ee42b6658061d71dc6131cb27ded19f1472d9da74536a7e
6
+ metadata.gz: f5d3c17986542ec15587d12462990a11831df53bf7f45b13feb16e2f8b615ce000ee0c415309da03980e64ac9cd91a984dbe4ec0866cbfcd42c83c8eb8df0fa8
7
+ data.tar.gz: 52b261fcf39547777311d34722cbb485822af0cf228990303d9398698cc88149e3c8c04fe3fa1c736eea5068f80186d18582fa00f76b72c8a7df34724f4386af
@@ -49,3 +49,9 @@ body.graph_starter-assets-controller.show-action #right-column .items .content {
49
49
  width: 100%;
50
50
  overflow-wrap: break-word;
51
51
  }
52
+
53
+ .cards .card .item .ui.avatar.image {
54
+ width: 1.7em;
55
+ height: 1.7em;
56
+ margin-left: -0.25em;
57
+ }
@@ -6,25 +6,34 @@ module GraphStarter
6
6
  def load_session_node
7
7
  session.delete('this_key_should_never_exist') # Make sure we have a session
8
8
 
9
- @session_node = Session.merge(session_id: session.id).tap do |session_node|
10
- if current_user && session_node.user.nil?
11
- session_node.user = current_user
12
- end
9
+ @session_node_thread = Thread.new do
10
+ Session.merge(session_id: session.id).tap do |session_node|
11
+ if current_user && session_node.user.nil?
12
+ session_node.user = current_user
13
+ end
13
14
 
14
- previous_session_id = session['previous_session_id']
15
- if previous_session_id && previous_session_id != session.id
16
- session_node.previous_session = Session.find_by(session_id: previous_session_id)
15
+ previous_session_id = session['previous_session_id']
16
+ if previous_session_id && previous_session_id != session.id
17
+ session_node.previous_session = Session.find_by(session_id: previous_session_id)
18
+ end
17
19
  end
18
20
  end
19
21
 
20
22
  session['previous_session_id'] = session.id
21
23
  end
22
24
 
25
+ def session_node
26
+ puts 'joining...'
27
+ @session_node_thread.join.value
28
+ end
29
+
23
30
  protected
24
31
 
25
32
  def model_class
26
33
  @model_slug = params[:model_slug]
27
34
  @model_slug.classify.constantize
35
+ rescue NameError
36
+ raise ActionController::RoutingError.new('Not Found')
28
37
  end
29
38
  end
30
39
  end
@@ -8,10 +8,12 @@ module GraphStarter
8
8
  @assets = asset_set.to_a
9
9
  @title = model_class.name.tableize.humanize
10
10
 
11
- @category_images = Asset.where(id: @assets.map(&:categories).flatten.map(&:id))
11
+ ids = @assets.map(&:categories).flatten.map(&:id)
12
+ @category_images = Asset.where(id: ids)
12
13
  .query_as(:asset)
13
14
  .match('(asset)-[:HAS_IMAGE]->(image:Image)')
14
15
  .pluck('asset.uuid', :image)
16
+
15
17
  @category_images = Hash[*@category_images.flatten]
16
18
  end
17
19
 
@@ -39,28 +41,19 @@ module GraphStarter
39
41
  render json: {results: results_data}.to_json
40
42
  end
41
43
 
42
- def require_model_class
43
- # For cases where the route picked up more than it should have and we try to constantize something wrong
44
- begin
45
- model_class
46
- rescue NameError
47
- render text: 'Not found', status: :not_found
48
- false
49
- end
50
-
51
- end
52
-
53
44
  def show
54
- return if !require_model_class
55
-
56
45
  @asset = asset
57
46
  @title = @asset.title
58
47
 
59
48
  if @asset
60
- View.record_view(@session_node,
61
- @asset,
62
- browser_string: request.env['HTTP_USER_AGENT'],
63
- ip_address: request.remote_ip)
49
+ # Don't wait
50
+ Thread.new do
51
+ View.record_view(session_node,
52
+ @asset,
53
+ browser_string: request.env['HTTP_USER_AGENT'],
54
+ ip_address: request.remote_ip)
55
+ puts 'ending view thread'
56
+ end
64
57
  else
65
58
  render file: 'public/404.html', status: :not_found, layout: false
66
59
  end
@@ -93,8 +86,6 @@ module GraphStarter
93
86
  end
94
87
 
95
88
  def create
96
- return if !require_model_class
97
-
98
89
  @asset = model_class.create(params[params[:model_slug].singularize])
99
90
 
100
91
  if @asset.persisted?
@@ -144,7 +135,9 @@ module GraphStarter
144
135
  end
145
136
 
146
137
  def asset
147
- apply_associations(model_class_scope.as(:asset).where('asset.uuid = {id} OR asset.slug = {id}', id: params[:id])).to_a[0]
138
+ apply_associations(model_class_scope.as(:asset).where('asset.uuid = {id} OR asset.slug = {id}', id: params[:id])).to_a[0].tap do |asset|
139
+ raise ActionController::RoutingError.new('Asset not found') if asset.blank?
140
+ end
148
141
  end
149
142
 
150
143
  def asset_with_access_level
@@ -176,7 +169,7 @@ module GraphStarter
176
169
 
177
170
  def apply_associations(scope, var = :asset)
178
171
  if associations.present?
179
- scope.query_as(var).with(var).proxy_as(model_class, var).with_associations(*associations)
172
+ scope.with_associations(*associations)
180
173
  else
181
174
  scope
182
175
  end
@@ -1,7 +1,9 @@
1
1
  module GraphStarter
2
2
  module ApplicationHelper
3
- def asset_path(asset, options = {})
4
- graph_starter.asset_path({id: asset.slug, model_slug: asset.class.model_slug}.merge(options))
3
+ def asset_path(asset)
4
+ # graph_starter.asset_path({id: asset.slug, model_slug: asset.class.model_slug}.merge(options))
5
+ # Switched to string for performance
6
+ "/#{asset.class.model_slug}/#{asset.slug}"
5
7
  end
6
8
 
7
9
  def engine_view(&b)
@@ -31,5 +33,20 @@ module GraphStarter
31
33
  def missing_image_tag
32
34
  @missing_image_tag ||= image_tag 'missing.png'
33
35
  end
36
+
37
+ # I know, right?
38
+ def asset_icon(asset, image = (image_unspecified = true; nil))
39
+ image_url = if !image_unspecified
40
+ image.source.url if image.present?
41
+ elsif (asset.class.has_images? || asset.class.has_image?) && asset.first_image_source_url.present?
42
+ asset.first_image_source_url
43
+ end
44
+
45
+ if image_url
46
+ image_tag image_url, class: 'ui avatar image'
47
+ else
48
+ content_tag :i, '', class: [asset.class.icon_class || 'folder', 'large', 'icon']
49
+ end
50
+ end
34
51
  end
35
52
  end
@@ -3,7 +3,7 @@ module GraphStarter
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- property :private, type: ActiveAttr::Typecasting::Boolean, default: nil
6
+ property :private, default: nil
7
7
  validates :private, inclusion: {in: [true, false, nil]}
8
8
 
9
9
  if GraphStarter.configuration.user_class
@@ -190,10 +190,10 @@ module GraphStarter
190
190
  self.class.sanitize_title(title)
191
191
  end
192
192
 
193
+ SANITIZER = Rails::Html::WhiteListSanitizer.new
194
+ # Should probably save in the DB?
193
195
  def self.sanitize_title(title)
194
- sanitizer = Rails::Html::WhiteListSanitizer.new
195
-
196
- sanitizer.sanitize(title, tags: %w(b em i strong)).try(:html_safe)
196
+ SANITIZER.sanitize(title, tags: %w(b em i strong)).try(:html_safe)
197
197
  end
198
198
 
199
199
 
@@ -309,11 +309,11 @@ module GraphStarter
309
309
  user_label = user_class.mapped_label_name
310
310
 
311
311
  query_as(:source)
312
- .match('source-[:HAS_CATEGORY]->(category:Category)<-[:HAS_CATEGORY]-(asset:Asset)')
312
+ .match('(source)-[:HAS_CATEGORY]->(category:Category)<-[:HAS_CATEGORY]-(asset:Asset)')
313
313
  .break
314
- .optional_match("source<-[:CREATED]-(creator:#{user_label})-[:CREATED]->asset")
314
+ .optional_match("(source)<-[:CREATED]-(creator:#{user_label})-[:CREATED]->(asset)")
315
315
  .break
316
- .optional_match("source<-[:VIEWED]-(viewer:#{user_label})-[:VIEWED]->asset")
316
+ .optional_match("(source)<-[:VIEWED]-(viewer:#{user_label})-[:VIEWED]->(asset)")
317
317
  .limit(5)
318
318
  .order('score DESC')
319
319
  .pluck(
@@ -336,12 +336,12 @@ module GraphStarter
336
336
  categories: categories # DEPRECATED
337
337
  }.tap do |result|
338
338
  result[:image_urls] = image_array.map(&:source_url) if image_array
339
- result[:images] = images.map {|image| image.source.url } if self.class.has_images?
339
+ result[:images] = images.map {|image| image.source_url } if self.class.has_images?
340
340
  result[:image] = image.source_url if self.class.has_image? && image
341
341
 
342
342
  self.class.category_associations.each do |association_name|
343
343
  result[association_name] = send(association_name)
344
- result[association_name].uniq! if result[association_name] && result[association_name].respond_to?(:to_a)
344
+ result[association_name].to_a.uniq! if result[association_name] && result[association_name].respond_to?(:to_a)
345
345
  end
346
346
  end
347
347
 
@@ -366,7 +366,7 @@ module GraphStarter
366
366
  end
367
367
 
368
368
  def self.model_slug
369
- name.tableize
369
+ @model_slug ||= name.tableize
370
370
  end
371
371
 
372
372
  def self.properties
@@ -389,7 +389,7 @@ module GraphStarter
389
389
  :asset, [:category]]
390
390
  else
391
391
  [all(:asset),
392
- :asset]
392
+ :asset, []]
393
393
  end
394
394
 
395
395
  ::GraphStarter::QueryAuthorizer.new(query, asset: GraphStarter.configuration.scope_filters[self.name.to_sym])
@@ -412,13 +412,13 @@ module GraphStarter
412
412
  .merge(model: {Model: {name: name}})
413
413
  .on_create_set(model: {private: false})
414
414
  .break
415
- .merge('model-[:HAS_PROPERTY]->(property:Property {name: property_name})')
415
+ .merge('(model)-[:HAS_PROPERTY]->(property:Property {name: property_name})')
416
416
  .on_create_set(property: {private: false})
417
417
  .on_create_set('property.uuid = uuid, property.ruby_type = ruby_type')
418
418
  .with(:property)
419
419
 
420
420
  ::GraphStarter::Property # rubocop:disable Lint/Void
421
- QueryAuthorizer.new(query).authorized_query(:property, user, [])
421
+ QueryAuthorizer.new(query).authorized_query(:property, [], user)
422
422
  end
423
423
 
424
424
  def self.property_name_and_uuid_and_ruby_type_query
@@ -14,7 +14,8 @@ module GraphStarter
14
14
  validates_attachment_content_type :source, content_type: ['image/jpg', 'image/jpeg', 'image/png', 'image/gif']
15
15
 
16
16
  def source_url
17
- source.present? ? source.url : original_url
17
+ default_style = GraphStarter.configuration.default_image_style
18
+ source.present? ? source.url(default_style) : original_url
18
19
  end
19
20
  end
20
21
  end
@@ -17,6 +17,6 @@
17
17
  - Array(result).each do |object|
18
18
  .item
19
19
  .content
20
- = render partial: '/graph_starter/assets/icon', locals: {asset: object}
20
+ = asset_icon object
21
21
  = link_to object.title, asset_path(object)
22
22
 
@@ -17,9 +17,10 @@
17
17
  .ui.relaxed.divided.list
18
18
  - categories[0,2].each do |category|
19
19
  .item
20
- = render partial: 'graph_starter/assets/icon', locals: {asset: category, image: (@category_images || {})[category.id]}
21
- .content
22
- = link_to category.safe_title, asset_path(category)
20
+ = asset_icon(category, (@category_images || {})[category.id])
21
+
22
+ .content = link_to category.safe_title, asset_path(category)
23
+
23
24
  - if categories.size > 2
24
25
  .item
25
26
  i.ellipsis.horizontal.large.icon
@@ -7,5 +7,4 @@
7
7
  - properties = model_class.properties
8
8
 
9
9
  .ui.link.cards
10
- - asset_group.each do |asset|
11
- = render partial: 'graph_starter/assets/card', locals: {asset: asset}
10
+ = render partial: 'graph_starter/assets/card', collection: asset_group, as: :asset
@@ -2,7 +2,7 @@ module GraphStarter
2
2
  class Configuration
3
3
  attr_writer :user_class
4
4
 
5
- attr_accessor :menu_models, :icon_classes, :scope_filters, :editable_properties
5
+ attr_accessor :menu_models, :icon_classes, :scope_filters, :editable_properties, :default_image_style
6
6
 
7
7
  def initialize
8
8
  @icon_classes = {}
@@ -89,9 +89,9 @@ module GraphStarter
89
89
  end
90
90
 
91
91
  def user_authorization_paths(variable, user_variable = :user)
92
- ["#{variable}<-[#{variable}_created_rel:CREATED]-#{user_variable}",
93
- "#{variable}<-[#{variable}_direct_access_rel:CAN_ACCESS]-#{user_variable}",
94
- "#{variable}<-[#{variable}_indirect_can_access_rel:CAN_ACCESS]-(:Group)<-[:HAS_SUBGROUP*0..5]-(:Group)<-[:BELONGS_TO]-#{user_variable}"]
92
+ ["(#{variable})<-[#{variable}_created_rel:CREATED]-(#{user_variable})",
93
+ "(#{variable})<-[#{variable}_direct_access_rel:CAN_ACCESS]-(#{user_variable})",
94
+ "(#{variable})<-[#{variable}_indirect_can_access_rel:CAN_ACCESS]-(:Group)<-[:HAS_SUBGROUP*0..5]-(:Group)<-[:BELONGS_TO]-(#{user_variable})"]
95
95
  end
96
96
  end
97
97
  end
@@ -1,3 +1,3 @@
1
1
  module GraphStarter
2
- VERSION = "0.16.1"
2
+ VERSION = "0.16.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graph_starter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.1
4
+ version: 0.16.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Underwood
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-06 00:00:00.000000000 Z
11
+ date: 2016-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: neo4j
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 6.0.0
33
+ version: 7.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 6.0.0
40
+ version: 7.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: semantic-ui-sass
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -196,9 +196,9 @@ files:
196
196
  - app/views/graph_starter/assets/_card.html.slim
197
197
  - app/views/graph_starter/assets/_cards.html.slim
198
198
  - app/views/graph_starter/assets/_extra_admin_buttons.html
199
+ - app/views/graph_starter/assets/_extra_buttons.html
199
200
  - app/views/graph_starter/assets/_extra_card_content.html.slim
200
201
  - app/views/graph_starter/assets/_form.html.slim
201
- - app/views/graph_starter/assets/_icon.html.slim
202
202
  - app/views/graph_starter/assets/_images.html.slim
203
203
  - app/views/graph_starter/assets/_property_items.html.slim
204
204
  - app/views/graph_starter/assets/_recommendations.html.slim
@@ -1,11 +0,0 @@
1
- - image_url = nil
2
- - if defined?(image)
3
- - image_url = image.source.url if defined?(image) && image.present?
4
- - elsif (asset.class.has_images? || asset.class.has_image?) && asset.first_image_source_url.present?
5
- - image_url = asset.first_image_source_url
6
-
7
- - if image_url
8
- = image_tag image_url, class: 'ui avatar image'
9
- - else
10
- i class="#{asset.class.icon_class || 'folder'} large icon"
11
-