biovision-poll 0.0.170908 → 0.1.180917.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +5 -5
  2. data/app/controllers/admin/poll_answers_controller.rb +1 -0
  3. data/app/controllers/admin/poll_questions_controller.rb +1 -0
  4. data/app/controllers/admin/polls_controller.rb +23 -0
  5. data/app/controllers/poll_answers_controller.rb +5 -5
  6. data/app/controllers/poll_questions_controller.rb +5 -5
  7. data/app/controllers/polls_controller.rb +36 -8
  8. data/app/helpers/polls_helper.rb +8 -3
  9. data/app/models/poll.rb +64 -5
  10. data/app/models/poll_answer.rb +5 -0
  11. data/app/models/poll_question.rb +4 -0
  12. data/app/models/poll_user.rb +10 -0
  13. data/app/views/admin/index/dashboard/_biovision_poll.html.erb +10 -0
  14. data/app/views/admin/poll_answers/entity/_in_list.html.erb +11 -12
  15. data/app/views/admin/poll_answers/show.html.erb +2 -2
  16. data/app/views/admin/poll_questions/entity/_in_list.html.erb +29 -8
  17. data/app/views/admin/poll_questions/show.html.erb +17 -4
  18. data/app/views/admin/poll_users/entity/_in_list.html.erb +18 -0
  19. data/app/views/admin/polls/_nav_item.html.erb +2 -6
  20. data/app/views/admin/polls/entity/_in_list.html.erb +30 -6
  21. data/app/views/admin/polls/entity/_user_filter.html.erb +85 -0
  22. data/app/views/admin/polls/show.html.erb +48 -17
  23. data/app/views/admin/polls/users.html.erb +21 -0
  24. data/app/views/admin/polls/users.jbuilder +10 -0
  25. data/app/views/poll_answers/_form.html.erb +39 -37
  26. data/app/views/poll_answers/_poll_answer.html.erb +6 -0
  27. data/app/views/poll_answers/edit.html.erb +1 -1
  28. data/app/views/poll_answers/new.html.erb +1 -1
  29. data/app/views/poll_questions/_form.html.erb +55 -47
  30. data/app/views/poll_questions/_poll_question.html.erb +10 -0
  31. data/app/views/poll_questions/edit.html.erb +1 -1
  32. data/app/views/poll_questions/new.html.erb +1 -1
  33. data/app/views/polls/_form.html.erb +49 -39
  34. data/app/views/polls/_list.html.erb +11 -0
  35. data/app/views/polls/_poll.html.erb +22 -0
  36. data/app/views/polls/edit.html.erb +1 -1
  37. data/app/views/polls/entity/_in_list.html.erb +20 -0
  38. data/app/views/polls/index.html.erb +9 -0
  39. data/app/views/polls/results.html.erb +6 -0
  40. data/app/views/polls/show.html.erb +3 -0
  41. data/config/locales/polls-ru.yml +36 -2
  42. data/config/routes.rb +27 -10
  43. data/db/migrate/20170906000001_create_polls.rb +19 -6
  44. data/db/migrate/20170906000002_create_poll_questions.rb +1 -1
  45. data/db/migrate/20170906000003_create_poll_answers.rb +1 -1
  46. data/db/migrate/20170906000004_create_poll_votes.rb +2 -2
  47. data/db/migrate/20180412000010_create_poll_users.rb +21 -0
  48. data/db/migrate/20180903111111_rename_vote_footprint.rb +11 -0
  49. data/lib/biovision/poll/engine.rb +10 -6
  50. data/lib/biovision/poll/version.rb +1 -1
  51. metadata +20 -6
  52. data/app/views/admin/poll_questions/_toggleable.html.erb +0 -7
  53. data/app/views/admin/polls/_toggleable.html.erb +0 -7
@@ -1,54 +1,62 @@
1
- <%= render partial: 'shared/list_of_errors', locals: { entity: entity } %>
1
+ <% model_name = entity.class.to_s.underscore %>
2
+ <%= form_with model: entity, html: { id: "#{model_name}-form" } do |f| %>
3
+ <%= render partial: 'shared/list_of_errors', locals: { entity: entity } %>
4
+ <dl>
5
+ <% unless entity.id.nil? %>
6
+ <dt><%= t('activerecord.attributes.poll_question.poll_id') %></dt>
7
+ <dd><%= admin_poll_link(entity.poll) %></dd>
8
+ <% end %>
2
9
 
