ish_models 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c162f07482409babf2ebfe1f11ab042314026ad
4
- data.tar.gz: 585a4e66b14c2ef29680e3d92654ccd3bd687983
3
+ metadata.gz: 669b08747fe005647df40af6afbb120239aa7a1b
4
+ data.tar.gz: 8091e1bce7eb3fc5247970122596a28c2fd72753
5
5
  SHA512:
6
- metadata.gz: 8a3a4d6df10916917a9a31dbc83080a155fd9582202132522b4ceb57f2025c31db67f03d88e77870c883448238b1b2f1270b2432f80708331712e687798d2791
7
- data.tar.gz: 4386857c2f79e68758072adec92da4b231e97d24b976f6b37a9443cb086b2df55fc29ea5aff72c33c329b91ba8bd98cc982ff0c5595517972b4b55b8b8537d90
6
+ metadata.gz: 7a5d8e9180fcb3a8adcf5ff8094dc63f69a55ea70d1673d6bb2bb578001471124303cee20cbc6d807f03e73d1e6022100b4c955f982b0c4f50f510275c94ab7a
7
+ data.tar.gz: a7c1e0d057b6a6915baf104a0426970696dc3eac67325c572b04b63bf5f96cc97f73871762967bef665183b58953853f48e0e9f7fe3ce2a1f45099a8c1480ff9
data/lib/city.rb ADDED
@@ -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
+
data/lib/country.rb ADDED
@@ -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
data/lib/event.rb ADDED
@@ -0,0 +1,21 @@
1
+
2
+ class Event
3
+
4
+ include Mongoid::Document
5
+ include Mongoid::Timestamps
6
+
7
+ field :name, :type => String
8
+ validates :name, :presence => true, :uniqueness => true
9
+
10
+ field :name_seo, :type => String
11
+ validates :name_seo, :presence => true, :uniqueness => true
12
+
13
+ field :descr, :type => String
14
+
15
+ field :date, :type => DateTime
16
+ validates :date, :presence => true
17
+
18
+ belongs_to :city
19
+ validates :city, :presence => true
20
+
21
+ end
data/lib/feature.rb ADDED
@@ -0,0 +1,38 @@
1
+
2
+ class Feature
3
+
4
+ include Mongoid::Document
5
+ include Mongoid::Timestamps
6
+
7
+ field :name, :type => String
8
+ field :subhead, :type => String
9
+
10
+ field :image_path, :type => String
11
+ field :link_path, :type => String
12
+ field :partial_name, :type => String
13
+ field :inner_html, :type => String
14
+ field :weight, :type => Integer, :default => 10
15
+
16
+ belongs_to :photo
17
+ belongs_to :report
18
+ belongs_to :gallery
19
+ belongs_to :video
20
+ # has_one :photo
21
+ # has_one :report
22
+ # has_one :gallery
23
+ # has_one :video
24
+
25
+ embedded_in :venue
26
+ embedded_in :site
27
+ embedded_in :city
28
+ embedded_in :tag
29
+
30
+ def self.all
31
+ self.order_by( :created_at => :desc )
32
+ end
33
+
34
+ def self.n_features
35
+ 4
36
+ end
37
+
38
+ end
data/lib/gallery.rb ADDED
@@ -0,0 +1,57 @@
1
+ require 'string'
2
+ class Gallery < AppModel2
3
+
4
+ belongs_to :site
5
+ validates :site, :presence => true
6
+
7
+ belongs_to :user
8
+ validates :user, :presence => true
9
+ field :username, :type => String
10
+
11
+ field :name, :type => String
12
+ validates :name, :uniqueness => true # , :allow_nil => false
13
+
14
+ field :galleryname, :type => String
15
+ validates :galleryname, :uniqueness => true # , :allow_nil => false
16
+
17
+ field :subhead, :type => String
18
+ field :descr, :type => String
19
+ field :lang, :type => String, :default => 'en'
20
+
21
+ # not necessary because AppModel2
22
+ # default_scope ->{ where( :is_public => true, :is_trash => false ).order_by( :created_at => :desc ) }
23
+
24
+ has_many :photos
25
+
26
+ belongs_to :tag
27
+ belongs_to :city
28
+ belongs_to :venue
29
+
30
+ set_callback(:create, :before) do |doc|
31
+ doc.username = doc.user.username
32
+ doc.galleryname = doc.name.to_simple_string
33
+
34
+ # for the homepage
35
+ if doc.is_public && doc.site
36
+ n = Newsitem.new {}
37
+ n.gallery = doc
38
+ n.username = doc.user.username
39
+ sites = Site.where( :domain => doc.site.domain )
40
+ sites.each do |site|
41
+ site.newsitems << n
42
+ flag = site.save
43
+ if !flag
44
+ puts! site.errors
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ # @deprecated, use Gallery::ACTIONS
51
+ def self.actions
52
+ [ 'show_mini', 'show_long', 'show' ]
53
+ end
54
+ ACTIONS = [ 'show_mini', 'show_long', 'show' ]
55
+
56
+ end
57
+
data/lib/site.rb ADDED
@@ -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
+ return 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
+ return true
54
+ elsif doc.id != possible_duplicate.id
55
+ return 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/lib/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
data/lib/venue.rb ADDED
@@ -0,0 +1,69 @@
1
+
2
+ require 'string'
3
+
4
+ class Venue
5
+
6
+ include Mongoid::Document
7
+ include Mongoid::Timestamps
8
+
9
+ field :name, :type => String
10
+ validates :name, :uniqueness => true, :allow_nil => false
11
+
12
+ field :name_seo, :type => String
13
+ validates :name_seo, :uniqueness => true, :allow_nil => false
14
+
15
+ field :descr, :type => String
16
+
17
+ field :is_trash, :type => Boolean, :default => false
18
+ scope :fresh, ->{ where({ :is_trash => false }) }
19
+ scope :trash, ->{ where({ :is_trash => true }) }
20
+
21
+ field :is_public, :type => Boolean, :default => true
22
+ scope :public, ->{ where({ :is_public => true }) }
23
+ scope :not_public, ->{ where({ :is_public => false }) }
24
+
25
+ field :is_feature, :type => Boolean, :default => false
26
+
27
+ field :x, :type => Float
28
+ field :y, :type => Float
29
+
30
+ field :lang, :type => String, :default => 'en'
31
+
32
+ belongs_to :city
33
+ belongs_to :owner, :class_name => 'User', :inverse_of => :owned_venue
34
+ validates :city, :allow_nil => false, :presence => true
35
+
36
+ has_and_belongs_to_many :users
37
+
38
+ has_one :profile_photo, :class_name => 'Photo', :inverse_of => :profile_venue
39
+
40
+ has_many :reports
41
+ has_many :galleries
42
+ has_many :photos
43
+
44
+ embeds_many :newsitems
45
+ embeds_many :features
46
+
47
+ def self.list conditions = { :is_trash => false }
48
+ out = self.where( conditions).order_by( :name => :asc )
49
+ [['', nil]] + out.map { |item| [ item.name, item.id ] }
50
+ end
51
+
52
+ set_callback(:create, :before) do |doc|
53
+ doc.name_seo = doc.name.to_simple_string
54
+ end
55
+
56
+ def self.types
57
+ return []
58
+ # if 'en' == @locale
59
+ # [ 'Hotels', 'Restaurants', 'Bars' ]
60
+ # else
61
+ # [ 'Hotels', 'Restaurants', 'Bars' ]
62
+ # end
63
+ end
64
+
65
+ def self.n_features
66
+ 6
67
+ end
68
+
69
+ end
data/lib/video.rb ADDED
@@ -0,0 +1,48 @@
1
+
2
+ class Video
3
+
4
+ include Mongoid::Document
5
+ include Mongoid::Timestamps
6
+
7
+ PER_PAGE = 6
8
+
9
+ field :name, :type => String
10
+ field :descr, :type => String
11
+
12
+ default_scope ->{ where({ :is_public => true, :is_trash => false }).order_by({ :created_at => :desc }) }
13
+
14
+ field :is_trash, :type => Boolean, :default => false
15
+ field :is_public, :type => Boolean, :default => true
16
+ field :is_feature, :type => Boolean, :default => false
17
+
18
+ field :x, :type => Float
19
+ field :y, :type => Float
20
+
21
+ field :lang, :type => String, :default => 'en'
22
+
23
+ field :youtube_id, :type => String
24
+ validates :youtube_id, :uniqueness => true, :presence => true
25
+
26
+ belongs_to :tag
27
+ belongs_to :city
28
+ belongs_to :site
29
+ validates :site, :presence => true
30
+ belongs_to :user
31
+ validates :user, :presence => true
32
+
33
+ accepts_nested_attributes_for :site, :tag, :city
34
+
35
+
36
+ def self.list
37
+ [['', nil]] + Video.all.order_by( :name => :desc ).map { |item| [ item.name, item.id ] }
38
+ end
39
+
40
+ set_callback( :create, :before ) do |doc|
41
+ if doc.is_public
42
+ doc.city.add_newsitem( doc ) unless doc.city.blank?
43
+ doc.site.add_newsitem( doc ) unless doc.site.blank?
44
+ end
45
+
46
+ end
47
+
48
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ish_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - piousbox
@@ -16,8 +16,17 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
+ - lib/city.rb
20
+ - lib/country.rb
21
+ - lib/event.rb
22
+ - lib/feature.rb
23
+ - lib/gallery.rb
19
24
  - lib/ish_models.rb
20
25
  - lib/report.rb
26
+ - lib/site.rb
27
+ - lib/tag.rb
28
+ - lib/venue.rb
29
+ - lib/video.rb
21
30
  homepage: http://wasya.co
22
31
  licenses:
23
32
  - MIT