Skip to content

Commit

Permalink
[WebUI IntelliHome#7] Adding serialization for result sets
Browse files Browse the repository at this point in the history
  • Loading branch information
skullbocks committed Aug 20, 2014
1 parent 1e040f6 commit 2fb2604
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 7 deletions.
18 changes: 17 additions & 1 deletion lib/IntelliHome/Schema/SQLite/Schema/Result/GPIO.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package IntelliHome::Schema::SQLite::Schema::Result::GPIO;

=head1 NAME
IntelliHome::Schema::SQLite::Schema::Result::GPIO - DBIx::Class model that represent a GPIO
IntelliHome::Schema::SQLite::Schema::Result::GPIO - DBIx::Class model that represent a GPIO
=head1 DESCRIPTION
Expand Down Expand Up @@ -91,4 +91,20 @@ sub status {
shift->value(@_);
}

sub serialize {
{ title => $_[0]->tags->first ? $_[0]->tags->first()->tag : "",
id => $_[0]->gpioid,
image => 0,
driver => $_[0]->driver,
status => $_[0]->status,
toggle => ( ( split( /::/, $_[0]->driver ) )[-1] eq "Mono" ) ? 1 : 0,
gpio => $_[0]->pin_id,
node_data => [ $_[0]->node ],
type => $_[0]->type,
room => $_[0]->node->room->name,
tags_data => [ map { $_->serialize } $_[0]->tags->all() ],
pins_data => [ map { $_->serialize } $_[0]->pins->all() ]
};
}

1;
20 changes: 17 additions & 3 deletions lib/IntelliHome/Schema/SQLite/Schema/Result/Node.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package IntelliHome::Schema::SQLite::Schema::Result::Node;

=head1 NAME
IntelliHome::Schema::SQLite::Schema::Result::Node - DBIx::Class model that represent a Node
IntelliHome::Schema::SQLite::Schema::Result::Node - DBIx::Class model that represent a Node
=head1 DESCRIPTION
Expand Down Expand Up @@ -97,11 +97,25 @@ sub Port {
}

sub selectFromType {
caller->instance->Remote->Parser->Backend->selectFromType($_[1]);
caller->instance->Remote->Parser->Backend->selectFromType( $_[1] );
}

sub serialize {
{ id => $_[0]->nodeid,
name => $_[0]->name,
description => $_[0]->description,
host => $_[0]->host,
port => $_[0]->port,
type => $_[0]->type,
username => $_[0]->username,
password => $_[0]->password,
gpios_data => [ map { $_->serialize } $_[0]->gpios->all() ],
room_data => [ $_[0]->room ]
};
}

sub selectFromHost {
caller->instance->Remote->Parser->Backend->selectFromHost($_[1],$_[2]);
caller->instance->Remote->Parser->Backend->selectFromHost( $_[1], $_[2] );
}

1;
11 changes: 10 additions & 1 deletion lib/IntelliHome/Schema/SQLite/Schema/Result/Pin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package IntelliHome::Schema::SQLite::Schema::Result::Pin;

=head1 NAME
IntelliHome::Schema::SQLite::Schema::Result::Pin - DBIx::Class model that represent a Pin of a Node
IntelliHome::Schema::SQLite::Schema::Result::Pin - DBIx::Class model that represent a Pin of a Node
=head1 DESCRIPTION
Expand Down Expand Up @@ -60,6 +60,15 @@ __PACKAGE__->belongs_to(
'gpioid'
);

sub serialize {
{ id => $_[0]->pinid,
gpioid => $_[0]->gpioid,
pin => $_[0]->pin,
type => $_[0]->type,
value => $_[0]->value
};
}

sub status {
shift->value(@_);
}
Expand Down
12 changes: 11 additions & 1 deletion lib/IntelliHome/Schema/SQLite/Schema/Result/Room.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package IntelliHome::Schema::SQLite::Schema::Result::Room;

=head1 NAME
IntelliHome::Schema::SQLite::Schema::Result::Room - DBIx::Class model that represent a Room in the house
IntelliHome::Schema::SQLite::Schema::Result::Room - DBIx::Class model that represent a Room in the house
=head1 DESCRIPTION
Expand Down Expand Up @@ -52,4 +52,14 @@ __PACKAGE__->has_many(
'roomid'
);

sub serialize {
{ id => $_[0]->roomid,
name => $_[0]->name,
location => $_[0]->location,
description => $_[0]->description,
notes => $_[0]->notes,
nodes_data => [ map { $_->serialize } $_[0]->nodes->all() ]
};
}

1;
9 changes: 8 additions & 1 deletion lib/IntelliHome/Schema/SQLite/Schema/Result/Tag.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package IntelliHome::Schema::SQLite::Schema::Result::Tag;

=head1 NAME
IntelliHome::Schema::SQLite::Schema::Result::Tag - DBIx::Class model that represent a Tag associated to a gpio
IntelliHome::Schema::SQLite::Schema::Result::Tag - DBIx::Class model that represent a Tag associated to a gpio
=head1 DESCRIPTION
Expand Down Expand Up @@ -55,4 +55,11 @@ __PACKAGE__->belongs_to(
'gpioid'
);

sub serialize {
{ id => $_[0]->tagid,
gpioid => $_[0]->gpioid,
tag => $_[0]->tag,
description => $_[0]->description,
};
}
1;

0 comments on commit 2fb2604

Please sign in to comment.