Pārlūkot izejas kodu

add pre exec option

Tuan Nguyen 1 gadu atpakaļ
vecāks
revīzija
a469b017b8
3 mainītis faili ar 90 papildinājumiem un 7 dzēšanām
  1. 22 3
      app.py
  2. 48 0
      static/style.css
  3. 20 4
      templates/index.html

+ 22 - 3
app.py

@@ -188,7 +188,7 @@ def restart():
 @app.route('/list_theta_rho_files', methods=['GET'])
 def list_theta_rho_files():
     files = os.listdir(THETA_RHO_DIR)
-    return jsonify(files)
+    return jsonify(sorted(files))
 
 @app.route('/upload_theta_rho', methods=['POST'])
 def upload_theta_rho():
@@ -201,6 +201,8 @@ def upload_theta_rho():
 @app.route('/run_theta_rho', methods=['POST'])
 def run_theta_rho():
     file_name = request.json.get('file_name')
+    pre_execution = request.json.get('pre_execution')  # New parameter for pre-execution action
+
     if not file_name:
         return jsonify({'error': 'No file name provided'}), 400
 
@@ -208,8 +210,25 @@ def run_theta_rho():
     if not os.path.exists(file_path):
         return jsonify({'error': 'File not found'}), 404
 
-    threading.Thread(target=run_theta_rho_file, args=(file_path,)).start()
-    return jsonify({'success': True})
+    try:
+        # Handle pre-execution actions
+        if pre_execution == 'clear_in':
+            clear_in_thread = threading.Thread(target=run_theta_rho_file, args=('./patterns/clear_from_in.thr',))
+            clear_in_thread.start()
+            clear_in_thread.join()  # Wait for completion before proceeding
+        elif pre_execution == 'clear_out':
+            clear_out_thread = threading.Thread(target=run_theta_rho_file, args=('./patterns/clear_from_out.thr',))
+            clear_out_thread.start()
+            clear_out_thread.join()  # Wait for completion before proceeding
+        elif pre_execution == 'none':
+            pass  # No pre-execution action required
+
+        # Start the main pattern execution
+        threading.Thread(target=run_theta_rho_file, args=(file_path,)).start()
+        return jsonify({'success': True})
+    except Exception as e:
+        return jsonify({'error': str(e)}), 500
+    
 
 @app.route('/stop_execution', methods=['POST'])
 def stop_execution():

+ 48 - 0
static/style.css

@@ -179,6 +179,54 @@ li.selected {
     box-shadow: 0 0 5px rgba(74, 144, 226, 0.5);
 }
 
+/* Radio Buttons and Labels */
+.pre-execution-toggles {
+    margin: 10px 0;
+    padding: 10px;
+    background: #fff;
+    border: 1px solid #ddd;
+    border-radius: 8px;
+    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
+}
+
+.pre-execution-toggles h3 {
+    margin: 0 0 10px 0;
+    color: #4A90E2;
+    font-size: 1.1em;
+}
+
+.pre-execution-toggles label {
+    display: flex;
+    align-items: center;
+    gap: 10px;
+    margin: 5px 0;
+    font-size: 1em;
+    color: #333;
+    cursor: pointer;
+    transition: all 0.3s ease;
+}
+
+.pre-execution-toggles label:hover {
+    color: #4A90E2;
+}
+
+input[type="radio"] {
+    appearance: none;
+    width: 16px;
+    height: 16px;
+    border: 2px solid #4A90E2;
+    border-radius: 50%;
+    outline: none;
+    cursor: pointer;
+    transition: all 0.3s ease;
+}
+
+input[type="radio"]:checked {
+    background-color: #4A90E2;
+    border-color: #4A90E2;
+    box-shadow: 0 0 3px rgba(74, 144, 226, 0.5);
+}
+
 /* Responsive Layout for Small Screens */
 @media (max-width: 768px) {
     .container {

+ 20 - 4
templates/index.html

@@ -54,11 +54,24 @@
                 <h2>Pattern Files</h2>
                 <input type="text" id="search_pattern" placeholder="Search files..." oninput="searchPatternFiles()">
                 <ul id="theta_rho_files"></ul>
+                <div class="pre-execution-toggles">
+                    <h3>Pre-Execution Action</h3>
+                    <label>
+                        <input type="radio" name="pre_execution" value="clear_in" id="clear_in"> Clear from In
+                    </label>
+                    <label>
+                        <input type="radio" name="pre_execution" value="clear_out" id="clear_out"> Clear from Out
+                    </label>
+                    <label>
+                        <input type="radio" name="pre_execution" value="none" id="no_action" checked> None
+                    </label>
+                </div>
                 <div class="button-group">
                     <button id="run_button" disabled>Run Selected File</button>
                     <button onclick="stopExecution()" class="delete-button">Stop</button>
                 </div>
             </div>
+            </div>
         </div>
     </div>
 
@@ -175,14 +188,17 @@
                 logMessage("No file selected to run.");
                 return;
             }
-
-            logMessage(`Running file: ${selectedFile}...`);
+        
+            // Get the selected pre-execution action
+            const preExecutionAction = document.querySelector('input[name="pre_execution"]:checked').value;
+        
+            logMessage(`Running file: ${selectedFile} with pre-execution action: ${preExecutionAction}...`);
             const response = await fetch('/run_theta_rho', {
                 method: 'POST',
                 headers: { 'Content-Type': 'application/json' },
-                body: JSON.stringify({ file_name: selectedFile })
+                body: JSON.stringify({ file_name: selectedFile, pre_execution: preExecutionAction })
             });
-
+        
             const result = await response.json();
             if (result.success) {
                 logMessage(`File running: ${selectedFile}`);