ish_lib_engine 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +34 -0
  5. data/app/assets/javascripts/ish_lib_engine/application.js +13 -0
  6. data/app/assets/javascripts/ish_lib_engine/articles.js +2 -0
  7. data/app/assets/stylesheets/ish_lib_engine/application.css +15 -0
  8. data/app/assets/stylesheets/ish_lib_engine/articles.css +4 -0
  9. data/app/assets/stylesheets/scaffold.css +56 -0
  10. data/app/controllers/ish_lib_engine/application_controller.rb +4 -0
  11. data/app/controllers/ish_lib_engine/articles_controller.rb +62 -0
  12. data/app/controllers/ish_lib_engine/manager/cities_controller.rb +95 -0
  13. data/app/controllers/ish_lib_engine/manager/cities_controller.rb~ +95 -0
  14. data/app/controllers/ish_lib_engine/manager/features_controller.rb +122 -0
  15. data/app/controllers/ish_lib_engine/manager/features_controller.rb~ +122 -0
  16. data/app/controllers/ish_lib_engine/manager/galleries_controller.rb +78 -0
  17. data/app/controllers/ish_lib_engine/manager/galleries_controller.rb~ +78 -0
  18. data/app/controllers/ish_lib_engine/manager/manager_controller.rb +31 -0
  19. data/app/controllers/ish_lib_engine/manager/manager_controller.rb~ +31 -0
  20. data/app/controllers/ish_lib_engine/manager/newsitems_controller.rb +47 -0
  21. data/app/controllers/ish_lib_engine/manager/newsitems_controller.rb~ +47 -0
  22. data/app/controllers/ish_lib_engine/manager/photos_controller.rb +20 -0
  23. data/app/controllers/ish_lib_engine/manager/photos_controller.rb~ +20 -0
  24. data/app/controllers/ish_lib_engine/manager/reports_controller.rb +62 -0
  25. data/app/controllers/ish_lib_engine/manager/reports_controller.rb~ +62 -0
  26. data/app/controllers/ish_lib_engine/manager/sites_controller.rb +72 -0
  27. data/app/controllers/ish_lib_engine/manager/sites_controller.rb~ +72 -0
  28. data/app/controllers/ish_lib_engine/manager/tags_controller.rb +54 -0
  29. data/app/controllers/ish_lib_engine/manager/tags_controller.rb~ +54 -0
  30. data/app/controllers/ish_lib_engine/manager/users_controller.rb +13 -0
  31. data/app/controllers/ish_lib_engine/manager/users_controller.rb~ +13 -0
  32. data/app/controllers/ish_lib_engine/manager/welcome_controller.rb +8 -0
  33. data/app/controllers/ish_lib_engine/manager/welcome_controller.rb~ +9 -0
  34. data/app/helpers/ish_lib_engine/application_helper.rb +4 -0
  35. data/app/helpers/ish_lib_engine/articles_helper.rb +4 -0
  36. data/app/models/ability.rb +152 -0
  37. data/app/models/ability.rb~ +151 -0
  38. data/app/models/admin_user.rb +113 -0
  39. data/app/models/app_model2.rb +33 -0
  40. data/app/models/auth_token.rb +17 -0
  41. data/app/models/aux_model.rb +22 -0
  42. data/app/models/cities_user.rb +17 -0
  43. data/app/models/city.rb +117 -0
  44. data/app/models/country.rb +13 -0
  45. data/app/models/day.rb +21 -0
  46. data/app/models/decoded_auth_token.rb +6 -0
  47. data/app/models/event.rb +21 -0
  48. data/app/models/feature.rb +38 -0
  49. data/app/models/gallery.rb +59 -0
  50. data/app/models/ish_lib_engine/article.rb +4 -0
  51. data/app/models/ish_lib_engine/comment.rb +4 -0
  52. data/app/models/manager.rb +10 -0
  53. data/app/models/manager_city.rb +4 -0
  54. data/app/models/manager_feature.rb +4 -0
  55. data/app/models/manager_gallery.rb +3 -0
  56. data/app/models/manager_newsitem.rb +5 -0
  57. data/app/models/manager_photo.rb +3 -0
  58. data/app/models/manager_report.rb +4 -0
  59. data/app/models/manager_site.rb +4 -0
  60. data/app/models/manager_tag.rb +6 -0
  61. data/app/models/manager_user.rb +3 -0
  62. data/app/models/manager_venue.rb +4 -0
  63. data/app/models/message.rb +14 -0
  64. data/app/models/newsitem.rb +50 -0
  65. data/app/models/nodeitem.rb +18 -0
  66. data/app/models/photo.rb +68 -0
  67. data/app/models/rate_me.rb +13 -0
  68. data/app/models/report.rb +144 -0
  69. data/app/models/review.rb +4 -0
  70. data/app/models/site.rb +83 -0
  71. data/app/models/tag.rb +78 -0
  72. data/app/models/user.rb +122 -0
  73. data/app/models/user_profile.rb +20 -0
  74. data/app/models/venue.rb +69 -0
  75. data/app/models/video.rb +48 -0
  76. data/app/models/welcome.rb +6 -0
  77. data/app/models/wikitravel_page.rb +19 -0
  78. data/app/views/application/_flash_messages.haml +24 -0
  79. data/app/views/application/_flash_messages.haml~ +24 -0
  80. data/app/views/ish_lib_engine/articles/_form.html.erb +25 -0
  81. data/app/views/ish_lib_engine/articles/edit.html.erb +6 -0
  82. data/app/views/ish_lib_engine/articles/index.html.erb +29 -0
  83. data/app/views/ish_lib_engine/articles/new.html.erb +5 -0
  84. data/app/views/ish_lib_engine/articles/show.html.erb +14 -0
  85. data/app/views/layouts/ish_lib_engine/application.html.erb +14 -0
  86. data/config/routes.rb +3 -0
  87. data/db/migrate/20160501041837_create_ish_lib_engine_articles.rb +10 -0
  88. data/db/migrate/20160501041940_create_ish_lib_engine_comments.rb +10 -0
  89. data/lib/addressbookitems_tasks.rb +33 -0
  90. data/lib/cities_tasks.rb +143 -0
  91. data/lib/core_extensions.rb +21 -0
  92. data/lib/features_tasks.rb +17 -0
  93. data/lib/float.rb +14 -0
  94. data/lib/galleries_tasks.rb +91 -0
  95. data/lib/ish_lib_engine.rb +4 -0
  96. data/lib/ish_lib_engine/engine.rb +5 -0
  97. data/lib/ish_lib_engine/version.rb +3 -0
  98. data/lib/reports_tasks.rb +53 -0
  99. data/lib/sitemaps_tasks.rb +108 -0
  100. data/lib/sites_tasks.rb +31 -0
  101. data/lib/string.rb +15 -0
  102. data/lib/tags_tasks.rb +104 -0
  103. data/lib/tasks/cities.rake +29 -0
  104. data/lib/tasks/galleries.rake +19 -0
  105. data/lib/tasks/ish_lib_engine_tasks.rake +4 -0
  106. data/lib/tasks/reports.rake +37 -0
  107. data/lib/tasks/resque.rake +8 -0
  108. data/lib/tasks/sitemaps.rake +12 -0
  109. data/lib/tasks/sites.rake +12 -0
  110. data/lib/tasks/tags.rake +17 -0
  111. data/lib/tasks/users.rake +14 -0
  112. data/lib/tasks/venues.rake +13 -0
  113. data/lib/tasks/videos.rake +18 -0
  114. data/lib/tasks/wikitravel_pages.rake +40 -0
  115. data/lib/test_extensions.rb +9 -0
  116. data/lib/u.rb +34 -0
  117. data/lib/users_tasks.rb +88 -0
  118. data/lib/venues_tasks.rb +15 -0
  119. data/lib/videos_tasks.rb +71 -0
  120. data/lib/wikitravel_tasks.rb +139 -0
  121. data/spec/factories/cities.rb +89 -0
  122. data/spec/factories/galleries.rb +133 -0
  123. data/spec/factories/photo.rb +20 -0
  124. data/spec/factories/reports.rb +379 -0
  125. data/spec/factories/site.rb +26 -0
  126. data/spec/factories/tag.rb +42 -0
  127. data/spec/factories/user.rb +87 -0
  128. data/spec/factories/user_profiles.rb +33 -0
  129. data/spec/factories/venues.rb +25 -0
  130. data/spec/factories/videos.rb +38 -0
  131. data/test/controllers/ish_lib_engine/articles_controller_test.rb +52 -0
  132. data/test/dummy/README.rdoc +28 -0
  133. data/test/dummy/Rakefile +6 -0
  134. data/test/dummy/app/assets/javascripts/application.js +13 -0
  135. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  136. data/test/dummy/app/controllers/application_controller.rb +5 -0
  137. data/test/dummy/app/helpers/application_helper.rb +2 -0
  138. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  139. data/test/dummy/bin/bundle +3 -0
  140. data/test/dummy/bin/rails +4 -0
  141. data/test/dummy/bin/rake +4 -0
  142. data/test/dummy/bin/setup +29 -0
  143. data/test/dummy/config.ru +4 -0
  144. data/test/dummy/config/application.rb +26 -0
  145. data/test/dummy/config/boot.rb +5 -0
  146. data/test/dummy/config/database.yml +25 -0
  147. data/test/dummy/config/environment.rb +5 -0
  148. data/test/dummy/config/environments/development.rb +41 -0
  149. data/test/dummy/config/environments/production.rb +79 -0
  150. data/test/dummy/config/environments/test.rb +42 -0
  151. data/test/dummy/config/initializers/assets.rb +11 -0
  152. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  153. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  154. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  155. data/test/dummy/config/initializers/inflections.rb +16 -0
  156. data/test/dummy/config/initializers/mime_types.rb +4 -0
  157. data/test/dummy/config/initializers/session_store.rb +3 -0
  158. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  159. data/test/dummy/config/locales/en.yml +23 -0
  160. data/test/dummy/config/routes.rb +4 -0
  161. data/test/dummy/config/secrets.yml +22 -0
  162. data/test/dummy/db/development.sqlite3 +0 -0
  163. data/test/dummy/db/schema.rb +30 -0
  164. data/test/dummy/log/development.log +15 -0
  165. data/test/dummy/public/404.html +67 -0
  166. data/test/dummy/public/422.html +67 -0
  167. data/test/dummy/public/500.html +66 -0
  168. data/test/dummy/public/favicon.ico +0 -0
  169. data/test/fixtures/ish_lib_engine/articles.yml +9 -0
  170. data/test/fixtures/ish_lib_engine/comments.yml +9 -0
  171. data/test/integration/navigation_test.rb +8 -0
  172. data/test/ish_lib_engine_test.rb +7 -0
  173. data/test/models/ish_lib_engine/article_test.rb +9 -0
  174. data/test/models/ish_lib_engine/comment_test.rb +9 -0
  175. data/test/test_helper.rb +21 -0
  176. metadata +361 -0
