biovision-poll 0.0.170908

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +26 -0
  5. data/app/assets/config/biovision_poll_manifest.js +2 -0
  6. data/app/assets/javascripts/biovision/poll/application.js +13 -0
  7. data/app/assets/stylesheets/biovision/poll/polls.scss +0 -0
  8. data/app/controllers/admin/poll_answers_controller.rb +23 -0
  9. data/app/controllers/admin/poll_questions_controller.rb +22 -0
  10. data/app/controllers/admin/polls_controller.rb +27 -0
  11. data/app/controllers/biovision/poll/application_controller.rb +7 -0
  12. data/app/controllers/poll_answers_controller.rb +55 -0
  13. data/app/controllers/poll_questions_controller.rb +55 -0
  14. data/app/controllers/polls_controller.rb +59 -0
  15. data/app/helpers/biovision/poll/application_helper.rb +6 -0
  16. data/app/helpers/polls_helper.rb +37 -0
  17. data/app/jobs/biovision/poll/application_job.rb +6 -0
  18. data/app/mailers/biovision/poll/application_mailer.rb +8 -0
  19. data/app/models/application_record.rb +3 -0
  20. data/app/models/biovision/poll/application_record.rb +7 -0
  21. data/app/models/poll.rb +56 -0
  22. data/app/models/poll_answer.rb +62 -0
  23. data/app/models/poll_question.rb +65 -0
  24. data/app/models/poll_vote.rb +21 -0
  25. data/app/uploaders/poll_image_uploader.rb +46 -0
  26. data/app/views/admin/poll_answers/entity/_in_list.html.erb +20 -0
  27. data/app/views/admin/poll_answers/show.html.erb +58 -0
  28. data/app/views/admin/poll_questions/_toggleable.html.erb +7 -0
  29. data/app/views/admin/poll_questions/entity/_in_list.html.erb +20 -0
  30. data/app/views/admin/poll_questions/show.html.erb +72 -0
  31. data/app/views/admin/poll_votes/entity/_in_list.html.erb +16 -0
  32. data/app/views/admin/polls/_nav_item.html.erb +6 -0
  33. data/app/views/admin/polls/_toggleable.html.erb +7 -0
  34. data/app/views/admin/polls/entity/_in_list.html.erb +20 -0
  35. data/app/views/admin/polls/index.html.erb +16 -0
  36. data/app/views/admin/polls/show.html.erb +61 -0
  37. data/app/views/layouts/biovision/poll/application.html.erb +14 -0
  38. data/app/views/poll_answers/_form.html.erb +42 -0
  39. data/app/views/poll_answers/edit.html.erb +19 -0
  40. data/app/views/poll_answers/new.html.erb +19 -0
  41. data/app/views/poll_questions/_form.html.erb +54 -0
  42. data/app/views/poll_questions/edit.html.erb +18 -0
  43. data/app/views/poll_questions/new.html.erb +18 -0
  44. data/app/views/polls/_form.html.erb +46 -0
  45. data/app/views/polls/edit.html.erb +17 -0
  46. data/app/views/polls/new.html.erb +15 -0
  47. data/config/locales/polls-ru.yml +131 -0
  48. data/config/routes.rb +18 -0
  49. data/db/migrate/20170906000001_create_polls.rb +57 -0
  50. data/db/migrate/20170906000002_create_poll_questions.rb +22 -0
  51. data/db/migrate/20170906000003_create_poll_answers.rb +20 -0
  52. data/db/migrate/20170906000004_create_poll_votes.rb +20 -0
  53. data/lib/biovision/poll.rb +7 -0
  54. data/lib/biovision/poll/engine.rb +14 -0
  55. data/lib/biovision/poll/version.rb +5 -0
  56. data/lib/tasks/biovision/poll_tasks.rake +4 -0
  57. metadata +253 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a178bf343ce1bc3f702577d444db93e3efdd58e6
