guider_cms 1.4.0
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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +133 -0
- data/Rakefile +32 -0
- data/app/assets/config/guider_cms_manifest.js +4 -0
- data/app/assets/images/guider_cms/down.jpg +0 -0
- data/app/assets/images/guider_cms/down.png +0 -0
- data/app/assets/images/guider_cms/up.png +0 -0
- data/app/assets/stylesheets/guider_cms/application.css +78 -0
- data/app/assets/stylesheets/guider_cms/articles.css +18 -0
- data/app/assets/stylesheets/guider_cms/categories.css +4 -0
- data/app/assets/stylesheets/guider_cms/current_user_articles.css +4 -0
- data/app/assets/stylesheets/guider_cms/subcategories.css +4 -0
- data/app/assets/stylesheets/scaffold.css +80 -0
- data/app/controllers/guider_cms/application_controller.rb +6 -0
- data/app/controllers/guider_cms/articles_controller.rb +232 -0
- data/app/controllers/guider_cms/categories_controller.rb +112 -0
- data/app/controllers/guider_cms/current_user_articles_controller.rb +14 -0
- data/app/controllers/guider_cms/subcategories_controller.rb +35 -0
- data/app/helpers/guider_cms/application_helper.rb +70 -0
- data/app/helpers/guider_cms/articles_helper.rb +32 -0
- data/app/helpers/guider_cms/categories_helper.rb +4 -0
- data/app/helpers/guider_cms/current_user_articles_helper.rb +4 -0
- data/app/helpers/guider_cms/subcategories_helper.rb +4 -0
- data/app/jobs/guider_cms/application_job.rb +4 -0
- data/app/mailers/guider_cms/application_mailer.rb +6 -0
- data/app/models/guider_cms/application_record.rb +5 -0
- data/app/models/guider_cms/article.rb +26 -0
- data/app/models/guider_cms/category.rb +10 -0
- data/app/views/guider_cms/articles/_form.html.erb +51 -0
- data/app/views/guider_cms/articles/edit.html.erb +5 -0
- data/app/views/guider_cms/articles/index.html.erb +540 -0
- data/app/views/guider_cms/articles/new.html.erb +5 -0
- data/app/views/guider_cms/articles/show.html.erb +68 -0
- data/app/views/guider_cms/categories/_form.html.erb +50 -0
- data/app/views/guider_cms/categories/edit.html.erb +6 -0
- data/app/views/guider_cms/categories/index.html.erb +76 -0
- data/app/views/guider_cms/categories/new.html.erb +7 -0
- data/app/views/guider_cms/current_user_articles/index.html.erb +32 -0
- data/app/views/guider_cms/subcategories/_form.html.erb +15 -0
- data/app/views/guider_cms/subcategories/new.html.erb +5 -0
- data/app/views/layouts/guider_cms/application.html.erb +22 -0
- data/config/initializers/friendly_id.rb +107 -0
- data/config/initializers/kaminari_config.rb +14 -0
- data/config/routes.rb +53 -0
- data/db/migrate/20200823094047_create_guider_cms_categories.rb +9 -0
- data/db/migrate/20200823094214_create_guider_cms_articles.rb +13 -0
- data/db/migrate/20200823095230_add_parent_id_to_guider_cms_categories.rb +5 -0
- data/db/migrate/20200823095828_create_guider_cms_category_hierarchies.rb +16 -0
- data/db/migrate/20200823095934_add_is_root_category_ro_guider_categories.rb +5 -0
- data/db/migrate/20200823100111_add_slug_to_articles.rb +6 -0
- data/db/migrate/20200823100118_create_friendly_id_slugs.rb +21 -0
- data/db/migrate/20200824104656_add_slug_to_guider_cms_categories.rb +6 -0
- data/db/migrate/20200827170106_add_view_type_to_guider_categories.rb +5 -0
- data/db/migrate/20200831182803_add_keywords_to_guider_cms_articles.rb +5 -0
- data/db/migrate/20200902203407_add_position_to_guider_cms_articles.rb +5 -0
- data/lib/generators/guider_cms/controller_generator.rb +33 -0
- data/lib/generators/guider_cms/install_generator.rb +34 -0
- data/lib/generators/guider_cms/routes_generator.rb +34 -0
- data/lib/generators/guider_cms/views_generator.rb +35 -0
- data/lib/generators/templates/README +20 -0
- data/lib/generators/templates/guider_cms.rb +4 -0
- data/lib/guider_cms.rb +10 -0
- data/lib/guider_cms/engine.rb +9 -0
- data/lib/guider_cms/version.rb +3 -0
- data/lib/tasks/guider_cms_tasks.rake +4 -0
- metadata +227 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 5eb810b2be18c92e39eafdb0ec9927124a5fbe94e1c444333687857499edb523
|
|
4
|
+
data.tar.gz: 41e3722062e82b595fe50e9db2304020f375c71f3ee77c2cc67ed340d8d634f4
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 3e1ba2758f3faf0a2062104e863d78a7356025fd36d079ac3e6178f6179937da21dd4bdddcf4cc67a33d0092d30dfd2b3da80cedeba0b23ba04c1e6b6e920552
|
|
7
|
+
data.tar.gz: 2d6dff252c094005189a4356128dbba933ef6890606765930557be015fbacd98145f4280bdc4551c84adab005fc4036580bd2a955241f9ab02a2ef75159036c6
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2020 Minat Silvester
|
|
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,133 @@
|
|
|
1
|
+
# GuiderCms
|
|
2
|
+
GuiderCms is a plugin which provides CMS functionality for multiple root origins
|
|
3
|
+
Is Rack Based
|
|
4
|
+
Based on MVC using rails engines
|
|
5
|
+
Allows you to have a CMS for multiple purposes
|
|
6
|
+
Supports for categories and subcategories for all root origin
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## Prerequisite
|
|
10
|
+
***Please Ensure you have active_storage, action_text and closure_tree gem set up in your application***
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
Add this line to your application's Gemfile:
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
gem 'guider_cms'
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
And then execute:
|
|
21
|
+
```bash
|
|
22
|
+
$ bundle install
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or install it yourself as:
|
|
26
|
+
```bash
|
|
27
|
+
$ gem install guider_cms
|
|
28
|
+
```
|
|
29
|
+
to generate the initializer file run
|
|
30
|
+
```bash
|
|
31
|
+
$ rails g guider_cms:install
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
In config/initializers/guider.rb set the name of your primary user model
|
|
35
|
+
```ruby
|
|
36
|
+
GuiderCms.author_class = "YOUR_USER_MODEL_CLASS"
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
then to generate all the migration files
|
|
40
|
+
```bash
|
|
41
|
+
$ rails guider_cms:install:migrations
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
then finally create the tables
|
|
45
|
+
```bash
|
|
46
|
+
$ rails db:migrate
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Once all that is done mount the engine in your main application in config/routes.rb
|
|
50
|
+
```ruby
|
|
51
|
+
mount GuiderCms::Engine => "/"
|
|
52
|
+
```
|
|
53
|
+
***Be sure to mount the engine at "/" and not any other path***
|
|
54
|
+
|
|
55
|
+
in app/models/your_user_model.rb, add
|
|
56
|
+
This is done to create the association between the user and articles table
|
|
57
|
+
```ruby
|
|
58
|
+
has_many :guider_cms_articles , class_name: 'GuiderCms::Article', foreign_key: :author_id
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
in your main application app/controllers/application_controller.rb
|
|
62
|
+
add these two functions
|
|
63
|
+
```ruby
|
|
64
|
+
def current_user
|
|
65
|
+
if user is logged_in
|
|
66
|
+
@current_user = the user object
|
|
67
|
+
else
|
|
68
|
+
@current_user = nil
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def is_guider_admin
|
|
74
|
+
if some condition to access guider functionality
|
|
75
|
+
@is_guider_admin = true
|
|
76
|
+
else
|
|
77
|
+
@is_guider_admin = false
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
***If you are using a engine or library that already provides a current_user method, then you can avoid declaring it seperately***
|
|
83
|
+
|
|
84
|
+
in app/views/layout/application.html.erb include
|
|
85
|
+
```html
|
|
86
|
+
<%= stylesheet_link_tag "guider_cms/application", media: "all" %>
|
|
87
|
+
```
|
|
88
|
+
this includes all the css for the engine
|
|
89
|
+
|
|
90
|
+
***You need atleast one root category to start working in guiderCMS***
|
|
91
|
+
Root categories can be things used to represent top of the any cms system
|
|
92
|
+
eg: Blogs, Articles, etc.
|
|
93
|
+
To start, navigate to guider_home_page
|
|
94
|
+
```ruby
|
|
95
|
+
guider_home_path
|
|
96
|
+
```
|
|
97
|
+
This part will ask you to create a new root category if none exists, Then you will have to create categories that come under this root visiting home path again will take you right there
|
|
98
|
+
|
|
99
|
+
## Routing
|
|
100
|
+
Consider you have a root category called "Blogs"
|
|
101
|
+
And in Blogs you have categories such as Computer science and Artificial Intelligence
|
|
102
|
+
Here Computer Science and Artificial Intelligence are main categories in Root Blogs
|
|
103
|
+
Main categories can have subcategories, such as Artificial Intelligence can have subcategories such as machine learning
|
|
104
|
+
|
|
105
|
+
So your root blogs is arranged in this way
|
|
106
|
+
- Blogs
|
|
107
|
+
- Computer Science
|
|
108
|
+
- Artificial Intelligence
|
|
109
|
+
- Machine Learning
|
|
110
|
+
|
|
111
|
+
To visit the home/index page:
|
|
112
|
+
```ruby
|
|
113
|
+
guider_home_path
|
|
114
|
+
```
|
|
115
|
+
To view index for specific root category:
|
|
116
|
+
```ruby
|
|
117
|
+
content_new_back_path(root: "Blogs")
|
|
118
|
+
```
|
|
119
|
+
To view index for specific root and selected category:
|
|
120
|
+
```ruby
|
|
121
|
+
contents_path(root: "Blogs", selected_category: "Artificial Intelligence")
|
|
122
|
+
```
|
|
123
|
+
the same for subcategory among the main categories
|
|
124
|
+
```ruby
|
|
125
|
+
contents_path(root: "Blogs", selected_category: "Machine Learning")
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
## Contributing
|
|
130
|
+
Contribution directions go here.
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
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 = 'GuiderCms'
|
|
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("test/dummy/Rakefile", __dir__)
|
|
18
|
+
load 'rails/tasks/engine.rake'
|
|
19
|
+
|
|
20
|
+
load 'rails/tasks/statistics.rake'
|
|
21
|
+
|
|
22
|
+
require 'bundler/gem_tasks'
|
|
23
|
+
|
|
24
|
+
require 'rake/testtask'
|
|
25
|
+
|
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
|
27
|
+
t.libs << 'test'
|
|
28
|
+
t.pattern = 'test/**/*_test.rb'
|
|
29
|
+
t.verbose = false
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
task default: :test
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
*/
|
|
16
|
+
|
|
17
|
+
.card-horizontal {
|
|
18
|
+
display: flex;
|
|
19
|
+
flex: 1 1 auto;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.card-img-top {
|
|
23
|
+
width: 100%;
|
|
24
|
+
height: 10vw;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.grid-style{
|
|
28
|
+
padding-top: 15px;
|
|
29
|
+
padding-bottom: 25px;
|
|
30
|
+
border-radius: 12px;
|
|
31
|
+
margin-bottom: 10px;
|
|
32
|
+
background-color: #3CB371;
|
|
33
|
+
color: white;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
.grid-style:hover{
|
|
38
|
+
background-color: #2E8B57;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/*
|
|
42
|
+
.grid-style:hover{
|
|
43
|
+
background-color: #3CB371;
|
|
44
|
+
color: white;
|
|
45
|
+
} */
|
|
46
|
+
|
|
47
|
+
.grid-link{
|
|
48
|
+
color: black;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.grid-link:hover{
|
|
52
|
+
text-decoration: none;
|
|
53
|
+
color: #3CB371;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.listing-links{
|
|
57
|
+
color: black
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.listing-active-links{
|
|
61
|
+
color: #3CB371;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.essesntial-links{
|
|
65
|
+
color: black;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.essesntial-links:hover{
|
|
69
|
+
color: #3CB371;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.listing-links:hover{
|
|
73
|
+
color: black
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.listing-active-links:hover{
|
|
77
|
+
color: #3CB371;
|
|
78
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Place all the styles related to the matching controller here.
|
|
3
|
+
They will automatically be included in application.css.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
.card-columns {
|
|
9
|
+
@include media-breakpoint-only(xl) {
|
|
10
|
+
column-count: 5;
|
|
11
|
+
}
|
|
12
|
+
@include media-breakpoint-only(lg) {
|
|
13
|
+
column-count: 4;
|
|
14
|
+
}
|
|
15
|
+
@include media-breakpoint-only(sm) {
|
|
16
|
+
column-count: 4;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
body {
|
|
2
|
+
background-color: #fff;
|
|
3
|
+
color: #333;
|
|
4
|
+
margin: 33px;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
body, p, ol, ul, td {
|
|
8
|
+
font-family: verdana, arial, helvetica, sans-serif;
|
|
9
|
+
font-size: 13px;
|
|
10
|
+
line-height: 18px;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
pre {
|
|
14
|
+
background-color: #eee;
|
|
15
|
+
padding: 10px;
|
|
16
|
+
font-size: 11px;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
a {
|
|
20
|
+
color: #000;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
a:visited {
|
|
24
|
+
color: #666;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
a:hover {
|
|
28
|
+
color: #fff;
|
|
29
|
+
background-color: #000;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
th {
|
|
33
|
+
padding-bottom: 5px;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
td {
|
|
37
|
+
padding: 0 5px 7px;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
div.field,
|
|
41
|
+
div.actions {
|
|
42
|
+
margin-bottom: 10px;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
#notice {
|
|
46
|
+
color: green;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.field_with_errors {
|
|
50
|
+
padding: 2px;
|
|
51
|
+
background-color: red;
|
|
52
|
+
display: table;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
#error_explanation {
|
|
56
|
+
width: 450px;
|
|
57
|
+
border: 2px solid red;
|
|
58
|
+
padding: 7px 7px 0;
|
|
59
|
+
margin-bottom: 20px;
|
|
60
|
+
background-color: #f0f0f0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
#error_explanation h2 {
|
|
64
|
+
text-align: left;
|
|
65
|
+
font-weight: bold;
|
|
66
|
+
padding: 5px 5px 5px 15px;
|
|
67
|
+
font-size: 12px;
|
|
68
|
+
margin: -7px -7px 0;
|
|
69
|
+
background-color: #c00;
|
|
70
|
+
color: #fff;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
#error_explanation ul li {
|
|
74
|
+
font-size: 12px;
|
|
75
|
+
list-style: square;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
label {
|
|
79
|
+
display: block;
|
|
80
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
require_dependency "guider_cms/application_controller"
|
|
2
|
+
|
|
3
|
+
module GuiderCms
|
|
4
|
+
class ArticlesController < ApplicationController
|
|
5
|
+
include GuiderCms::ArticlesHelper
|
|
6
|
+
before_action :set_article, only: [:edit, :update, :destroy, :edit_article_position_one_backward, :edit_article_position_one_forward]
|
|
7
|
+
# before_action :is_guider_assesible, only: [:new, :edit, :update, :destroy]
|
|
8
|
+
# before_action :is_correct_user, only: [:edit, :update, :destroy]
|
|
9
|
+
# GET /articles
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def index
|
|
13
|
+
@root = params[:root]
|
|
14
|
+
@is_guider_admin = is_guider_admin
|
|
15
|
+
@current_user = current_user
|
|
16
|
+
@selected_category = params[:selected_category]
|
|
17
|
+
if @root.nil?
|
|
18
|
+
@root_category = Category.where(is_root_category: true).first
|
|
19
|
+
if @root_category.nil?
|
|
20
|
+
redirect_to new_optimized_category_path, alert: "Create a root category first"
|
|
21
|
+
else
|
|
22
|
+
@root = @root_category.classification
|
|
23
|
+
if @selected_category.nil?
|
|
24
|
+
@selected_category_class = @root_category
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
@children_category = @root_category.children.order(:id)
|
|
28
|
+
else
|
|
29
|
+
@root_category = Category.find_by(classification: @root) || Category.find_by(slug: @root)
|
|
30
|
+
if @selected_category.nil?
|
|
31
|
+
@selected_category_class = @root_category
|
|
32
|
+
else
|
|
33
|
+
@selected_category_class = Category.find_by(classification: @selected_category) || Category.find_by(slug: @selected_category)
|
|
34
|
+
end
|
|
35
|
+
@children_category = @root_category.children.order(:id)
|
|
36
|
+
end
|
|
37
|
+
if @root_category.view_type == "menu" || @root_category.view_type == "ordered list"
|
|
38
|
+
if @root_category.articles == [] && @root_category.children != []
|
|
39
|
+
@selected_category_class = @root_category.children.first
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
if @root_category.view_type == "ordered list"
|
|
43
|
+
if @root_category.children == []
|
|
44
|
+
redirect_to new_optimized_category_path, notice: "Create a new category under #{@root_category.classification}"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
if @root_category.view_type == "blog grid" || @root_category.view_type == "blog list"
|
|
48
|
+
@categories = category_options_array_for_article(nil, [], @root_category.id, 0)
|
|
49
|
+
@articles_id = []
|
|
50
|
+
|
|
51
|
+
@categories.each do |category|
|
|
52
|
+
@required_category_class = Category.find_by(classification: category[0].gsub(' ', ''))
|
|
53
|
+
@required_category_class.articles.each do |article|
|
|
54
|
+
@articles_id.append(article.id)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
@articles = Article.where(id: @articles_id).order(updated_at: :desc).page params[:page]
|
|
58
|
+
|
|
59
|
+
# @articles = Article.all.order(created_at: :desc).page params[:page]
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
# GET /articles/1
|
|
65
|
+
def show
|
|
66
|
+
@article = Article.friendly.find(params[:id])
|
|
67
|
+
@coming_from = params[:action_from]
|
|
68
|
+
@root = params[:root]
|
|
69
|
+
@selected_category = params[:selected_category]
|
|
70
|
+
if Category.find_by(classification: @root).nil?
|
|
71
|
+
@root_category = Category.find_by(slug: @root)
|
|
72
|
+
else
|
|
73
|
+
@root_category = Category.find_by(classification: @root)
|
|
74
|
+
end
|
|
75
|
+
if @selected_category.nil?
|
|
76
|
+
@selected_category = @root
|
|
77
|
+
@selected_category_class = @root_category
|
|
78
|
+
else
|
|
79
|
+
if Category.find_by(classification: @selected_category).nil?
|
|
80
|
+
@selected_category_class = Category.find_by(slug: @selected_category)
|
|
81
|
+
else
|
|
82
|
+
@selected_category_class = Category.find_by(classification: @selected_category)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# GET /articles/new
|
|
88
|
+
def new
|
|
89
|
+
|
|
90
|
+
if current_user && is_guider_admin
|
|
91
|
+
|
|
92
|
+
@root = params[:root]
|
|
93
|
+
@article = Article.new
|
|
94
|
+
if @root.nil?
|
|
95
|
+
redirect_to guider_home_path
|
|
96
|
+
else
|
|
97
|
+
if Category.find_by(classification: @root).nil?
|
|
98
|
+
@root_category = Category.find_by(slug: @root)
|
|
99
|
+
else
|
|
100
|
+
@root_category = Category.find_by(classification: @root)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
end
|
|
104
|
+
else
|
|
105
|
+
redirect_to content_new_back_path(root: @root_category.slug || @root_category.classification)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# GET /articles/1/edit
|
|
111
|
+
def edit
|
|
112
|
+
if current_user && current_user.id != @article.author_id
|
|
113
|
+
redirect_to guider_home_path
|
|
114
|
+
else
|
|
115
|
+
@root = params[:root]
|
|
116
|
+
@categories = Category.all
|
|
117
|
+
@selected_category = Category.friendly.find(@article.category_id)
|
|
118
|
+
if @selected_category.parent.nil?
|
|
119
|
+
@root_category = @selected_category
|
|
120
|
+
else
|
|
121
|
+
@root_category = @selected_category.ancestors.last
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# POST /articles
|
|
127
|
+
def create
|
|
128
|
+
@categories = Category.all
|
|
129
|
+
@article = Article.new(article_params)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
@selected_category = Category.find(@article.category_id)
|
|
133
|
+
@root_category = @selected_category.ancestors.last
|
|
134
|
+
|
|
135
|
+
@article.author_id = current_user.id
|
|
136
|
+
|
|
137
|
+
if @article.save
|
|
138
|
+
if @root_category.nil?
|
|
139
|
+
redirect_to content_new_back_path(root: @selected_category.slug || @selected_category.classification)
|
|
140
|
+
else
|
|
141
|
+
redirect_to content_path(@article, root: @root_category.slug || @root_category.classification, selected_category: @selected_category.slug || @selected_category.classification), notice: 'Article was successfully created.'
|
|
142
|
+
end
|
|
143
|
+
# redirect_to guider_home_path
|
|
144
|
+
else
|
|
145
|
+
render :new
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# PATCH/PUT /articles/1
|
|
150
|
+
def update
|
|
151
|
+
|
|
152
|
+
category_id = @article.id
|
|
153
|
+
if @article.update(article_params)
|
|
154
|
+
req_category_id = @article.id || category_id
|
|
155
|
+
@selected_category_class = Category.find(req_category_id)
|
|
156
|
+
@root_category = @selected_category_class.ancestors.last
|
|
157
|
+
# redirect_to user_articles_path, notice: 'Article was successfully updated.'
|
|
158
|
+
if @root_category.nil?
|
|
159
|
+
redirect_to content_new_back_path(root: @selected_category.slug || @selected_category.classification)
|
|
160
|
+
else
|
|
161
|
+
redirect_to content_path(@article, root: @root_category.slug || @root_category.classification, selected_category: @selected_category_class.slug || @selected_category_class.classification), notice: 'Article was successfully created.'
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# redirect_to guider_home_path
|
|
165
|
+
|
|
166
|
+
else
|
|
167
|
+
render :edit
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def edit_article_position_one_backward
|
|
172
|
+
root = params[:root]
|
|
173
|
+
selected_category = params[:selected_category]
|
|
174
|
+
@article.move_higher
|
|
175
|
+
if selected_category == ""
|
|
176
|
+
redirect_to content_new_back_path(root: root)
|
|
177
|
+
else
|
|
178
|
+
redirect_to contents_path(root: root, selected_category: selected_category)
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def edit_article_position_one_forward
|
|
183
|
+
root = params[:root]
|
|
184
|
+
selected_category = params[:selected_category]
|
|
185
|
+
@article.move_lower
|
|
186
|
+
if selected_category == ""
|
|
187
|
+
redirect_to content_new_back_path(root: root)
|
|
188
|
+
else
|
|
189
|
+
redirect_to contents_path(root: root, selected_category: selected_category)
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
# DELETE /articles/1
|
|
194
|
+
def destroy
|
|
195
|
+
if @article.author_id == current_user.id or is_guider_admin
|
|
196
|
+
@article.destroy
|
|
197
|
+
redirect_to guider_home_path, notice: 'Article was successfully destroyed.'
|
|
198
|
+
else
|
|
199
|
+
redirect_to guider_home_path, alert: "Cannot do that"
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
private
|
|
204
|
+
# Use callbacks to share common setup or constraints between actions.
|
|
205
|
+
def is_correct_user
|
|
206
|
+
@article = Article.find(params[:id])
|
|
207
|
+
if current_user.id != @article.author_id
|
|
208
|
+
redirect_to root_path
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def is_guider_assesible
|
|
213
|
+
# puts(current_user)
|
|
214
|
+
if current_user and is_guider_admin?
|
|
215
|
+
redirect_to root_path
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
def set_article
|
|
220
|
+
if Article.friendly.find(params[:id]).nil?
|
|
221
|
+
@article = Article.find_by(slug: params[:id])
|
|
222
|
+
else
|
|
223
|
+
@article = Article.friendly.find(params[:id])
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
# Only allow a trusted parameter "white list" through.
|
|
228
|
+
def article_params
|
|
229
|
+
params.require(:article).permit(:title, :description, :body, :category_id, :author_id, :header_image, :root, :keywords)
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
end
|