caboose-rets 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTdiNTUxZTc2OGM0OTlhYjVlNTJjYzQ3YjcwY2VhNTRjNmRiYjgyMg==
4
+ NmQ4NTg0MjYwZGM4NzhhNjU5NDJmZTZlNThkOTRjNTE5NjUzYTE4NA==
5
5
  data.tar.gz: !binary |-
6
- NTU4ZjAwNjRiYmExNzAwZGYzNjk5ZGY2YzZmZTg5MjZmMTdiMGFlNQ==
6
+ Y2Y3ZDViNmM5N2Q0MTRjZTA0NDkyMzliNGY4OWQxZjhhYWJhOTBlZQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MTY0NmI2YmUzYzhhZDQ0ZjdjNmJjZDJjNGZiZGY3MzE5MzU0ZDliZDAzYTli
10
- NDNkMGRlOGIzOWY3ODkzYjY2MTEwMjBkNTU0Yzc2NmI2YjIzYjQ5YjhhZWRh
11
- OGFlYjk3YzgyODU0NTI3ODY4MzQzNDFkN2U0M2IzYmNjZWYyMmE=
9
+ ZWQ5OTIwMGJmOWY5M2M4NGViZmVkZTQ4ODhiNWE5Y2U3ZjNiYWQwN2Q4N2Ew
10
+ YTBkNjhjMDkyNjA3YjYyZWNkZTJiM2E0NTRjZTZlNWIwZDkxZjM1ZWMwZDE1
11
+ NjI3MTBlOThlOTY5YTAzNjk2N2EwZDE0MjUwMTU0MjI4YzkzZWM=
12
12
  data.tar.gz: !binary |-
13
- ZTE2NWM1MzU4ZWFlMDk3NjkyNjMzNWQ0NWNkZDA0YzJlY2I1YzM0YTg3ODEw
14
- YjcxMThiMDI2ODY3NzM1MDFjYTQ5ZDg0Y2RmOTM3NTI3YWNhNGNiZmI0ZWNl
15
- ODFkNDczNmM4MzcwMWQ1ZDc5NTQ1MzEzNmY4OTYxOTVhNTc1NTk=
13
+ MTgwOTEwZDEzYWI1OTNjMmNlNjkxZjNiMTdkYzIzNDE3YzJlNDhjODQ0NGMw
14
+ N2RhODJjM2Q0NDIyZjhmMTM5OTgwMTgwNWZlN2ZiNmRkODNhZjUwZTQxNzY5
15
+ NWEzNWQ1OWVhOTlkMzczMzRkNDA0ZWU3M2UzZmY0NGM4NWIzYjQ=
@@ -53,6 +53,11 @@ module CabooseRets
53
53
  if params[:waterfront].present? then @properties.reject!{|p| p.waterfront.blank?} end
54
54
  if params[:ftr_lotdesc] == 'golf' then @properties.reject!{|p| p.ftr_lotdesc != 'golf'} end
55
55
  #if params[:foreclosure] then @properties.reject!{|p| p.foreclosure_yn != "Y"} end
56
+
57
+ @saved_search = nil
58
+ if CabooseRets::SavedSearch.exists?(:uri => request.fullpath)
59
+ @saved_search = CabooseRets::SavedSearch.where(:uri => request.fullpath).first
60
+ end
56
61
  end
57
62
 
58
63
  # GET /residential/:mls_acct/details
