Skip to content

Commit da9250f

Browse files
committed
ok
1 parent 4e09b79 commit da9250f

32 files changed

+756
-12
lines changed

app/assets/images/heart-faded.png

726 Bytes
Loading

app/assets/images/heart.png

717 Bytes
Loading

app/assets/images/trashbin_empty.png

23.6 KB
Loading

app/assets/images/trashbin_full.png

27.4 KB
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Place all the behaviors and hooks related to the matching controller here.
2+
# All this logic will automatically be available in application.js.
3+
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Place all the styles related to the dashboard controller here.
2+
// They will automatically be included in application.css.
3+
// You can use Sass (SCSS) here: http://sass-lang.com/
4+
5+
// copied from apotomo_peters_guide
6+
7+
.column { width: 300px; float: left; padding-bottom: 100px; }
8+
.portlet { margin: 0 1em 1em 0; }
9+
.portlet-header { margin: 0.3em; padding-bottom: 4px; padding-left: 0.2em; }
10+
.portlet-header .ui-icon { float: right; }
11+
.portlet-content { padding: 0.4em; }
12+
.ui-sortable-placeholder { border: 1px dotted black; visibility: visible !important; height: 50px !important; }
13+
.ui-sortable-placeholder * { visibility: hidden; }
14+
15+
#twitter li {
16+
list-style-type: none;
17+
margin: 0 0 0.25em;
18+
19+
background:none repeat scroll 0 0 darkgrey;
20+
color:#EEEEEE;
21+
display:block;
22+
padding:0.25em;
23+
text-decoration:none;
24+
width:12em;
25+
}
26+
27+
#twitter ul {
28+
margin: 0;
29+
padding: 0;
30+
width: 0;
31+
}
32+
33+
#twitter li img {
34+
float: right;
35+
margin-right: 3px;
36+
}
37+
38+
#twitter input {
39+
width: 240px;
40+
}
41+
42+
#errorExplanation {
43+
background-color: grey;
44+
padding: 8px;
45+
}
46+
#errorExplanation {
47+
font-size: 9pt;
48+
}
49+
#errorExplanation h2 {
50+
font-size: 12pt;
51+
}
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

app/assets/stylesheets/eggplant/jquery-ui-1.8.5.custom.css

Lines changed: 572 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class DashboardController < ApplicationController
2+
3+
has_widgets do |root|
4+
root << widget(:twitter, :title => "Twitter")
5+
root << widget(:trashbin, :title => "Trash Bin")
6+
end
7+
8+
def index
9+
end
10+
11+
end

app/helpers/dashboard_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module DashboardHelper
2+
end

app/views/dashboard/index.html.haml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
%h1 Rails Portlets Dashboard
2+
3+
#dashboard
4+
.column
5+
= render_widget 'twitter'
6+
.column
7+
= render_widget 'trashbin'
8+
-#.column
9+
-#= render_widget 'autocomplete'
10+
11+
:javascript
12+
$(function() {
13+
$(".column").sortable({
14+
connectWith: '.column'
15+
});
16+
17+
$(".portlet").addClass("ui-widget ui-widget-content ui-helper-clearfix ui-corner-all")
18+
.find(".portlet-header")
19+
.addClass("ui-widget-header ui-corner-all")
20+
.prepend('<span class="ui-icon ui-icon-minusthick"></span>')
21+
.end()
22+
.find(".portlet-content");
23+
24+
$(".portlet-header .ui-icon").click(function() {
25+
$(this).toggleClass("ui-icon-minusthick").toggleClass("ui-icon-plusthick");
26+
$(this).parents(".portlet:first").find(".portlet-content").toggle();
27+
});
28+
});

app/widgets/layouts/portlet.haml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
= widget_div :class => :portlet, :id => "portlet-#{widget_id}" do
2+
.portlet-header
3+
= @title || "Eggplant portlet!"
4+
.portlet-content(id=widget_id)
5+
= yield
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
= widget_div do
2-
%h1
3-
TrashbinWidget#display
4-
%p
5-
Find me in app/widgets/trashbin/display.html.haml
1+
= image_tag "trashbin_empty.png", 'data-event-url' => url_for_event(:drop), :id => "trashbin-imgtag"
2+
3+
:javascript
4+
$("#trashbin").droppable({
5+
drop: function(event, ui) {
6+
$.ajax({url: $("#trashbin-imgtag").attr("data-event-url") + "&id=" + ui.draggable.attr("data-id")});
7+
}
8+
});

app/widgets/trashbin_widget.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
class TrashbinWidget < Apotomo::Widget
22

3+
responds_to_event :drop, :with => :trash
4+
5+
after_initialize :setup!
6+
37
def display
4-
render
8+
render :layout => 'portlet'
59
end
10+
11+
def trash
12+
Tweet.find(param(:id)).delete
13+
trigger :tweetDeleted
14+
15+
update :view => :display
16+
end
17+
18+
private
19+
def setup!(*)
20+
@title = options[:title]
21+
end
622

723
end

app/widgets/twitter/display.html.haml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1-
= widget_div do
2-
%h1
3-
TwitterWidget#display
4-
%p
5-
Find me in app/widgets/twitter/display.html.haml
1+
%ul
2+
- for tweet in @tweets
3+
%li{'data-id' => tweet.id}
4+
= tweet.text
5+
6+
%p
7+
What are you up to?
8+
9+
= form_tag "", "data-event-url" => url_for_event(:submit) do
10+
= text_field_tag 'text'
11+
12+
= submit_tag "Tweet!"
13+
14+
:javascript
15+
var form = $("##{widget_id} form");
16+
form.submit(function() {
17+
$.ajax({url: form.attr("data-event-url"), data: form.serialize()})
18+
return false;
19+
});
20+
$("##{widget_id} li").draggable({revert: "invalid"});

app/widgets/twitter_widget.rb

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
11
class TwitterWidget < Apotomo::Widget
22

3+
responds_to_event :submit, :with => :process_tweet
4+
after_initialize :setup!
5+
6+
after_add do
7+
root.respond_to_event :tweetDeleted, :with => :redraw, :on => widget_id
8+
end
9+
310
def display
4-
render
11+
@tweets = Tweet.find(:all)
12+
render :layout => "portlet"
13+
end
14+
15+
def process_tweet(evt)
16+
@tweet = Tweet.new(:text => evt[:text]).save
17+
18+
@tweets = Tweet.find(:all)
19+
update :view => :display
20+
end
21+
22+
def redraw
23+
@tweets = Tweet.find(:all)
24+
update :view => :display
525
end
26+
27+
private
28+
def setup!(*)
29+
@title = options[:title]
30+
end
631

732
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require 'test_helper'
2+
3+
class DashboardControllerTest < ActionController::TestCase
4+
test "should get index" do
5+
get :index
6+
assert_response :success
7+
end
8+
9+
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require 'test_helper'
2+
3+
class DashboardHelperTest < ActionView::TestCase
4+
end

0 commit comments

Comments
 (0)