c80_estate 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/CODE_OF_CONDUCT.md +49 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +67 -0
  7. data/Rakefile +2 -0
  8. data/app/admin/c80_estate/areas.rb +56 -0
  9. data/app/admin/c80_estate/atypes.rb +44 -0
  10. data/app/admin/c80_estate/prop_names.rb +48 -0
  11. data/app/admin/c80_estate/properties.rb +38 -0
  12. data/app/admin/c80_estate/role_types.rb +40 -0
  13. data/app/admin/c80_estate/uoms.rb +33 -0
  14. data/app/assets/javascript/c80_estate/backend/admin/areas.js +423 -0
  15. data/app/assets/javascript/c80_estate/backend/init.js +36 -0
  16. data/app/assets/javascript/c80_estate/backend/init_selectpicker.js +6 -0
  17. data/app/assets/javascript/c80_estate/lib/jalert.js +16 -0
  18. data/app/assets/javascript/c80_estate_active_admin.js.coffee +4 -0
  19. data/app/assets/stylesheets/c80_estate/backend/admin_areas.scss +109 -0
  20. data/app/assets/stylesheets/c80_estate/backend/admin_users.scss +27 -0
  21. data/app/assets/stylesheets/c80_estate/backend/common.scss +3 -0
  22. data/app/assets/stylesheets/c80_estate/lib/mixins.scss +17 -0
  23. data/app/assets/stylesheets/c80_estate_active_admin.scss +2 -0
  24. data/app/controllers/c80_estate/ajax_controller.rb +17 -0
  25. data/app/models/c80_estate/aphoto.rb +6 -0
  26. data/app/models/c80_estate/area.rb +26 -0
  27. data/app/models/c80_estate/astatus.rb +6 -0
  28. data/app/models/c80_estate/atphoto.rb +6 -0
  29. data/app/models/c80_estate/atype.rb +132 -0
  30. data/app/models/c80_estate/comment.rb +7 -0
  31. data/app/models/c80_estate/item_prop.rb +70 -0
  32. data/app/models/c80_estate/owner.rb +62 -0
  33. data/app/models/c80_estate/pphoto.rb +5 -0
  34. data/app/models/c80_estate/prop_name.rb +19 -0
  35. data/app/models/c80_estate/property.rb +15 -0
  36. data/app/models/c80_estate/role.rb +6 -0
  37. data/app/models/c80_estate/role_type.rb +5 -0
  38. data/app/models/c80_estate/uom.rb +5 -0
  39. data/app/uploaders/c80_estate/aphoto_uploader.rb +21 -0
  40. data/app/uploaders/c80_estate/atphoto_uploader.rb +21 -0
  41. data/app/uploaders/c80_estate/pphoto_uploader.rb +21 -0
  42. data/bin/console +14 -0
  43. data/bin/setup +8 -0
  44. data/c80_estate.gemspec +25 -0
  45. data/config/routes.rb +3 -0
  46. data/db/migrate/20160629033533_create_c80_estate_areas.rb +13 -0
  47. data/db/migrate/20160629033535_create_c80_estate_properties.rb +15 -0
  48. data/db/migrate/20160629034444_create_c80_prop_names.rb +12 -0
  49. data/db/migrate/20160629041414_create_c80_estate_uoms.rb +10 -0
  50. data/db/migrate/20160629090606_create_c80_estate_aphotos.rb +9 -0
  51. data/db/migrate/20160629091313_create_c80_estate_astatuses.rb +9 -0
  52. data/db/migrate/20160629092323_create_c80_item_props.rb +14 -0
  53. data/db/migrate/20160629093030_create_c80_estate_comments.rb +12 -0
  54. data/db/migrate/20160629100505_create_c80_atypes.rb +10 -0
  55. data/db/migrate/20160629205151_create_c80_estate_atphotos.rb +9 -0
  56. data/db/migrate/20160630012727_create_c80_estate_pphotos.rb +9 -0
  57. data/db/migrate/20160630013636_create_join_table_areas_astatuses.rb +12 -0
  58. data/db/migrate/20160630013737_create_join_table_atypes_prop_names.rb +12 -0
  59. data/db/migrate/20160704050000_create_c80_estate_role_types.rb +9 -0
  60. data/db/migrate/20160704063131_create_c80_estate_roles.rb +10 -0
  61. data/db/seeds/50_fill_uoms.rb.example +8 -0
  62. data/db/seeds/55_fill_prop_names.rb.example +51 -0
  63. data/db/seeds/60_fill_atypes.rb.example +29 -0
  64. data/lib/c80_estate.rb +8 -0
  65. data/lib/c80_estate/engine.rb +23 -0
  66. data/lib/c80_estate/version.rb +3 -0
  67. metadata +151 -0
