mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-25 09:19:15 -04:00
Compare commits
316 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b4fcf004cd | ||
|
|
b783448ec3 | ||
|
|
e8b5850bfe | ||
|
|
bca72680c4 | ||
|
|
358eb96684 | ||
|
|
05807d41f4 | ||
|
|
96f1995768 | ||
|
|
deefbbce71 | ||
|
|
1f66df0743 | ||
|
|
72f52230a1 | ||
|
|
acecbe93c1 | ||
|
|
bafe2b7fd1 | ||
|
|
3be1454a69 | ||
|
|
232e5d50ac | ||
|
|
7207a39039 | ||
|
|
291f865f7f | ||
|
|
47e82eb0a7 | ||
|
|
08dc2a0513 | ||
|
|
5d44196947 | ||
|
|
1c41cb7b66 | ||
|
|
c3c55eaa09 | ||
|
|
98aa9521fe | ||
|
|
96bb345ca9 | ||
|
|
9de991a075 | ||
|
|
f76619864c | ||
|
|
ec149997b0 | ||
|
|
ac07f18b2d | ||
|
|
4ce3e8968f | ||
|
|
cd35538b83 | ||
|
|
35d8461811 | ||
|
|
8d03a3ffa8 | ||
|
|
2b0f199329 | ||
|
|
24f18f78da | ||
|
|
3cc637017d | ||
|
|
37f9dcd7dd | ||
|
|
f516ef2e57 | ||
|
|
182c626226 | ||
|
|
ea2fcd09dc | ||
|
|
878fc7ebcd | ||
|
|
3fdc23098e | ||
|
|
515325c44e | ||
|
|
25b1836146 | ||
|
|
c925c95398 | ||
|
|
2d00206abf | ||
|
|
f499f245de | ||
|
|
35414391c3 | ||
|
|
1f7f4f52d1 | ||
|
|
b4efeee904 | ||
|
|
5b588bf9e9 | ||
|
|
07611e9a5d | ||
|
|
baa89a790f | ||
|
|
00395ae68b | ||
|
|
d7eb5e0014 | ||
|
|
f08d02f4c5 | ||
|
|
a6a7f789a3 | ||
|
|
6ed7376c58 | ||
|
|
c8a200bf19 | ||
|
|
a62b668781 | ||
|
|
09f82d5995 | ||
|
|
8d0bec34a6 | ||
|
|
d7ec4eacee | ||
|
|
3a3f4eefbf | ||
|
|
9e00023332 | ||
|
|
3058160a59 | ||
|
|
e3886ce5b5 | ||
|
|
48f8085e2d | ||
|
|
594e466fd4 | ||
|
|
b813669d71 | ||
|
|
d0b8ae3411 | ||
|
|
9c993e9f47 | ||
|
|
d5fece87d0 | ||
|
|
33816d4312 | ||
|
|
00e6aeed5c | ||
|
|
0205b345d0 | ||
|
|
9f8a32e9f8 | ||
|
|
7357524271 | ||
|
|
6aa689b0d8 | ||
|
|
962b3b574d | ||
|
|
d77d1d9a77 | ||
|
|
4bed6da422 | ||
|
|
023c870d49 | ||
|
|
9aff65e956 | ||
|
|
0446c0a405 | ||
|
|
7719d1f896 | ||
|
|
c9558e4d51 | ||
|
|
8a679670e4 | ||
|
|
a7586e9d2b | ||
|
|
811011419e | ||
|
|
dae3ea2789 | ||
|
|
49aa6bb846 | ||
|
|
c154a9b845 | ||
|
|
ad14ecb41b | ||
|
|
08a73ce503 | ||
|
|
6663f3ade4 | ||
|
|
451030761d | ||
|
|
d4e4ca6519 | ||
|
|
284f0cddcd | ||
|
|
4ced7ee7e9 | ||
|
|
b60510e016 | ||
|
|
e85daa405b | ||
|
|
9ab83f7bbc | ||
|
|
329e0106bb | ||
|
|
4743fc7a63 | ||
|
|
c66a5b12a5 | ||
|
|
f98bb32612 | ||
|
|
771443ee85 | ||
|
|
1322ebd8e3 | ||
|
|
9e98db423e | ||
|
|
305702f644 | ||
|
|
1f4f806bb0 | ||
|
|
6a17ba547f | ||
|
|
3ffdc61428 | ||
|
|
bb6e9e32e6 | ||
|
|
229396d9e7 | ||
|
|
0fa02272b0 | ||
|
|
a91b8605c4 | ||
|
|
f1107b518c | ||
|
|
52d93a7ccd | ||
|
|
d3df1e8f33 | ||
|
|
eb77715b70 | ||
|
|
252910694d | ||
|
|
bd063be3a9 | ||
|
|
9a6d827b6d | ||
|
|
ede5187369 | ||
|
|
610a5b7a48 | ||
|
|
1fa71c1546 | ||
|
|
7574eb554e | ||
|
|
eea7e19ecf | ||
|
|
dafaffcd73 | ||
|
|
3e149a5d1d | ||
|
|
c20d9b78c5 | ||
|
|
7906d50d13 | ||
|
|
faed8b019e | ||
|
|
c8974a869f | ||
|
|
3969f410f1 | ||
|
|
6304f230a5 | ||
|
|
73524b8883 | ||
|
|
fd9fc38def | ||
|
|
949c7c31d8 | ||
|
|
e34dcd03bc | ||
|
|
929229379e | ||
|
|
d8bf8ae4df | ||
|
|
ac0e52f15d | ||
|
|
c7f427fe8a | ||
|
|
50fd9ae9b0 | ||
|
|
efe39da878 | ||
|
|
1cd3c64590 | ||
|
|
b591529892 | ||
|
|
cef236d8f8 | ||
|
|
5ad0068142 | ||
|
|
b8a5ff9acf | ||
|
|
90653aa57f | ||
|
|
80a4739f34 | ||
|
|
a6cc530fe5 | ||
|
|
97f19a0038 | ||
|
|
140611d868 | ||
|
|
3fa5ffc544 | ||
|
|
eeafb4caa5 | ||
|
|
c747d46ab5 | ||
|
|
3009ed2d83 | ||
|
|
f68a15c04e | ||
|
|
06295fb9e9 | ||
|
|
c4a1806a87 | ||
|
|
fa5e151af0 | ||
|
|
13e8d1f5a5 | ||
|
|
c1836cc78e | ||
|
|
28fdb6e1ed | ||
|
|
67dec795a0 | ||
|
|
86ea8eab39 | ||
|
|
8884056ff3 | ||
|
|
d01a5d7976 | ||
|
|
66c08650ba | ||
|
|
521873b656 | ||
|
|
83fea92353 | ||
|
|
2060d9ab9e | ||
|
|
1795b27152 | ||
|
|
1317ce9db0 | ||
|
|
93193c9fba | ||
|
|
e489831241 | ||
|
|
df7a9448b0 | ||
|
|
3d4f5c6917 | ||
|
|
1b4d77e017 | ||
|
|
08e7c7dd29 | ||
|
|
5fec826c41 | ||
|
|
c29234c40c | ||
|
|
2f0cb5c815 | ||
|
|
b6cbfe25d2 | ||
|
|
d8f5876518 | ||
|
|
ae2cbf0bec | ||
|
|
c9d5c42814 | ||
|
|
b60f47f502 | ||
|
|
d86e0af5ad | ||
|
|
fc0058d677 | ||
|
|
41110f96d1 | ||
|
|
33822abf93 | ||
|
|
5877da95a6 | ||
|
|
88a119deac | ||
|
|
d07fd1a277 | ||
|
|
c96695258b | ||
|
|
2fbba52bc8 | ||
|
|
a2ae429f6b | ||
|
|
7ca76e69cf | ||
|
|
c6824b1262 | ||
|
|
2a74c057f3 | ||
|
|
85cc9e77c6 | ||
|
|
a0d6d154f0 | ||
|
|
7e9707e3b0 | ||
|
|
4fe0dba28e | ||
|
|
328037b8c0 | ||
|
|
e4ab5114f7 | ||
|
|
a5d43af899 | ||
|
|
2d384c9851 | ||
|
|
205247b136 | ||
|
|
963a182981 | ||
|
|
1090db6d21 | ||
|
|
f187b31653 | ||
|
|
809dd81378 | ||
|
|
62beec23a1 | ||
|
|
a60a5ce591 | ||
|
|
7206f99510 | ||
|
|
bf6475da57 | ||
|
|
c5971cd46b | ||
|
|
2f47eeb7b3 | ||
|
|
928749aaad | ||
|
|
1d64d4d1d2 | ||
|
|
1e86cf7662 | ||
|
|
941dab7c4a | ||
|
|
2696d12771 | ||
|
|
6bf87c243c | ||
|
|
ec63d8086f | ||
|
|
470aacd1c9 | ||
|
|
9997c365d8 | ||
|
|
eaa65fda9e | ||
|
|
e844eade94 | ||
|
|
35e7b6a5b4 | ||
|
|
6c33c335d8 | ||
|
|
26537943e3 | ||
|
|
136c082003 | ||
|
|
b3fd8e32d0 | ||
|
|
9b1b22afa8 | ||
|
|
996706ee78 | ||
|
|
9d11bcc039 | ||
|
|
b1684b0156 | ||
|
|
ec00baef0d | ||
|
|
eb585611fe | ||
|
|
9280049a84 | ||
|
|
53d7fd1479 | ||
|
|
4cc0f77bd0 | ||
|
|
5e5773aa59 | ||
|
|
2422939b4f | ||
|
|
d5a1a683f1 | ||
|
|
f5bb47e4ca | ||
|
|
8359218294 | ||
|
|
285e6edc61 | ||
|
|
f2fac9db1b | ||
|
|
cabc4fd030 | ||
|
|
20fe9e4cc5 | ||
|
|
fac24c5e99 | ||
|
|
fa600bea9e | ||
|
|
99e7fb1f7d | ||
|
|
81e22d6fb2 | ||
|
|
10a8df47a9 | ||
|
|
b0a4df629c | ||
|
|
0b8357a261 | ||
|
|
7104781d1b | ||
|
|
267f27b3f8 | ||
|
|
31a37bf6dc | ||
|
|
d1951b8b65 | ||
|
|
cd99769311 | ||
|
|
71cb3f8c5f | ||
|
|
d540342acb | ||
|
|
f66b0768e2 | ||
|
|
251f44b0c7 | ||
|
|
adf07ce5ef | ||
|
|
54b204c636 | ||
|
|
ff446c2139 | ||
|
|
62d84d7af4 | ||
|
|
92fa09a1d3 | ||
|
|
b09c4aa7a1 | ||
|
|
692ab59285 | ||
|
|
302bdba150 | ||
|
|
aa3057056f | ||
|
|
9ef40532ad | ||
|
|
70ba8c8421 | ||
|
|
3b81affbe5 | ||
|
|
9703d4e983 | ||
|
|
22e1718ce6 | ||
|
|
b90b4e42fb | ||
|
|
202f557e32 | ||
|
|
8364c8c688 | ||
|
|
3a286cd240 | ||
|
|
41dbf6fb1b | ||
|
|
47ecbe3f94 | ||
|
|
0f066ab302 | ||
|
|
8e94ddb4bf | ||
|
|
a9cedc6a8a | ||
|
|
7d6c49d8c3 | ||
|
|
0d8ca89b14 | ||
|
|
82a37d69bc | ||
|
|
4533d35fe7 | ||
|
|
4b445907d5 | ||
|
|
fce6395d21 | ||
|
|
2946dca5fc | ||
|
|
9eb6d84e5a | ||
|
|
96b4742e78 | ||
|
|
68c14a695e | ||
|
|
e42ec4f8ae | ||
|
|
f7b75157e7 | ||
|
|
7e27b6deef | ||
|
|
cd69ea1487 | ||
|
|
4cdcbdac19 | ||
|
|
f3d03c00b2 | ||
|
|
d9aa9df7fe | ||
|
|
af60489459 | ||
|
|
f3e88f5aae | ||
|
|
1e81dac699 |
22
.rubocop.yml
22
.rubocop.yml
@@ -7,32 +7,40 @@ AllCops:
|
||||
Exclude:
|
||||
- 'db/schema.rb'
|
||||
- 'vendor/**/*'
|
||||
TargetRailsVersion: 4.0
|
||||
|
||||
Rails:
|
||||
Enabled: true
|
||||
|
||||
Style/FileName:
|
||||
Exclude:
|
||||
- 'Guardfile'
|
||||
- 'Gemfile'
|
||||
- 'Gemfile.lock'
|
||||
|
||||
Style/StringLiterals:
|
||||
Enabled: false
|
||||
|
||||
Style/MultilineMethodCallIndentation:
|
||||
# Stop hound and codeclimate fighting
|
||||
Style/PercentLiteralDelimiters:
|
||||
PreferredDelimiters:
|
||||
default: ()
|
||||
'%i': ()
|
||||
'%w': ()
|
||||
|
||||
Layout/MultilineMethodCallIndentation:
|
||||
EnforcedStyle: indented
|
||||
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
|
||||
# SupportedStyles: with_first_parameter, with_fixed_indentation
|
||||
Style/AlignParameters:
|
||||
Layout/AlignParameters:
|
||||
EnforcedStyle: with_fixed_indentation
|
||||
|
||||
Metrics/LineLength:
|
||||
Max: 120
|
||||
|
||||
|
||||
# See https://github.com/bbatsov/rubocop/issues/3629
|
||||
Rails/HttpPositionalArguments:
|
||||
# turn these back on in Rails 5
|
||||
Rails/HttpPositionalArguments: # See https://github.com/bbatsov/rubocop/issues/3629
|
||||
Enabled: false
|
||||
|
||||
Style/Documentation:
|
||||
@@ -58,9 +66,9 @@ Metrics/BlockLength:
|
||||
Metrics/MethodLength:
|
||||
Max: 34
|
||||
Metrics/AbcSize:
|
||||
Max: 32
|
||||
Max: 31
|
||||
Metrics/ClassLength:
|
||||
Max: 207
|
||||
Max: 179
|
||||
Metrics/CyclomaticComplexity:
|
||||
Max: 11
|
||||
Metrics/PerceivedComplexity:
|
||||
|
||||
@@ -1,23 +1,15 @@
|
||||
# This configuration was generated by
|
||||
# `rubocop --auto-gen-config --no-offense-counts`
|
||||
# on 2017-05-28 10:57:55 +1200 using RuboCop version 0.47.1.
|
||||
# on 2017-12-06 11:20:15 +1300 using RuboCop version 0.49.1.
|
||||
# The point is for the user to remove these configuration records
|
||||
# one by one as the offenses are removed from the code base.
|
||||
# Note that changes in the inspected code, or installation of new
|
||||
# versions of RuboCop, may require this file to be generated again.
|
||||
|
||||
|
||||
Lint/HandleExceptions:
|
||||
Exclude:
|
||||
- 'lib/tasks/testing.rake'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
|
||||
Lint/UnusedBlockArgument:
|
||||
Exclude:
|
||||
- 'app/controllers/sessions_controller.rb'
|
||||
- 'config/unicorn.rb'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
|
||||
Lint/UnusedMethodArgument:
|
||||
@@ -26,12 +18,6 @@ Lint/UnusedMethodArgument:
|
||||
- 'app/controllers/passwords_controller.rb'
|
||||
- 'app/controllers/registrations_controller.rb'
|
||||
- 'app/validators/approved_validator.rb'
|
||||
- 'spec/views/plantings/show.html.haml_spec.rb'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
Performance/StringReplacement:
|
||||
Exclude:
|
||||
- 'spec/rails_helper.rb'
|
||||
|
||||
Rails/FilePath:
|
||||
Exclude:
|
||||
@@ -57,7 +43,6 @@ Rails/TimeZone:
|
||||
- 'spec/factories/member.rb'
|
||||
- 'spec/factories/post.rb'
|
||||
- 'spec/models/post_spec.rb'
|
||||
- 'spec/views/plantings/index.html.haml_spec.rb'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
@@ -71,37 +56,6 @@ Style/AsciiComments:
|
||||
Exclude:
|
||||
- 'config/initializers/comfortable_mexican_sofa.rb'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
# SupportedStyles: percent_q, bare_percent
|
||||
Style/BarePercentLiterals:
|
||||
Exclude:
|
||||
- 'app/helpers/auto_suggest_helper.rb'
|
||||
- 'spec/support/feature_helpers.rb'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
|
||||
# SupportedStyles: line_count_based, semantic, braces_for_chaining
|
||||
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
|
||||
# FunctionalMethods: let, let!, subject, watch
|
||||
# IgnoredMethods: lambda, proc, it
|
||||
Style/BlockDelimiters:
|
||||
Exclude:
|
||||
- 'spec/controllers/order_items_controller_spec.rb'
|
||||
- 'spec/features/notifications_spec.rb'
|
||||
- 'spec/models/ability_spec.rb'
|
||||
- 'spec/models/comment_spec.rb'
|
||||
- 'spec/models/follow_spec.rb'
|
||||
- 'spec/models/member_spec.rb'
|
||||
- 'spec/models/post_spec.rb'
|
||||
- 'spec/views/crops/edit.html.haml_spec.rb'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
Style/BlockEndNewline:
|
||||
Exclude:
|
||||
- 'spec/models/ability_spec.rb'
|
||||
- 'spec/models/member_spec.rb'
|
||||
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
# SupportedStyles: nested, compact
|
||||
Style/ClassAndModuleChildren:
|
||||
@@ -110,46 +64,10 @@ Style/ClassAndModuleChildren:
|
||||
- 'lib/actions/oauth_signup_action.rb'
|
||||
- 'lib/haml/filters/escaped_markdown.rb'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
Style/ColonMethodCall:
|
||||
Exclude:
|
||||
- 'spec/lib/haml/filters/escaped_markdown_spec.rb'
|
||||
- 'spec/lib/haml/filters/growstuff_markdown_spec.rb'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
Style/EachForSimpleLoop:
|
||||
Exclude:
|
||||
- 'spec/models/crop_spec.rb'
|
||||
- 'spec/views/home/_crops.html.haml_spec.rb'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
# SupportedStyles: compact, expanded
|
||||
Style/EmptyMethod:
|
||||
Exclude:
|
||||
- 'app/controllers/roles_controller.rb'
|
||||
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
# SupportedStyles: format, sprintf, percent
|
||||
Style/FormatString:
|
||||
Exclude:
|
||||
- 'app/helpers/application_helper.rb'
|
||||
- 'spec/helpers/application_helper_spec.rb'
|
||||
- 'spec/views/shop/index_spec.rb'
|
||||
|
||||
Style/IdenticalConditionalBranches:
|
||||
Exclude:
|
||||
- 'app/controllers/follows_controller.rb'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: MaxLineLength.
|
||||
Style/IfUnlessModifier:
|
||||
Exclude:
|
||||
- 'app/helpers/crops_helper.rb'
|
||||
- 'app/models/planting.rb'
|
||||
- 'config/initializers/geocoder.rb'
|
||||
- 'lib/tasks/growstuff.rake'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
# SupportedStyles: line_count_dependent, lambda, literal
|
||||
@@ -163,33 +81,11 @@ Style/MultilineIfModifier:
|
||||
Exclude:
|
||||
- 'spec/rails_helper.rb'
|
||||
|
||||
Style/MultilineTernaryOperator:
|
||||
Exclude:
|
||||
- 'app/controllers/notifications_controller.rb'
|
||||
- 'app/controllers/order_items_controller.rb'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
Style/MutableConstant:
|
||||
Exclude:
|
||||
- 'app/models/planting.rb'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
Style/NegatedIf:
|
||||
Exclude:
|
||||
- 'app/helpers/crops_helper.rb'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
|
||||
# SupportedStyles: skip_modifier_ifs, always
|
||||
Style/Next:
|
||||
Exclude:
|
||||
- 'lib/tasks/growstuff.rake'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
Style/NilComparison:
|
||||
Exclude:
|
||||
- 'lib/tasks/growstuff.rake'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: AutoCorrect, EnforcedStyle, SupportedStyles.
|
||||
# SupportedStyles: predicate, comparison
|
||||
@@ -205,14 +101,6 @@ Style/ParallelAssignment:
|
||||
Exclude:
|
||||
- 'app/mailers/notifier.rb'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: PreferredDelimiters.
|
||||
Style/PercentLiteralDelimiters:
|
||||
Exclude:
|
||||
- 'app/helpers/auto_suggest_helper.rb'
|
||||
- 'spec/features/signin_spec.rb'
|
||||
- 'spec/features/signout_spec.rb'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
|
||||
# SupportedStyles: slashes, percent_r, mixed
|
||||
@@ -223,24 +111,3 @@ Style/RegexpLiteral:
|
||||
- 'spec/views/devise/registrations/edit_spec.rb'
|
||||
- 'spec/views/members/index.html.haml_spec.rb'
|
||||
- 'spec/views/posts/index.html.haml_spec.rb'
|
||||
- 'spec/views/posts/show.html.haml_spec.rb'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: SupportedStyles.
|
||||
# SupportedStyles: use_perl_names, use_english_names
|
||||
Style/SpecialGlobalVars:
|
||||
EnforcedStyle: use_perl_names
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: IgnoredMethods.
|
||||
# IgnoredMethods: respond_to, define_method
|
||||
Style/SymbolProc:
|
||||
Exclude:
|
||||
- 'lib/tasks/growstuff.rake'
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: SupportedStyles, WordRegex.
|
||||
# SupportedStyles: percent, brackets
|
||||
Style/WordArray:
|
||||
EnforcedStyle: percent
|
||||
MinSize: 5
|
||||
|
||||
@@ -33,7 +33,7 @@ before_script:
|
||||
if [ "${STATIC_CHECKS}" = "true" ]; then
|
||||
./script/install_linters;
|
||||
else
|
||||
bundle exec rake db:create db:migrate db:test:prepare;
|
||||
RAILS_ENV=test bundle exec rake db:create db:migrate;
|
||||
bundle exec rake assets:precompile;
|
||||
fi
|
||||
- set +e
|
||||
|
||||
@@ -81,6 +81,7 @@ submit the change with your pull request.
|
||||
- Arun Kumar / [arun1595](https://github.com/arun1595)
|
||||
- Harry Brodsky / [hbrodsk1](https://github.com/hbrodsk1)
|
||||
- Jeff Kingswood / [ancyentmariner](https://github.com/ancyentmariner)
|
||||
- Logan Gingerich / [logangingerich](https://github.com/logangingerich)
|
||||
|
||||
## Bots
|
||||
|
||||
|
||||
21
Gemfile
21
Gemfile
@@ -1,4 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
source 'https://rubygems.org'
|
||||
|
||||
ruby '2.4.1'
|
||||
@@ -11,12 +12,18 @@ gem 'coffee-rails'
|
||||
gem 'haml'
|
||||
gem 'sass-rails'
|
||||
|
||||
# API data
|
||||
gem 'jsonapi-resources'
|
||||
|
||||
# CSS framework
|
||||
gem 'bootstrap-sass'
|
||||
gem 'font-awesome-sass'
|
||||
|
||||
gem 'uglifier' # JavaScript compressor
|
||||
|
||||
# planting and harvest predictions
|
||||
gem 'active_median'
|
||||
|
||||
gem 'flickraw'
|
||||
gem 'jquery-rails'
|
||||
gem 'jquery-ui-rails', '~> 5.0.2' # needs careful upgrade with change of location
|
||||
@@ -26,8 +33,11 @@ gem 'cancancan' # for checking member privileges
|
||||
gem 'csv_shaper' # CSV export
|
||||
gem 'figaro' # for handling config via ENV variables
|
||||
gem 'gibbon', '~>1.2.0' # for Mailchimp newsletter subscriptions
|
||||
gem 'leaflet-markercluster-rails'
|
||||
gem 'leaflet-rails', '~> 0.7.7' # Newer versions break tests - see https://travis-ci.org/CloCkWeRX/growstuff/builds/200984350
|
||||
|
||||
# Maps
|
||||
gem 'leaflet-rails'
|
||||
gem 'rails-assets-leaflet.markercluster', source: 'https://rails-assets.org'
|
||||
|
||||
gem 'pg'
|
||||
gem 'ruby-units' # for unit conversion
|
||||
gem 'unicorn' # http server
|
||||
@@ -37,8 +47,8 @@ gem 'comfortable_mexican_sofa' # content management system
|
||||
gem 'bootstrap-kaminari-views' # bootstrap views for kaminari
|
||||
gem 'kaminari' # pagination
|
||||
|
||||
gem 'activemerchant'
|
||||
gem 'active_utils'
|
||||
gem 'activemerchant'
|
||||
gem 'sidekiq'
|
||||
|
||||
# Markdown formatting for updates etc
|
||||
@@ -124,7 +134,8 @@ group :development, :test do
|
||||
gem 'capybara-screenshot' # for test debugging
|
||||
gem 'coveralls', require: false # coverage analysis
|
||||
gem 'database_cleaner'
|
||||
gem 'factory_girl_rails' # for creating test data
|
||||
gem 'factory_bot_rails' # for creating test data
|
||||
gem 'faker'
|
||||
gem 'haml-i18n-extractor'
|
||||
gem 'haml-rails' # HTML templating language
|
||||
gem 'haml_lint' # Checks haml files for goodness
|
||||
@@ -134,7 +145,7 @@ group :development, :test do
|
||||
gem 'rainbow', '< 2.2.0' # See https://github.com/sickill/rainbow/issues/44
|
||||
gem 'rspec-activemodel-mocks'
|
||||
gem 'rspec-rails' # unit testing framework
|
||||
gem 'rubocop', '<= 0.47.1', require: false # Pin to rubocop (0.47.1) as 0.48.0 is buggy
|
||||
gem 'rubocop'
|
||||
gem 'selenium-webdriver'
|
||||
gem 'webrat' # provides HTML matchers for view tests
|
||||
end
|
||||
|
||||
114
Gemfile.lock
114
Gemfile.lock
@@ -1,5 +1,6 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
remote: https://rails-assets.org/
|
||||
specs:
|
||||
actionmailer (4.2.10)
|
||||
actionpack (= 4.2.10)
|
||||
@@ -23,6 +24,8 @@ GEM
|
||||
active_link_to (1.0.5)
|
||||
actionpack
|
||||
addressable
|
||||
active_median (0.1.4)
|
||||
activerecord
|
||||
active_merchant-paypal-bogus-gateway (0.1.0)
|
||||
activemerchant
|
||||
active_utils (3.3.9)
|
||||
@@ -31,7 +34,7 @@ GEM
|
||||
activejob (4.2.10)
|
||||
activesupport (= 4.2.10)
|
||||
globalid (>= 0.3.0)
|
||||
activemerchant (1.73.0)
|
||||
activemerchant (1.75.0)
|
||||
activesupport (>= 3.2.14, < 6.x)
|
||||
builder (>= 2.1.2, < 4.0.0)
|
||||
i18n (>= 0.6.9)
|
||||
@@ -55,7 +58,7 @@ GEM
|
||||
public_suffix (>= 2.0.2, < 4.0)
|
||||
arel (6.0.4)
|
||||
ast (2.3.0)
|
||||
autoprefixer-rails (7.1.6)
|
||||
autoprefixer-rails (7.2.2)
|
||||
execjs
|
||||
bcrypt (3.1.11)
|
||||
better_errors (2.2.0)
|
||||
@@ -78,12 +81,12 @@ GEM
|
||||
sass (>= 3.3.4)
|
||||
bootstrap_form (2.7.0)
|
||||
builder (3.2.3)
|
||||
bullet (5.6.1)
|
||||
bullet (5.7.0)
|
||||
activesupport (>= 3.0.0)
|
||||
uniform_notifier (~> 1.10.0)
|
||||
byebug (9.1.0)
|
||||
cancancan (2.0.0)
|
||||
capybara (2.15.4)
|
||||
cancancan (2.1.2)
|
||||
capybara (2.16.1)
|
||||
addressable
|
||||
mini_mime (>= 0.1.3)
|
||||
nokogiri (>= 1.3.3)
|
||||
@@ -93,7 +96,7 @@ GEM
|
||||
capybara-email (2.5.0)
|
||||
capybara (~> 2.4)
|
||||
mail
|
||||
capybara-screenshot (1.0.17)
|
||||
capybara-screenshot (1.0.18)
|
||||
capybara (>= 1.0, < 3)
|
||||
launchy
|
||||
childprocess (0.8.0)
|
||||
@@ -137,13 +140,13 @@ GEM
|
||||
term-ansicolor (~> 1.3)
|
||||
thor (~> 0.19.1)
|
||||
tins (~> 1.6)
|
||||
crass (1.0.2)
|
||||
crass (1.0.3)
|
||||
csv_shaper (1.3.0)
|
||||
activesupport (>= 3.0.0)
|
||||
d3-rails (3.5.17)
|
||||
railties (>= 3.1)
|
||||
dalli (2.7.6)
|
||||
database_cleaner (1.6.1)
|
||||
database_cleaner (1.6.2)
|
||||
debug_inspector (0.0.3)
|
||||
devise (4.3.0)
|
||||
bcrypt (~> 3.0)
|
||||
@@ -173,11 +176,13 @@ GEM
|
||||
erubis (2.7.0)
|
||||
excon (0.59.0)
|
||||
execjs (2.7.0)
|
||||
factory_girl (4.8.1)
|
||||
factory_bot (4.8.2)
|
||||
activesupport (>= 3.0.0)
|
||||
factory_girl_rails (4.8.0)
|
||||
factory_girl (~> 4.8.0)
|
||||
factory_bot_rails (4.8.2)
|
||||
factory_bot (~> 4.8.2)
|
||||
railties (>= 3.0.0)
|
||||
faker (1.8.5)
|
||||
i18n (~> 0.9.1)
|
||||
faraday (0.12.2)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
ffi (1.9.18)
|
||||
@@ -189,11 +194,11 @@ GEM
|
||||
formatador (0.2.5)
|
||||
friendly_id (5.2.3)
|
||||
activerecord (>= 4.0.0)
|
||||
geocoder (1.4.4)
|
||||
geocoder (1.4.5)
|
||||
gibbon (1.2.1)
|
||||
httparty
|
||||
multi_json (>= 1.9.0)
|
||||
globalid (0.4.0)
|
||||
globalid (0.4.1)
|
||||
activesupport (>= 4.2.0)
|
||||
gravatar-ultimate (2.0.0)
|
||||
activesupport (>= 2.3.14)
|
||||
@@ -227,11 +232,11 @@ GEM
|
||||
haml (>= 4.0.6, < 6.0)
|
||||
html2haml (>= 1.0.1)
|
||||
railties (>= 4.0.1)
|
||||
haml_lint (0.25.1)
|
||||
haml_lint (0.26.0)
|
||||
haml (>= 4.0, < 5.1)
|
||||
rainbow
|
||||
rake (>= 10, < 13)
|
||||
rubocop (>= 0.47.0)
|
||||
rubocop (>= 0.49.0)
|
||||
sysexits (~> 1.1)
|
||||
hashie (3.5.6)
|
||||
heroics (0.0.24)
|
||||
@@ -239,7 +244,7 @@ GEM
|
||||
excon
|
||||
moneta
|
||||
multi_json (>= 1.9.2)
|
||||
highline (1.7.8)
|
||||
highline (1.7.10)
|
||||
html2haml (2.2.0)
|
||||
erubis (~> 2.7.0)
|
||||
haml (>= 4.0, < 6)
|
||||
@@ -247,7 +252,7 @@ GEM
|
||||
ruby_parser (~> 3.5)
|
||||
httparty (0.15.6)
|
||||
multi_xml (>= 0.5.2)
|
||||
i18n (0.9.0)
|
||||
i18n (0.9.1)
|
||||
concurrent-ruby (~> 1.0)
|
||||
i18n-tasks (0.9.12)
|
||||
activesupport (>= 4.0.2)
|
||||
@@ -271,10 +276,14 @@ GEM
|
||||
thor (>= 0.14, < 2.0)
|
||||
jquery-ui-rails (5.0.5)
|
||||
railties (>= 3.2.16)
|
||||
js-routes (1.4.1)
|
||||
js-routes (1.4.2)
|
||||
railties (>= 3.2)
|
||||
sprockets-rails
|
||||
json (2.1.0)
|
||||
jsonapi-resources (0.9.0)
|
||||
activerecord (>= 4.1)
|
||||
concurrent-ruby
|
||||
railties (>= 4.1)
|
||||
jwt (1.5.6)
|
||||
kaminari (1.1.1)
|
||||
activesupport (>= 4.1.0)
|
||||
@@ -289,12 +298,11 @@ GEM
|
||||
kaminari-core (= 1.1.1)
|
||||
kaminari-core (1.1.1)
|
||||
kgio (2.11.0)
|
||||
kramdown (1.15.0)
|
||||
kramdown (1.16.2)
|
||||
launchy (2.4.3)
|
||||
addressable (~> 2.3)
|
||||
leaflet-markercluster-rails (0.7.0)
|
||||
railties (>= 3.1)
|
||||
leaflet-rails (0.7.7)
|
||||
leaflet-rails (1.2.0)
|
||||
rails (>= 4.2.0)
|
||||
letter_opener (1.4.1)
|
||||
launchy (~> 2.2)
|
||||
listen (3.1.5)
|
||||
@@ -305,15 +313,15 @@ GEM
|
||||
crass (~> 1.0.2)
|
||||
nokogiri (>= 1.5.9)
|
||||
lumberjack (1.0.12)
|
||||
mail (2.6.6)
|
||||
mime-types (>= 1.16, < 4)
|
||||
mail (2.7.0)
|
||||
mini_mime (>= 0.1.1)
|
||||
memcachier (0.0.2)
|
||||
method_source (0.9.0)
|
||||
mime-types (3.1)
|
||||
mime-types-data (~> 3.2015)
|
||||
mime-types-data (3.2016.0521)
|
||||
mimemagic (0.3.2)
|
||||
mini_mime (0.1.4)
|
||||
mini_mime (1.0.0)
|
||||
mini_portile2 (2.3.0)
|
||||
minitest (5.10.3)
|
||||
moneta (0.8.1)
|
||||
@@ -321,13 +329,13 @@ GEM
|
||||
multi_xml (0.6.0)
|
||||
multipart-post (2.0.0)
|
||||
nenv (0.3.0)
|
||||
newrelic_rpm (4.5.0.337)
|
||||
newrelic_rpm (4.6.0.338)
|
||||
nokogiri (1.8.1)
|
||||
mini_portile2 (~> 2.3.0)
|
||||
notiffany (0.1.1)
|
||||
nenv (~> 0.1)
|
||||
shellany (~> 0.0)
|
||||
oauth (0.5.3)
|
||||
oauth (0.5.4)
|
||||
oauth2 (1.4.0)
|
||||
faraday (>= 0.8, < 0.13)
|
||||
jwt (~> 1.0)
|
||||
@@ -358,8 +366,9 @@ GEM
|
||||
cocaine (~> 0.5.5)
|
||||
mime-types
|
||||
mimemagic (~> 0.3.0)
|
||||
parser (2.4.0.0)
|
||||
ast (~> 2.2)
|
||||
parallel (1.12.0)
|
||||
parser (2.4.0.2)
|
||||
ast (~> 2.3)
|
||||
pg (0.21.0)
|
||||
phantomjs (2.1.1.0)
|
||||
platform-api (2.1.0)
|
||||
@@ -372,10 +381,10 @@ GEM
|
||||
cliver (~> 0.3.1)
|
||||
websocket-driver (>= 0.2.0)
|
||||
powerpack (0.1.1)
|
||||
pry (0.11.2)
|
||||
pry (0.11.3)
|
||||
coderay (~> 1.1.0)
|
||||
method_source (~> 0.9.0)
|
||||
public_suffix (3.0.0)
|
||||
public_suffix (3.0.1)
|
||||
quiet_assets (1.1.0)
|
||||
railties (>= 3.1, < 5.0)
|
||||
rack (1.6.8)
|
||||
@@ -394,6 +403,9 @@ GEM
|
||||
bundler (>= 1.3.0, < 2.0)
|
||||
railties (= 4.2.10)
|
||||
sprockets-rails
|
||||
rails-assets-leaflet (1.2.0)
|
||||
rails-assets-leaflet.markercluster (1.2.0)
|
||||
rails-assets-leaflet (>= 1.0.3)
|
||||
rails-deprecated_sanitizer (1.0.3)
|
||||
activesupport (>= 4.2.0.alpha)
|
||||
rails-dom-testing (1.0.8)
|
||||
@@ -417,7 +429,7 @@ GEM
|
||||
thor (>= 0.18.1, < 2.0)
|
||||
rainbow (2.1.0)
|
||||
raindrops (0.19.0)
|
||||
rake (12.1.0)
|
||||
rake (12.3.0)
|
||||
rb-fsevent (0.10.2)
|
||||
rb-inotify (0.9.10)
|
||||
ffi (>= 0.5.0, < 2)
|
||||
@@ -441,7 +453,7 @@ GEM
|
||||
rspec-mocks (3.7.0)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.7.0)
|
||||
rspec-rails (3.7.1)
|
||||
rspec-rails (3.7.2)
|
||||
actionpack (>= 3.0)
|
||||
activesupport (>= 3.0)
|
||||
railties (>= 3.0)
|
||||
@@ -450,30 +462,31 @@ GEM
|
||||
rspec-mocks (~> 3.7.0)
|
||||
rspec-support (~> 3.7.0)
|
||||
rspec-support (3.7.0)
|
||||
rubocop (0.47.1)
|
||||
rubocop (0.49.1)
|
||||
parallel (~> 1.10)
|
||||
parser (>= 2.3.3.1, < 3.0)
|
||||
powerpack (~> 0.1)
|
||||
rainbow (>= 1.99.1, < 3.0)
|
||||
ruby-progressbar (~> 1.7)
|
||||
unicode-display_width (~> 1.0, >= 1.0.1)
|
||||
ruby-progressbar (1.9.0)
|
||||
ruby-units (2.2.0)
|
||||
ruby-units (2.2.1)
|
||||
ruby_dep (1.5.0)
|
||||
ruby_parser (3.10.1)
|
||||
sexp_processor (~> 4.9)
|
||||
rubyzip (1.2.1)
|
||||
sass (3.5.2)
|
||||
sass (3.5.3)
|
||||
sass-listen (~> 4.0.0)
|
||||
sass-listen (4.0.0)
|
||||
rb-fsevent (~> 0.9, >= 0.9.4)
|
||||
rb-inotify (~> 0.9, >= 0.9.7)
|
||||
sass-rails (5.0.6)
|
||||
sass-rails (5.0.7)
|
||||
railties (>= 4.0.0, < 6)
|
||||
sass (~> 3.1)
|
||||
sprockets (>= 2.8, < 4.0)
|
||||
sprockets-rails (>= 2.0, < 4.0)
|
||||
tilt (>= 1.1, < 3)
|
||||
selenium-webdriver (3.6.0)
|
||||
selenium-webdriver (3.8.0)
|
||||
childprocess (~> 0.5)
|
||||
rubyzip (~> 1.0)
|
||||
sexp_processor (4.10.0)
|
||||
@@ -488,8 +501,8 @@ GEM
|
||||
json (>= 1.8, < 3)
|
||||
simplecov-html (~> 0.10.0)
|
||||
simplecov-html (0.10.2)
|
||||
sparkpost_rails (1.4.0)
|
||||
rails (>= 4.0, < 5.1)
|
||||
sparkpost_rails (1.5.0)
|
||||
rails (>= 4.0, < 5.2)
|
||||
sprockets (3.7.1)
|
||||
concurrent-ruby (~> 1.0)
|
||||
rack (> 1, < 3)
|
||||
@@ -508,11 +521,11 @@ GEM
|
||||
thread_safe (0.3.6)
|
||||
tilt (2.0.8)
|
||||
timecop (0.9.1)
|
||||
tins (1.15.0)
|
||||
tins (1.16.3)
|
||||
trollop (1.16.2)
|
||||
tzinfo (1.2.3)
|
||||
tzinfo (1.2.4)
|
||||
thread_safe (~> 0.1)
|
||||
uglifier (3.2.0)
|
||||
uglifier (4.0.2)
|
||||
execjs (>= 0.3.0, < 3)
|
||||
unicode-display_width (1.3.0)
|
||||
unicorn (5.3.1)
|
||||
@@ -527,7 +540,7 @@ GEM
|
||||
rack-test (>= 0.5.3)
|
||||
websocket-driver (0.7.0)
|
||||
websocket-extensions (>= 0.1.0)
|
||||
websocket-extensions (0.1.2)
|
||||
websocket-extensions (0.1.3)
|
||||
will_paginate (3.1.6)
|
||||
xmlrpc (0.3.0)
|
||||
xpath (2.1.0)
|
||||
@@ -537,6 +550,7 @@ PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
active_median
|
||||
active_merchant-paypal-bogus-gateway
|
||||
active_utils
|
||||
activemerchant
|
||||
@@ -567,7 +581,8 @@ DEPENDENCIES
|
||||
elasticsearch-api (~> 2.0.0)
|
||||
elasticsearch-model
|
||||
elasticsearch-rails
|
||||
factory_girl_rails
|
||||
factory_bot_rails
|
||||
faker
|
||||
figaro
|
||||
flickraw
|
||||
font-awesome-sass
|
||||
@@ -587,9 +602,9 @@ DEPENDENCIES
|
||||
jquery-rails
|
||||
jquery-ui-rails (~> 5.0.2)
|
||||
js-routes
|
||||
jsonapi-resources
|
||||
kaminari
|
||||
leaflet-markercluster-rails
|
||||
leaflet-rails (~> 0.7.7)
|
||||
leaflet-rails
|
||||
letter_opener
|
||||
memcachier
|
||||
newrelic_rpm
|
||||
@@ -603,13 +618,14 @@ DEPENDENCIES
|
||||
pry
|
||||
quiet_assets
|
||||
rails (~> 4.2.8)
|
||||
rails-assets-leaflet.markercluster!
|
||||
rails_12factor
|
||||
rainbow (< 2.2.0)
|
||||
rake (>= 10.0.0)
|
||||
responders
|
||||
rspec-activemodel-mocks
|
||||
rspec-rails
|
||||
rubocop (<= 0.47.1)
|
||||
rubocop
|
||||
ruby-units
|
||||
sass-rails
|
||||
selenium-webdriver
|
||||
@@ -627,4 +643,4 @@ RUBY VERSION
|
||||
ruby 2.4.1p111
|
||||
|
||||
BUNDLED WITH
|
||||
1.15.4
|
||||
1.16.0
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
guard :rspec,
|
||||
cmd: 'bundle exec rspec --format documentation',
|
||||
failed_mode: :keep do
|
||||
cmd: 'bundle exec rspec --format documentation',
|
||||
failed_mode: :keep do
|
||||
watch(%r{^spec/.+_spec\.rb$})
|
||||
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/libs/#{m[1]}_spec.rb" }
|
||||
watch('spec/spec_helper.rb') { "spec" }
|
||||
watch('spec/spec_helper.rb') { "spec" }
|
||||
|
||||
# Rails example
|
||||
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
||||
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
||||
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
||||
watch('config/routes.rb') { "spec/routing" }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
@import 'bootstrap-datepicker'
|
||||
@import 'leaflet'
|
||||
@import 'leaflet.markercluster'
|
||||
@import 'leaflet.markercluster.default'
|
||||
@import 'custom_bootstrap/custom_bootstrap'
|
||||
@import 'overrides'
|
||||
@import 'graphs'
|
||||
|
||||
@@ -5,7 +5,7 @@ class AccountTypesController < ApplicationController
|
||||
|
||||
# GET /account_types
|
||||
def index
|
||||
@account_types = AccountType.all
|
||||
@account_types = AccountType.all.order(:name)
|
||||
respond_with(@account_types)
|
||||
end
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ class AccountsController < ApplicationController
|
||||
|
||||
# GET /accounts
|
||||
def index
|
||||
@accounts = Account.all
|
||||
@accounts = Account.all.order(created_at: :desc)
|
||||
respond_with(@accounts)
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class AlternateNamesController < ApplicationController
|
||||
before_action :authenticate_member!, except: [:index, :show]
|
||||
before_action :authenticate_member!, except: %i(index show)
|
||||
load_and_authorize_resource
|
||||
respond_to :html, :json
|
||||
responders :flash
|
||||
@@ -7,7 +7,7 @@ class AlternateNamesController < ApplicationController
|
||||
# GET /alternate_names
|
||||
# GET /alternate_names.json
|
||||
def index
|
||||
@alternate_names = AlternateName.all
|
||||
@alternate_names = AlternateName.all.order(:name)
|
||||
respond_with(@alternate_names)
|
||||
end
|
||||
|
||||
|
||||
7
app/controllers/api/v1/base_controller.rb
Normal file
7
app/controllers/api/v1/base_controller.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
module Api
|
||||
module V1
|
||||
class BaseController < JSONAPI::ResourceController
|
||||
abstract
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/crops_controller.rb
Normal file
6
app/controllers/api/v1/crops_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class CropsController < BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/gardens_controller.rb
Normal file
6
app/controllers/api/v1/gardens_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class GardensController < BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/harvests_controller.rb
Normal file
6
app/controllers/api/v1/harvests_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class HarvestsController < BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/members_controller.rb
Normal file
6
app/controllers/api/v1/members_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class MembersController < BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/photos_controller.rb
Normal file
6
app/controllers/api/v1/photos_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class PhotosController < BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/plantings_controller.rb
Normal file
6
app/controllers/api/v1/plantings_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class PlantingsController < BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/seeds_controller.rb
Normal file
6
app/controllers/api/v1/seeds_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class SeedsController < BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,3 +1,4 @@
|
||||
require './lib/actions/oauth_signup_action'
|
||||
class AuthenticationsController < ApplicationController
|
||||
before_action :authenticate_member!
|
||||
load_and_authorize_resource
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
class CommentsController < ApplicationController
|
||||
before_action :authenticate_member!, except: [:index, :show]
|
||||
before_action :authenticate_member!, except: %i(index show)
|
||||
load_and_authorize_resource
|
||||
respond_to :html, :json
|
||||
respond_to :rss, only: :index
|
||||
responders :flash
|
||||
|
||||
def index
|
||||
@comments = Comment.paginate(page: params[:page])
|
||||
@comments = Comment.order(created_at: :desc).paginate(page: params[:page])
|
||||
respond_with(@comments)
|
||||
end
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
require 'will_paginate/array'
|
||||
|
||||
class CropsController < ApplicationController
|
||||
before_action :authenticate_member!, except: [:index, :hierarchy, :search, :show]
|
||||
before_action :authenticate_member!, except: %i(index hierarchy search show)
|
||||
load_and_authorize_resource
|
||||
skip_authorize_resource only: [:hierarchy, :search]
|
||||
skip_authorize_resource only: %i(hierarchy search)
|
||||
respond_to :html, :json, :rss, :csv
|
||||
responders :flash
|
||||
|
||||
@@ -50,7 +50,7 @@ class CropsController < ApplicationController
|
||||
|
||||
def show
|
||||
@crop = Crop.includes(:scientific_names, plantings: :photos).find(params[:id])
|
||||
@posts = @crop.posts.paginate(page: params[:page])
|
||||
@posts = @crop.posts.order(created_at: :desc).paginate(page: params[:page])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.haml
|
||||
@@ -134,10 +134,10 @@ class CropsController < ApplicationController
|
||||
end
|
||||
|
||||
def recreate_names(param_name, name_type)
|
||||
return unless params[param_name].present?
|
||||
return if params[param_name].blank?
|
||||
destroy_names(name_type)
|
||||
params[param_name].each do |_i, value|
|
||||
create_name!(name_type, value)
|
||||
create_name!(name_type, value) unless value.empty?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -154,13 +154,14 @@ class CropsController < ApplicationController
|
||||
:name,
|
||||
:parent_id,
|
||||
:creator_id,
|
||||
:perennial,
|
||||
:approval_status,
|
||||
:request_notes,
|
||||
:reason_for_rejection,
|
||||
:rejection_notes,
|
||||
scientific_names_attributes: [:scientific_name,
|
||||
:_destroy,
|
||||
:id])
|
||||
scientific_names_attributes: %i(scientific_name
|
||||
_destroy
|
||||
id))
|
||||
end
|
||||
|
||||
def filename
|
||||
@@ -172,7 +173,7 @@ class CropsController < ApplicationController
|
||||
include: {
|
||||
plantings: {
|
||||
include: {
|
||||
owner: { only: [:id, :login_name, :location, :latitude, :longitude] }
|
||||
owner: { only: %i(id login_name location latitude longitude) }
|
||||
}
|
||||
},
|
||||
scientific_names: { only: [:name] },
|
||||
@@ -184,7 +185,7 @@ class CropsController < ApplicationController
|
||||
def crops
|
||||
q = Crop.approved.includes(:scientific_names, plantings: :photos)
|
||||
q = q.popular unless @sort == 'alpha'
|
||||
q.includes(:photos).paginate(page: params[:page])
|
||||
q.order("LOWER(crops.name)").includes(:photos).paginate(page: params[:page])
|
||||
end
|
||||
|
||||
def requested_crops
|
||||
|
||||
@@ -5,7 +5,7 @@ class ForumsController < ApplicationController
|
||||
# GET /forums
|
||||
# GET /forums.json
|
||||
def index
|
||||
@forums = Forum.all
|
||||
@forums = Forum.all.order(:name)
|
||||
respond_with(@forums)
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class GardensController < ApplicationController
|
||||
before_action :authenticate_member!, except: [:index, :show]
|
||||
after_action :expire_homepage, only: [:create, :delete]
|
||||
before_action :authenticate_member!, except: %i(index show)
|
||||
after_action :expire_homepage, only: %i(create delete)
|
||||
load_and_authorize_resource
|
||||
respond_to :html, :json
|
||||
|
||||
@@ -68,6 +68,6 @@ class GardensController < ApplicationController
|
||||
def gardens
|
||||
g = @owner ? @owner.gardens : Garden.all
|
||||
g = g.active unless @show_all
|
||||
g.joins(:owner).order(:updated_at).paginate(page: params[:page])
|
||||
g.joins(:owner).order(:name).paginate(page: params[:page])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class HarvestsController < ApplicationController
|
||||
before_action :authenticate_member!, except: [:index, :show]
|
||||
before_action :authenticate_member!, except: %i(index show)
|
||||
after_action :update_crop_medians, only: %i(create update destroy)
|
||||
load_and_authorize_resource
|
||||
respond_to :html, :json
|
||||
respond_to :csv, only: :index
|
||||
@@ -33,6 +34,7 @@ class HarvestsController < ApplicationController
|
||||
|
||||
def create
|
||||
@harvest.crop_id = @harvest.planting.crop_id if @harvest.planting_id
|
||||
@harvest.harvested_at = Time.zone.now if @harvest.harvested_at.blank?
|
||||
@harvest.save
|
||||
respond_with(@harvest)
|
||||
end
|
||||
@@ -71,8 +73,8 @@ class HarvestsController < ApplicationController
|
||||
elsif @planting
|
||||
@planting.harvests
|
||||
else
|
||||
Harvest
|
||||
end.joins(:owner, :crop).paginate(page: params[:page])
|
||||
Harvest.all
|
||||
end.order(harvested_at: :desc).joins(:owner, :crop).paginate(page: params[:page])
|
||||
end
|
||||
|
||||
def csv_filename
|
||||
@@ -83,4 +85,13 @@ class HarvestsController < ApplicationController
|
||||
end
|
||||
"Growstuff-#{specifics}Harvests-#{Time.zone.now.to_s(:number)}.csv"
|
||||
end
|
||||
|
||||
def update_crop_medians
|
||||
# We only update medians to predict plantings
|
||||
# if this harvest is not linked to a planting, then do nothing
|
||||
return if @harvest.planting.nil?
|
||||
|
||||
@harvest.planting.update_harvest_days
|
||||
@harvest.crop.update_harvest_medians
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class MembersController < ApplicationController
|
||||
load_and_authorize_resource except: [:finish_signup, :unsubscribe, :view_follows, :view_followers, :show]
|
||||
skip_authorize_resource only: [:nearby, :unsubscribe, :finish_signup]
|
||||
load_and_authorize_resource except: %i(finish_signup unsubscribe view_follows view_followers show)
|
||||
skip_authorize_resource only: %i(nearby unsubscribe finish_signup)
|
||||
respond_to :html, :json, :rss
|
||||
after_action :expire_homepage, only: :create
|
||||
|
||||
@@ -62,7 +62,6 @@ class MembersController < ApplicationController
|
||||
@member.update(@type => false)
|
||||
|
||||
flash.now[:notice] = I18n.t('members.unsubscribed', email_type: EMAIL_TYPE_STRING[@type])
|
||||
|
||||
rescue ActiveSupport::MessageVerifier::InvalidSignature
|
||||
flash.now[:alert] = I18n.t('members.unsubscribe.error')
|
||||
end
|
||||
@@ -88,16 +87,18 @@ class MembersController < ApplicationController
|
||||
end
|
||||
|
||||
def member_json_fields
|
||||
[
|
||||
:id, :login_name,
|
||||
:slug, :bio, :created_at,
|
||||
:location, :latitude, :longitude
|
||||
]
|
||||
%i(
|
||||
id login_name
|
||||
slug bio created_at
|
||||
location latitude longitude
|
||||
)
|
||||
end
|
||||
|
||||
def members
|
||||
q = Member.confirmed
|
||||
q = q.recently_joined if @sort == 'recently_joined'
|
||||
q.paginate(page: params[:page])
|
||||
if @sort == 'recently_joined'
|
||||
Member.recently_joined
|
||||
else
|
||||
Member.order(:login_name)
|
||||
end.confirmed.paginate(page: params[:page])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@ class NotificationsController < ApplicationController
|
||||
|
||||
# GET /notifications
|
||||
def index
|
||||
@notifications = Notification.by_recipient(current_member).page(params[:page])
|
||||
@notifications = Notification.by_recipient(current_member).order(:created_at).page(params[:page])
|
||||
end
|
||||
|
||||
# GET /notifications/1
|
||||
|
||||
@@ -30,7 +30,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
||||
@authentication = action.establish_authentication(auth, member)
|
||||
|
||||
if action.member_created?
|
||||
raise "Invalid provider" unless ['facebook', 'twitter', 'flickr'].index(auth['provider'].to_s)
|
||||
raise "Invalid provider" unless %w(facebook twitter flickr).index(auth['provider'].to_s)
|
||||
|
||||
session["devise.#{auth['provider']}_data"] = request.env["omniauth.auth"]
|
||||
sign_in member
|
||||
|
||||
@@ -1,28 +1,35 @@
|
||||
class OrderItemsController < ApplicationController
|
||||
before_action :authenticate_member!
|
||||
load_and_authorize_resource
|
||||
respond_to :html
|
||||
responders :flash
|
||||
|
||||
# POST /order_items
|
||||
def create
|
||||
if params[:order_item][:price]
|
||||
params[:order_item][:price] = params[:order_item][:price].to_f * 100 # convert to cents
|
||||
end
|
||||
|
||||
@order_item = OrderItem.new(order_item_params)
|
||||
@order_item.order = current_member.current_order || Order.create(member_id: current_member.id)
|
||||
|
||||
respond_to do |format|
|
||||
if @order_item.save
|
||||
format.html { redirect_to @order_item.order, notice: 'Added item to your order.' }
|
||||
else
|
||||
errors = @order_item.errors.empty? ?
|
||||
"There was a problem with your order." : @order_item.errors.full_messages.to_sentence
|
||||
format.html { redirect_to shop_path, alert: errors }
|
||||
end
|
||||
if @order_item.save
|
||||
redirect_to @order_item.order, notice: 'Added item to your order.'
|
||||
else
|
||||
redirect_to shop_path, alert: errors
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def errors
|
||||
if @order_item.errors.empty?
|
||||
"There was a problem with your order."
|
||||
else
|
||||
@order_item.errors.full_messages.to_sentence
|
||||
end
|
||||
end
|
||||
|
||||
def order_item_params
|
||||
params.require(:order_item).permit(:order_id, :price, :product_id, :quantity)
|
||||
end
|
||||
|
||||
@@ -1,20 +1,28 @@
|
||||
class PhotosController < ApplicationController
|
||||
before_action :authenticate_member!, except: [:index, :show]
|
||||
after_action :expire_homepage, only: [:create, :delete]
|
||||
before_action :authenticate_member!, except: %i(index show)
|
||||
after_action :expire_homepage, only: %i(create delete)
|
||||
load_and_authorize_resource
|
||||
respond_to :html, :json
|
||||
responders :flash
|
||||
|
||||
def index
|
||||
@photos = Photo.paginate(page: params[:page])
|
||||
if params[:crop_id]
|
||||
@crop = Crop.find params[:crop_id]
|
||||
@photos = @crop.photos
|
||||
else
|
||||
@photos = Photo.all
|
||||
end
|
||||
@photos = @photos.order(created_at: :desc)
|
||||
.includes(:owner)
|
||||
.paginate(page: params[:page])
|
||||
respond_with(@photos)
|
||||
end
|
||||
|
||||
def new
|
||||
@type = params[:type]
|
||||
@id = params[:id]
|
||||
|
||||
@photo = Photo.new
|
||||
@item = item_to_link_to
|
||||
@type = item_type
|
||||
@id = item_id
|
||||
retrieve_from_flickr
|
||||
respond_with @photo
|
||||
end
|
||||
@@ -24,9 +32,13 @@ class PhotosController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
find_or_create_photo_from_flickr_photo
|
||||
add_photo_to_collection
|
||||
@photo.save if @photo.present?
|
||||
ActiveRecord::Base.transaction do
|
||||
@photo = find_or_create_photo_from_flickr_photo
|
||||
@item = item_to_link_to
|
||||
raise "Could not find this #{type} owned by you" unless @item
|
||||
collection << @item unless collection.include?(@item)
|
||||
@photo.save! if @photo.present?
|
||||
end
|
||||
respond_with @photo
|
||||
end
|
||||
|
||||
@@ -42,8 +54,14 @@ class PhotosController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
def item_id?
|
||||
params.key? :id
|
||||
#
|
||||
# Params
|
||||
def item_id
|
||||
params[:id]
|
||||
end
|
||||
|
||||
def item_type
|
||||
params[:type]
|
||||
end
|
||||
|
||||
def flickr_photo_id_param
|
||||
@@ -55,26 +73,32 @@ class PhotosController < ApplicationController
|
||||
:license_url, :thumbnail_url, :fullsize_url, :link_url)
|
||||
end
|
||||
|
||||
def find_or_create_photo_from_flickr_photo
|
||||
@photo = Photo.find_by(flickr_photo_id: flickr_photo_id_param)
|
||||
@photo = Photo.new(photo_params) unless @photo
|
||||
@photo.owner_id = current_member.id
|
||||
@photo.set_flickr_metadata
|
||||
@photo
|
||||
# Item with photos attached
|
||||
#
|
||||
def item_to_link_to
|
||||
raise "No item id provided" if item_id.nil?
|
||||
raise "No item type provided" if item_type.nil?
|
||||
raise "Missing or invalid type provided" unless photos_supported_on_type?(item_type)
|
||||
item_class = Growstuff::Constants::PhotoModels.get_item(item_type)
|
||||
item_class.find_by!(id: params[:id], owner_id: current_member.id)
|
||||
end
|
||||
|
||||
def add_photo_to_collection
|
||||
raise "Missing or invalid type provided" unless Growstuff::Constants::PhotoModels.types.include?(params[:type])
|
||||
raise "No item id provided" unless item_id?
|
||||
collection = Growstuff::Constants::PhotoModels.get_relation(@photo, params[:type])
|
||||
def collection
|
||||
Growstuff::Constants::PhotoModels.get_relation(@photo, item_type)
|
||||
end
|
||||
|
||||
item_class = Growstuff::Constants::PhotoModels.get_item(params[:type])
|
||||
item = item_class.find_by!(id: params[:id], owner_id: current_member.id)
|
||||
raise "Could not find this item owned by you" unless item
|
||||
def photos_supported_on_type?(_type)
|
||||
Growstuff::Constants::PhotoModels.types.include?(item_type)
|
||||
end
|
||||
|
||||
collection << item unless collection.include?(item)
|
||||
rescue => e
|
||||
flash[:alert] = e.message
|
||||
#
|
||||
# Flickr retrieval
|
||||
def find_or_create_photo_from_flickr_photo
|
||||
photo = Photo.find_by(flickr_photo_id: flickr_photo_id_param)
|
||||
photo ||= Photo.new(photo_params)
|
||||
photo.owner_id = current_member.id
|
||||
photo.set_flickr_metadata
|
||||
photo
|
||||
end
|
||||
|
||||
def retrieve_from_flickr
|
||||
|
||||
@@ -7,9 +7,9 @@ class PlacesController < ApplicationController
|
||||
format.html
|
||||
# json response is whatever we want to map here
|
||||
format.json do
|
||||
render json: Member.located.to_json(only: [
|
||||
:id, :login_name, :slug, :location, :latitude, :longitude
|
||||
])
|
||||
render json: Member.located.to_json(only: %i(
|
||||
id login_name slug location latitude longitude
|
||||
))
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -22,9 +22,9 @@ class PlacesController < ApplicationController
|
||||
respond_to do |format|
|
||||
format.html # show.html.haml
|
||||
format.json do
|
||||
render json: @nearby_members.to_json(only: [
|
||||
:id, :login_name, :slug, :location, :latitude, :longitude
|
||||
])
|
||||
render json: @nearby_members.to_json(only: %i(
|
||||
id login_name slug location latitude longitude
|
||||
))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ class PlantPartsController < ApplicationController
|
||||
responders :flash
|
||||
|
||||
def index
|
||||
@plant_parts = PlantPart.all
|
||||
@plant_parts = PlantPart.all.order(:name)
|
||||
respond_with(@plant_parts)
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
class PlantingsController < ApplicationController
|
||||
before_action :authenticate_member!, except: [:index, :show]
|
||||
after_action :expire_homepage, only: [:create, :update, :destroy]
|
||||
before_action :authenticate_member!, except: %i(index show)
|
||||
after_action :expire_homepage, only: %i(create update destroy)
|
||||
after_action :update_crop_medians, only: %i(create update destroy)
|
||||
after_action :update_planting_medians, only: :update
|
||||
load_and_authorize_resource
|
||||
|
||||
respond_to :html, :json
|
||||
@@ -51,13 +53,11 @@ class PlantingsController < ApplicationController
|
||||
def create
|
||||
@planting = Planting.new(planting_params)
|
||||
@planting.owner = current_member
|
||||
@planting.calc_and_set_days_before_maturity
|
||||
@planting.save
|
||||
@planting.save!
|
||||
respond_with @planting
|
||||
end
|
||||
|
||||
def update
|
||||
@planting.calc_and_set_days_before_maturity
|
||||
@planting.update(planting_params)
|
||||
respond_with @planting
|
||||
end
|
||||
@@ -69,6 +69,14 @@ class PlantingsController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
def update_crop_medians
|
||||
@planting.crop.update_lifespan_medians
|
||||
end
|
||||
|
||||
def update_planting_medians
|
||||
@planting.update_harvest_days
|
||||
end
|
||||
|
||||
def planting_params
|
||||
params[:planted_at] = parse_date(params[:planted_at]) if params[:planted_at]
|
||||
params.require(:planting).permit(
|
||||
@@ -87,6 +95,9 @@ class PlantingsController < ApplicationController
|
||||
Planting
|
||||
end
|
||||
p = p.current unless @show_all
|
||||
p.joins(:owner, :crop, :garden).order(:created_at).paginate(page: params[:page])
|
||||
p.joins(:owner, :crop, :garden)
|
||||
.order(created_at: :desc)
|
||||
.includes(:crop, :owner, :garden)
|
||||
.paginate(page: params[:page])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
class PostsController < ApplicationController
|
||||
before_action :authenticate_member!, except: [:index, :show]
|
||||
before_action :authenticate_member!, except: %i(index show)
|
||||
load_and_authorize_resource
|
||||
respond_to :html, :json
|
||||
respond_to :rss, only: [:index, :show]
|
||||
respond_to :rss, only: %i(index show)
|
||||
|
||||
# GET /posts
|
||||
# GET /posts.json
|
||||
@@ -66,6 +66,6 @@ class PostsController < ApplicationController
|
||||
@author.posts
|
||||
else
|
||||
Post
|
||||
end.includes(:author, comments: :author).paginate(page: params[:page])
|
||||
end.order(created_at: :desc).includes(:author, comments: :author).paginate(page: params[:page])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@ class ProductsController < ApplicationController
|
||||
responders :flash
|
||||
|
||||
def index
|
||||
@products = Product.all
|
||||
@products = Product.all.order(:name)
|
||||
respond_with @products
|
||||
end
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ class RolesController < ApplicationController
|
||||
responders :flash
|
||||
|
||||
def index
|
||||
@roles = Role.all
|
||||
@roles = Role.all.order(:name)
|
||||
respond_with @roles
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class ScientificNamesController < ApplicationController
|
||||
before_action :authenticate_member!, except: [:index, :show]
|
||||
before_action :authenticate_member!, except: %i(index show)
|
||||
load_and_authorize_resource
|
||||
respond_to :html, :json
|
||||
responders :flash
|
||||
@@ -7,7 +7,7 @@ class ScientificNamesController < ApplicationController
|
||||
# GET /scientific_names
|
||||
# GET /scientific_names.json
|
||||
def index
|
||||
@scientific_names = ScientificName.all
|
||||
@scientific_names = ScientificName.all.order(:name)
|
||||
respond_with(@scientific_names)
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class SeedsController < ApplicationController
|
||||
before_action :authenticate_member!, except: [:index, :show]
|
||||
before_action :authenticate_member!, except: %i(index show)
|
||||
load_and_authorize_resource
|
||||
respond_to :html, :json
|
||||
respond_to :csv, only: :index
|
||||
@@ -75,7 +75,7 @@ class SeedsController < ApplicationController
|
||||
crop.seeds
|
||||
else
|
||||
Seed
|
||||
end.includes(:owner, :crop).paginate(page: params[:page])
|
||||
end.order(created_at: :desc).includes(:owner, :crop).paginate(page: params[:page])
|
||||
end
|
||||
|
||||
def csv_filename
|
||||
|
||||
@@ -2,7 +2,7 @@ class SessionsController < Devise::SessionsController
|
||||
respond_to :json
|
||||
|
||||
def create
|
||||
super do |resource|
|
||||
super do |_resource|
|
||||
if Crop.pending_approval.present? && current_member.role?(:crop_wrangler)
|
||||
flash[:alert] = "There are crops waiting to be wrangled."
|
||||
end
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
module ApplicationHelper
|
||||
def price_in_dollars(price)
|
||||
sprintf('%.2f', price / 100.0)
|
||||
format('%.2f', price / 100.0)
|
||||
end
|
||||
|
||||
# 999 cents becomes 9.99 AUD -- for products/orders/etc
|
||||
def price_with_currency(price)
|
||||
sprintf('%.2f %s', price / 100.0, Growstuff::Application.config.currency)
|
||||
format('%.2f %s', price / 100.0, Growstuff::Application.config.currency)
|
||||
end
|
||||
|
||||
def parse_date(str)
|
||||
|
||||
@@ -11,7 +11,7 @@ module AutoSuggestHelper
|
||||
resource = resource.class.name.downcase
|
||||
source_path = Rails.application.routes.url_helpers.send("#{source}s_search_path")
|
||||
|
||||
%Q{
|
||||
%(
|
||||
<input id="#{source}" class="auto-suggest #{options[:class]}"
|
||||
type="text" value="#{default}" data-source-url="#{source_path}",
|
||||
placeholder="e.g. lettuce">
|
||||
@@ -20,6 +20,6 @@ module AutoSuggestHelper
|
||||
</noscript>
|
||||
<input id="#{resource}_#{source}_id" class="auto-suggest-id"
|
||||
type="hidden" name="#{resource}[#{source}_id]" value="#{default_id}">
|
||||
}.html_safe
|
||||
).html_safe
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,9 +8,7 @@ module CropsHelper
|
||||
total_quantity += seed.quantity if seed.quantity
|
||||
end
|
||||
|
||||
if !seeds.any?
|
||||
return "You don't have any seeds of this crop."
|
||||
end
|
||||
return "You don't have any seeds of this crop." if seeds.none?
|
||||
|
||||
if total_quantity != 0
|
||||
"You have #{total_quantity} #{Seed.model_name.human(count: total_quantity)} of this crop."
|
||||
|
||||
@@ -15,7 +15,7 @@ module HarvestsHelper
|
||||
|
||||
if harvest.unit == 'individual' # just the number
|
||||
number_to_human(harvest.quantity, strip_insignificant_zeros: true)
|
||||
elsif !harvest.unit.blank? # pluralize anything else
|
||||
elsif harvest.unit.present? # pluralize anything else
|
||||
pluralize(number_to_human(harvest.quantity, strip_insignificant_zeros: true), harvest.unit)
|
||||
else
|
||||
"#{number_to_human(harvest.quantity, strip_insignificant_zeros: true)} #{harvest.unit}"
|
||||
|
||||
@@ -1,18 +1,6 @@
|
||||
module PlantingsHelper
|
||||
def display_days_before_maturity(planting)
|
||||
# First try to calc from finished/finished_at
|
||||
if planting.finished? || planting.finished_at.present?
|
||||
planting.days_until_finished.to_s
|
||||
# then try to calc from planted at + maturity
|
||||
elsif planting.planted_at.present? && planting.days_before_maturity.present?
|
||||
planting.days_until_mature.to_s
|
||||
else
|
||||
"unknown"
|
||||
end
|
||||
end
|
||||
|
||||
def display_finished(planting)
|
||||
if !planting.finished_at.nil?
|
||||
if planting.finished_at.present?
|
||||
planting.finished_at
|
||||
elsif planting.finished
|
||||
"Yes (no date specified)"
|
||||
@@ -22,11 +10,11 @@ module PlantingsHelper
|
||||
end
|
||||
|
||||
def display_planted_from(planting)
|
||||
!planting.planted_from.blank? ? planting.planted_from : "not specified"
|
||||
planting.planted_from.present? ? planting.planted_from : "not specified"
|
||||
end
|
||||
|
||||
def display_planting_quantity(planting)
|
||||
!planting.quantity.blank? ? planting.quantity : "not specified"
|
||||
planting.quantity.present? ? planting.quantity : "not specified"
|
||||
end
|
||||
|
||||
def display_planting(planting)
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
class AccountType < ActiveRecord::Base
|
||||
#
|
||||
# Relationships
|
||||
has_many :products
|
||||
|
||||
#
|
||||
# Validations
|
||||
validates :name, presence: true, uniqueness: true
|
||||
|
||||
def to_s
|
||||
name
|
||||
end
|
||||
|
||||
@@ -2,7 +2,6 @@ class Comment < ActiveRecord::Base
|
||||
belongs_to :author, class_name: 'Member'
|
||||
belongs_to :post
|
||||
|
||||
default_scope { order("created_at DESC") }
|
||||
scope :post_order, -> { reorder("created_at ASC") } # for display on post page
|
||||
|
||||
after_create do
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
class Crop < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
friendly_id :name, use: [:slugged, :finders]
|
||||
friendly_id :name, use: %i(slugged finders)
|
||||
|
||||
has_many :scientific_names, after_add: :update_index, after_remove: :update_index
|
||||
accepts_nested_attributes_for :scientific_names,
|
||||
allow_destroy: true,
|
||||
reject_if: :all_blank
|
||||
##
|
||||
## Triggers
|
||||
before_destroy { |crop| crop.posts.clear }
|
||||
|
||||
##
|
||||
## Relationships
|
||||
has_many :scientific_names, after_add: :update_index, after_remove: :update_index, dependent: :destroy
|
||||
accepts_nested_attributes_for :scientific_names, allow_destroy: true, reject_if: :all_blank
|
||||
has_many :alternate_names, after_add: :update_index, after_remove: :update_index, dependent: :destroy
|
||||
has_many :plantings
|
||||
has_many :photos, through: :plantings
|
||||
@@ -15,33 +18,31 @@ class Crop < ActiveRecord::Base
|
||||
has_many :plant_parts, -> { uniq.reorder("plant_parts.name") }, through: :harvests
|
||||
belongs_to :creator, class_name: 'Member'
|
||||
belongs_to :requester, class_name: 'Member'
|
||||
|
||||
belongs_to :parent, class_name: 'Crop'
|
||||
has_many :varieties, class_name: 'Crop', foreign_key: 'parent_id'
|
||||
has_and_belongs_to_many :posts # rubocop:disable Rails/HasAndBelongsToMany
|
||||
before_destroy { |crop| crop.posts.clear }
|
||||
|
||||
default_scope { order("lower(crops.name) asc") }
|
||||
scope :recent, lambda {
|
||||
approved.reorder("created_at desc")
|
||||
}
|
||||
scope :toplevel, lambda {
|
||||
approved.where(parent_id: nil)
|
||||
}
|
||||
scope :popular, lambda {
|
||||
approved.reorder("plantings_count desc, lower(name) asc")
|
||||
}
|
||||
scope :randomized, lambda {
|
||||
# ok on sqlite and psql, but not on mysql
|
||||
approved.reorder('random()')
|
||||
}
|
||||
##
|
||||
## Scopes
|
||||
scope :recent, -> { approved.order(created_at: :desc) }
|
||||
scope :toplevel, -> { approved.where(parent_id: nil) }
|
||||
scope :popular, -> { approved.reorder("plantings_count desc, lower(name) asc") }
|
||||
# ok on sqlite and psql, but not on mysql
|
||||
scope :randomized, -> { approved.reorder('random()') }
|
||||
scope :pending_approval, -> { where(approval_status: "pending") }
|
||||
scope :approved, -> { where(approval_status: "approved") }
|
||||
scope :rejected, -> { where(approval_status: "rejected") }
|
||||
|
||||
scope :interesting, -> { approved.has_photos.randomized }
|
||||
scope :has_photos, -> { includes(:photos).where.not(photos: { id: nil }) }
|
||||
|
||||
##
|
||||
## Validations
|
||||
# Reasons are only necessary when rejecting
|
||||
validates :reason_for_rejection, presence: true, if: :rejected?
|
||||
## This validation addresses a race condition
|
||||
validate :approval_status_cannot_be_changed_again
|
||||
validate :must_be_rejected_if_rejected_reasons_present
|
||||
validate :must_have_meaningful_reason_for_rejection
|
||||
## Wikipedia urls are only necessary when approving a crop
|
||||
validates :en_wikipedia_url,
|
||||
format: {
|
||||
@@ -50,16 +51,6 @@ class Crop < ActiveRecord::Base
|
||||
},
|
||||
if: :approved?
|
||||
|
||||
## Reasons are only necessary when rejecting
|
||||
validates :reason_for_rejection, presence: true, if: :rejected?
|
||||
|
||||
## This validation addresses a race condition
|
||||
validate :approval_status_cannot_be_changed_again
|
||||
|
||||
validate :must_be_rejected_if_rejected_reasons_present
|
||||
|
||||
validate :must_have_meaningful_reason_for_rejection
|
||||
|
||||
####################################
|
||||
# Elastic search configuration
|
||||
if ENV["GROWSTUFF_ELASTICSEARCH"] == "true"
|
||||
@@ -106,14 +97,8 @@ class Crop < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def as_indexed_json(_options = {})
|
||||
as_json(
|
||||
only: [:id, :name, :approval_status],
|
||||
include: {
|
||||
scientific_names: { only: :name },
|
||||
alternate_names: { only: :name }
|
||||
}
|
||||
)
|
||||
def harvest_photos
|
||||
Photo.joins(:harvests).where("harvests.crop_id": id)
|
||||
end
|
||||
|
||||
# update the Elasticsearch index (only if we're using it in this
|
||||
@@ -121,7 +106,6 @@ class Crop < ActiveRecord::Base
|
||||
def update_index(_name_obj)
|
||||
__elasticsearch__.index_document if ENV["GROWSTUFF_ELASTICSEARCH"] == "true"
|
||||
end
|
||||
|
||||
# End Elasticsearch section
|
||||
|
||||
def to_s
|
||||
@@ -132,19 +116,18 @@ class Crop < ActiveRecord::Base
|
||||
scientific_names.first.name unless scientific_names.empty?
|
||||
end
|
||||
|
||||
# crop.default_photo
|
||||
# currently returns the first available photo, but exists so that
|
||||
# later we can choose a default photo based on different criteria,
|
||||
# eg. popularity
|
||||
def default_photo
|
||||
return photos.first if photos.any?
|
||||
# most recent photo
|
||||
return photos.order(created_at: :desc).first if photos.any?
|
||||
|
||||
# Crop has no photos? Look for the most recent harvest with a photo.
|
||||
harvest_with_photo = Harvest.where(crop_id: id).joins(:photos).order('harvests.id DESC').limit(1).first
|
||||
harvest_with_photo.photos.first if harvest_with_photo
|
||||
end
|
||||
|
||||
# crop.sunniness
|
||||
# returns hash indicating whether this crop is grown in
|
||||
# sun/semi-shade/shade
|
||||
# key: sunniness (eg. 'sun')
|
||||
@@ -153,7 +136,6 @@ class Crop < ActiveRecord::Base
|
||||
count_uses_of_property 'sunniness'
|
||||
end
|
||||
|
||||
# crop.planted_from
|
||||
# returns a hash of propagation methods (seed, seedling, etc),
|
||||
# key: propagation method (eg. 'seed')
|
||||
# value: count of how many times it's been used by plantings
|
||||
@@ -161,7 +143,6 @@ class Crop < ActiveRecord::Base
|
||||
count_uses_of_property 'planted_from'
|
||||
end
|
||||
|
||||
# crop.popular_plant_parts
|
||||
# returns a hash of most harvested plant parts (fruit, seed, etc)
|
||||
# key: plant part (eg. 'fruit')
|
||||
# value: count of how many times it's been used by harvests
|
||||
@@ -173,6 +154,10 @@ class Crop < ActiveRecord::Base
|
||||
.count("harvests.id")
|
||||
end
|
||||
|
||||
def annual?
|
||||
!perennial
|
||||
end
|
||||
|
||||
def interesting?
|
||||
min_plantings = 3 # needs this many plantings to be interesting
|
||||
min_photos = 3 # needs this many photos to be interesting
|
||||
@@ -206,45 +191,24 @@ class Crop < ActiveRecord::Base
|
||||
reason_for_rejection
|
||||
end
|
||||
|
||||
# Crop.search(string)
|
||||
def update_medians
|
||||
plantings.each(&:update_harvest_days)
|
||||
update_lifespan_medians
|
||||
update_harvest_medians
|
||||
end
|
||||
|
||||
def update_lifespan_medians
|
||||
# Median lifespan of plantings
|
||||
update(median_lifespan: Planting.where(crop: self).median(:lifespan))
|
||||
end
|
||||
|
||||
def update_harvest_medians
|
||||
update(median_days_to_first_harvest: Planting.where(crop: self).median(:days_to_first_harvest))
|
||||
update(median_days_to_last_harvest: Planting.where(crop: self).median(:days_to_last_harvest))
|
||||
end
|
||||
|
||||
def self.search(query)
|
||||
if ENV['GROWSTUFF_ELASTICSEARCH'] == "true"
|
||||
search_str = query.nil? ? "" : query.downcase
|
||||
response = __elasticsearch__.search( # Finds documents which match any field, but uses the _score from
|
||||
# the best field insead of adding up _score from each field.
|
||||
query: {
|
||||
multi_match: {
|
||||
query: search_str.to_s,
|
||||
analyzer: "standard",
|
||||
fields: ["name",
|
||||
"scientific_names.scientific_name",
|
||||
"alternate_names.name"]
|
||||
}
|
||||
},
|
||||
filter: {
|
||||
term: { approval_status: "approved" }
|
||||
},
|
||||
size: 50
|
||||
)
|
||||
response.records.to_a
|
||||
else
|
||||
# if we don't have elasticsearch, just do a basic SQL query.
|
||||
# also, make sure it's an actual array not an activerecord
|
||||
# collection, so it matches what we get from elasticsearch and we can
|
||||
# manipulate it in the same ways (eg. deleting elements without deleting
|
||||
# the whole record from the db)
|
||||
matches = Crop.approved.where("name ILIKE ?", "%#{query}%").to_a
|
||||
|
||||
# we want to make sure that exact matches come first, even if not
|
||||
# using elasticsearch (eg. in development)
|
||||
exact_match = Crop.approved.find_by(name: query)
|
||||
if exact_match
|
||||
matches.delete(exact_match)
|
||||
matches.unshift(exact_match)
|
||||
end
|
||||
|
||||
matches
|
||||
end
|
||||
CropSearchService.search(query)
|
||||
end
|
||||
|
||||
def self.case_insensitive_name(name)
|
||||
|
||||
@@ -34,7 +34,7 @@ class CsvImporter
|
||||
|
||||
def add_scientific_names(scientific_names)
|
||||
names_to_add = []
|
||||
if !scientific_names.blank? # i.e. we actually passed something in, which isn't a given
|
||||
if scientific_names.present? # i.e. we actually passed something in, which isn't a given
|
||||
names_to_add = scientific_names.split(/,\s*/)
|
||||
elsif @crop.parent && !@crop.parent.scientific_names.empty? # pick up from parent
|
||||
names_to_add = @crop.parent.scientific_names.map(&:name)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class Forum < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
validates :name, presence: true
|
||||
friendly_id :name, use: [:slugged, :finders]
|
||||
friendly_id :name, use: %i(slugged finders)
|
||||
|
||||
has_many :posts
|
||||
belongs_to :owner, class_name: "Member"
|
||||
|
||||
@@ -2,7 +2,7 @@ class Garden < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
include Geocodable
|
||||
include PhotoCapable
|
||||
friendly_id :garden_slug, use: [:slugged, :finders]
|
||||
friendly_id :garden_slug, use: %i(slugged finders)
|
||||
|
||||
belongs_to :owner, class_name: 'Member', foreign_key: 'owner_id', counter_cache: true
|
||||
has_many :plantings, dependent: :destroy
|
||||
@@ -14,7 +14,7 @@ class Garden < ActiveRecord::Base
|
||||
after_validation :empty_unwanted_geocodes
|
||||
after_save :mark_inactive_garden_plantings_as_finished
|
||||
|
||||
default_scope { joins(:owner).order("lower(name) asc") }
|
||||
default_scope { joins(:owner) } # Ensures owner exists
|
||||
scope :active, -> { where(active: true) }
|
||||
scope :inactive, -> { where(active: false) }
|
||||
|
||||
@@ -23,7 +23,7 @@ class Garden < ActiveRecord::Base
|
||||
|
||||
validates :name,
|
||||
format: {
|
||||
with: /\A\w+[\w ]+\z/
|
||||
with: /\A\w+[\w ()]+\z/
|
||||
},
|
||||
length: { maximum: 255 }
|
||||
|
||||
@@ -41,7 +41,7 @@ class Garden < ActiveRecord::Base
|
||||
"acres" => "acre"
|
||||
}.freeze
|
||||
validates :area_unit, inclusion: { in: AREA_UNITS_VALUES.values,
|
||||
message: "%{value} is not a valid area unit" },
|
||||
message: "%<value>s is not a valid area unit" },
|
||||
allow_nil: true,
|
||||
allow_blank: true
|
||||
|
||||
@@ -62,7 +62,7 @@ class Garden < ActiveRecord::Base
|
||||
unique_plantings = []
|
||||
seen_crops = []
|
||||
|
||||
plantings.includes(:garden, :crop, :owner, :harvests).each do |p|
|
||||
plantings.order(created_at: :desc).includes(:garden, :crop, :owner, :harvests).each do |p|
|
||||
unless seen_crops.include?(p.crop)
|
||||
unique_plantings.push(p)
|
||||
seen_crops.push(p.crop)
|
||||
@@ -88,6 +88,6 @@ class Garden < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def default_photo
|
||||
photos.first
|
||||
photos.order(created_at: :desc).first
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,28 +1,11 @@
|
||||
class Harvest < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
include ActionView::Helpers::NumberHelper
|
||||
extend FriendlyId
|
||||
include PhotoCapable
|
||||
friendly_id :harvest_slug, use: [:slugged, :finders]
|
||||
|
||||
belongs_to :crop
|
||||
belongs_to :owner, class_name: 'Member', counter_cache: true
|
||||
belongs_to :plant_part
|
||||
belongs_to :planting
|
||||
|
||||
default_scope { joins(:owner).order(created_at: :desc) }
|
||||
validates :crop, approved: true
|
||||
|
||||
validates :crop, presence: { message: "must be present and exist in our database" }
|
||||
|
||||
validates :plant_part, presence: { message: "must be present and exist in our database" }
|
||||
|
||||
validates :quantity,
|
||||
numericality: {
|
||||
only_integer: false,
|
||||
greater_than_or_equal_to: 0
|
||||
},
|
||||
allow_nil: true
|
||||
friendly_id :harvest_slug, use: %i(slugged finders)
|
||||
|
||||
# Constants
|
||||
UNITS_VALUES = {
|
||||
"individual" => "individual",
|
||||
"bunches" => "bunch",
|
||||
@@ -35,29 +18,54 @@ class Harvest < ActiveRecord::Base
|
||||
"baskets" => "basket",
|
||||
"bushels" => "bushel"
|
||||
}.freeze
|
||||
validates :unit, inclusion: { in: UNITS_VALUES.values,
|
||||
message: "%{value} is not a valid unit" },
|
||||
allow_nil: true,
|
||||
allow_blank: true
|
||||
|
||||
validates :weight_quantity,
|
||||
numericality: { only_integer: false },
|
||||
allow_nil: true
|
||||
|
||||
WEIGHT_UNITS_VALUES = {
|
||||
"kg" => "kg",
|
||||
"lb" => "lb",
|
||||
"oz" => "oz"
|
||||
}.freeze
|
||||
validates :weight_unit, inclusion: { in: WEIGHT_UNITS_VALUES.values,
|
||||
message: "%{value} is not a valid unit" },
|
||||
allow_nil: true,
|
||||
allow_blank: true
|
||||
|
||||
##
|
||||
## Triggers
|
||||
after_validation :cleanup_quantities
|
||||
|
||||
before_save :set_si_weight
|
||||
|
||||
##
|
||||
## Relationships
|
||||
belongs_to :crop
|
||||
belongs_to :owner, class_name: 'Member', counter_cache: true
|
||||
belongs_to :plant_part
|
||||
belongs_to :planting
|
||||
|
||||
##
|
||||
## Scopes
|
||||
default_scope { joins(:owner) } # Ensures owner exists
|
||||
|
||||
##
|
||||
## Validations
|
||||
validates :crop, approved: true
|
||||
validates :crop, presence: { message: "must be present and exist in our database" }
|
||||
validates :plant_part, presence: { message: "must be present and exist in our database" }
|
||||
validates :harvested_at, presence: true
|
||||
validates :quantity, allow_nil: true, numericality: {
|
||||
only_integer: false, greater_than_or_equal_to: 0
|
||||
}
|
||||
validates :unit, allow_nil: true, allow_blank: true, inclusion: {
|
||||
in: UNITS_VALUES.values, message: "%<value>s is not a valid unit"
|
||||
}
|
||||
validates :weight_quantity, allow_nil: true, numericality: { only_integer: false }
|
||||
validates :weight_unit, allow_nil: true, allow_blank: true, inclusion: {
|
||||
in: WEIGHT_UNITS_VALUES.values, message: "%<value>s is not a valid unit"
|
||||
}
|
||||
validate :crop_must_match_planting
|
||||
validate :owner_must_match_planting
|
||||
validate :harvest_must_be_after_planting
|
||||
|
||||
def time_from_planting_to_harvest
|
||||
return if planting.blank?
|
||||
harvested_at - planting.planted_at
|
||||
end
|
||||
|
||||
# we're storing the harvest weight in kilograms in the db too
|
||||
# to make data manipulation easier
|
||||
def set_si_weight
|
||||
@@ -116,6 +124,24 @@ class Harvest < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def default_photo
|
||||
photos.first || crop.default_photo
|
||||
photos.order(created_at: :desc).first || crop.default_photo
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def crop_must_match_planting
|
||||
return if planting.blank? # only check if we are linked to a planting
|
||||
errors.add(:planting, "must be the same crop") unless crop == planting.crop
|
||||
end
|
||||
|
||||
def owner_must_match_planting
|
||||
return if planting.blank? # only check if we are linked to a planting
|
||||
errors.add(:owner, "of harvest must be the same as planting") unless owner == planting.owner
|
||||
end
|
||||
|
||||
def harvest_must_be_after_planting
|
||||
# only check if we are linked to a planting
|
||||
return unless harvested_at.present? && planting.present? && planting.planted_at.present?
|
||||
errors.add(:planting, "cannot be harvested before planting") unless harvested_at > planting.planted_at
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,50 +4,42 @@ class Member < ActiveRecord::Base
|
||||
include Geocodable
|
||||
extend FriendlyId
|
||||
|
||||
friendly_id :login_name, use: [:slugged, :finders]
|
||||
friendly_id :login_name, use: %i(slugged finders)
|
||||
|
||||
#
|
||||
# Relationshops
|
||||
has_many :posts, foreign_key: 'author_id'
|
||||
has_many :comments, foreign_key: 'author_id'
|
||||
has_many :forums, foreign_key: 'owner_id'
|
||||
has_many :gardens, foreign_key: 'owner_id'
|
||||
has_many :plantings, foreign_key: 'owner_id'
|
||||
|
||||
has_many :seeds, foreign_key: 'owner_id'
|
||||
has_many :harvests, foreign_key: 'owner_id'
|
||||
|
||||
has_and_belongs_to_many :roles # rubocop:disable Rails/HasAndBelongsToMany
|
||||
|
||||
has_many :notifications, foreign_key: 'recipient_id'
|
||||
has_many :sent_notifications, foreign_key: 'sender_id'
|
||||
|
||||
has_many :authentications
|
||||
|
||||
has_many :orders
|
||||
has_one :account
|
||||
has_one :account_type, through: :account
|
||||
|
||||
has_many :photos
|
||||
|
||||
has_many :requested_crops, class_name: Crop, foreign_key: 'requester_id'
|
||||
has_many :likes, dependent: :destroy
|
||||
has_many :follows, class_name: "Follow", foreign_key: "follower_id", dependent: :destroy
|
||||
has_many :inverse_follows, class_name: "Follow", foreign_key: "followed_id", dependent: :destroy
|
||||
has_many :followed, through: :follows
|
||||
has_many :followers, through: :inverse_follows, source: :follower
|
||||
|
||||
default_scope { order("lower(login_name) asc") }
|
||||
|
||||
#
|
||||
# Scopes
|
||||
scope :confirmed, -> { where.not(confirmed_at: nil) }
|
||||
scope :located, -> { where.not(location: '').where.not(latitude: nil).where.not(longitude: nil) }
|
||||
scope :recently_signed_in, -> { reorder(updated_at: :desc) }
|
||||
scope :recently_joined, -> { reorder(confirmed_at: :desc) }
|
||||
scope :wants_newsletter, -> { where(newsletter: true) }
|
||||
scope :interesting, -> { confirmed.located.recently_signed_in.has_plantings }
|
||||
|
||||
scope :has_plantings, -> { joins(:plantings).group("members.id") }
|
||||
|
||||
has_many :follows, class_name: "Follow", foreign_key: "follower_id"
|
||||
has_many :followed, through: :follows
|
||||
|
||||
has_many :inverse_follows, class_name: "Follow", foreign_key: "followed_id"
|
||||
has_many :followers, through: :inverse_follows, source: :follower
|
||||
|
||||
# Include default devise modules. Others available are:
|
||||
# :token_authenticatable, :confirmable,
|
||||
# :lockable, :timeoutable and :omniauthable
|
||||
@@ -57,45 +49,42 @@ class Member < ActiveRecord::Base
|
||||
|
||||
# set up geocoding
|
||||
geocoded_by :location
|
||||
after_validation :geocode
|
||||
after_validation :empty_unwanted_geocodes
|
||||
|
||||
# Virtual attribute for authenticating by either username or email
|
||||
# This is in addition to a real persisted field like 'username'
|
||||
attr_accessor :login
|
||||
|
||||
#
|
||||
# Validations
|
||||
# Requires acceptance of the Terms of Service
|
||||
validates :tos_agreement, acceptance: { allow_nil: true,
|
||||
accept: true }
|
||||
|
||||
validates :tos_agreement, acceptance: { allow_nil: true, accept: true }
|
||||
validates :login_name,
|
||||
length: {
|
||||
minimum: 2,
|
||||
maximum: 25,
|
||||
message: "should be between 2 and 25 characters long"
|
||||
minimum: 2, maximum: 25, message: "should be between 2 and 25 characters long"
|
||||
},
|
||||
exclusion: {
|
||||
in: %w(growstuff admin moderator staff nearby),
|
||||
message: "name is reserved"
|
||||
in: %w(growstuff admin moderator staff nearby), message: "name is reserved"
|
||||
},
|
||||
format: {
|
||||
with: /\A\w+\z/,
|
||||
message: "may only include letters, numbers, or underscores"
|
||||
with: /\A\w+\z/, message: "may only include letters, numbers, or underscores"
|
||||
},
|
||||
uniqueness: {
|
||||
case_sensitive: false
|
||||
}
|
||||
|
||||
# Give each new member a default garden
|
||||
after_create { |member| Garden.create(name: "Garden", owner_id: member.id) }
|
||||
#
|
||||
# Triggers
|
||||
after_validation :geocode
|
||||
after_validation :empty_unwanted_geocodes
|
||||
after_save :update_newsletter_subscription
|
||||
|
||||
# Give each new member a default garden
|
||||
# and an account record (for paid accounts etc)
|
||||
# we use find_or_create to avoid accidentally creating a second one,
|
||||
# which can happen sometimes especially with FactoryGirl associations
|
||||
# which can happen sometimes especially with FactoryBot associations
|
||||
after_create { |member| Garden.create(name: "Garden", owner_id: member.id) }
|
||||
after_create { |member| Account.find_or_create_by(member_id: member.id) }
|
||||
|
||||
after_save :update_newsletter_subscription
|
||||
|
||||
# allow login via either login_name or email address
|
||||
def self.find_first_by_auth_conditions(warden_conditions)
|
||||
conditions = warden_conditions.dup
|
||||
|
||||
@@ -5,7 +5,6 @@ class Notification < ActiveRecord::Base
|
||||
|
||||
validates :subject, length: { maximum: 255 }
|
||||
|
||||
default_scope { order('created_at DESC') }
|
||||
scope :unread, -> { where(read: false) }
|
||||
scope :by_recipient, ->(recipient) { where(recipient_id: recipient) }
|
||||
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
class Order < ActiveRecord::Base
|
||||
#
|
||||
# Relationships
|
||||
belongs_to :member, with_deleted: true
|
||||
|
||||
has_many :order_items, dependent: :destroy
|
||||
|
||||
default_scope { order('created_at DESC') }
|
||||
|
||||
#
|
||||
# Validations
|
||||
validates :referral_code, format: {
|
||||
with: /\A[a-zA-Z0-9 ]*\z/,
|
||||
message: "may only include letters and numbers"
|
||||
}
|
||||
|
||||
#
|
||||
# Teiggers
|
||||
before_save :standardize_referral_code
|
||||
|
||||
#
|
||||
# Scopes
|
||||
scope :by_member, ->(member) { where(member: member) }
|
||||
|
||||
# total price of an order
|
||||
|
||||
@@ -8,7 +8,7 @@ class Photo < ActiveRecord::Base
|
||||
|
||||
before_destroy { all_associations.clear }
|
||||
|
||||
default_scope { joins(:owner).order(created_at: :desc) }
|
||||
default_scope { joins(:owner) } # Ensures the owner still exists
|
||||
|
||||
def associations?
|
||||
plantings.any? || harvests.any? || gardens.any? || seeds.any?
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class PlantPart < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
friendly_id :name, use: [:slugged, :finders]
|
||||
friendly_id :name, use: %i(slugged finders)
|
||||
|
||||
has_many :harvests
|
||||
has_many :crops, -> { uniq }, through: :harvests
|
||||
|
||||
@@ -1,17 +1,30 @@
|
||||
class Planting < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
include PhotoCapable
|
||||
friendly_id :planting_slug, use: [:slugged, :finders]
|
||||
friendly_id :planting_slug, use: %i(slugged finders)
|
||||
|
||||
# Constants
|
||||
SUNNINESS_VALUES = %w(sun semi-shade shade)
|
||||
PLANTED_FROM_VALUES = [
|
||||
'seed', 'seedling', 'cutting', 'root division', 'runner',
|
||||
'bulb', 'root/tuber', 'bare root plant', 'advanced plant',
|
||||
'graft', 'layering'
|
||||
]
|
||||
|
||||
##
|
||||
## Triggers
|
||||
before_save :calculate_lifespan
|
||||
|
||||
belongs_to :garden
|
||||
belongs_to :owner, class_name: 'Member', counter_cache: true
|
||||
belongs_to :crop, counter_cache: true
|
||||
has_many :harvests, dependent: :destroy
|
||||
|
||||
default_scope { joins(:owner).order(created_at: :desc) }
|
||||
##
|
||||
## Scopes
|
||||
default_scope { joins(:owner) } # Ensures the owner still exists
|
||||
scope :finished, -> { where(finished: true) }
|
||||
scope :current, -> { where(finished: false) }
|
||||
|
||||
scope :interesting, -> { has_photos.one_per_owner }
|
||||
scope :one_per_owner, lambda {
|
||||
joins("JOIN members m ON (m.id=plantings.owner_id)
|
||||
@@ -19,60 +32,26 @@ class Planting < ActiveRecord::Base
|
||||
ON (m.id=p2.owner_id AND plantings.id < p2.id)").where("p2 IS NULL")
|
||||
}
|
||||
|
||||
delegate :name,
|
||||
:en_wikipedia_url,
|
||||
:default_scientific_name,
|
||||
:plantings_count,
|
||||
to: :crop,
|
||||
prefix: true
|
||||
##
|
||||
## Delegations
|
||||
delegate :name, :en_wikipedia_url, :default_scientific_name, :plantings_count,
|
||||
to: :crop, prefix: true
|
||||
|
||||
##
|
||||
## Validations
|
||||
validates :garden, presence: true
|
||||
validates :crop, presence: true
|
||||
validates :crop, approved: { message: "must be present and exist in our database" }
|
||||
|
||||
validates :quantity,
|
||||
numericality: {
|
||||
only_integer: true,
|
||||
greater_than_or_equal_to: 0
|
||||
},
|
||||
allow_nil: true
|
||||
|
||||
SUNNINESS_VALUES = %w(sun semi-shade shade)
|
||||
validates :sunniness, inclusion: { in: SUNNINESS_VALUES,
|
||||
message: "%{value} is not a valid sunniness value" },
|
||||
allow_nil: true,
|
||||
allow_blank: true
|
||||
|
||||
PLANTED_FROM_VALUES = [
|
||||
'seed',
|
||||
'seedling',
|
||||
'cutting',
|
||||
'root division',
|
||||
'runner',
|
||||
'bulb',
|
||||
'root/tuber',
|
||||
'bare root plant',
|
||||
'advanced plant',
|
||||
'graft',
|
||||
'layering'
|
||||
]
|
||||
validates :planted_from, inclusion: { in: PLANTED_FROM_VALUES,
|
||||
message: "%{value} is not a valid planting method" },
|
||||
allow_nil: true,
|
||||
allow_blank: true
|
||||
|
||||
validates :crop, presence: true, approved: { message: "must be present and exist in our database" }
|
||||
validate :finished_must_be_after_planted
|
||||
|
||||
delegate :days_until_finished, to: :predict
|
||||
delegate :days_until_mature, to: :predict
|
||||
delegate :percentage_grown, to: :predict
|
||||
delegate :start_to_finish_diff, to: :predict
|
||||
|
||||
# check that any finished_at date occurs after planted_at
|
||||
def finished_must_be_after_planted
|
||||
return unless planted_at && finished_at # only check if we have both
|
||||
errors.add(:finished_at, "must be after the planting date") unless planted_at < finished_at
|
||||
end
|
||||
validate :owner_must_match_garden_owner
|
||||
validates :quantity, allow_nil: true, numericality: {
|
||||
only_integer: true, greater_than_or_equal_to: 0
|
||||
}
|
||||
validates :sunniness, allow_nil: true, allow_blank: true, inclusion: {
|
||||
in: SUNNINESS_VALUES, message: "%<value>s is not a valid sunniness value"
|
||||
}
|
||||
validates :planted_from, allow_nil: true, allow_blank: true, inclusion: {
|
||||
in: PLANTED_FROM_VALUES, message: "%<value>s is not a valid planting method"
|
||||
}
|
||||
|
||||
def planting_slug
|
||||
[
|
||||
@@ -93,20 +72,71 @@ class Planting < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def default_photo
|
||||
photos.first
|
||||
photos.order(created_at: :desc).first
|
||||
end
|
||||
|
||||
def planted?
|
||||
planted_at.present? && planted_at <= Date.current
|
||||
end
|
||||
|
||||
def calc_and_set_days_before_maturity
|
||||
self.days_before_maturity = predict.predict_days_before_maturity
|
||||
def finish_predicted_at
|
||||
planted_at + crop.median_lifespan.days if crop.median_lifespan.present? && planted_at.present?
|
||||
end
|
||||
|
||||
def calculate_lifespan
|
||||
self.lifespan = (planted_at.present? && finished_at.present? ? finished_at - planted_at : nil)
|
||||
end
|
||||
|
||||
def expected_lifespan
|
||||
if planted_at.present? && finished_at.present?
|
||||
return (finished_at - planted_at).to_i
|
||||
end
|
||||
crop.median_lifespan
|
||||
end
|
||||
|
||||
def days_since_planted
|
||||
(Time.zone.today - planted_at).to_i if planted_at.present?
|
||||
end
|
||||
|
||||
def percentage_grown
|
||||
return 100 if finished
|
||||
return if planted_at.blank? || expected_lifespan.blank?
|
||||
p = (days_since_planted / expected_lifespan.to_f) * 100
|
||||
return p if p <= 100
|
||||
100
|
||||
end
|
||||
|
||||
def update_harvest_days
|
||||
days_to_first_harvest = nil
|
||||
days_to_last_harvest = nil
|
||||
if planted_at.present? && harvests_with_dates.size.positive?
|
||||
days_to_first_harvest = (first_harvest_date - planted_at).to_i
|
||||
days_to_last_harvest = (last_harvest_date - planted_at).to_i if finished?
|
||||
end
|
||||
update(days_to_first_harvest: days_to_first_harvest, days_to_last_harvest: days_to_last_harvest)
|
||||
end
|
||||
|
||||
def first_harvest_date
|
||||
harvests_with_dates.minimum(:harvested_at)
|
||||
end
|
||||
|
||||
def last_harvest_date
|
||||
harvests_with_dates.maximum(:harvested_at)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def predict
|
||||
PlantingPredictions.new(self)
|
||||
def harvests_with_dates
|
||||
harvests.where.not(harvested_at: nil)
|
||||
end
|
||||
|
||||
# check that any finished_at date occurs after planted_at
|
||||
def finished_must_be_after_planted
|
||||
return unless planted_at && finished_at # only check if we have both
|
||||
errors.add(:finished_at, "must be after the planting date") unless planted_at < finished_at
|
||||
end
|
||||
|
||||
def owner_must_match_garden_owner
|
||||
errors.add(:owner, "must be the same as garden") unless owner == garden.owner
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,46 +1,28 @@
|
||||
class Post < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
include Likeable
|
||||
friendly_id :author_date_subject, use: [:slugged, :finders]
|
||||
friendly_id :author_date_subject, use: %i(slugged finders)
|
||||
|
||||
#
|
||||
# Relationships
|
||||
belongs_to :author, class_name: 'Member'
|
||||
belongs_to :forum
|
||||
has_many :comments, dependent: :destroy
|
||||
has_and_belongs_to_many :crops # rubocop:disable Rails/HasAndBelongsToMany
|
||||
before_destroy { |post| post.crops.clear }
|
||||
after_save :update_crops_posts_association
|
||||
# also has_many notifications, but kinda meaningless to get at them
|
||||
# from this direction, so we won't set up an association for now.
|
||||
|
||||
after_create do
|
||||
recipients = []
|
||||
sender = author.id
|
||||
body.scan(Haml::Filters::GrowstuffMarkdown::MEMBER_REGEX) do |_m|
|
||||
# find member case-insensitively and add to list of recipients
|
||||
member = Member.case_insensitive_login_name(Regexp.last_match(1)).first
|
||||
recipients << member if member && !recipients.include?(member)
|
||||
end
|
||||
body.scan(Haml::Filters::GrowstuffMarkdown::MEMBER_AT_REGEX) do |_m|
|
||||
# find member case-insensitively and add to list of recipients
|
||||
member = Member.case_insensitive_login_name(Regexp.last_match(1)[1..-1]).first
|
||||
recipients << member if member && !recipients.include?(member)
|
||||
end
|
||||
# don't send notifications to yourself
|
||||
recipients.map(&:id).each do |recipient|
|
||||
next unless recipient != sender
|
||||
Notification.create(
|
||||
recipient_id: recipient,
|
||||
sender_id: sender,
|
||||
subject: "#{author} mentioned you in their post #{subject}",
|
||||
body: body
|
||||
)
|
||||
end
|
||||
end
|
||||
#
|
||||
# Triggers
|
||||
before_destroy { |post| post.crops.clear }
|
||||
after_save :update_crops_posts_association
|
||||
after_create :send_notification
|
||||
|
||||
default_scope { joins(:author).order(created_at: :desc) }
|
||||
default_scope { joins(:author) } # Ensures the owner still exists
|
||||
|
||||
validates :subject,
|
||||
presence: true,
|
||||
length: { maximum: 255 }
|
||||
#
|
||||
# Validations
|
||||
validates :subject, presence: true, length: { maximum: 255 }
|
||||
|
||||
def author_date_subject
|
||||
# slugs are created before created_at is set
|
||||
@@ -56,7 +38,7 @@ class Post < ActiveRecord::Base
|
||||
# i.e. the time of the most recent comment, or of the post itself if
|
||||
# there are no comments.
|
||||
def recent_activity
|
||||
comments.present? ? comments.reorder('created_at DESC').first.created_at : created_at
|
||||
comments.present? ? comments.order(created_at: :desc).first.created_at : created_at
|
||||
end
|
||||
|
||||
# return posts sorted by recent activity
|
||||
@@ -78,4 +60,29 @@ class Post < ActiveRecord::Base
|
||||
crops << crop if crop && !crops.include?(crop)
|
||||
end
|
||||
end
|
||||
|
||||
def send_notification
|
||||
recipients = []
|
||||
sender = author.id
|
||||
body.scan(Haml::Filters::GrowstuffMarkdown::MEMBER_REGEX) do |_m|
|
||||
# find member case-insensitively and add to list of recipients
|
||||
member = Member.case_insensitive_login_name(Regexp.last_match(1)).first
|
||||
recipients << member if member && !recipients.include?(member)
|
||||
end
|
||||
body.scan(Haml::Filters::GrowstuffMarkdown::MEMBER_AT_REGEX) do |_m|
|
||||
# find member case-insensitively and add to list of recipients
|
||||
member = Member.case_insensitive_login_name(Regexp.last_match(1)[1..-1]).first
|
||||
recipients << member if member && !recipients.include?(member)
|
||||
end
|
||||
# don't send notifications to yourself
|
||||
recipients.map(&:id).each do |recipient_id|
|
||||
next unless recipient_id != sender
|
||||
Notification.create(
|
||||
recipient_id: recipient_id,
|
||||
sender_id: sender,
|
||||
subject: "#{author} mentioned you in their post #{subject}",
|
||||
body: body
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
class Product < ActiveRecord::Base
|
||||
has_and_belongs_to_many :orders # rubocop:disable Rails/HasAndBelongsToMany
|
||||
#
|
||||
# Relationships
|
||||
belongs_to :account_type
|
||||
has_and_belongs_to_many :orders # rubocop:disable Rails/HasAndBelongsToMany
|
||||
|
||||
validates :paid_months,
|
||||
numericality: {
|
||||
only_integer: true,
|
||||
greater_than_or_equal_to: 0
|
||||
},
|
||||
allow_nil: true
|
||||
#
|
||||
# Validations
|
||||
validates :paid_months, allow_nil: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
|
||||
validates :min_price, presence: true
|
||||
|
||||
def to_s
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
class Role < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
friendly_id :name, use: [:slugged, :finders]
|
||||
friendly_id :name, use: %i(slugged finders)
|
||||
|
||||
has_and_belongs_to_many :members # rubocop:disable Rails/HasAndBelongsToMany
|
||||
|
||||
class << self
|
||||
[:crop_wranglers, :admins].each do |method|
|
||||
%i(crop_wranglers admins).each do |method|
|
||||
define_method method do
|
||||
slug = method.to_s.singularize.dasherize
|
||||
Role.where(slug: slug).try(:first).try(:members)
|
||||
|
||||
@@ -1,83 +1,52 @@
|
||||
class Seed < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
include PhotoCapable
|
||||
friendly_id :seed_slug, use: [:slugged, :finders]
|
||||
friendly_id :seed_slug, use: %i(slugged finders)
|
||||
|
||||
TRADABLE_TO_VALUES = %w(nowhere locally nationally internationally).freeze
|
||||
ORGANIC_VALUES = ['certified organic', 'non-certified organic', 'conventional/non-organic', 'unknown'].freeze
|
||||
GMO_VALUES = ['certified GMO-free', 'non-certified GMO-free', 'GMO', 'unknown'].freeze
|
||||
HEIRLOOM_VALUES = %w(heirloom hybrid unknown).freeze
|
||||
|
||||
#
|
||||
# Relationships
|
||||
belongs_to :crop
|
||||
belongs_to :owner, class_name: 'Member', foreign_key: 'owner_id', counter_cache: true
|
||||
|
||||
default_scope { joins(:owner).order(created_at: :desc) }
|
||||
|
||||
#
|
||||
# Validations
|
||||
validates :crop, approved: true
|
||||
delegate :name, to: :crop
|
||||
delegate :default_photo, to: :crop
|
||||
|
||||
validates :crop, presence: { message: "must be present and exist in our database" }
|
||||
validates :quantity,
|
||||
numericality: {
|
||||
only_integer: true,
|
||||
greater_than_or_equal_to: 0
|
||||
},
|
||||
allow_nil: true
|
||||
validates :days_until_maturity_min,
|
||||
numericality: {
|
||||
only_integer: true,
|
||||
greater_than_or_equal_to: 0
|
||||
},
|
||||
allow_nil: true
|
||||
validates :days_until_maturity_max,
|
||||
numericality: {
|
||||
only_integer: true,
|
||||
greater_than_or_equal_to: 0
|
||||
},
|
||||
allow_nil: true
|
||||
validates :quantity, allow_nil: true,
|
||||
numericality: { only_integer: true, greater_than_or_equal_to: 0 }
|
||||
validates :days_until_maturity_min, allow_nil: true,
|
||||
numericality: { only_integer: true, greater_than_or_equal_to: 0 }
|
||||
validates :days_until_maturity_max, allow_nil: true,
|
||||
numericality: { only_integer: true, greater_than_or_equal_to: 0 }
|
||||
validates :tradable_to, allow_nil: false, allow_blank: false,
|
||||
inclusion: { in: TRADABLE_TO_VALUES, message: "You may only trade seed nowhere, "\
|
||||
"locally, nationally, or internationally" }
|
||||
validates :organic, allow_nil: false, allow_blank: false,
|
||||
inclusion: { in: ORGANIC_VALUES, message: "You must say whether the seeds "\
|
||||
"are organic or not, or that you don't know" }
|
||||
validates :gmo, allow_nil: false, allow_blank: false,
|
||||
inclusion: { in: GMO_VALUES, message: "You must say whether the seeds are "\
|
||||
"genetically modified or not, or that you don't know" }
|
||||
validates :heirloom, allow_nil: false, allow_blank: false,
|
||||
inclusion: { in: HEIRLOOM_VALUES, message: "You must say whether the seeds"\
|
||||
"are heirloom, hybrid, or unknown" }
|
||||
|
||||
#
|
||||
# Scopes
|
||||
default_scope { joins(:owner) } # Ensure owner exists
|
||||
scope :tradable, -> { where.not(tradable_to: 'nowhere') }
|
||||
scope :interesting, -> { tradable.has_location }
|
||||
scope :has_location, -> { joins(:owner).where.not("members.location": nil) }
|
||||
TRADABLE_TO_VALUES = %w(nowhere locally nationally internationally).freeze
|
||||
validates :tradable_to, inclusion: { in: TRADABLE_TO_VALUES,
|
||||
message: "You may only trade seed nowhere, "\
|
||||
"locally, nationally, or internationally" },
|
||||
allow_nil: false,
|
||||
allow_blank: false
|
||||
|
||||
ORGANIC_VALUES = [
|
||||
'certified organic',
|
||||
'non-certified organic',
|
||||
'conventional/non-organic',
|
||||
'unknown'
|
||||
].freeze
|
||||
validates :organic, inclusion: { in: ORGANIC_VALUES,
|
||||
message: "You must say whether the seeds "\
|
||||
"are organic or not, or that you don't know" },
|
||||
allow_nil: false,
|
||||
allow_blank: false
|
||||
|
||||
GMO_VALUES = [
|
||||
'certified GMO-free',
|
||||
'non-certified GMO-free',
|
||||
'GMO',
|
||||
'unknown'
|
||||
].freeze
|
||||
validates :gmo, inclusion: { in: GMO_VALUES,
|
||||
message: "You must say whether the seeds are "\
|
||||
"genetically modified or not, or that you don't know" },
|
||||
allow_nil: false,
|
||||
allow_blank: false
|
||||
|
||||
HEIRLOOM_VALUES = %w(heirloom hybrid unknown).freeze
|
||||
validates :heirloom, inclusion: { in: HEIRLOOM_VALUES,
|
||||
message: "You must say whether the seeds are heirloom, hybrid, or unknown" },
|
||||
allow_nil: false,
|
||||
allow_blank: false
|
||||
|
||||
def tradable?
|
||||
if tradable_to == 'nowhere'
|
||||
false
|
||||
else
|
||||
true
|
||||
end
|
||||
tradable_to != 'nowhere'
|
||||
end
|
||||
|
||||
def seed_slug
|
||||
|
||||
8
app/resources/api/v1/base_resource.rb
Normal file
8
app/resources/api/v1/base_resource.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
module Api
|
||||
module V1
|
||||
class BaseResource < JSONAPI::Resource
|
||||
immutable
|
||||
abstract
|
||||
end
|
||||
end
|
||||
end
|
||||
22
app/resources/api/v1/crop_resource.rb
Normal file
22
app/resources/api/v1/crop_resource.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
module Api
|
||||
module V1
|
||||
class CropResource < BaseResource
|
||||
immutable
|
||||
|
||||
filter :approval_status, default: 'approved'
|
||||
|
||||
has_many :plantings
|
||||
has_many :photos
|
||||
has_many :harvests
|
||||
has_one :parent
|
||||
|
||||
attribute :name
|
||||
attribute :en_wikipedia_url
|
||||
|
||||
attribute :perennial
|
||||
attribute :median_lifespan
|
||||
attribute :median_days_to_first_harvest
|
||||
attribute :median_days_to_last_harvest
|
||||
end
|
||||
end
|
||||
end
|
||||
13
app/resources/api/v1/garden_resource.rb
Normal file
13
app/resources/api/v1/garden_resource.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
module Api
|
||||
module V1
|
||||
class GardenResource < BaseResource
|
||||
immutable
|
||||
|
||||
has_one :owner, class_name: 'Member'
|
||||
has_many :plantings
|
||||
has_many :photos
|
||||
|
||||
attribute :name
|
||||
end
|
||||
end
|
||||
end
|
||||
19
app/resources/api/v1/harvest_resource.rb
Normal file
19
app/resources/api/v1/harvest_resource.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
module Api
|
||||
module V1
|
||||
class HarvestResource < BaseResource
|
||||
immutable
|
||||
|
||||
has_one :crop
|
||||
has_one :planting
|
||||
has_one :owner, class_name: 'Member'
|
||||
has_many :photos
|
||||
|
||||
attribute :harvested_at
|
||||
attribute :description
|
||||
attribute :unit
|
||||
attribute :weight_quantity
|
||||
attribute :weight_unit
|
||||
attribute :si_weight
|
||||
end
|
||||
end
|
||||
end
|
||||
15
app/resources/api/v1/member_resource.rb
Normal file
15
app/resources/api/v1/member_resource.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
module Api
|
||||
module V1
|
||||
class MemberResource < BaseResource
|
||||
immutable
|
||||
|
||||
has_many :gardens
|
||||
has_many :plantings
|
||||
has_many :harvests
|
||||
has_many :seeds
|
||||
has_many :photos
|
||||
|
||||
attribute :login_name
|
||||
end
|
||||
end
|
||||
end
|
||||
18
app/resources/api/v1/photo_resource.rb
Normal file
18
app/resources/api/v1/photo_resource.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
module Api
|
||||
module V1
|
||||
class PhotoResource < BaseResource
|
||||
immutable
|
||||
|
||||
has_one :owner, class_name: 'Member'
|
||||
has_many :plantings
|
||||
has_many :gardens
|
||||
has_many :harvests
|
||||
|
||||
attribute :thumbnail_url
|
||||
attribute :fullsize_url
|
||||
attribute :license_name
|
||||
attribute :link_url
|
||||
attribute :title
|
||||
end
|
||||
end
|
||||
end
|
||||
28
app/resources/api/v1/planting_resource.rb
Normal file
28
app/resources/api/v1/planting_resource.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
module Api
|
||||
module V1
|
||||
class PlantingResource < BaseResource
|
||||
immutable
|
||||
|
||||
has_one :garden
|
||||
has_one :crop
|
||||
has_one :owner, class_name: 'Member'
|
||||
has_many :photos
|
||||
has_many :harvests
|
||||
|
||||
attribute :planted_at
|
||||
attribute :finished_at
|
||||
attribute :finished
|
||||
attribute :quantity
|
||||
attribute :description
|
||||
attribute :sunniness
|
||||
attribute :planted_from
|
||||
|
||||
# Predictions
|
||||
attribute :expected_lifespan
|
||||
attribute :finish_predicted_at
|
||||
attribute :percentage_grown
|
||||
attribute :first_harvest_date
|
||||
attribute :last_harvest_date
|
||||
end
|
||||
end
|
||||
end
|
||||
20
app/resources/api/v1/seed_resource.rb
Normal file
20
app/resources/api/v1/seed_resource.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
module Api
|
||||
module V1
|
||||
class SeedResource < BaseResource
|
||||
immutable
|
||||
|
||||
has_one :owner, class_name: 'Member'
|
||||
has_one :crop
|
||||
|
||||
attribute :description
|
||||
attribute :quantity
|
||||
attribute :plant_before
|
||||
attribute :tradable_to
|
||||
attribute :days_until_maturity_min
|
||||
attribute :days_until_maturity_max
|
||||
attribute :organic
|
||||
attribute :gmo
|
||||
attribute :heirloom
|
||||
end
|
||||
end
|
||||
end
|
||||
42
app/services/crop_search_service.rb
Normal file
42
app/services/crop_search_service.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
class CropSearchService
|
||||
# Crop.search(string)
|
||||
def self.search(query)
|
||||
if ENV['GROWSTUFF_ELASTICSEARCH'] == "true"
|
||||
search_str = query.nil? ? "" : query.downcase
|
||||
response = Crop.__elasticsearch__.search( # Finds documents which match any field, but uses the _score from
|
||||
# the best field insead of adding up _score from each field.
|
||||
query: {
|
||||
multi_match: {
|
||||
query: search_str.to_s,
|
||||
analyzer: "standard",
|
||||
fields: ["name",
|
||||
"scientific_names.scientific_name",
|
||||
"alternate_names.name"]
|
||||
}
|
||||
},
|
||||
filter: {
|
||||
term: { approval_status: "approved" }
|
||||
},
|
||||
size: 50
|
||||
)
|
||||
response.records.to_a
|
||||
else
|
||||
# if we don't have elasticsearch, just do a basic SQL query.
|
||||
# also, make sure it's an actual array not an activerecord
|
||||
# collection, so it matches what we get from elasticsearch and we can
|
||||
# manipulate it in the same ways (eg. deleting elements without deleting
|
||||
# the whole record from the db)
|
||||
matches = Crop.approved.where("name ILIKE ?", "%#{query}%").to_a
|
||||
|
||||
# we want to make sure that exact matches come first, even if not
|
||||
# using elasticsearch (eg. in development)
|
||||
exact_match = Crop.approved.find_by(name: query)
|
||||
if exact_match
|
||||
matches.delete(exact_match)
|
||||
matches.unshift(exact_match)
|
||||
end
|
||||
|
||||
matches
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,58 +0,0 @@
|
||||
class PlantingPredictions
|
||||
def initialize(planting)
|
||||
@planting = planting
|
||||
end
|
||||
|
||||
def days_until_finished
|
||||
return 0 if @planting.finished?
|
||||
days = (@planting.finished_at - Date.current).to_i
|
||||
days.positive? ? days : 0
|
||||
end
|
||||
|
||||
def days_until_mature
|
||||
days = ((@planting.planted_at + @planting.days_before_maturity) - Date.current).to_i
|
||||
days.positive? ? days : 0
|
||||
end
|
||||
|
||||
def percentage_grown
|
||||
return nil unless @planting.days_before_maturity && @planting.planted?
|
||||
|
||||
days = (Date.current - @planting.planted_at.to_date).to_f
|
||||
|
||||
return 0 if Date.current < @planting.planted_at
|
||||
return 100 if days > @planting.days_before_maturity
|
||||
percent = (days / @planting.days_before_maturity * 100).to_i
|
||||
|
||||
percent = 100 if percent >= 100
|
||||
|
||||
percent
|
||||
end
|
||||
|
||||
def start_to_finish_diff
|
||||
(@planting.finished_at - @planting.planted_at).to_i if @planting.finished_at && @planting.planted_at
|
||||
end
|
||||
|
||||
def predict_days_before_maturity
|
||||
# calculate the number of days, from planted_at, until maturity
|
||||
if @planting.planted_at && @planting.finished_at
|
||||
start_to_finish_diff
|
||||
elsif @planting.crop_id
|
||||
plantings = other_finished_plantings_same_crop
|
||||
PlantingPredictions.mean_days_until_maturity(plantings)
|
||||
end
|
||||
end
|
||||
|
||||
def self.mean_days_until_maturity(plantings)
|
||||
## Given a set of finished plantings, calculate the average/mean time from start to finish
|
||||
differences = plantings.collect(&:start_to_finish_diff)
|
||||
differences.compact.sum / differences.compact.size unless differences.compact.empty?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def other_finished_plantings_same_crop
|
||||
Planting.where(crop_id: @planting.crop_id)
|
||||
.where.not(id: @planting.id)
|
||||
.where.not(finished_at: nil)
|
||||
end
|
||||
end
|
||||
@@ -29,6 +29,16 @@
|
||||
Wranglers: please ensure this is singular, and capitalize
|
||||
proper nouns only.
|
||||
|
||||
.form-group
|
||||
= f.label :perennial, 'Lifespan', class: 'control-label col-md-2'
|
||||
.col-md-8
|
||||
= f.radio_button(:perennial, false)
|
||||
= f.label(:perennial_false, "Annual")
|
||||
%span.help-block Living and reproducing in a single year or less
|
||||
= f.radio_button(:perennial, true)
|
||||
= f.label(:perennial_true, "Perennial")
|
||||
%span.help-block Living more than two years
|
||||
|
||||
.form-group
|
||||
= f.label :en_wikipedia_url, 'Wikipedia URL', class: 'control-label col-md-2'
|
||||
.col-md-8
|
||||
|
||||
@@ -12,11 +12,23 @@
|
||||
%p
|
||||
%b Scientific name:
|
||||
= crop.default_scientific_name
|
||||
%p
|
||||
%b
|
||||
Planted
|
||||
= pluralize(crop.plantings.size, "time")
|
||||
by #{ENV['GROWSTUFF_SITE_NAME']} members
|
||||
|
||||
- if crop.annual? && crop.median_lifespan.present?
|
||||
%p
|
||||
Median Lifespan
|
||||
%b= crop.median_lifespan
|
||||
days
|
||||
- unless crop.median_days_to_first_harvest.nil?
|
||||
%p
|
||||
First harvest expected
|
||||
%b= crop.median_days_to_first_harvest
|
||||
days after planting
|
||||
|
||||
- if crop.annual? && crop.median_days_to_last_harvest.present?
|
||||
%p
|
||||
Last harvest expected
|
||||
%b= crop.median_days_to_last_harvest
|
||||
days after planting
|
||||
|
||||
- if can? :create, Planting
|
||||
= link_to 'Plant this', new_planting_path(params: { crop_id: crop.id }), class: 'btn btn-primary'
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
- unless crop.harvest_photos.empty?
|
||||
%h3 Photos of #{crop.name} harvests
|
||||
.row
|
||||
- crop.harvest_photos.first(6).each do |p|
|
||||
.col-xs-6.col-md-2
|
||||
= render "photos/thumbnail", photo: p
|
||||
|
||||
- unless crop.photos.empty?
|
||||
%h3 Photos of #{crop.name} plants
|
||||
.row
|
||||
- crop.photos.first(6).each do |p|
|
||||
.col-xs-6.col-md-2
|
||||
= render "photos/thumbnail", photo: p
|
||||
.row
|
||||
- unless crop.photos.empty?
|
||||
- crop.photos.first(3).each do |p|
|
||||
.col-md-4
|
||||
= render partial: "photos/thumbnail", locals: { photo: p }
|
||||
= link_to "more photos", crop_photos_path(crop_id: crop.id)
|
||||
|
||||
29
app/views/crops/_predictions.html.haml
Normal file
29
app/views/crops/_predictions.html.haml
Normal file
@@ -0,0 +1,29 @@
|
||||
- unless crop.perennial.nil?
|
||||
%p
|
||||
#{crop.name} is
|
||||
- if crop.perennial == true
|
||||
= link_to 'https://en.wikipedia.org/wiki/Annual_vs._perennial_plant_evolution' do
|
||||
a perennial crop
|
||||
(living more than two years)
|
||||
- elsif crop.perennial == false
|
||||
= link_to 'https://en.wikipedia.org/wiki/Annual_vs._perennial_plant_evolution' do
|
||||
an annual crop
|
||||
(living and reproducing in a single year or less)
|
||||
|
||||
- if crop.annual? && crop.median_lifespan.present?
|
||||
%p
|
||||
Median lifespan of #{crop.name} plants is
|
||||
%strong= crop.median_lifespan
|
||||
days
|
||||
|
||||
- if crop.median_days_to_first_harvest.present?
|
||||
%p
|
||||
First harvest expected
|
||||
%strong= crop.median_days_to_first_harvest
|
||||
days after planting
|
||||
|
||||
- if crop.annual? && crop.median_days_to_last_harvest.present?
|
||||
%p
|
||||
Last harvest expected
|
||||
%strong= crop.median_days_to_last_harvest
|
||||
days after planting
|
||||
@@ -20,19 +20,17 @@
|
||||
|
||||
- if can? :create, Seed
|
||||
= link_to 'Add seeds to stash', new_seed_path(params: { crop_id: @crop.id }), class: 'btn btn-default'
|
||||
- if member_signed_in?
|
||||
= display_seed_availability(@current_member, @crop)
|
||||
= link_to "View your seeds", seeds_by_owner_path(owner: current_member.slug)
|
||||
|
||||
.row
|
||||
.col-md-9
|
||||
- unless current_member
|
||||
Learn how to grow #{@crop.name.pluralize} from growers around the world.
|
||||
#{ENV['GROWSTUFF_SITE_NAME']} has tips and advice from real-life growers,
|
||||
including when to plant #{@crop.name.pluralize}, how to harvest
|
||||
#{@crop.name.pluralize}, and more.
|
||||
- if member_signed_in?
|
||||
= display_seed_availability(@current_member, @crop)
|
||||
= link_to "View your seeds", seeds_by_owner_path(owner: current_member.slug)
|
||||
|
||||
= render partial: 'photos', locals: { crop: @crop }
|
||||
%h2 Predictions
|
||||
= render 'predictions', crop: @crop
|
||||
|
||||
%p= render 'crops/photos', crop: @crop
|
||||
|
||||
%h2
|
||||
- if !@crop.plantings.empty?
|
||||
@@ -86,18 +84,18 @@
|
||||
|
||||
%h4 How to grow #{@crop.name.pluralize}
|
||||
|
||||
= render partial: 'grown_for', locals: { crop: @crop }
|
||||
= render partial: 'planting_advice', locals: { crop: @crop }
|
||||
= render 'grown_for', crop: @crop
|
||||
= render 'planting_advice', crop: @crop
|
||||
|
||||
= render partial: 'scientific_names', locals: { crop: @crop }
|
||||
= render partial: 'alternate_names', locals: { crop: @crop }
|
||||
= render 'scientific_names', crop: @crop
|
||||
= render 'alternate_names', crop: @crop
|
||||
|
||||
%h4 #{@crop.name.capitalize} varieties
|
||||
= render partial: 'varieties', locals: { crop: @crop }
|
||||
= render 'varieties', crop: @crop
|
||||
|
||||
= render partial: 'plantings', locals: { crop: @crop }
|
||||
= render partial: 'harvests', locals: { crop: @crop }
|
||||
= render partial: 'find_seeds', locals: { crop: @crop }
|
||||
= render 'plantings', crop: @crop
|
||||
= render 'harvests', crop: @crop
|
||||
= render 'find_seeds', crop: @crop
|
||||
|
||||
|
||||
%h4 Learn more about #{@crop.name.pluralize}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
confirm: "Are you sure you want to remove this connection?",
|
||||
method: :delete, class: "remove"
|
||||
- else
|
||||
= link_to 'Connect to Twitter', '/auth/twitter'
|
||||
= link_to 'Connect to Twitter', '/members/auth/twitter'
|
||||
|
||||
.row
|
||||
.col-md-12
|
||||
@@ -30,7 +30,7 @@
|
||||
confirm: "Are you sure you want to remove this connection?",
|
||||
method: :delete, class: "remove"
|
||||
- else
|
||||
= link_to 'Connect to Flickr', '/auth/flickr'
|
||||
= link_to 'Connect to Flickr', '/members/auth/flickr'
|
||||
|
||||
.row
|
||||
.col-md-12
|
||||
@@ -44,4 +44,4 @@
|
||||
confirm: "Are you sure you want to remove this connection?",
|
||||
method: :delete, class: "remove"
|
||||
- else
|
||||
= link_to 'Connect to Facebook', '/auth/facebook'
|
||||
= link_to 'Connect to Facebook', '/members/auth/facebook'
|
||||
|
||||
@@ -21,3 +21,8 @@
|
||||
class: 'btn btn-default', id: 'delete_garden_link' do
|
||||
%span.glyphicon.glyphicon-trash{ title: "Delete" }
|
||||
Delete
|
||||
- if can?(:edit, garden) && can?(:create, Photo)
|
||||
= link_to new_photo_path(type: "garden", id: garden.id),
|
||||
class: 'btn btn-primary' do
|
||||
%span.glyphicon.glyphicon-camera{ title: "Add Photo" }
|
||||
Add Photo
|
||||
|
||||
@@ -91,8 +91,8 @@
|
||||
%p
|
||||
= link_to new_photo_path(type: "garden", id: @garden.id),
|
||||
class: 'btn btn-primary' do
|
||||
%span.glyphicon.glyphicon-camera{ title: "Add Photo" }
|
||||
Add Photo
|
||||
%span.glyphicon.glyphicon-camera{ title: "Add photo" }
|
||||
Add photo
|
||||
- if @garden.photos.size.positive?
|
||||
%h3= localize_plural(@garden.photos, Photo)
|
||||
.row
|
||||
|
||||
29
app/views/harvests/_card.html.haml
Normal file
29
app/views/harvests/_card.html.haml
Normal file
@@ -0,0 +1,29 @@
|
||||
.panel.panel-success
|
||||
.panel-heading
|
||||
%h3.panel-title
|
||||
= link_to "#{harvest.owner.login_name}'s #{harvest.crop.name} harvest", harvest
|
||||
- if can? :edit, harvest
|
||||
%a.pull-right{ href: edit_harvest_path(harvest), role: "button", id: "edit_harvest_glyphicon" }
|
||||
%span.glyphicon.glyphicon-pencil{ title: "Edit" }
|
||||
.panel-body
|
||||
.row
|
||||
.col-md-4
|
||||
= link_to image_tag((harvest.default_photo ? harvest.default_photo.thumbnail_url : 'placeholder_150.png'),
|
||||
alt: harvest.crop.name, class: 'img'),
|
||||
harvest
|
||||
.col-md-8
|
||||
%dl.dl-horizontal
|
||||
%dt Crop :
|
||||
%dd= link_to harvest.crop.name, harvest.crop
|
||||
%dt Plant part :
|
||||
%dd= link_to harvest.plant_part, harvest.plant_part
|
||||
%dt Quantity :
|
||||
%dd= display_quantity(harvest)
|
||||
%dt Harvest date :
|
||||
%dd= harvest.harvested_at
|
||||
.panel-footer
|
||||
%dt Description
|
||||
%dd.truncate
|
||||
= display_harvest_description(harvest)
|
||||
= if harvest.description.present?
|
||||
- link_to "Read more", harvest_path(harvest)
|
||||
@@ -1,29 +1,9 @@
|
||||
.panel.panel-success
|
||||
.panel-heading
|
||||
%h3.panel-title
|
||||
= link_to "#{harvest.owner.login_name}'s #{harvest.crop.name} harvest", harvest
|
||||
- if can? :edit, harvest
|
||||
%a.pull-right{ href: edit_harvest_path(harvest), role: "button", id: "edit_harvest_glyphicon" }
|
||||
%span.glyphicon.glyphicon-pencil{ title: "Edit" }
|
||||
.panel-body
|
||||
.row
|
||||
.col-md-4
|
||||
= link_to image_tag((harvest.default_photo ? harvest.default_photo.thumbnail_url : 'placeholder_150.png'),
|
||||
alt: harvest.crop.name, class: 'img'),
|
||||
harvest
|
||||
.col-md-8
|
||||
%dl.dl-horizontal
|
||||
%dt Crop :
|
||||
%dd= link_to harvest.crop.name, harvest.crop
|
||||
%dt Plant part :
|
||||
%dd= link_to harvest.plant_part, harvest.plant_part
|
||||
%dt Quantity :
|
||||
%dd= display_quantity(harvest)
|
||||
%dt Harvest date :
|
||||
%dd= harvest.harvested_at
|
||||
.panel-footer
|
||||
%dt Description
|
||||
%dd.truncate
|
||||
= display_harvest_description(harvest)
|
||||
= if harvest.description.present?
|
||||
- link_to "Read more", harvest_path(harvest)
|
||||
.thumbnail
|
||||
.harvest-thumbnail
|
||||
- if harvest
|
||||
= link_to image_tag((harvest.default_photo ? harvest.default_photo.thumbnail_url : 'placeholder_150.png'),
|
||||
alt: harvest.crop.name, class: 'img'),
|
||||
harvest
|
||||
.harvestinfo
|
||||
.harvest-name
|
||||
= link_to harvest, harvest
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
- unless @harvests.empty?
|
||||
- @harvests.each do |harvest|
|
||||
.col-md-6
|
||||
= render partial: 'harvests/thumbnail', locals: { harvest: harvest }
|
||||
= render 'harvests/card', harvest: harvest
|
||||
|
||||
.pagination
|
||||
= page_entries_info @harvests
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
= render partial: "posts/summary", locals: { posts: posts, howmany: 6 }
|
||||
|
||||
- cache cache_key_for(Forum) do
|
||||
- forums = Forum.all
|
||||
- forums = Forum.all.order(:name)
|
||||
- if forums
|
||||
%ul.list-inline
|
||||
%li
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
%h2= t('.title')
|
||||
.row
|
||||
.col-md-8
|
||||
- Seed.includes(:owner, crop: :photos).interesting.first(6).each do |seed|
|
||||
- Seed.includes(:owner, crop: :photos).order(created_at: :desc).interesting.first(6).each do |seed|
|
||||
.col-md-3
|
||||
.thumbnail
|
||||
- cache cache_key_for(Crop, seed.id) do
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
%small
|
||||
%br/
|
||||
Recently planted:
|
||||
!= member.plantings.first(3).map { |p| link_to p.crop_name, p }.join(", ")
|
||||
!= member.plantings.order(created_at: :desc).first(3).map { |p| link_to p.crop_name, p }.join(", ")
|
||||
%p
|
||||
%small
|
||||
Joined
|
||||
@@ -24,4 +24,3 @@
|
||||
= [localize_plural(member.gardens, Garden),
|
||||
localize_plural(member.plantings, Planting),
|
||||
localize_plural(member.seeds, Seed)].join(", ")
|
||||
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
- content_for :title, "Photos"
|
||||
|
||||
- if @crop
|
||||
%h2= @crop.name
|
||||
|
||||
%p Most recent photos added to #{ENV['GROWSTUFF_SITE_NAME']}.
|
||||
|
||||
.pagination
|
||||
= page_entries_info @photos
|
||||
= will_paginate @photos
|
||||
|
||||
|
||||
.row
|
||||
- @photos.each do |p|
|
||||
.col-md-2.six-across
|
||||
@@ -19,5 +23,3 @@
|
||||
.pagination
|
||||
= page_entries_info @photos
|
||||
= will_paginate @photos
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
- content_for :title, "New Photo"
|
||||
|
||||
%h3
|
||||
Choose photo for
|
||||
= @item
|
||||
|
||||
- if @flickr_auth
|
||||
%p
|
||||
Connected to Flickr as
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
- if plant_part.crops.empty?
|
||||
No crops are harvested for this plant part (yet).
|
||||
- else
|
||||
!= plant_part.crops.map { |c| link_to(c, c) }.join(", ")
|
||||
- plant_part.crops.limit(100).each do |crop|
|
||||
= link_to(crop, crop_path(crop))
|
||||
%p
|
||||
= link_to "More detail", plant_part
|
||||
|
||||
@@ -18,6 +19,3 @@
|
||||
= link_to 'Edit', edit_plant_part_path(plant_part), class: 'btn btn-default btn-xs'
|
||||
- if can? :destroy, plant_part
|
||||
= link_to 'Delete', plant_part, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-default btn-xs'
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,16 +1,27 @@
|
||||
- if can?(:edit, planting) || can?(:destroy, planting)
|
||||
- if can? :edit, planting
|
||||
= link_to edit_planting_path(planting), class: 'btn btn-default btn-xs' do
|
||||
%span.glyphicon.glyphicon-pencil{ title: "Edit garden" }
|
||||
%span.glyphicon.glyphicon-pencil{ title: "Edit" }
|
||||
Edit
|
||||
- if can? :destroy, planting
|
||||
= link_to planting, method: :delete,
|
||||
data: { confirm: 'Are you sure?' },
|
||||
class: 'btn btn-default btn-xs' do
|
||||
data: { confirm: 'Are you sure?' }, class: 'btn btn-default btn-xs' do
|
||||
%span.glyphicon.glyphicon-trash{ title: "Delete" }
|
||||
Delete
|
||||
|
||||
- unless planting.finished
|
||||
= link_to "Mark as finished", planting_path(planting, planting: { finished: 1 }),
|
||||
method: :put, class: 'btn btn-default btn-xs append-date'
|
||||
- if can? :create, Harvest
|
||||
= link_to 'Harvest', new_planting_harvest_path(planting), class: 'btn btn-default btn-xs'
|
||||
= link_to planting_path(planting, planting: { finished: 1 }),
|
||||
method: :put, class: 'btn btn-default btn-xs append-date' do
|
||||
|
||||
%span.glyphicon.glyphicon-ok{ title: "Finished" }
|
||||
Mark as finished
|
||||
|
||||
- if can? :edit, planting
|
||||
= link_to new_planting_harvest_path(planting), class: 'btn btn-default btn-xs' do
|
||||
%span.glyphicon.glyphicon-leaf{ title: "Harvest" }
|
||||
Harvest
|
||||
|
||||
- if can?(:edit, planting) && can?(:create, Photo)
|
||||
= link_to new_photo_path(id: planting.id, type: 'planting'), class: 'btn btn-default btn-xs' do
|
||||
%span.glyphicon.glyphicon-camera{ title: "Add photo" }
|
||||
Add photo
|
||||
|
||||
@@ -33,10 +33,8 @@
|
||||
%dt Planted from:
|
||||
%dd= display_planted_from(planting)
|
||||
|
||||
%dt Mature in:
|
||||
%dd
|
||||
= display_days_before_maturity(planting)
|
||||
days
|
||||
%dt Finish expected:
|
||||
%dd= planting.finish_predicted_at if planting.finish_predicted_at.present?
|
||||
|
||||
%p= render 'plantings/progress', planting: planting, show_explanation: true
|
||||
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
- unless planting.harvests.empty?
|
||||
Harvests:
|
||||
%ul
|
||||
- planting.harvests.each do |harvest|
|
||||
%li
|
||||
= harvest.harvested_at ? harvest.harvested_at : "undated"
|
||||
= link_to harvest, harvest_path(harvest)
|
||||
= link_to "more harvests from this planting", planting_harvests_path(planting)
|
||||
- if planting.harvests.empty?
|
||||
%p no harvests yet
|
||||
- else
|
||||
.row
|
||||
- planting.harvests.order(created_at: :desc).includes(:crop).each do |harvest|
|
||||
.col-xs-6.col-md-2
|
||||
= render 'harvests/thumbnail', harvest: harvest
|
||||
- if can? :edit, planting
|
||||
.col-xs-6.col-md-2
|
||||
= link_to new_planting_harvest_path(planting), class: 'btn btn-primary' do
|
||||
%span.glyphicon.glyphicon-leaf{ title: "Harvest" }
|
||||
Harvest
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
- if !planting.planted?
|
||||
- if show_explanation == true
|
||||
Progress: 0% - not planted yet
|
||||
- if planting.crop.perennial
|
||||
%p Perennial
|
||||
- elsif !planting.planted?
|
||||
- if show_explanation
|
||||
%p Progress: 0% - not planted yet
|
||||
= render "plantings/progress_bar", status: "not planted", progress: 0
|
||||
|
||||
- elsif planting.finished?
|
||||
- if show_explanation == true
|
||||
Progress: 100%
|
||||
= render "plantings/progress_bar", status: 'finished', progress: 100
|
||||
|
||||
- elsif planting.days_before_maturity.nil?
|
||||
- elsif planting.finish_predicted_at.nil?
|
||||
- if show_explanation == true
|
||||
Progress: Not calculated, days before maturity unknown
|
||||
%p Progress: Not enough data
|
||||
= render "plantings/progress_bar", status: "unknown", progress: nil
|
||||
|
||||
- else
|
||||
- if show_explanation == true
|
||||
Progress: #{planting.percentage_grown}%
|
||||
= render "plantings/progress_bar", status: 'growing', progress: planting.percentage_grown
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
-# haml-lint:disable InlineStyles
|
||||
%div{ class: "progress-bar progress-bar-#{status}", role: "progressbar", style: "width: #{progress}%" }
|
||||
- if progress >= 30
|
||||
#{progress}%
|
||||
#{sprintf '%.0f', progress}%
|
||||
- if progress < 30
|
||||
#{progress}%
|
||||
#{sprintf '%.0f', progress}%
|
||||
-# haml-lint:enable InlineStyles
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
= tag("meta", property: "og:url", content: request.original_url)
|
||||
= tag("meta", property: "og:site_name", content: ENV['GROWSTUFF_SITE_NAME'])
|
||||
|
||||
%p= render 'plantings/actions', planting: @planting
|
||||
.row.planting
|
||||
.col-md-6
|
||||
%dl.dl-horizontal.planting-attributes
|
||||
@@ -28,13 +29,11 @@
|
||||
- unless @planting.owner.location.blank?
|
||||
(#{@planting.owner.location})
|
||||
%dt Quantity:
|
||||
%dd
|
||||
= display_planting_quantity(@planting)
|
||||
%dd= display_planting_quantity(@planting)
|
||||
|
||||
- unless @planting.planted_from.blank?
|
||||
%dt Planted from:
|
||||
%dd
|
||||
= display_planted_from(@planting)
|
||||
%dd= display_planted_from(@planting)
|
||||
|
||||
%dt Sun or shade?
|
||||
%dd
|
||||
@@ -42,16 +41,34 @@
|
||||
= image_tag("sunniness_#{sunniness}.png", size: "25x25", alt: sunniness, title: sunniness)
|
||||
= sunniness
|
||||
|
||||
%dt Days until maturity:
|
||||
%dd= display_days_before_maturity(@planting)
|
||||
- unless @planting.crop.perennial
|
||||
%dt Predicted finish:
|
||||
%dd
|
||||
- if @planting.finish_predicted_at.present?
|
||||
= @planting.finish_predicted_at
|
||||
- elsif @planting.planted_at.blank?
|
||||
%strong Set planted date to get predictions
|
||||
- if @planting.finished?
|
||||
%dt Finished:
|
||||
%dd= display_finished(@planting)
|
||||
- if @planting.crop.median_lifespan.present?
|
||||
%dt Expected Lifespan:
|
||||
%dd #{@planting.crop.median_lifespan} days
|
||||
- if @planting.lifespan.present?
|
||||
%dt Actual Lifespan:
|
||||
%dd #{@planting.lifespan} days
|
||||
- if @planting.days_to_first_harvest.present?
|
||||
%dt First Harvest:
|
||||
%dd #{@planting.days_to_first_harvest} days after planting
|
||||
- if @planting.days_to_last_harvest.present?
|
||||
%dt Last Harvest:
|
||||
%dd #{@planting.days_to_last_harvest} days after planting
|
||||
|
||||
%dt Finished:
|
||||
%dd= display_finished(@planting)
|
||||
|
||||
%p= render 'plantings/harvests', planting: @planting
|
||||
%h2 Progress
|
||||
%p= render 'plantings/progress', planting: @planting, show_explanation: true
|
||||
|
||||
= render 'plantings/actions', planting: @planting
|
||||
%h2 Harvests
|
||||
%p= render 'plantings/harvests', planting: @planting
|
||||
|
||||
.col-md-6
|
||||
= render partial: "crops/index_card", locals: { crop: @planting.crop }
|
||||
@@ -67,10 +84,10 @@
|
||||
#{ @planting.description != "" ? strip_tags(@planting.description) : "No description given." }
|
||||
|
||||
- if !@planting.photos.empty? || (can?(:edit, @planting) && can?(:create, Photo))
|
||||
%h2 Pictures
|
||||
%h2 Photos
|
||||
|
||||
.row
|
||||
- @planting.photos.each do |p|
|
||||
- @planting.photos.includes(:owner).each do |p|
|
||||
.col-md-2.six-across
|
||||
= render partial: 'photos/thumbnail', locals: { photo: p }
|
||||
- if can?(:create, Photo) && can?(:edit, @planting)
|
||||
|
||||
@@ -44,7 +44,7 @@ Growstuff::Application.configure do
|
||||
# config.action_view.raise_on_missing_translations = true
|
||||
|
||||
# Growstuff config
|
||||
config.action_mailer.default_url_options = { host: 'localhost:8080' }
|
||||
config.action_mailer.default_url_options = { host: 'localhost:3000' }
|
||||
|
||||
config.action_mailer.delivery_method = :letter_opener
|
||||
config.action_mailer.smtp_settings = {
|
||||
@@ -55,7 +55,7 @@ Growstuff::Application.configure do
|
||||
authentication: :login
|
||||
}
|
||||
|
||||
config.host = 'localhost:8080'
|
||||
config.host = 'localhost:3000'
|
||||
config.analytics_code = ''
|
||||
|
||||
# this config variable cannot be put in application.yml as it is needed
|
||||
|
||||
9
config/factory_bot.rb
Normal file
9
config/factory_bot.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
ActionDispatch::Callbacks.after do
|
||||
# Reload the factories
|
||||
return unless Rails.env.development? || Rails.env.test?
|
||||
|
||||
if FactoryBot.factories.present? # first init will load factories, this should only run on subsequent reloads
|
||||
FactoryBot.factories.clear
|
||||
FactoryBot.find_definitions
|
||||
end
|
||||
end
|
||||
@@ -1,9 +0,0 @@
|
||||
ActionDispatch::Callbacks.after do
|
||||
# Reload the factories
|
||||
return unless Rails.env.development? || Rails.env.test?
|
||||
|
||||
unless FactoryGirl.factories.blank? # first init will load factories, this should only run on subsequent reloads
|
||||
FactoryGirl.factories.clear
|
||||
FactoryGirl.find_definitions
|
||||
end
|
||||
end
|
||||
@@ -43,7 +43,7 @@ Devise.setup do |config|
|
||||
# Configure which authentication keys should have whitespace stripped.
|
||||
# These keys will have whitespace before and after removed upon creating or
|
||||
# modifying a user and when used to authenticate or find a user. Default is :email.
|
||||
config.strip_whitespace_keys = [:email, :login_name]
|
||||
config.strip_whitespace_keys = %i(email login_name)
|
||||
|
||||
# Tell if authentication through request.params is enabled. True by default.
|
||||
# It can be set to an array that will enable params authentication only for the
|
||||
|
||||
@@ -11,6 +11,4 @@ Geocoder.configure(
|
||||
)
|
||||
# This configuration takes precedence over environment/test.rb
|
||||
# Reported as https://github.com/alexreisner/geocoder/issues/509
|
||||
if Geocoder.config.lookup != :test
|
||||
Geocoder.configure(lookup: :nominatim)
|
||||
end
|
||||
Geocoder.configure(lookup: :nominatim) if Geocoder.config.lookup != :test
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user