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
@@ -9,8 +9,8 @@
9
9
  <h1><%= @entity.text %></h1>
10
10
 
11
11
  <ul class="actions">
12
- <li><%= return_icon(admin_poll_path(@entity.poll_id)) %></li>
13
- <li><%= edit_icon(edit_poll_question_path(@entity.id)) %></li>
12
+ <li><%= return_icon(admin_poll_path(id: @entity.poll_id)) %></li>
13
+ <li><%= edit_icon(edit_poll_question_path(id: @entity.id)) %></li>
14
14
  </ul>
15
15
 
16
16
  <% unless @entity.image.blank? %>
@@ -54,12 +54,25 @@
54
54
  <% end %>
55
55
  </dl>
56
56
 
57
- <%= redner partial: 'admin/poll_questions/toggleable', locals: { entity: @entity } %>
57
+ <%=
58
+ render(
59
+ partial: 'shared/admin/toggleable',
60
+ locals: {
61
+ entity: @entity,
62
+ url: toggle_admin_poll_question_path(id: @entity.id)
63
+ }
64
+ )
65
+ %>
58
66
 
59
67
  <section>
60
68
  <h2><%= t(:poll_answer_count, count: @entity.poll_answers_count) %></h2>
61
69
 
62
- <%= render partial: 'shared/admin/list_with_priority', locals: { collection: @entity.poll_answers.ordered_by_priority } %>
70
+ <%=
71
+ render(
72
+ partial: 'shared/admin/list_with_priority',
73
+ locals: { collection: @entity.poll_answers.ordered_by_priority }
74
+ )
75
+ %>
63
76
  </section>
64
77
 
65
78
  <% if @entity.poll_answers.count < 10 %>
@@ -0,0 +1,18 @@
1
+ <div class="image">
2
+ <%= profile_avatar(entity.user) %>
3
+ </div>
4
+ <div class="data">
5
+ <div><%= admin_user_link(entity.user) %> (<%= entity.user.slug %>)</div>
6
+ <div class="info">
7
+ <%= entity.user.email %><br/>
8
+ <%=
9
+ button_tag(
10
+ t(:delete),
11
+ class: 'button-destroy',
12
+ data: {
13
+ url: user_admin_poll_path(id: entity.poll_id, user_id: entity.user_id)
14
+ }
15
+ )
16
+ %>
17
+ </div>
18
+ </div>
@@ -1,6 +1,2 @@
1
- <div>
2
- <%= link_to t('.text'), admin_editable_pages_path %>
3
- </div>
4
- <div class="description">
5
- <%= t('.description') %>
6
- </div>
1
+ <div><%= link_to t('.text'), admin_polls_path %></div>
2
+ <div class="description"><%= t('.description') %></div>
@@ -4,17 +4,41 @@
4
4
  <div class="data">
5
5
  <div><%= admin_poll_link(entity) %></div>
6
6
  <% unless entity.description.blank? %>
7
- <div class="info">
8
- <%= entity.description %>
9
- </div>
7
+ <div class="info">
8
+ <%= entity.description %>
9
+ </div>
10
+ <% end %>
11
+ <% unless entity.end_date.blank? %>
12
+ <div class="info">
13
+ <%= t('activerecord.attributes.poll.end_date') %>:
14
+ <%= time_tag entity.end_date %>
15
+ </div>
10
16
  <% end %>
11
17
  <div class="secondary info">
12
- <%= t(:poll_question_count, count: entity.poll_questions_count) %>
18
+ <%= admin_user_link(entity.user) %>
19
+ <% if entity.poll_questions.any? %>
20
+ <div>
21
+ <div><%= t(:poll_question_count, count: entity.poll_questions_count) %></div>
22
+ <ol>
23
+ <% entity.poll_questions.ordered_by_priority.each do |question| %>
24
+ <li><%= admin_poll_question_link(question) %></li>
25
+ <% end %>
26
+ </ol>
27
+ </div>
28
+ <% end %>
13
29
  </div>
14
30
 
