Subham9126 commited on
Commit
75a7b0e
·
verified ·
1 Parent(s): b2e62e9

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +21 -8
index.html CHANGED
@@ -77,20 +77,23 @@
77
  <script>
78
  $(document).ready(function() {
79
  let isResultShown = false;
 
 
80
  $('#submit').click(function() {
81
  const query = $('#query').val();
82
  const givenFacet = $('#given_facet').val();
83
  try {
84
- const facetObj = JSON.parse(givenFacet.replace(/'/g, '"'));
85
- generateBoxes(facetObj);
86
  resetResult();
87
  } catch (error) {
88
  alert('Invalid facet format. Please enter a valid JSON array of objects.');
89
  }
90
  });
 
91
  function generateBoxes(facetArray) {
92
  const $dynamicBoxes = $('#dynamicBoxes').empty();
93
- facetArray.forEach(facetObj => {
94
  const [key, values] = Object.entries(facetObj)[0];
95
  const $box = $('<div>').addClass('bg-white rounded-lg shadow-md p-6 fade-in');
96
  const $title = $('<div>').addClass('flex items-center justify-between mb-4')
@@ -98,6 +101,7 @@
98
  .append($('<input>').attr({
99
  type: 'checkbox',
100
  name: key,
 
101
  class: 'form-checkbox h-5 w-5 text-blue-600'
102
  }));
103
  const $content = $('<div>').addClass('space-y-2');
@@ -108,14 +112,22 @@
108
  $dynamicBoxes.append($box);
109
  });
110
  }
 
111
  $('#getList').click(function() {
112
- const checkedBoxes = $('input[type="checkbox"]:checked').map(function() {
113
- return `{'${this.name}': []}`;
114
- }).get();
115
- const result = `[${checkedBoxes.join(', ')}]`;
116
- $('#result').text(result).addClass('fade-in');
 
 
 
 
 
 
117
  isResultShown = true;
118
  });
 
119
  $('#reset').click(function() {
120
  $('input[type="checkbox"]').prop('checked', false);
121
  if (isResultShown) {
@@ -123,6 +135,7 @@
123
  isResultShown = false;
124
  }
125
  });
 
126
  function resetResult() {
127
  $('#result').text('').removeClass('fade-in');
128
  isResultShown = false;
 
77
  <script>
78
  $(document).ready(function() {
79
  let isResultShown = false;
80
+ let facetData = [];
81
+
82
  $('#submit').click(function() {
83
  const query = $('#query').val();
84
  const givenFacet = $('#given_facet').val();
85
  try {
86
+ facetData = JSON.parse(givenFacet.replace(/'/g, '"'));
87
+ generateBoxes(facetData);
88
  resetResult();
89
  } catch (error) {
90
  alert('Invalid facet format. Please enter a valid JSON array of objects.');
91
  }
92
  });
93
+
94
  function generateBoxes(facetArray) {
95
  const $dynamicBoxes = $('#dynamicBoxes').empty();
96
+ facetArray.forEach((facetObj, index) => {
97
  const [key, values] = Object.entries(facetObj)[0];
98
  const $box = $('<div>').addClass('bg-white rounded-lg shadow-md p-6 fade-in');
99
  const $title = $('<div>').addClass('flex items-center justify-between mb-4')
 
101
  .append($('<input>').attr({
102
  type: 'checkbox',
103
  name: key,
104
+ 'data-index': index,
105
  class: 'form-checkbox h-5 w-5 text-blue-600'
106
  }));
107
  const $content = $('<div>').addClass('space-y-2');
 
112
  $dynamicBoxes.append($box);
113
  });
114
  }
115
+
116
  $('#getList').click(function() {
117
+ const result = facetData.reduce((acc, facetObj) => {
118
+ const [key] = Object.keys(facetObj);
119
+ const $categoryCheckbox = $(`input[type="checkbox"][name="${key}"]`);
120
+ if ($categoryCheckbox.is(':checked')) {
121
+ acc.push(`'${key}'`);
122
+ }
123
+ return acc;
124
+ }, []);
125
+
126
+ const formattedResult = `[${result.join(', ')}]`;
127
+ $('#result').text(formattedResult).addClass('fade-in');
128
  isResultShown = true;
129
  });
130
+
131
  $('#reset').click(function() {
132
  $('input[type="checkbox"]').prop('checked', false);
133
  if (isResultShown) {
 
135
  isResultShown = false;
136
  }
137
  });
138
+
139
  function resetResult() {
140
  $('#result').text('').removeClass('fade-in');
141
  isResultShown = false;