1import { Controller } from '@hotwired/stimulus'; 2import moment from 'moment'; 3 4/* stimulusFetch: 'lazy' */ 5export default class extends Controller { 6 static targets = ['categorie', 'categorieTout', 'etat', 'etatTout', 'dateTypeInput']; 7 static values = { 8 isArchive: Boolean, 9 stationSlug: String 10 } 11 12 allCategoryChecked() { 13 const categories = this.categorieTargets; 14 return categories.every(category => category.checked); 15 } 16 17 activeCategories() { 18 const checkAll = this.allCategoryChecked(); 19 const checkToutes = this.categorieToutTarget.checked; 20 const categories = this.categorieTargets; 21 22 categories.forEach(category => category.checked = checkToutes ? true : !checkAll); 23 this.reloadMarkers(); 24 } 25 26 activeCategorieToutes() { 27 const checkToutes = this.categorieToutTarget.checked; 28 const checkAll = this.allCategoryChecked(); 29 30 if (!checkAll && checkToutes) { 31 this.categorieToutTarget.checked = false; 32 } else if (checkAll && !checkToutes) { 33 this.categorieToutTarget.checked = true; 34 } 35 this.reloadMarkers(); 36 } 37 38 allStateChecked() { 39 const etats = this.etatTargets; 40 return etats.every(etat => etat.checked); 41 } 42 43 activeEtats() { 44 const checkAll = this.allStateChecked(); 45 const checkToutes = this.etatToutTarget.checked; 46 const etats = this.etatTargets; 47 48 etats.forEach(etat => etat.checked = checkToutes ? true : !checkAll); 49 this.reloadMarkers(); 50 } 51 52 activeEtatToutes() { 53 const checkToutes = this.etatToutTarget.checked; 54 const checkAll = this.allStateChecked(); 55 56 if (!checkAll && checkToutes) { 57 this.etatToutTarget.checked = false; 58 } else if (checkAll && !checkToutes) { 59 this.etatToutTarget.checked = true; 60 } 61 this.reloadMarkers(); 62 63 } 64 65 getTableauCategorie() { 66 return this.categorieTargets.filter(categorie => categorie.checked).map(categorie => categorie.getAttribute('code')); 67 } 68 69 getTableauEtat() { 70 return this.etatTargets.filter(etat => etat.checked).map(etat => etat.getAttribute('code')); 71 } 72 73 getTypeDateSelectionnee() { 74 const selectedDate = this.dateTypeInputTargets.find(date => date.checked); 75 return selectedDate.dataset.code !== undefined ? parseInt(selectedDate.dataset.code) : 0; 76 } 77 78 getDateFromTypeDate(typeDate) { 79 let date = undefined; 80 81 switch (typeDate) { 82 case 1: 83 date = moment(); 84 date.subtract(1, 'days'); // -1 day 85 break; 86 case 2: 87 date = moment(); 88 date.subtract(7, 'days'); // -1 week 89 break; 90 case 3: 91 date = moment(); 92 date.subtract(1, 'months'); // -1 month 93 break; 94 } 95 96 if (date !== undefined) { 97 return date.format('YYYY-MM-DD HH:mm:ss'); 98 } 99 100 return date; 101 } 102 103 reloadMarkers() { 104 const typeDate = this.getTypeDateSelectionnee(); 105 const categories = this.getTableauCategorie(); 106 const etats = this.getTableauEtat(); 107 const texteRecherche = document.getElementById('customSearch').value; 108 109 console.log(typeDate, categories, etats, texteRecherche); 110 111 this.refreshMap(typeDate, categories, etats); 112 this.refreshTab(this.stationSlugValue, this.isArchiveValue, typeDate, categories, etats, texteRecherche); 113 } 114 115 refreshMap(typeDate, categories, etats) { 116 const date = this.getDateFromTypeDate(typeDate); 117 const markers = map_container.overlays.markers; 118 119 for (const keyMarker in markers) { 120 if (markers.hasOwnProperty(keyMarker)) { 121 const marker = markers[keyMarker]; 122 123 marker.setVisible( 124 categories.includes(marker.categorie) && 125 etats.includes(marker.etat) && 126 (date === undefined || (marker.date >= date)) 127 ); 128 } 129 } 130 } 131 132 refreshTab(slug, archive, typeDate, categories, etats, texteRecherche) { 133 const url = Routing.generate('moncompte_signalement_index_tab', { 134 station_slug: slug, 135 archive: archive, 136 date: typeDate, 137 categories: JSON.stringify(categories), 138 etats: JSON.stringify(etats), 139 recherche: texteRecherche 140 }); 141 142 fetch(url) 143 .then(response => response.text()) 144 .then(html => { 145 document.getElementById('tab_1-1').innerHTML = html; 146 }) 147 .catch(error => { 148 document.getElementById('tab_1-1').innerHTML = 'Problème lors du rafraîchissement du tableau.'; 149 }); 150 } 151 152 153}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.