ish_lib 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -3
  3. data/Gemfile.lock +5 -3
  4. data/Rakefile +3 -0
  5. data/VERSION +1 -1
  6. data/ish_lib.gemspec +50 -7
  7. data/lib/app/models/ability.rb +151 -0
  8. data/lib/app/models/admin_user.rb +113 -0
  9. data/lib/app/models/app_model2.rb +33 -0
  10. data/lib/app/models/auth_token.rb +17 -0
  11. data/lib/app/models/aux_model.rb +22 -0
  12. data/lib/app/models/cities_user.rb +17 -0
  13. data/lib/app/models/city.rb +117 -0
  14. data/lib/app/models/country.rb +13 -0
  15. data/lib/app/models/day.rb +21 -0
  16. data/lib/app/models/decoded_auth_token.rb +6 -0
  17. data/lib/app/models/event.rb +21 -0
  18. data/lib/app/models/feature.rb +38 -0
  19. data/lib/app/models/gallery.rb +57 -0
  20. data/lib/app/models/manager.rb +10 -0
  21. data/lib/app/models/manager_city.rb +4 -0
  22. data/lib/app/models/manager_feature.rb +4 -0
  23. data/lib/app/models/manager_gallery.rb +3 -0
  24. data/lib/app/models/manager_newsitem.rb +5 -0
  25. data/lib/app/models/manager_photo.rb +3 -0
  26. data/lib/app/models/manager_report.rb +4 -0
  27. data/lib/app/models/manager_site.rb +4 -0
  28. data/lib/app/models/manager_tag.rb +6 -0
  29. data/lib/app/models/manager_user.rb +3 -0
  30. data/lib/app/models/manager_venue.rb +4 -0
  31. data/lib/app/models/message.rb +14 -0
  32. data/lib/app/models/newsitem.rb +50 -0
  33. data/lib/app/models/nodeitem.rb +18 -0
  34. data/lib/app/models/photo.rb +68 -0
  35. data/lib/app/models/rate_me.rb +13 -0
  36. data/lib/app/models/report.rb +144 -0
  37. data/lib/app/models/review.rb +4 -0
  38. data/lib/app/models/site.rb +85 -0
  39. data/lib/app/models/tag.rb +78 -0
  40. data/lib/app/models/user.rb +122 -0
  41. data/lib/app/models/user_profile.rb +20 -0
  42. data/lib/app/models/venue.rb +69 -0
  43. data/lib/app/models/video.rb +48 -0
  44. data/lib/app/models/welcome.rb +6 -0
  45. data/lib/app/models/wikitravel_page.rb +19 -0
  46. data/lib/ish_lib.rb +19 -0
  47. data/lib/string.rb +15 -0
  48. metadata +59 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c37dbe7bc8ca7aa98f7d32ca88307100065a65f8
4
- data.tar.gz: b3c1aa19667a22e5aa3aaa61da876f2c716406d0
3
+ metadata.gz: 71c39f269cb3d9ddca2bf7ee91842f8c6efdc68f
4
+ data.tar.gz: ad304992337961d8821100af6b1053d272900a95
5
5
  SHA512:
6
- metadata.gz: 559160236cbc0646145d7a260b93284e82b5cf355790c8a11d727eb7ccf17a2d7710a36ce6c27b973fb9e28e8c3d8141519dd2bc34e007ed8a918a51be3eb9e7
7
- data.tar.gz: f392a0b06a6f508931394e9f9f8538e34b1839b66b26ec06c09b4cc39399d2aa08c1c7fca4456cd86d67d113b01af496d85c4a53c36ce63432d3af984c163ad1
6
+ metadata.gz: d9cf2599c06e806f49f5752f350d8032e2ab99298fc7be5839e4e0590419247d7bae2e55c63a0755334e25004e78354d78ff3dfcaaf6072b362eb4ddcbe102ee
7
+ data.tar.gz: a078f21d9d61df055538d2b8b4bc89100999b0acf0ededd6b5ae9bb50ff9579d38434e17d21227072953e8d02561f04d46231f522ad43fcbbb32d077b2450a37
data/Gemfile CHANGED
@@ -1,14 +1,13 @@
1
1
  source "https://rubygems.org"
2
+
2
3
  # Add dependencies required to use your gem here.
3
4
  # Example:
4
5
  # gem "activesupport", ">= 2.3.5"
5
6
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
7
  group :development do
9
8
  gem "shoulda", ">= 0"
10
9
  gem "rdoc", "~> 3.12"
11
10
  gem "bundler", "~> 1.0"
12
- gem "jeweler", "~> 2.0.1"
11
+ gem "jeweler", "~> 2.1.1"
13
12
  gem "simplecov", ">= 0"
14
13
  end
data/Gemfile.lock CHANGED
@@ -25,7 +25,7 @@ GEM
25
25
  hashie (3.4.4)
26
26
  highline (1.7.8)
27
27
  i18n (0.7.0)
28
- jeweler (2.0.1)
28
+ jeweler (2.1.1)
29
29
  builder
30
30
  bundler (>= 1.0)
31
31
  git (>= 1.2.5)
@@ -34,6 +34,7 @@ GEM
34
34
  nokogiri (>= 1.5.10)
35
35
  rake
36
36
  rdoc
37
+ semver
37
38
  json (1.8.3)
38
39
  jwt (1.5.1)
39
40
  mini_portile2 (2.0.0)
@@ -53,6 +54,7 @@ GEM
53
54
  rake (11.1.2)
54
55
  rdoc (3.12.2)
55
56
  json (~> 1.4)
57
+ semver (1.0.1)
56
58
  shoulda (3.5.0)
57
59
  shoulda-context (~> 1.0, >= 1.0.1)
58
60
  shoulda-matchers (>= 1.4.1, < 3.0)
@@ -73,10 +75,10 @@ PLATFORMS
73
75
 
74
76
  DEPENDENCIES
75
77
  bundler (~> 1.0)
76
- jeweler (~> 2.0.1)
78
+ jeweler (~> 2.1.1)
77
79
  rdoc (~> 3.12)
78
80
  shoulda
79
81
  simplecov
80
82
 
81
83
  BUNDLED WITH
82
- 1.11.2
84
+ 1.12.1
data/Rakefile CHANGED
@@ -21,7 +21,10 @@ Jeweler::Tasks.new do |gem|
21
21
  gem.description = %Q{models and assets for piousbox.com}
22
22
  gem.email = "piousbox@gmail.com"
23
23
  gem.authors = ["Victor Piousbox"]
24
+
24
25
  # dependencies defined in Gemfile
26
+ gem.add_dependency 'kaminari'
27
+
25
28
  end
26
29
  Jeweler::RubygemsDotOrgTasks.new
27
30
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
data/ish_lib.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: ish_lib 0.0.5 ruby lib
5
+ # stub: ish_lib 0.0.6 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "ish_lib"
9
- s.version = "0.0.5"
9
+ s.version = "0.0.6"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Victor Piousbox"]
14
- s.date = "2016-05-01"
14
+ s.date = "2016-05-03"
15
15
  s.description = "models and assets for piousbox.com"
16
16
  s.email = "piousbox@gmail.com"
17
17
  s.extra_rdoc_files = [
@@ -27,13 +27,53 @@ Gem::Specification.new do |s|
27
27
  "Rakefile",
28
28
  "VERSION",
29
29
  "ish_lib.gemspec",
30
+ "lib/app/models/ability.rb",
31
+ "lib/app/models/admin_user.rb",
32
+ "lib/app/models/app_model2.rb",
33
+ "lib/app/models/auth_token.rb",
34
+ "lib/app/models/aux_model.rb",
35
+ "lib/app/models/cities_user.rb",
36
+ "lib/app/models/city.rb",
37
+ "lib/app/models/country.rb",
38
+ "lib/app/models/day.rb",
39
+ "lib/app/models/decoded_auth_token.rb",
40
+ "lib/app/models/event.rb",
41
+ "lib/app/models/feature.rb",
42
+ "lib/app/models/gallery.rb",
43
+ "lib/app/models/manager.rb",
44
+ "lib/app/models/manager_city.rb",
45
+ "lib/app/models/manager_feature.rb",
46
+ "lib/app/models/manager_gallery.rb",
47
+ "lib/app/models/manager_newsitem.rb",
48
+ "lib/app/models/manager_photo.rb",
49
+ "lib/app/models/manager_report.rb",
50
+ "lib/app/models/manager_site.rb",
51
+ "lib/app/models/manager_tag.rb",
52
+ "lib/app/models/manager_user.rb",
53
+ "lib/app/models/manager_venue.rb",
54
+ "lib/app/models/message.rb",
55
+ "lib/app/models/newsitem.rb",
56
+ "lib/app/models/nodeitem.rb",
57
+ "lib/app/models/photo.rb",
58
+ "lib/app/models/rate_me.rb",
59
+ "lib/app/models/report.rb",
60
+ "lib/app/models/review.rb",
61
+ "lib/app/models/site.rb",
62
+ "lib/app/models/tag.rb",
63
+ "lib/app/models/user.rb",
64
+ "lib/app/models/user_profile.rb",
65
+ "lib/app/models/venue.rb",
66
+ "lib/app/models/video.rb",
67
+ "lib/app/models/welcome.rb",
68
+ "lib/app/models/wikitravel_page.rb",
30
69
  "lib/ish_lib.rb",
70
+ "lib/string.rb",
31
71
  "test/helper.rb",
32
72
  "test/test_ish_lib.rb"
33
73
  ]
34
74
  s.homepage = "http://github.com/piousbox/ish_lib"
35
75
  s.licenses = ["MIT"]
36
- s.rubygems_version = "2.2.2"
76
+ s.rubygems_version = "2.5.1"
37
77
  s.summary = "ish_lib, powering piousbox.com"
38
78
 
39
79
  if s.respond_to? :specification_version then
@@ -43,21 +83,24 @@ Gem::Specification.new do |s|
43
83
  s.add_development_dependency(%q<shoulda>, [">= 0"])
44
84
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
45
85
  s.add_development_dependency(%q<bundler>, ["~> 1.0"])
46
- s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
86
+ s.add_development_dependency(%q<jeweler>, ["~> 2.1.1"])
47
87
  s.add_development_dependency(%q<simplecov>, [">= 0"])
88
+ s.add_runtime_dependency(%q<kaminari>, [">= 0"])
48
89
  else
49
90
  s.add_dependency(%q<shoulda>, [">= 0"])
50
91
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
51
92
  s.add_dependency(%q<bundler>, ["~> 1.0"])
52
- s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
93
+ s.add_dependency(%q<jeweler>, ["~> 2.1.1"])
53
94
  s.add_dependency(%q<simplecov>, [">= 0"])
95
+ s.add_dependency(%q<kaminari>, [">= 0"])
54
96
  end
55
97
  else
56
98
  s.add_dependency(%q<shoulda>, [">= 0"])
57
99
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
58
100
  s.add_dependency(%q<bundler>, ["~> 1.0"])
59
- s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
101
+ s.add_dependency(%q<jeweler>, ["~> 2.1.1"])
60
102
  s.add_dependency(%q<simplecov>, [">= 0"])
103
+ s.add_dependency(%q<kaminari>, [">= 0"])
61
104
  end
62
105
  end
63
106
 