3
- <%= form_for entity do |f| %>
4
- <!--
5
- <figure class="preview" id="poll-question-image">
6
- <% if entity.image.blank? %>
7
- <% image_path = 'biovision/base/placeholders/image.svg' %>
8
- <% else %>
9
- <% image_path = entity.image.url %>
10
- <% end %>
11
- <%= label_tag(:poll_question_image, image_tag(image_path, alt: t('activerecord.attributes.poll.image'))) %>
12
- <figcaption>
13
- <%= f.label :image %>
14
- <%= f.file_field :image, accept: 'image/jpeg,image/png', data: { image: 'poll-question-image' } %>
15
- <div class="guideline"><%= t('.guidelines.image') %></div>
16
- </figcaption>
17
- </figure>
18
- -->
19
-
20
- <dl>
21
- <% unless entity.id.nil? %>
22
- <dt><%= t('activerecord.attributes.poll_question.poll_id') %></dt>
23
- <dd><%= admin_poll_link(entity.poll) %></dd>
24
- <% end %>
10
+ <dt><%= f.label :priority %></dt>
11
+ <dd>
12
+ <%=
13
+ f.number_field(
14
+ :priority,
15
+ id: "#{model_name}_priority",
16
+ in: PollQuestion::PRIORITY_RANGE,
17
+ required: true
18
+ )
19
+ %>
20
+ </dd>
25
21
 
26
- <dt><%= f.label :priority %></dt>
27
- <dd>
28
- <%= f.number_field :priority, in: PollQuestion::PRIORITY_RANGE, required: true %>
29
- </dd>
22
+ <dt><%= f.label :text %></dt>
23
+ <dd>
24
+ <%=
25
+ f.text_field(
26
+ :text,
27
+ id: "#{model_name}_text",
28
+ required: true,
29
+ size: nil,
30
+ maxlength: PollQuestion::TEXT_LIMIT,
31
+ placeholder: t('.placeholders.text')
32
+ )
33
+ %>
34
+ <div class="guideline"><%= t('.guidelines.text') %></div>
35
+ </dd>
30
36
 
31
- <dt><%= f.label :text %></dt>
32
- <dd>
33
- <%= f.text_field :text, required: true, size: nil, maxlength: PollQuestion::TEXT_LIMIT, placeholder: t('.placeholders.text') %>
34
- <div class="guideline"><%= t('.guidelines.text') %></div>
35
- </dd>
37
+ <!--
38
+ <dt><%= f.label :comment %></dt>
39
+ <dd>
40
+ <%=
41
+ f.text_field(
42
+ :comment,
43
+ id: "#{model_name}_comment",
44
+ size: nil,
45
+ maxlength: PollQuestion::COMMENT_LIMIT,
46
+ placeholder: t('.placeholders.comment')
47
+ )
48
+ %>
49
+ <div class="guideline"><%= t('.guidelines.comment') %></div>
50
+ </dd>
51
+ -->
36
52
 
37
- <dt><%= f.label :comment %></dt>
38
- <dd>
39
- <%= f.text_field :comment, size: nil, maxlength: PollQuestion::COMMENT_LIMIT, placeholder: t('.placeholders.comment') %>
40
- <div class="guideline"><%= t('.guidelines.comment') %></div>
41
- </dd>
42
- </dl>
53
+ <%= render(partial: 'shared/forms/entity_flags', locals: { f: f }) %>
54
+ </dl>
43
55
 
44
- <ul class="flags">
45
- <% PollQuestion.toggleable_attributes.each do |flag| %>
46
- <li><%= f.check_box flag %><%= f.label flag %></li>
47
- <% end %>
48
- </ul>
56
+ <%= render 'shared/forms/state_container' %>
49
57
 
50
- <div class="buttons">
51
- <%= f.hidden :poll_id if entity.id.nil? %>
52
- <%= f.button t(:save), type: :submit %>
53
- </div>
58
+ <div class="buttons">
59
+ <%= f.hidden_field :poll_id if entity.id.nil? %>
60
+ <%= f.button t(:save), type: :submit, class: 'button-save' %>
61
+ </div>
54
62
  <% end %>
@@ -0,0 +1,10 @@
1
+ <section>
2
+ <h2><%= poll_question.text %></h2>
3
+ <% unless poll_question.comment.blank? %>
4
+ <div class="description"><%= poll_question.comment %></div>
5
+ <% end %>
6
+
7
+ <div class="answers">
8
+ <%= render poll_question.poll_answers.ordered_by_priority %>
9
+ </div>
10
+ </section>
@@ -10,7 +10,7 @@
10
10
  <h1><%= t('.heading') %></h1>
