File size: 7,880 Bytes
c31ff32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Data Collection App</title>
    <script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gradient-to-br from-blue-50 to-indigo-100 min-h-screen flex items-center justify-center p-4">
    <div class="bg-white rounded-lg shadow-2xl p-8 w-full max-w-md">
        <h1 class="text-3xl font-bold text-gray-800 mb-8 text-center">Data Collection</h1>
        
        <!-- Input Form -->
        <div id="formContainer" class="space-y-5 mb-8">
            <div>
                <label class="block text-sm font-semibold text-gray-700 mb-2">Human</label>
                <input 

                    type="text" 

                    id="person1" 

                    placeholder="Enter human name"

                    class="w-full px-4 py-2 border-2 border-gray-300 rounded-lg focus:outline-none focus:border-indigo-500 transition"

                >
            </div>
            
            <div>
                <label class="block text-sm font-semibold text-gray-700 mb-2">AI</label>
                <input 

                    type="text" 

                    id="person2" 

                    placeholder="Enter AI name"

                    class="w-full px-4 py-2 border-2 border-gray-300 rounded-lg focus:outline-none focus:border-indigo-500 transition"

                >
            </div>
            
            <button 

                onclick="addData()"

                class="w-full bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded-lg transition duration-200 ease-in-out transform hover:scale-105"

            >
                ADD
            </button>
        </div>
        
        <!-- Status Message -->
        <div id="statusMessage" class="mb-6 text-center"></div>
        
        <!-- Download Button -->
        <button 

            onclick="openPasswordModal()"

            class="w-full bg-green-600 hover:bg-green-700 text-white font-bold py-2 px-4 rounded-lg transition duration-200 ease-in-out transform hover:scale-105"

        >
            Download Data
        </button>
    </div>

    <!-- Password Modal -->
    <div id="passwordModal" class="hidden fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
        <div class="bg-white rounded-lg p-8 max-w-sm w-full mx-4 shadow-2xl">
            <h2 class="text-2xl font-bold text-gray-800 mb-6">Enter Password</h2>
            
            <input 

                type="password" 

                id="passwordInput" 

                placeholder="Enter password"

                class="w-full px-4 py-2 border-2 border-gray-300 rounded-lg focus:outline-none focus:border-indigo-500 transition mb-6"

            >
            
            <div id="passwordError" class="text-red-600 text-sm mb-4 text-center hidden"></div>
            
            <div class="flex gap-3">
                <button 

                    onclick="closePasswordModal()"

                    class="flex-1 bg-gray-400 hover:bg-gray-500 text-white font-bold py-2 px-4 rounded-lg transition"

                >
                    Cancel
                </button>
                <button 

                    onclick="verifyPassword()"

                    class="flex-1 bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded-lg transition"

                >
                    Submit
                </button>
            </div>
        </div>
    </div>

    <script>

        function addData() {

            const person1 = document.getElementById('person1').value;

            const person2 = document.getElementById('person2').value;

            const statusMsg = document.getElementById('statusMessage');

            

            if (!person1 || !person2) {

                showStatus('Please fill in both fields', 'error');

                return;

            }

            

            fetch('/add_data', {

                method: 'POST',

                headers: {

                    'Content-Type': 'application/json'

                },

                body: JSON.stringify({

                    person1: person1,

                    person2: person2

                })

            })

            .then(response => response.json())

            .then(data => {

                if (data.success) {

                    showStatus('✓ Data added successfully', 'success');

                    document.getElementById('person1').value = '';

                    document.getElementById('person2').value = '';

                    document.getElementById('person1').focus();

                } else {

                    showStatus('✗ ' + data.message, 'error');

                }

            })

            .catch(error => {

                showStatus('✗ Error: ' + error, 'error');

            });

        }

        

        function openPasswordModal() {

            document.getElementById('passwordModal').classList.remove('hidden');

            document.getElementById('passwordInput').value = '';

            document.getElementById('passwordError').classList.add('hidden');

            document.getElementById('passwordInput').focus();

        }

        

        function closePasswordModal() {

            document.getElementById('passwordModal').classList.add('hidden');

        }

        

        function verifyPassword() {

            const password = document.getElementById('passwordInput').value;

            const errorMsg = document.getElementById('passwordError');

            

            if (!password) {

                errorMsg.textContent = 'Please enter a password';

                errorMsg.classList.remove('hidden');

                return;

            }

            

            fetch('/verify_password', {

                method: 'POST',

                headers: {

                    'Content-Type': 'application/json'

                },

                body: JSON.stringify({

                    password: password

                })

            })

            .then(response => response.json())

            .then(data => {

                if (data.success) {

                    closePasswordModal();

                    window.location.href = '/download_csv';

                } else {

                    errorMsg.textContent = 'Incorrect password';

                    errorMsg.classList.remove('hidden');

                }

            })

            .catch(error => {

                errorMsg.textContent = 'Error: ' + error;

                errorMsg.classList.remove('hidden');

            });

        }

        

        function showStatus(message, type) {

            const statusMsg = document.getElementById('statusMessage');

            statusMsg.textContent = message;

            statusMsg.className = 'text-center font-semibold text-sm p-3 rounded-lg';

            

            if (type === 'success') {

                statusMsg.classList.add('bg-green-100', 'text-green-700');

            } else {

                statusMsg.classList.add('bg-red-100', 'text-red-700');

            }

            

            setTimeout(() => {

                statusMsg.textContent = '';

                statusMsg.className = 'text-center';

            }, 3000);

        }

        

        // Allow Enter key to submit

        document.getElementById('person2').addEventListener('keypress', function(e) {

            if (e.key === 'Enter') addData();

        });

        

        document.getElementById('passwordInput').addEventListener('keypress', function(e) {

            if (e.key === 'Enter') verifyPassword();

        });

    </script>
</body>
</html>