@@ -0,0 +1,151 @@
1
+ class Ability
2
+
3
+ include CanCan::Ability
4
+ def initialize(user)
5
+
6
+ #
7
+ # signed in user
8
+ #
9
+ unless user.blank?
10
+
11
+ can [ :create, :new ], Gallery
12
+ can [ :edit, :update, :destroy_photo, :show, :show_long ], Gallery do |g|
13
+ g.user == user
14
+ end
15
+
16
+ can [ :new ], Message
17
+
18
+ can [ :upload, :driver, :set_profile_photo, :new_profile_photo ], Photo
19
+ can [ :move, :edit, :update, :show ], Photo do |photo|
20
+ photo.user == user
21
+ end
22
+ can [ :show ], Photo do |photo|
23
+ photo.viewer_ids.include? user.id || user == photo.user
24
+ end
25
+ can [ :destroy ], Photo do |photo|
26
+ if photo.user == user
27
+ if photo.gallery.blank?
28
+ true
29
+ elsif photo.gallery.is_anonymous
30
+ false
31
+ else
32
+ true
33
+ end
34
+ else
35
+ false
36
+ end
37
+ end
38
+
39
+ can [ :new, :create, :search, :index, :my_index ], Report
40
+ can [ :edit, :update, :show, :delete ], Report do |r|
41
+ r.user == user
42
+ end
43
+
44
+ can [ :newsitems_new, :newsitems_create ], Site
45
+
46
+ can [ :organizer, :photos, :new_profile, :create_profile, :edit_profile, :update_profile ], User
47
+ can [ :edit, :update, :update_profile ], User do |uu|
48
+ uu == user
49
+ end
50
+
51
+ can [ :new ], Venue
52
+
53
+ can [ :new, :create ], Video
54
+
55
+ # manager, group_id 1
56
+ #
57
+ if user[:group_id] <= 2
58
+ can [ :manage ], CitiesUser
59
+ can [ :manage ], City
60
+ can [ :manage ], Country
61
+ can [ :manage ], Day
62
+ can [ :manage ], Event
63
+ can [ :manage ], Feature
64
+ can [ :manage ], Gallery
65
+ can [ :manage ], Newsitem
66
+ can [ :manage ], Nodeitem
67
+ can [ :manage ], Photo
68
+ can [ :manage ], Report
69
+ can [ :manage ], Site
70
+ can [ :manage ], Tag
71
+ can [ :manage ], User
72
+ can [ :manage ], UserProfile
73
+ can [ :manage ], Venue
74
+ can [ :manage ], Video
75
+ can [ :manage ], Welcome
76
+ can [ :manage ], Manager
77
+ can [ :manage ], ManagerCity
78
+ can [ :manage ], ManagerFeature
79
+ can [ :manage ], ManagerGallery
80
+ can [ :manage ], ManagerNewsitem
81
+ can [ :manage ], ManagerPhoto
82
+ can [ :manage ], ManagerReport
83
+ can [ :manage ], ManagerSite
84
+ can [ :manage ], ManagerTag
85
+ can [ :manage ], ManagerUser
86
+ can [ :manage ], ManagerVenue
87
+ end
88
+
89
+ #
90
+ # if admin
91
+ #
92
+ can :manage, :all do
93
+ user.group_id.to_s == "1"
94
+ end
95
+
96
+ end
97
+ user ||= User.new
98
+
99
+ ###
100
+ ### applies to all users
101
+ ###
102
+
103
+ can [ :index, :show ], City
104
+
105
+ can [ :render_partial ], AuxModel
106
+
107
+ can [ :new ], Event
108
+
109
+ can [ :index, :search, :not_found, :set_show_style, :new ], Gallery
110
+ can [ :show ], Gallery do |g|
111
+ g.is_public && !g.is_trash
112
+ end
113
+
114
+ can [ :error500, :search ], Manager
115
+
116
+ # has to be outside user auth b/c the uploading component is ajax.
117
+ can [ :new, :create, :index, :do_upload, :not_found ], Photo
118
+ can [ :show ], Photo do |photo|
119
+ photo.is_public && !photo.is_trash
120
+ end
121
+
122
+ can [ :search, :not_found, :new, :index ], Report
123
+ can [ :show ], Report do |r|
124
+ r.is_public && !r.is_trash
125
+ end
126
+
127
+ can [ :new ], Review
128
+
129
+ can [ :show, :newsitems, :features, :newsitems, :create_missing, :register ], Site do |s|
130
+ !s.is_private
131
+ end
132
+
133
+ can [ :index ], Tag
134
+ can [ :show ], Tag do |t|
135
+ true
136
+ end
137
+
138
+ can [ :resume, :reports, :galleries, :report, :gallery,
139
+ :sign_in, :sign_up, :sign_out, :logout,
140
+ :index, :show, :not_found, :github, :about ], User
141
+ can [ :report ], User do |r|
142
+ r.is_public && !r.is_trash
143
+ end
144
+
145
+ can [ :new, :index, :show, :not_found ], Venue
146
+
147
+ can [ :index, :show, :view ], Video
148
+
149
+ end
150
+ end
151
+
@@ -0,0 +1,113 @@
1
+
2
+ class AdminUser
3
+
4
+ include Mongoid::Document
5
+ # Include default devise modules. Others available are:
6
+ # :token_authenticatable, :confirmable,
7
+ # :lockable, :timeoutable and :omniauthable
8
+ devise :database_authenticatable,
9
+ :recoverable, :rememberable, :trackable, :validatable
10
+
11
+ # Include default devise modules. Others available are:
12
+ # :token_authenticatable, :confirmable,
13
+ # :lockable, :timeoutable and :omniauthable
14
+ devise :database_authenticatable,
15
+ :recoverable, :rememberable, :trackable, :validatable
16
+
17
+ # Include default devise modules. Others available are:
18
+ # :token_authenticatable, :confirmable,
19
+ # :lockable, :timeoutable and :omniauthable
20
+ devise :database_authenticatable,
21
+ :recoverable, :rememberable, :trackable, :validatable
22
+
23
+ # Include default devise modules. Others available are:
24
+ # :token_authenticatable, :confirmable,
25
+ # :lockable, :timeoutable and :omniauthable
26
+ devise :database_authenticatable,
27
+ :recoverable, :rememberable, :trackable, :validatable
28
+
29
+ ## Database authenticatable
30
+ field :email, :type => String, :default => ""
31
+ field :encrypted_password, :type => String, :default => ""
32
+
33
+ ## Recoverable
34
+ field :reset_password_token, :type => String
35
+ field :reset_password_sent_at, :type => Time
36
+
37
+ ## Rememberable
38
+ field :remember_created_at, :type => Time
39
+
40
+ ## Trackable
41
+ field :sign_in_count, :type => Integer, :default => 0
42
+ field :current_sign_in_at, :type => Time
43
+ field :last_sign_in_at, :type => Time
44
+ field :current_sign_in_ip, :type => String
45
+ field :last_sign_in_ip, :type => String
46
+
47
+ ## Confirmable
48
+ # field :confirmation_token, :type => String
49
+ # field :confirmed_at, :type => Time
50
+ # field :confirmation_sent_at, :type => Time
51
+ # field :unconfirmed_email, :type => String # Only if using reconfirmable
52
+
53
+ ## Lockable
54
+ # field :failed_attempts, :type => Integer, :default => 0 # Only if lock strategy is :failed_attempts
55
+ # field :unlock_token, :type => String # Only if unlock strategy is :email or :both
56
+ # field :locked_at, :type => Time
57
+
58
+ ## Token authenticatable
59
+ # field :authentication_token, :type => String
60
+
61
+ # Include default devise modules. Others available are:
62
+ # :token_authenticatable, :confirmable,
63
+ # :lockable, :timeoutable and :omniauthable
64
+ devise :database_authenticatable,
65
+ :recoverable, :rememberable, :trackable, :validatable
66
+
67
+ # Include default devise modules. Others available are:
68
+ # :token_authenticatable, :confirmable,
69
+ # :lockable, :timeoutable and :omniauthable
70
+ devise :database_authenticatable,
71
+ :recoverable, :rememberable, :trackable, :validatable
72
+
73
+ # Include default devise modules. Others available are:
74
+ # :token_authenticatable, :confirmable,
75
+ # :lockable, :timeoutable and :omniauthable
76
+ devise :database_authenticatable,
77
+ :recoverable, :rememberable, :trackable, :validatable
78
+
79
+ ## Database authenticatable
80
+ field :email, :type => String, :default => ""
81
+ field :encrypted_password, :type => String, :default => ""
82
+
83
+ validates_presence_of :email
84
+ validates_presence_of :encrypted_password
85
+
86
+ ## Recoverable
87
+ field :reset_password_token, :type => String
88
+ field :reset_password_sent_at, :type => Time
89
+
90
+ ## Rememberable
91
+ field :remember_created_at, :type => Time
92
+
93
+ ## Trackable
94
+ field :sign_in_count, :type => Integer, :default => 0
95
+ field :current_sign_in_at, :type => Time
96
+ field :last_sign_in_at, :type => Time
97
+ field :current_sign_in_ip, :type => String
98
+ field :last_sign_in_ip, :type => String
99
+
100
+ ## Confirmable
101
+ # field :confirmation_token, :type => String
102
+ # field :confirmed_at, :type => Time
103
+ # field :confirmation_sent_at, :type => Time
104
+ # field :unconfirmed_email, :type => String # Only if using reconfirmable
105
+
106
+ ## Lockable
107
+ # field :failed_attempts, :type => Integer, :default => 0 # Only if lock strategy is :failed_attempts
108
+ # field :unlock_token, :type => String # Only if unlock strategy is :email or :both
109
+ # field :locked_at, :type => Time
110
+
111
+ ## Token authenticatable
112
+ # field :authentication_token, :type => String
113
+ end
@@ -0,0 +1,33 @@
1
+ class AppModel2
2
+ include Mongoid::Document
3
+ include Mongoid::Timestamps
4
+
5
+ field :is_feature, :type => Boolean, :default => false
6
+ field :is_public, :type => Boolean, :default => true
7
+ field :is_done, :type => Boolean, :default => false
8
+ field :is_trash, :type => Boolean, :default => false
9
+ field :is_anonymous, :type => Boolean, :default => false
10
+
11
+ scope :fresh, ->{ where({ :is_trash => false }) }
12
+ scope :trash, ->{ where({ :is_trash => true }) }
13
+ scope :public, ->{ where({ :is_public => true }) }
14
+ scope :done, ->{ where({ :is_done => true }) }
15
+
16
+ default_scope ->{ where({ :is_public => true, :is_trash => false }).order_by({ :created_at => :desc }) }
17
+
18
+ field :x, :type => Float
19
+ field :y, :type => Float
20
+
21
+ def self.list conditions = { :is_trash => false }
22
+ out = self.where( conditions).order_by( :name => :asc )
23
+ [['', nil]] + out.map { |item| [ item.name, item.id ] }
24
+ end
25
+
26
+ private
27
+
28
+ def puts! arg, label=""
29
+ puts "+++ +++ #{label}"
30
+ puts arg.inspect
31
+ end
32
+
33
+ end
@@ -0,0 +1,17 @@
1
+
2
+ class AuthToken
3
+
4
+ def self.encode(payload, exp=24.hours.from_now)
5
+ payload[:exp] = exp.to_i
6
+ JWT.encode(payload, Rails.application.config.secret_key_base)
7
+ end
8
+
9
+ def self.decode(token)
10
+ payload = JWT.decode(token, Rails.application.config.secret_key_base)[0]
11
+ DecodedAuthToken.new(payload)
12
+ rescue
13
+ nil
14
+ end
15
+
16
+ end
17
+
@@ -0,0 +1,22 @@
1
+
2
+ module AuxModel
3
+
4
+ def add_newsitem item
5
+ n = Newsitem.new
6
+ case item.class.name
7
+ when 'Video'
8
+ n.video_id = item.id
9
+ when 'Photo'
10
+ raise 'Not Implemented'
11
+ when 'Report'
12
+ raise 'Not Implemented'
13
+ when 'Gallery'
14
+ raise 'Not Implmented'
15
+ else
16
+ raise 'Not Implemented'
17
+ end
18
+ self.newsitems << n
19
+ self.save
20
+ end
21
+
22
+ end
@@ -0,0 +1,17 @@
1
+
2
+ class CitiesUser
3
+
4
+ include Mongoid::Document
5
+ include Mongoid::Timestamps
6
+
7
+ field :date, :type => Time
8
+ field :name, :type => String
9
+ field :descr, :type => String
10
+
11
+ belongs_to :city
12
+ belongs_to :user
13
+
14
+ has_many :reports
15
+ has_many :galleries
16
+
17
+ end
@@ -0,0 +1,117 @@
1
+
2
+ class City
3
+
4
+ include Mongoid::Document
5
+ include Mongoid::Timestamps
6
+
7
+ # this does not have to be validated because I can autogenerate this value, yes?
8
+ field :name, :type => String
9
+
10
+ field :cityname, :type => String
11
+ validates :cityname, :uniqueness => true, :allow_nil => false, :presence => true
12
+
13
+ field :name_en, :type => String, :default => ''
14
+ validates :name_en, :uniqueness => true, :allow_nil => false, :presence => true
15
+
16
+ field :name_ru, :type => String, :default => ''
17
+ validates :name_ru, :uniqueness => true, :allow_nil => false, :presence => true
18
+
19
+ field :name_pt, :type => String, :default => ''
20
+ validates :name_pt, :uniqueness => true, :allow_nil => false, :presence => true
21
+
22
+ field :is_feature, :type => Boolean, :default => false
23
+
24
+ field :x, :type => Float
25
+ field :y, :type => Float
26
+
27
+ belongs_to :country
28
+
29
+ has_many :events
30
+ has_many :galleries
31
+ has_many :photos
32
+ has_many :reports
33
+ has_many :venues
34
+ has_many :videos
35
+
36
+ has_one :profile_photo, :class_name => 'Photo', :inverse_of => :profile_city
37
+ has_one :guide, :class_name => 'User', :inverse_of => :guide_city
38
+ has_many :current_users, :class_name => 'User', :inverse_of => :current_city
39
+
40
+ embeds_many :newsitems, cascade_callbacks: true
41
+ accepts_nested_attributes_for :newsitems
42
+ # @TODO @deprecated, I wish I don't use it.
43
+ field :n_newsitems, :type => Integer, :default => 16
44
+
45
+ embeds_many :features
46
+ # @TODO @deprecated, I wish I don't use it.
47
+ field :n_features, :type => Integer, :default => 4
48
+
49
+ field :calendar_frame, :type => String
50
+
51
+ default_scope ->{ order_by({ :name => :asc }) }
52
+
53
+ def self.feature
54
+ where( :is_feature => true )
55
+ end
56
+
57
+ def self.non_feature
58
+ where( :is_feature => false )
59
+ end
60
+
61
+ def self.list
62
+ out = self.order_by( :name => :asc )
63
+ # no_city = City.where( :cityname => 'no_city' ).first || City.create( :cityname => 'no_city', :name => 'No City' )
64
+ [['', nil]] + out.map { |item| [ item.name, item.id ] }
65
+ end
66
+
67
+ def self.list_citynames lang = 'en'
68
+ out = self.order_by( :name => :asc )
69
+ [['', nil]] + out.map { |item| [ item['name_'+lang], item.cityname ] }
70
+ end
71
+
72
+ def self.clear
73
+ if Rails.env.test?
74
+ City.all.each { |r| r.remove }
75
+ end
76
+ end
77
+
78
+ def self.n_features
79
+ 4
80
+ end
81
+
82
+ def j_reports args = {}
83
+ out = []
84
+ self.reports.each do |r| # .page( params[:reports_page]
85
+ rr = r.clone
86
+ # rr[:photo_url] = r.photo.photo.url( :mini ) unless r.photo.blank?
87
+ # rr[:photo_url] ||= '/assets/missing.png'
88
+ rr[:username] = r.user.username
89
+ rr.created_at = r.created_at # pretty_date( r.created_at )
90
+ rr[:tag_name] = r.tag.name unless r.tag.blank?
91
+ rr[:tag_name] ||= ''
92
+ out << rr
93
+ end
94
+ return out
95
+ end
96
+
97
+ def self.for_homepage
98
+ cities = City.all.order_by( :name => :asc )
99
+ cities = cities.delete_if do |c|
100
+ ( false == c.is_feature ) && ( 0 == c.galleries.length ) && ( 0 == c.reports.length )
101
+ end
102
+ return cities
103
+ end
104
+
105
+ def self.feature
106
+ City.where( :is_feature => true )
107
+ end
108
+
109
+ def add_newsitem doc
110
+ # puts! self.newsitems, "city newsitems are"
111
+ if 'Video' == doc.class.name
112
+ self.newsitems << Newsitem.new({ :descr => '', :username => '', :video => doc })
113
+ end
114
+ end
115
+
116
+ end
117
+
@@ -0,0 +1,13 @@
1
+
2
+
3
+ class Country
4
+
5
+ include Mongoid::Document
6
+ include Mongoid::Timestamps
7
+
8
+ field :name, :type => String
9
+ field :countryname, :type => String
10
+
11
+ has_many :cities
12
+
13
+ end