rails_admin_draft 0.1.1 → 0.1.3
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 +4 -4
- data/README.md +1 -1
- data/app/views/rails_admin/main/edit.html.erb +4 -1
- data/config/locales/rails_admin_draft/en.yml +1 -0
- data/config/locales/rails_admin_draft/fr.yml +1 -0
- data/lib/rails_admin_draft/concern/draft_concern.rb +20 -15
- data/lib/rails_admin_draft/services/draft/overwrite_service.rb +21 -1
- data/lib/rails_admin_draft/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50f58bc7bf92dc6416841d6c1f6d45ec06d10c08c8c2c73c6ef44d9a992c0fc0
|
4
|
+
data.tar.gz: e9c3a67f666a61995fd37c687b9b2a1b35d0cfde738e905b6f2d5af2e47a19b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d727b538cd1d7c1ee072fd03575215df9c651f9396f31dc5f58af2c2246e55f13ff49f5741f460a37351221351877dc0dfbbc6693def7bde51607b996b50b639
|
7
|
+
data.tar.gz: 845c88469340f36465b6b71f91dbd2e5ca1b7afc69edb15e06b0a22e3fd5abd4ca4dfc35edd7f1a324d63c9c1255db67ffd1bae83532a18cc170ce69462f4451
|
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
<% if @draft_conf.draft? && @object.is_draft? %>
|
2
2
|
<div class="alert alert-dark">
|
3
|
-
<b><%=I18n.t('admin.form.draft_header')%></b>
|
3
|
+
<b><%= I18n.t('admin.form.draft_header') %></b>
|
4
|
+
<% if @object.draft_source_id.present? %>
|
5
|
+
<%= I18n.t('admin.form.of' )%> <%= link_to "#{@object.class.name} ID:1", edit_path(@abstract_model, @object.draft_source_id) %>
|
6
|
+
<% end %>
|
4
7
|
</div>
|
5
8
|
<% end %>
|
6
9
|
|
@@ -55,22 +55,27 @@ module DraftConcern
|
|
55
55
|
return if !self.is_draft?
|
56
56
|
model_to_publish = self
|
57
57
|
|
58
|
-
|
59
|
-
if
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
58
|
+
if self.draft_source_id.present?
|
59
|
+
# Save new image if we publish directly the draft
|
60
|
+
self.image.store! if self.image.present?
|
61
|
+
self.save!
|
62
|
+
|
63
|
+
model_to_publish = Draft::OverwriteService.new(source: self, destination: self.draft_source).perform
|
64
|
+
model_to_publish.slug = self.slug # Keep same slug
|
65
|
+
|
66
|
+
if Object.const_defined?('DiscardConcern') && self.class.include?('DiscardConcern'.constantize)
|
67
|
+
self.image.remove!
|
68
|
+
self.destroy(true)
|
69
|
+
else
|
70
|
+
self.image.remove!
|
71
|
+
self.destroy
|
68
72
|
end
|
69
|
-
|
70
|
-
model_to_publish.draft_status = DraftStatus::PUBLISHED
|
71
|
-
model_to_publish.save!
|
73
|
+
remove_draft_on_unique_text_fields(model_to_publish)
|
72
74
|
end
|
73
75
|
|
76
|
+
model_to_publish.draft_status = DraftStatus::PUBLISHED
|
77
|
+
model_to_publish.save!
|
78
|
+
|
74
79
|
return model_to_publish
|
75
80
|
end
|
76
81
|
|
@@ -98,8 +103,8 @@ module DraftConcern
|
|
98
103
|
|
99
104
|
class_methods do
|
100
105
|
# Creates bi-directional association for draft source.
|
101
|
-
def
|
102
|
-
association_class_name =
|
106
|
+
def has_draft
|
107
|
+
association_class_name = self.name.to_s
|
103
108
|
class_eval do
|
104
109
|
has_one :draft, class_name: "#{association_class_name}", foreign_key: :draft_source_id, inverse_of: :draft_source
|
105
110
|
belongs_to :draft_source, class_name: "#{association_class_name}", optional: true
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
1
3
|
module Draft
|
2
4
|
class OverwriteService
|
3
5
|
DRAFT_ASSOCIATIONS = [:draft, :draft_source]
|
@@ -46,8 +48,26 @@ module Draft
|
|
46
48
|
return if attributes.blank?
|
47
49
|
|
48
50
|
attributes.each do |attribute|
|
49
|
-
|
51
|
+
if @destination.send(attribute).present?
|
52
|
+
destination_path = File.dirname(File.open(@destination.send(attribute).file.path))
|
53
|
+
@destination.send(attribute).remove!
|
54
|
+
|
55
|
+
end
|
56
|
+
|
50
57
|
new_upload = @source.send(attribute).present? ? File.open(@source.send(attribute).file.path) : nil
|
58
|
+
|
59
|
+
if @source.image.present?
|
60
|
+
dir_source = @source.send(attribute).file.path.remove(@source.send(attribute).identifier)
|
61
|
+
|
62
|
+
Dir[File.join(dir_source, "*#{@source.send(attribute).identifier}")].each do | filename |
|
63
|
+
# copy if image destination is present
|
64
|
+
FileUtils.mv(filename, destination_path) if destination_path.present?
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Delete folder
|
69
|
+
FileUtils.remove_dir(dir_source, true) if dir_source.present?
|
70
|
+
|
51
71
|
@destination.send("#{attribute}=", new_upload)
|
52
72
|
end
|
53
73
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_admin_draft
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grégory Huet
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-02-
|
12
|
+
date: 2023-02-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|