@@ -0,0 +1,50 @@
1
+ class Newsitem
2
+ include Mongoid::Document
3
+ include Mongoid::Timestamps
4
+ include Mongoid::Paranoia
5
+
6
+ embedded_in :user
7
+ embedded_in :site
8
+ embedded_in :city
9
+ embedded_in :tag
10
+
11
+ belongs_to :photo
12
+ belongs_to :report
13
+ belongs_to :gallery
14
+ belongs_to :video
15
+
16
+ field :name, :type => String
17
+ field :descr, :type => String
18
+ field :image_path, :type => String
19
+ field :link_path, :type => String
20
+ field :username, :type => String # @TODO do I use this???
21
+ field :partial_name, :type => String, :default => nil # @deprecated, but let's not remove it.
22
+
23
+ field :weight, :type => Integer, :default => 10
24
+ field :n_upvotes, :type => Integer, :default => 0
25
+ field :n_downvotes, :type => Integer, :default => 0
26
+ field :upvoting_users, :type => Array, :default => []
27
+ field :downvoting_users, :type => Array, :default => []
28
+ field :is_feature, :type => Boolean, :default => false
29
+
30
+ default_scope ->{ order_by({ :created_at => :desc }) }
31
+
32
+ def self.from_params item
33
+ n = Newsitem.new
34
+ n.descr = item[:descr]
35
+ n.username = item[:username]
36
+
37
+ unless item[:report_id].blank?
38
+ n.report = Report.find item[:report_id]
39
+ end
40
+
41
+ unless item[:gallery_id].blank?
42
+ n.gallery = Gallery.find item[:gallery_id]
43
+ end
44
+
45
+ n.partial_name = item.partial_name unless item.partial_name.blank?
46
+
47
+ return n
48
+ end
49
+
50
+ end
@@ -0,0 +1,18 @@
1
+
2
+ class Nodeitem
3
+
4
+ include Mongoid::Document
5
+ include Mongoid::Timestamps
6
+
7
+ field :repository, :type => String
8
+ validates :repository, :presence => true
9
+
10
+ field :branch, :type => String
11
+ validates :branch, :presence => true
12
+
13
+ field :subdomain, :type => String
14
+ validates :subdomain, :presence => true, :uniqueness => true
15
+
16
+ field :status, :type => String
17
+
18
+ end
@@ -0,0 +1,68 @@
1
+
2
+ class Photo
3
+
4
+ include Mongoid::Document
5
+ include Mongoid::Timestamps
6
+ include Mongoid::Paperclip
7
+
8
+ belongs_to :user, :inverse_of => :photos
9
+ validates :user, :presence => true
10
+ field :username, :type => String
11
+
12
+ has_and_belongs_to_many :viewers, :class_name => 'User', :inverse_of => :viewable_photos
13
+
14
+ belongs_to :profile_user, :class_name => 'User', :inverse_of => :profile_photo
15
+ belongs_to :profile_city, :class_name => 'City', :inverse_of => :profile_photo
16
+ belongs_to :profile_venue, :class_name => 'Venue', :inverse_of => :profile_photo
17
+
18
+ belongs_to :report
19
+ belongs_to :tag
20
+ belongs_to :venue
21
+ belongs_to :feature
22
+ belongs_to :gallery
23
+
24
+ field :name, :type => String
25
+ field :descr, :type => String
26
+
27
+ field :weight, :type => Integer, :default => 10
28
+
29
+ field :is_public, :type => Boolean, :default => true
30
+ field :is_trash, :type => Boolean, :default => false
31
+
32
+ # default_scope ->{ where({ :is_trash => false, :is_public => true }) }
33
+ default_scope ->{ where({ :is_trash => false }) }
34
+
35
+ has_mongoid_attached_file :photo,
36
+ :styles => {
37
+ :mini => '20x20#',
38
+ :thumb => "100x100#",
39
+ # :two_hundred => '200x200#',
40
+ :small => "400x400>",
41
+ # :small_square => "400x400#",
42
+ # :large_square => '950x650',
43
+ :large => '950x650>'
44
+ },
45
+ :storage => :s3,
46
+ :s3_credentials => ::S3_CREDENTIALS,
47
+ :path => "photos/:style/:id/:filename"
48
+
49
+ def self.n_per_manager_gallery
50
+ 25
51
+ end
52
+
53
+ validates_attachment_content_type :photo, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]
54
+
55
+ set_callback(:create, :before) do |doc|
56
+ # if doc.is_public
57
+ # Site.languages.each do |lang|
58
+ # n = Newsitem.new({
59
+ # # :descr => t('photos.new'),
60
+ # :photo => doc, :username => doc.user.username })
61
+ # Site.where( :domain => DOMAIN, :lang => lang ).first.newsitems << n
62
+ # end
63
+ # end
64
+ end
65
+
66
+ end
67
+
68
+
@@ -0,0 +1,13 @@
1
+
2
+ module RateMe
3
+
4
+ def self.included(base)
5
+ base.send :field, :n_upvotes, :type => Integer, :default => 1
6
+ base.send :field, :n_downvotes, :type => Integer, :default => 0
7
+ base.send :field, :upvoters, :type => Array, :default => [ 'anonymous' ]
8
+ base.send :field, :downvoters, :type => Array, :default => []
9
+ end
10
+
11
+ end
12
+
13
+
@@ -0,0 +1,144 @@
1
+ class Report
2
+ include Mongoid::Document
3
+ include Mongoid::Timestamps
4
+
5
+ field :name, :type => String
6
+ validates :name, :presence => true
7
+ index({ :name => 1 }, { :unique => true })
8
+ index({ :name => 1, :is_trash => 1 })
9
+
10
+ field :name_seo, :type => String
11
+ validates :name_seo, :uniqueness => true, :presence => true
12
+ index({ :name_seo => 1 }, { :unique => true })
13
+
14
+ field :descr, :type => String
15
+
16
+ field :is_trash, :type => Boolean, :default => false
17
+ index :is_trash => 1, :is_public => 1
18
+
19
+ field :is_public, :type => Boolean, :default => true
20
+ index({ :is_public => 1 })
21
+ scope :public, ->{
22
+ where({ is_public: true })
23
+ }
24
+
25
+ field :is_feature, :type => Boolean, :default => false
26
+ index({ :is_feature => 1 })
27
+
28
+ field :is_done, :type => Boolean, :default => true
29
+ index({ :is_done => 1 })
30
+
31
+ field :x, :type => Float
32
+ field :y, :type => Float
33
+
34
+ field :lang, :type => String, :default => 'en'
35
+ index({ :lang => 1 })
36
+
37
+ field :username, :type => String, :default => 'anonymous'
38
+ validates :username, :presence => true, :allow_nil => false
39
+ belongs_to :user
40
+ validates :user, :presence => true, :allow_nil => false
41
+ index({ :username => 1 })
42
+
43
+ field :subhead, :type => String
44
+
45
+ belongs_to :tag
46
+ belongs_to :city
47
+
48
+ belongs_to :site
49
+ validates :site, :presence => true
50
+
51
+ has_and_belongs_to_many :venues
52
+ belongs_to :cities_user
53
+
54
+ has_one :photo
55
+
56
+ field :n_upvotes, :default => 0
57
+ field :n_spamvotes, :default => 0
58
+
59
+ default_scope ->{
60
+ where({ is_public: true, is_trash: false }).order_by({ created_at: :desc })
61
+ }
62
+
63
+ def self.list conditions = { :is_trash => false }
64
+ out = self.where( conditions ).order_by( :name => :asc ).limit( 100 )
65
+ [['', nil]] + out.map { |item| [ item.name, item.id ] }
66
+ end
67
+
68
+ PER_PAGE = 20
69
+ def self.paginates_per
70
+ self::PER_PAGE
71
+ end
72
+
73
+ def venue
74
+ return self.venues[0] || nil
75
+ end
76
+
77
+ def self.all
78
+ self.where( :is_public => true, :is_trash => false ).order_by( :created_at => :desc )
79
+ end
80
+
81
+ def self.not_tagged
82
+ Report.where( :tag_id => nil, :city => nil )
83
+ end
84
+
85
+ def self.for_homepage args
86
+ begin
87
+ tag_ids = args[:main_tag].children_tags.map { |tag| tag._id } + [ args[:main_tag]._id ]
88
+ return Report.where( :tag_id.in => tag_ids ).page args[:page]
89
+ rescue
90
+ return Report.page args[:page]
91
+ end
92
+ end
93
+
94
+ set_callback :create, :after do |doc|
95
+ if doc.is_public
96
+
97
+ if !doc.venue_ids.blank?
98
+ ( doc.venue_ids || [] ).each do |venue_id|
99
+ v = Venue.find venue_id
100
+ u = User.find doc.user_id
101
+ n = Newsitem.new
102
+ n.username = u.username unless u.blank?
103
+ n.report = doc
104
+ v.newsitems << n
105
+ v.save
106
+ end
107
+ end
108
+
109
+ #
110
+ # hidden
111
+ proc do # nothing
112
+ unless doc.site.blank?
113
+ username = doc.user.username || 'anonymous'
114
+ doc.site.newsitems << Newsitem.new({ :report_id => doc.id, :username => username, :descr => doc.subhead, :name => doc.name })
115
+ flag = doc.site.save
116
+ puts! flag unless flag
117
+ end
118
+ end
119
+
120
+ unless doc.city.blank?
121
+ city = City.find doc.city.id
122
+ username = doc.user.username || 'anon'
123
+ n = Newsitem.new :report => doc, :username => username
124
+ city.newsitems << n
125
+ city.save
126
+ end
127
+ end
128
+ end
129
+
130
+ def self.clear
131
+ if Rails.env.test?
132
+ self.unscoped.each { |r| r.remove }
133
+ end
134
+ end
135
+
136
+ def self.not_tagged
137
+ Report.where( :tag_id => nil, :city => nil )
138
+ end
139
+
140
+ def venue
141
+ self.venues[0] || nil
142
+ end
143
+
144
+ end
@@ -0,0 +1,4 @@
1
+
2
+ class Review
3
+
4
+ end
@@ -0,0 +1,83 @@
1
+
2
+ class Site
3
+
4
+ include Mongoid::Document
5
+ include Mongoid::Timestamps
6
+ include AuxModel
7
+
8
+ field :domain, :type => String
9
+
10
+ field :lang, :type => String, :default => 'en'
11
+ # validates :lang, { :uniqueness => :true, :scope => :domain }
12
+
13
+ field :title, :type => String
14
+ field :subhead, :type => String
15
+ field :home_redirect_path, :type => String, :default => nil
16
+
17
+ field :n_features, :type => Integer, :default => 4
18
+ field :n_newsitems, :type => Integer, :default => 20
19
+
20
+ # denormalized
21
+ field :n_reports, :type => Integer
22
+ field :n_galleries, :type => Integer
23
+
24
+ field :is_video_enabled, :type => Boolean, :default => false
25
+ field :is_resume_enabled, :type => Boolean, :default => false
26
+ field :is_ads_enabled, :type => Boolean, :default => true
27
+ field :is_trash, :type => Boolean, :default => false
28
+ field :is_primary, :type => Boolean, :default => false
29
+ field :is_private, :type => Boolean, :default => false
30
+
31
+ field :homepage_layout, :type => String, :default => 'show'
32
+ field :layout, :type => String, :default => 'application'
33
+
34
+ has_many :reports
35
+ has_many :galleries
36
+ has_many :tags
37
+ has_many :videos
38
+
39
+ embeds_many :features
40
+ embeds_many :newsitems
41
+
42
+ default_scope ->{ where({ :is_trash => false }).order_by({ :domain => :asc, :lang => :asc }) }
43
+
44
+ set_callback :create, :before do |doc|
45
+ if Site.where( :lang => doc.lang, :domain => doc.domain ).length > 0
46
+ false
47
+ end
48
+ end
49
+
50
+ set_callback :update, :before do |doc|
51
+ possible_duplicate = Site.where( :lang => doc.lang, :domain => doc.domain ).first
52
+ if possible_duplicate.blank?
53
+ true
54
+ elsif doc.id != possible_duplicate.id
55
+ false
56
+ end
57
+ end
58
+
59
+ LANGUAGES = [ 'en', 'ru', 'pt' ]
60
+
61
+ # manager uses it.
62
+ def self.list
63
+ out = self.all.order_by( :domain => :asc, :lang => :asc )
64
+ [['', nil]] + out.map { |item| [ "#{item.domain} #{item.lang}", item.id ] }
65
+ end
66
+
67
+ def self.mobi
68
+ Site.where( :domain => 'travel-guide.mobi', :lang => 'en' ).first
69
+ end
70
+
71
+ def n_reports
72
+ self.reports.unscoped.where( :is_trash => false ).length
73
+ end
74
+
75
+ def n_private_reports
76
+ self.reports.unscoped.where( :is_public => false, :is_trash => false ).length
77
+ end
78
+
79
+ def its_locales
80
+ Site.where( :domain => self.domain ).map { |s| s.lang.to_sym }
81
+ end
82
+
83
+ end
data/app/models/tag.rb ADDED
@@ -0,0 +1,78 @@
1
+
2
+ class Tag
3
+
4
+ include Mongoid::Document
5
+ include Mongoid::Timestamps
6
+
7
+ field :name, :type => String
8
+ validates :name, :uniqueness => true, :allow_nil => false
9
+
10
+ field :name_seo, :type => String
11
+ validates :name_seo, :uniqueness => true, :allow_nil => false
12
+
13
+ field :descr, :type => String, :default => ''
14
+
15
+ field :is_public, :type => Boolean, :default => true
16
+ field :is_trash, :type => Boolean, :default => false
17
+ field :is_feature, :type => Boolean, :default => false
18
+
19
+ field :weight, :type => Integer, :default => 10
20
+
21
+ has_many :reports
22
+ has_many :galleries
23
+ has_many :videos
24
+
25
+ has_many :children_tags, :class_name => 'Tag', :inverse_of => :parent_tag
26
+ belongs_to :parent_tag, :class_name => 'Tag', :inverse_of => :children_tags
27
+
28
+ embeds_many :features
29
+ embeds_many :newsitems
30
+
31
+ belongs_to :site
32
+ validates :site, :presence => true
33
+
34
+ default_scope ->{
35
+ where({ :is_public => true, :is_trash => false }).order_by({ :name => :asc })
36
+ }
37
+
38
+ before_create do |d|
39
+ if d.name_seo.blank?
40
+ d.name_seo = d.name.to_simple_string
41
+ end
42
+ end
43
+
44
+ def self.clear
45
+ if Rails.env.test?
46
+ Tag.each { |r| r.remove }
47
+ end
48
+ end
49
+
50
+ def self.no_parent
51
+ Tag.where( :parent_tag_id => nil )
52
+ end
53
+
54
+ def self.list
55
+ out = Tag.all.order_by( :name => :desc )
56
+ [['', nil]] + out.map { |item| [ item.name, item.id ] }
57
+ end
58
+
59
+ # @deprecated, there will be no reports or galleries in tags. There will be only features and newsitems
60
+ def self.n_items
61
+ 10
62
+ end
63
+ def self.n_reports
64
+ 4
65
+ end
66
+ def self.n_galleries
67
+ 4
68
+ end
69
+ def self.n_videos
70
+ 4
71
+ end
72
+
73
+ # @deprecated I don't even know why I have this. Should be simplified into non-being.
74
+ def self.n_features
75
+ 4
76
+ end
77
+
78
+ end