Skip to content

Commit

Permalink
MC
Browse files Browse the repository at this point in the history
  • Loading branch information
dnarvaez27 committed Dec 6, 2017
1 parent f495866 commit b03aee6
Show file tree
Hide file tree
Showing 31 changed files with 595 additions and 826 deletions.
4 changes: 4 additions & 0 deletions Proyecto/Proyecto-BackEnd/app/Global.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ public void onStart( Application app )
area12.save( );
}

System.out.println( "Size: " + Microcontrolador.find.all( ).size( ) );

if( Microcontrolador.find.all( ).isEmpty( ) )
{
Area a1 = new Area( );
Expand Down Expand Up @@ -251,6 +253,8 @@ public void onStart( Application app )
m9.save( );
}

System.out.println( "Size: " + Microcontrolador.find.all( ) );

if( VariableAmbiental.find.all( ).isEmpty( ) )
{
VariableAmbiental v1 = new VariableAmbiental( );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Result create( Long idArea )
public Result retrieveAll( Long idArea )
{

List<Actuador> actuador = Actuador.find.where( ).eq( "idArea", idArea ).findList( );
List<Actuador> actuador = Actuador.find.where( ).eq( "area.id", idArea ).findList( );
return ok( Json.toJson( actuador ) );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Result create( Long idArea )
@RolesAllowed( { Roles.ADMIN, Roles.SUPERVISOR } )
public Result retrieveAll( Long idArea )
{
List<Alerta> alerta = Alerta.find.where( ).eq( "idArea", idArea ).findList( );
List<Alerta> alerta = Alerta.find.where( ).eq( "area.id", idArea ).findList( );
return ok( Json.toJson( alerta ) );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Result create( Long idNivel )
@RolesAllowed( { Roles.ADMIN, Roles.SUPERVISOR } )
public play.mvc.Result retrieveAll( Long idNivel )
{
List<Area> area = Area.find.where( ).eq( "idNivel", idNivel ).findList( );
List<Area> area = Area.find.where( ).eq( "nivel.id", idNivel ).findList( );
return ok( Json.toJson( area ) );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Result create( Long idSensor )
@RolesAllowed( { Roles.ADMIN, Roles.SUPERVISOR } )
public Result retrieveAll( Long idSensor )
{
List<Dato> dato = Dato.find.where( ).eq( "idSensor", idSensor ).findList( );
List<Dato> dato = Dato.find.where( ).eq( "sensor.id", idSensor ).findList( );
return ok( Json.toJson( dato ) );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Result create( Long idArea )
@RolesAllowed( { Roles.ADMIN, Roles.SUPERVISOR } )
public Result retrieveAll( Long idArea )
{
List<Microcontrolador> microcontrolador = Microcontrolador.find.where( ).eq( "idArea", idArea ).findList( );
List<Microcontrolador> microcontrolador = Microcontrolador.find.where( ).eq( "area.id", idArea ).findList( );
return ok( Json.toJson( microcontrolador ) );
}

Expand Down Expand Up @@ -61,4 +61,10 @@ public Result delete( Long id )
microcontrolador.delete( );
return ok( play.libs.Json.toJson( microcontrolador ) );
}

public Result getAll( )
{
List<Microcontrolador> microcontrolador = Microcontrolador.find.all( );
return ok( Json.toJson( microcontrolador ) );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Result create( Long idNivel )
@RolesAllowed( { Roles.ADMIN, Roles.SUPERVISOR } )
public Result retrieveAll( Long idNivel )
{
List<Reporte> reporte = Reporte.find.where( ).eq( "idNivel", idNivel ).findList( );
List<Reporte> reporte = Reporte.find.where( ).eq( "nivel.id", idNivel ).findList( );
return ok( Json.toJson( reporte ) );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Result create( Long idMicrocontrolador )
@RolesAllowed( { Roles.ADMIN, Roles.SUPERVISOR } )
public Result retrieveAll( Long idMicrocontrolador )
{
List<Sensor> sensor = Sensor.find.where( ).eq( "idMicrocontrolador", idMicrocontrolador ).findList( );
List<Sensor> sensor = Sensor.find.where( ).eq( "microcontrolador.id", idMicrocontrolador ).findList( );
return ok( Json.toJson( sensor ) );
}

Expand Down
32 changes: 29 additions & 3 deletions Proyecto/Proyecto-BackEnd/app/models/main/Area.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ public void setAlertas( List<Alerta> alertas )
this.alertas = alertas;
}

public List<Microcontrolador> getMicrocontroladores( )
public java.util.List<Microcontrolador> getMicrocontroladores( )
{
return microcontroladores;
}

public void setMicrocontroladores( List<Microcontrolador> microcontroladores )
public void setMicrocontroladores( java.util.List<Microcontrolador> microcontroladores )
{
this.microcontroladores = microcontroladores;
}
Expand All @@ -102,7 +102,33 @@ public static Area bind( JsonNode json )
Area area = new Area( );
area.setId( json.findPath( "id" ).asLong( ) );
area.setTipo( json.findPath( "tipo" ).asInt( ) );
//TODO Lists
area.setMicrocontroladores( new java.util.LinkedList<>( ) );
area.setAlertas( new java.util.LinkedList<>( ) );
area.setActuadores( new java.util.LinkedList<>( ) );

for( JsonNode j : json.findPath( "microcontroladores" ) )
{
Long id = j.findPath( "id" ).asLong( );
Microcontrolador mc = new Microcontrolador( );
mc.setId( id );
area.microcontroladores.add( mc );
}

for( JsonNode j : json.findPath( "alertas" ) )
{
Long id = j.findPath( "id" ).asLong( );
Alerta alerta = new Alerta( );
alerta.setId( id );
area.alertas.add( alerta );
}

for( JsonNode j : json.findPath( "actuadores" ) )
{
Long id = j.findPath( "id" ).asLong( );
models.main.Actuador actuador = new models.main.Actuador( );
actuador.setId( id );
area.actuadores.add( actuador );
}
return area;
}
}
1 change: 1 addition & 0 deletions Proyecto/Proyecto-BackEnd/app/models/main/Dato.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class Dato extends Model

private Date timeStamp;

@com.fasterxml.jackson.annotation.JsonIgnore
@javax.persistence.ManyToOne
private Sensor sensor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public class Microcontrolador extends Model
@javax.persistence.OneToMany( mappedBy = "microcontrolador" )
private List<Sensor> sensores;

@com.fasterxml.jackson.annotation.JsonIgnore
@javax.persistence.ManyToOne
@javax.persistence.Column( nullable = false )
private Area area;

public Microcontrolador( )
Expand Down Expand Up @@ -53,7 +55,7 @@ public Area getArea( )
return area;
}

public void setArea( Area idArea )
public void setArea( Area area )
{
this.area = area;
}
Expand Down
1 change: 1 addition & 0 deletions Proyecto/Proyecto-BackEnd/app/models/main/Sensor.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Sensor extends Model
@javax.persistence.OneToMany( mappedBy = "sensor" )
private List<Dato> datos;

@com.fasterxml.jackson.annotation.JsonIgnore
@javax.persistence.ManyToOne
private models.main.Microcontrolador microcontrolador;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class VariableAmbiental extends Model

private String nombre;

@com.fasterxml.jackson.annotation.JsonIgnore
@javax.persistence.OneToMany( mappedBy = "tipo" )
private java.util.List<Sensor> sensores;

Expand Down
3 changes: 3 additions & 0 deletions Proyecto/Proyecto-BackEnd/conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,6 @@ DELETE /variablesAmbientales/:idVariable controller

# OPTIONS
# OPTIONS /*any controllers.Application.options(any: String)


GET /microcontroladores controllers.MicrocontroladorController.getAll()
4 changes: 4 additions & 0 deletions Proyecto/Proyecto-FrontEnd/app/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
'ui.router',
'ngCookies',

'microcontroladorModule',
'areaModule',
'variablesModule',
'rolesModule',
'nivelesModule',
Expand Down Expand Up @@ -31,6 +33,8 @@
'/menu/roles$': [ 'ADMIN', 'SYSO' ],
'/menu/variables$': [ 'ADMIN', 'SYSO' ],
'/menu/niveles/[0-9]+$': [ 'ADMIN', 'SYSO' ],
'/menu/areas/[0-9]+$': [ 'ADMIN', 'SYSO' ],
'/menu/microcontroladores/[0-9]+$': [ 'ADMIN', 'SYSO' ],
},
verifyRol: function ( user ) {
let self = this;
Expand Down
107 changes: 107 additions & 0 deletions Proyecto/Proyecto-FrontEnd/app/src/modules/areas/areas.ctrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
(function ( ng ) {
let mod = ng.module( 'areaModule' );

mod.controller( 'areasCtrl', [ '$scope', '$stateParams', 'AuthService', 'SessionService', '$http', 'urlBack', '$state',
function ( $scope, $stateParams, AuthService, SessionService, $http, urlBack, $state ) {
AuthService.checkUser( $scope.$parent.user )
.then( function ( response ) {
$http( {
method: 'GET',
url: urlBack + '/areas/' + $stateParams.idArea,
headers: {
'user': SessionService.user.login,
'token': SessionService.user.token
}
} )
.then( function ( response ) {
$scope.area = response.data;
$scope.microcontroladores = $scope.area.microcontroladores;

const maxInRow = 10;
let row = -1;
let temp = [];
$scope.microcontroladores.forEach( function ( item, index ) {
if ( index % maxInRow === 0 ) {
row++;
}
let nuevo = {
id: item.id,
sensores: item.sensores,
x: row,
y: index % maxInRow,
value: 10, //TODO
'hc-a2': 'MicronControlador ' + item.id
};
temp.push( nuevo );
} );

$scope.microcontroladores = temp;
let info = {
chart: {
type: 'tilemap',
inverted: true,
// height: '50%',
},
title: {
text: 'Niveles Del Sistema'
},
xAxis: {
visible: false
},
yAxis: {
visible: false
},
colorAxis: {
dataClasses: [ {
from: 0,
to: 50,
color: '#F9EDB3',
name: '< 50'
}, {
from: 51,
to: 100,
color: '#FFC428',
name: '50 - 100'
}, {
from: 101,
color: '#FF7987',
name: '> 100'
} ]
},
tooltip: {
headerFormat: '',
pointFormat: 'The population of <b> {point.name}</b> is <b>{point.value}</b>'
},
plotOptions: {
series: {
dataLabels: {
enabled: true,
format: '{point.hc-a2}',
color: '#000000',
style: {
textOutline: false
}
},
point: {
events: {
click: function () {
$scope.seeMC( this.id );
}
}
}
}
},
series: [ {
name: '',
data: $scope.microcontroladores
} ]
};
Highcharts.chart( 'containerMicrocontrolador', info );
} );
} );
$scope.seeMC = function ( id ) {
$state.go( 'microcontroladoresDetail', { idMicrocontrolador: id } );
};
}
] );
})( angular );
7 changes: 7 additions & 0 deletions Proyecto/Proyecto-FrontEnd/app/src/modules/areas/areas.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h1>{{'Area '+area.id}}</h1>

<div class="niveles-container">
<div>
<div id="containerMicrocontrolador"></div>
</div>
</div>
23 changes: 23 additions & 0 deletions Proyecto/Proyecto-FrontEnd/app/src/modules/areas/areas.mod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(function ( ng ) {
let mod = ng.module( 'areaModule', [ 'ui.router' ] );

mod.config( [ '$stateProvider', '$urlRouterProvider',
function ( $stateProvider, $urlRouterProvider ) {
$urlRouterProvider.otherwise( '/areas' );

$stateProvider
.state( 'areas', {
url: '/areas/:idArea',
parent: 'menu',
params: {
idArea: null
},
views: {
'listView': {
templateUrl: 'app/src/modules/areas/areas.html',
controller: 'areasCtrl'
}
}
} );
} ] );
})( window.angular );
Empty file.
Empty file.
Loading

0 comments on commit b03aee6

Please sign in to comment.