11
11
 
12
12
  <ul class="actions">
13
- <li><%= return_icon(admin_poll_question_path(@entity.id)) %></li>
13
+ <li><%= return_icon(admin_poll_question_path(id: @entity.id)) %></li>
14
14
  <li class="danger"><%= destroy_icon(@entity) %></li>
15
15
  </ul>
16
16
 
@@ -10,7 +10,7 @@
10
10
 
11
11
  <% unless @entity.poll_id.nil? %>
12
12
  <ul class="actions">
13
- <li><%= return_icon(admin_poll_path(@entity.poll_id)) %></li>
13
+ <li><%= return_icon(admin_poll_path(id: @entity.poll_id)) %></li>
14
14
  </ul>
15
15
  <% end %>
16
16
 
@@ -1,46 +1,56 @@
1
- <%= render partial: 'shared/list_of_errors', locals: { entity: entity } %>
1
+ <% model_name = entity.class.to_s.underscore %>
2
+ <%= form_with model: entity, html: { id: "#{model_name}-form" } do |f| %>
3
+ <%= render partial: 'shared/list_of_errors', locals: { entity: entity } %>
2
4
 
3
- <%= form_for entity do |f| %>
4
- <figure class="preview" id="poll-image">
5
- <% if entity.image.blank? %>
6
- <% image_path = 'biovision/base/placeholders/image.svg' %>
7
- <% else %>
8
- <% image_path = entity.image.url %>
9
- <% end %>
10
- <%= label_tag(:poll_image, image_tag(image_path, alt: t('activerecord.attributes.poll.image'))) %>
11
- <figcaption>
12
- <%= f.label :image %>
13
- <%= f.file_field :image, accept: 'image/jpeg,image/png', data: { image: 'poll-image' } %>
14
- <div class="guideline"><%= t('.guidelines.image') %></div>
15
- </figcaption>
16
- </figure>
5
+ <dl>
6
+ <dt><%= f.label :name %></dt>
7
+ <dd>
8
+ <%=
9
+ f.text_field(
10
+ :name,
11
+ id: "#{model_name}_name",
12
+ required: true,
13
+ size: nil,
14
+ maxlength: Poll::NAME_LIMIT,
15
+ placeholder: t('.placeholders.name')
16
+ )
17
+ %>
18
+ <div class="guideline"><%= t('.guidelines.name') %></div>
19
+ </dd>
17
20
 
18
- <dl>
19
- <dt><%= f.label :name %></dt>
20
- <dd>
21
- <%= f.text_field :name, required: true, size: nil, maxlength: Poll::NAME_LIMIT, placeholder: t('.placeholders.name') %>
22
- <div class="guideline"><%= t('.guidelines.name') %></div>
23
- </dd>
21
+ <!--
22
+ <dt><%= f.label :description %></dt>
23
+ <dd>
24
+ <%=
25
+ f.text_field(
26
+ :description,
27
+ id: "#{model_name}_description",
28
+ size: nil,
29
+ maxlength: Poll::DESCRIPTION_LIMIT,
30
+ placeholder: t('.placeholders.description')
31
+ )
32
+ %>
33
+ <div class="guideline"><%= t('.guidelines.description') %></div>
34
+ </dd>
35
+ -->
24
36
 
25
- <dt><%= f.label :description %></dt>
26
- <dd>
27
- <%= f.text_field :description, size: nil, maxlength: Poll::DESCRIPTION_LIMIT, placeholder: t('.placeholders.description') %>
28
- <div class="guideline"><%= t('.guidelines.description') %></div>
29
- </dd>
37
+ <dt><%= f.label :end_date %></dt>
38
+ <dd>
39
+ <%=
40
+ f.date_field(
41
+ :end_date,
42
+ id: "#{model_name}_end_date",
43
+ size: 10
44
+ )
45
+ %>
46
+ </dd>
30
47
 
31
- <dt><%= f.label :end_date %></dt>
32
- <dd>
33
- <%= f.date_field :end_date %>
34
- </dd>
35
- </dl>
48
+ <%= render(partial: 'shared/forms/entity_flags', locals: { f: f }) %>
49
+ </dl>
36
50
 