15
- <%= redner partial: 'admin/polls/toggleable', locals: { entity: entity } %>
31
+ <%=
32
+ render(
33
+ partial: 'shared/admin/toggleable',
34
+ locals: {
35
+ entity: entity,
36
+ url: toggle_admin_poll_path(id: entity.id)
37
+ }
38
+ )
39
+ %>
16
40
 
17
41
  <ul class="actions">
18
- <li><%= edit_icon(edit_poll_path(entity)) %></li>
42
+ <li><%= edit_icon(edit_poll_path(id: entity.id)) %></li>
19
43
  </ul>
20
44
  </div>
@@ -0,0 +1,85 @@
1
+ <section>
2
+ <h2><%= t('.heading') %></h2>
3
+
4
+ <div>
5
+ <div>
6
+ <label for="poll-user-id">Id:</label>
7
+ <%= number_field_tag('user_id', '', in: User.ids_range, id: 'poll-user-id') %>
8
+ </div>
9
+ <%= render partial: 'admin/users/search', locals: { target_id: 'poll-user-id' } %>
10
+ <div class="buttons">
11
+ <%=
12
+ button_tag(
13
+ t('.add_user'),
14
+ type: :button,
15
+ class: 'button-save',
16
+ id: 'poll-user-add',
17
+ data: { url: users_admin_poll_path(id: entity.id) }
18
+ )
19
+ %>
20
+ </div>
21
+ </div>
22
+ </section>
23
+
24
+ <script>
25
+ 'use strict';
26
+
27
+ const poll_user_remover = function() {
28
+ const li = this.closest('li[data-id]');
29
+ const url = this.getAttribute('data-url');
30
+ const request = Biovision.new_ajax_request('delete', url, function() {
31
+ li.remove();
32
+ });
33
+
34
+ request.send();
35
+ };
36
+
37
+ document.addEventListener('DOMContentLoaded', function () {
38
+ const button = document.getElementById('poll-user-add');
39
+ const input = document.getElementById('poll-user-id');
40
+ const container = document.getElementById('poll-allowed-users');
41
+
42
+ container.querySelectorAll('button.button-destroy').forEach(function (element) {
43
+ element.addEventListener('click', poll_user_remover);
44
+ });
45
+
46
+ if (button) {
47
+ const url = button.getAttribute('data-url');
48
+ const add_user = function () {
49
+ const response = JSON.parse(this.responseText);
50
+
51
+ if (response.hasOwnProperty('data')) {
52
+ let list = container.querySelector('ul.list-of-entities');
53
+ if (!list) {
54
+ list = document.createElement('ul');
55
+ list.classList.add('list-of-entities');
56
+ container.innerHTML = '';
57
+ container.append(list);
58
+ }
59
+
60
+ list.innerHTML = '';
61
+
62
+ response.data.forEach(function(item) {
63
+ const li = document.createElement('li');
64
+
65
+ li.setAttribute('data-id', item.id);
66
+ li.innerHTML = item.meta.html;
67
+ li.querySelector('button.button-destroy').addEventListener('click', poll_user_remover);
68
+ list.append(li);
69
+ });
70
+ }
71
+ };
72
+
73
+ button.addEventListener('click', function () {
74
+ const user_id = parseInt(input.value);
75
+
76
+ if (user_id > 0) {
77
+ const request = Biovision.new_ajax_request('post', url, add_user);
78
+
79
+ request.setRequestHeader('Content-Type', 'application/json');
80
+ request.send(JSON.stringify({user_id: user_id}));
81
+ }
82
+ });
83
+ }
84
+ });
85
+ </script>
@@ -1,7 +1,7 @@
1
1
  <% content_for :meta_title, t('.title', name: @entity.name) %>
2
2
  <% content_for :breadcrumbs do %>
3
- <%= link_to(t('admin.polls.nav_item.text'), admin_polls_path) %>
4
- <span><%= @entity.name %></span>
3
+ <%= link_to(t('admin.polls.nav_item.text'), admin_polls_path) %>
4
+ <span><%= @entity.name %></span>
5
5
  <% end %>
6
6
 
7
7
  <article>
@@ -9,14 +9,27 @@
9
9
 
10
10
  <ul class="actions">
11
11
  <li><%= back_icon(admin_polls_path) %></li>
