ish_models 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/ish_models.rb +9 -0
- data/lib/report.rb +133 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 45d3efbf83341b50c589abdd4a8d1a0d0425c1ea
|
4
|
+
data.tar.gz: 4f9bc029176b256598e532f9e4412a41e9977df5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 42bb530a457bf51247287d74617a3c21642561197ac8707a0a25a1a7715ed7a2d62e572e4feb68c21d869023498a7088bb635ab5885d19c9070c95c1853fc14f
|
7
|
+
data.tar.gz: f2149a121e7f2dc19d4f4840195b2da582fb62ee5bc55007e8d9f02c737564a376aa2c2db9d1a92e5ea09245242a9824b89eec25d9157bf33224bb7d40a4cf05
|
data/lib/ish_models.rb
ADDED
data/lib/report.rb
ADDED
@@ -0,0 +1,133 @@
|
|
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
|
+
unless doc.city.blank?
|
110
|
+
city = City.find doc.city.id
|
111
|
+
username = doc.user.username || 'anon'
|
112
|
+
n = Newsitem.new :report => doc, :username => username
|
113
|
+
city.newsitems << n
|
114
|
+
city.save
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.clear
|
120
|
+
if Rails.env.test?
|
121
|
+
self.unscoped.each { |r| r.remove }
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.not_tagged
|
126
|
+
Report.where( :tag_id => nil, :city => nil )
|
127
|
+
end
|
128
|
+
|
129
|
+
def venue
|
130
|
+
self.venues[0] || nil
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ish_models
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- piousbox
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-10 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: models of ish
|
14
|
+
email: victor@wasya.co
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/ish_models.rb
|
20
|
+
- lib/report.rb
|
21
|
+
homepage: http://wasya.co
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.5.1
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: models of ish
|
45
|
+
test_files: []
|