Change "Your Saved Exercises" by "Your Exercises"

Save in local storage all the data for be faster
This commit is contained in:
Mathieu Sanchez 2018-12-15 15:15:58 +09:00
parent 2a1c7da008
commit b10d2a1737
4 changed files with 90 additions and 41 deletions

View File

@ -3,8 +3,8 @@
namespace WebProjectFitness; namespace WebProjectFitness;
class Config { class Config {
const SITE_JS_VERSION = '1.00'; const SITE_JS_VERSION = '1.01';
const SITE_CSS_VERSION = '1.00'; const SITE_CSS_VERSION = '1.01';
const TITLE_HEADER = 'Fitness'; const TITLE_HEADER = 'Fitness';
const DESCRIPTION_HEADER = 'Site for find all the fitness exercise you need'; const DESCRIPTION_HEADER = 'Site for find all the fitness exercise you need';

View File

@ -6,15 +6,15 @@ use Exception;
use PDO; use PDO;
class BDD { class BDD {
// const SQL_SERVER = 'web3.pulseheberg.net'; // BDD Server const SQL_SERVER = 'web3.pulseheberg.net'; // BDD Server
// const SQL_LOGIN = 'why7n0_fitness'; // BDD Login const SQL_LOGIN = 'why7n0_fitness'; // BDD Login
// const SQL_PASSWORD = 'KpB728zu'; // BDD Password const SQL_PASSWORD = 'KpB728zu'; // BDD Password
// const SQL_DB = 'why7n0_fitness'; // BDD Name const SQL_DB = 'why7n0_fitness'; // BDD Name
const SQL_SERVER = 'localhost'; // BDD Server // const SQL_SERVER = 'localhost'; // BDD Server
const SQL_LOGIN = 'root'; // BDD Login // const SQL_LOGIN = 'root'; // BDD Login
const SQL_PASSWORD = ''; // BDD Password // const SQL_PASSWORD = ''; // BDD Password
const SQL_DB = 'fitness'; // BDD Name // const SQL_DB = 'fitness'; // BDD Name
private static $bdd; private static $bdd;

View File

@ -46,7 +46,7 @@
<ul id="user" class="dropdown-content"> <ul id="user" class="dropdown-content">
<li><a id="change-name">Change Your Name</a></li> <li><a id="change-name">Change Your Name</a></li>
<li class="divider"></li> <li class="divider"></li>
<li><a>Your Saved Exercises</a></li> <li><a>Your Exercises</a></li>
<li class="divider"></li> <li class="divider"></li>
<li><a>Your Training</a></li> <li><a>Your Training</a></li>
</ul> </ul>

View File

@ -122,7 +122,11 @@ let Point = ( function () {
// Click on a point not selected // Click on a point not selected
$( document ).on( "click", ".point:not(.selected)", ( elem ) => { $( document ).on( "click", ".point:not(.selected)", ( elem ) => {
let $elem = $( elem.target ); let $elem = $( elem.target );
let storageData = localStorage.getItem( "muscles" );
if ( storageData ) {
storageData = JSON.parse( storageData );
}
$( ".point" ).each( ( i, e ) => { $( ".point" ).each( ( i, e ) => {
let $e = $( e ); let $e = $( e );
@ -131,6 +135,19 @@ let Point = ( function () {
$elem.addClass( "selected" ); $elem.addClass( "selected" );
$( "#exercise-title" ).text( $elem.attr( "title" ) ); $( "#exercise-title" ).text( $elem.attr( "title" ) );
if ( storageData && storageData[ $elem.data( "name" ) ] ) {
let data = storageData[ $elem.data( "name" ) ];
let c = $( "#exercises-container" );
c.empty();
if ( data.length > 0 ) {
for ( let exercise of data ) {
c.append( `<div data-id="${ exercise.id }">${ exercise.title }</div>` );
}
} else {
c.append( "<div>Please select a muscle</div>" );
}
} else {
$.ajax( { $.ajax( {
url: "/api/muscles/get-list", url: "/api/muscles/get-list",
method: "POST", method: "POST",
@ -138,10 +155,16 @@ let Point = ( function () {
muscle: $elem.data( "name" ) muscle: $elem.data( "name" )
}, },
success: function ( data ) { success: function ( data ) {
data = JSON.parse( data );
if ( storageData === null ) {
storageData = {};
}
storageData[ $elem.data( "name" ) ] = data;
localStorage.setItem( "muscles", JSON.stringify( storageData ) );
let c = $( "#exercises-container" ); let c = $( "#exercises-container" );
data = JSON.parse( data );
localStorage.setItem( $elem.data( "name" ), data );
c.empty(); c.empty();
if ( data.length > 0 ) { if ( data.length > 0 ) {
for ( let exercise of data ) { for ( let exercise of data ) {
@ -152,6 +175,7 @@ let Point = ( function () {
} }
} }
} ); } );
}
} ); } );
// Click on a point selected // Click on a point selected
@ -167,8 +191,28 @@ let Point = ( function () {
// Click on an exercise // Click on an exercise
$( document ).on( "click", "#exercises-container div", ( elem ) => { $( document ).on( "click", "#exercises-container div", ( elem ) => {
let $elem = $( elem.target ); let $elem = $( elem.target );
let storageData = localStorage.getItem( "exercises" );
if ( storageData ) {
storageData = JSON.parse( storageData );
} else {
storageData = {};
}
if ( $elem.data( "id" ) ) { if ( $elem.data( "id" ) ) {
if ( storageData[ $elem.data( "id" ) ] ) {
let data = storageData[ $elem.data( "id" ) ];
let main = $( "#main-container" );
main.html( `
<h2>${ data.title }</h2>
<div class="center-align">
<iframe width="560" height="315" src="${ data.video.replace( "https://youtu.be/", "https://www.youtube.com/embed/" ) }" frameborder="0"
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen></iframe>
<div class="exercise-info-container blue-grey lighten-4 left-align">${ ( data.description ? data.description : "" ) }</div>
</div>
` );
} else {
$.ajax( { $.ajax( {
url: "/api/muscles/get-exercise", url: "/api/muscles/get-exercise",
method: "POST", method: "POST",
@ -177,6 +221,10 @@ let Point = ( function () {
}, },
success: function ( data ) { success: function ( data ) {
data = JSON.parse( data ); data = JSON.parse( data );
storageData[ $elem.data( "id" ) ] = data;
localStorage.setItem( "exercises", JSON.stringify( storageData ) );
let main = $( "#main-container" ); let main = $( "#main-container" );
main.html( ` main.html( `
@ -191,6 +239,7 @@ let Point = ( function () {
} }
} ); } );
} }
}
} ); } );
}; };