graph_starter 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/graph_starter/assets_controller.rb +4 -2
- data/app/helpers/graph_starter/application_helper.rb +9 -1
- data/app/models/graph_starter/asset.rb +63 -10
- data/app/models/graph_starter/rating.rb +1 -1
- data/app/views/graph_starter/assets/_body.html.slim +15 -0
- data/app/views/graph_starter/assets/show.html.slim +19 -25
- data/app/views/graph_starter/properties/_property.html.slim +8 -4
- data/app/views/layouts/graph_starter/_menu.html.slim +1 -1
- data/app/views/layouts/graph_starter/application.html.slim +1 -1
- data/lib/graph_starter/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ee7e090e013ceee1f953a9859c2d469ec6f82c1
|
4
|
+
data.tar.gz: f039138c5c6fea91161098c1722979e5a85e2a40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff56c5adb8387d6d1ef8266faf4b07402548c7521a5dd668693c66f1507a2c4961241b99eae8231095178ad4daaf44c73c9f306247d0527001245b019c29754d
|
7
|
+
data.tar.gz: 4eec5d0d5d330cece01ca5fb15f4d0c2acfe2a9e8c47307af807d87c6180b2ba0f5352e24d5ec737cf3e23680f03236a32e976e5e85ff74d876c1741b5d523c7
|
@@ -70,9 +70,11 @@ module GraphStarter
|
|
70
70
|
def rate
|
71
71
|
if current_user
|
72
72
|
rating = asset.rating_for(current_user)
|
73
|
-
rating ||= Rating.
|
73
|
+
rating ||= Rating.create(from_node: current_user, to_node: asset)
|
74
74
|
|
75
|
-
|
75
|
+
new_rating = params[:new_rating].to_i
|
76
|
+
new_rating = nil if new_rating.zero?
|
77
|
+
rating.update_attribute(:level, new_rating)
|
76
78
|
|
77
79
|
render json: rating
|
78
80
|
else
|
@@ -6,6 +6,14 @@ module GraphStarter
|
|
6
6
|
|
7
7
|
def engine_view(&b)
|
8
8
|
yield eval("__FILE__.gsub(Rails.root.to_s, GraphStarter::Engine.root.to_s)",b.binding)
|
9
|
-
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def render_body
|
12
|
+
views = Dir.glob(Rails.root.join("app/views/#{@model_slug}/_body.html.*"))
|
13
|
+
|
14
|
+
partial_path = views.present? ? "#{@model_slug}/body" : 'body'
|
15
|
+
|
16
|
+
render partial: partial_path, locals: {asset: @asset}
|
17
|
+
end
|
10
18
|
end
|
11
19
|
end
|
@@ -13,9 +13,6 @@ module GraphStarter
|
|
13
13
|
|
14
14
|
property :view_count, type: Integer
|
15
15
|
|
16
|
-
property :private, type: Boolean, default: false
|
17
|
-
|
18
|
-
|
19
16
|
if GraphStarter.configuration.user_class
|
20
17
|
#has_many :in, :creators, type: :CREATED, model_class: GraphStarter.configuration.user_class
|
21
18
|
|
@@ -27,12 +24,14 @@ module GraphStarter
|
|
27
24
|
|
28
25
|
SecretSauceRecommendation = Struct.new(:asset, :score)
|
29
26
|
|
30
|
-
def body
|
31
|
-
end
|
32
|
-
|
33
27
|
def self.has_images
|
34
28
|
@has_images = true
|
35
29
|
has_many :out, :images, type: :HAS_IMAGE, model_class: '::GraphStarter::Image'
|
30
|
+
has_one :out, :image, type: :HAS_IMAGE, model_class: '::GraphStarter::Image'
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.has_image
|
34
|
+
has_images
|
36
35
|
end
|
37
36
|
|
38
37
|
def self.has_images?
|
@@ -40,7 +39,7 @@ module GraphStarter
|
|
40
39
|
end
|
41
40
|
|
42
41
|
def first_image_source_url
|
43
|
-
|
42
|
+
image && image.source_url
|
44
43
|
end
|
45
44
|
|
46
45
|
def self.category_association(association_name = nil)
|
@@ -80,7 +79,7 @@ module GraphStarter
|
|
80
79
|
else
|
81
80
|
fail "Cannot declare name_property twice" if @name_property.present?
|
82
81
|
name = property_name.to_sym
|
83
|
-
fail ArgumentError, "Property #{name} is not defined" if attributes
|
82
|
+
fail ArgumentError, "Property #{name} is not defined" if !attributes.key?(name.to_s)
|
84
83
|
@name_property = name
|
85
84
|
|
86
85
|
validates name, presence: true
|
@@ -88,6 +87,10 @@ module GraphStarter
|
|
88
87
|
end
|
89
88
|
end
|
90
89
|
|
90
|
+
def self.name_property?(property_name)
|
91
|
+
@name_property && @name_property.to_sym == property_name.to_sym
|
92
|
+
end
|
93
|
+
|
91
94
|
def self.default_name_property
|
92
95
|
(%w(name title) & attributes.keys)[0].tap do |property|
|
93
96
|
if property.nil?
|
@@ -96,6 +99,46 @@ module GraphStarter
|
|
96
99
|
end
|
97
100
|
end
|
98
101
|
|
102
|
+
|
103
|
+
def self.body_property(property_name = nil)
|
104
|
+
if property_name.nil?
|
105
|
+
body_property(default_name_property) if @body_property.nil?
|
106
|
+
|
107
|
+
@body_property
|
108
|
+
else
|
109
|
+
fail "Cannot declare body_property twice" if @body_property.present?
|
110
|
+
name = property_name.to_sym
|
111
|
+
fail ArgumentError, "Property #{name} is not defined" if !attributes.key?(name.to_s)
|
112
|
+
@body_property = name
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.body_property?(property_name)
|
117
|
+
@body_property && @body_property.to_sym == property_name.to_sym
|
118
|
+
end
|
119
|
+
|
120
|
+
def self.default_body_property
|
121
|
+
if @body_property.nil? && !attributes.key?('body')
|
122
|
+
fail "No body_property defined for #{self.name}!"
|
123
|
+
end
|
124
|
+
|
125
|
+
body_property || 'body'
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
def self.display_properties(*property_names)
|
130
|
+
if property_names.empty?
|
131
|
+
@display_properties || []
|
132
|
+
else
|
133
|
+
@display_properties = property_names.map(&:to_sym)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def self.display_property?(property_name)
|
138
|
+
display_properties.include?(property_name.to_sym)
|
139
|
+
end
|
140
|
+
|
141
|
+
|
99
142
|
def rating_level_for(user)
|
100
143
|
rating = rating_for(user)
|
101
144
|
rating && rating.level
|
@@ -111,6 +154,12 @@ module GraphStarter
|
|
111
154
|
read_attribute(self.class.name_property)
|
112
155
|
end
|
113
156
|
|
157
|
+
send(method_name)
|
158
|
+
elsif method_name.to_sym == :body
|
159
|
+
self.class.send(:define_method, method_name) do
|
160
|
+
read_attribute(self.class.body_property)
|
161
|
+
end
|
162
|
+
|
114
163
|
send(method_name)
|
115
164
|
else
|
116
165
|
super
|
@@ -138,6 +187,8 @@ module GraphStarter
|
|
138
187
|
|
139
188
|
def secret_sauce_recommendations
|
140
189
|
user_class = GraphStarter.configuration.user_class
|
190
|
+
return [] if user_class.nil? # Should fix this later
|
191
|
+
|
141
192
|
user_class = (user_class.is_a?(Class) ? user_class : user_class.to_s.constantize)
|
142
193
|
user_label = user_class.mapped_label_name
|
143
194
|
|
@@ -225,7 +276,9 @@ module GraphStarter
|
|
225
276
|
|
226
277
|
def self.property_name_and_uuid_and_ruby_type_query
|
227
278
|
properties_and_uuids_and_ruby_types = properties.map do |property|
|
228
|
-
|
279
|
+
type = self.attributes[property][:type]
|
280
|
+
type = type.name if type.is_a?(Class)
|
281
|
+
[property, SecureRandom.uuid, type]
|
229
282
|
end
|
230
283
|
|
231
284
|
Neo4j::Session.current.query
|
@@ -236,7 +289,7 @@ module GraphStarter
|
|
236
289
|
end
|
237
290
|
|
238
291
|
def self.authorized_associations
|
239
|
-
associations.except(*Asset.associations.keys + [:images])
|
292
|
+
associations.except(*Asset.associations.keys + [:images, :image])
|
240
293
|
end
|
241
294
|
|
242
295
|
def self.icon_class
|
@@ -0,0 +1,15 @@
|
|
1
|
+
- if asset.body.present?
|
2
|
+
= asset.body
|
3
|
+
- if asset.images.present?
|
4
|
+
.ui.link.cards
|
5
|
+
- asset.images.each do |image|
|
6
|
+
.card
|
7
|
+
.image = image_tag image.source_url, class: 'ui image tiny rounded'
|
8
|
+
.content
|
9
|
+
.header = image.title if image.title.present?
|
10
|
+
- if image.description.present?
|
11
|
+
.meta = image.description
|
12
|
+
.extra.content
|
13
|
+
a.ui.large.green.button href="#{image.source_url}" Full Size
|
14
|
+
|
15
|
+
|
@@ -55,29 +55,17 @@ javascript:
|
|
55
55
|
|
56
56
|
- if main_column_exists
|
57
57
|
.ten.wide.column
|
58
|
-
|
59
|
-
= @asset.body
|
60
|
-
- if @asset.images.present?
|
61
|
-
.ui.link.cards
|
62
|
-
- @asset.images.each do |image|
|
63
|
-
.card
|
64
|
-
.image = image_tag image.source_url, class: 'ui image tiny rounded'
|
65
|
-
.content
|
66
|
-
.header = image.title if image.title.present?
|
67
|
-
- if image.description.present?
|
68
|
-
.meta = image.description
|
69
|
-
.extra.content
|
70
|
-
a.ui.large.green.button href="#{image.source_url}" Full Size
|
71
|
-
|
58
|
+
= render_body
|
72
59
|
|
73
60
|
div class="#{side_column_width} wide column" id="right-column"
|
74
61
|
- if @current_user_is_admin
|
75
62
|
a.ui.labeled.icon.button.right.floated data-authorizable="#{@asset.to_json}"
|
76
63
|
| Edit Permissions
|
77
64
|
|
78
|
-
|
79
|
-
|
80
|
-
|
65
|
+
- if @current_user_is_admin
|
66
|
+
a.ui.labeled.icon.button.right.floated href="#{edit_asset_path(id: @asset)}"
|
67
|
+
i.edit.icon
|
68
|
+
| Edit
|
81
69
|
|
82
70
|
.ui.items
|
83
71
|
- if @asset.class.rated? && defined?(current_user) && current_user
|
@@ -88,6 +76,7 @@ javascript:
|
|
88
76
|
.ui.star.rating data-max-rating="5" data-rating="#{@asset.rating_level_for(current_user)}"
|
89
77
|
coffee:
|
90
78
|
$('#right-column .ui.rating').rating
|
79
|
+
clearable: true
|
91
80
|
onRate: (new_rating) ->
|
92
81
|
$.ajax
|
93
82
|
method: 'PUT'
|
@@ -95,6 +84,9 @@ javascript:
|
|
95
84
|
|
96
85
|
|
97
86
|
- @asset.class.authorized_properties(defined?(current_user) && current_user).each do |property|
|
87
|
+
- next if !@asset.class.display_property?(property.name)
|
88
|
+
- next if @asset.class.name_property?(property.name) || @asset.class.body_property?(property.name)
|
89
|
+
|
98
90
|
- if @asset.read_attribute(property.name).present?
|
99
91
|
.item
|
100
92
|
.content
|
@@ -105,12 +97,14 @@ javascript:
|
|
105
97
|
.description
|
106
98
|
= render partial: 'graph_starter/properties/property', locals: {property: property, asset: @asset, level: 'read'}
|
107
99
|
|
108
|
-
.
|
109
|
-
.
|
110
|
-
.
|
111
|
-
|
100
|
+
- if @asset.class.display_property?(:created_at)
|
101
|
+
.item
|
102
|
+
.content
|
103
|
+
.ui.horizontal.divider Created
|
104
|
+
.description = @asset.created_at
|
112
105
|
|
113
|
-
.
|
114
|
-
.
|
115
|
-
.
|
116
|
-
|
106
|
+
- if @asset.class.display_property?(:updated_at)
|
107
|
+
.item
|
108
|
+
.content
|
109
|
+
.ui.horizontal.divider Last updated
|
110
|
+
.description = @asset.updated_at
|
@@ -1,12 +1,14 @@
|
|
1
1
|
- can_write = (level == 'write') && !form.nil?
|
2
2
|
|
3
|
+
- value = asset.read_attribute(property.name)
|
4
|
+
|
3
5
|
- ruby_type = property.ruby_type.to_s
|
4
6
|
- case ruby_type
|
5
7
|
- when 'Integer'
|
6
8
|
- if can_write
|
7
9
|
= form.number_field property.name
|
8
10
|
- else
|
9
|
-
=
|
11
|
+
= value
|
10
12
|
- when 'DateTime', 'Date'
|
11
13
|
- if can_write
|
12
14
|
i.calendar.icon
|
@@ -15,7 +17,6 @@
|
|
15
17
|
- strftime_format = {'DateTime' => '%Y-%m-%d %H:%M', 'Date' => '%Y-%m-%d'}[ruby_type]
|
16
18
|
|
17
19
|
- id = SecureRandom.uuid
|
18
|
-
- value = asset.read_attribute(property.name)
|
19
20
|
|
20
21
|
= form.text_field property.name, value: value && value.strftime(strftime_format), id: id
|
21
22
|
|
@@ -25,10 +26,13 @@
|
|
25
26
|
$('##{id}').datetimepicker({#{js_options.html_safe}});
|
26
27
|
});
|
27
28
|
- else
|
28
|
-
=
|
29
|
+
= value
|
29
30
|
|
30
31
|
- else
|
31
32
|
- if can_write
|
32
33
|
= form.text_field property.name
|
33
34
|
- else
|
34
|
-
|
35
|
+
- if property.name.to_s.match(/url$/i)
|
36
|
+
= link_to value, value
|
37
|
+
- else
|
38
|
+
= value
|
@@ -2,6 +2,6 @@
|
|
2
2
|
= link_to 'Home', '/', class: "item #{'active' if request.path == '/'}"
|
3
3
|
- GraphStarter::Asset.descendants.each do |model_class|
|
4
4
|
- path = graph_starter.assets_path(model_slug: model_class.model_slug)
|
5
|
-
= link_to model_class.name.
|
5
|
+
= link_to model_class.name.tableize.humanize, path, class: "item #{'active' if request.path.match(/^#{path}/)}"
|
6
6
|
|
7
7
|
= render 'layouts/graph_starter/custom_menu'
|
@@ -3,7 +3,7 @@ doctype html
|
|
3
3
|
html
|
4
4
|
|
5
5
|
head
|
6
|
-
title
|
6
|
+
title = @title || Rails.application.class.to_s.split("::").first.tableize.singularize.humanize
|
7
7
|
= stylesheet_link_tag 'graph_starter/application', media: 'all', 'data-turbolinks-track' => true
|
8
8
|
|
9
9
|
= render partial: 'layouts/graph_starter/twitter_meta_tags'
|
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.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Underwood
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -131,6 +131,7 @@ files:
|
|
131
131
|
- app/models/graph_starter/rating.rb
|
132
132
|
- app/models/graph_starter/view.rb
|
133
133
|
- app/views/graph_starter/assets/TODO.md
|
134
|
+
- app/views/graph_starter/assets/_body.html.slim
|
134
135
|
- app/views/graph_starter/assets/_cards.html.slim
|
135
136
|
- app/views/graph_starter/assets/edit.html.slim
|
136
137
|
- app/views/graph_starter/assets/home.html.slim
|