37
- <ul class="flags">
38
- <% Poll.toggleable_attributes.each do |flag| %>
39
- <li><%= f.check_box flag %><%= f.label flag %></li>
40
- <% end %>
41
- </ul>
51
+ <%= render 'shared/forms/state_container' %>
42
52
 
43
- <div class="buttons">
44
- <%= f.button t(:save), type: :submit %>
45
- </div>
53
+ <div class="buttons">
54
+ <%= f.button t(:save), type: :submit, class: 'button-save' %>
55
+ </div>
46
56
  <% end %>
@@ -0,0 +1,11 @@
1
+ <% if collection.any? %>
2
+ <ul class="biovision-polls">
3
+ <% collection.each do |entity| %>
4
+ <li>
5
+ <%= render partial: 'polls/entity/in_list', locals: { entity: entity } %>
6
+ </li>
7
+ <% end %>
8
+ </ul>
9
+ <% else %>
10
+ <div class="message-box-warning"><%= t('.no_polls') %></div>
11
+ <% end %>
@@ -0,0 +1,22 @@
1
+ <article class="biovision-poll">
2
+ <h1><%= poll.name %></h1>
3
+
4
+ <% if poll.editable_by?(current_user) %>
5
+ <ul class="actions">
6
+ <li><%= gear_icon(admin_poll_path(id: poll.id)) %></li>
7
+ </ul>
8
+ <% end %>
9
+
10
+ <div class="description"><%= poll.description %></div>
11
+
12
+ <%= form_tag results_poll_path(id: poll.id), method: :post do %>
13
+ <%= render poll.poll_questions.ordered_by_priority %>
14
+
15
+ <div class="buttons">
16
+ <%= button_tag t('.answer'), type: :submit %>
17
+ <% if poll.open_results? %>
18
+ <%= link_to('Результаты', results_poll_path(id: poll.id), class: 'nav-button') %>
19
+ <% end %>
20
+ </div>
21
+ <% end %>
22
+ </article>
@@ -9,7 +9,7 @@
9
9
  <h1><%= t('.heading') %></h1>
10
10
 
11
11
  <ul class="actions">
12
- <li><%= return_icon(admin_poll_path(@entity.id)) %></li>
12
+ <li><%= return_icon(admin_poll_path(id: @entity.id)) %></li>
13
13
  <li class="danger"><%= destroy_icon(@entity) %></li>
14
14
  </ul>
15
15
 
@@ -0,0 +1,20 @@
1
+ <div class="name"><%= poll_link(entity) %></div>
2
+ <% unless entity.description.blank? %>
3
+ <div class="description"><%= entity.description %></div>
4
+ <% end %>
5
+ <div class="info">
6
+ <div class="user"><%= user_link(entity.user) %></div>
7
+ <div class="question_count"><%= t(:poll_question_count, count: entity.poll_questions_count) %></div>
8
+ <% if entity.active? %>
9
+ <div class="state active">
10
+ <%= t('activerecord.attributes.poll.active') %>
11
+ <% unless entity.end_date.blank? %>
12
+ <%= t('.until') %> <%= time_tag(entity.end_date) %>
13
+ <% end %>
14
+ </div>
15
+ <% else %>
16
+ <div class="state inactive">
17
+ <%= t('.poll_ended') %>
18
+ </div>
19
+ <% end %>
20
+ </div>
@@ -0,0 +1,9 @@
1
+ <% content_for :meta_title, t('.title', page: current_page) %>
2
+
3
+ <article>
4
+ <h1><%= t('.heading') %></h1>
5
+
6
+ <%= paginate @collection %>
7
+ <%= render partial: 'list', locals: { collection: @collection } %>
8
+ <%= paginate @collection %>
9
+ </article>
@@ -0,0 +1,6 @@
1
+ <% content_for :meta_title, t('.title', name: @entity.name) %>
2
+
3
+ <article>
4
+ <h1><%= @entity.name %></h1>
5
+ <h2><%= t('.heading') %></h2>
6
+ </article>
@@ -0,0 +1,3 @@
1
+ <% content_for :meta_title, t('.title', name: @entity.name) %>
2
+
3
+ <%= render @entity %>
@@ -22,13 +22,15 @@ ru:
22
22
  poll: "Опрос"
23
23
  poll_answer: "Ответ на вопрос"
24
24
  poll_question: "Вопрос"
25
+ poll_user: "Допущенный к голосованию пользователь"
25
26
  poll_vote: "Голос в опросе"
26
27
  attributes:
27
28
  poll:
28
29
  active: "Можно голосовать"