@@ -0,0 +1,82 @@
1
+ module CabooseRets
2
+ class SavedSearchesController < ApplicationController
3
+
4
+ # GET /saved-searches
5
+ def index
6
+ return if !verify_logged_in
7
+ @searches = SavedSearch.where(:user_id => logged_in_user.id).all
8
+ render :layout => 'caboose/modal'
9
+ end
10
+
11
+ # POST /saved-searches
12
+ def add
13
+ return if !verify_logged_in
14
+
15
+ resp = Caboose::StdClass.new
16
+
17
+ if SavedSearch.exists?(:uri => params[:uri])
18
+ resp.redirect = "/saved-searches"
19
+ else
20
+ search = SavedSearch.new(
21
+ :user_id => logged_in_user.id,
22
+ :date_last => Date.today,
23
+ :interval => 1,
24
+ :notify => true,
25
+ :uri => params[:uri],
26
+ :property_type => params[:property_type],
27
+ :params => params[:params]
28
+ )
29
+ if search.save
30
+ resp.redirect = "/saved-searches"
31
+ else
32
+ resp.error = "There was an error saving your search."
33
+ end
34
+ end
35
+ render :json => resp
36
+ end
37
+
38
+ # GET /saved-searches/:id
39
+ def redirect
40
+ return if !verify_logged_in
41
+ @search = SavedSearch.find(params[:id])
42
+ redirect_to @search.uri
43
+ end
44
+
45
+ # PUT /saved-searches/:id
46
+ def update
47
+ return if !verify_logged_in
48
+
49
+ resp = Caboose::StdClass.new({'attributes' => {}})
50
+ search = SavedSearch.find(params[:id])
51
+
52
+ save = true
53
+ params.each do |name,value|
54
+ case name
55
+ when 'interval'
56
+ search.interval = value
57
+ resp.attributes['interval'] = { 'text' => "#{value}" }
58
+ end
59
+ end
60
+ resp.success = save && search.save
61
+ render :json => resp
62
+ end
63
+
64
+ # DELETE /saved-searches/:id
65
+ def delete
66
+ return if !verify_logged_in
67
+
68
+ resp = Caboose::StdClass.new
69
+ search = SavedSearch.find(params[:id])
70
+
71
+ if search
72
+ search.destroy
73
+ resp.success = "The saved search has been deleted."
74
+ else
75
+ resp.error = "There was an error deleting your search."
76
+ end
77
+
78
+ render :json => resp
79
+ end
80
+
81
+ end
82
+ end
@@ -1,7 +1,16 @@
1
1
  class CabooseRets::RetsPlugin < Caboose::CaboosePlugin
2
2
 
3
3
  def self.admin_nav(nav, user = nil, page = nil)
4
- return nav if user.nil? || !user.is_allowed('properties', 'view')
4
+ return nav if user.nil?
5
+
6
+ nav << {
7
+ 'id' => 'saved-searches',
8
+ 'text' => 'Saved Searches',
9
+ 'href' => '/saved-searches',
10
+ 'modal' => true
11
+ }
12
+
13
+ return nav if !user.is_allowed('properties', 'view')
5
14
 
