Skip to content

Commit

Permalink
joooder, estoy impresionado... funcionaaa
Browse files Browse the repository at this point in the history
  • Loading branch information
danigb committed Nov 19, 2010
1 parent e6e4382 commit 034b113
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 153 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem "simple_form"
gem "show_for"
gem "cancan"
gem "jammit"
gem "rest-client"


# Bundle edge Rails instead:
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ GEM
remarkable (~> 3.1.13)
rspec (>= 1.2.0)
responders (0.6.2)
rest-client (1.6.1)
mime-types (>= 1.16)
rspec (2.0.1)
rspec-core (~> 2.0.1)
rspec-expectations (~> 2.0.1)
Expand Down Expand Up @@ -140,6 +142,7 @@ DEPENDENCIES
rails (= 3.0.0)
rails3-generators
remarkable_activerecord
rest-client
rspec
rspec-rails (>= 2.0.0.beta)
ruby-debug
Expand Down
11 changes: 10 additions & 1 deletion app/controllers/operations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@ class OperationsController < InheritedResources::Base
belongs_to :assembly
actions :all, :except => [:show]
respond_to :html, :xml, :json

URL = 'http://api.beaconpush.com/1.0.0/5ed7901c/channels/asamblea'

def create
# TODO: ensure currect (use cancan)
current_user.participants.find(params[:operation][:participant_id])
participant_id = params[:operation][:participant_id]
current_user.participants.find(participant_id)

create! do |format|
data = {:type => 'action',
:participant_id => participant_id, :assembly_id => params[:assembly_id],
:operation => @operation
}
RestClient.post URL + params[:assembly_id], data.to_json, :content_type => :json, :accept => :json

format.html { assembly_operations_path(@assembly) }
format.json { render :json => @operation}
format.xml { render :xml => @operation }
Expand Down
2 changes: 1 addition & 1 deletion app/views/assemblies/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<%= participant.name %>
<% end %> </td>
<td class="actions">

<%= link_to 'Enviar mensaje', new_assembly_message_path(assembly) %>
<%= link_to 'Participantes', assembly_participants_path(assembly) %>
<%= link_to 'Operaciones', assembly_operations_path(assembly) %>
<%= link_to 'Editar', edit_assembly_path(assembly) %>
Expand Down
1 change: 1 addition & 0 deletions app/views/assemblies/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<script type="text/javascript">
Assembly = {}
Assembly.operation_url = '<%= assembly_operations_url(@assembly) %>';
Assembly.messages_url = '<%= assembly_messages_url(@assembly) %>';
Assembly.current_participant_id = <%= @participant.id %>;
Assembly.attributes = <%= @assembly.to_json.html_safe %>;
Assembly.participants = <%= @assembly.participants.to_json.html_safe %>;
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/client.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<!--script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script -->
<!-- script>!window.jQuery && document.write('<script src="/javascripts/jquery-1.4.2.min.js"><\/script>')</script -->
<%= csrf_meta_tag %>
<script type="text/javascript" src="http://beaconpush.com/1/client.js"></script>
<%= include_javascripts :assembly %>

<!--[if lt IE 7 ]>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
resources :assemblies, :path => 'a' do
resources :operations, :path => 'o'
resources :participants, :path => 'p'
resources :messages, :path => 'm'
end
resources :groups, :path => 'grupos'
resources :activities, :path => 'actividades'
Expand Down
44 changes: 0 additions & 44 deletions public/javascripts/client/helpers/ajax_helper.js

This file was deleted.

53 changes: 0 additions & 53 deletions public/javascripts/client/helpers/color_helper.js

This file was deleted.

26 changes: 0 additions & 26 deletions public/javascripts/client/helpers/execute_helper.js

This file was deleted.

16 changes: 8 additions & 8 deletions public/javascripts/client/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
});

function loadData() {
var assembly = new $$.Assembly(Assembly.attributes);
$$.Session.set({
assembly : new $$.Assembly(Assembly.attributes)
assembly : assembly
});

$$.RealTime.connect(assembly.get('id'));

// LOAD PARTICIPANTS
for (var index = 0; index < Assembly.participants.length; index++) {
$$.Participants.add(new $$.Participant(Assembly.participants[index]));
for (var parIndex = 0; parIndex < Assembly.participants.length; parIndex++) {
$$.Participants.add(new $$.Participant(Assembly.participants[parIndex]));
}
var current_participant = $$.Participants.getByParticipantId(Assembly.current_participant_id);
console.log("SET current", current_participant)
Expand All @@ -35,11 +38,8 @@
});

// LOAD OPERATIONS
for (var opi = 0; opi < Assembly.operations.length; opi++) {
var operation = Assembly.operations[opi];
console.log("LOAD OP", operation);
operation.params = $.parseJSON(operation.params);
$$.Operations.add(new $$.Operation(operation));
for (var opIndex = 0; opIndex < Assembly.operations.length; opIndex++) {
$$.Operations.receive(Assembly.operations[opIndex]);
}


Expand Down
23 changes: 19 additions & 4 deletions public/javascripts/client/models/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,26 @@
DONE: "done",
PENDING: "pending",
initialize: function() {
var participant = $$.Session.current_participant;
this.set({
participant_name : participant.get('name'),
participant_color : participant.get('color')
if (!this.get('participant_id')) {
var participant = $$.Session.current_participant;
this.set({
participant_id : participant.get('id'),
participant_name : participant.get('name'),
participant_color : participant.get('color')
});
} else {
participant = $$.Participants.getByParticipantId(this.get('participant_id'))
this.set({
participant_name : participant.get('name'),
participant_color : participant.get('color')
});
}

if (!this.get('type')) {
this.set({
type : 'message'
})
}
},
clear: function() {
this.destroy();
Expand Down
3 changes: 2 additions & 1 deletion public/javascripts/client/models/message_list.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(function() {
$$.MessageList = Backbone.Collection.extend({
model: $$.Message,

url: Assembly.messages_url,

initialize : function() {
_.bindAll(this, 'process');
this.bind('add', this.process);
Expand Down
18 changes: 5 additions & 13 deletions public/javascripts/client/models/operation_list.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
(function() {
var Factories = {
Topic : {

},
Entry : {
create : function(attributes) {
console.log("FACTORY Entry", attributes);
var topic = $$.Topics.getByOperationId(attributes.topic_id);
topic.addEntry(new $$.Entry(attributes));
}
}
};

$$.OperationList = Backbone.Collection.extend({
model: $$.Operation,
url: Assembly.operation_url,

initialize : function() {
_.bindAll(this, 'execute');
this.bind('add', $$.ExecuteHelper);
},
receive : function(operation) {
operation.params = $.parseJSON(operation.params);
console.log("RECEIVED OP", operation);
$$.Operations.add(new $$.Operation(operation));
}
});
})(jQuery);
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@

createOnEnter: function(e) {
if (e.keyCode == 13) {
$$.Messages.add({
$$.Messages.create(new $$.Message({
body: this.input.val()
});
}));
this.input.val('');
return false;
}
Expand Down

0 comments on commit 034b113

Please sign in to comment.