biovision-courses 0.0.180221

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) 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_courses_manifest.js +2 -0
  6. data/app/assets/javascripts/biovision/courses/application.js +13 -0
  7. data/app/assets/stylesheets/biovision/courses/application.css +15 -0
  8. data/app/controllers/admin/course_categories_controller.rb +28 -0
  9. data/app/controllers/admin/course_tags_controller.rb +28 -0
  10. data/app/controllers/admin/courses_controller.rb +29 -0
  11. data/app/controllers/biovision/courses/application_controller.rb +7 -0
  12. data/app/controllers/course_categories_controller.rb +70 -0
  13. data/app/controllers/course_tags_controller.rb +66 -0
  14. data/app/controllers/courses_controller.rb +94 -0
  15. data/app/helpers/biovision/courses/application_helper.rb +6 -0
  16. data/app/helpers/biovision_courses_helper.rb +80 -0
  17. data/app/jobs/biovision/courses/application_job.rb +6 -0
  18. data/app/mailers/biovision/courses/application_mailer.rb +8 -0
  19. data/app/models/application_record.rb +3 -0
  20. data/app/models/biovision/courses/application_record.rb +7 -0
  21. data/app/models/course.rb +109 -0
  22. data/app/models/course_category.rb +137 -0
  23. data/app/models/course_course_tag.rb +13 -0
  24. data/app/models/course_tag.rb +49 -0
  25. data/app/uploaders/course_image_uploader.rb +46 -0
  26. data/app/views/admin/course_categories/_nav_item.html.erb +2 -0
  27. data/app/views/admin/course_categories/entity/_in_list.html.erb +43 -0
  28. data/app/views/admin/course_categories/index.html.erb +17 -0
  29. data/app/views/admin/course_categories/show.html.erb +85 -0
  30. data/app/views/admin/course_tags/_nav_item.html.erb +2 -0
  31. data/app/views/admin/course_tags/entity/_in_list.html.erb +21 -0
  32. data/app/views/admin/course_tags/index.html.erb +19 -0
  33. data/app/views/admin/course_tags/show.html.erb +39 -0
  34. data/app/views/admin/courses/_nav_item.html.erb +2 -0
  35. data/app/views/admin/courses/entity/_in_list.html.erb +40 -0
  36. data/app/views/admin/courses/index.html.erb +17 -0
  37. data/app/views/admin/courses/show.html.erb +117 -0
  38. data/app/views/admin/index/dashboard/_biovision_courses.html.erb +12 -0
  39. data/app/views/course_categories/_form.html.erb +96 -0
  40. data/app/views/course_categories/edit.html.erb +22 -0
  41. data/app/views/course_categories/edit.js.erb +1 -0
  42. data/app/views/course_categories/new.html.erb +15 -0
  43. data/app/views/course_categories/new.js.erb +1 -0
  44. data/app/views/course_tags/_form.html.erb +72 -0
  45. data/app/views/course_tags/edit.html.erb +17 -0
  46. data/app/views/course_tags/edit.js.erb +1 -0
  47. data/app/views/course_tags/new.html.erb +15 -0
  48. data/app/views/course_tags/new.js.erb +1 -0
  49. data/app/views/courses/_form.html.erb +244 -0
  50. data/app/views/courses/edit.html.erb +17 -0
  51. data/app/views/courses/edit.js.erb +1 -0
  52. data/app/views/courses/form/_wysiwyg.html.erb +14 -0
  53. data/app/views/courses/new.html.erb +15 -0
  54. data/app/views/courses/new.js.erb +1 -0
  55. data/app/views/layouts/biovision/courses/application.html.erb +14 -0
  56. data/config/locales/courses-ru.yml +138 -0
  57. data/config/routes.rb +26 -0
  58. data/db/migrate/20180218120000_prepare_course_privileges.rb +19 -0
  59. data/db/migrate/20180218120005_create_course_categories.rb +28 -0
  60. data/db/migrate/20180218120010_create_course_tags.rb +20 -0
  61. data/db/migrate/20180218120015_create_courses.rb +42 -0
  62. data/db/migrate/20180218120020_create_course_course_tags.rb +17 -0
  63. data/lib/biovision/courses.rb +7 -0
  64. data/lib/biovision/courses/engine.rb +18 -0
  65. data/lib/biovision/courses/version.rb +5 -0
  66. data/lib/tasks/biovision/courses_tasks.rake +4 -0
  67. metadata +207 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ef0a244be3c7edae730b4a22aa130a30a5e46d5871a077e523f888206f730a4d
4
+ data.tar.gz: 5dcc1ab277316189046e8bb6f92d76f7ea25b15ac2b2fcd7b9de8f9f6b196686
5
+ SHA512:
6
+ metadata.gz: 6e079e7d896731c82f592a768f3c0ca054579e4fec37ff1a554d0eab2b739c273be1d45e9f9b3e295da824490f5c6835e10be1da9e237875b883862533be93c6
7
+ data.tar.gz: b8c41be72cf172bfd3117f4f7a77806edc5a68ca832b5be37b4083360691d2d0ffb07a1ad53617f9eacbcd7b4b57741c62dd0675c6ba4efc95f24845b428c465
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 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::Courses
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-courses'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install biovision-courses
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::Courses'
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/test_app/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/courses .js
2
+ //= link_directory ../stylesheets/biovision/courses .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 .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,28 @@
1
+ class Admin::CourseCategoriesController < AdminController
2
+ include ToggleableEntity
3
+ include EntityPriority
4
+
5
+ before_action :set_entity, except: [:index]
6
+
7
+ # get /admin/course_categories
8
+ def index
9
+ end
10
+
11
+ # get /admin/course_categories/:id
12
+ def show
13
+ @collection = @entity.courses.page_for_administration(current_page)
14
+ end
15
+
16
+ private
17
+
18
+ def set_entity
19
+ @entity = CourseCategory.find_by(id: params[:id])
20
+ if @entity.nil?
21
+ handle_http_404('Cannot find course category')
22
+ end
23
+ end
24
+
25
+ def restrict_access
26
+ require_privilege :chief_course_manager
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ class Admin::CourseTagsController < AdminController
2
+ include ToggleableEntity
3
+
4
+ before_action :set_entity, except: [:index]
5
+
6
+ # get /admin/course_tags
7
+ def index
8
+ @collection = CourseTag.page_for_administration(current_page)
9
+ end
10
+
11
+ # get /admin/course_tags/:id
12
+ def show
13
+ @collection = @entity.courses.page_for_administration(current_page)
14
+ end
15
+
16
+ private
17
+
18
+ def set_entity
19
+ @entity = CourseTag.find_by(id: params[:id])
20
+ if @entity.nil?
21
+ handle_http_404('Cannot find course tag')
22
+ end
23
+ end
24
+
25
+ def restrict_access
26
+ require_privilege :chief_course_manager
27
+ end
28
+ end
@@ -0,0 +1,29 @@
1
+ class Admin::CoursesController < AdminController
2
+ include LockableEntity
3
+ include ToggleableEntity
4
+ include EntityPriority
5
+
6
+ before_action :set_entity, except: [:index]
7
+
8
+ # get /admin/courses
9
+ def index
10
+ @collection = Course.page_for_administration(current_page)
11
+ end
12
+
13
+ # get /admin/courses/:id
14
+ def show
15
+ end
16
+
17
+ private
18
+
19
+ def set_entity
20
+ @entity = Course.find_by(id: params[:id])
21
+ if @entity.nil?
22
+ handle_http_404('Cannot find course')
23
+ end
24
+ end
25
+
26
+ def restrict_access
27
+ require_privilege_group :course_managers
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ module Biovision
2
+ module Courses
3
+ class ApplicationController < ActionController::Base
4
+ protect_from_forgery with: :exception
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,70 @@
1
+ class CourseCategoriesController < AdminController
2
+ before_action :set_entity, only: [:edit, :update, :destroy]
3
+
4
+ # get /course_categories/new
5
+ def new
6
+ @entity = CourseCategory.new
7
+ end
8
+
9
+ # post /course_categories
10
+ def create
11
+ @entity = CourseCategory.new(creation_parameters)
12
+ if @entity.save
13
+ next_page = admin_course_category_path(@entity.id)
14
+ respond_to do |format|
15
+ format.html { redirect_to(next_page) }
16
+ format.json { render json: { links: { self: next_page } } }
17
+ format.js { render(js: "document.location.href = '#{next_page}'") }
18
+ end
19
+ else
20
+ render :new, status: :bad_request
21
+ end
22
+ end
23
+
24
+ # get /course_categories/:id/edit
25
+ def edit
26
+ end
27
+
28
+ # patch /course_categories/:id
29
+ def update
30
+ if @entity.update entity_parameters
31
+ next_page = admin_course_category_path(@entity.id)
32
+ respond_to do |format|
33
+ format.html { redirect_to(next_page, notice: t('course_categories.update.success')) }
34
+ format.json { render json: { links: { self: next_page } } }
35
+ format.js { render(js: "document.location.href = '#{next_page}'") }
36
+ end
37
+ else
38
+ render :edit, status: :bad_request
39
+ end
40
+ end
41
+
42
+ # delete /course_categories/:id
43
+ def destroy
44
+ if @entity.destroy
45
+ flash[:notice] = t('course_categories.destroy.success')
46
+ end
47
+ redirect_to(admin_course_categories_path)
48
+ end
49
+
50
+ protected
51
+
52
+ def restrict_access
53
+ require_privilege :chief_course_manager
54
+ end
55
+
56
+ def set_entity
57
+ @entity = CourseCategory.find_by(id: params[:id])
58
+ if @entity.nil?
59
+ handle_http_404('Cannot find course_category')
60
+ end
61
+ end
62
+
63
+ def entity_parameters
64
+ params.require(:course_category).permit(CourseCategory.entity_parameters)
65
+ end
66
+
67
+ def creation_parameters
68
+ params.require(:course_category).permit(CourseCategory.creation_parameters)
69
+ end
70
+ end
@@ -0,0 +1,66 @@
1
+ class CourseTagsController < AdminController
2
+ before_action :set_entity, only: [:edit, :update, :destroy]
3
+
4
+ # get /course_tags/new
5
+ def new
6
+ @entity = CourseTag.new
7
+ end
8
+
9
+ # post /course_tags
10
+ def create
11
+ @entity = CourseTag.new(entity_parameters)
12
+ if @entity.save
13
+ next_page = admin_course_tag_path(@entity.id)
14
+ respond_to do |format|
15
+ format.html { redirect_to(next_page) }
16
+ format.json { render json: { links: { self: next_page } } }
17
+ format.js { render(js: "document.location.href = '#{next_page}'") }
18
+ end
19
+ else
20
+ render :new, status: :bad_request
21
+ end
22
+ end
23
+
24
+ # get /course_tags/:id/edit
25
+ def edit
26
+ end
27
+
28
+ # patch /course_tags/:id
29
+ def update
30
+ if @entity.update entity_parameters
31
+ next_page = admin_course_tag_path(@entity.id)
32
+ respond_to do |format|
33
+ format.html { redirect_to(next_page, notice: t('course_tags.update.success')) }
34
+ format.json { render json: { links: { self: next_page } } }
35
+ format.js { render(js: "document.location.href = '#{next_page}'") }
36
+ end
37
+ else
38
+ render :edit, status: :bad_request
39
+ end
40
+ end
41
+
42
+ # delete /course_tags/:id
43
+ def destroy
44
+ if @entity.destroy
45
+ flash[:notice] = t('course_tags.destroy.success')
46
+ end
47
+ redirect_to(admin_course_tags_path)
48
+ end
49
+
50
+ protected
51
+
52
+ def restrict_access
53
+ require_privilege :chief_course_manager
54
+ end
55
+
56
+ def set_entity
57
+ @entity = CourseTag.find_by(id: params[:id])
58
+ if @entity.nil?
59
+ handle_http_404('Cannot find course_tag')
60
+ end
61
+ end
62
+
63
+ def entity_parameters
64
+ params.require(:course_tag).permit(CourseTag.entity_parameters)
65
+ end
66
+ end
@@ -0,0 +1,94 @@
1
+ class CoursesController < ApplicationController
2
+ before_action :restrict_access, only: [:new, :create]
3
+ before_action :set_entity, only: [:edit, :update, :destroy]
4
+ before_action :restrict_editing, only: [:edit, :update, :destroy]
5
+
6
+ layout 'admin', only: [:new, :edit]
7
+
8
+ # get /courses
9
+ def index
10
+ @collection = Course.page_for_visitors(current_page)
11
+ end
12
+
13
+ # get /courses/new
14
+ def new
15
+ @entity = Course.new
16
+ end
17
+
18
+ # post /courses
19
+ def create
20
+ @entity = Course.new(creation_parameters)
21
+ if @entity.save
22
+ next_page = admin_course_path(@entity.id)
23
+ respond_to do |format|
24
+ format.html { redirect_to next_page }
25
+ format.json { render json: { links: { self: next_page } } }
26
+ format.js { render js: "document.location.href = '#{next_page}'" }
27
+ end
28
+ else
29
+ render :new, status: :bad_request
30
+ end
31
+ end
32
+
33
+ # get /courses/:id
34
+ def show
35
+ @entity = Course.find_by(id: params[:id], visible: true, deleted: false)
36
+ if @entity.nil?
37
+ handle_http_404("Cannot find non-deleted course #{params[:id]}")
38
+ end
39
+ end
40
+
41
+ # get /courses/:id/edit
42
+ def edit
43
+ end
44
+
45
+ # patch /courses/:id
46
+ def update
47
+ if @entity.update(entity_parameters)
48
+ next_page = admin_course_path(@entity.id)
49
+ respond_to do |format|
50
+ format.html { redirect_to next_page }
51
+ format.json { render json: { links: { self: next_page } } }
52
+ format.js { render js: "document.location.href = '#{next_page}'" }
53
+ end
54
+ else
55
+ render :edit, status: :bad_request
56
+ end
57
+ end
58
+
59
+ # delete /courses/:id
60
+ def destroy
61
+ if @entity.destroy #@entity.update(deleted: true)
62
+ flash[:notice] = t('courses.destroy.success')
63
+ end
64
+ redirect_to admin_courses_path
65
+ end
66
+
67
+ private
68
+
69
+ def set_entity
70
+ @entity = Course.find_by(id: params[:id])
71
+ if @entity.nil?
72
+ handle_http_404('Cannot find course')
73
+ end
74
+ end
75
+
76
+ def restrict_access
77
+ require_privilege_group :course_managers
78
+ end
79
+
80
+ def restrict_editing
81
+ if @entity.locked? || !@entity.editable_by?(current_user)
82
+ handle_http_403('Course is locked or not editable by current user')
83
+ end
84
+ end
85
+
86
+ def entity_parameters
87
+ params.require(:course).permit(Course.entity_parameters)
88
+ end
89
+
90
+ def creation_parameters
91
+ parameters = params.require(:course).permit(Course.entity_parameters)
92
+ parameters.merge(owner_for_entity(true))
93
+ end
94
+ end