yawl_rails 0.1.1 → 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 23c0a0837ced1dd8761391411dc7d4da06e8070e
4
+ data.tar.gz: db1f00918971dd80826e0c17b0486b485c15b4b1
5
+ SHA512:
6
+ metadata.gz: 303eeab3010e199135534f336bb0eb5ba7bf48aedb8b15a8e22ba68da0fd4af1894b4e0eef481adad2c94230043edcaa0c46074e5bb0aa471a517c523a1e1ac5
7
+ data.tar.gz: f40d303a4921fd3387461bbb13b66727be2c985937ac7b4f1ac9f4cc152a14ec944a909b475a79357114b0cb461b2c53f522d72ee3d815dda944615d673f322a
data/README.md CHANGED
@@ -4,8 +4,30 @@ This is the UI and Rails integration component of [yawl](https://github.com/rica
4
4
 
5
5
  ## Migrations
6
6
 
7
- `yawl_rails` automatically sets the schema file to be in sql format because of the `json` column used in `yawl`
7
+ The engine should automatically hook into Rails and allow you to *just* run `rake db:migrate`
8
+
9
+ ## Routing
10
+
11
+ I like to mount the engine at the root, so the following would work but you can also mount it anywhere you see fit.
8
12
 
9
13
  ```
10
- config.active_record.schema_format = :sql
14
+ mount YawlRails::Engine, at: "/"
11
15
  ```
16
+
17
+ ## Config
18
+
19
+ Extra config variables added:
20
+
21
+ * `Yawl::Config.pagination_per_page`: Number of processes to list per page
22
+
23
+ ## Templates
24
+
25
+ It's currently setup so that you need to use haml in `yawl_rails` and assumes that you want to share your layout with it to maintain an integrated look. One caveat is that it's using bootstrap 2--*maybe a rails4 only engine + bootstrap 3 is in the future?*.
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
@@ -2,8 +2,11 @@ require_dependency "yawl_rails/application_controller"
2
2
 
3
3
  module YawlRails
4
4
  class ProcessesController < ApplicationController
5
+ before_filter :load_process, only: [:show, :restart, :steps]
6
+
5
7
  def index
6
- @processes = ::Yawl::Process.order(:id).reverse
8
+ page = (params[:page] || 1).to_i
9
+ @processes = ::Yawl::Process.pagination_dataset.order(:id).reverse.paginate(page, Yawl::Config.pagination_per_page)
7
10
 
8
11
  respond_to do |format|
9
12
  format.html
@@ -12,8 +15,6 @@ module YawlRails
12
15
  end
13
16
 
14
17
  def show
15
- @process = ::Yawl::Process.first(:id => params[:id])
16
-
17
18
  respond_to do |format|
18
19
  format.html
19
20
  format.json { render :json => @process.to_hash.merge(:steps => @process.steps.map(&:to_hash)) }
@@ -21,7 +22,6 @@ module YawlRails
21
22
  end
22
23
 
23
24
  def restart
24
- @process = ::Yawl::Process.first(:id => params[:id])
25
25
  @process.start_first_unfinished_step
26
26
 
27
27
  respond_to do |format|
@@ -31,12 +31,23 @@ module YawlRails
31
31
  end
32
32
 
33
33
  def steps
34
- @process = ::Yawl::Process.first(:id => params[:id])
35
-
36
34
  respond_to do |format|
37
35
  format.html { render :partial => "step_rows" }
38
36
  format.json { render :json => @process.to_hash.merge(:steps => @process.steps.map(&:to_hash)) }
39
37
  end
40
38
  end
39
+
40
+ protected
41
+
42
+ def load_process
43
+ @process = ::Yawl::Process.first(:name => params[:id])
44
+ if @process.nil?
45
+ respond_to do |format|
46
+ format.html { render :text => "Process not found", :status => 404 }
47
+ format.json { render :json => { "error" => "Process not found" }, :status => 404 }
48
+ end
49
+ false
50
+ end
51
+ end
41
52
  end
42
53
  end
@@ -3,7 +3,7 @@ require_dependency "yawl_rails/application_controller"
3
3
  module YawlRails
4
4
  class StepsController < ApplicationController
5
5
  def show
6
- @process = ::Yawl::Process.first(:id => params[:process_id])
6
+ @process = ::Yawl::Process.first(:name => params[:process_id])
7
7
  @step = @process.steps_dataset.first(:id => params[:id])
8
8
 
9
9
  respond_to do |format|
@@ -0,0 +1,5 @@
1
+ .pagination
2
+ %ul
3
+ - objects.page_range.each do |page|
4
+ %li
5
+ %a{:href => "?page=#{page}", :class => (objects.current_page == page ? 'active' : '')}= page
@@ -1,5 +1,5 @@
1
1
  = javascript_include_tag "yawl_rails/processes"
2
2
 
3
3
  :javascript
4
- YawlProcess.url = "#{steps_yawl_process_path(@process.id)}";
4
+ YawlProcess.url = "#{steps_yawl_process_path(@process.name)}";
5
5
  YawlProcess.init();
@@ -1,10 +1,10 @@
1
1
  - @process.steps.each do |step|
2
2
  %tr.step{:id => "step-#{step.seq}"}
3
- %td= link_to step.seq, yawl_process_step_path(@process.id, step.id)
3
+ %td= link_to step.seq, yawl_process_step_path(@process.name, step.id)
4
4
  %td
5
5
  = step.name
6
6
  - if step.state == "failed" && @process.current?
7
- = link_to "<i class='icon-refresh icon-white'></i> Retry".html_safe, restart_yawl_process_path(@process.id), :method => :post, :class => "btn btn-mini btn-primary"
7
+ = link_to "<i class='icon-refresh icon-white'></i> Retry".html_safe, restart_yawl_process_path(@process.name), :method => :post, :class => "btn btn-mini btn-primary"
8
8
  %td.step-state= step.state
9
9
  %td= step.attempts.count
10
10
  %td
@@ -13,7 +13,10 @@
13
13
  %tbody
14
14
  - @processes.each do |p|
15
15
  %tr{:id => "process-#{p.name}"}
16
- %td= link_to p.name, yawl_process_path(p.id)
16
+ %td= link_to p.name, yawl_process_path(p.name)
17
17
  %td= p.desired_state
18
18
  %td= p.state
19
19
  %td= p.created_at
20
+
21
+ - if @processes.page_count > 1
22
+ = render 'pagination', objects: @processes
@@ -13,6 +13,7 @@
13
13
  %dt State
14
14
  %dd= @process.state
15
15
 
16
+ = render 'process_extra_info'
16
17
 
17
18
  .progress.progress-striped.active
18
19
  .bar#process-progress{:style => "width: 0%;"}
@@ -1,4 +1,4 @@
1
- %h1= link_to "Process #{@process.name}", yawl_process_path(@process.id)
1
+ %h1= link_to "Process #{@process.name}", yawl_process_path(@process.name)
2
2
 
3
3
  %h2= "Step #{@step.seq}: #{@step.name}"
4
4
 
data/config/routes.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  YawlRails::Engine.routes.draw do
2
2
  scope as: 'yawl' do
3
- resources :processes, :only => [:index, :show] do
3
+ resources :processes, :only => [:index, :show], :constraints => {:id => /[^\s]+/} do
4
4
  member do
5
5
  post :restart
6
6
  get :steps
@@ -0,0 +1,21 @@
1
+ module Yawl
2
+ module Config
3
+ mattr_accessor :pagination_per_page
4
+
5
+ DEFAULT_PAGINATION_PER_PAGE = 20
6
+ end
7
+
8
+ module Pagination
9
+ module ClassMethods
10
+ def pagination_dataset
11
+ dataset.extension(:pagination)
12
+ end
13
+ end
14
+
15
+ def self.included(klass)
16
+ klass.extend(ClassMethods)
17
+ end
18
+ end
19
+ end
20
+
21
+ ::Yawl::Process.send(:include, Yawl::Pagination)
@@ -11,12 +11,23 @@ module YawlRails
11
11
 
12
12
  initializer "yawl_rails.append_migrations" do |app|
13
13
  unless app.root.to_s.match root.to_s
14
- app.config.paths["db/migrate"] += config.paths["db/migrate"].expanded
14
+ if Rails::VERSION::MAJOR >= 4
15
+ config.paths["db/migrate"].expanded.each do |expanded_path|
16
+ app.config.paths["db/migrate"] << expanded_path
17
+ end
18
+ else
19
+ app.config.paths["db/migrate"] += config.paths["db/migrate"].expanded
20
+ end
15
21
  end
16
22
  end
17
23
 
18
24
  initializer "yawl_rails.setup_yawl" do |app|
19
25
  require "yawl/rails"
20
26
  end
27
+
28
+ initializer "yawl_rails.setup_pagination" do |app|
29
+ require "yawl/pagination"
30
+ Yawl::Config.pagination_per_page ||= Yawl::Config::DEFAULT_PAGINATION_PER_PAGE
31
+ end
21
32
  end
22
33
  end
@@ -1,3 +1,3 @@
1
1
  module YawlRails
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -19,5 +19,23 @@ module YawlRails
19
19
  assigns(:processes).map(&:id).should match_array([@p2, @p1])
20
20
  end
21
21
  end
22
+
23
+ describe "GET #show" do
24
+ it "shows the process" do
25
+ @p1 = ::Yawl::Process.insert(:desired_state => "test1", :name => "p1-test")
26
+
27
+ get :show, id: "p1-test", use_route: :yawl_rails
28
+
29
+ expect(response).to be_success
30
+ expect(response).to render_template("show")
31
+ end
32
+
33
+ it "returns a 404 for an unknown process" do
34
+ get :show, id: "unknown-test", use_route: :yawl_rails
35
+
36
+ expect(response.code).to eq("404")
37
+ expect(response).to_not render_template("show")
38
+ end
39
+ end
22
40
  end
23
41
  end
@@ -3,20 +3,21 @@ require 'spec_helper'
3
3
  module YawlRails
4
4
  describe StepsController do
5
5
  before(:each) do
6
- @process_id = Yawl::Process.insert(:desired_state => "testing")
6
+ @process_name = "p1-123"
7
+ @process_id = Yawl::Process.insert(:desired_state => "testing", :name => @process_name)
7
8
  @step_id = Yawl::Step.insert(:process_id => @process_id, :name => "step1", :seq => 1)
8
9
  end
9
10
 
10
11
  describe "GET #show" do
11
12
  it "renders the right template" do
12
- get :show, :process_id => @process_id, :id => @step_id, :use_route => :yawl_rails
13
+ get :show, :process_id => @process_name, :id => @step_id, :use_route => :yawl_rails
13
14
 
14
15
  expect(response).to be_success
15
16
  expect(response).to render_template("show")
16
17
  end
17
18
 
18
19
  it "assigns @step" do
19
- get :show, :process_id => @process_id, :id => @step_id, :use_route => :yawl_rails
20
+ get :show, :process_id => @process_name, :id => @step_id, :use_route => :yawl_rails
20
21
 
21
22
  assigns(:step).id.should eq(@step_id)
22
23
  end
@@ -0,0 +1,33 @@
1
+ require "spec_helper"
2
+
3
+ feature "List Processes" do
4
+ scenario "does not contain pagination" do
5
+ @p1 = ::Yawl::Process.insert(:name => "p1", :desired_state => "test1")
6
+
7
+ visit yawl_rails.yawl_processes_path
8
+ expect(page).to_not have_selector(".pagination")
9
+ end
10
+
11
+ scenario "contains pagination" do
12
+ @p1 = ::Yawl::Process.insert(:name => "p1", :desired_state => "test1")
13
+ @p2 = ::Yawl::Process.insert(:name => "p2", :desired_state => "test1")
14
+ @p3 = ::Yawl::Process.insert(:name => "p3", :desired_state => "test1")
15
+
16
+ visit yawl_rails.yawl_processes_path
17
+ expect(page).to have_selector(".pagination")
18
+ expect(find(".pagination")).to have_link("1", href: "?page=1")
19
+ expect(find(".pagination")).to have_link("2", href: "?page=2")
20
+ expect(find(".pagination")).to_not have_link("3", href: "?page=3")
21
+ expect(find(".pagination")).to_not have_link("0", href: "?page=0")
22
+ end
23
+
24
+ scenario "doesn't blow up if given a bad page number" do
25
+ @p1 = ::Yawl::Process.insert(:name => "p1", :desired_state => "test1")
26
+ @p2 = ::Yawl::Process.insert(:name => "p2", :desired_state => "test1")
27
+ @p3 = ::Yawl::Process.insert(:name => "p3", :desired_state => "test1")
28
+
29
+ visit yawl_rails.yawl_processes_path + "?page=3"
30
+ expect(page).to have_selector(".pagination")
31
+ expect(find(".pagination")).to_not have_link("3", href: "?page=3")
32
+ end
33
+ end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ feature "Process Page" do
4
+ background do
5
+ @p1_id = ::Yawl::Process.insert(:name => "p1", :desired_state => "test1")
6
+ end
7
+
8
+ scenario "javascript uses correct process url" do
9
+ visit yawl_rails.yawl_process_path('p1')
10
+ expect(page.source).to include("/yawl_rails/processes/p1/steps")
11
+ end
12
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,15 @@
1
1
  ENV['RAILS_ENV'] ||= 'test'
2
- ENV['DATABASE_URL'] = 'postgres://localhost/yawl-rails-test'
2
+ ENV['DATABASE_URL'] ||= 'postgres://localhost/yawl-rails-test'
3
3
 
4
4
  require File.expand_path("../test_app/config/environment.rb", __FILE__)
5
5
  require 'rspec/rails'
6
6
  require 'rspec/autorun'
7
7
 
8
+ require 'capybara/rails'
9
+ require 'capybara/rspec'
10
+
11
+ Yawl::Config.pagination_per_page = 2
12
+
8
13
  Rails.backtrace_cleaner.remove_silencers!
9
14
 
10
15
  # Load support files
data/yawl_rails.gemspec CHANGED
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_development_dependency "pg"
27
27
  spec.add_development_dependency "rspec-rails"
28
+ spec.add_development_dependency "capybara"
28
29
  end
metadata CHANGED
@@ -1,94 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yawl_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ricardo Chimal, Jr.
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-02-26 00:00:00.000000000 Z
11
+ date: 2014-04-28 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: yawl
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: 0.2.0
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: 0.2.0
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: haml
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: pg
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rspec-rails
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: capybara
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
+ - - ">="
92
95
  - !ruby/object:Gem::Version
93
96
  version: '0'
94
97
  description: Rails UI for YAWL
@@ -99,7 +102,7 @@ executables:
99
102
  extensions: []
100
103
  extra_rdoc_files: []
101
104
  files:
102
- - .gitignore
105
+ - ".gitignore"
103
106
  - Gemfile
104
107
  - LICENSE.txt
105
108
  - README.md
@@ -110,6 +113,8 @@ files:
110
113
  - app/controllers/yawl_rails/steps_controller.rb
111
114
  - app/helpers/yawl_rails/application_helper.rb
112
115
  - app/helpers/yawl_rails/processes_helper.rb
116
+ - app/views/yawl_rails/processes/_pagination.html.haml
117
+ - app/views/yawl_rails/processes/_process_extra_info.html.haml
113
118
  - app/views/yawl_rails/processes/_show_inline_js.html.haml
114
119
  - app/views/yawl_rails/processes/_step_rows.html.haml
115
120
  - app/views/yawl_rails/processes/index.html.haml
@@ -119,6 +124,7 @@ files:
119
124
  - config/routes.rb
120
125
  - db/migrate/20140225002136_setup_yawl.rb
121
126
  - lib/tasks/yawl_rails_tasks.rake
127
+ - lib/yawl/pagination.rb
122
128
  - lib/yawl/process_active_record.rb
123
129
  - lib/yawl/rails.rb
124
130
  - lib/yawl_rails.rb
@@ -126,6 +132,8 @@ files:
126
132
  - lib/yawl_rails/version.rb
127
133
  - spec/controllers/yawl_rails/processes_controller_spec.rb
128
134
  - spec/controllers/yawl_rails/steps_controller_spec.rb
135
+ - spec/features/yawl_rails/processes/list_spec.rb
136
+ - spec/features/yawl_rails/processes/show_spec.rb
129
137
  - spec/helpers/yawl_rails/processes_helper_spec.rb
130
138
  - spec/spec_helper.rb
131
139
  - spec/test_app/README.rdoc
@@ -170,37 +178,32 @@ files:
170
178
  homepage: ''
171
179
  licenses:
172
180
  - MIT
181
+ metadata: {}
173
182
  post_install_message:
174
183
  rdoc_options: []
175
184
  require_paths:
176
185
  - lib
177
186
  required_ruby_version: !ruby/object:Gem::Requirement
178
- none: false
179
187
  requirements:
180
- - - ! '>='
188
+ - - ">="
181
189
  - !ruby/object:Gem::Version
182
190
  version: '0'
183
- segments:
184
- - 0
185
- hash: -3973182591231445544
186
191
  required_rubygems_version: !ruby/object:Gem::Requirement
187
- none: false
188
192
  requirements:
189
- - - ! '>='
193
+ - - ">="
190
194
  - !ruby/object:Gem::Version
191
195
  version: '0'
192
- segments:
193
- - 0
194
- hash: -3973182591231445544
195
196
  requirements: []
196
197
  rubyforge_project:
197
- rubygems_version: 1.8.23
198
+ rubygems_version: 2.2.2
198
199
  signing_key:
199
- specification_version: 3
200
+ specification_version: 4
200
201
  summary: Rails UI for YAWL
201
202
  test_files:
202
203
  - spec/controllers/yawl_rails/processes_controller_spec.rb
203
204
  - spec/controllers/yawl_rails/steps_controller_spec.rb
205
+ - spec/features/yawl_rails/processes/list_spec.rb
206
+ - spec/features/yawl_rails/processes/show_spec.rb
204
207
  - spec/helpers/yawl_rails/processes_helper_spec.rb
205
208
  - spec/spec_helper.rb
206
209
  - spec/test_app/README.rdoc