12
- <li><%= edit_icon(edit_poll_path(@entity.id)) %></li>
12
+ <li><%= world_icon(poll_path(id: @entity.id)) %></li>
13
+ <li><%= edit_icon(edit_poll_path(id: @entity.id)) %></li>
13
14
  </ul>
14
15
 
16
+ <% if @entity.exclusive? %>
17
+ <nav>
18
+ <%=
19
+ link_to(
20
+ t('.allowed_users'),
21
+ users_admin_poll_path(id: @entity.id),
22
+ class: 'button-nav'
23
+ )
24
+ %>
25
+ </nav>
26
+ <% end %>
27
+
15
28
  <% unless @entity.image.blank? %>
16
- <figure>
17
- <%= poll_image_medium(@entity) %>
18
- <figcaption><%= t('activerecord.attributes.poll.image') %></figcaption>
19
- </figure>
29
+ <figure>
30
+ <%= poll_image_medium(@entity) %>
31
+ <figcaption><%= t('activerecord.attributes.poll.image') %></figcaption>
32
+ </figure>
20
33
  <% end %>
21
34
 
22
35
  <dl>
@@ -36,26 +49,44 @@
36
49
  </dd>
37
50
 
38
51
  <% unless @entity.description.blank? %>
39
- <dt><%= t('activerecord.attributes.poll.description') %></dt>
40
- <dd>
41
- <%= @entity.description %>
42
- </dd>
52
+ <dt><%= t('activerecord.attributes.poll.description') %></dt>
53
+ <dd>
54
+ <%= @entity.description %>
55
+ </dd>
43
56
  <% end %>
44
57
  </dl>
45
58
 
46
- <%= redner partial: 'admin/polls/toggleable', locals: { entity: @entity } %>
59
+ <%=
60
+ render(
61
+ partial: 'shared/admin/toggleable',
62
+ locals: {
63
+ entity: @entity,
64
+ url: toggle_admin_poll_path(id: @entity.id)
65
+ }
66
+ )
67
+ %>
47
68
 
48
69
  <section>
49
70
  <h2><%= t(:poll_question_count, count: @entity.poll_questions_count) %></h2>
50
71
 
51
- <%= render partial: 'shared/admin/list_with_priority', locals: { collection: @entity.poll_questions.ordered_by_priority } %>
72
+ <%=
73
+ render(
74
+ partial: 'shared/admin/list_with_priority',
75
+ locals: { collection: @entity.poll_questions.ordered_by_priority }
76
+ )
77
+ %>
52
78
  </section>
53
79
 
54
80
  <% if @entity.poll_questions.count < 10 %>
55
- <section>
56
- <h2><%= t('poll_questions.new.heading') %></h2>
81
+ <section>
82
+ <h2><%= t('poll_questions.new.heading') %></h2>
57
83
 
58
- <%= render partial: 'poll_questions/form', locals: { entity: @entity.poll_questions.new } %>
59
- </section>
84
+ <%=
85
+ render(
86
+ partial: 'poll_questions/form',
87
+ locals: { entity: @entity.poll_questions.new }
88
+ )
89
+ %>
90
+ </section>
60
91
  <% end %>
61
92
  </article>
@@ -0,0 +1,21 @@
1
+ <% content_for :meta_title, t('.title', name: @entity.name, page: current_page) %>
2
+ <% content_for :breadcrumbs do %>
3
+ <%= link_to(t('admin.polls.nav_item.text'), admin_polls_path) %>
4
+ <%= admin_poll_link(@entity) %>
5
+ <span><%= t('.heading') %></span>
6
+ <% end %>
7
+
8
+ <article>
9
+ <h1><%= @entity.name %></h1>
10
+ <h2><%= t('.heading') %></h2>
11
+
12
+ <ul class="actions">
13
+ <li><%= return_icon(admin_poll_path(id: @entity.id)) %></li>
14
+ </ul>
15
+
16
+ <div id="poll-allowed-users">
17
+ <%= render partial: 'shared/admin/list', locals: { collection: @collection } %>
18
+ </div>
19
+
20
+ <%= render partial: 'admin/polls/entity/user_filter', locals: { entity: @entity } %>
21
+ </article>
@@ -0,0 +1,10 @@
1
+ json.data @entity.poll_users.list_for_administration do |entity|
2
+ json.id entity.id
3
+ json.type entity.class.table_name
4
+ json.attributes do
5
+ json.(entity, :user_id, :poll_id)
6
+ end
7
+ json.meta do
8
+ json.html render(partial: 'admin/poll_users/entity/in_list', formats: [:html], locals: { entity: entity })
9
+ end
10
+ end
@@ -1,42 +1,44 @@
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_answer.poll_question_id') %></dt>
7
+ <dd><%= admin_poll_question_link(entity.poll_question) %></dd>
8
+ <% end %>
2
9
 
3
- <%= form_for entity do |f| %>
4
- <!--
5
- <figure class="preview" id="poll-answer-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_answer_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-answer-image' } %>
15
- <div class="guideline"><%= t('.guidelines.image') %></div>
16
- </figcaption>
17
- </figure>
18
- -->
10
+ <dt><%= f.label :priority %></dt>
11
+ <dd>
12
+ <%=
13
+ f.number_field(
14
+ :priority,
15
+ id: "#{model_name}_priority",
16
+ in: PollAnswer::PRIORITY_RANGE,
17
+ required: true
18
+ )
19
+ %>
20
+ </dd>
19
21
 
20
- <dl>
21
- <% unless entity.id.nil? %>
22
- <dt><%= t('activerecord.attributes.poll_answer.poll_question_id') %></dt>
23
- <dd><%= admin_poll_question_link(entity.poll_question) %></dd>
24
- <% end %>
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: PollAnswer::TEXT_LIMIT,
31
+ placeholder: t('.placeholders.text')
32
+ )
33
+ %>
34
+ <div class="guideline"><%= t('.guidelines.text') %></div>
35
+ </dd>
36
+ </dl>
25
37
 
26
- <dt><%= f.label :priority %></dt>
27
- <dd>
28
- <%= f.number_field :priority, in: PollAnswer::PRIORITY_RANGE, required: true %>
29
- </dd>
38
+ <%= render 'shared/forms/state_container' %>
30
39
 
31
- <dt><%= f.label :text %></dt>
32
- <dd>
33
- <%= f.text_field :text, required: true, size: nil, maxlength: PollAnswer::TEXT_LIMIT, placeholder: t('.placeholders.text') %>
34
- <div class="guideline"><%= t('.guidelines.text') %></div>
35
- </dd>
36
- </dl>
37
-
38
- <div class="buttons">
39
- <%= f.hidden :poll_question_id if entity.id.nil? %>
40
- <%= f.button t(:save), type: :submit %>
41
- </div>
40
+ <div class="buttons">
41
+ <%= f.hidden_field :poll_question_id if entity.id.nil? %>
42
+ <%= f.button t(:save), type: :submit, class: 'button-save' %>
43
+ </div>
42
44
  <% end %>
@@ -0,0 +1,6 @@
1
+ <div>
2
+ <% qid = poll_answer.poll_question_id %>
3
+ <% field_id = "poll_votes_#{qid}_#{poll_answer.id}" %>
4
+ <%= radio_button_tag "poll_votes_#{qid}", poll_answer.id, false, required: true, id: field_id %>
5
+ <%= label_tag(field_id, poll_answer.text) %>
6
+ </div>
@@ -11,7 +11,7 @@
11
11
  <h1><%= t('.heading') %></h1>
12
12
 
13
13
  <ul class="actions">
14
- <li><%= return_icon(admin_poll_answer_path(@entity.id)) %></li>
14
+ <li><%= return_icon(admin_poll_answer_path(id: @entity.id)) %></li>
15
15
  <li class="danger"><%= destroy_icon(@entity) %></li>
16
16
  </ul>
17
17
 
@@ -11,7 +11,7 @@
11
11
 
12
12
  <% unless @entity.poll_id.nil? %>
13
13
  <ul class="actions">
14
- <li><%= return_icon(admin_poll_question_path(@entity.poll_question_id)) %></li>
14
+ <li><%= return_icon(admin_poll_question_path(id: @entity.poll_question_id)) %></li>
15
15
  </ul>
16
16
  <% end %>
17
17