@@ -0,0 +1,70 @@
1
+ module C80Estate
2
+ class ItemProp < ActiveRecord::Base
3
+
4
+ belongs_to :area
5
+ belongs_to :property
6
+ belongs_to :prop_name
7
+
8
+ before_save :before_save_format_value
9
+
10
+ private
11
+
12
+ def self.capz
13
+ [24, 36, 46]
14
+ end
15
+
16
+ def self.uppz
17
+ [27, 37, 38]
18
+ end
19
+
20
+ def self.siz
21
+ [23]
22
+ end
23
+
24
+ def before_save_format_value
25
+
26
+ v = self.value
27
+ uom = prop_name.uom
28
+
29
+ # удаляем пробелы в начале и в конце строки
30
+ v = v.strip! || v
31
+
32
+ # числовые значения преобразуем в числа
33
+ if uom.present? && uom.is_number
34
+
35
+ v = v.gsub(' ', '')
36
+ v = v.gsub(',', '.')
37
+ v = v[/([0-9.]+)/]
38
+
39
+ # нечисловые значения: либо capitalize, либо upcase, либо downcase
40
+ else
41
+
42
+ if prop_name_id.in?(ItemProp.capz)
43
+ v = v.mb_chars.capitalize.to_s
44
+ elsif prop_name_id.in?(ItemProp.uppz)
45
+ v = v.mb_chars.upcase.to_s
46
+ else
47
+ v = v.mb_chars.downcase.to_s
48
+ end
49
+
50
+ end
51
+
52
+ if prop_name_id.in?(ItemProp.siz)
53
+ v = v.gsub(',', '.')
54
+ sizes = v.scan(/([0-9,]+)/)
55
+ oum = v.scan(/[мс]*м/)
56
+ v = sizes.join(" x ")
57
+ if oum.count > 0
58
+ v += " #{oum[0]}"
59
+ else
60
+ v += ' мм'
61
+ end
62
+ end
63
+
64
+
65
+ self.value = v
66
+
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,62 @@
1
+ module C80Estate
2
+
3
+ module Owner
4
+
5
+ extend ActiveSupport::Concern
6
+
7
+ # ERROR: Cannot define multiple 'included' blocks for a Concern
8
+ # included do
9
+ #
10
+ # end
11
+
12
+ def self.included(klass)
13
+ klass.extend ClassMethods
14
+ klass.send(:include, InstanceMethods)
15
+ end
16
+
17
+ module ClassMethods
18
+
19
+ def act_as_owner
20
+ class_eval do
21
+ # эти взаимосвязи можно трактовать, как "создатель объектов этих классов"
22
+ has_many :areas, :as => :owner, :class_name => 'C80Estate::Area', :dependent => :nullify
23
+ has_many :properties, :as => :owner, :class_name => 'C80Estate::Property', :dependent => :nullify
24
+ has_many :comments, :as => :owner, :class_name => 'C80Estate::Comment', :dependent => :destroy
25
+ # эта взаимосвязь трактуется, как "роль, назначенная персоне"
26
+ has_many :roles, :as => :owner, :class_name => 'C80Estate::Role', :dependent => :destroy
27
+ accepts_nested_attributes_for :roles,
28
+ :reject_if => lambda { |attributes|
29
+ !attributes.present?
30
+ },
31
+ :allow_destroy => true
32
+
33
+ after_create :create_role
34
+
35
+ def create_role
36
+ Rails.logger.debug('<Owner.create_role>')
37
+ r = C80Estate::Role.create({ role_type_id: nil })
38
+ roles << r
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+
45
+ module InstanceMethods
46
+
47
+ def role_type_title
48
+ res = " - "
49
+ if roles.count > 0
50
+ if roles.first.role_type_id.present?
51
+ res = roles.first.role_type.title
52
+ end
53
+ end
54
+ res
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+ end
61
+
62
+ ActiveRecord::Base.send :include, C80Estate::Owner
@@ -0,0 +1,5 @@
1
+ module C80Estate
2
+ class Pphoto < ActiveRecord::Base
3
+ mount_uploader :image, PphotoUploader
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ module C80Estate
2
+ class PropName < ActiveRecord::Base
3
+
4
+ # validates_with PropNameValidator
5
+
6
+ # у этой (абстрактной по сути) характеристики есть конкретные порождения - свойства.
7
+ has_many :item_props, :dependent => :destroy
8
+ has_and_belongs_to_many :atypes, :join_table => 'c80_estate_atypes_prop_names'
9
+
10
+ # каждое свойство принадлежит какой-то единице измерения
11
+ belongs_to :uom
12
+
13
+ # accepts_nested_attributes_for :uom
14
+ # has_and_belongs_to_many :main_props
15
+ # has_and_belongs_to_many :common_props
16
+ # has_and_belongs_to_many :price_props
17
+ default_scope {order(:title => :asc)}
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ module C80Estate
2
+ class Property < ActiveRecord::Base
3
+ belongs_to :atype
4
+ belongs_to :owner, :polymorphic => true
5
+ has_many :item_props, :dependent => :destroy
6
+ has_many :pphotos, :dependent => :destroy # одна или несколько фоток
7
+ accepts_nested_attributes_for :pphotos,
8
+ :reject_if => lambda { |attributes|
9
+ !attributes.present?
10
+ },
11
+ :allow_destroy => true
12
+ has_many :areas, :dependent => :destroy
13
+ has_many :comments, :dependent => :destroy
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ module C80Estate
2
+ class Role < ActiveRecord::Base
3
+ belongs_to :owner
4
+ belongs_to :role_type
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module C80Estate
2
+ class RoleType < ActiveRecord::Base
3
+ has_many :roles, :dependent => :nullify
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module C80Estate
2
+ class Uom < ActiveRecord::Base
3
+ has_many :prop_names
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ module C80Estate
2
+ class AphotoUploader < BaseFileUploader
3
+
4
+ # ограничение оригинальной картинки
5
+ process :resize_to_limit => [1024, 1024]
6
+
7
+ version :thumb512 do
8
+ process :resize_to_limit => [512, 512]
9
+ end
10
+
11
+ version :thumb256 do
12
+ process :resize_to_limit => [256, 256]
13
+ end
14
+
15
+ def store_dir
16
+ "uploads/areas/#{model.id}"
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,21 @@
1
+ module C80Estate
2
+ class AtphotoUploader < BaseFileUploader
3
+
4
+ # ограничение оригинальной картинки
5
+ process :resize_to_limit => [1024, 1024]
6
+
7
+ version :thumb512 do
8
+ process :resize_to_limit => [512, 512]
9
+ end
10
+
11
+ version :thumb256 do
12
+ process :resize_to_limit => [256, 256]
13
+ end
14
+
15
+ def store_dir
16
+ "uploads/atypes/#{model.id}"
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,21 @@
1
+ module C80Estate
2
+ class PphotoUploader < BaseFileUploader
3
+
4
+ # ограничение оригинальной картинки
5
+ process :resize_to_limit => [1024, 1024]
6
+
7
+ version :thumb512 do
8
+ process :resize_to_limit => [512, 512]
9
+ end
10
+
11
+ version :thumb256 do
12
+ process :resize_to_limit => [256, 256]
13
+ end
14
+
15
+ def store_dir
16
+ "uploads/properties/#{model.id}"
17
+ end
18
+
19
+ end
20
+
21
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "c80_estate"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'c80_estate/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "c80_estate"
8
+ spec.version = C80Estate::VERSION
9
+ spec.authors = ["C80609A"]
10
+ spec.email = ["c080609a@gmail.com"]
11
+
12
+ spec.summary = 'Estate Gem'
13
+ spec.description = 'for real estate app'
14
+ spec.homepage = "http://bc-acond.ru"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_dependency 'activesupport', ['>= 3.0.0']
25
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ C80Estate::Engine.routes.draw do
2
+ match '/estate/get_atype_propnames', :to => 'ajax#get_atype_propnames', :via => :post
3
+ end
@@ -0,0 +1,13 @@
1
+ class CreateC80EstateAreas < ActiveRecord::Migration
2
+ def change
3
+ create_table :c80_estate_areas, :options => 'COLLATE=utf8_unicode_ci' do |t|
4
+ t.string :title
5
+ t.text :desc
6
+ t.references :property, index: true
7
+ t.references :atype, index: true
8
+ t.string :owner_type
9
+ t.references :owner, index: true
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ class CreateC80EstateProperties < ActiveRecord::Migration
2
+ def change
3
+ create_table :c80_estate_properties, :options => 'COLLATE=utf8_unicode_ci' do |t|
4
+ t.string :title
5
+ t.text :desc
6
+ t.string :address
7
+ t.string :latitude
8
+ t.string :longitude
9
+ t.string :owner_type
10
+ t.references :owner, index: true
11
+ t.references :atype, index: true
12
+ t.timestamps
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ class CreateC80PropNames < ActiveRecord::Migration
2
+ def change
3
+ create_table :c80_estate_prop_names, :options => 'COLLATE=utf8_unicode_ci' do |t|
4
+ t.string :title
5
+ t.boolean :is_normal_price
6
+ t.boolean :is_excluded_from_filtering
7
+ t.references :uom, index: true
8
+ t.timestamps
9
+ end
10
+ # add_foreign_key :c80_sass_seo_sites, :owners
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ class CreateC80EstateUoms < ActiveRecord::Migration
2
+ def change
3
+ create_table :c80_estate_uoms, :options => 'COLLATE=utf8_unicode_ci' do |t|
4
+ t.string :title
5
+ t.string :comment
6
+ t.boolean :is_number
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ class CreateC80EstateAphotos < ActiveRecord::Migration
2
+ def change
3
+ create_table :c80_estate_aphotos, :options => 'COLLATE=utf8_unicode_ci' do |t|
4
+ t.string :image
5
+ t.references :area, index: true
6
+ t.timestamps null: false
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class CreateC80EstateAstatuses < ActiveRecord::Migration
2
+ def change
3
+ create_table :c80_estate_astatuses, :options => 'COLLATE=utf8_unicode_ci' do |t|
4
+ t.string :tag
5
+ t.string :title
6
+ t.timestamps null: false
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ class CreateC80ItemProps < ActiveRecord::Migration
2
+ def change
3
+ create_table :c80_estate_item_props, :options => 'COLLATE=utf8_unicode_ci' do |t|
4
+ t.string :value
5
+ t.references :area, index: true
6
+ t.references :property, index: true
7
+ t.references :prop_name, index: true
8
+
9
+ t.timestamps null: false
10
+ end
11
+ # add_foreign_key :c80_item_props, :areas
12
+ # add_foreign_key :c80_item_props, :prop_names
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ class CreateC80EstateComments < ActiveRecord::Migration
2
+ def change
3
+ create_table :c80_estate_comments, :options => 'COLLATE=utf8_unicode_ci' do |t|
4
+ t.text :content
5
+ t.references :area, index: true
6
+ t.references :property, index: true
7
+ t.string :owner_type
8
+ t.references :owner, index: true
9
+ t.timestamps null: false
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ class CreateC80Atypes < ActiveRecord::Migration
2
+ def change
3
+ create_table :c80_estate_atypes, :options => 'COLLATE=utf8_unicode_ci' do |t|
4
+ t.string :title
5
+ t.string :slug
6
+
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end