active_versioning_workflow 1.0.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/.gitignore +10 -0
- data/.rspec +2 -0
- data/Gemfile +3 -0
- data/README.md +170 -0
- data/Rakefile +6 -0
- data/active_versioning_workflow.gemspec +31 -0
- data/app/assets/javascripts/active_versioning/workflow.js +13 -0
- data/app/assets/stylesheets/active_versioning/workflow.scss +96 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/circle.yml +6 -0
- data/lib/active_versioning/workflow.rb +15 -0
- data/lib/active_versioning/workflow/controller.rb +78 -0
- data/lib/active_versioning/workflow/draft_actions.rb +16 -0
- data/lib/active_versioning/workflow/dsl.rb +9 -0
- data/lib/active_versioning/workflow/engine.rb +9 -0
- data/lib/active_versioning/workflow/previewable.rb +31 -0
- data/lib/active_versioning/workflow/router.rb +13 -0
- data/lib/active_versioning/workflow/show_resource.rb +128 -0
- data/lib/active_versioning/workflow/show_version.rb +51 -0
- data/lib/active_versioning/workflow/version.rb +5 -0
- data/lib/active_versioning_workflow.rb +1 -0
- data/lib/generators/active_versioning/templates/active_admin_resources/version.rb +45 -0
- data/lib/generators/active_versioning/templates/active_admin_views/_commit_form.html.erb +17 -0
- data/lib/generators/active_versioning/templates/initializers/active_versioning_workflow.rb +4 -0
- data/lib/generators/active_versioning/templates/locales/active_versioning.en.yml +31 -0
- data/lib/generators/active_versioning/workflow_generator.rb +35 -0
- metadata +156 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c6ccbcef6a2ddf4cbbac736460c019d342ebf637
|
4
|
+
data.tar.gz: 7f648b388482f2481c5b1c086136de3f5b97242e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f121626c87df06c944365fc4e06a81f9eb0632f2079b35c9f2bf1df17557063e2369f5b153f1273018c05013835a2bc3e27daa1534b1b6644364dcfa51fd5fd6
|
7
|
+
data.tar.gz: ad18878f2135250692f94ac247c0c143933c7fae5a526253350097c4523b0c41dc5e124cdd000abaeca897fa6d4ec2bd60bb2efdab4ed6af5d3ed9ef2c578e7a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
# ActiveVersioning Workflow
|
2
|
+
|
3
|
+
ActiveVersioning Workflow is an extension of ActiveVersioning that provides version workflow for ActiveAdmin-based CMSes.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
ActiveVersioning Workflow is designed for ActiveAdmin, ActiveMaterial, and Rails 4.2+ applications, so ensure you have the following in your gemfile:
|
8
|
+
```ruby
|
9
|
+
gem 'activeadmin', github: 'activeadmin'
|
10
|
+
gem 'devise' # Necessary if using standard ActiveAdmin configuration
|
11
|
+
gem 'active_material', git: 'git@github.com:vigetlabs/active_material.git'
|
12
|
+
```
|
13
|
+
These should all be installed and configured as well.
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
```ruby
|
17
|
+
gem 'active_versioning_workflow', git: 'git@github.com:vigetlabs/active_versioning_workflow.git'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
```
|
22
|
+
$ bundle install
|
23
|
+
$ rails generate active_versioning:workflow
|
24
|
+
$ bundle exec rake db:migrate
|
25
|
+
```
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
After installing all the necessary gems, there are a handful of things to do in order to get versioning workflow in place for an ActiveAdmin resource:
|
30
|
+
|
31
|
+
1. Configure models for versioning
|
32
|
+
2. Pull in necessary styles and javascript
|
33
|
+
3. Add versioned routes to the routes file
|
34
|
+
4. Include the workflow controller module to the ActiveAdmin resource
|
35
|
+
5. Configure how versioned resources are displayed in ActiveAdmin
|
36
|
+
6. Set up live preview (optional)
|
37
|
+
|
38
|
+
### Configure Models for Versioning
|
39
|
+
First off, if you haven't already configured the models you'd like to have versioned, follow the steps in the [ActiveVersioning README](https://github.com/vigetlabs/active_versioning).
|
40
|
+
|
41
|
+
### Require Stylesheets and Javascript
|
42
|
+
We'll need to pull in some CSS and JS for versioning to look and function correctly in ActiveAdmin.
|
43
|
+
|
44
|
+
In `app/assets/javascripts/active_admin.js.coffee`, add:
|
45
|
+
```coffeescript
|
46
|
+
#= require active_versioning/workflow
|
47
|
+
```
|
48
|
+
|
49
|
+
In `app/assets/stylesheets/active_admin.scss`, add the following after the other ActiveAdmin-related import statements:
|
50
|
+
```scss
|
51
|
+
@import "active_versioning/workflow";
|
52
|
+
```
|
53
|
+
|
54
|
+
### Versioned Routes (using `ActiveVersioning::Workflow::Router`)
|
55
|
+
The generator for ActiveVersioning Workflow includes a router module that provides a `versioned_routes` method inside the main Rails routes block. It takes a list of underscored model names and generates version routes for each of the given models:
|
56
|
+
```ruby
|
57
|
+
Rails.application.routes.draw do
|
58
|
+
self.class.send(:include, ActiveVersioning::Workflow::Router) # Inserted after running the generator
|
59
|
+
devise_for :admin_users, ActiveAdmin::Devise.config # Inserted by an ActiveAdmin install
|
60
|
+
ActiveAdmin.routes(self) # Inserted by an ActiveAdmin install
|
61
|
+
|
62
|
+
namespace :admin do
|
63
|
+
versioned_routes :posts
|
64
|
+
|
65
|
+
# If the Post model was namespaced -- something like Blog::Post -- you'd need to do the following based on how AA sets up routes:
|
66
|
+
versioned_routes :blog_posts
|
67
|
+
end
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
In a fresh ActiveAdmin-based Rails app, this is what your routes file would look like in order to manage a versioned `Post` model in ActiveAdmin under the `:admin` namespace (default namespace for ActiveAdmin). If you have ActiveAdmin configured differently and are using different namespaces, you'll want to use `versioned_routes` in the appropriate context.
|
72
|
+
|
73
|
+
In this example, we'd get routes like `/admin/posts/1/versions` and `/admin/posts/1/versions/1`.
|
74
|
+
|
75
|
+
*Note: If you are using a different attribute for admin URLs (eg: slug or friendly_id), then you'll need to manually specify this in `app/admin/version.rb` after running the generator. Running with the Post example, that would look like so:*
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
ActiveAdmin.register Version do
|
79
|
+
# ...
|
80
|
+
|
81
|
+
controller do
|
82
|
+
# Override the finder option if all your versioned models use the same thing, like `finder: :find_by_slug!` for example.
|
83
|
+
ActiveVersioning.versioned_models.each do |model|
|
84
|
+
belongs_to model.name.underscore.gsub('/', '_').to_sym, class_name: model.name, polymorphic: true, finder: :find_by_id!
|
85
|
+
end
|
86
|
+
|
87
|
+
# Otherwise, either replace the above block or explicitly add a `belongs_to` statement for each non-standard model:
|
88
|
+
belongs_to :post, polymorphic: true, finder: :find_by_slug!
|
89
|
+
|
90
|
+
# ...
|
91
|
+
end
|
92
|
+
end
|
93
|
+
```
|
94
|
+
|
95
|
+
### Versioned Controller (using `ActiveVersioning::Workflow::Controller`)
|
96
|
+
Running with the example of a versioned `Post` model, we should have a file that registers the `Post` model with ActiveAdmin (generated with the `rails generate active_admin:resource Post` command and probably lives at `app/admin/post.rb`). At the top of the register block, include the controller module:
|
97
|
+
```ruby
|
98
|
+
ActiveAdmin.register Post do
|
99
|
+
include ActiveVersioning::Workflow::Controller
|
100
|
+
end
|
101
|
+
```
|
102
|
+
|
103
|
+
This adds the necessary actions to the admin controller for our resource so we can work with versions.
|
104
|
+
|
105
|
+
### Versioned Form
|
106
|
+
Use the `draft_actions` method over the default `actions` method at the end of the form block:
|
107
|
+
```ruby
|
108
|
+
ActiveAdmin.register Post do
|
109
|
+
include ActiveVersioning::Workflow::Controller
|
110
|
+
|
111
|
+
form do |f|
|
112
|
+
inputs do
|
113
|
+
input :title
|
114
|
+
input :body
|
115
|
+
end
|
116
|
+
|
117
|
+
draft_actions
|
118
|
+
end
|
119
|
+
end
|
120
|
+
```
|
121
|
+
|
122
|
+
This pulls a label from `t('active_versioning.actions.draft')`, which is included in the generated locale file for ActiveVersioning Workflow. It defaults to "Save Draft".
|
123
|
+
|
124
|
+
### Versioned Show Page
|
125
|
+
Finally, we'll want to configure the show page for our versioned resource. This is done in a similar style to the regular `show` block in ActiveAdmin, except that we'll use `show_version` and `version_attributes_panel`:
|
126
|
+
```ruby
|
127
|
+
ActiveAdmin.register Post do
|
128
|
+
include ActiveVersioning::Workflow::Controller
|
129
|
+
|
130
|
+
permit_params :title, :body
|
131
|
+
|
132
|
+
show_version do |version|
|
133
|
+
version_attributes_panel(version) do
|
134
|
+
attributes_table_for(version) do
|
135
|
+
row :title
|
136
|
+
row :body
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
```
|
142
|
+
When all is said and done, this will give us an awesome interface for version workflow in ActiveAdmin:
|
143
|
+

|
144
|
+
|
145
|
+
### Live Preview
|
146
|
+
ActiveVersioning Workflow allows for some optional basic previewing functionality that leverages the non-admin controller for a resource. If you'd like to take advantage of previewing, here's how you'll want to set it up:
|
147
|
+
```ruby
|
148
|
+
class PostsController < ApplicationController
|
149
|
+
extend ActiveVersioning::Workflow::Previewable
|
150
|
+
|
151
|
+
preview_resource :post
|
152
|
+
|
153
|
+
def show
|
154
|
+
end
|
155
|
+
|
156
|
+
private
|
157
|
+
|
158
|
+
def post
|
159
|
+
@post ||= Post.find(params[:id])
|
160
|
+
end
|
161
|
+
helper_method :post
|
162
|
+
end
|
163
|
+
```
|
164
|
+
|
165
|
+
The `extend` adds the necessary functionality and `preview_resource` class method to the controller. Previewing only works for show pages where there's a single resource to preview, so you'll need a `show` method (and the corresponding route in your routes file) and then point the `preview_resource` at the reader method for the versioned resource.
|
166
|
+
|
167
|
+
In the ActiveAdmin draft panel, you'll see an extra preview button:
|
168
|
+

|
169
|
+
|
170
|
+
This will open a new window with our `PostsController#show` rendered out with the current draft version of our post.
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'active_versioning/workflow/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = "active_versioning_workflow"
|
10
|
+
spec.version = ActiveVersioning::Workflow::VERSION
|
11
|
+
spec.authors = ["Ryan Stenberg"]
|
12
|
+
spec.email = ["ryan.stenberg@viget.com"]
|
13
|
+
|
14
|
+
spec.summary = "An ActiveVersioning Extension for Version Workflow in ActiveAdmin"
|
15
|
+
spec.description = "ActiveVersioning Workflow provides the tools necessary for version workflow in ActiveAdmin."
|
16
|
+
spec.homepage = "https://github.com/vigetlabs/active_versioning_workflow"
|
17
|
+
spec.license = "BSD"
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_path = ['lib']
|
23
|
+
|
24
|
+
spec.add_dependency "active_versioning", "~> 1.0.0"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", ">= 1.10"
|
27
|
+
spec.add_development_dependency "rake", ">= 10.0"
|
28
|
+
spec.add_development_dependency "rspec"
|
29
|
+
spec.add_development_dependency "pry"
|
30
|
+
spec.add_development_dependency "generator_spec"
|
31
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
/**
|
2
|
+
* ActiveVersioning Workflow Styles
|
3
|
+
* A two-abreast display of a current version and draft version
|
4
|
+
*
|
5
|
+
* Dependent upon ActiveMaterial.
|
6
|
+
*/
|
7
|
+
|
8
|
+
.column {
|
9
|
+
float: left;
|
10
|
+
}
|
11
|
+
|
12
|
+
.committed-version-column,
|
13
|
+
.current-draft-column {
|
14
|
+
margin-bottom: grid(4);
|
15
|
+
|
16
|
+
.panel_contents {
|
17
|
+
border-top: 1px solid $theme-divider;
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
.header_action {
|
22
|
+
padding: 0 10px;
|
23
|
+
|
24
|
+
a,
|
25
|
+
a:hover {
|
26
|
+
text-decoration: none;
|
27
|
+
}
|
28
|
+
|
29
|
+
a.commit-link {
|
30
|
+
color: $theme-accent;
|
31
|
+
|
32
|
+
&:before {
|
33
|
+
content: '\02713';
|
34
|
+
padding-right: 5px;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
a.edit-link {
|
39
|
+
color: $theme-primary;
|
40
|
+
|
41
|
+
&:before {
|
42
|
+
content: '\0270E';
|
43
|
+
padding-right: 5px;
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
a.preview-link {
|
48
|
+
color: $theme-primary;
|
49
|
+
|
50
|
+
&:before {
|
51
|
+
content: '\026B2';
|
52
|
+
display: inline-block;
|
53
|
+
transform: translate(0, 2px) rotate(45deg);
|
54
|
+
padding-right: 8px;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
a.discard-link {
|
59
|
+
color: $theme-error;
|
60
|
+
|
61
|
+
&:before {
|
62
|
+
content: '\02716';
|
63
|
+
padding-right: 5px;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
.commit-draft {
|
69
|
+
display: none;
|
70
|
+
padding: 10px 15px;
|
71
|
+
|
72
|
+
.input.string {
|
73
|
+
padding: 0;
|
74
|
+
}
|
75
|
+
|
76
|
+
input[type=text] {
|
77
|
+
width: calc(100% - 22px);
|
78
|
+
}
|
79
|
+
|
80
|
+
a.cancel-commit {
|
81
|
+
font-size: 1em;
|
82
|
+
padding: 7px 16px 6px;
|
83
|
+
}
|
84
|
+
|
85
|
+
p {
|
86
|
+
margin-bottom: 1em;
|
87
|
+
}
|
88
|
+
|
89
|
+
.inline-hints {
|
90
|
+
color: #666;
|
91
|
+
font-size: 0.95em;
|
92
|
+
font-style: italic;
|
93
|
+
font-weight: normal;
|
94
|
+
line-height: 1.5;
|
95
|
+
}
|
96
|
+
}
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "active_versioning_workflow"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/circle.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'active_versioning'
|
2
|
+
require 'active_versioning/workflow/engine'
|
3
|
+
require 'generators/active_versioning/workflow_generator'
|
4
|
+
|
5
|
+
module ActiveVersioning
|
6
|
+
module Workflow
|
7
|
+
autoload :Controller, 'active_versioning/workflow/controller'
|
8
|
+
autoload :DraftActions, 'active_versioning/workflow/draft_actions'
|
9
|
+
autoload :DSL, 'active_versioning/workflow/dsl'
|
10
|
+
autoload :Previewable, 'active_versioning/workflow/previewable'
|
11
|
+
autoload :Router, 'active_versioning/workflow/router'
|
12
|
+
autoload :ShowResource, 'active_versioning/workflow/show_resource'
|
13
|
+
autoload :ShowVersion, 'active_versioning/workflow/show_version'
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module ActiveVersioning
|
2
|
+
module Workflow
|
3
|
+
module Controller
|
4
|
+
def self.included(dsl)
|
5
|
+
dsl.instance_eval do
|
6
|
+
member_action :commit, method: :put do
|
7
|
+
if resource.commit(commit_params)
|
8
|
+
# We need to reload the resource by ID, in case the resource uses
|
9
|
+
# something other than id for the param and it has changed
|
10
|
+
set_resource_ivar(resource.class.find(resource.id))
|
11
|
+
|
12
|
+
redirect_to resource_path, notice: I18n.t('active_versioning.notices.commit')
|
13
|
+
else
|
14
|
+
# FIXME: In what ways can this fail?
|
15
|
+
#:nocov:
|
16
|
+
redirect_to resource_path, alert: I18n.t('active_versioning.errors.commit')
|
17
|
+
#:nocov:
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
member_action :create_draft, method: :post do
|
22
|
+
if resource.create_draft_from_version(params[:version_id])
|
23
|
+
redirect_to edit_resource_path,
|
24
|
+
notice: I18n.t('active_versioning.notices.create_draft_from_version')
|
25
|
+
else
|
26
|
+
# FIXME: In what ways can this fail?
|
27
|
+
#:nocov:
|
28
|
+
redirect_to [active_admin_namespace.name, resource, :versions],
|
29
|
+
alert: I18n.t('active_versioning.errors.create_draft_from_version')
|
30
|
+
#:nocov:
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
member_action :discard_draft, method: :delete do
|
35
|
+
resource.destroy_draft
|
36
|
+
redirect_to resource_path, notice: I18n.t('active_versioning.notices.discard_draft')
|
37
|
+
end
|
38
|
+
|
39
|
+
controller do
|
40
|
+
before_action :assign_version_params, only: [:create, :update]
|
41
|
+
before_action :set_draft_as_resource, only: [:edit, :update, :commit, :preview]
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def renderer_for(action)
|
46
|
+
if action == :show
|
47
|
+
ShowResource
|
48
|
+
else
|
49
|
+
super
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# `resource_params` is an Array where the first element is the permitted
|
54
|
+
# params and the next element is a role. These params are splatted into a
|
55
|
+
# build method within Inherited Resources -- a remnant of Rails 3
|
56
|
+
# `attr_accessible` method. This method will modify that first parameter
|
57
|
+
# by merging in the version author.
|
58
|
+
def assign_version_params
|
59
|
+
resource_params.first.merge!(version_author: committer)
|
60
|
+
end
|
61
|
+
|
62
|
+
def set_draft_as_resource
|
63
|
+
set_resource_ivar(resource.current_draft)
|
64
|
+
end
|
65
|
+
|
66
|
+
def committer
|
67
|
+
current_admin_user.email
|
68
|
+
end
|
69
|
+
|
70
|
+
def commit_params
|
71
|
+
params.permit(:commit_message).merge(committer: committer)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module ActiveVersioning
|
2
|
+
module Workflow
|
3
|
+
module Previewable
|
4
|
+
KEY = :_preview
|
5
|
+
|
6
|
+
def self.extended(base)
|
7
|
+
base.cattr_reader :_previewable_resource_method
|
8
|
+
|
9
|
+
base.include InstanceMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
def preview_resource(resource_method)
|
13
|
+
class_variable_set(:@@_previewable_resource_method, resource_method)
|
14
|
+
|
15
|
+
before_action :use_draft_as_resource, only: :show, if: :previewing?
|
16
|
+
end
|
17
|
+
|
18
|
+
module InstanceMethods
|
19
|
+
private
|
20
|
+
|
21
|
+
def use_draft_as_resource
|
22
|
+
instance_variable_set("@#{_previewable_resource_method}", send(_previewable_resource_method).current_draft)
|
23
|
+
end
|
24
|
+
|
25
|
+
def previewing?
|
26
|
+
params.has_key?(KEY)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
module ActiveVersioning
|
2
|
+
module Workflow
|
3
|
+
class ShowResource < ::ActiveAdmin::Views::Pages::Show
|
4
|
+
def main_content
|
5
|
+
instance_exec(resource, &show_block)
|
6
|
+
end
|
7
|
+
|
8
|
+
def version_attributes_panel(version, &block)
|
9
|
+
args = if version.live?
|
10
|
+
[I18n.t('active_versioning.panels.committed_version'), id: 'committed-panel']
|
11
|
+
else
|
12
|
+
[I18n.t('active_versioning.panels.current_draft'), id: 'current-draft-panel']
|
13
|
+
end
|
14
|
+
|
15
|
+
panel(*args) do
|
16
|
+
if version.live?
|
17
|
+
header_action(versions_link)
|
18
|
+
else
|
19
|
+
header_action(discard_link)
|
20
|
+
header_action(commit_link)
|
21
|
+
header_action(preview_link)
|
22
|
+
header_action(edit_link)
|
23
|
+
|
24
|
+
render 'commit_form'
|
25
|
+
end
|
26
|
+
|
27
|
+
instance_eval(&block)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def committed_version_panels
|
32
|
+
instance_exec(resource, &version_block)
|
33
|
+
end
|
34
|
+
|
35
|
+
def current_draft_panels
|
36
|
+
if resource.current_draft?
|
37
|
+
instance_exec(resource.current_draft, &version_block)
|
38
|
+
else
|
39
|
+
blank_slate(draft_blank_slate_content)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def committed_version_column
|
44
|
+
column class: 'committed-version-column column' do
|
45
|
+
committed_version_panels
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def current_draft_column
|
50
|
+
column class: 'current-draft-column column' do
|
51
|
+
current_draft_panels
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def show_block
|
58
|
+
config.block || default_show_block
|
59
|
+
end
|
60
|
+
|
61
|
+
def version_config
|
62
|
+
active_admin_config.get_page_presenter(:show_version)
|
63
|
+
end
|
64
|
+
|
65
|
+
def version_block
|
66
|
+
version_config.block
|
67
|
+
end
|
68
|
+
|
69
|
+
#:nocov:
|
70
|
+
def default_show_block
|
71
|
+
proc do
|
72
|
+
columns do
|
73
|
+
committed_version_column
|
74
|
+
|
75
|
+
current_draft_column
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
#:nocov:
|
80
|
+
|
81
|
+
def draft_blank_slate_content
|
82
|
+
[
|
83
|
+
I18n.t('active_versioning.helpers.blank_slate'),
|
84
|
+
draft_blank_slate_link
|
85
|
+
].compact.join(' ')
|
86
|
+
end
|
87
|
+
|
88
|
+
def draft_blank_slate_link
|
89
|
+
link_to I18n.t('active_versioning.links.blank_slate'), [:edit, active_admin_namespace.name, resource]
|
90
|
+
end
|
91
|
+
|
92
|
+
def versions_link
|
93
|
+
link_to I18n.t('active_versioning.links.view_versions'), [active_admin_namespace.name, resource, :versions]
|
94
|
+
end
|
95
|
+
|
96
|
+
def commit_link
|
97
|
+
link_to I18n.t('active_versioning.links.commit'), '#', class: 'commit-link'
|
98
|
+
end
|
99
|
+
|
100
|
+
def edit_link
|
101
|
+
link_to I18n.t('active_versioning.links.edit'), [:edit, active_admin_namespace.name, resource], class: 'edit-link'
|
102
|
+
end
|
103
|
+
|
104
|
+
def preview_controller
|
105
|
+
@preview_controller ||= "#{resource_class.to_s.pluralize}Controller".safe_constantize
|
106
|
+
end
|
107
|
+
|
108
|
+
def preview_link
|
109
|
+
unless preview_controller && preview_controller.singleton_class.ancestors.include?(ActiveVersioning::Workflow::Previewable)
|
110
|
+
return ''
|
111
|
+
end
|
112
|
+
|
113
|
+
link_to I18n.t('active_versioning.links.preview'), polymorphic_url(resource, _preview: true), {
|
114
|
+
class: 'preview-link',
|
115
|
+
target: :blank
|
116
|
+
}
|
117
|
+
end
|
118
|
+
|
119
|
+
def discard_link
|
120
|
+
link_to I18n.t('active_versioning.links.discard_draft'), [:discard_draft, active_admin_namespace.name, resource], {
|
121
|
+
class: 'discard-link',
|
122
|
+
method: :delete,
|
123
|
+
data: { confirm: I18n.t('active_versioning.confirmations.discard_draft') }
|
124
|
+
}
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module ActiveVersioning
|
2
|
+
module Workflow
|
3
|
+
class ShowVersion < ::ActiveAdmin::Views::Pages::Show
|
4
|
+
def main_content
|
5
|
+
instance_exec(version, &show_block)
|
6
|
+
end
|
7
|
+
|
8
|
+
def version_attributes_panel(version, &block)
|
9
|
+
panel I18n.t('active_admin.details', model: resource_config.resource_label) do
|
10
|
+
instance_eval(&block)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def version_details_panel
|
15
|
+
panel I18n.t('active_admin.details', model: Version.model_name.human) do
|
16
|
+
attributes_table_for(resource) do
|
17
|
+
row 'Responsible for Change', &:committer
|
18
|
+
row :commit_message
|
19
|
+
row :committed_at
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def versioned_resource
|
25
|
+
@versioned_resource ||= resource.reify
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def show_block
|
31
|
+
config.block || default_show_block
|
32
|
+
end
|
33
|
+
|
34
|
+
def default_show_block
|
35
|
+
proc do
|
36
|
+
instance_exec(versioned_resource, &version_block)
|
37
|
+
|
38
|
+
version_details_panel
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def resource_config
|
43
|
+
active_admin_namespace.resource_for(versioned_resource.class)
|
44
|
+
end
|
45
|
+
|
46
|
+
def version_block
|
47
|
+
resource_config.get_page_presenter(:show_version).block
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'active_versioning/workflow'
|
@@ -0,0 +1,45 @@
|
|
1
|
+
ActiveAdmin.register Version do
|
2
|
+
config.sort_order = 'committed_at_desc'
|
3
|
+
config.batch_actions = false
|
4
|
+
|
5
|
+
navigation_menu :default
|
6
|
+
|
7
|
+
menu false
|
8
|
+
|
9
|
+
actions :index, :show
|
10
|
+
|
11
|
+
filter :committer_cont, label: 'Committer'
|
12
|
+
filter :commit_message_cont, label: 'Commit Message'
|
13
|
+
filter :committed_at
|
14
|
+
|
15
|
+
index download_links: false do
|
16
|
+
column :committed_at
|
17
|
+
column :committer, sortable: false
|
18
|
+
column :commit_message, sortable: false
|
19
|
+
|
20
|
+
actions do |version|
|
21
|
+
link_to t('active_versioning.links.create_draft_from_version'),
|
22
|
+
[:create_draft, active_admin_namespace.name, version.versionable, { version_id: version }],
|
23
|
+
method: :post,
|
24
|
+
data: { confirm: t('active_versioning.confirmations.create_draft_from_version') }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
show title: :to_s
|
29
|
+
|
30
|
+
controller do
|
31
|
+
ActiveVersioning.versioned_models.each do |model|
|
32
|
+
belongs_to model.name.underscore.gsub('/', '_').to_sym, class_name: model.name, polymorphic: true, finder: :find_by_id!
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def renderer_for(action)
|
38
|
+
if action == :show
|
39
|
+
ActiveVersioning::Workflow::ShowVersion
|
40
|
+
else
|
41
|
+
super
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<div class="commit-draft">
|
2
|
+
<%= form_tag [:commit, :admin, resource], method: :put do %>
|
3
|
+
<p class="input string">
|
4
|
+
<%= text_field_tag :commit_message, params[:commit_message], placeholder: t('active_versioning.placeholders.commit') %>
|
5
|
+
</p>
|
6
|
+
|
7
|
+
<p>
|
8
|
+
<%= submit_tag 'Commit' %>
|
9
|
+
<%= link_to 'Cancel', '#', class: 'table_tools_button cancel-commit' %>
|
10
|
+
</p>
|
11
|
+
|
12
|
+
<p class="inline-hints">
|
13
|
+
<%= t('active_versioning.helpers.commit') %>
|
14
|
+
</p>
|
15
|
+
<% end %>
|
16
|
+
<hr>
|
17
|
+
</div>
|
@@ -0,0 +1,31 @@
|
|
1
|
+
en:
|
2
|
+
active_versioning:
|
3
|
+
actions:
|
4
|
+
draft: 'Save Draft'
|
5
|
+
confirmations:
|
6
|
+
create_draft_from_version: 'Are you sure you wish to create a draft from this version?'
|
7
|
+
discard_draft: 'Are you sure you want to discard this draft?'
|
8
|
+
errors:
|
9
|
+
commit: 'An error occurred while committing.'
|
10
|
+
create_draft_from_version: 'An error occurred while restoring this version.'
|
11
|
+
helpers:
|
12
|
+
blank_slate: "This resource doesn't have a draft."
|
13
|
+
commit: 'Committing this draft will overwrite the attributes in the committed version. If the committed version is published, then the changes will be reflected on the live site.'
|
14
|
+
links:
|
15
|
+
blank_slate: 'Create one.'
|
16
|
+
commit: 'Commit'
|
17
|
+
create_draft_from_version: 'Create Draft'
|
18
|
+
discard_draft: 'Discard'
|
19
|
+
edit: 'Edit'
|
20
|
+
preview: 'Preview'
|
21
|
+
view_versions: 'View Versions'
|
22
|
+
not_versioned: '%{model} are not versioned. Any changes you make will appear on the site immediately.'
|
23
|
+
notices:
|
24
|
+
commit: 'Committed!'
|
25
|
+
create_draft_from_version: 'Versioning successfully restored.'
|
26
|
+
discard_draft: 'Draft successfully discarded.'
|
27
|
+
panels:
|
28
|
+
committed_version: 'Committed Version'
|
29
|
+
current_draft: 'Current Draft'
|
30
|
+
placeholders:
|
31
|
+
commit: 'Enter a note about what changed.'
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module ActiveVersioning
|
4
|
+
class WorkflowGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
def install_active_versioning
|
8
|
+
InstallGenerator.new.tap do |generator|
|
9
|
+
generator.destination_root = destination_root
|
10
|
+
generator.install_models
|
11
|
+
generator.install_migrations
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def install_initializers
|
16
|
+
copy_file 'initializers/active_versioning_workflow.rb', 'config/initializers/active_versioning_workflow.rb'
|
17
|
+
end
|
18
|
+
|
19
|
+
def install_router
|
20
|
+
route 'self.class.send(:include, ActiveVersioning::Workflow::Router)'
|
21
|
+
end
|
22
|
+
|
23
|
+
def install_locales
|
24
|
+
copy_file 'locales/active_versioning.en.yml', 'config/locales/active_versioning.en.yml'
|
25
|
+
end
|
26
|
+
|
27
|
+
def install_active_admin_resources
|
28
|
+
copy_file 'active_admin_resources/version.rb', 'app/admin/version.rb'
|
29
|
+
end
|
30
|
+
|
31
|
+
def install_active_admin_views
|
32
|
+
copy_file 'active_admin_views/_commit_form.html.erb', 'app/views/active_admin/resource/_commit_form.html.erb'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_versioning_workflow
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Stenberg
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: active_versioning
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: generator_spec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: ActiveVersioning Workflow provides the tools necessary for version workflow
|
98
|
+
in ActiveAdmin.
|
99
|
+
email:
|
100
|
+
- ryan.stenberg@viget.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- Gemfile
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- active_versioning_workflow.gemspec
|
111
|
+
- app/assets/javascripts/active_versioning/workflow.js
|
112
|
+
- app/assets/stylesheets/active_versioning/workflow.scss
|
113
|
+
- bin/console
|
114
|
+
- bin/setup
|
115
|
+
- circle.yml
|
116
|
+
- lib/active_versioning/workflow.rb
|
117
|
+
- lib/active_versioning/workflow/controller.rb
|
118
|
+
- lib/active_versioning/workflow/draft_actions.rb
|
119
|
+
- lib/active_versioning/workflow/dsl.rb
|
120
|
+
- lib/active_versioning/workflow/engine.rb
|
121
|
+
- lib/active_versioning/workflow/previewable.rb
|
122
|
+
- lib/active_versioning/workflow/router.rb
|
123
|
+
- lib/active_versioning/workflow/show_resource.rb
|
124
|
+
- lib/active_versioning/workflow/show_version.rb
|
125
|
+
- lib/active_versioning/workflow/version.rb
|
126
|
+
- lib/active_versioning_workflow.rb
|
127
|
+
- lib/generators/active_versioning/templates/active_admin_resources/version.rb
|
128
|
+
- lib/generators/active_versioning/templates/active_admin_views/_commit_form.html.erb
|
129
|
+
- lib/generators/active_versioning/templates/initializers/active_versioning_workflow.rb
|
130
|
+
- lib/generators/active_versioning/templates/locales/active_versioning.en.yml
|
131
|
+
- lib/generators/active_versioning/workflow_generator.rb
|
132
|
+
homepage: https://github.com/vigetlabs/active_versioning_workflow
|
133
|
+
licenses:
|
134
|
+
- BSD
|
135
|
+
metadata: {}
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options: []
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
requirements: []
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 2.5.1
|
153
|
+
signing_key:
|
154
|
+
specification_version: 4
|
155
|
+
summary: An ActiveVersioning Extension for Version Workflow in ActiveAdmin
|
156
|
+
test_files: []
|