2 # This file is part of SMR.
4 # SMR is free software: you can redistribute it and/or modify it under the
5 # terms of the GNU General Public License as published by the Free Software
6 # Foundation, either version 3 of the License, or (at your option) any later
9 # SMR is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # SMR. If not, see <http://www.gnu.org/licenses/>.
16 require 'quoterecords'
19 # Quote Records are a way of ordering market quotes into trends and putting
20 # personal notes on them. Interpretation of events that is.
21 class QuoterecordsController < ApplicationController
24 # Obtains SmrQuoterecords collection.
26 smr_menu_addsubitem('quote records', {
27 'rules'=>:quoterecord_rules,
28 '+ quote'=>:new_quoterecord,
31 @securities = smr_securities_list
32 if params[:id_security] and params[:id_security].to_i>1 then
33 session[:quoterecords_security_index] = @securities.index{|s|s.id==params[:id_security].to_i}
37 when 'previous' then session[:quoterecords_security_index] -= 1
38 when 'next' then session[:quoterecords_security_index] += 1
40 session[:quoterecords_security_index] = 0 if not (0..@securities.count-1) === session[:quoterecords_security_index]
41 @selected_security = @securities[ session[:quoterecords_security_index] ]
43 @intraday_quotes = Quote.where(:id_security=>@selected_security.id, :date=>smr_browse_date.beginning_of_day.to_i..smr_browse_date.end_of_day.to_i).order(date: :desc)
44 @quoterecords, @total_pages = smr_paginate(
46 Smr::Quoterecords.new(current_user.id, @selected_security, smr_browse_date)
48 @sensitivity = QuoterecordThreshold.where(:id_user=>current_user.id, :id_security=>@selected_security.id).first || (QuoterecordThreshold.new(:id_security=>@selected_security.id))
50 @possible_columns = Hash.new
51 Quoterecord.get_columns.collect do |c|
52 @possible_columns[Quoterecord.translate_column(c)] = c
57 # handle new Quote data
60 @quote = Quote.new(:date=>Time.now.to_i)
65 # handles creates and updates
67 if params[:quoterecord][:id].to_i > 0 then
68 qr = Quoterecord.where(:id=>params[:quoterecord][:id], :id_user=>current_user.id).first
69 qr.update(quoterecord_params)
71 qr = Quoterecord.new(quoterecord_params)
72 qr.id_user = current_user.id
73 qr.created = Time.now.to_i
82 # present exiting Quoterecord for editing.
85 @quoterecord = Quoterecord.where(:id=>params[:id], :id_user=>current_user.id).first
90 # View QuoterecordRule.
99 # internal helper defining parameters acceptable for quoterecord
100 def quoterecord_params
101 params.require(:quoterecord).permit(
102 :id_security, :id_quote, :column, :comment, :is_pivotal_point, :is_uphit,
103 :is_downhit, :is_signal