Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Commit 5ce9930

Browse files
committed
Merge pull request #38 from gurix/features/export_data
As an administrator, I want to export my data
2 parents aa97429 + d471c3d commit 5ce9930

29 files changed

Lines changed: 260 additions & 73 deletions

File tree

Gemfile.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
PATH
22
remote: .
33
specs:
4-
helena (0.2.2)
4+
helena (0.3.0)
55
bootstrap-sass
66
breadcrumbs_on_rails
77
haml
88
haml-rails
99
jquery-rails
1010
liquid
11-
mongoid (~> 4.0.0.beta1)
11+
mongoid (~> 4.0.0.rc2)
1212
mongoid-simple-tags
1313
mongoid_orderable
1414
rails (~> 4.1.1)
@@ -107,15 +107,15 @@ GEM
107107
highline (1.6.21)
108108
hike (1.2.3)
109109
i18n (0.6.9)
110-
i18n-tasks (0.4.5)
110+
i18n-tasks (0.5.1)
111111
activesupport
112112
easy_translate (>= 0.5.0)
113113
erubis
114114
highline
115115
slop (>= 3.5.0)
116116
term-ansicolor
117117
terminal-table
118-
jquery-rails (3.1.0)
118+
jquery-rails (3.1.1)
119119
railties (>= 3.0, < 5.0)
120120
thor (>= 0.14, < 2.0)
121121
json (1.8.1)
@@ -129,9 +129,9 @@ GEM
129129
mime-types (1.25.1)
130130
mini_portile (0.6.0)
131131
minitest (5.3.5)
132-
mongoid (4.0.0.rc2)
132+
mongoid (4.0.0)
133133
activemodel (~> 4.0)
134-
moped (~> 2.0.0.rc2)
134+
moped (~> 2.0.0)
135135
origin (~> 2.1)
136136
tzinfo (>= 0.3.37)
137137
mongoid-rspec (1.10.0)
@@ -143,7 +143,7 @@ GEM
143143
mongoid (>= 3.0.3)
144144
mongoid_orderable (4.1.0)
145145
mongoid
146-
moped (2.0.0.rc2)
146+
moped (2.0.0)
147147
bson (~> 2.2)
148148
connection_pool (~> 2.0)
149149
optionable (~> 0.2.0)
@@ -207,7 +207,7 @@ GEM
207207
rspec-expectations (~> 3.0.0)
208208
rspec-mocks (~> 3.0.0)
209209
rspec-support (~> 3.0.0)
210-
rspec-support (3.0.1)
210+
rspec-support (3.0.2)
211211
ruby-progressbar (1.5.1)
212212
rubyzip (1.1.4)
213213
sass (3.2.19)
Lines changed: 29 additions & 0 deletions
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.helena-admin
2+
.actions
3+
font-size: 18pt
4+
5+
.icon
6+
width: 70px
File renamed without changes.

app/controllers/helena/admin/question_groups_controller.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ def create
2222

2323
if @question_group.save
2424
notify_successful_create_for(@question_group.title)
25-
else
26-
notify_error
2725
end
2826
respond_with @question_group, location: admin_survey_question_groups_path(@survey)
2927
end
@@ -37,9 +35,6 @@ def update
3735

3836
if @question_group.update_attributes question_group_params
3937
notify_successful_update_for(@question_group.title)
40-
else
41-
notify_error
42-
add_breadcrumb @question_group.title_was
4338
end
4439
respond_with @question_group, location: admin_survey_question_groups_path(@survey)
4540
end

app/controllers/helena/admin/sessions_controller.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ class SessionsController < Admin::ApplicationController
66
before_filter :load_survey, :add_breadcrumbs
77

88
def index
9-
@sessions = @survey.sessions.desc(:created_at)
9+
respond_to do |format|
10+
@sessions = @survey.sessions.desc(:created_at)
11+
format.html
12+
format.json { render json: @sessions }
13+
format.csv { render text: @sessions.to_csv }
14+
end
1015
end
1116

1217
def destroy

app/controllers/helena/admin/versions_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def update
3434

3535
def destroy
3636
@version = @survey.versions.find_by id: params[:id]
37-
notify_successful_delete_for(@version.version) if @version.destroy
37+
notify_successful_delete_for(@version.version) if @version.destroy && Helena::Session.where(version: @version).destroy
3838
respond_with @version, location: admin_survey_versions_path(@survey)
3939
end
4040

app/models/helena/session.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,39 @@ def reset_tokens
2222
self.view_token = generate_token(25) until unique_token_for?(:view_token)
2323
end
2424

25+
def self.to_csv
26+
CSV.generate do |csv|
27+
csv << fields.keys + uniq_answer_codes
28+
all.each do |session|
29+
csv << session.attributes.values_at(*fields.keys) + answer_values_in(session)
30+
end
31+
end
32+
end
33+
2534
private
2635

36+
def self.answer_values_in(session)
37+
answers = []
38+
answer_codes.each do |code|
39+
answers << session.answers.where(code: code).first.try(&:value)
40+
end
41+
answers
42+
end
43+
44+
def self.answer_codes
45+
answer_codes = []
46+
all.each do |session|
47+
answer_codes += session.answers.map(&:code) - answer_codes
48+
end
49+
answer_codes
50+
end
51+
52+
def self.uniq_answer_codes
53+
answer_codes.map do |code|
54+
fields.keys.include?(code) ? "answer_#{code}" : code
55+
end
56+
end
57+
2758
def generate_token(size)
2859
SecureRandom.base64(size).delete('/+=')[0, size]
2960
end

app/views/helena/admin/question_groups/index.html.haml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
%tbody
1717
- @question_groups.each do |question_group|
1818
%tr[question_group]
19-
%td.position{ data: { title: Helena::QuestionGroup.human_attribute_name(:position) } }
19+
%td.position
2020
= question_group.position
21-
%td.title{ data: { title: Helena::QuestionGroup.human_attribute_name(:title) } }
21+
%td.title
2222
= question_group.title
2323
%td
2424
.btn-group.btn-group-sm

app/views/helena/admin/questions/_labels.html.haml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
%tbody
1212
= form.simple_fields_for :labels do |label|
1313
%tr[label.object]
14-
%td.position{ data: { title: Helena::Label.human_attribute_name(:position) } }
14+
%td.position
1515
= label.input :position, as: :integer, label: false
16-
%td.preselected{ data: { title: Helena::Label.human_attribute_name(:preselected) } }
16+
%td.preselected
1717
= label.input :preselected, as: :boolean, wrapper: :checkbox, label: Helena::Label.human_attribute_name(:preselected)
18-
%td.text{ data: { title: Helena::Label.human_attribute_name(:text) } }
18+
%td.text
1919
= label.input :text, label: false
20-
%td.value{ data: { title: Helena::Label.human_attribute_name(:value) } }
20+
%td.value
2121
= label.input :value, label: false
2222
%td.delete
2323
- unless label.object.new_record?

0 commit comments

Comments
 (0)