29
- anonymous_votes: "Разрешить анонммные голоса"
30
+ anonymous_votes: "Разрешить анонимные голоса"
30
31
  description: "Описание"
31
32
  end_date: "Дата окончания"
33
+ exclusive: "Эксклюзивный"
32
34
  image: "Картинка"
33
35
  name: "Название"
34
36
  open_results: "Результаты видны всем"
@@ -54,8 +56,12 @@ ru:
54
56
  poll_id: "Опрос"
55
57
  priority: "Порядок сортировки"
56
58
  text: "Текст"
59
+ poll_user:
60
+ poll: "Опрос"
61
+ user: "Пользователь"
62
+ user_id: "Пользователь"
57
63
  poll_vote:
58
- footprint: "Отпечаток"
64
+ slug: "Идентификатор"
59
65
  poll_answer: "Ответ"
60
66
  user: "Пользователь"
61
67
  admin:
@@ -68,12 +74,24 @@ ru:
68
74
  title: "Опросы, страница %{page}"
69
75
  show:
70
76
  title: "Опрос «%{name}»"
77
+ allowed_users: "Допущенные пользователи"
78
+ users:
79
+ title: "Опрос «%{name}»: допущенные пользователи, страница %{page}"
80
+ heading: "Допущенные пользователи"
81
+ entity:
82
+ user_filter:
83
+ heading: "Добавить пользователя"
84
+ add_user: "Добавить пользователя"
71
85
  poll_questions:
72
86
  show:
73
87
  title: "Опрос «%{poll}»: %{question}"
74
88
  poll_answers:
75
89
  show:
76
90
  title: "Опрос «%{poll}»: %{question} — «%{answer}»"
91
+ index:
92
+ dashboard:
93
+ biovision_poll:
94
+ heading: "Опросы"
77
95
  polls:
78
96
  new:
79
97
  heading: "Новый опрос"
@@ -93,6 +111,22 @@ ru:
93
111
  placeholders:
94
112
  description: "Нужно проголосовать за лучший вариант"
95
113
  name: "О принятии какого-либо решения"
114
+ index:
115
+ title: "Опросы, страница %{page}"
116
+ heading: "Опросы"
117
+ list:
118
+ no_polls: "Опросов нет"
119
+ entity:
120
+ in_list:
121
+ until: "до"
122
+ poll_ended: "Опрос окончен"
123
+ show:
124
+ title: "Опрос «%{name}»"
125
+ poll:
126
+ answer: "Ответить"
127
+ results:
128
+ title: "Результаты опроса «%{name}»"
129
+ heading: "Результаты опроса"
96
130
  poll_questions:
97
131
  new:
98
132
  heading: "Новый вопрос"
data/config/routes.rb CHANGED
@@ -1,18 +1,35 @@
1
- Biovision::Poll::Engine.routes.draw do
2
- resources :polls
3
- resources :poll_questions, :poll_answers, except: [:index, :new, :show]
1
+ Rails.application.routes.draw do
2
+ resources :polls, :poll_questions, :poll_answers, only: %i[update destroy]
4
3
 
5
- namespace :admin do
6
- resources :polls, only: [:index, :show] do
4
+ scope '(:locale)', constraints: { locale: /ru|en|sv/ } do
5
+ resources :polls, except: %i[update destroy] do
7
6
  member do
8
- post 'toggle', defaults: { format: :json }
7
+ post 'results' => :answer
8
+ get 'results'
9
9
  end
10
10
  end
11
- resources :poll_questions, only: [:show] do
12
- member do
13
- post 'toggle', defaults: { format: :json }
11
+ resources :poll_questions, :poll_answers, only: %i[create edit]
12
+
13
+ namespace :admin do
14
+ resources :polls, only: %i[index show] do
15
+ member do
16
+ post 'toggle', defaults: { format: :json }
17
+ get 'users'
18
+ post 'users' => :add_user, defaults: { format: :json }
19
+ delete 'users/:user_id' => :remove_user, as: :user, defaults: { format: :json }
20
+ end
21
+ end
22
+ resources :poll_questions, only: :show do
23
+ member do
24
+ post 'toggle', defaults: { format: :json }
25
+ post 'priority', defaults: { format: :json }
26
+ end
27
+ end
28
+ resources :poll_answers, only: :show do
29
+ member do
30
+ post 'priority', defaults: { format: :json }
31
+ end
14
32
  end
15
33
  end
16
- resources :poll_answers, only: [:show]
17
34
  end
18
35
  end