Commit 066dbd66 by gema

Merge branch 'master' of http://git.setisl.com/inutraliaapp/2018_web_app into gemis_dev

parents 76f5d585 5e23a7bf
...@@ -22,9 +22,11 @@ use Fuel\Core\Session; ...@@ -22,9 +22,11 @@ use Fuel\Core\Session;
class Controller_App extends Controller{ class Controller_App extends Controller{
use Trait_InutraliaWS;
public function before(){ public function before(){
if (!$this->control_time_session()){ if (!Session::get('token_auth') || !$this->control_time_session()){
Session::destroy(); Session::destroy();
Response::redirect("/"); Response::redirect("/");
} }
......
...@@ -55,6 +55,7 @@ class Controller_Login_Index extends Controller ...@@ -55,6 +55,7 @@ class Controller_Login_Index extends Controller
'Se perdio la ventana de autenticación, ha pasado demasiado tiempo 'Se perdio la ventana de autenticación, ha pasado demasiado tiempo
inactivo, intentelo de nuevo.' inactivo, intentelo de nuevo.'
); );
\Session::delete('token_auth');
Response::redirect('auth/login'); Response::redirect('auth/login');
return null; return null;
} }
...@@ -85,7 +86,7 @@ class Controller_Login_Index extends Controller ...@@ -85,7 +86,7 @@ class Controller_Login_Index extends Controller
); );
} }
\Session::delete('token_auth');
Response::redirect('auth/login'); Response::redirect('auth/login');
return null; return null;
} }
......
...@@ -23,7 +23,7 @@ class Controller_Perfil_Index extends \Controller_App{ ...@@ -23,7 +23,7 @@ class Controller_Perfil_Index extends \Controller_App{
public function before(){ public function before(){
//Se cargan funciones de javascript especificas de esta funcionalidad //Se cargan funciones de javascript especificas de esta funcionalidad
Casset::js('dashboard/index.js'); Casset::js('perfil/index.js');
//Se marca la navegación en forma de migas de pan. Cada miga de pan la forman dos variables: //Se marca la navegación en forma de migas de pan. Cada miga de pan la forman dos variables:
// ds : String a mostrar // ds : String a mostrar
...@@ -33,6 +33,13 @@ class Controller_Perfil_Index extends \Controller_App{ ...@@ -33,6 +33,13 @@ class Controller_Perfil_Index extends \Controller_App{
parent::before(); parent::before();
} }
/**
*
* Pantalla carga perfil
*
* @return Response
*/
public function action_index(){ public function action_index(){
$view = View::forge('perfil/index.twig'); $view = View::forge('perfil/index.twig');
...@@ -46,8 +53,21 @@ class Controller_Perfil_Index extends \Controller_App{ ...@@ -46,8 +53,21 @@ class Controller_Perfil_Index extends \Controller_App{
//Paso de las opciones de menu que deben aparecer seleccionadas //Paso de las opciones de menu que deben aparecer seleccionadas
$view->option_menu = $this->_option_menu; $view->option_menu = $this->_option_menu;
$view -> profile = $this->ws_profile_get();
return Response::forge($view); return Response::forge($view);
} }
/**
* Guardamos datos perfil.
*
* @return bool
*/
public function post_update(){
return $this->ws_profile_put(\Input::post('id'),\Input::post('inputs')) ? true : false;
}
} }
\ No newline at end of file
...@@ -15,43 +15,49 @@ trait Trait_InutraliaWS { ...@@ -15,43 +15,49 @@ trait Trait_InutraliaWS {
public function get_header(){ public function get_header(){
return array( return array(
'Content-Type: application/json', 'Content-Type: application/json',
'Accept: application/json', 'Accept: application/json',
'Authorization: Basic '. \Session::get('token_auth') 'Authorization: Basic '. \Session::get('token_auth'),
); );
} }
/** /**
* Method to make requests to inutralia. *
* Metodo generico para relaizar peticiones al WS de inutralia
* *
* MORE INFO CURL --> http://php.net/manual/es/function.curl-setopt.php * MORE INFO CURL --> http://php.net/manual/es/function.curl-setopt.php
* *
* @param $parameter_url * @param $url
* @param bool $header * @param string $method
* @param int $timeout
* @param bool $httpget
* @param int $return_transfer * @param int $return_transfer
* @param array $extra_options --> Opciones extra para la request curl, arrat(key, opcion curl / value, valor curl).
* @param array $add_params_header --> Array para añadir mas opciones a la cabecera por defecto.
* @return mixed * @return mixed
*/ */
public function request_generic($url, $method = "get", $return_transfer = 1, $extra_options = array(),$add_params_header = array()){
public function request_generic($parameter_url, $header = false, $timeout = 30, $httpget = true, $return_transfer = 1){
$constant = \Config::load('constants'); $constant = \Config::load('constants');
// La url la obtiene de config dependiendo del entorno. // La url la obtiene de config dependiendo del entorno.
$process = curl_init($constant[$parameter_url]); $ch = curl_init($constant['domain'].$url.$constant['apikey']);
curl_setopt($ch, CURLOPT_HTTPHEADER,array_merge($this->get_header(),$add_params_header));
curl_setopt($ch, $method == "get" ? CURLOPT_HTTPGET :CURLOPT_POST , 1);
curl_setopt($process, CURLOPT_HTTPHEADER,$this->get_header()); curl_setopt($ch, CURLOPT_RETURNTRANSFER, $return_transfer);
curl_setopt($process, CURLOPT_HEADER, $header);
curl_setopt($process, CURLOPT_TIMEOUT, $timeout);
curl_setopt($process, CURLOPT_HTTPGET , $httpget);
curl_setopt($process, CURLOPT_RETURNTRANSFER, $return_transfer);
$return = curl_exec($process); foreach ($extra_options as $key => $value){
curl_setopt($ch, $key, $value);
}
curl_close($process);
$return = curl_exec($ch);
curl_close($ch);
return $return; return $return;
} }
...@@ -73,13 +79,35 @@ trait Trait_InutraliaWS { ...@@ -73,13 +79,35 @@ trait Trait_InutraliaWS {
} }
/** /**
* Request get profile * Reques profile get
*
* @param null $data
* @return mixed
*/ */
public function ws_profile(){ public function ws_profile_get(){
return json_decode($this->request_generic('profile')); return json_decode($this->request_generic('profile'));
} }
/**
* Reques profile put
*
* @param $data
* @return mixed
*/
public function ws_profile_put($id, $data){
$data_json = json_encode($data);
$extra_options = array(
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS => $data_json
);
return json_decode($this->request_generic('profile'.DS.$id,"post",1,$extra_options,array('Content-Length: ' . strlen($data_json))));
}
} }
\ No newline at end of file
...@@ -124,6 +124,7 @@ class Twig_Seti_Extension extends Twig_Extension ...@@ -124,6 +124,7 @@ class Twig_Seti_Extension extends Twig_Extension
'sha1' => new Twig_Function_Function('sha1'), 'sha1' => new Twig_Function_Function('sha1'),
'var_dump' => new Twig_Function_Function('var_dump'), 'var_dump' => new Twig_Function_Function('var_dump'),
'is_divisible' => new Twig_Function_Method($this, 'is_divisible'),
); );
} }
...@@ -185,4 +186,17 @@ class Twig_Seti_Extension extends Twig_Extension ...@@ -185,4 +186,17 @@ class Twig_Seti_Extension extends Twig_Extension
return Fuel::VERSION; return Fuel::VERSION;
} }
/**
*
* Comprueba si un numero es divisible a otro.
*
* @param $num
* @param $div
* @return bool
*/
public function is_divisible($num,$div)
{
return ($num%$div == 0) ? true : false;
}
} }
...@@ -29,13 +29,11 @@ ...@@ -29,13 +29,11 @@
const DOMAIN = "http://inutraliaback20"; const DOMAIN = "http://inutraliaback20";
const V1 = '/api/v1/'; const V1 = '/api/v1/';
const APIKEY = "?api-key=7745289b-f09c-4e0b-89d1-bb59c599c85e";
// PARAMETERS // PARAMETERS
const USER = 'user';
return array( return array(
'user' => DOMAIN.V1.USER.APIKEY, 'domain' => DOMAIN.V1,
'apikey' => "?api-key=7745289b-f09c-4e0b-89d1-bb59c599c85e"
); );
\ No newline at end of file
...@@ -32,9 +32,11 @@ const APIKEY = "?api-key=7745289b-f09c-4e0b-89d1-bb59c599c85e"; ...@@ -32,9 +32,11 @@ const APIKEY = "?api-key=7745289b-f09c-4e0b-89d1-bb59c599c85e";
// PARAMETERS // PARAMETERS
const USER = 'user'; const USER = 'user';
const PROFILE = 'profile';
return array( return array(
'user' => DOMAIN.V1.USER.APIKEY, 'user' => DOMAIN.V1.USER.APIKEY,
'profile' => DOMAIN.V1.PROFILE.APIKEY,
); );
\ No newline at end of file
...@@ -25,17 +25,28 @@ return array( ...@@ -25,17 +25,28 @@ return array(
/*HOME*/ /*HOME*/
'dashboard' => 'dashboard/index', 'dashboard' => 'dashboard/index',
'perfil' =>'perfil/index',
// PERFIL
'perfil' => 'perfil/index',
'perfil/update' => 'perfil/index/update',
// MENU PERSONALIZADO
'menupersonalizado' =>'menupersonalizado/index', 'menupersonalizado' =>'menupersonalizado/index',
// MENU SALUDABLES
'menussaludables' =>'menussaludables/lista/index', 'menussaludables' =>'menussaludables/lista/index',
'menussaludables-menu' =>'menussaludables/menu/index', 'menussaludables-menu' =>'menussaludables/menu/index',
// RECETA
'receta-detalle' =>'receta/index', 'receta-detalle' =>'receta/index',
// RECETARIO
'recetario' =>'recetario/index', 'recetario' =>'recetario/index',
// BOLETIN SALUDABLE
'boletin-saludable' =>'boletinsaludable/index', 'boletin-saludable' =>'boletinsaludable/index',
// ARTICULO
'articulo-detalle' =>'articulo/index', 'articulo-detalle' =>'articulo/index',
'lista-compra' =>'listacompra/index', 'lista-compra' =>'listacompra/index',
......
...@@ -3,9 +3,8 @@ ...@@ -3,9 +3,8 @@
</div> </div>
<span class="input input--nao"> <span class="input input--nao">
<input class="input__field input__field--nao" type="text" id="edad" name="edad" required=""/> <input class="input__field input__field--nao data-profile" type="text" id="age" rel="age" name="age" required="" value="{{ profile.age }}"/>
<label class="input__label input__label--nao" for="age">
<label class="input__label input__label--nao" for="input-1">
<span class="input__label-content input__label-content--nao">Edad</span> <span class="input__label-content input__label-content--nao">Edad</span>
</label> </label>
<svg class="graphic graphic--nao" width="300%" height="100%" viewBox="0 0 1200 60" preserveAspectRatio="none"> <svg class="graphic graphic--nao" width="300%" height="100%" viewBox="0 0 1200 60" preserveAspectRatio="none">
...@@ -14,20 +13,18 @@ ...@@ -14,20 +13,18 @@
</span> </span>
<span class="input input--nao"> <span class="input input--nao">
<input class="input__field input__field--nao" type="text" id="altura" name="altura" required=""/> <input class="input__field input__field--nao data-profile" type="text" id="height" rel="height" name="height" required="" value="{{ profile.height }}"/>
<label class="input__label input__label--nao" for="height">
<label class="input__label input__label--nao" for="input-1">
<span class="input__label-content input__label-content--nao">Altura</span> <span class="input__label-content input__label-content--nao">Altura</span>
</label> </label>
<svg class="graphic graphic--nao" width="300%" height="100%" viewBox="0 0 1200 60" preserveAspectRatio="none"> <svg class="graphic graphic--nao" width="300%" height="100%" viewBox="0 0 1200 60" preserveAspectRatio="none">
<path d="M0,56.5c0,0,298.666,0,399.333,0C448.336,56.5,513.994,46,597,46c77.327,0,135,10.5,200.999,10.5c95.996,0,402.001,0,402.001,0"/> <path d="M0,56.5c0,0,298.666,0,399.333,0C448.336,56.5,513.994,46,597,46c77.327,0,135,10.5,200.999,10.5c95.996,0,402.001,0,402.001,0"/>
</svg> </svg>
</span> </span>
<span class="input input--nao"> <span class="input input--nao">
<input class="input__field input__field--nao" type="text" id="peso" name="peso" required=""/> <input class="input__field input__field--nao data-profile" type="text" id="weight" rel="weight" name="weight" required="" value="{{ profile.weight }}"/>
<label class="input__label input__label--nao" for="weight">
<label class="input__label input__label--nao" for="input-1">
<span class="input__label-content input__label-content--nao">Peso</span> <span class="input__label-content input__label-content--nao">Peso</span>
</label> </label>
<svg class="graphic graphic--nao" width="300%" height="100%" viewBox="0 0 1200 60" preserveAspectRatio="none"> <svg class="graphic graphic--nao" width="300%" height="100%" viewBox="0 0 1200 60" preserveAspectRatio="none">
...@@ -35,29 +32,27 @@ ...@@ -35,29 +32,27 @@
</svg> </svg>
</span> </span>
<span class="input input--nao"> <select class="cs-select cs-skin-underline mt20 data-profile" rel="gender">
<input class="input__field input__field--nao" type="text" id="genero" name="genero" required=""/>
<label class="input__label input__label--nao" for="input-1"> <option value="" {% if (profile.gender=='') %} selected {% endif %} disabled >Género...</option>
<span class="input__label-content input__label-content--nao">Género</span> <option value="H"{% if(profile.gender=='H') %} selected {% endif %} >Hombre</option>
</label> <option value="M"{% if(profile.gender=='M') %} selected {% endif %} >Mujer</option>
<svg class="graphic graphic--nao" width="300%" height="100%" viewBox="0 0 1200 60" preserveAspectRatio="none">
<path d="M0,56.5c0,0,298.666,0,399.333,0C448.336,56.5,513.994,46,597,46c77.327,0,135,10.5,200.999,10.5c95.996,0,402.001,0,402.001,0"/>
</svg>
</span>
<select class="cs-select cs-skin-underline mt20">
<option value="" disabled selected>Actividad fisica...</option>
<option value="1">Sedentario</option>
<option value="2">Ligero</option>
<option value="3">Moderado</option>
<option value="4">Intenso</option>
<option value="5">Muy Intenso</option>
</select> </select>
<select class="cs-select cs-skin-underline mt20"> <select class="cs-select cs-skin-underline mt20 data-profile" rel="physical" >
<option value="" disabled selected>Preferencia de dieta...</option>
<option value="1">Normal</option> <option value="" {% if (profile.physical=='') %} selected {% endif %} disabled >Actividad fisica...</option>
<option value="2">Vegetariana</option> <option value="1"{% if(profile.physical=='1') %} selected {% endif %} >Sedentario</option>
<option value="3">Vegana</option> <option value="2"{% if(profile.physical=='2') %} selected {% endif %} >Ligero</option>
<option value="3"{% if(profile.physical=='3') %} selected {% endif %} >Moderado</option>
<option value="4"{% if(profile.physical=='4') %} selected {% endif %} >Intenso</option>
<option value="5"{% if(profile.physical=='5') %} selected {% endif %} >Muy Intenso</option>
</select>
<select class="cs-select cs-skin-underline mt20 data-profile" rel="preference">
<option value="" {% if profile.preference == "" %} selected {% endif %}disabled>Preferencia de dieta...</option>
<option value="1"{% if profile.preference == "1" %} selected {% endif %}>Normal</option>
<option value="2"{% if profile.preference == "2" %} selected {% endif %}>Vegetariana</option>
<option value="3"{% if profile.preference == "3" %} selected {% endif %}>Vegana</option>
</select> </select>
\ No newline at end of file
...@@ -15,7 +15,9 @@ ...@@ -15,7 +15,9 @@
</div> </div>
</div> </div>
<div class="container pb80" >
<div class="container pb80">
<input type="hidden" id="profile_id" value="{{ profile.id }}">
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
<div class="solid-box bg-color-perfil pb50"> <div class="solid-box bg-color-perfil pb50">
...@@ -23,18 +25,19 @@ ...@@ -23,18 +25,19 @@
</div> </div>
</div> </div>
<div class="col-md-8"> <div class="col-md-8">
<div class="border-box border-perfil"> <div class="border-box border-perfil">
<div class="title-box-border-box bg-color-perfil"> <div class="title-box-border-box bg-color-perfil">
¿Padeces, estás o tienes... ¿Padeces, estás o tienes...
</div> </div>
<div class="container-box-border-box"> <div class="container-box-border-box">
{% include 'switches.twig' %} {% include 'switches.twig' %}
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-6 col-md-offset-6"> <div class="col-md-6 col-md-offset-6">
<button class="btn btn-custom btn-perfil mt40" ><i class="fa fa-save"></i> Guardar Perfil</button> <button class="btn btn-custom btn-perfil mt40"><i class="fa fa-save"></i> Guardar Perfil
</button>
</div> </div>
</div> </div>
</div> </div>
......
<div class="row"> <div class="row">
{% for i in 1..13 %}
<div class="col-xs-6 col-sm-6 col-md-4">
<div class="form-group text-center">
<label class="switch" for="checkbox_{{ i }}">
<input type="checkbox" id="checkbox_{{ i }}" />
<div class="slider round"></div>
</label>
<p>caracteristica {{ i }}</p>
</div>
</div>
{% endfor %}
{% set caracterisitcas =
{
'cv' : 'una enfermedad cardiovascular ?',
'hypertension' : 'hipertensión ?',
'menopause' : 'menopausia ?',
'pregnancy' : 'embarazo ?',
'lactation' : 'lactancia ?',
'celiac' : 'celiacos ?',
'lactose' : 'intolerante a la lactosa?',
'diabetes' : 'diabetes ?',
'cholesterol' : 'colesterol ?',
'triglycerides' : 'trígliceridos ?',
'al_fish' : 'alergia al pescado/marisco ?',
'al_egg' : 'alergia al huevo ?',
'al_nuts' : 'alergia a los frutos secos ?'
} %}
<div class="row">
{#FOR PARA COLOCAR EN ROWS DE 3 COLUMNAS LAS CARACTERISTICAS EN PANTALLAS GRANDES ( MD Y LG )#}
{% for key,value in caracterisitcas %}
{% if is_divisible( loop.index -1 ,3) %}
</div>
<div class="row">
{% endif %}
<div class="container-checkbox col-md-4 col-lg-4 visible-md visible-lg">
<div class="form-group text-center">
<label class="switch" for="{{ key }}">
<input type="checkbox" class="data-profile" id="{{ key }}" rel="{{ key }}" {% if attribute(profile, key) %} checked {% endif %}/>
<div class="slider round"></div>
</label>
<p>{{ value }}</p>
</div>
</div>
{% endfor %}
{#FIN FOR LG / MG#}
{#FOR PARA COLOCAR EN ROWS DE 2 COLUMNAS LAS CARACTERISTICAS EN PANTALLAS PEQUEÑAS ( XS Y SM )#}
{% for key,value in caracterisitcas %}
{% if is_divisible( loop.index -1 ,2) %}
</div>
<div class="row">
{% endif %}
<div class="container-checkbox col-xs-6 col-sm-6 visible-xs visible-sm">
<div class="form-group text-center">
<label class="switch" for="{{ "movil_"~key }}">
<input type="checkbox" class="data-profile" id="{{ "movil_"~key }}" rel="{{ key }}" {% if attribute(profile, key) %} checked {% endif %}/>
<div class="slider round"></div>
</label>
<p>{{ value }}</p>
</div>
</div>
{% endfor %}
</div>
</div> </div>
\ No newline at end of file
$(document).ready(function() {
/**
* Guardamos perfil
*/
$('#save-profile').on('click',function () {
var inputs = {};
// Recorremos todos los inputs a guardar
$('.data-profile').map(function () {
if(typeof $(this).attr('rel') !== "undefined"){
// Si el input es de tipo checkout lo tratamos de forma diferente.
if($(this).attr('type') === "checkbox"){
// Exiten inputs ocultos (para movil) identicos a los visibles, con esto los diferenciamos.
if( $(this).closest('div.container-checkbox').css('display') !== 'none' ){
inputs[$(this).attr('rel')] = $(this).is(':checked') ? "1" : "0";
}
}else{
inputs[$(this).attr('rel')] = $(this).val()
}
}
});
$.ajax({
url: "perfil/update",
type: "POST",
method:"post",
data: {
id: $('#profile_id').val(),
inputs: inputs
},
success: function (data) {
if(data != "" && data != 0){
// Modal success
}else{
// Modal error
}
location.reload();
}
})
})
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment