smart_list 0.0.1 → 0.0.2
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/README.md +67 -0
- data/app/controllers/smart_list_controller.rb +50 -0
- data/app/views/smart_links/_move_links.html.erb +6 -0
- data/lib/smart_list.rb +1 -1
- data/lib/smart_list_helper.rb +12 -0
- metadata +5 -1
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# FRIENDS-Smart-List
|
2
|
+
SmartList Plug-In - Part of FRIENDS SmartConcepts
|
3
|
+
(c) 2011 Florian Eck, FRIENDS Financial Coaching
|
4
|
+
|
5
|
+
## About
|
6
|
+
|
7
|
+
This is my SmartList plugin, kinda raw, not yet test-covered or anything, but works good as hell.
|
8
|
+
Its kinda similar to acts_as_list, but it does the following things (better in my opinion, thats why i wrote it;-):
|
9
|
+
|
10
|
+
## Example:
|
11
|
+
|
12
|
+
Class UserStuff < ActiveRecord::Base
|
13
|
+
|
14
|
+
smart_list :group => :user_id, :base_class => 'UserStuff' # => shiity thing which needs to be fixed - always must pass the model name !
|
15
|
+
# default value for ordering stuff is 'order_bit', could be anything else, like 'created_at' or what ever
|
16
|
+
# u can ignore ':group' if u just want a whole table as one list
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
You have the following data in your user stuff table:
|
21
|
+
|
22
|
+
id user_id some_data order_bit
|
23
|
+
1 1 'bli' 100
|
24
|
+
2 2 'bla' 100
|
25
|
+
3 3 'blubb' 100
|
26
|
+
4 1 'blibla' 101
|
27
|
+
5 1 'blubbblubb' 102
|
28
|
+
6 1 'abc' 103
|
29
|
+
7 2 'blubbbla' 101
|
30
|
+
8 3 'def' 101
|
31
|
+
|
32
|
+
|
33
|
+
Now u can do:
|
34
|
+
|
35
|
+
stuff = UserStuff.find_by_user_id(1) # stuff is <UserStuff #1>
|
36
|
+
|
37
|
+
### Get all items in group
|
38
|
+
stuff.group_list_items #=> returns [<UserStuff #1>, <UserStuff #4>, <UserStuff #5>, <UserStuff #6>]
|
39
|
+
|
40
|
+
### Or u do
|
41
|
+
UserStuff.grouped_list(1) # Get all items with user_id 1
|
42
|
+
|
43
|
+
### if u have an item of a list, you can do:
|
44
|
+
|
45
|
+
item.move_up! # Move item up in oder position
|
46
|
+
item.move_down! # Move item down in oder position
|
47
|
+
|
48
|
+
item.pre # Get previous item in list, returns self when no other item is available
|
49
|
+
item.post # Get next item in list, returns self when no other item is available
|
50
|
+
|
51
|
+
item.followers # check which items are next in list
|
52
|
+
item.group_list_items # show all items in group
|
53
|
+
|
54
|
+
|
55
|
+
### Includes Helpers, Partials and Controllers to do:
|
56
|
+
|
57
|
+
|
58
|
+
<%= smart_list_links(item, options = {:uplink => {:text => "<", :class => nil}, :downlink => {:text => ">", :class => nil}}) %>
|
59
|
+
will render a button box for controlling the list items (movin up and down)
|
60
|
+
|
61
|
+
## Notes
|
62
|
+
No test coverage yet, hope u like it anyway
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
class SmartListController < ApplicationController
|
3
|
+
|
4
|
+
before_filter :check_smart_list
|
5
|
+
|
6
|
+
def move_up
|
7
|
+
begin
|
8
|
+
@item.move_up!
|
9
|
+
flash[:notice] = "Item moved up"
|
10
|
+
rescue
|
11
|
+
flash[:error] = "Item could not be moved"
|
12
|
+
end
|
13
|
+
redirect_to :back
|
14
|
+
end
|
15
|
+
|
16
|
+
def move_down
|
17
|
+
begin
|
18
|
+
@item.move_down!
|
19
|
+
flash[:notice] = "Item moved down"
|
20
|
+
rescue
|
21
|
+
flash[:error] = "Item could not be moved"
|
22
|
+
end
|
23
|
+
redirect_to :back
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# Verify data
|
30
|
+
def check_smart_list
|
31
|
+
params[:type] = $active_smart_lists[params[:type]]
|
32
|
+
if params[:type].blank? || params[:id].blank?
|
33
|
+
flash[:error] = "You need to specify a :type and an :id"
|
34
|
+
redirect_to :back
|
35
|
+
elsif !(params[:type].constantize.is_smart_list? rescue false )
|
36
|
+
flash[:error] = "#{params[:type]} is not a smart_list item"
|
37
|
+
redirect_to :back
|
38
|
+
else
|
39
|
+
@item = params[:type].constantize.find(params[:id]) rescue nil
|
40
|
+
if @item.nil?
|
41
|
+
flash[:error] = "Item not found"
|
42
|
+
else
|
43
|
+
return true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<span class="smart-up">
|
2
|
+
<%= link_to (raw((options[:uplink][:text] rescue "↑"))), {:controller => "/smart_list", :action => "move_up", :id => item.id, :type =>item.class_name_sha}, :class => ((options[:uplink][:class] rescue nil)) %>
|
3
|
+
</span>
|
4
|
+
<span class="smart-down">
|
5
|
+
<%= link_to (raw((options[:downlink][:text] rescue "↓"))), {:controller => "/smart_list", :action => "move_down", :id => item.id, :type => item.class_name_sha}, :class => ((options[:downlink][:class] rescue nil)) %>
|
6
|
+
</span>
|
data/lib/smart_list.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module SmartListHelper
|
3
|
+
|
4
|
+
def render_list(list)
|
5
|
+
|
6
|
+
end
|
7
|
+
|
8
|
+
def smart_list_links(item, options = {:uplink => {:text => "↑", :class => nil}, :downlink => {:text => "↓", :class => nil}})
|
9
|
+
render :partial => "/smart_links/move_links", :locals => {:item => item, :options => options}
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_list
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -20,6 +20,10 @@ extra_rdoc_files: []
|
|
20
20
|
files:
|
21
21
|
- lib/smart_list.rb
|
22
22
|
- lib/add_order_bit.rb
|
23
|
+
- lib/smart_list_helper.rb
|
24
|
+
- app/controllers/smart_list_controller.rb
|
25
|
+
- app/views/smart_links/_move_links.html.erb
|
26
|
+
- README.md
|
23
27
|
homepage: https://github.com/florianeck/smart_list
|
24
28
|
licenses: []
|
25
29
|
post_install_message:
|