processData.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import {createFirstRow, createFirstRowOcc, createRow} from "./createTable.js"
  2. import {createPagination} from './pagination.js'
  3. import {createOccRow} from './createTable.js'
  4. import {createPage} from './createSingleContext.js'
  5. export let arrayResponse = [];
  6. export function processData(response){
  7. console.log(response);
  8. $("#loader").css("display", "none");
  9. if(response.length==0){
  10. alert('No results!')
  11. }
  12. else {
  13. arrayResponse = response;
  14. var keys = Object.keys(response[0]);
  15. createFirstRow(keys);
  16. var ll = response.length;
  17. for (var i=0; i<ll; i++) {
  18. let newRow = response[i];
  19. createRow(i, newRow);
  20. }
  21. }
  22. }
  23. export function processOccData(response){
  24. console.log(response);
  25. $("#loader").css("display", "none");
  26. if(response.length==0){
  27. alert('No results!')
  28. }
  29. else {
  30. arrayResponse = response;
  31. var keys = Object.keys(response[0]);
  32. createFirstRowOcc(keys);
  33. var ll = response.length;
  34. let pags = Math.floor(ll / 5);
  35. let extraP = ll % 5;
  36. if (extraP != 0) {
  37. pags = pags + 1;
  38. }
  39. let pp = 4;
  40. let ref = 1;
  41. createPagination(pags);
  42. for (var j=1; j<pags+1; j++) {
  43. var newDiv = document.createElement('div');
  44. newDiv.id = "pag_" + j;
  45. newDiv.className = "page";
  46. $("#result").append(newDiv)
  47. }
  48. for (var i=0; i<ll; i++) {
  49. if (i >= pp) {
  50. pp = pp + 5;
  51. ref = ref + 1;
  52. } else {
  53. pp = pp;
  54. }
  55. let newRow = response[i];
  56. createOccRow(i, newRow, ref);
  57. }
  58. }
  59. }
  60. export function processSingleContext(response){
  61. if(response.length==0){
  62. alert('No results!')
  63. }
  64. else {
  65. console.log(response);
  66. createPage(response[0]);
  67. }
  68. }