Skip to content

Commit

Permalink
[WebUI IntelliHome#7] Adding return data in JSON format for add and d…
Browse files Browse the repository at this point in the history
…elete functions in controllers
  • Loading branch information
skullbocks committed Aug 20, 2014
1 parent 2fb2604 commit 0049e33
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
21 changes: 10 additions & 11 deletions lib/IntelliHome/WebUI/Controller/Gpio.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,48 @@ use List::Util qw(min max);
use POSIX;
use Encode;
use IntelliHome::WebUI::Model::Tile;
use Data::Dumper;
use JSON;

sub add {
my $self = shift;
my %data = $self->deserialize_form_data( $self->param("data") );
my $node = { id => $data{nodeid} };
delete $data{nodeid};
$self->render( text => scalar $self->build_new_gpio( \%data, $node ) );
$self->render( json => $self->build_new_gpio( \%data, $node ) );
}

sub add_tag {
my $self = shift;
my %data = $self->deserialize_form_data( $self->param("data") );
my $gpio = { id => $data{gpioid} };
delete $data{gpioid};
$self->render( text => scalar $self->build_new_tag( \%data, $gpio ) );
$self->render( json => $self->build_new_tag( \%data, $gpio ) );
}

sub add_pin {
my $self = shift;
my %data = $self->deserialize_form_data( $self->param("data") );
my $gpio = { id => $data{gpioid} };
delete $data{gpioid};
$self->render( text => scalar $self->build_new_pin( \%data, $gpio ) );
$self->render( json => $self->build_new_pin( \%data, $gpio ) );
}

sub delete {
my $self = shift;
$self->render(
text => $self->delete_entity( "GPIO", $self->param("id") ) );
$self->render( json =>
{ result => $self->delete_entity( "GPIO", $self->param("id") ) }
);
}

sub delete_tag {
my $self = shift;
$self->render(
text => $self->delete_entity( "Tag", $self->param("id") ) );
$self->render( json =>
{ result => $self->delete_entity( "Tag", $self->param("id") ) } );
}

sub delete_pin {
my $self = shift;
$self->render(
text => $self->delete_entity( "Pin", $self->param("id") ) );
$self->render( json =>
{ result => $self->delete_entity( "Pin", $self->param("id") ) } );
}

1;
Expand Down
7 changes: 4 additions & 3 deletions lib/IntelliHome/WebUI/Controller/Node.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ use List::Util qw(min max);
use POSIX;
use Encode;
use IntelliHome::WebUI::Model::Tile;
use JSON;

sub add {
my $self = shift;
my %data = $self->deserialize_form_data( $self->param("data") );
my $room = { id => $data{roomid} };
my $room = { id => $data{roomid} };
delete $data{roomid};
$self->render( text => scalar $self->build_new_node( \%data, $room ) );
$self->render( json => $self->build_new_node( \%data, $room ) );
}

sub delete {
my $self = shift;
$self->render(
text => $self->delete_entity( "Node", $self->param("id") ) );
{ result => $self->delete_entity( "Node", $self->param("id") ) } );
}

1;
Expand Down
11 changes: 7 additions & 4 deletions lib/IntelliHome/WebUI/Controller/Room.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ use List::Util qw(min max);
use POSIX;
use Encode;
use IntelliHome::WebUI::Model::Tile;
use JSON;

sub add {
my $self = shift;
my %data = $self->deserialize_form_data( $self->param("data") );
$self->render( text => scalar $self->build_new_room( \%data ) );
$self->render( json => $self->build_new_room( \%data ) );
}

sub delete {
my $self = shift;
$self->app->rooms([ grep{ $_->id != $self->param("id") } @{$self->app->rooms} ]);
$self->render(
text => $self->delete_entity( "Room", $self->param("id") ) );
my $result = $self->delete_entity( "Room", $self->param("id") );
$self->app->rooms(
[ grep { $_->id != $self->param("id") } @{ $self->app->rooms } ] )
if ($result);
$self->render( json => { result => $result } );
}

1;
Expand Down

0 comments on commit 0049e33

Please sign in to comment.