[update] history search (front-end)
This commit is contained in:
parent
80e0fcc0c1
commit
e0f20cdd85
|
@ -234,7 +234,7 @@
|
||||||
$history_r = DatabaseDriver::getPDO()->prepare("SELECT id_history FROM history
|
$history_r = DatabaseDriver::getPDO()->prepare("SELECT id_history FROM history
|
||||||
WHERE id_user IN (SELECT id_user FROM user WHERE username LIKE '%$keyword%')
|
WHERE id_user IN (SELECT id_user FROM user WHERE username LIKE '%$keyword%')
|
||||||
or id_machine IN (SELECT id_machine FROM machine WHERE name LIKE '%$keyword%')
|
or id_machine IN (SELECT id_machine FROM machine WHERE name LIKE '%$keyword%')
|
||||||
ORDER BY id_history ASC;");
|
ORDER BY timestamp DESC;");
|
||||||
|
|
||||||
$history_r->execute();
|
$history_r->execute();
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<article class='inline-row' data-history='{{ entry.id_history }}'>
|
<article class='inline-row' id='{{ entry.id_history }}'>
|
||||||
|
|
||||||
<span data-machine='{{ entry.id_machine }}' class='title'><span>#{{ entry.machine_name }}</span></span>
|
<span data-machine='{{ entry.id_machine }}' class='title'><span>#{{ entry.machine_name }}</span></span>
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<span>
|
<span>
|
||||||
<button class='search'>Détails</button>
|
<button class='search' data-details='{{ entry.id_history }}'>Détails</button>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
</article>
|
</article>
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
// On referencie toutes les sections
|
||||||
|
var section = {
|
||||||
|
view: {
|
||||||
|
text: '#CONTAINER > section[data-sublink="view"] ',
|
||||||
|
element: document.querySelector('#CONTAINER > section[data-sublink="view"]'),
|
||||||
|
searchbar: document.querySelector('#CONTAINER > section[data-sublink="view"] > .searchbar')
|
||||||
|
},
|
||||||
|
|
||||||
|
details: {
|
||||||
|
text: '#CONTAINER > section[data-sublink="details"] ',
|
||||||
|
element: document.querySelector('#CONTAINER > section[data-sublink="details"]')
|
||||||
|
},
|
||||||
|
|
||||||
|
archive: {
|
||||||
|
text: '#CONTAINER > section[data-sublink="archive"] ',
|
||||||
|
element: document.querySelector('#CONTAINER > section[data-sublink="archive"]')
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* GESTION DE L'AFFICHAGE DES ENTREES
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if( section.view.element != null ){
|
||||||
|
|
||||||
|
/* (1) On recupere tous les liens */
|
||||||
|
section.view.link = {
|
||||||
|
details: document.querySelectorAll(section.view.text + 'button[data-details]')
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* (2) Gestion de la recherche instantannee */
|
||||||
|
section.view.searchbar.addEventListener('keyup', function(e){
|
||||||
|
|
||||||
|
var search = {
|
||||||
|
path: 'historyDefault/search',
|
||||||
|
keywords: section.view.searchbar.value
|
||||||
|
};
|
||||||
|
|
||||||
|
// On envoie la requete
|
||||||
|
api.send(search, function(result){
|
||||||
|
if( result.error == 0 ){ // si aucune erreur
|
||||||
|
|
||||||
|
// On enregistre tous les UID dans un tableau
|
||||||
|
var uid_list = [];
|
||||||
|
for( var i = 0 ; i < result.history.length ; i++ )
|
||||||
|
uid_list.push( parseInt(result.history[i].id_history) );
|
||||||
|
|
||||||
|
// On recupere la liste des elements correspondants aux logs
|
||||||
|
var history_list = document.querySelectorAll(section.view.text + '> article.inline-row[id]');
|
||||||
|
|
||||||
|
// Pour chaque log
|
||||||
|
for( var i = 0 ; i < history_list.length ; i++ ){
|
||||||
|
console.log(uid_list, history_list);
|
||||||
|
// Si doit etre visible
|
||||||
|
if( uid_list.indexOf(parseInt(history_list[i].id)) > -1 )
|
||||||
|
history_list[i].remClass('hidden');
|
||||||
|
// Si ne doit pas etre visible
|
||||||
|
else
|
||||||
|
history_list[i].addClass('hidden');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue