forked from IntelliHome/Google-at-Home
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WebUI IntelliHome#7] Added new controllers for add and delete functions
- Loading branch information
skullbocks
committed
Aug 19, 2014
1 parent
726017f
commit b21fc78
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|