Change "Your Saved Exercises" by "Your Exercises"
Save in local storage all the data for be faster
This commit is contained in:
parent
2a1c7da008
commit
b10d2a1737
@ -3,8 +3,8 @@
|
||||
namespace WebProjectFitness;
|
||||
|
||||
class Config {
|
||||
const SITE_JS_VERSION = '1.00';
|
||||
const SITE_CSS_VERSION = '1.00';
|
||||
const SITE_JS_VERSION = '1.01';
|
||||
const SITE_CSS_VERSION = '1.01';
|
||||
|
||||
const TITLE_HEADER = 'Fitness';
|
||||
const DESCRIPTION_HEADER = 'Site for find all the fitness exercise you need';
|
||||
|
@ -6,15 +6,15 @@ use Exception;
|
||||
use PDO;
|
||||
|
||||
class BDD {
|
||||
// const SQL_SERVER = 'web3.pulseheberg.net'; // BDD Server
|
||||
// const SQL_LOGIN = 'why7n0_fitness'; // BDD Login
|
||||
// const SQL_PASSWORD = 'KpB728zu'; // BDD Password
|
||||
// const SQL_DB = 'why7n0_fitness'; // BDD Name
|
||||
const SQL_SERVER = 'web3.pulseheberg.net'; // BDD Server
|
||||
const SQL_LOGIN = 'why7n0_fitness'; // BDD Login
|
||||
const SQL_PASSWORD = 'KpB728zu'; // BDD Password
|
||||
const SQL_DB = 'why7n0_fitness'; // BDD Name
|
||||
|
||||
const SQL_SERVER = 'localhost'; // BDD Server
|
||||
const SQL_LOGIN = 'root'; // BDD Login
|
||||
const SQL_PASSWORD = ''; // BDD Password
|
||||
const SQL_DB = 'fitness'; // BDD Name
|
||||
// const SQL_SERVER = 'localhost'; // BDD Server
|
||||
// const SQL_LOGIN = 'root'; // BDD Login
|
||||
// const SQL_PASSWORD = ''; // BDD Password
|
||||
// const SQL_DB = 'fitness'; // BDD Name
|
||||
|
||||
private static $bdd;
|
||||
|
||||
|
@ -46,7 +46,7 @@
|
||||
<ul id="user" class="dropdown-content">
|
||||
<li><a id="change-name">Change Your Name</a></li>
|
||||
<li class="divider"></li>
|
||||
<li><a>Your Saved Exercises</a></li>
|
||||
<li><a>Your Exercises</a></li>
|
||||
<li class="divider"></li>
|
||||
<li><a>Your Training</a></li>
|
||||
</ul>
|
||||
|
@ -122,7 +122,11 @@ let Point = ( function () {
|
||||
// Click on a point not selected
|
||||
$( document ).on( "click", ".point:not(.selected)", ( elem ) => {
|
||||
let $elem = $( elem.target );
|
||||
let storageData = localStorage.getItem( "muscles" );
|
||||
|
||||
if ( storageData ) {
|
||||
storageData = JSON.parse( storageData );
|
||||
}
|
||||
$( ".point" ).each( ( i, e ) => {
|
||||
let $e = $( e );
|
||||
|
||||
@ -131,6 +135,19 @@ let Point = ( function () {
|
||||
|
||||
$elem.addClass( "selected" );
|
||||
$( "#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( {
|
||||
url: "/api/muscles/get-list",
|
||||
method: "POST",
|
||||
@ -138,10 +155,16 @@ let Point = ( function () {
|
||||
muscle: $elem.data( "name" )
|
||||
},
|
||||
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" );
|
||||
|
||||
data = JSON.parse( data );
|
||||
localStorage.setItem( $elem.data( "name" ), data );
|
||||
c.empty();
|
||||
if ( data.length > 0 ) {
|
||||
for ( let exercise of data ) {
|
||||
@ -152,6 +175,7 @@ let Point = ( function () {
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
} );
|
||||
|
||||
// Click on a point selected
|
||||
@ -167,8 +191,28 @@ let Point = ( function () {
|
||||
// Click on an exercise
|
||||
$( document ).on( "click", "#exercises-container div", ( elem ) => {
|
||||
let $elem = $( elem.target );
|
||||
let storageData = localStorage.getItem( "exercises" );
|
||||
|
||||
if ( storageData ) {
|
||||
storageData = JSON.parse( storageData );
|
||||
} else {
|
||||
storageData = {};
|
||||
}
|
||||
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( {
|
||||
url: "/api/muscles/get-exercise",
|
||||
method: "POST",
|
||||
@ -177,6 +221,10 @@ let Point = ( function () {
|
||||
},
|
||||
success: function ( data ) {
|
||||
data = JSON.parse( data );
|
||||
|
||||
storageData[ $elem.data( "id" ) ] = data;
|
||||
localStorage.setItem( "exercises", JSON.stringify( storageData ) );
|
||||
|
||||
let main = $( "#main-container" );
|
||||
|
||||
main.html( `
|
||||
@ -191,6 +239,7 @@ let Point = ( function () {
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
} );
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user