rails_admin_draft 0.1.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/README.md +115 -0
- data/Rakefile +11 -0
- data/app/assets/stylesheets/rails_admin/rails_admin_draft.css +3 -0
- data/app/views/rails_admin/main/_submit_buttons.html.erb +53 -0
- data/app/views/rails_admin/main/edit.html.erb +9 -0
- metadata +204 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fedb5ecfd53550b653e9f7f657e25d50249340b1e2c91d9438f10a400d797e7b
|
4
|
+
data.tar.gz: 4fe1a560eb1ac34cce4cca876e7017f579203f79d68073bb5f9ebf638a62317f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '009375e2a43f657dca86acfd1db71b6dd4e1cb2f39df18c02b26cb564bf5713ad4605670c1fc79098883d3f8c7fd5249be8bb3bb5283d82b0e05f63044961635'
|
7
|
+
data.tar.gz: e8878ea65561aa366b08e1a782efee1fe9395c4f22cf9590857ee9f90f2da4127f5786c3cd120545b68f92be16fc1f1e7d9ee649e84fadf00af7098bec313850
|
data/README.md
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
# Rails Admin Draft
|
2
|
+
|
3
|
+
Rails Admin Draft allows you to make drafts of the desired models in [rails_admin](https://github.com/railsadminteam/rails_admin).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rails_admin_draft'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```
|
16
|
+
$ bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```
|
22
|
+
$ gem install rails_admin_draft
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Add draft columns to your table
|
28
|
+
|
29
|
+
Create migration
|
30
|
+
|
31
|
+
```
|
32
|
+
$ rails generate draft_migration --table [TABLE]
|
33
|
+
```
|
34
|
+
|
35
|
+
Run the migration
|
36
|
+
|
37
|
+
```
|
38
|
+
$ rake db:migrate
|
39
|
+
```
|
40
|
+
|
41
|
+
### Add draft to your model
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
class MyModel < ApplicationRecord
|
45
|
+
include DraftConcern
|
46
|
+
set_draft_relation(klass_name: "MyModel")
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
### Add draft to your rails_admin model config
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
RailsAdmin.config do |config|
|
54
|
+
config.model 'MyModel' do
|
55
|
+
has_draft true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
### Add copy_as_draft action in your rails_admin config
|
61
|
+
|
62
|
+
You can skip this part if you don't want the copy_as_draft action in the listings.
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
RailsAdmin.config do |config|
|
66
|
+
config.actions do
|
67
|
+
copy_as_draft
|
68
|
+
end
|
69
|
+
end
|
70
|
+
```
|
71
|
+
|
72
|
+
## Additional information
|
73
|
+
|
74
|
+
### Available scopes
|
75
|
+
|
76
|
+
When your model includes `DraftConcern`, you have access to the following scopes:
|
77
|
+
- `draft`: Records where draft_status = 'draft'
|
78
|
+
- `published`: Records where draft_status = 'published'
|
79
|
+
|
80
|
+
### Available rails_admin scopes
|
81
|
+
|
82
|
+
When your model includes `DraftConcern`, you have access to the following scopes:
|
83
|
+
- `rails_admin_all`: All records
|
84
|
+
- `rails_admin_draft`: Records where draft_status = 'draft'
|
85
|
+
- `rails_admin_published`: Records where draft_status = 'draft'
|
86
|
+
|
87
|
+
These can be used to add scopes in rails_admin listing:
|
88
|
+
```ruby
|
89
|
+
RailsAdmin.config do |config|
|
90
|
+
config.model 'MyModel' do
|
91
|
+
has_draft true
|
92
|
+
list do
|
93
|
+
scopes [:rails_admin_all, :rails_admin_published, :rails_admin_draft]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
```
|
98
|
+
|
99
|
+
### Available methods
|
100
|
+
|
101
|
+
When your model includes `DraftConcern`, you have access to the following methods:
|
102
|
+
- `title_with_draft_status`: Adds 'draft' to your model's title if it's a draft. Used to display in rails_admin listing. By default, the title attribute is `title`. If you want to change it, override the `title_attribute` class method in your model.
|
103
|
+
- `is_draft?`: Returns true if your model is a draft
|
104
|
+
- `is_published?`: Returns true if your model is published
|
105
|
+
|
106
|
+
### Overridable class methods
|
107
|
+
|
108
|
+
When your model includes `DraftConcern`, you can override these class methods:
|
109
|
+
- `unique_text_fields`: List of string fields that are unique. When you copy a published record as draft, the string 'draft-' will be added at the beginning of each field to avoid unique constraint errors. The string 'draft-' is removed when the record is published. By default, the only field is `slug`.
|
110
|
+
- `except_upload_attributes`: When you copy a record as draft, its uploads are also copied. To prevent an upload of being copied, add it to this list. You can also add attributes in associated tables. Ex: `[ :image, { relation_name: :associated_model, attribute: :image } ]`
|
111
|
+
- `title_attribute`: The attribute that represent the title/name of the record. By default, it is set to `title`. Used by the `title_with_draft_status` method.
|
112
|
+
|
113
|
+
### How to handle unique indexes
|
114
|
+
|
115
|
+
Since this gem allows a published record to be copied as draft, you have to make sure your unique indexes are composite indexes including the `draft_status` attribute.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
<div class="form-actions row justify-content-end my-3">
|
2
|
+
<div class="col-sm-10">
|
3
|
+
<input name="return_to" type="<%= :hidden %>" value="<%= (params[:return_to].presence || request.referer) %>" />
|
4
|
+
|
5
|
+
<% if Object.const_defined?('DraftConcern') && @object.class.include?('DraftConcern'.constantize) %>
|
6
|
+
<% if @object.is_draft? || @object.new_record? %>
|
7
|
+
<button class="btn btn-primary" title="<%= t("admin.form.buttons.publish.title") %>"data-disable-with="<%= t("admin.form.buttons.publish.name") %>" name="_publish" type="submit"<%= ' disabled' unless @action.enabled? %>>
|
8
|
+
<i class="fas fa-check"></i>
|
9
|
+
<%= t("admin.form.buttons.publish.name") %>
|
10
|
+
</button>
|
11
|
+
<button class="btn btn-secondary" title="<%= t("admin.form.buttons.save_draft.title") %>" data-disable-with="<%= t("admin.form.buttons.save_draft.name") %>" name="_add_edit" type="submit"<%= ' disabled' unless @action.enabled? %>>
|
12
|
+
<%= t("admin.form.buttons.save_draft.name") %>
|
13
|
+
</button>
|
14
|
+
<% elsif @object.is_published? %>
|
15
|
+
<button class="btn btn-primary" title="<%= t("admin.form.save") %>" data-disable-with="<%= t("admin.form.save") %>" name="_save" type="submit"<%= ' disabled' unless @action.enabled? %>>
|
16
|
+
<i class="fas fa-check"></i>
|
17
|
+
<%= t("admin.form.save") %>
|
18
|
+
</button>
|
19
|
+
<% if !@object.class.exists?(draft_source_id: @object.id) %>
|
20
|
+
<button class="btn btn-secondary" title="<%= t("admin.form.buttons.switch_to_draft.title") %>" data-disable-with="<%= t("admin.form.buttons.switch_to_draft.name") %>" name="_switch_to_draft" type="submit"<%= ' disabled' unless @action.enabled? %>>
|
21
|
+
<%= t("admin.form.buttons.switch_to_draft.name") %>
|
22
|
+
</button>
|
23
|
+
<% end %>
|
24
|
+
<button class="btn btn-secondary" title="<%= t("admin.form.buttons.copy_as_draft.title") %>" data-disable-with="<%= t("admin.form.buttons.copy_as_draft.name") %>" name="_copy_as_draft" type="submit"<%= ' disabled' unless @action.enabled? %>>
|
25
|
+
<%= t("admin.form.buttons.copy_as_draft.name") %>
|
26
|
+
</button>
|
27
|
+
<% end %>
|
28
|
+
<% else %>
|
29
|
+
<button class="btn btn-primary" title="<%= t("admin.form.save") %>" data-disable-with="<%= t("admin.form.save") %>" name="_save" type="submit"<%= ' disabled' unless @action.enabled? %>>
|
30
|
+
<i class="fas fa-check"></i>
|
31
|
+
<%= t("admin.form.save") %>
|
32
|
+
</button>
|
33
|
+
<% end %>
|
34
|
+
|
35
|
+
<span class="extra_buttons">
|
36
|
+
<% if @action.enabled? && authorized?(:new, @abstract_model) %>
|
37
|
+
<button class="btn btn-info" title="<%= t("admin.form.save_and_add_another") %>" data-disable-with="<%= t("admin.form.save_and_add_another") %>" name="_add_another" type="submit">
|
38
|
+
<%= t("admin.form.save_and_add_another") %>
|
39
|
+
</button>
|
40
|
+
<% end %>
|
41
|
+
<% if @action.enabled? && authorized?(:edit, @abstract_model) %>
|
42
|
+
<button class="btn btn-info" title="<%= t("admin.form.save_and_edit") %>" data-disable-with="<%= t("admin.form.save_and_edit") %>" name="_add_edit" type="submit"<%= ' disabled' unless @action.enabled? %>>
|
43
|
+
<%= t("admin.form.save_and_edit") %>
|
44
|
+
</button>
|
45
|
+
<% end %>
|
46
|
+
<button class="btn btn-light" title="<%= t("admin.form.cancel") %>" data-disable-with="<%= t("admin.form.cancel") %>" formnovalidate="<%= true %>" name="_continue" type="submit">
|
47
|
+
<i class="fas fa-times"></i>
|
48
|
+
<%= t("admin.form.cancel") %>
|
49
|
+
</button>
|
50
|
+
</span>
|
51
|
+
</div>
|
52
|
+
</div>
|
53
|
+
<%= stylesheet_link_tag "rails_admin/rails_admin_draft", media: "all" %>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<% if @draft_conf.draft? && @object.is_draft? %>
|
2
|
+
<div class="alert alert-dark">
|
3
|
+
<b><%=I18n.t('admin.form.draft_header')%></b>
|
4
|
+
</div>
|
5
|
+
<% end %>
|
6
|
+
|
7
|
+
<%= rails_admin_form_for @object, url: edit_path(@abstract_model, @object.id), as: @abstract_model.param_key, html: { method: "put", multipart: true, class: "main", data: { title: @page_name } } do |form| %>
|
8
|
+
<%= form.generate action: :update %>
|
9
|
+
<% end %>
|
metadata
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_admin_draft
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Grégory Huet
|
8
|
+
- Louis-Charles Drouin-Zara
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2023-01-31 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '7.0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '7.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rails_admin
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '3.1'
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 3.1.1
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - "~>"
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '3.1'
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.1.1
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: sass-rails
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '6.0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '6.0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: amoeba
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.2.0
|
69
|
+
type: :runtime
|
70
|
+
prerelease: false
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.2.0
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: rails
|
78
|
+
requirement: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '7.0'
|
83
|
+
type: :development
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '7.0'
|
90
|
+
- !ruby/object:Gem::Dependency
|
91
|
+
name: rails_admin
|
92
|
+
requirement: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.1'
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 3.1.1
|
100
|
+
type: :development
|
101
|
+
prerelease: false
|
102
|
+
version_requirements: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - "~>"
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '3.1'
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 3.1.1
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rake
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '13.0'
|
117
|
+
type: :development
|
118
|
+
prerelease: false
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '13.0'
|
124
|
+
- !ruby/object:Gem::Dependency
|
125
|
+
name: minitest
|
126
|
+
requirement: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '5.0'
|
131
|
+
type: :development
|
132
|
+
prerelease: false
|
133
|
+
version_requirements: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '5.0'
|
138
|
+
- !ruby/object:Gem::Dependency
|
139
|
+
name: amoeba
|
140
|
+
requirement: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: 3.2.0
|
145
|
+
type: :development
|
146
|
+
prerelease: false
|
147
|
+
version_requirements: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - "~>"
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: 3.2.0
|
152
|
+
- !ruby/object:Gem::Dependency
|
153
|
+
name: carrierwave
|
154
|
+
requirement: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - "~>"
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: 2.2.3
|
159
|
+
type: :development
|
160
|
+
prerelease: false
|
161
|
+
version_requirements: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - "~>"
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: 2.2.3
|
166
|
+
description: Give the possibility to change a model status (draft or publish) and
|
167
|
+
overwrite an existing published with its draft.
|
168
|
+
email:
|
169
|
+
- dev@ixmedia.com
|
170
|
+
executables: []
|
171
|
+
extensions: []
|
172
|
+
extra_rdoc_files: []
|
173
|
+
files:
|
174
|
+
- README.md
|
175
|
+
- Rakefile
|
176
|
+
- app/assets/stylesheets/rails_admin/rails_admin_draft.css
|
177
|
+
- app/views/rails_admin/main/_submit_buttons.html.erb
|
178
|
+
- app/views/rails_admin/main/edit.html.erb
|
179
|
+
homepage: https://github.com/ixmedia/rails_admin_draft
|
180
|
+
licenses:
|
181
|
+
- MIT
|
182
|
+
metadata:
|
183
|
+
homepage_uri: https://github.com/ixmedia/rails_admin_draft
|
184
|
+
source_code_uri: https://github.com/ixmedia/rails_admin_draft
|
185
|
+
post_install_message:
|
186
|
+
rdoc_options: []
|
187
|
+
require_paths:
|
188
|
+
- lib
|
189
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: 2.6.5
|
194
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
195
|
+
requirements:
|
196
|
+
- - ">="
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
version: '0'
|
199
|
+
requirements: []
|
200
|
+
rubygems_version: 3.3.7
|
201
|
+
signing_key:
|
202
|
+
specification_version: 4
|
203
|
+
summary: Have the possibility to create a draft from a published post
|
204
|
+
test_files: []
|