Permalink
Browse files

commit iniziale

  • Loading branch information...
1 parent 3cd3331 commit 6f7db3b077db872e8d30689590f4bb95c9e814e2 @larcara larcara committed Feb 2, 2013
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -14,7 +14,12 @@ def all
def index
template=params[:survey_template_id]
@survey_template=SurveyTemplate.find(template)
- @survey_responses = SurveyResponse.where(:survey_template_id=>@survey_template.id)
+ if current_user.is_admin?
+ @survey_responses = SurveyResponse.where(:survey_template_id=>@survey_template.id)
+ else
+ @survey_responses = SurveyResponse.where(:survey_template_id=>@survey_template.id, :user_id => current_user.id)
+ end
+
respond_to do |format|
format.html # index.html.erb
@@ -39,8 +44,12 @@ def new
template=params[:survey_template_id]
@survey_template=SurveyTemplate.find(template)
@survey_response = SurveyResponse.new(:survey_template_id => @survey_template.id, :user_id=>current_user.id, :azienda=>current_user.username)
- @survey_template.survey_template_lines.each do |line|
- @survey_response.survey_response_lines.build(:survey_template_line_id=>line.id)
+ @survey_template.survey_template_lines.roots.each do |r|
+ @survey_response.survey_response_lines.build(:survey_template_line_id=>r.id)
+ r.children.each do |l|
+ @survey_response.survey_response_lines.build(:survey_template_line_id=>l.id)
+ end
+
end
respond_to do |format|
@@ -1,4 +1,15 @@
class SurveyTemplateLinesController < ApplicationController
+
+ def move_up
+ @survey_template_line = SurveyTemplateLine.find(params[:id])
+ @survey_template_line.move_left
+ redirect_to edit_survey_template_path(@survey_template_line.survey_template), :notice => "spostamento eseguito correttamente."
+ end
+ def move_down
+ @survey_template_line = SurveyTemplateLine.find(params[:id])
+ @survey_template_line.move_right
+ redirect_to edit_survey_template_path(@survey_template_line.survey_template), :notice => "spostamento eseguito correttamente."
+ end
def index
@survey_template_lines = SurveyTemplateLine.all
end
@@ -10,6 +21,9 @@ def show
def new
@survey_template_line = SurveyTemplateLine.new(:survey_template_id=>params[:survey_template_id])
end
+ def new_group
+ @survey_template_line = SurveyTemplateLine.new(:survey_template_id=>params[:survey_template_id])
+ end
def create
@survey_template_line = SurveyTemplateLine.new(params[:survey_template_line])
@@ -22,6 +36,11 @@ def create
def edit
@survey_template_line = SurveyTemplateLine.find(params[:id])
+ if @survey_template_line.root?
+ render :new_group
+ else
+ render :edit
+ end
end
def update
@@ -5,19 +5,31 @@ def export
@survey_template = SurveyTemplate.find(params[:id])
spreadsheet = StringIO.new ""
book = Spreadsheet::Workbook.new
+ linea=0
@survey_template.survey_responses.each do |sr|
i||=0
i=i+1
sheet = book.create_worksheet#(:name=>"#{i} #{sr.azienda}")
bold = Spreadsheet::Format.new :weight => :bold
-
sheet.update_row 0, @survey_template.nome
sheet.update_row 1, "","Azienda",sr.azienda
-
sheet.update_row 2, "","Nome e Cognome","#{sr.nome} #{sr.cognome}"
sheet.update_row 3, "","Telefono","#{sr.telefono}"
sheet.update_row 4, "","Email","#{sr.email}"
sheet.update_row 5, "CODICE", "DESCRIZIONE","UNITA' DI MISURA", "DATI ANNUALI"
+ sheet.column(1).width=100
+ format = Spreadsheet::Format.new
+ format.top=:medium
+ format.bottom=:medium
+ format.left=:medium
+ format.right=:medium
+ bold = format.clone
+ bold.font.weight=:bold
+ grigio = format.clone
+ grigio.font.weight=:bold
+ grigio.pattern=1
+ grigio.pattern_bg_color=:gray
+ grigio.pattern_fg_color=:gray
linea =5
sheet.row(linea).set_format(0, bold)
sheet.row(linea).set_format(1, bold)
@@ -29,16 +41,20 @@ def export
unless gruppo.eql?(srl.gruppo)
gruppo= srl.gruppo
sheet.update_row linea, "", gruppo
- sheet.row(linea).set_format(0, bold)
- sheet.row(linea).set_format(1, bold)
- sheet.row(linea).set_format(2, bold)
- sheet.row(linea).set_format(3, bold)
+ sheet.row(linea).set_format(0, grigio)
+ sheet.row(linea).set_format(1, grigio)
+ sheet.row(linea).set_format(2, grigio)
linea+=1
end
sheet.update_row linea, srl.codice, srl.domanda,srl.um, srl.risposta
- linea+=1
+ (0..4).each{|i| sheet.row(linea).set_format(i, format)}
+ linea+=1
+ end
+ linea.times do |i|
+ sheet.row(i).height=25
end
end
+
book.write spreadsheet
send_data spreadsheet.string, :type=>"application/excel", :disposition=>'attachment', :filename => 'out.xls'
end
@@ -1,7 +1,8 @@
class SurveyResponse < ActiveRecord::Base
attr_accessible :survey_response_lines_attributes , :survey_template_id , :user_id, :azienda , :nome, :cognome, :telefono, :email, :data_compilazione
- has_many :survey_response_lines
+ has_many :survey_response_lines , :dependent => :delete_all
belongs_to :survey_template
+ validates_associated :survey_template
accepts_nested_attributes_for :survey_response_lines
end
Oops, something went wrong.

0 comments on commit 6f7db3b

Please sign in to comment.