File size: 14,943 Bytes
e1551f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI Coach for Site Supervisors</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/heroicons/2.1.1/outline/index.min.css" rel="stylesheet">
    <style>
        body {
            font-family: 'Inter', sans-serif;
        }
        .checklist-item {
            transition: background-color 0.3s ease, transform 0.2s ease;
        }
        .checklist-item.completed {
            background-color: #ecfdf5;
            transform: scale(1.02);
        }
        .checklist-item:hover {
            transform: scale(1.02);
        }
        .tip-card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        .tip-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
        }
        .fade-in {
            animation: fadeIn 0.5s ease-in-out;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        .gradient-header {
            background: linear-gradient(135deg, #3b82f6, #1d4ed8);
        }
        .spinner {
            border: 4px solid #f3f3f3;
            border-top: 4px solid #3b82f6;
            border-radius: 50%;
            width: 24px;
            height: 24px;
            animation: spin 1s linear infinite;
            display: none;
        }
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    </style>
</head>
<body class="bg-gray-50 min-h-screen flex flex-col">
    <!-- Header -->
    <header class="gradient-header text-white p-6 shadow-lg">
        <h1 class="text-3xl font-bold tracking-tight flex items-center">
            <svg class="w-8 h-8 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
            </svg>
            AI Coach for Supervisors
        </h1>
        <p class="mt-1 text-sm opacity-80">Your daily guide to success</p>
    </header>

    <!-- Main Content -->
    <main class="flex-1 p-6 space-y-8 max-w-3xl mx-auto">
        <!-- Supervisor Input Form -->
        <section class="bg-white rounded-xl shadow-md p-6 fade-in">
            <h2 class="text-2xl font-semibold text-gray-800 mb-4 flex items-center">
                <svg class="w-6 h-6 mr-2 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"></path>
                </svg>
                Supervisor Details
            </h2>
            <div class="space-y-4">
                <div>
                    <label class="block text-gray-700 font-medium mb-1">Role</label>
                    <input id="role" type="text" value="Site Supervisor" class="w-full p-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-400 focus:border-transparent" placeholder="e.g., Site Supervisor">
                </div>
                <div>
                    <label class="block text-gray-700 font-medium mb-1">Location</label>
                    <input id="location" type="text" value="Construction Site A" class="w-full p-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-400 focus:border-transparent" placeholder="e.g., Construction Site A">
                </div>
                <div>
                    <label class="block text-gray-700 font-medium mb-1">Project Schedule (JSON)</label>
                    <textarea id="schedule" class="w-full p-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-400 focus:border-transparent" rows="3" placeholder='e.g., [{"task": "Foundation Inspection", "due_date": "2025-05-07", "status": "Pending"}]'>[{"task": "Foundation Inspection", "due_date": "2025-05-07", "status": "Pending"}, {"task": "Material Delivery", "due_date": "2025-05-06", "status": "Delayed"}]</textarea>
                </div>
                <button id="loadData" class="w-full bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 transition-colors duration-200 flex items-center justify-center">
                    <svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9H20m-7 7v5h-.582m-7.356-2A8.001 8.001 0 0119.418 15H4"></path>
                    </svg>
                    Load Coaching Data
                    <div id="spinner" class="spinner ml-2"></div>
                </button>
            </div>
        </section>

        <!-- Alerts (Placeholder) -->
        <section id="alerts" class="bg-red-50 rounded-xl shadow-md p-6 fade-in hidden">
            <h2 class="text-2xl font-semibold text-red-800 mb-4 flex items-center">
                <svg class="w-6 h-6 mr-2 text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                </svg>
                Alerts
            </h2>
            <p class="text-red-700">No alerts at this time. (Placeholder for missed milestones or unsafe patterns)</p>
        </section>

        <!-- Checklist -->
        <section id="checklistSection" class="bg-white rounded-xl shadow-md p-6 fade-in hidden">
            <h2 class="text-2xl font-semibold text-gray-800 mb-4 flex items-center">
                <svg class="w-6 h-6 mr-2 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                </svg>
                Daily Checklist
            </h2>
            <ul id="checklist" class="space-y-3"></ul>
        </section>

        <!-- Tips -->
        <section id="tipsSection" class="bg-white rounded-xl shadow-md p-6 fade-in hidden">
            <h2 class="text-2xl font-semibold text-gray-800 mb-4 flex items-center">
                <svg class="w-6 h-6 mr-2 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"></path>
                </svg>
                Today's Top 3 Focus Areas
            </h2>
            <ul id="tips" class="space-y-3"></ul>
        </section>

        <!-- Quote -->
        <section id="quoteSection" class="bg-white rounded-xl shadow-md p-6 fade-in hidden">
            <h2 class="text-2xl font-semibold text-gray-800 mb-4 flex items-center">
                <svg class="w-6 h-6 mr-2 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"></path>
                </svg>
                Motivational Quote
            </h2>
            <p id="quote" class="italic text-gray-600 text-lg"></p>
        </section>

        <!-- Reflection Journal -->
        <section class="bg-white rounded-xl shadow-md p-6 fade-in">
            <h2 class="text-2xl font-semibold text-gray-800 mb-4 flex items-center">
                <svg class="w-6 h-6 mr-2 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path>
                </svg>
                Reflection Journal
            </h2>
            <textarea id="reflection" class="w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-400 focus:border-transparent" rows="4" placeholder="Log your thoughts or observations..."></textarea>
            <button id="saveReflection" class="mt-3 w-full bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 transition-colors duration-200">Save Reflection</button>
        </section>

        <!-- Engagement Score -->
        <section class="bg-white rounded-xl shadow-md p-6 fade-in">
            <h2 class="text-2xl font-semibold text-gray-800 mb-4 flex items-center">
                <svg class="w-6 h-6 mr-2 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2V7a2 2 0 012-2h2a2 2 0 012 2v12a2 2 0 01-2 2h-2a2 2 0 01-2-2z"></path>
                </svg>
                Engagement Score
            </h2>
            <p class="text-gray-600 mb-3">Weekly trend (Placeholder)</p>
            <div class="h-40 bg-gray-100 rounded-lg flex items-center justify-center">
                <svg width="100%" height="100" class="max-w-full">
                    <polyline points="10,90 30,70 50,80 70,50 90,60 110,40 130,60" fill="none" stroke="#3b82f6" stroke-width="2"/>
                    <text x="10" y="20" fill="#4b5563" font-size="12">Engagement: 85%</text>
                    <line x1="10" y1="90" x2="130" y2="90" stroke="#d1d5db" stroke-width="1"/>
                    <line x1="10" y1="90" x2="10" y2="30" stroke="#d1d5db" stroke-width="1"/>
                </svg>
            </div>
        </section>

        <!-- PDF Download -->
        <section class="bg-white rounded-xl shadow-md p-6 fade-in">
            <h2 class="text-2xl font-semibold text-gray-800 mb-4 flex items-center">
                <svg class="w-6 h-6 mr-2 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path>
                </svg>
                Summary Report
            </h2>
            <button id="downloadPdf" class="w-full bg-green-600 text-white px-4 py-2 rounded-lg hover:bg-green-700 transition-colors duration-200">Download PDF Summary</button>
        </section>
    </main>

    <script>
        // Default supervisor data
        let supervisorData = {
            supervisor_id: "SUP123",
            role: "Site Supervisor",
            project_id: "PRJ456",
            milestones: [
                { task: "Foundation Inspection", due_date: "2025-05-07", status: "Pending" },
                { task: "Material Delivery", due_date: "2025-05-06", status: "Delayed" }
            ],
            reflection_log: "Noticed delays due to rain; team morale is low.",
            weather: "Rainy, 20°C"
        };

        async function fetchCoachingOutput() {
            const spinner = document.getElementById('spinner');
            spinner.style.display = 'block';
            try {
                const response = await fetch('/generate', {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify(supervisorData)
                });
                const result = await response.json();
                if (result.status === 'success') {
                    updateUI(result.output);
                } else {
                    alert('Error: ' + result.message);
                }
            } catch (error) {
                alert('Failed to fetch coaching output: ' + error.message);
            } finally {
                spinner.style.display = 'none';
            }
        }

        function updateUI(output) {
            // Show sections
            document.getElementById('checklistSection').classList.remove('hidden');
            document.getElementById('tipsSection').classList.remove('hidden');
            document.getElementById('quoteSection').classList.remove('hidden');

            // Checklist
            const checklist = document.getElementById('checklist');
            checklist.innerHTML = output.checklist.map(item => `
                <li class="checklist-item flex items-center p-3 bg-gray-50 rounded-lg">
                    <input type="checkbox" class="w-5 h-5 text-green-500 rounded focus:ring-green-400 mr-3" onchange="toggleCompletion(this)">
                    <span class="text-gray-700">${item}</span>
                </li>
            `).join('');

            // Tips
            const tips = document.getElementById('tips');
            tips.innerHTML = output.tips.map(tip => `
                <li class="tip-card p-4 bg-blue-50 rounded-lg text-gray-700">${tip}</li>
            `).join('');

            // Quote
            document.getElementById('quote').textContent = output.quote;
        }

        function toggleCompletion(checkbox) {
            const li = checkbox.parentElement;
            li.classList.toggle('completed', checkbox.checked);
        }

        document.getElementById('saveReflection').addEventListener('click', () => {
            const reflection = document.getElementById('reflection').value;
            if (reflection) {
                alert('Reflection saved: ' + reflection);
            } else {
                alert('Please enter a reflection');
            }
        });

        document.getElementById('downloadPdf').addEventListener('click', () => {
            alert('PDF download feature coming soon...');
        });

        document.getElementById('loadData').addEventListener('click', () => {
            const role = document.getElementById('role').value;
            const location = document.getElementById('location').value;
            const schedule = JSON.parse(document.getElementById('schedule').value || '[]');
            supervisorData.role = role;
            supervisorData.location = location;
            supervisorData.milestones = schedule;
            fetchCoachingOutput();
        });

        // Initial load (optional, can be triggered by button only)
        fetchCoachingOutput();
    </script>
</body>
</html>