Skip to content

Commit

Permalink
[WebUI IntelliHome#7] Added new controllers for add and delete functions
Browse files Browse the repository at this point in the history
  • Loading branch information
skullbocks committed Aug 19, 2014
1 parent 726017f commit b21fc78
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
54 changes: 54 additions & 0 deletions lib/IntelliHome/WebUI/Controller/Gpio.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package IntelliHome::WebUI::Controller::Gpio;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::Util qw(hmac_sha1_sum);
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 ) );
}

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 ) );
}

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 ) );
}

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

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

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

1;

24 changes: 24 additions & 0 deletions lib/IntelliHome/WebUI/Controller/Node.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package IntelliHome::WebUI::Controller::Node;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::Util qw(hmac_sha1_sum);
use List::Util qw(min max);
use POSIX;
use Encode;
use IntelliHome::WebUI::Model::Tile;

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

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

1;

23 changes: 23 additions & 0 deletions lib/IntelliHome/WebUI/Controller/Room.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package IntelliHome::WebUI::Controller::Room;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::Util qw(hmac_sha1_sum);
use List::Util qw(min max);
use POSIX;
use Encode;
use IntelliHome::WebUI::Model::Tile;

sub add {
my $self = shift;
my %data = $self->deserialize_form_data( $self->param("data") );
$self->render( text => scalar $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") ) );
}

1;

0 comments on commit b21fc78

Please sign in to comment.