ciyidogan commited on
Commit
7abe33d
·
verified ·
1 Parent(s): f4edbe7

Update static/js/project.js

Browse files
Files changed (1) hide show
  1. static/js/project.js +41 -9
static/js/project.js CHANGED
@@ -1,3 +1,5 @@
 
 
1
  function listProjects() {
2
  apiGet('/project/list')
3
  .then(data => {
@@ -96,7 +98,8 @@ function editIntent(name) {
96
  document.getElementById('intent-fallback').value = intent.fallback_error_message || '';
97
  document.getElementById('intent-prompt').value = intent.humanization_prompt || '';
98
  document.getElementById('intent-examples').value = (intent.examples || []).join(', ');
99
- document.getElementById('intent-parameters').value = JSON.stringify(intent.parameters || [], null, 2);
 
100
 
101
  $('#intentModal').modal('show');
102
  })
@@ -110,20 +113,13 @@ function saveIntent() {
110
  const fallback = document.getElementById('intent-fallback').value;
111
  const prompt = document.getElementById('intent-prompt').value;
112
  const examples = document.getElementById('intent-examples').value.split(',').map(e => e.trim());
113
- let parameters = [];
114
- try {
115
- parameters = JSON.parse(document.getElementById('intent-parameters').value);
116
- } catch (e) {
117
- alert('Invalid JSON in parameters.');
118
- return;
119
- }
120
 
121
  const intentData = {
122
  action: action,
123
  fallback_error_message: fallback,
124
  humanization_prompt: prompt,
125
  examples: examples,
126
- parameters: parameters
127
  };
128
 
129
  apiPost('/project/update_intent', {
@@ -149,3 +145,39 @@ function saveProject() {
149
  function publishProject() {
150
  alert('Publish logic will be implemented here.');
151
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ let currentParameters = [];
2
+
3
  function listProjects() {
4
  apiGet('/project/list')
5
  .then(data => {
 
98
  document.getElementById('intent-fallback').value = intent.fallback_error_message || '';
99
  document.getElementById('intent-prompt').value = intent.humanization_prompt || '';
100
  document.getElementById('intent-examples').value = (intent.examples || []).join(', ');
101
+ currentParameters = intent.parameters || [];
102
+ populateParameterTable(currentParameters);
103
 
104
  $('#intentModal').modal('show');
105
  })
 
113
  const fallback = document.getElementById('intent-fallback').value;
114
  const prompt = document.getElementById('intent-prompt').value;
115
  const examples = document.getElementById('intent-examples').value.split(',').map(e => e.trim());
 
 
 
 
 
 
 
116
 
117
  const intentData = {
118
  action: action,
119
  fallback_error_message: fallback,
120
  humanization_prompt: prompt,
121
  examples: examples,
122
+ parameters: currentParameters
123
  };
124
 
125
  apiPost('/project/update_intent', {
 
145
  function publishProject() {
146
  alert('Publish logic will be implemented here.');
147
  }
148
+
149
+ function populateParameterTable(parameters) {
150
+ const body = document.getElementById('parameter-body');
151
+ body.innerHTML = '';
152
+ parameters.forEach((param, index) => {
153
+ const row = document.createElement('tr');
154
+ row.innerHTML = `
155
+ <td><input type="text" class="form-control" value="${param.name || ''}" onchange="updateParam(${index}, 'name', this.value)"></td>
156
+ <td>
157
+ <select class="form-control" onchange="updateParam(${index}, 'type', this.value)">
158
+ <option value="string" ${param.type === 'string' ? 'selected' : ''}>string</option>
159
+ <option value="int" ${param.type === 'int' ? 'selected' : ''}>int</option>
160
+ <option value="float" ${param.type === 'float' ? 'selected' : ''}>float</option>
161
+ </select>
162
+ </td>
163
+ <td><input type="text" class="form-control" value="${param.regex || ''}" onchange="updateParam(${index}, 'regex', this.value)"></td>
164
+ <td><input type="text" class="form-control" value="${param.validation_message || ''}" onchange="updateParam(${index}, 'validation_message', this.value)"></td>
165
+ <td><button class="btn btn-sm btn-danger" onclick="removeParameterRow(${index})">Delete</button></td>
166
+ `;
167
+ body.appendChild(row);
168
+ });
169
+ }
170
+
171
+ function addParameterRow() {
172
+ currentParameters.push({ name: '', type: 'string', regex: '', validation_message: '' });
173
+ populateParameterTable(currentParameters);
174
+ }
175
+
176
+ function removeParameterRow(index) {
177
+ currentParameters.splice(index, 1);
178
+ populateParameterTable(currentParameters);
179
+ }
180
+
181
+ function updateParam(index, key, value) {
182
+ currentParameters[index][key] = value;
183
+ }