6
15
  item = {
7
16
  'id' => 'rets',
@@ -0,0 +1,86 @@
1
+ class CabooseRets::SavedSearch < ActiveRecord::Base
2
+ self.table_name = 'rets_saved_searches'
3
+
4
+ belongs_to :user
5
+ attr_accessible :id, :user_id, :property_type, :uri, :params, :date_last, :interval, :notify
6
+
7
+ # We're storing the params as JSON, so parse it when we init
8
+ after_initialize do
9
+ unless self.params.is_a?(Hash) || self.params.nil?
10
+ obj = JSON.parse(self.params)
11
+ self.params = obj
12
+ end
13
+ end
14
+
15
+ # Store it back as JSON
16
+ before_save do
17
+ obj = Caboose::StdClass.new(self.params)
18
+ self.params = obj.to_json
19
+ end
20
+
21
+ def results()
22
+ @gen = Caboose::PageBarGenerator.new(self.params, self.search_fields, self.search_options)
23
+ return @gen.items
24
+ end
25
+
26
+ def new_results?()
27
+ return false if self.new_results.nil? || self.new_results == []
28
+ end
29
+
30
+ def new_results
31
+ return self.results.reject{|r|r.date_created.to_date > self.date_last.to_date }
32
+ end
33
+
34
+ def model
35
+ case self.property_type
36
+ when 'residential' then return CabooseRets::ResidentialProperty
37
+ when 'commercial' then return CabooseRets::CommercialProperty
38
+ when 'land' then return CabooseRets::LandProperty
39
+ when 'multi-family' then return CabooseRets::MultiFamilyProperty
40
+ end
41
+ return nil
42
+ end
43
+
44
+ def search_fields()
45
+ return {
46
+ 'name' => '',
47
+ 'current_price_gte' => '',
48
+ 'current_price_lte' => '',
49
+ 'bedrooms_gte' => '',
50
+ 'bedrooms_lte' => '',
51
+ 'prop_type' => '',
52
+ 'tot_heat_sqft_gte' => '',
53
+ 'tot_heat_sqft_lte' => '',
54
+ 'neighborhood' => '',
55
+ 'elem_school' => '',
56
+ 'middle_school' => '',
57
+ 'high_school' => '',
58
+ 'address' => '',
59
+ 'lo_lo_code' => '',
60
+ 'remarks_like' => '',
61
+ 'waterfront' => '',
62
+ 'ftr_lotdesc_like' => '',
63
+ 'mls_acct' => '',
64
+ 'subdivision' => '',
65
+ 'foreclosure_yn' => '',
66
+ 'street_name_like' => '',
67
+ 'street_num_like' => '',
68
+ 'date_created_gte' => '',
69
+ 'date_created_lte' => '',
70
+ 'date_modified_gte' => '',
71
+ 'date_modified_lte' => '',
72
+ 'status' => ['active']
73
+ }
74
+ end
75
+
76
+ def search_options
77
+ return {
78
+ 'model' => self.model.to_s,
79
+ 'sort' => 'current_price ASC, mls_acct',
80
+ 'desc' => false,
81
+ 'base_url' => "/#{self.property_type}",
82
+ 'items_per_page' => 10
83
+ }
84
+ end
85
+
86
+ end
@@ -0,0 +1,35 @@
1
+
2
+ <h1>Edit Saved Search</h1>
3
+ <%= render :partial => 'caboose_rets/agents/admin_top_nav' %>
4
+
5
+ <p>Search Type: <%= @search.property_type %></p>
6
+ <p>Parameters: </p>
7
+ <ul><% @search.params.each do |k,v| %><li><%= k %>: <%= v %></li><% end %></ul>
8
+ <div id='savedsearch_<%= @search.id %>_notify'></div>
9
+
10
+ <p style='clear: both;'><input type='button' value='< Back' onclick="window.location='/saved-searches';" /></p>
11
+
12
+ <% content_for :caboose_js do %>
13
+ <%= javascript_include_tag "caboose/model/all" %>
14
+ <script type='text/javascript'>
15
+ $(document).ready(function() {
16
+ m = new ModelBinder({
17
+ name: 'SavedSearch',
18
+ id: <%= @search.id %>,
19
+ update_url: '/saved-searches/<%= @search.id %>',
20
+ authenticity_token: '<%= form_authenticity_token %>',
21
+ attributes: [{
22
+ name: 'notify',
23
+ nice_name: 'Notify me of new properties',
24
+ type: 'checkbox',
25
+ value: <%= @search.notify ? 1 : 0 %>,
26
+ width: 600
27
+ }]
28
+ });
29
+ });
30
+ $(window).load(function() {
31
+ var modal = new CabooseModal(800);
32
+ });
33
+
34
+ </script>
35
+ <% end %>
@@ -0,0 +1,78 @@
1
+ <h1>Saved Searches</h1>
2
+
3
+ <% if @searches && @searches.count > 0 %>
4
+ <table class='data'>
5
+ <tr>
6
+ <th>Parameters</th>
7
+ <th>Notify</th>
8
+ <th>&nbsp;</th>
9
+ <th>&nbsp;</th>
10
+ </tr>
11
+ <% @searches.each do |search| %>
12
+ <tr>
13
+ <td>
14
+ <% search.params.each do |k,v| %>
15
+ <% next if v.nil? || v.length == 0 %>
16
+ <%= k.titleize %>: <%= v %><br />
17
+ <% end %>
18
+ </td>
19
+ <td><div id='savedsearch_<%= search.id %>_notify'></div></td>
20
+ <td><input type='button' value='See Results' onclick="parent.window.location='<%= raw search.uri %>';" /></td>
21
+ <td><input type='button' value='Delete Search' onclick="delete_search(<%= search.id %>);" /></td>
22
+ </tr>
23
+ <% end %>
24
+ </table>
25
+ <% else %>
26
+ <p>You don't have any saved searches yet.</p>
27
+ <% end %>
28
+
29
+ <div id='message'></div>
30
+ <p><input type='button' value='Close' onclick="modal.close();" /></p>
31
+
32
+ <% content_for :caboose_js do %>
33
+ <%= javascript_include_tag "caboose/model/all" %>
34
+ <script type='text/javascript'>
35
+
36
+ $(document).ready(function() {
37
+ <% @searches.each do |search| %>
38
+ m = new ModelBinder({
39
+ name: 'SavedSearch',
40
+ id: <%= search.id %>,
41
+ update_url: '/saved-searches/<%= search.id %>',
42
+ authenticity_token: '<%= form_authenticity_token %>',
43
+ attributes: [{ name: 'notify', nice_name: 'Notify', type: 'checkbox', fixed_placeholder: false, value: <%= search.notify ? 1 : 0 %>, width: 25 }]
44
+ });
45
+ <% end %>
46
+ });
47
+
48
+ function delete_search(search_id, confirm)
49
+ {
50
+ if (!confirm)
51
+ {
52
+ var p = $('<p/>')
53
+ .addClass('note warning')
54
+ .append("Are you sure? This can't be undone. ")
55
+ .append($("<input />").attr('type', 'button').val('Yes').click(function() { delete_search(search_id, true); }))
56
+ .append(" ")
57
+ .append($("<input />").attr('type', 'button').val('No' ).click(function() { $('#message').empty(); modal.autosize(); }))
58
+ modal.autosize(p);
59
+ return;
60
+ }
61
+ modal.autosize("<p class='loading'>Deleting search...</p>");
62
+ $.ajax({
63
+ url: '/saved-searches/' + search_id,
64
+ type: 'delete',
65
+ success: function(resp) {
66
+ if (resp.success) window.location.reload(true);
67
+ if (resp.error) modal.autosize("<p class='note error'>" + resp.error + "</p>");
68
+ }
69
+ });
70
+ }
71
+
72
+ var modal = false;
73
+ $(window).load(function() {
74
+ modal = new CabooseModal(800);
75
+ });
76
+
77
+ </script>
78
+ <% end %>
data/config/routes.rb CHANGED
@@ -60,5 +60,11 @@ CabooseRets::Engine.routes.draw do
60
60
  get "admin/multi-family/:mls_acct/refresh" => "multi_family#admin_refresh"
61
61
  put "admin/multi-family/:mls_acct" => "multi_family#admin_update"
62
62
  post "admin/multi-family/:mls_acct" => "multi_family#admin_update"
63
+
64
+ get "saved-searches" => "saved_searches#index"
65
+ post "saved-searches" => "saved_searches#add"
66
+ get "saved-searches/:id" => "saved_searches#redirect"
67
+ put "saved-searches/:id" => "saved_searches#update"
68
+ delete "saved-searches/:id" => "saved_searches#delete"
63
69
 
64
70
  end
@@ -1,3 +1,3 @@
1
1
  module CabooseRets
2
- VERSION = '0.0.15'
2
+ VERSION = '0.0.16'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caboose-rets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Barry
@@ -39,6 +39,7 @@ files:
39
39
  - app/controllers/caboose_rets/offices_controller.rb
40
40
  - app/controllers/caboose_rets/open_houses_controller.rb
41
41
  - app/controllers/caboose_rets/residential_controller.rb
42
+ - app/controllers/caboose_rets/saved_searches_controller.rb
42
43
  - app/helpers/caboose_rets/application_helper.rb
43
44
  - app/models/caboose_rets/agent.rb
44
45
  - app/models/caboose_rets/commercial_property.rb
@@ -50,6 +51,7 @@ files:
50
51
  - app/models/caboose_rets/residential_property.rb
51
52
  - app/models/caboose_rets/rets_importer.rb
52
53
  - app/models/caboose_rets/rets_plugin.rb
54
+ - app/models/caboose_rets/saved_search.rb
53
55
  - app/views/caboose_rets/agents/_admin_top_nav.html.erb
54
56
  - app/views/caboose_rets/agents/admin_edit.html.erb
55
57
  - app/views/caboose_rets/agents/admin_edit_bio.html.erb
@@ -78,6 +80,8 @@ files:
78
80
  - app/views/caboose_rets/residential/index.html.erb
79
81
  - app/views/caboose_rets/residential/residential_not_exists.html.erb
80
82
  - app/views/caboose_rets/residential/test_form.html.erb
83
+ - app/views/caboose_rets/saved_searches/edit.html.erb
84
+ - app/views/caboose_rets/saved_searches/index.html.erb
81
85
  - config/routes.rb
82
86
  - lib/caboose-rets.rb
83
87
  - lib/caboose_rets/caboose_rets_helper.rb