lato_blog 2.1.2 → 2.2.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 +5 -5
- data/MIT-LICENSE +1 -1
- data/app/assets/javascripts/lato_blog/modules/BlogPosts.js +8 -0
- data/app/assets/stylesheets/lato_blog/pages/_posts.scss +1 -1
- data/app/controllers/lato_blog/api/categories_controller.rb +2 -2
- data/app/controllers/lato_blog/api/posts_controller.rb +4 -0
- data/app/controllers/lato_blog/api/tags_controller.rb +32 -0
- data/app/controllers/lato_blog/back/categories_controller.rb +1 -1
- data/app/controllers/lato_blog/back/posts_controller.rb +25 -0
- data/app/controllers/lato_blog/back/tags_controller.rb +137 -0
- data/app/models/lato_blog/post/serializer_helpers.rb +13 -1
- data/app/models/lato_blog/post.rb +5 -0
- data/app/models/lato_blog/tag/entity_helpers.rb +37 -0
- data/app/models/lato_blog/tag/serializer_helpers.rb +52 -0
- data/app/models/lato_blog/tag.rb +83 -0
- data/app/models/lato_blog/tag_parent.rb +9 -0
- data/app/models/lato_blog/tag_post.rb +31 -0
- data/app/views/lato_blog/back/categories/edit.html.erb +2 -0
- data/app/views/lato_blog/back/categories/index.html.erb +9 -3
- data/app/views/lato_blog/back/post_fields/create_relay_field.js.erb +1 -0
- data/app/views/lato_blog/back/post_fields/destroy_relay_field.js.erb +1 -0
- data/app/views/lato_blog/back/posts/edit.html.erb +4 -0
- data/app/views/lato_blog/back/posts/new.html.erb +2 -0
- data/app/views/lato_blog/back/posts/shared/edit/_edit_tags.html.erb +28 -0
- data/app/views/lato_blog/back/posts/shared/index/_index.html.erb +5 -5
- data/app/views/lato_blog/back/tags/edit.html.erb +44 -0
- data/app/views/lato_blog/back/tags/index.html.erb +24 -0
- data/app/views/lato_blog/back/tags/new.html.erb +40 -0
- data/app/views/lato_blog/back/tags/shared/_form.html.erb +34 -0
- data/app/views/lato_blog/back/tags/shared/edit/_edit_informations.html.erb +24 -0
- data/app/views/lato_blog/back/tags/shared/edit/_edit_languages.html.erb +38 -0
- data/app/views/lato_blog/back/tags/shared/new/_new_informations.html.erb +21 -0
- data/app/views/lato_blog/doc/doc/index.html.erb +1 -1
- data/config/configs.yml +5 -0
- data/config/languages/default.yml +11 -1
- data/config/languages/it.yml +10 -0
- data/config/routes/api.rb +4 -0
- data/config/routes/back.rb +5 -1
- data/db/migrate/20171020131140_create_lato_blog_tags.rb +15 -0
- data/db/migrate/20171021131140_create_lato_blog_tag_parents.rb +8 -0
- data/db/migrate/20171022131140_create_lato_blog_tag_posts.rb +10 -0
- data/lib/lato_blog/interface.rb +3 -3
- data/lib/lato_blog/interfaces/categories.rb +66 -0
- data/lib/lato_blog/interfaces/posts.rb +148 -0
- data/lib/lato_blog/interfaces/tags.rb +80 -0
- data/lib/lato_blog/version.rb +1 -1
- metadata +24 -6
- data/lib/lato_blog/interfaces/queries.rb +0 -161
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c9bb80d2ed4130127c19c7cccb7b816b56383c058aade29c7a5559a5ab9404b2
|
4
|
+
data.tar.gz: ed30ea6b89d13aa5cd6ff7ea2a59b83a56446d19cec66b3cfd80f4a7ab08a860
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33d6d80e98e5cd3e25abd2802132bce0f3703d22fc03d0ac7273888fa774bada18adb08aeff561fd150a70f8765dc9fe30bd3b6f41bc2ccf43deea3a79916444
|
7
|
+
data.tar.gz: e4e33e4bb1c86e26c7823f39ec12af1af6a9a2534d270c947a1dd3f39e4475484bb0029dd041ffdcfea5c105f9deb9d25af230ba68ecfc9e5e15d8650de58f75
|
data/MIT-LICENSE
CHANGED
@@ -24,6 +24,13 @@ var BlogPosts = (function () {
|
|
24
24
|
})
|
25
25
|
}
|
26
26
|
|
27
|
+
function _initializeTagsAutosave () {
|
28
|
+
var form = $('.posts__edit-tags').find('form')
|
29
|
+
$(form).find('select').change(function () {
|
30
|
+
$(form).submit()
|
31
|
+
})
|
32
|
+
}
|
33
|
+
|
27
34
|
function _initializePublicationDatetimeAutosave () {
|
28
35
|
var form = $('.posts__edit-publication-datetime').find('form')
|
29
36
|
$(form).find('input').change(function () {
|
@@ -50,6 +57,7 @@ var BlogPosts = (function () {
|
|
50
57
|
function init () {
|
51
58
|
_initializeAutosave()
|
52
59
|
_initializeCategoriesAutosave()
|
60
|
+
_initializeTagsAutosave()
|
53
61
|
_initializePublicationDatetimeAutosave()
|
54
62
|
_initializeStatusSwitchAutosave()
|
55
63
|
_initializeSeoDescriptionAutosave()
|
@@ -9,6 +9,10 @@ module LatoBlog
|
|
9
9
|
category_permalink_AND: params[:category_permalink_AND],
|
10
10
|
category_id: params[:category_id],
|
11
11
|
category_id_AND: params[:category_id_AND],
|
12
|
+
tag_permalink: params[:tag_permalink],
|
13
|
+
tag_permalink_AND: params[:tag_permalink_AND],
|
14
|
+
tag_id: params[:tag_id],
|
15
|
+
tag_id_AND: params[:tag_id_AND],
|
12
16
|
search: params[:search],
|
13
17
|
page: params[:page],
|
14
18
|
per_page: params[:per_page]
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module LatoBlog
|
2
|
+
class Api::TagsController < Api::ApiController
|
3
|
+
|
4
|
+
def index
|
5
|
+
result = blog__get_tags(
|
6
|
+
order: params[:order],
|
7
|
+
language: params[:language],
|
8
|
+
search: params[:search],
|
9
|
+
page: params[:page].to_i,
|
10
|
+
per_page: params[:per_page].to_i
|
11
|
+
)
|
12
|
+
|
13
|
+
# render response
|
14
|
+
core__send_request_success(result)
|
15
|
+
end
|
16
|
+
|
17
|
+
def show
|
18
|
+
# check parameters
|
19
|
+
core__send_request_fail('Uncorrect parameters') && return unless params[:id] || params[:permalink]
|
20
|
+
|
21
|
+
tag = blog__get_tag(
|
22
|
+
id: params[:id],
|
23
|
+
permalink: params[:permalink]
|
24
|
+
)
|
25
|
+
|
26
|
+
# render respnse
|
27
|
+
core__send_request_fail('Tag not found') && return unless tag
|
28
|
+
core__send_request_success(tag: tag)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -99,7 +99,7 @@ module LatoBlog
|
|
99
99
|
id: @category.id).map { |cat| { title: cat.title, value: cat.id } }
|
100
100
|
end
|
101
101
|
|
102
|
-
# This function checks the @
|
102
|
+
# This function checks the @category variable is present and redirect to index if it not exist.
|
103
103
|
def check_category_presence
|
104
104
|
if !@category
|
105
105
|
flash[:warning] = LANGUAGES[:lato_blog][:flashes][:category_not_found]
|
@@ -139,6 +139,30 @@ module LatoBlog
|
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
|
+
# This function updates the tags of a post.
|
143
|
+
def update_tags
|
144
|
+
@post = LatoBlog::Post.find_by(id: params[:id])
|
145
|
+
return unless check_post_presence
|
146
|
+
|
147
|
+
params_tags = params[:tags].map(&:to_i)
|
148
|
+
tag_posts = LatoBlog::TagPost.where(lato_blog_post_id: @post.id)
|
149
|
+
|
150
|
+
params_tags.each do |tag_id|
|
151
|
+
tag = LatoBlog::Tag.find_by(id: tag_id)
|
152
|
+
next if !tag || tag.meta_language != @post.meta_language
|
153
|
+
|
154
|
+
tag_post = tag_posts.find_by(lato_blog_tag_id: tag.id)
|
155
|
+
LatoBlog::TagPost.create(lato_blog_post_id: @post.id, lato_blog_tag_id: tag.id) unless tag_post
|
156
|
+
end
|
157
|
+
|
158
|
+
tag_ids = tag_posts.pluck(:lato_blog_tag_id)
|
159
|
+
tag_ids.each do |tag_id|
|
160
|
+
next if params_tags.include?(tag_id)
|
161
|
+
tag_post = tag_posts.find_by(lato_blog_tag_id: tag_id)
|
162
|
+
tag_post.destroy if tag_post
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
142
166
|
# This function updates the seo description of a post.
|
143
167
|
def update_seo_description
|
144
168
|
@post = LatoBlog::Post.find_by(id: params[:id])
|
@@ -191,6 +215,7 @@ module LatoBlog
|
|
191
215
|
|
192
216
|
def fetch_external_objects
|
193
217
|
@categories = LatoBlog::Category.all.where(meta_language: cookies[:lato_blog__current_language])
|
218
|
+
@tags = LatoBlog::Tag.all.where(meta_language: cookies[:lato_blog__current_language])
|
194
219
|
@medias = LatoMedia::Media.all
|
195
220
|
end
|
196
221
|
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LatoBlog
|
4
|
+
|
5
|
+
# Back::TagsController.
|
6
|
+
class Back::TagsController < Back::BackController
|
7
|
+
|
8
|
+
before_action do
|
9
|
+
core__set_menu_active_item('blog_articles')
|
10
|
+
end
|
11
|
+
|
12
|
+
# This function shows the list of possible tags.
|
13
|
+
def index
|
14
|
+
core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:tags])
|
15
|
+
# find tags to show
|
16
|
+
@tags = LatoBlog::Tag.where(meta_language: cookies[:lato_blog__current_language]).order('title ASC')
|
17
|
+
@widget_index_tags = core__widgets_index(@tags, search: 'title', pagination: 10)
|
18
|
+
end
|
19
|
+
|
20
|
+
# This function shows a single tag. It create a redirect to the edit path.
|
21
|
+
def show
|
22
|
+
# use edit as default post show page
|
23
|
+
redirect_to lato_blog.edit_tag_path(params[:id])
|
24
|
+
end
|
25
|
+
|
26
|
+
# This function shows the view to create a new tag.
|
27
|
+
def new
|
28
|
+
core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:tags_new])
|
29
|
+
@tag = LatoBlog::Tag.new
|
30
|
+
|
31
|
+
if params[:language]
|
32
|
+
set_current_language params[:language]
|
33
|
+
end
|
34
|
+
|
35
|
+
if params[:parent]
|
36
|
+
@tag_parent = LatoBlog::TagParent.find_by(id: params[:parent])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# This function creates a new tag.
|
41
|
+
def create
|
42
|
+
@tag = LatoBlog::Tag.new(new_tag_params)
|
43
|
+
|
44
|
+
if !@tag.save
|
45
|
+
flash[:danger] = @tag.errors.full_messages.to_sentence
|
46
|
+
redirect_to lato_blog.new_tag_path
|
47
|
+
return
|
48
|
+
end
|
49
|
+
|
50
|
+
flash[:success] = LANGUAGES[:lato_blog][:flashes][:tag_create_success]
|
51
|
+
redirect_to lato_blog.tag_path(@tag.id)
|
52
|
+
end
|
53
|
+
|
54
|
+
# This function show the view to edit a tag.
|
55
|
+
def edit
|
56
|
+
core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:tags_edit])
|
57
|
+
@tag = LatoBlog::Tag.find_by(id: params[:id])
|
58
|
+
return unless check_tag_presence
|
59
|
+
|
60
|
+
if @tag.meta_language != cookies[:lato_blog__current_language]
|
61
|
+
set_current_language @tag.meta_language
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# This function updates a tag.
|
66
|
+
def update
|
67
|
+
@tag = LatoBlog::Tag.find_by(id: params[:id])
|
68
|
+
return unless check_tag_presence
|
69
|
+
|
70
|
+
if !@tag.update(edit_tag_params)
|
71
|
+
flash[:danger] = @tag.errors.full_messages.to_sentence
|
72
|
+
redirect_to lato_blog.edit_tag_path(@tag.id)
|
73
|
+
return
|
74
|
+
end
|
75
|
+
|
76
|
+
flash[:success] = LANGUAGES[:lato_blog][:flashes][:tag_update_success]
|
77
|
+
redirect_to lato_blog.tag_path(@tag.id)
|
78
|
+
end
|
79
|
+
|
80
|
+
# This function destroyes a tag.
|
81
|
+
def destroy
|
82
|
+
@tag = LatoBlog::Tag.find_by(id: params[:id])
|
83
|
+
return unless check_tag_presence
|
84
|
+
|
85
|
+
if !@tag.destroy
|
86
|
+
flash[:danger] = @tag.tag_parent.errors.full_messages.to_sentence
|
87
|
+
redirect_to lato_blog.edit_tag_path(@tag.id)
|
88
|
+
return
|
89
|
+
end
|
90
|
+
|
91
|
+
flash[:success] = LANGUAGES[:lato_blog][:flashes][:tag_destroy_success]
|
92
|
+
redirect_to lato_blog.categories_path(status: 'deleted')
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
# This function checks the @tag variable is present and redirect to index if it not exist.
|
98
|
+
def check_tag_presence
|
99
|
+
if !@tag
|
100
|
+
flash[:warning] = LANGUAGES[:lato_blog][:flashes][:tag_not_found]
|
101
|
+
redirect_to lato_blog.tags_path
|
102
|
+
return false
|
103
|
+
end
|
104
|
+
|
105
|
+
return true
|
106
|
+
end
|
107
|
+
|
108
|
+
# Params helpers:
|
109
|
+
|
110
|
+
# This function generate params for a new tag.
|
111
|
+
def new_tag_params
|
112
|
+
# take params from front-end request
|
113
|
+
tag_params = params.require(:tag).permit(:title).to_h
|
114
|
+
# add current superuser id
|
115
|
+
tag_params[:lato_core_superuser_creator_id] = @core__current_superuser.id
|
116
|
+
# add post parent id
|
117
|
+
tag_params[:lato_blog_tag_parent_id] = (params[:parent] && !params[:parent].blank? ? params[:parent] : generate_tag_parent)
|
118
|
+
# add metadata
|
119
|
+
tag_params[:meta_language] = cookies[:lato_blog__current_language]
|
120
|
+
# return final post object
|
121
|
+
return tag_params
|
122
|
+
end
|
123
|
+
|
124
|
+
# This function generate params for a edit tag.
|
125
|
+
def edit_tag_params
|
126
|
+
params.require(:tag).permit(:title, :lato_blog_tag_id, :meta_permalink)
|
127
|
+
end
|
128
|
+
|
129
|
+
# This function generate and save a new tag parent and return the id.
|
130
|
+
def generate_tag_parent
|
131
|
+
tag_parent = LatoBlog::TagParent.create
|
132
|
+
return tag_parent.id
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
@@ -22,6 +22,9 @@ module LatoBlog
|
|
22
22
|
# add categories informations
|
23
23
|
serialized[:categories] = serialize_categories
|
24
24
|
|
25
|
+
# add tags informations
|
26
|
+
serialized[:tags] = serialize_tags
|
27
|
+
|
25
28
|
# add post parent informations
|
26
29
|
serialized[:other_informations] = serialize_other_informations
|
27
30
|
|
@@ -55,7 +58,7 @@ module LatoBlog
|
|
55
58
|
serialized
|
56
59
|
end
|
57
60
|
|
58
|
-
# This function serializes the list of
|
61
|
+
# This function serializes the list of categories for the post.
|
59
62
|
def serialize_categories
|
60
63
|
serialized = {}
|
61
64
|
categories.each do |category|
|
@@ -64,6 +67,15 @@ module LatoBlog
|
|
64
67
|
serialized
|
65
68
|
end
|
66
69
|
|
70
|
+
# This function serializes the list of tags for the post.
|
71
|
+
def serialize_tags
|
72
|
+
serialized = {}
|
73
|
+
tags.each do |tag|
|
74
|
+
serialized[tag.id] = tag.serialize_base
|
75
|
+
end
|
76
|
+
serialized
|
77
|
+
end
|
78
|
+
|
67
79
|
# This function serializes other informations for the post.
|
68
80
|
def serialize_other_informations
|
69
81
|
serialized = {}
|
@@ -29,6 +29,11 @@ module LatoBlog
|
|
29
29
|
dependent: :destroy
|
30
30
|
has_many :categories, through: :category_relations
|
31
31
|
|
32
|
+
has_many :tag_relations, foreign_key: :lato_blog_post_id,
|
33
|
+
class_name: 'LatoBlog::TagPost',
|
34
|
+
dependent: :destroy
|
35
|
+
has_many :tags, through: :tag_relations
|
36
|
+
|
32
37
|
# Scopes:
|
33
38
|
|
34
39
|
scope :published, -> { where(meta_status: BLOG_POSTS_STATUS[:published]) }
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module LatoBlog
|
2
|
+
module Tag::EntityHelpers
|
3
|
+
|
4
|
+
# This function return the pretty name of the language of the tag.
|
5
|
+
def get_pretty_language
|
6
|
+
CONFIGS[:lato_blog][:languages].values.each do |language|
|
7
|
+
return language[:title] if language[:identifier] === self.meta_language
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# This function returns a pretty presentation of the creation date for the post.
|
12
|
+
def get_pretty_created_at
|
13
|
+
self.created_at.strftime('%d/%m/%Y - %H:%M')
|
14
|
+
end
|
15
|
+
|
16
|
+
# This function returns a pretty presentation of the update date for the post.
|
17
|
+
def get_pretty_updated_at
|
18
|
+
self.updated_at.strftime('%d/%m/%Y - %H:%M')
|
19
|
+
end
|
20
|
+
|
21
|
+
# This function returns the name of the superuser creator of the post.
|
22
|
+
def get_superuser_creator_name
|
23
|
+
self.superuser_creator ? self.superuser_creator.get_complete_name : 'Anonymous'
|
24
|
+
end
|
25
|
+
|
26
|
+
# This function the post translation for a specific language.
|
27
|
+
def get_translation_for_language language_identifier
|
28
|
+
self.tag_parent.tags.find_by(meta_language: language_identifier)
|
29
|
+
end
|
30
|
+
|
31
|
+
# This function return the number of posts of the tag.
|
32
|
+
def get_number_of_posts
|
33
|
+
self.posts.length
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module LatoBlog
|
2
|
+
module Tag::SerializerHelpers
|
3
|
+
|
4
|
+
# This function serializes a complete version of the tag.
|
5
|
+
def serialize
|
6
|
+
serialized = {}
|
7
|
+
|
8
|
+
# set basic info
|
9
|
+
serialized[:id] = id
|
10
|
+
serialized[:title] = title
|
11
|
+
serialized[:meta_language] = meta_language
|
12
|
+
serialized[:meta_permalink] = meta_permalink
|
13
|
+
|
14
|
+
# add tag parent informations
|
15
|
+
serialized[:other_informations] = serialize_other_informations
|
16
|
+
|
17
|
+
# return serialized post
|
18
|
+
serialized
|
19
|
+
end
|
20
|
+
|
21
|
+
# This function serializes a basic version of the tag.
|
22
|
+
def serialize_base
|
23
|
+
serialized = {}
|
24
|
+
|
25
|
+
# set basic info
|
26
|
+
serialized[:id] = id
|
27
|
+
serialized[:title] = title
|
28
|
+
serialized[:meta_language] = meta_language
|
29
|
+
serialized[:meta_permalink] = meta_permalink
|
30
|
+
|
31
|
+
# return serialized tag
|
32
|
+
serialized
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def serialize_other_informations
|
38
|
+
serialized = {}
|
39
|
+
|
40
|
+
# set translations links
|
41
|
+
serialized[:translations] = {}
|
42
|
+
tag_parent.tags.each do |tag|
|
43
|
+
next if tag.id == id
|
44
|
+
serialized[:translations][tag.meta_language] = tag.serialize_base
|
45
|
+
end
|
46
|
+
|
47
|
+
# return serialzed informations
|
48
|
+
serialized
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module LatoBlog
|
2
|
+
class Tag < ApplicationRecord
|
3
|
+
|
4
|
+
include Tag::EntityHelpers
|
5
|
+
include Tag::SerializerHelpers
|
6
|
+
|
7
|
+
# Validations:
|
8
|
+
|
9
|
+
validates :title, presence: true, length: { maximum: 250 }
|
10
|
+
|
11
|
+
validates :meta_permalink, presence: true, uniqueness: true,
|
12
|
+
length: { maximum: 250 }
|
13
|
+
validates :meta_language, presence: true, length: { maximum: 250 },
|
14
|
+
inclusion: { in: ([nil] + BLOG_LANGUAGES_IDENTIFIER) }
|
15
|
+
|
16
|
+
# Relations:
|
17
|
+
|
18
|
+
belongs_to :tag_parent, foreign_key: :lato_blog_tag_parent_id,
|
19
|
+
class_name: 'LatoBlog::TagParent'
|
20
|
+
|
21
|
+
belongs_to :superuser_creator, foreign_key: :lato_core_superuser_creator_id,
|
22
|
+
class_name: 'LatoCore::Superuser'
|
23
|
+
|
24
|
+
has_many :post_relations, foreign_key: :lato_blog_tag_id,
|
25
|
+
class_name: 'LatoBlog::TagPost',
|
26
|
+
dependent: :destroy
|
27
|
+
has_many :posts, through: :post_relations
|
28
|
+
|
29
|
+
# Callbacks:
|
30
|
+
|
31
|
+
before_validation :check_meta_permalink, on: :create
|
32
|
+
|
33
|
+
before_save do
|
34
|
+
self.meta_permalink = meta_permalink.parameterize
|
35
|
+
meta_language.downcase!
|
36
|
+
|
37
|
+
check_lato_blog_tag_parent
|
38
|
+
end
|
39
|
+
|
40
|
+
after_destroy do
|
41
|
+
blog__clean_tag_parents
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
# This function check if current permalink is valid. If it is not valid it
|
47
|
+
# generate a new from the post title.
|
48
|
+
def check_meta_permalink
|
49
|
+
candidate = (self.meta_permalink ? self.meta_permalink : self.title.parameterize)
|
50
|
+
accepted = nil
|
51
|
+
counter = 0
|
52
|
+
|
53
|
+
while accepted.nil?
|
54
|
+
if LatoBlog::Tag.find_by(meta_permalink: candidate)
|
55
|
+
counter += 1
|
56
|
+
candidate = "#{candidate}-#{counter}"
|
57
|
+
else
|
58
|
+
accepted = candidate
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
self.meta_permalink = accepted
|
63
|
+
end
|
64
|
+
|
65
|
+
# This function check that the category parent exist and has not others tags for the same language.
|
66
|
+
def check_lato_blog_tag_parent
|
67
|
+
tag_parent = LatoBlog::TagParent.find_by(id: lato_blog_tag_parent_id)
|
68
|
+
if !tag_parent
|
69
|
+
errors.add('Tag parent', 'not exist for the tag')
|
70
|
+
throw :abort
|
71
|
+
return
|
72
|
+
end
|
73
|
+
|
74
|
+
same_language_tag = tag_parent.tags.find_by(meta_language: meta_language)
|
75
|
+
if same_language_tag && same_language_tag.id != id
|
76
|
+
errors.add('Tag parent', 'has another tag for the same language')
|
77
|
+
throw :abort
|
78
|
+
return
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module LatoBlog
|
2
|
+
class TagPost < ApplicationRecord
|
3
|
+
|
4
|
+
# Validations:
|
5
|
+
|
6
|
+
validates :lato_blog_tag_id, presence: true
|
7
|
+
validates :lato_blog_post_id, presence: true
|
8
|
+
|
9
|
+
# Relations:
|
10
|
+
|
11
|
+
belongs_to :tag, foreign_key: :lato_blog_tag_id, class_name: 'LatoBlog::Tag'
|
12
|
+
|
13
|
+
belongs_to :post, foreign_key: :lato_blog_post_id, class_name: 'LatoBlog::Post'
|
14
|
+
|
15
|
+
# Callbacks:
|
16
|
+
|
17
|
+
before_save do
|
18
|
+
check_relation_language
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def check_relation_language
|
24
|
+
if self.tag.meta_language != self.post.meta_language
|
25
|
+
errors.add('Tag and Post', 'have not same language')
|
26
|
+
throw :abort
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -8,9 +8,15 @@
|
|
8
8
|
|
9
9
|
<%=raw block.open %>
|
10
10
|
|
11
|
-
<%=raw cell(:widgets, :index).new(
|
12
|
-
|
13
|
-
|
11
|
+
<%=raw cell(:widgets, :index).new(
|
12
|
+
records: @widget_index_categories,
|
13
|
+
index_url: lato_blog.categories_path,
|
14
|
+
head: [LANGUAGES[:lato_blog][:forms][:title], LANGUAGES[:lato_blog][:forms][:language], LANGUAGES[:lato_blog][:forms][:category_father], LANGUAGES[:lato_blog][:mixed][:number_of_posts]],
|
15
|
+
columns: ['title', 'get_pretty_language', 'get_category_father_title', 'get_number_of_posts'],
|
16
|
+
actions: {show: true, new: true, delete: true},
|
17
|
+
search: true,
|
18
|
+
pagination: true
|
19
|
+
) %>
|
14
20
|
|
15
21
|
<%=raw block.close %>
|
16
22
|
|
@@ -15,6 +15,8 @@
|
|
15
15
|
|
16
16
|
<%=raw block.open %>
|
17
17
|
|
18
|
+
<%=raw cell(:elements, :title).new(label: @post.title, size: 4) %>
|
19
|
+
|
18
20
|
<%= render 'lato_blog/back/posts/shared/form', url: lato_blog.post_path(@post.id), method: :put %>
|
19
21
|
|
20
22
|
<%=raw block.close %>
|
@@ -37,6 +39,8 @@
|
|
37
39
|
|
38
40
|
<%= render 'lato_blog/back/posts/shared/edit/edit_pubblication_datetime' %>
|
39
41
|
|
42
|
+
<%= render 'lato_blog/back/posts/shared/edit/edit_tags' %>
|
43
|
+
|
40
44
|
<%= render 'lato_blog/back/posts/shared/edit/edit_categories' %>
|
41
45
|
|
42
46
|
<%= render 'lato_blog/back/posts/shared/edit/edit_seo_description' %>
|
@@ -15,6 +15,8 @@
|
|
15
15
|
|
16
16
|
<%=raw block.open %>
|
17
17
|
|
18
|
+
<%=raw cell(:elements, :title).new(label: LANGUAGES[:lato_blog][:mixed][:create_new_post], size: 4) %>
|
19
|
+
|
18
20
|
<%= render 'lato_blog/back/posts/shared/form', url: lato_blog.posts_path, method: :post %>
|
19
21
|
|
20
22
|
<%=raw block.close %>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<%
|
2
|
+
block = cell(:elements, :block).new(class: 'xs-12 sm-12 md-12 posts__edit-tags')
|
3
|
+
row = cell(:elements, :row).new
|
4
|
+
form = cell(:inputs, :form).new(url: lato_blog.posts_update_tags_path, method: :post, remote: true)
|
5
|
+
%>
|
6
|
+
|
7
|
+
<%=raw block.open %>
|
8
|
+
|
9
|
+
<%=raw cell(:elements, :title).new(label: LANGUAGES[:lato_blog][:mixed][:tags], size: 6) %>
|
10
|
+
|
11
|
+
<%=raw form.open %>
|
12
|
+
|
13
|
+
<input type="hidden" name="id" value="<%= @post.id %>">
|
14
|
+
|
15
|
+
<%=raw row.open %>
|
16
|
+
|
17
|
+
<%=raw cell(:inputs, :select).new(
|
18
|
+
name: 'tags[]',
|
19
|
+
options: @tags.map { |t| {value: t.id, name: t.title} },
|
20
|
+
multiple: true,
|
21
|
+
value: @post.tags.pluck(:id)
|
22
|
+
) %>
|
23
|
+
|
24
|
+
<%=raw row.close %>
|
25
|
+
|
26
|
+
<%=raw form.close %>
|
27
|
+
|
28
|
+
<%=raw block.close %>
|