selections 0.1.12 → 0.1.13
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.
- data/CHANGELOG.md +3 -0
- data/README.md +23 -14
- data/lib/generators/selections_scaffold/selections_scaffold_generator.rb +35 -0
- data/lib/generators/selections_scaffold/templates/.DS_Store +0 -0
- data/lib/generators/selections_scaffold/templates/_form.html.haml +36 -0
- data/lib/generators/selections_scaffold/templates/create_selections.rb +15 -0
- data/lib/generators/selections_scaffold/templates/edit.html.erb +6 -0
- data/lib/generators/selections_scaffold/templates/edit.html.haml +3 -0
- data/lib/generators/selections_scaffold/templates/index.html.erb +35 -0
- data/lib/generators/selections_scaffold/templates/index.html.haml +26 -0
- data/lib/generators/selections_scaffold/templates/new.html.erb +6 -0
- data/lib/generators/selections_scaffold/templates/new.html.haml +3 -0
- data/lib/generators/selections_scaffold/templates/selection.rb +5 -0
- data/lib/generators/selections_scaffold/templates/selection_spec.rb +4 -0
- data/lib/generators/selections_scaffold/templates/selections.yml +17 -0
- data/lib/generators/selections_scaffold/templates/selections_controller.rb +51 -0
- data/lib/generators/selections_scaffold/templates/selections_controller_spec.rb +4 -0
- data/lib/generators/selections_scaffold/templates/selections_helper.rb +9 -0
- data/lib/selections/version.rb +1 -1
- metadata +18 -2
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
## 0.1.13
|
2
|
+
|
3
|
+
* https://github.com/nigelr/selections/issues/4 - selections-4 create selection Management scaffold generator
|
1
4
|
## 0.1.12
|
2
5
|
|
3
6
|
* https://github.com/nigelr/selections/issues/6 - #label_to_id feature to allow quick ID lookups within factories (speed enhancement)
|
data/README.md
CHANGED
@@ -30,6 +30,15 @@ Or install it yourself as:
|
|
30
30
|
|
31
31
|
## Usage
|
32
32
|
|
33
|
+
### Generator
|
34
|
+
|
35
|
+
Scaffold generates basic model, controller views that support the tree adding and editing of selections. Also generates a sample selections.yml file.
|
36
|
+
```
|
37
|
+
rails generate selections_scaffold
|
38
|
+
```
|
39
|
+
|
40
|
+
|
41
|
+
### Manual
|
33
42
|
First, you need to configure your selection model. We typically use `Selection` for this (although you
|
34
43
|
can change the name), and should be generated such as:
|
35
44
|
|
@@ -207,27 +216,27 @@ Selections.model { YourSelectionModel }
|
|
207
216
|
|
208
217
|
When using fixtures with the label same as the system_code, use this method to return the ID of the of the fixture and use this in Factories instead of using a lookup as it does not need a DB search.
|
209
218
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
priority_high:
|
219
|
+
Fixture File
|
220
|
+
```yaml
|
221
|
+
priority_high:
|
214
222
|
name: Priorities
|
215
223
|
system_code: priority_high
|
216
224
|
parent: priority
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
+
```
|
226
|
+
### In Factory
|
227
|
+
Don't do this as it will need a DB lookup
|
228
|
+
```ruby
|
229
|
+
priority: { Selection.priority_high }
|
230
|
+
```
|
231
|
+
Do this as it will be much quicker
|
232
|
+
```ruby
|
233
|
+
priority_id: { Selection.label_to_id(:priority_high) }
|
234
|
+
```
|
225
235
|
|
226
236
|
|
227
237
|
# TODO
|
228
238
|
|
229
|
-
*
|
230
|
-
* Add selections management scaffold/generator
|
239
|
+
* Suggestions please
|
231
240
|
|
232
241
|
## Contributing
|
233
242
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
require 'rails/generators/active_record'
|
4
|
+
|
5
|
+
class SelectionsScaffoldGenerator < Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
|
8
|
+
source_root File.expand_path('../templates', __FILE__)
|
9
|
+
|
10
|
+
def self.next_migration_number(path)
|
11
|
+
ActiveRecord::Generators::Base.next_migration_number(path)
|
12
|
+
end
|
13
|
+
|
14
|
+
def generate_selections_scaffold
|
15
|
+
{
|
16
|
+
'selection_spec.rb' => 'spec/models/',
|
17
|
+
'selection.rb' => 'app/models/',
|
18
|
+
'selections_controller_spec.rb' => 'spec/controllers/',
|
19
|
+
'selections_controller.rb' => 'app/controllers/',
|
20
|
+
'selections_helper.rb' => 'app/helpers/',
|
21
|
+
'selections.yml' => 'spec/fixtures/',
|
22
|
+
'_form.html.haml' => 'app/views/selections/',
|
23
|
+
'edit.html.haml' => 'app/views/selections/',
|
24
|
+
'index.html.haml' => 'app/views/selections/',
|
25
|
+
'new.html.haml' => 'app/views/selections/'
|
26
|
+
}.each_pair do |file, dir|
|
27
|
+
copy_file file, dir + file
|
28
|
+
end
|
29
|
+
|
30
|
+
migration_template 'create_selections.rb', 'db/migrate/create_selections.rb'
|
31
|
+
|
32
|
+
route 'resources(:selections, :only => :index) { resources :selections, except: :show }'
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
Binary file
|
@@ -0,0 +1,36 @@
|
|
1
|
+
= form_for ([@parent, @selection]), html: {class: 'form-horizontal'} do |f|
|
2
|
+
- if @selection.errors.any?
|
3
|
+
#error_explanation
|
4
|
+
%h2= "#{pluralize(@selection.errors.count, "error")} prohibited this selection from being saved:"
|
5
|
+
%ul
|
6
|
+
- @selection.errors.full_messages.each do |msg|
|
7
|
+
%li= msg
|
8
|
+
|
9
|
+
.control-group
|
10
|
+
= f.label :name
|
11
|
+
.controls
|
12
|
+
= f.text_field :name
|
13
|
+
.control-group
|
14
|
+
= f.label :parent
|
15
|
+
.controls
|
16
|
+
= link_to @selection.parent, selection_selections_path(@selection.parent)
|
17
|
+
.control-group
|
18
|
+
= f.label :system_code
|
19
|
+
.controls
|
20
|
+
= f.text_field :system_code, :readonly => !@selection.new_record?
|
21
|
+
.control-group
|
22
|
+
= f.label :position_value
|
23
|
+
.controls
|
24
|
+
= f.text_field :position_value
|
25
|
+
.control-group
|
26
|
+
= f.label :is_default
|
27
|
+
.controls
|
28
|
+
= f.check_box :is_default
|
29
|
+
.control-group
|
30
|
+
= f.label :archived
|
31
|
+
.controls
|
32
|
+
= f.check_box :archived
|
33
|
+
|
34
|
+
.form-actions
|
35
|
+
= f.submit 'Save Changes', :class => 'btn-primary'
|
36
|
+
= link_to 'Cancel', selection_selections_path(@parent), :class => 'btn'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateSelections < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :selections do |t|
|
4
|
+
t.string :name
|
5
|
+
t.integer :parent_id
|
6
|
+
t.string :system_code
|
7
|
+
t.integer :position_value
|
8
|
+
t.boolean :is_default
|
9
|
+
t.boolean :is_system
|
10
|
+
t.datetime :archived_at
|
11
|
+
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<% if @parent %>
|
2
|
+
<h3>
|
3
|
+
<%= "Children of #{@parent.name}" %>
|
4
|
+
</h3>
|
5
|
+
<%= link_to 'New Selection', new_selection_selection_path(@parent), :class => 'btn create' unless @parent.is_system %>
|
6
|
+
<% else %>
|
7
|
+
<h3>
|
8
|
+
Selections
|
9
|
+
</h3>
|
10
|
+
<% end %>
|
11
|
+
<table class="data table-striped" width="100%">
|
12
|
+
<tr>
|
13
|
+
<th>Name</th>
|
14
|
+
<th>Position value</th>
|
15
|
+
<th>Is default</th>
|
16
|
+
<th>Archived at</th>
|
17
|
+
<th>System code</th>
|
18
|
+
</tr>
|
19
|
+
<% if @selections.size == 0 %>
|
20
|
+
<tr class="no-records">
|
21
|
+
<td colspan="6"><p>No records to display.</p></td>
|
22
|
+
</tr>
|
23
|
+
<% end %>
|
24
|
+
<% @selections.each do |selection| %>
|
25
|
+
<tr>
|
26
|
+
<td><%= selector selection %></td>
|
27
|
+
<td><%= selection.position_value %></td>
|
28
|
+
<td><%= selection.is_default %></td>
|
29
|
+
<td><%= selection.archived_at %></td>
|
30
|
+
<td><%= selection.system_code %></td>
|
31
|
+
</tr>
|
32
|
+
<% end %>
|
33
|
+
</table>
|
34
|
+
|
35
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
- if @parent
|
2
|
+
%h3
|
3
|
+
= "Children of #{@parent.name}"
|
4
|
+
= link_to ' (Back)', selections_path
|
5
|
+
= link_to 'New Selection', new_selection_selection_path(@parent), :class => 'btn create' unless @parent.is_system
|
6
|
+
- else
|
7
|
+
%h3
|
8
|
+
Selections
|
9
|
+
%table.data.table-striped{:width => "100%"}
|
10
|
+
%tr
|
11
|
+
%th Name
|
12
|
+
%th Position value
|
13
|
+
%th Is default
|
14
|
+
%th Archived at
|
15
|
+
%th System code
|
16
|
+
- if @selections.size == 0
|
17
|
+
%tr.no-records
|
18
|
+
%td{:colspan => "6"}
|
19
|
+
%p No records to display.
|
20
|
+
- @selections.each do |selection|
|
21
|
+
%tr
|
22
|
+
%td= selector selection
|
23
|
+
%td= selection.position_value
|
24
|
+
%td= selection.is_default
|
25
|
+
%td= selection.archived_at
|
26
|
+
%td= selection.system_code
|
@@ -0,0 +1,17 @@
|
|
1
|
+
example:
|
2
|
+
name: Example
|
3
|
+
is_system: false
|
4
|
+
system_code: $LABEL
|
5
|
+
example_one:
|
6
|
+
name: One
|
7
|
+
parent: example
|
8
|
+
position_value:
|
9
|
+
is_default: true
|
10
|
+
system_code: $LABEL
|
11
|
+
example_two:
|
12
|
+
name: Two
|
13
|
+
parent: example
|
14
|
+
position_value:
|
15
|
+
is_default: false
|
16
|
+
system_code: $LABEL
|
17
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class SelectionsController < ApplicationController
|
2
|
+
before_filter :parent_finder
|
3
|
+
|
4
|
+
def index
|
5
|
+
if @parent
|
6
|
+
@selections = @parent.children
|
7
|
+
else
|
8
|
+
@selections = Selection.roots
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def new
|
13
|
+
@selection = @parent.children.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def edit
|
17
|
+
@selection = @parent.children.find(params[:id])
|
18
|
+
end
|
19
|
+
|
20
|
+
def create
|
21
|
+
@selection = @parent.children.new(params[:selection])
|
22
|
+
|
23
|
+
if @selection.save
|
24
|
+
redirect_to selection_selections_path(@parent), notice: 'Selection was successfully created.'
|
25
|
+
else
|
26
|
+
render action: 'new'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def update
|
31
|
+
@selection = Selection.find(params[:id])
|
32
|
+
|
33
|
+
if @selection.update_attributes(params[:selection])
|
34
|
+
redirect_to selection_selections_path(@parent), notice: 'Selection was successfully updated.'
|
35
|
+
else
|
36
|
+
render action: 'edit'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def destroy
|
41
|
+
@selection = Selection.find(params[:id])
|
42
|
+
@selection.destroy
|
43
|
+
|
44
|
+
redirect_to selections_url
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
def parent_finder
|
49
|
+
@parent = Selection.find_by_id(params[:selection_id])
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module SelectionsHelper
|
2
|
+
def selector selection
|
3
|
+
if selection.leaf?
|
4
|
+
link_to_unless selection.parent.try(:is_system), selection.name, edit_selection_selection_path(@parent, selection)
|
5
|
+
else
|
6
|
+
link_to selection.name, selection_selections_path(selection)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
data/lib/selections/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: selections
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -140,6 +140,22 @@ files:
|
|
140
140
|
- LICENSE.txt
|
141
141
|
- README.md
|
142
142
|
- Rakefile
|
143
|
+
- lib/generators/selections_scaffold/selections_scaffold_generator.rb
|
144
|
+
- lib/generators/selections_scaffold/templates/.DS_Store
|
145
|
+
- lib/generators/selections_scaffold/templates/_form.html.haml
|
146
|
+
- lib/generators/selections_scaffold/templates/create_selections.rb
|
147
|
+
- lib/generators/selections_scaffold/templates/edit.html.erb
|
148
|
+
- lib/generators/selections_scaffold/templates/edit.html.haml
|
149
|
+
- lib/generators/selections_scaffold/templates/index.html.erb
|
150
|
+
- lib/generators/selections_scaffold/templates/index.html.haml
|
151
|
+
- lib/generators/selections_scaffold/templates/new.html.erb
|
152
|
+
- lib/generators/selections_scaffold/templates/new.html.haml
|
153
|
+
- lib/generators/selections_scaffold/templates/selection.rb
|
154
|
+
- lib/generators/selections_scaffold/templates/selection_spec.rb
|
155
|
+
- lib/generators/selections_scaffold/templates/selections.yml
|
156
|
+
- lib/generators/selections_scaffold/templates/selections_controller.rb
|
157
|
+
- lib/generators/selections_scaffold/templates/selections_controller_spec.rb
|
158
|
+
- lib/generators/selections_scaffold/templates/selections_helper.rb
|
143
159
|
- lib/selections.rb
|
144
160
|
- lib/selections/belongs_to_selection.rb
|
145
161
|
- lib/selections/form_builder_extensions.rb
|