Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template id="artesanias.html">
  2. <ons-page id="artesanias">
  3. <ons-toolbar>
  4. <div class="left"><ons-back-button>Atrás</ons-back-button></div>
  5. <div class="center"></div>
  6. </ons-toolbar>
  7. <ons-pull-hook id="pull-hook" threshold-height="120px">
  8. <ons-icon id="pull-hook-icon" size="22px" class="pull-hook-content" icon="fa-arrow-down"></ons-icon>
  9. </ons-pull-hook>
  10. <ons-list id="artesania-list" src="">
  11. <ons-list-header>Artesanias</ons-list-header>
  12. </ons-list>
  13. <ons-list id="artesanos-list" src="">
  14. <ons-list-header>Artesanos</ons-list-header>
  15. </ons-list>
  16. <script>
  17. ons.getScriptPage().onInit = function () {
  18. this.querySelector('ons-toolbar div.center').textContent = this.data.title;
  19. //var File = this.data.title.toUpperCase() + '.json' ;
  20. var Esp = this.data.esp.split(', ');
  21. var artesanos_json = this.data.json;
  22. //Convertir en mayuscula primera letra del string.
  23. for(var i=0; i<Esp.length; i++) {
  24. Esp[i] = Esp[i].charAt(0).toUpperCase() + Esp[i].slice(1);
  25. };
  26. var pullHook = document.getElementById('pull-hook');
  27. var icon = document.getElementById('pull-hook-icon');
  28. pullHook.addEventListener('changestate', function (event) {
  29. switch (event.state) {
  30. case 'initial':
  31. icon.setAttribute('icon', 'fa-arrow-down');
  32. icon.removeAttribute('rotate');
  33. icon.removeAttribute('spin');
  34. break;
  35. case 'preaction':
  36. icon.setAttribute('icon', 'fa-arrow-down');
  37. icon.setAttribute('rotate', '180');
  38. icon.removeAttribute('spin');
  39. break;
  40. case 'action':
  41. icon.setAttribute('icon', 'fa-spinner');
  42. icon.removeAttribute('rotate');
  43. icon.setAttribute('spin', true);
  44. break;
  45. }
  46. });
  47. var getArtesania = function (num) {
  48. var Artesanos = ``,
  49. ArtesanosInfo = ``;
  50. //console.log('Filtrado de ',Esp[num])
  51. var results = [];
  52. var searchVal = "my Name";
  53. for (var i=0 ; i < artesanos_json.length ; i++)
  54. {
  55. if (artesanos_json[i].Especificaciones.includes(Esp[num])) {
  56. results.push(artesanos_json[i]);
  57. }
  58. }
  59. /*var arr1=artesanos_json.filter(function(item){
  60. return item.Nombre=="Ana";
  61. });*/
  62. for(var i=0; i<results.length; i++) {
  63. //if(Esp[num] in artesanos_json.) {}
  64. Artesanos+=`${results[i].Nombre}|`
  65. ArtesanosInfo+=`${results[i].Municipio}|${results[i]["Tel\u00e9fono 1"]}|${results[i]["E-mail"]}|${results[i].Especificaciones}&&`
  66. //`<a id='home.html'>${Artesania.artesano} | ${Artesania.municipio}</a> `
  67. }
  68. return {
  69. name: Esp[num],
  70. artesan: Artesanos,
  71. info: ArtesanosInfo
  72. };
  73. };
  74. var getData = function () {
  75. const data = [];
  76. for (var i = 0; i < Esp.length; i++) {
  77. data.push(getArtesania(i));
  78. }
  79. return data;
  80. };
  81. var createArtesania = function (Artesania) {
  82. //console.log('Devuelto elemento')
  83. var listaArt=``;
  84. var arts = Artesania.artesan.split('|');
  85. var artsInfo = Artesania.info.split('&&');
  86. for(var i=0; i<arts.length; i++) {
  87. var lot = artsInfo[i].split('|'),
  88. mun = lot[0],
  89. tel = lot[1],
  90. email = lot[2],
  91. esp = lot[3];
  92. listaArt += `<ons-item tappable onclick="myNavigator.pushPage('artesano.html', {data: {title:'${arts[i]}', mun: '${mun}', tel: '${tel}', email: '${email}', esp: '${esp}'}} )" ><div class="center">`+ arts[i] +`</div></ons-item><br>`;
  93. }
  94. return ons.createElement(`
  95. <ons-list-item expandable tappable>
  96. <div class="center" >${Artesania.name}</div>
  97. <div class="expandable-content">Artesanos que trabajan con ${Artesania.name}
  98. <ons-card>${listaArt}</ons-card></div>
  99. </ons-list-item>`
  100. );
  101. };
  102. var Artesanias = getData();
  103. for (Art of Artesanias) {
  104. var Artesania = createArtesania(Art);
  105. document.getElementById('artesania-list').appendChild(Artesania);
  106. };
  107. pullHook.onAction = function (done) {
  108. setTimeout(function() {
  109. document.getElementById('artesania-list').appendChild(createArtesania(getArtesania()));
  110. done();
  111. }, 400);
  112. }
  113. var createArtesano = function (Artesano) {
  114. return ons.createElement(`
  115. <ons-list-item expandable tappable>
  116. <div class="center" >${Artesano.Nombre}</div>
  117. <div class="expandable-content"> Municipio: ${Artesano.Municipio}<br>
  118. Tel\u00e9fono: ${Artesano["Tel\u00e9fono 1"]}<br>
  119. Correo Electr\u00f3nico: ${Artesano["E-mail"]}<br>
  120. Trabaja con: ${Artesano.Especificaciones}<br>
  121. </div>
  122. </ons-list-item>`
  123. );
  124. };
  125. //var Artesanias = getData();
  126. //artesanos_json
  127. for (Artesano of artesanos_json) {
  128. var cont = 0;
  129. var lista = document.getElementById('artesanos-list');
  130. //Recopilar datos no vacios.
  131. if (Artesano.Municipio.trim().length != 0) {
  132. cont ++;
  133. }
  134. if (Artesano["Tel\u00e9fono 1"].trim().length != 0) {
  135. cont ++;
  136. }
  137. if (Artesano["E-mail"].trim().length != 0) {
  138. cont ++;
  139. }
  140. if (Artesano.Especificaciones.trim().length != 0) {
  141. cont ++;
  142. }
  143. //info a pasar
  144. //'title':'${Artesano.Nombre}','esp': '${info}'
  145. var item = ons.createElement(`<ons-list-item onclick="myNavigator.pushPage('artesano.html', { data: { title: '${Artesano.Nombre}', mun: '${Artesano.Municipio}', tel: '${Artesano["Tel\u00e9fono 1"]}', email: '${Artesano["E-mail"]}', esp: '${Artesano.Especificaciones}' } })" tappable>
  146. <div class="title">${Artesano.Nombre}</div>
  147. </ons-list-item>`);
  148. if(cont == 0){
  149. console.log(Artesano.Nombre+' no tiene ningun tipo de informacion.');
  150. //return ons.createElement(``);
  151. }
  152. else {
  153. lista.appendChild(item);
  154. }
  155. };
  156. };
  157. </script>
  158. <style>
  159. .pull-hook-content {
  160. color: #333;
  161. transition: transform .25s ease-in-out;
  162. }
  163. </style>
  164. </ons-page>
  165. </template>