4
+ data.tar.gz: 2997c450eb8e26ea18da19910aef9f1e9f5c0698
5
+ SHA512:
6
+ metadata.gz: 8f5217cc9b0e0bb6a367da4dddab9ed70fa88e9fbfd79f2a6e7d1f0e79fa5b4846697200b3fed8a99414718bc5ff175e2eac6474ac7ed4c65e22bcb7f2ef593d
7
+ data.tar.gz: 45ba435cc521559641c5eb4e86d19878d8e32d92e8b22971ccb9596a3620214a05992676b51c7f4bb8df471739f3efc83e123fbee62a4fcf35093fa0b3b05ff5
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Maxim Khan-Magomedov
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Biovision::Poll
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'biovision-poll'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install biovision-poll
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Biovision::Poll'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/biovision/poll .js
2
+ //= link_directory ../stylesheets/biovision/poll .css
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
File without changes
@@ -0,0 +1,23 @@
1
+ class Admin::PollAnswersController < AdminController
2
+ include ToggleableEntity
3
+
4
+ before_action :set_entity
5
+
6
+ # get /admin/poll_answers/:id
7
+ def show
8
+ @collection = @entity.poll_votes.page_for_administration(current_page)
9
+ end
10
+
11
+ private
12
+
13
+ def restrict_access
14
+ require_privilege_group :poll_managers
15
+ end
16
+
17
+ def set_entity
18
+ @entity = PollAnswer.find_by(id: params[:id])
19
+ if @entity.nil?
20
+ handle_http_404('Cannot find poll answer')
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ class Admin::PollQuestionsController < AdminController
2
+ include ToggleableEntity
3
+
4
+ before_action :set_entity
5
+
6
+ # get /admin/poll_questions/:id
7
+ def show
8
+ end
9
+
10
+ private
11
+
12
+ def restrict_access
13
+ require_privilege_group :poll_managers
14
+ end
15
+
16
+ def set_entity
17
+ @entity = PollQuestion.find_by(id: params[:id])
18
+ if @entity.nil?
19
+ handle_http_404('Cannot find poll question')
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ class Admin::PollsController < AdminController
2
+ include ToggleableEntity
3
+
4
+ before_action :set_entity, except: [:index]
5
+
6
+ # get /admin/polls
7
+ def index
8
+ @collection = Poll.page_for_administration(current_page)
9
+ end
10
+
11
+ # get /admin/polls/:id
12
+ def show
13
+ end
14
+
15
+ private
16
+
17
+ def restrict_access
18
+ require_privilege_group :poll_managers
19
+ end
20
+
21
+ def set_entity
22
+ @entity = Poll.find_by(id: params[:id])
23
+ if @entity.nil?
24
+ handle_http_404('Cannot find poll')
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ module Biovision
2
+ module Poll
3
+ class ApplicationController < ActionController::Base
4
+ protect_from_forgery with: :exception
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,55 @@
1
+ class PollAnswersController < AdminController
2
+ before_action :set_entity, only: [:edit, :update, :destroy]
3
+
4
+ # post /poll_answers
5
+ def create
6
+ @entity = PollAnswer.new(creation_parameters)
7
+ if @entity.save
8
+ redirect_to admin_poll_answer_path(@entity.id)
9
+ else
10
+ render :new, status: :bad_request
11
+ end
12
+ end
13
+
14
+ # get /poll_answers/:id/edit
15
+ def edit
16
+ end
17
+
18
+ # patch /poll_answers/:id
19
+ def update
20
+ if @entity.update(entity_parameters)
21
+ redirect_to admin_poll_answer_path(@entity.id), notice: t('poll_answers.update.success')
22
+ else
23
+ render :edit, status: :bad_request
24
+ end
25
+ end
26
+
27
+ # delete /poll_answers/:id
28
+ def destroy
29
+ if @entity.destroy
30
+ flash[:notice] = t('poll_answers.destroy.success')
31
+ end
32
+ redirect_to(admin_poll_path(@entity.id))
33
+ end
34
+
35
+ protected
36
+
37
+ def restrict_access
38
+ require_privilege_group :poll_managers
39
+ end
40
+
41
+ def set_entity
42
+ @entity = PollAnswer.find_by(id: params[:id])
43
+ if @entity.nil?
44
+ handle_http_404('Cannot find poll answer')
45
+ end
46
+ end
47
+
48
+ def entity_parameters
49
+ params.require(:poll_answer).permit(PollAnswer.entity_parameters)
50
+ end
51
+
52
+ def creation_parameters
53
+ params.require(:poll_answer).permit(PollAnswer.creation_parameters)
54
+ end
55
+ end
@@ -0,0 +1,55 @@
1
+ class PollQuestionsController < AdminController
2
+ before_action :set_entity, only: [:edit, :update, :destroy]
3
+
4
+ # post /poll_questions
5
+ def create
6
+ @entity = PollQuestion.new(creation_parameters)
7
+ if @entity.save
8
+ redirect_to admin_poll_question_path(@entity.id)
9
+ else
10
+ render :new, status: :bad_request
11
+ end
12
+ end
13
+
14
+ # get /poll_questions/:id/edit
15
+ def edit
16
+ end
17
+
18
+ # patch /poll_questions/:id
19
+ def update
20
+ if @entity.update(entity_parameters)
21
+ redirect_to admin_poll_question_path(@entity.id), notice: t('poll_questions.update.success')
22
+ else
23
+ render :edit, status: :bad_request
24
+ end
25
+ end
26
+
27
+ # delete /poll_questions/:id
28
+ def destroy
29
+ if @entity.destroy
30
+ flash[:notice] = t('poll_questions.destroy.success')
31
+ end
32
+ redirect_to(admin_poll_path(@entity.poll_id))
33
+ end
34
+
35
+ protected
36
+
37
+ def restrict_access
38
+ require_privilege_group :poll_managers
39
+ end
40
+
41
+ def set_entity
42
+ @entity = PollQuestion.find_by(id: params[:id])
43
+ if @entity.nil?
44
+ handle_http_404('Cannot find poll question')
45
+ end
46
+ end
47
+
48
+ def entity_parameters
49
+ params.require(:poll_question).permit(PollQuestion.entity_parameters)
50
+ end
51
+
52
+ def creation_parameters
53
+ params.require(:poll_question).permit(PollQuestion.creation_parameters)
54
+ end
55
+ end
@@ -0,0 +1,59 @@
1
+ class PollsController < ApplicationController
2
+ before_action :restrict_access, except: [:index, :show]
3
+ before_action :set_entity, only: [:edit, :update, :destroy]
4
+
5
+ layout 'admin', except: [:index, :show]
6
+
7
+ # get /polls/new
8
+ def new
9
+ @entity = Poll.new
10
+ end
11
+
12
+ # post /polls
13
+ def create
14
+ @entity = Poll.new(entity_parameters)
15
+ if @entity.save
16
+ redirect_to(admin_poll_path(@entity.id))
17
+ else
18
+ render :new, status: :bad_request
19
+ end
20
+ end
21
+
22
+ # get /polls/:id/edit
23
+ def edit
24
+ end
25
+
26
+ # patch /polls/:id
27
+ def update
28
+ if @entity.update(entity_parameters)
29
+ redirect_to admin_poll_path(@entity), notice: t('polls.update.success')
30
+ else
31
+ render :edit, status: :bad_request
32
+ end
33
+ end
34
+
35
+ # delete /polls/:id
36
+ def destroy
37
+ if @entity.destroy
38
+ flash[:notice] = t('polls.destroy.success')
39
+ end
40
+ redirect_to(admin_polls_path)
41
+ end
42
+
43
+ protected
44
+
45
+ def restrict_access
46
+ require_privilege_group :poll_managers
47
+ end
48
+
49
+ def set_entity
50
+ @entity = Poll.find_by(id: params[:id])
51
+ if @entity.nil?
52
+ handle_http_404('Cannot find poll')
53
+ end
54
+ end
55
+
56
+ def entity_parameters
57
+ params.require(:poll).permit(Poll.entity_parameters)
58
+ end
59
+ end
@@ -0,0 +1,6 @@
1
+ module Biovision
2
+ module Poll
3
+ module ApplicationHelper
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,37 @@
1
+ module PollsHelper
2
+ # @param [Poll] entity
3
+ def admin_poll_link(entity)
4
+ link_to(entity.name, admin_poll_path(entity.id))
5
+ end
6
+
7
+ # @param [PollQuestion] entity
8
+ def admin_poll_question_link(entity)
9
+ link_to(entity.text, admin_poll_question_path(entity.id))
10
+ end
11
+
12
+ # @param [Poll] entity
13
+ def poll_link(entity)
14
+ link_to(entity.name, poll_path(entity.id))
15
+ end
16
+
17
+ # @param [Poll] entity
18
+ def poll_image_medium(entity)
19
+ return '' if entity.image.blank?
20
+ versions = "#{entity.image.medium_2x.url} 2x"
21
+ image_tag(entity.image.medium.url, alt: entity.name, srcset: versions)
22
+ end
23
+
24
+ # @param [Poll] entity
25
+ def poll_image_small(entity)
26
+ return '' if entity.image.blank?
27
+ versions = "#{entity.image.medium.url} 2x"
28
+ image_tag(entity.image.small.url, alt: entity.name, srcset: versions)
29
+ end
30
+
31
+ # @param [Poll] entity
32
+ def poll_image_preview(entity)
33
+ return '' if entity.image.blank?
34
+ versions = "#{entity.image.preview_2x.url} 2x"
35
+ image_tag(entity.image.preview.url, alt: entity.name, srcset: versions)
36
+ end
37
+ end
@@ -0,0 +1,6 @@
1
+ module Biovision
2
+ module Poll
3
+ class ApplicationJob < ActiveJob::Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ module Biovision
2
+ module Poll
3
+ class ApplicationMailer < ActionMailer::Base
4
+ default from: 'from@example.com'
5
+ layout 'mailer'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
@@ -0,0 +1,7 @@
1
+ module Biovision
2
+ module Poll
3
+ class ApplicationRecord < ActiveRecord::Base
4
+ self.abstract_class = true
5
+ end
6
+ end
7
+ end