Spaces:
Sleeping
Sleeping
Commit
·
5c56bc9
1
Parent(s):
96ff01d
Professional UI redesign + Itinerary Template + SharePoint integration
Browse files- app/main.py +109 -0
- app/sharepoint.py +158 -0
- app/static/index.html +825 -134
- requirements.txt +2 -0
app/main.py
CHANGED
|
@@ -289,6 +289,115 @@ async def root():
|
|
| 289 |
return RedirectResponse(url="/app", status_code=302)
|
| 290 |
|
| 291 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
|
| 293 |
@app.get("/templates", response_model=List[TemplateSummary], tags=["Templates"])
|
| 294 |
async def get_templates():
|
|
|
|
| 289 |
return RedirectResponse(url="/app", status_code=302)
|
| 290 |
|
| 291 |
|
| 292 |
+
# ==================== SHAREPOINT ENDPOINTS ====================
|
| 293 |
+
|
| 294 |
+
from app.sharepoint import SharePointConnector
|
| 295 |
+
|
| 296 |
+
sharepoint = SharePointConnector()
|
| 297 |
+
|
| 298 |
+
@app.get("/auth/sharepoint/login", tags=["SharePoint"])
|
| 299 |
+
async def sharepoint_login(request: Request):
|
| 300 |
+
"""Start SharePoint OAuth flow."""
|
| 301 |
+
redirect_uri = str(request.url_for('sharepoint_callback')).replace('http:', 'https:') if 'huggingface.co' in str(request.base_url) else str(request.url_for('sharepoint_callback'))
|
| 302 |
+
|
| 303 |
+
# Fix for localhost/dev
|
| 304 |
+
if "localhost" in str(request.base_url) or "127.0.0.1" in str(request.base_url):
|
| 305 |
+
redirect_uri = "http://localhost:8001/auth/sharepoint/callback"
|
| 306 |
+
|
| 307 |
+
auth_url = sharepoint.get_auth_url(redirect_uri)
|
| 308 |
+
return {"auth_url": auth_url}
|
| 309 |
+
|
| 310 |
+
@app.get("/auth/sharepoint/callback", tags=["SharePoint"])
|
| 311 |
+
async def sharepoint_callback(code: str, request: Request):
|
| 312 |
+
"""Handle OAuth callback."""
|
| 313 |
+
# Reconstruct redirect_uri logic
|
| 314 |
+
redirect_uri = str(request.url_for('sharepoint_callback')).replace('http:', 'https:') if 'huggingface.co' in str(request.base_url) else str(request.url_for('sharepoint_callback'))
|
| 315 |
+
if "localhost" in str(request.base_url) or "127.0.0.1" in str(request.base_url):
|
| 316 |
+
redirect_uri = "http://localhost:8001/auth/sharepoint/callback"
|
| 317 |
+
|
| 318 |
+
try:
|
| 319 |
+
# Get token
|
| 320 |
+
result = sharepoint.acquire_token_by_code(code, redirect_uri)
|
| 321 |
+
access_token = result.get("access_token")
|
| 322 |
+
|
| 323 |
+
# Return simple HTML that saves token to localStorage and closes window
|
| 324 |
+
html_content = f"""
|
| 325 |
+
<html>
|
| 326 |
+
<body>
|
| 327 |
+
<h1>Authentication Successful!</h1>
|
| 328 |
+
<p>You can close this window now.</p>
|
| 329 |
+
<script>
|
| 330 |
+
// Send token back to parent window if opened as popup
|
| 331 |
+
if (window.opener) {{
|
| 332 |
+
window.opener.postMessage({{ type: 'SHAREPOINT_AUTH', token: '{access_token}' }}, '*');
|
| 333 |
+
window.close();
|
| 334 |
+
}} else {{
|
| 335 |
+
// Fallback if not a popup
|
| 336 |
+
localStorage.setItem('sharepoint_token', '{access_token}');
|
| 337 |
+
window.location.href = '/app';
|
| 338 |
+
}}
|
| 339 |
+
</script>
|
| 340 |
+
</body>
|
| 341 |
+
</html>
|
| 342 |
+
"""
|
| 343 |
+
return HTMLResponse(content=html_content)
|
| 344 |
+
except Exception as e:
|
| 345 |
+
return HTMLResponse(content=f"<h1>Authentication Failed</h1><p>{str(e)}</p>", status_code=400)
|
| 346 |
+
|
| 347 |
+
@app.get("/sharepoint/drives", tags=["SharePoint"])
|
| 348 |
+
async def list_drives(token: str = Query(..., description="SharePoint Access Token")):
|
| 349 |
+
"""List available drives (OneDrive + SharePoint sites)."""
|
| 350 |
+
try:
|
| 351 |
+
drives = sharepoint.get_drives(token)
|
| 352 |
+
return drives
|
| 353 |
+
except Exception as e:
|
| 354 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 355 |
+
|
| 356 |
+
@app.get("/sharepoint/items", tags=["SharePoint"])
|
| 357 |
+
async def list_items(
|
| 358 |
+
drive_id: str,
|
| 359 |
+
folder_id: Optional[str] = None,
|
| 360 |
+
token: str = Query(..., description="SharePoint Access Token")
|
| 361 |
+
):
|
| 362 |
+
"""List items in a specific drive/folder."""
|
| 363 |
+
try:
|
| 364 |
+
items = sharepoint.list_items(token, drive_id, folder_id)
|
| 365 |
+
return items
|
| 366 |
+
except Exception as e:
|
| 367 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 368 |
+
|
| 369 |
+
class SharePointDownload(BaseModel):
|
| 370 |
+
drive_id: str
|
| 371 |
+
file_ids: List[str]
|
| 372 |
+
token: str
|
| 373 |
+
project_id: Optional[int] = None
|
| 374 |
+
|
| 375 |
+
@app.post("/sharepoint/download-and-validate", tags=["SharePoint"])
|
| 376 |
+
async def download_and_validate(data: SharePointDownload):
|
| 377 |
+
"""Download files from SharePoint and validate them."""
|
| 378 |
+
try:
|
| 379 |
+
results = []
|
| 380 |
+
|
| 381 |
+
for file_id in data.file_ids:
|
| 382 |
+
# Download file content
|
| 383 |
+
content = sharepoint.download_file(data.token, data.drive_id, file_id)
|
| 384 |
+
|
| 385 |
+
# Since we don't know the exact filename easily here without relisting or passing it,
|
| 386 |
+
# we might need to assume or fetch metadata.
|
| 387 |
+
# For simplicity, let's assume specific operations or just return success for now.
|
| 388 |
+
# Ideally, we should integrate this with validator.
|
| 389 |
+
|
| 390 |
+
# TODO: Integrate with existing validator logic
|
| 391 |
+
# This requires converting bytes to UploadFile-like object or modifying validator to accept bytes
|
| 392 |
+
|
| 393 |
+
pass
|
| 394 |
+
|
| 395 |
+
return {"features": "Download validated (stub)"}
|
| 396 |
+
|
| 397 |
+
except Exception as e:
|
| 398 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 399 |
+
|
| 400 |
+
|
| 401 |
|
| 402 |
@app.get("/templates", response_model=List[TemplateSummary], tags=["Templates"])
|
| 403 |
async def get_templates():
|
app/sharepoint.py
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
SharePoint/OneDrive Connector for Medical Document Validator.
|
| 3 |
+
Handles Microsoft Graph API authentication and file operations.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
import logging
|
| 8 |
+
import msal
|
| 9 |
+
import requests
|
| 10 |
+
from typing import List, Dict, Optional, Any
|
| 11 |
+
|
| 12 |
+
logger = logging.getLogger(__name__)
|
| 13 |
+
|
| 14 |
+
class SharePointConnector:
|
| 15 |
+
"""Handles connection to Microsoft SharePoint/OneDrive via Graph API."""
|
| 16 |
+
|
| 17 |
+
def __init__(self):
|
| 18 |
+
self.client_id = os.environ.get("AZURE_CLIENT_ID")
|
| 19 |
+
self.tenant_id = os.environ.get("AZURE_TENANT_ID")
|
| 20 |
+
self.client_secret = os.environ.get("AZURE_CLIENT_SECRET")
|
| 21 |
+
self.authority = f"https://login.microsoftonline.com/{self.tenant_id}"
|
| 22 |
+
|
| 23 |
+
# Scopes required for the app
|
| 24 |
+
self.scopes = ["Files.Read.All", "Sites.Read.All", "User.Read"]
|
| 25 |
+
|
| 26 |
+
# Initialize MSAL Client Application
|
| 27 |
+
if self.client_id and self.tenant_id and self.client_secret:
|
| 28 |
+
self.app = msal.ConfidentialClientApplication(
|
| 29 |
+
self.client_id,
|
| 30 |
+
authority=self.authority,
|
| 31 |
+
client_credential=self.client_secret
|
| 32 |
+
)
|
| 33 |
+
else:
|
| 34 |
+
self.app = None
|
| 35 |
+
logger.warning("Azure credentials not fully configured. SharePoint integration disabled.")
|
| 36 |
+
|
| 37 |
+
def get_auth_url(self, redirect_uri: str, state: str = None) -> str:
|
| 38 |
+
"""Generate the login URL for the user."""
|
| 39 |
+
if not self.app:
|
| 40 |
+
return "#"
|
| 41 |
+
|
| 42 |
+
auth_url = self.app.get_authorization_request_url(
|
| 43 |
+
self.scopes,
|
| 44 |
+
redirect_uri=redirect_uri,
|
| 45 |
+
state=state
|
| 46 |
+
)
|
| 47 |
+
return auth_url
|
| 48 |
+
|
| 49 |
+
def acquire_token_by_code(self, code: str, redirect_uri: str) -> Dict[str, Any]:
|
| 50 |
+
"""Exchange auth code for access token."""
|
| 51 |
+
if not self.app:
|
| 52 |
+
raise ValueError("SharePoint connector not configured")
|
| 53 |
+
|
| 54 |
+
result = self.app.acquire_token_by_authorization_code(
|
| 55 |
+
code,
|
| 56 |
+
scopes=self.scopes,
|
| 57 |
+
redirect_uri=redirect_uri
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
if "error" in result:
|
| 61 |
+
logger.error(f"Failed to acquire token: {result.get('error_description')}")
|
| 62 |
+
raise Exception(result.get("error_description"))
|
| 63 |
+
|
| 64 |
+
return result
|
| 65 |
+
|
| 66 |
+
def get_drives(self, access_token: str) -> List[Dict[str, Any]]:
|
| 67 |
+
"""List available drives (document libraries)."""
|
| 68 |
+
headers = {'Authorization': f'Bearer {access_token}'}
|
| 69 |
+
|
| 70 |
+
# Get user's OneDrive
|
| 71 |
+
onedrive_url = "https://graph.microsoft.com/v1.0/me/drive"
|
| 72 |
+
drives = []
|
| 73 |
+
|
| 74 |
+
try:
|
| 75 |
+
# Try to get personal drive
|
| 76 |
+
resp = requests.get(onedrive_url, headers=headers)
|
| 77 |
+
if resp.status_code == 200:
|
| 78 |
+
data = resp.json()
|
| 79 |
+
drives.append({
|
| 80 |
+
"id": data.get("id"),
|
| 81 |
+
"name": "My OneDrive",
|
| 82 |
+
"type": "personal"
|
| 83 |
+
})
|
| 84 |
+
except Exception as e:
|
| 85 |
+
logger.error(f"Error fetching OneDrive: {e}")
|
| 86 |
+
|
| 87 |
+
# Get shared libraries (SharePoint sites)
|
| 88 |
+
sites_url = "https://graph.microsoft.com/v1.0/sites?search=*"
|
| 89 |
+
try:
|
| 90 |
+
resp = requests.get(sites_url, headers=headers)
|
| 91 |
+
if resp.status_code == 200:
|
| 92 |
+
sites = resp.json().get('value', [])
|
| 93 |
+
for site in sites:
|
| 94 |
+
# Get drives for this site
|
| 95 |
+
site_id = site.get('id')
|
| 96 |
+
drives_url = f"https://graph.microsoft.com/v1.0/sites/{site_id}/drives"
|
| 97 |
+
d_resp = requests.get(drives_url, headers=headers)
|
| 98 |
+
if d_resp.status_code == 200:
|
| 99 |
+
site_drives = d_resp.json().get('value', [])
|
| 100 |
+
for drive in site_drives:
|
| 101 |
+
drives.append({
|
| 102 |
+
"id": drive.get("id"),
|
| 103 |
+
"name": f"{site.get('name', 'Site')} - {drive.get('name', 'Documents')}",
|
| 104 |
+
"type": "sharepoint"
|
| 105 |
+
})
|
| 106 |
+
except Exception as e:
|
| 107 |
+
logger.error(f"Error fetching SharePoint sites: {e}")
|
| 108 |
+
|
| 109 |
+
return drives
|
| 110 |
+
|
| 111 |
+
def list_items(self, access_token: str, drive_id: str, folder_id: str = None) -> List[Dict[str, Any]]:
|
| 112 |
+
"""List items in a drive folder."""
|
| 113 |
+
headers = {'Authorization': f'Bearer {access_token}'}
|
| 114 |
+
|
| 115 |
+
if folder_id:
|
| 116 |
+
url = f"https://graph.microsoft.com/v1.0/drives/{drive_id}/items/{folder_id}/children"
|
| 117 |
+
else:
|
| 118 |
+
url = f"https://graph.microsoft.com/v1.0/drives/{drive_id}/root/children"
|
| 119 |
+
|
| 120 |
+
resp = requests.get(url, headers=headers)
|
| 121 |
+
if resp.status_code != 200:
|
| 122 |
+
logger.error(f"Failed to list items: {resp.text}")
|
| 123 |
+
raise Exception("Failed to list folder contents")
|
| 124 |
+
|
| 125 |
+
items = resp.json().get('value', [])
|
| 126 |
+
|
| 127 |
+
# Filter for files and folders
|
| 128 |
+
result = []
|
| 129 |
+
for item in items:
|
| 130 |
+
entry = {
|
| 131 |
+
"id": item.get("id"),
|
| 132 |
+
"name": item.get("name"),
|
| 133 |
+
"webUrl": item.get("webUrl"),
|
| 134 |
+
"lastModified": item.get("lastModifiedDateTime"),
|
| 135 |
+
"size": item.get("size")
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
if "folder" in item:
|
| 139 |
+
entry["type"] = "folder"
|
| 140 |
+
entry["childCount"] = item["folder"].get("childCount")
|
| 141 |
+
elif "file" in item:
|
| 142 |
+
entry["type"] = "file"
|
| 143 |
+
entry["mimeType"] = item["file"].get("mimeType")
|
| 144 |
+
|
| 145 |
+
result.append(entry)
|
| 146 |
+
|
| 147 |
+
return result
|
| 148 |
+
|
| 149 |
+
def download_file(self, access_token: str, drive_id: str, file_id: str) -> bytes:
|
| 150 |
+
"""Download a file content."""
|
| 151 |
+
headers = {'Authorization': f'Bearer {access_token}'}
|
| 152 |
+
url = f"https://graph.microsoft.com/v1.0/drives/{drive_id}/items/{file_id}/content"
|
| 153 |
+
|
| 154 |
+
resp = requests.get(url, headers=headers)
|
| 155 |
+
if resp.status_code != 200:
|
| 156 |
+
raise Exception("Failed to download file")
|
| 157 |
+
|
| 158 |
+
return resp.content
|
app/static/index.html
CHANGED
|
@@ -5,7 +5,37 @@
|
|
| 5 |
<meta charset="UTF-8">
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 7 |
<title>Medical Document Validator</title>
|
|
|
|
|
|
|
|
|
|
| 8 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
* {
|
| 10 |
margin: 0;
|
| 11 |
padding: 0;
|
|
@@ -13,109 +43,320 @@
|
|
| 13 |
}
|
| 14 |
|
| 15 |
body {
|
| 16 |
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
|
| 17 |
-
background:
|
| 18 |
min-height: 100vh;
|
| 19 |
-
|
|
|
|
| 20 |
}
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
background:
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
}
|
| 30 |
|
| 31 |
-
|
| 32 |
-
color:
|
| 33 |
-
|
| 34 |
-
font-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
}
|
| 36 |
|
| 37 |
-
.
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
font-size: 16px;
|
| 41 |
}
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
.form-group {
|
| 44 |
-
margin-bottom:
|
| 45 |
}
|
| 46 |
|
| 47 |
label {
|
| 48 |
display: block;
|
| 49 |
margin-bottom: 8px;
|
| 50 |
-
color:
|
| 51 |
-
font-weight:
|
| 52 |
font-size: 14px;
|
| 53 |
}
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
select,
|
| 56 |
-
input[type="
|
|
|
|
|
|
|
| 57 |
width: 100%;
|
| 58 |
-
padding: 12px;
|
| 59 |
-
border: 2px solid
|
| 60 |
-
border-radius:
|
| 61 |
-
font-size:
|
| 62 |
-
|
|
|
|
|
|
|
| 63 |
}
|
| 64 |
|
| 65 |
select:focus,
|
| 66 |
-
input[type="
|
|
|
|
| 67 |
outline: none;
|
| 68 |
-
border-color:
|
|
|
|
| 69 |
}
|
| 70 |
|
| 71 |
select {
|
| 72 |
-
background: white;
|
| 73 |
cursor: pointer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
}
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
}
|
| 79 |
|
| 80 |
.file-info {
|
| 81 |
-
margin-top:
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
font-size: 14px;
|
| 84 |
}
|
| 85 |
|
|
|
|
| 86 |
.btn {
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
|
|
|
| 93 |
font-weight: 600;
|
| 94 |
cursor: pointer;
|
| 95 |
-
|
| 96 |
-
|
|
|
|
| 97 |
}
|
| 98 |
|
| 99 |
-
.btn
|
| 100 |
-
|
| 101 |
-
|
| 102 |
}
|
| 103 |
|
| 104 |
-
.btn:
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
}
|
| 107 |
|
| 108 |
.btn:disabled {
|
| 109 |
-
|
| 110 |
cursor: not-allowed;
|
| 111 |
-
transform: none;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
}
|
| 113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
.loading {
|
| 115 |
display: none;
|
| 116 |
text-align: center;
|
| 117 |
-
|
| 118 |
-
color: #667eea;
|
| 119 |
}
|
| 120 |
|
| 121 |
.spinner {
|
|
@@ -504,25 +745,142 @@
|
|
| 504 |
</head>
|
| 505 |
|
| 506 |
<body>
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 510 |
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 518 |
<option value="">No Project (Not Saved)</option>
|
| 519 |
</select>
|
| 520 |
-
<button type="button" class="btn-secondary" id="createProjectBtn"
|
| 521 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 522 |
</button>
|
| 523 |
-
|
| 524 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 526 |
</div>
|
| 527 |
</div>
|
| 528 |
|
|
@@ -549,40 +907,67 @@
|
|
| 549 |
</div>
|
| 550 |
</div>
|
| 551 |
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
<
|
| 557 |
-
<option value="">Loading templates...</option>
|
| 558 |
-
</select>
|
| 559 |
</div>
|
| 560 |
|
| 561 |
-
<
|
| 562 |
-
<
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
|
|
|
|
|
|
|
|
|
| 566 |
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 574 |
</div>
|
| 575 |
-
</div>
|
| 576 |
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 586 |
|
| 587 |
<div class="debug-section">
|
| 588 |
<h3 style="margin-bottom: 10px; font-size: 18px;">🔍 Debug: Image Extraction</h3>
|
|
@@ -661,38 +1046,38 @@
|
|
| 661 |
<button type="button" class="btn" id="bulkValidateBtn" style="width: 100%;" disabled>
|
| 662 |
✅ Validate All Certificates
|
| 663 |
</button>
|
| 664 |
-
|
| 665 |
-
|
| 666 |
-
|
| 667 |
-
|
| 668 |
-
|
| 669 |
-
|
| 670 |
-
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
|
| 689 |
-
|
| 690 |
-
|
| 691 |
-
|
| 692 |
-
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
</
|
| 696 |
|
| 697 |
<script>
|
| 698 |
// Load templates on page load
|
|
@@ -717,17 +1102,45 @@
|
|
| 717 |
}
|
| 718 |
}
|
| 719 |
|
| 720 |
-
// Handle file input change
|
| 721 |
-
document.getElementById('
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 728 |
}
|
| 729 |
});
|
| 730 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 731 |
// Handle character count for custom prompt
|
| 732 |
document.getElementById('customPrompt').addEventListener('input', function () {
|
| 733 |
const count = this.value.length;
|
|
@@ -1555,6 +1968,284 @@
|
|
| 1555 |
alert('Projects view coming soon! For now, use the dropdown to select projects.');
|
| 1556 |
});
|
| 1557 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1558 |
// Load templates when page loads
|
| 1559 |
loadProjects();
|
| 1560 |
loadTemplates();
|
|
|
|
| 5 |
<meta charset="UTF-8">
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 7 |
<title>Medical Document Validator</title>
|
| 8 |
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
| 9 |
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 10 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
| 11 |
<style>
|
| 12 |
+
:root {
|
| 13 |
+
--primary: #1E3A5F;
|
| 14 |
+
--primary-light: #2D5A8A;
|
| 15 |
+
--accent: #00A878;
|
| 16 |
+
--accent-hover: #008F66;
|
| 17 |
+
--bg-main: #F0F4F8;
|
| 18 |
+
--bg-card: #FFFFFF;
|
| 19 |
+
--bg-sidebar: #1E3A5F;
|
| 20 |
+
--text-primary: #1F2937;
|
| 21 |
+
--text-secondary: #6B7280;
|
| 22 |
+
--text-muted: #9CA3AF;
|
| 23 |
+
--border: #E5E7EB;
|
| 24 |
+
--border-focus: #00A878;
|
| 25 |
+
--success: #10B981;
|
| 26 |
+
--success-bg: #D1FAE5;
|
| 27 |
+
--warning: #F59E0B;
|
| 28 |
+
--warning-bg: #FEF3C7;
|
| 29 |
+
--error: #EF4444;
|
| 30 |
+
--error-bg: #FEE2E2;
|
| 31 |
+
--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
|
| 32 |
+
--shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
| 33 |
+
--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
|
| 34 |
+
--radius-sm: 6px;
|
| 35 |
+
--radius-md: 10px;
|
| 36 |
+
--radius-lg: 16px;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
* {
|
| 40 |
margin: 0;
|
| 41 |
padding: 0;
|
|
|
|
| 43 |
}
|
| 44 |
|
| 45 |
body {
|
| 46 |
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
| 47 |
+
background: var(--bg-main);
|
| 48 |
min-height: 100vh;
|
| 49 |
+
color: var(--text-primary);
|
| 50 |
+
display: flex;
|
| 51 |
}
|
| 52 |
|
| 53 |
+
/* Sidebar Navigation */
|
| 54 |
+
.sidebar {
|
| 55 |
+
width: 260px;
|
| 56 |
+
background: var(--bg-sidebar);
|
| 57 |
+
min-height: 100vh;
|
| 58 |
+
padding: 24px 16px;
|
| 59 |
+
position: fixed;
|
| 60 |
+
left: 0;
|
| 61 |
+
top: 0;
|
| 62 |
+
display: flex;
|
| 63 |
+
flex-direction: column;
|
| 64 |
}
|
| 65 |
|
| 66 |
+
.sidebar-logo {
|
| 67 |
+
color: white;
|
| 68 |
+
font-size: 20px;
|
| 69 |
+
font-weight: 700;
|
| 70 |
+
padding: 12px 16px;
|
| 71 |
+
margin-bottom: 32px;
|
| 72 |
+
display: flex;
|
| 73 |
+
align-items: center;
|
| 74 |
+
gap: 12px;
|
| 75 |
}
|
| 76 |
|
| 77 |
+
.sidebar-logo svg {
|
| 78 |
+
width: 32px;
|
| 79 |
+
height: 32px;
|
|
|
|
| 80 |
}
|
| 81 |
|
| 82 |
+
.sidebar-nav {
|
| 83 |
+
flex: 1;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
.nav-item {
|
| 87 |
+
display: flex;
|
| 88 |
+
align-items: center;
|
| 89 |
+
gap: 12px;
|
| 90 |
+
padding: 12px 16px;
|
| 91 |
+
color: rgba(255, 255, 255, 0.7);
|
| 92 |
+
text-decoration: none;
|
| 93 |
+
border-radius: var(--radius-md);
|
| 94 |
+
margin-bottom: 4px;
|
| 95 |
+
cursor: pointer;
|
| 96 |
+
transition: all 0.2s;
|
| 97 |
+
font-weight: 500;
|
| 98 |
+
font-size: 14px;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
.nav-item:hover {
|
| 102 |
+
background: rgba(255, 255, 255, 0.1);
|
| 103 |
+
color: white;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
.nav-item.active {
|
| 107 |
+
background: var(--accent);
|
| 108 |
+
color: white;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
.nav-item svg {
|
| 112 |
+
width: 20px;
|
| 113 |
+
height: 20px;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
/* Main Content */
|
| 117 |
+
.main-content {
|
| 118 |
+
margin-left: 260px;
|
| 119 |
+
flex: 1;
|
| 120 |
+
padding: 32px;
|
| 121 |
+
min-height: 100vh;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
/* Header */
|
| 125 |
+
.page-header {
|
| 126 |
+
margin-bottom: 32px;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
.page-header h1 {
|
| 130 |
+
font-size: 28px;
|
| 131 |
+
font-weight: 700;
|
| 132 |
+
color: var(--text-primary);
|
| 133 |
+
margin-bottom: 8px;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
.page-header p {
|
| 137 |
+
color: var(--text-secondary);
|
| 138 |
+
font-size: 15px;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
/* Cards */
|
| 142 |
+
.card {
|
| 143 |
+
background: var(--bg-card);
|
| 144 |
+
border-radius: var(--radius-lg);
|
| 145 |
+
box-shadow: var(--shadow-md);
|
| 146 |
+
padding: 24px;
|
| 147 |
+
margin-bottom: 24px;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
.card-header {
|
| 151 |
+
display: flex;
|
| 152 |
+
align-items: center;
|
| 153 |
+
gap: 12px;
|
| 154 |
+
margin-bottom: 20px;
|
| 155 |
+
padding-bottom: 16px;
|
| 156 |
+
border-bottom: 1px solid var(--border);
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
.card-header h2 {
|
| 160 |
+
font-size: 18px;
|
| 161 |
+
font-weight: 600;
|
| 162 |
+
color: var(--text-primary);
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
.card-icon {
|
| 166 |
+
width: 40px;
|
| 167 |
+
height: 40px;
|
| 168 |
+
border-radius: var(--radius-md);
|
| 169 |
+
display: flex;
|
| 170 |
+
align-items: center;
|
| 171 |
+
justify-content: center;
|
| 172 |
+
font-size: 20px;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
.card-icon.primary {
|
| 176 |
+
background: rgba(30, 58, 95, 0.1);
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.card-icon.accent {
|
| 180 |
+
background: rgba(0, 168, 120, 0.1);
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.card-icon.warning {
|
| 184 |
+
background: rgba(245, 158, 11, 0.1);
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
/* Form Elements */
|
| 188 |
.form-group {
|
| 189 |
+
margin-bottom: 20px;
|
| 190 |
}
|
| 191 |
|
| 192 |
label {
|
| 193 |
display: block;
|
| 194 |
margin-bottom: 8px;
|
| 195 |
+
color: var(--text-primary);
|
| 196 |
+
font-weight: 500;
|
| 197 |
font-size: 14px;
|
| 198 |
}
|
| 199 |
|
| 200 |
+
label .optional {
|
| 201 |
+
color: var(--text-muted);
|
| 202 |
+
font-weight: 400;
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
select,
|
| 206 |
+
input[type="text"],
|
| 207 |
+
input[type="file"],
|
| 208 |
+
textarea {
|
| 209 |
width: 100%;
|
| 210 |
+
padding: 12px 16px;
|
| 211 |
+
border: 2px solid var(--border);
|
| 212 |
+
border-radius: var(--radius-md);
|
| 213 |
+
font-size: 14px;
|
| 214 |
+
font-family: inherit;
|
| 215 |
+
transition: all 0.2s;
|
| 216 |
+
background: white;
|
| 217 |
}
|
| 218 |
|
| 219 |
select:focus,
|
| 220 |
+
input[type="text"]:focus,
|
| 221 |
+
textarea:focus {
|
| 222 |
outline: none;
|
| 223 |
+
border-color: var(--border-focus);
|
| 224 |
+
box-shadow: 0 0 0 3px rgba(0, 168, 120, 0.1);
|
| 225 |
}
|
| 226 |
|
| 227 |
select {
|
|
|
|
| 228 |
cursor: pointer;
|
| 229 |
+
appearance: none;
|
| 230 |
+
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%236B7280'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
|
| 231 |
+
background-repeat: no-repeat;
|
| 232 |
+
background-position: right 12px center;
|
| 233 |
+
background-size: 20px;
|
| 234 |
+
padding-right: 40px;
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
/* File Upload */
|
| 238 |
+
.file-upload-wrapper {
|
| 239 |
+
border: 2px dashed var(--border);
|
| 240 |
+
border-radius: var(--radius-md);
|
| 241 |
+
padding: 32px;
|
| 242 |
+
text-align: center;
|
| 243 |
+
cursor: pointer;
|
| 244 |
+
transition: all 0.2s;
|
| 245 |
+
background: #FAFBFC;
|
| 246 |
}
|
| 247 |
|
| 248 |
+
.file-upload-wrapper:hover {
|
| 249 |
+
border-color: var(--accent);
|
| 250 |
+
background: rgba(0, 168, 120, 0.02);
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
.file-upload-wrapper.dragover {
|
| 254 |
+
border-color: var(--accent);
|
| 255 |
+
background: rgba(0, 168, 120, 0.05);
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
.file-upload-icon {
|
| 259 |
+
font-size: 48px;
|
| 260 |
+
margin-bottom: 12px;
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
.file-upload-text {
|
| 264 |
+
font-size: 15px;
|
| 265 |
+
color: var(--text-secondary);
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
.file-upload-text strong {
|
| 269 |
+
color: var(--accent);
|
| 270 |
}
|
| 271 |
|
| 272 |
.file-info {
|
| 273 |
+
margin-top: 12px;
|
| 274 |
+
padding: 12px;
|
| 275 |
+
background: var(--success-bg);
|
| 276 |
+
border-radius: var(--radius-sm);
|
| 277 |
+
color: var(--success);
|
| 278 |
+
font-weight: 500;
|
| 279 |
font-size: 14px;
|
| 280 |
}
|
| 281 |
|
| 282 |
+
/* Buttons */
|
| 283 |
.btn {
|
| 284 |
+
display: inline-flex;
|
| 285 |
+
align-items: center;
|
| 286 |
+
justify-content: center;
|
| 287 |
+
gap: 8px;
|
| 288 |
+
padding: 12px 24px;
|
| 289 |
+
border-radius: var(--radius-md);
|
| 290 |
+
font-size: 14px;
|
| 291 |
font-weight: 600;
|
| 292 |
cursor: pointer;
|
| 293 |
+
transition: all 0.2s;
|
| 294 |
+
border: none;
|
| 295 |
+
font-family: inherit;
|
| 296 |
}
|
| 297 |
|
| 298 |
+
.btn-primary {
|
| 299 |
+
background: var(--accent);
|
| 300 |
+
color: white;
|
| 301 |
}
|
| 302 |
|
| 303 |
+
.btn-primary:hover {
|
| 304 |
+
background: var(--accent-hover);
|
| 305 |
+
transform: translateY(-1px);
|
| 306 |
+
box-shadow: var(--shadow-md);
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
.btn-secondary {
|
| 310 |
+
background: var(--bg-main);
|
| 311 |
+
color: var(--text-primary);
|
| 312 |
+
border: 2px solid var(--border);
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
.btn-secondary:hover {
|
| 316 |
+
background: var(--border);
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
.btn-outline {
|
| 320 |
+
background: transparent;
|
| 321 |
+
color: var(--primary);
|
| 322 |
+
border: 2px solid var(--primary);
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
.btn-outline:hover {
|
| 326 |
+
background: var(--primary);
|
| 327 |
+
color: white;
|
| 328 |
}
|
| 329 |
|
| 330 |
.btn:disabled {
|
| 331 |
+
opacity: 0.5;
|
| 332 |
cursor: not-allowed;
|
| 333 |
+
transform: none !important;
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
.btn-lg {
|
| 337 |
+
padding: 16px 32px;
|
| 338 |
+
font-size: 16px;
|
| 339 |
}
|
| 340 |
|
| 341 |
+
.btn-full {
|
| 342 |
+
width: 100%;
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
.button-group {
|
| 346 |
+
display: flex;
|
| 347 |
+
gap: 12px;
|
| 348 |
+
margin-top: 24px;
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
.button-group .btn {
|
| 352 |
+
flex: 1;
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
/* Loading */
|
| 356 |
.loading {
|
| 357 |
display: none;
|
| 358 |
text-align: center;
|
| 359 |
+
padding: 40px;
|
|
|
|
| 360 |
}
|
| 361 |
|
| 362 |
.spinner {
|
|
|
|
| 745 |
</head>
|
| 746 |
|
| 747 |
<body>
|
| 748 |
+
<!-- Sidebar Navigation -->
|
| 749 |
+
<aside class="sidebar">
|
| 750 |
+
<div class="sidebar-logo">
|
| 751 |
+
<svg viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
|
| 752 |
+
<rect width="32" height="32" rx="8" fill="#00A878" />
|
| 753 |
+
<path d="M16 8L8 12v8l8 4 8-4v-8l-8-4z" stroke="white" stroke-width="2" fill="none" />
|
| 754 |
+
<path d="M16 16v8M8 12l8 4 8-4" stroke="white" stroke-width="2" />
|
| 755 |
+
</svg>
|
| 756 |
+
<span>DocValidator</span>
|
| 757 |
+
</div>
|
| 758 |
|
| 759 |
+
<nav class="sidebar-nav">
|
| 760 |
+
<div class="nav-item active" data-tab="validate">
|
| 761 |
+
<svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
| 762 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
| 763 |
+
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
| 764 |
+
</svg>
|
| 765 |
+
Validate Document
|
| 766 |
+
</div>
|
| 767 |
+
<div class="nav-item" data-tab="compare">
|
| 768 |
+
<svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
| 769 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
| 770 |
+
d="M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4"></path>
|
| 771 |
+
</svg>
|
| 772 |
+
Compare Documents
|
| 773 |
+
</div>
|
| 774 |
+
<div class="nav-item" data-tab="bulk">
|
| 775 |
+
<svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
| 776 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
| 777 |
+
d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10">
|
| 778 |
+
</path>
|
| 779 |
+
</svg>
|
| 780 |
+
Bulk Validation
|
| 781 |
+
</div>
|
| 782 |
+
</nav>
|
| 783 |
+
|
| 784 |
+
<div style="padding: 16px; border-top: 1px solid rgba(255,255,255,0.1); margin-top: auto;">
|
| 785 |
+
<div class="nav-item" id="logoutBtn">
|
| 786 |
+
<svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
| 787 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
| 788 |
+
d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1">
|
| 789 |
+
</path>
|
| 790 |
+
</svg>
|
| 791 |
+
Logout
|
| 792 |
+
</div>
|
| 793 |
+
</div>
|
| 794 |
+
</aside>
|
| 795 |
+
|
| 796 |
+
<!-- Main Content -->
|
| 797 |
+
<main class="main-content">
|
| 798 |
+
<div class="page-header">
|
| 799 |
+
<h1>Document Validation</h1>
|
| 800 |
+
<p>Upload a document and select a template to validate against</p>
|
| 801 |
+
</div>
|
| 802 |
+
|
| 803 |
+
<!-- Project Selector Card -->
|
| 804 |
+
<div class="card" style="padding: 16px;">
|
| 805 |
+
<div style="display: flex; align-items: center; gap: 16px; flex-wrap: wrap;">
|
| 806 |
+
<div style="display: flex; align-items: center; gap: 8px;">
|
| 807 |
+
<span style="font-size: 20px;">📂</span>
|
| 808 |
+
<label style="font-weight: 600; margin: 0; white-space: nowrap;">Project:</label>
|
| 809 |
+
</div>
|
| 810 |
+
<select id="currentProject" style="flex: 1; min-width: 200px;">
|
| 811 |
<option value="">No Project (Not Saved)</option>
|
| 812 |
</select>
|
| 813 |
+
<button type="button" class="btn btn-secondary" id="createProjectBtn">+ New</button>
|
| 814 |
+
<button type="button" class="btn btn-secondary" id="viewProjectsBtn">View All</button>
|
| 815 |
+
</div>
|
| 816 |
+
</div>
|
| 817 |
+
|
| 818 |
+
<!-- SharePoint Integration -->
|
| 819 |
+
<div
|
| 820 |
+
style="background: #f3f6f9; padding: 15px; border-radius: 8px; margin-bottom: 30px; border-left: 4px solid #0078d4; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;">
|
| 821 |
+
<div style="display: flex; align-items: center; gap: 10px;">
|
| 822 |
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
| 823 |
+
<path d="M12.5 4H19.5C20.6046 4 21.5 4.89543 21.5 6V20C21.5 21.1046 20.6046 22 19.5 22H12.5V4Z"
|
| 824 |
+
fill="#0078D4" />
|
| 825 |
+
<path d="M2.5 6C2.5 4.89543 3.39543 4 4.5 4H11.5V22H4.5C3.39543 22 2.5 21.1046 2.5 20V6Z"
|
| 826 |
+
fill="#50E6FF" fill-opacity="0.3" />
|
| 827 |
+
<path d="M11.5 4V13H7.5V7H11.5V4Z" fill="#0078D4" fill-opacity="0.5" />
|
| 828 |
+
</svg>
|
| 829 |
+
<div>
|
| 830 |
+
<strong style="display: block; color: #333;">Microsoft SharePoint / OneDrive</strong>
|
| 831 |
+
<span style="font-size: 12px; color: #666;">Import documents directly from cloud</span>
|
| 832 |
+
</div>
|
| 833 |
+
</div>
|
| 834 |
+
<div id="sharepointAuthSection">
|
| 835 |
+
<button type="button" class="btn-secondary" id="connectSharePointBtn"
|
| 836 |
+
style="border: 1px solid #0078d4; color: #0078d4; background: white;">
|
| 837 |
+
🔗 Connect Account
|
| 838 |
</button>
|
| 839 |
+
</div>
|
| 840 |
+
<div id="sharepointActionsSection" style="display: none;">
|
| 841 |
+
<span id="sharepointStatus"
|
| 842 |
+
style="font-size: 12px; color: #28a745; font-weight: 600; margin-right: 10px;">✓ Connected</span>
|
| 843 |
+
<button type="button" class="btn-secondary" id="browseSharePointBtn"
|
| 844 |
+
style="background: #0078d4; color: white; border: none;">
|
| 845 |
+
📂 Browse Files
|
| 846 |
</button>
|
| 847 |
+
<button type="button" class="btn-secondary" id="logoutSharePointBtn"
|
| 848 |
+
style="background: #eee; border: 1px solid #ccc; font-size: 12px; padding: 5px 10px;">
|
| 849 |
+
Disconnect
|
| 850 |
+
</button>
|
| 851 |
+
</div>
|
| 852 |
+
</div>
|
| 853 |
+
|
| 854 |
+
<!-- SharePoint File Browser Modal -->
|
| 855 |
+
<div id="sharePointModal"
|
| 856 |
+
style="display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 2000; align-items: center; justify-content: center;">
|
| 857 |
+
<div
|
| 858 |
+
style="background: white; padding: 0; border-radius: 8px; max-width: 800px; width: 90%; height: 80vh; display: flex; flex-direction: column; box-shadow: 0 10px 25px rgba(0,0,0,0.2);">
|
| 859 |
+
<div
|
| 860 |
+
style="padding: 20px; border-bottom: 1px solid #eee; display: flex; justify-content: space-between; align-items: center;">
|
| 861 |
+
<h2 style="margin: 0; font-size: 20px;">📂 Select Documents</h2>
|
| 862 |
+
<button type="button" id="closeSharePointModal"
|
| 863 |
+
style="background: none; border: none; font-size: 24px; cursor: pointer;">×</button>
|
| 864 |
+
</div>
|
| 865 |
+
|
| 866 |
+
<div
|
| 867 |
+
style="padding: 10px 20px; background: #f8f9fa; border-bottom: 1px solid #eee; display: flex; align-items: center; gap: 10px;">
|
| 868 |
+
<button id="spBackBtn" disabled style="padding: 5px 10px; cursor: pointer;">⬅ Back</button>
|
| 869 |
+
<div id="spBreadcrumbs"
|
| 870 |
+
style="font-size: 14px; color: #666; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">
|
| 871 |
+
Home</div>
|
| 872 |
+
</div>
|
| 873 |
+
|
| 874 |
+
<div id="spFileList" style="flex: 1; overflow-y: auto; padding: 20px;">
|
| 875 |
+
<!-- Drives/Files populated here -->
|
| 876 |
+
<div style="text-align: center; color: #999;">Loading...</div>
|
| 877 |
+
</div>
|
| 878 |
+
|
| 879 |
+
<div style="padding: 20px; border-top: 1px solid #eee; background: #fcfcfc; text-align: right;">
|
| 880 |
+
<span id="spSelectionCount" style="margin-right: 15px; color: #666; font-size: 14px;">0 files
|
| 881 |
+
selected</span>
|
| 882 |
+
<button type="button" class="btn" id="spImportBtn" disabled>Import & Validate</button>
|
| 883 |
+
</div>
|
| 884 |
</div>
|
| 885 |
</div>
|
| 886 |
|
|
|
|
| 907 |
</div>
|
| 908 |
</div>
|
| 909 |
|
| 910 |
+
<!-- Validation Form Card -->
|
| 911 |
+
<div class="card" id="validateSection">
|
| 912 |
+
<div class="card-header">
|
| 913 |
+
<div class="card-icon accent">✓</div>
|
| 914 |
+
<h2>Validate Document</h2>
|
|
|
|
|
|
|
| 915 |
</div>
|
| 916 |
|
| 917 |
+
<form id="validationForm">
|
| 918 |
+
<div class="form-group">
|
| 919 |
+
<label for="templateSelect">Select Template <span class="optional">(Required for template
|
| 920 |
+
validation)</span></label>
|
| 921 |
+
<select id="templateSelect" name="template">
|
| 922 |
+
<option value="">-- Select a template --</option>
|
| 923 |
+
</select>
|
| 924 |
+
</div>
|
| 925 |
|
| 926 |
+
<div class="form-group">
|
| 927 |
+
<label for="fileInput">Upload Document</label>
|
| 928 |
+
<div class="file-upload-wrapper" id="dropZone">
|
| 929 |
+
<div class="file-upload-icon">📄</div>
|
| 930 |
+
<div class="file-upload-text">
|
| 931 |
+
<strong>Click to upload</strong> or drag and drop<br>
|
| 932 |
+
PDF, DOCX, or PPTX files
|
| 933 |
+
</div>
|
| 934 |
+
<input type="file" id="fileInput" name="file" accept=".pdf,.docx,.pptx" required
|
| 935 |
+
style="display: none;">
|
| 936 |
+
</div>
|
| 937 |
+
<div class="file-info" id="fileInfo" style="display: none;"></div>
|
| 938 |
</div>
|
|
|
|
| 939 |
|
| 940 |
+
<div class="form-group">
|
| 941 |
+
<label for="customPrompt">Custom Instructions <span class="optional">(Optional)</span></label>
|
| 942 |
+
<textarea id="customPrompt" name="customPrompt" rows="3" maxlength="500"
|
| 943 |
+
placeholder="e.g., 'Focus on date format validation' or 'Pay special attention to logo placement'..."></textarea>
|
| 944 |
+
<div style="text-align: right; font-size: 12px; color: var(--text-muted); margin-top: 4px;">
|
| 945 |
+
<span id="charCount">0</span>/500 characters
|
| 946 |
+
</div>
|
| 947 |
+
</div>
|
| 948 |
+
|
| 949 |
+
<div class="button-group">
|
| 950 |
+
<button type="button" class="btn btn-primary btn-lg" id="validateBtn">
|
| 951 |
+
<svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
| 952 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
| 953 |
+
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
| 954 |
+
</svg>
|
| 955 |
+
Validate Document
|
| 956 |
+
</button>
|
| 957 |
+
<button type="button" class="btn btn-secondary btn-lg" id="spellingOnlyBtn">
|
| 958 |
+
<svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
| 959 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
| 960 |
+
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">
|
| 961 |
+
</path>
|
| 962 |
+
</svg>
|
| 963 |
+
Quality Check Only
|
| 964 |
+
</button>
|
| 965 |
+
</div>
|
| 966 |
+
<p style="font-size: 13px; color: var(--text-muted); margin-top: 12px; text-align: center;">
|
| 967 |
+
💡 Use "Quality Check Only" for grammar and spelling without template validation
|
| 968 |
+
</p>
|
| 969 |
+
</form>
|
| 970 |
+
</div>
|
| 971 |
|
| 972 |
<div class="debug-section">
|
| 973 |
<h3 style="margin-bottom: 10px; font-size: 18px;">🔍 Debug: Image Extraction</h3>
|
|
|
|
| 1046 |
<button type="button" class="btn" id="bulkValidateBtn" style="width: 100%;" disabled>
|
| 1047 |
✅ Validate All Certificates
|
| 1048 |
</button>
|
| 1049 |
+
</div>
|
| 1050 |
+
|
| 1051 |
+
<div class="loading" id="loading">
|
| 1052 |
+
<div class="spinner"></div>
|
| 1053 |
+
<p>Validating document...</p>
|
| 1054 |
+
</div>
|
| 1055 |
+
|
| 1056 |
+
<div class="error" id="error"></div>
|
| 1057 |
+
|
| 1058 |
+
<div class="results" id="results">
|
| 1059 |
+
<div class="status" id="status"></div>
|
| 1060 |
+
<div class="summary" id="summary"></div>
|
| 1061 |
+
<ul class="elements-list" id="elementsList"></ul>
|
| 1062 |
+
</div>
|
| 1063 |
+
|
| 1064 |
+
<!-- Comparison Results -->
|
| 1065 |
+
<div class="results" id="comparisonResults" style="display: none;">
|
| 1066 |
+
<h2 style="margin-bottom: 20px;">📊 Comparison Results</h2>
|
| 1067 |
+
<div id="comparisonSummary" style="margin-bottom: 20px;"></div>
|
| 1068 |
+
<div id="comparisonDetails"></div>
|
| 1069 |
+
</div>
|
| 1070 |
+
|
| 1071 |
+
<!-- Bulk Validation Results -->
|
| 1072 |
+
<div class="results" id="bulkResults" style="display: none;">
|
| 1073 |
+
<h2 style="margin-bottom: 20px;">📊 Bulk Validation Results</h2>
|
| 1074 |
+
<div id="bulkSummary" style="margin-bottom: 20px;"></div>
|
| 1075 |
+
<button type="button" class="btn-secondary" id="downloadCSVBtn" style="margin-bottom: 20px;">
|
| 1076 |
+
📥 Download CSV Report
|
| 1077 |
+
</button>
|
| 1078 |
+
<div id="bulkDetails"></div>
|
| 1079 |
+
</div>
|
| 1080 |
+
</main>
|
| 1081 |
|
| 1082 |
<script>
|
| 1083 |
// Load templates on page load
|
|
|
|
| 1102 |
}
|
| 1103 |
}
|
| 1104 |
|
| 1105 |
+
// Handle file input change - updated for new drag-drop wrapper
|
| 1106 |
+
const dropZone = document.getElementById('dropZone');
|
| 1107 |
+
const fileInput = document.getElementById('fileInput');
|
| 1108 |
+
const fileInfo = document.getElementById('fileInfo');
|
| 1109 |
+
|
| 1110 |
+
// Click to open file dialog
|
| 1111 |
+
dropZone.addEventListener('click', () => fileInput.click());
|
| 1112 |
+
|
| 1113 |
+
// Drag and drop handlers
|
| 1114 |
+
dropZone.addEventListener('dragover', (e) => {
|
| 1115 |
+
e.preventDefault();
|
| 1116 |
+
dropZone.classList.add('dragover');
|
| 1117 |
+
});
|
| 1118 |
+
|
| 1119 |
+
dropZone.addEventListener('dragleave', () => {
|
| 1120 |
+
dropZone.classList.remove('dragover');
|
| 1121 |
+
});
|
| 1122 |
+
|
| 1123 |
+
dropZone.addEventListener('drop', (e) => {
|
| 1124 |
+
e.preventDefault();
|
| 1125 |
+
dropZone.classList.remove('dragover');
|
| 1126 |
+
if (e.dataTransfer.files.length) {
|
| 1127 |
+
fileInput.files = e.dataTransfer.files;
|
| 1128 |
+
updateFileInfo(e.dataTransfer.files[0]);
|
| 1129 |
+
}
|
| 1130 |
+
});
|
| 1131 |
+
|
| 1132 |
+
fileInput.addEventListener('change', function (e) {
|
| 1133 |
+
if (e.target.files[0]) {
|
| 1134 |
+
updateFileInfo(e.target.files[0]);
|
| 1135 |
}
|
| 1136 |
});
|
| 1137 |
|
| 1138 |
+
function updateFileInfo(file) {
|
| 1139 |
+
fileInfo.style.display = 'block';
|
| 1140 |
+
fileInfo.innerHTML = `✓ ${file.name} (${(file.size / 1024).toFixed(1)} KB)`;
|
| 1141 |
+
dropZone.style.display = 'none';
|
| 1142 |
+
}
|
| 1143 |
+
|
| 1144 |
// Handle character count for custom prompt
|
| 1145 |
document.getElementById('customPrompt').addEventListener('input', function () {
|
| 1146 |
const count = this.value.length;
|
|
|
|
| 1968 |
alert('Projects view coming soon! For now, use the dropdown to select projects.');
|
| 1969 |
});
|
| 1970 |
|
| 1971 |
+
|
| 1972 |
+
// ==================== SHAREPOINT INTEGRATION ====================
|
| 1973 |
+
|
| 1974 |
+
const spState = {
|
| 1975 |
+
token: localStorage.getItem('sharepoint_token'),
|
| 1976 |
+
currentDriveId: null,
|
| 1977 |
+
currentFolderId: null,
|
| 1978 |
+
breadcrumbs: [],
|
| 1979 |
+
selectedFiles: new Set()
|
| 1980 |
+
};
|
| 1981 |
+
|
| 1982 |
+
// Initialize UI based on auth state
|
| 1983 |
+
function updateSharePointUI() {
|
| 1984 |
+
if (spState.token) {
|
| 1985 |
+
document.getElementById('sharepointAuthSection').style.display = 'none';
|
| 1986 |
+
document.getElementById('sharepointActionsSection').style.display = 'block';
|
| 1987 |
+
} else {
|
| 1988 |
+
document.getElementById('sharepointAuthSection').style.display = 'block';
|
| 1989 |
+
document.getElementById('sharepointActionsSection').style.display = 'none';
|
| 1990 |
+
}
|
| 1991 |
+
}
|
| 1992 |
+
updateSharePointUI();
|
| 1993 |
+
|
| 1994 |
+
// Connect Button Handler
|
| 1995 |
+
document.getElementById('connectSharePointBtn').addEventListener('click', async () => {
|
| 1996 |
+
try {
|
| 1997 |
+
const response = await fetch('/auth/sharepoint/login');
|
| 1998 |
+
const data = await response.json();
|
| 1999 |
+
|
| 2000 |
+
// Open popup
|
| 2001 |
+
const width = 600;
|
| 2002 |
+
const height = 700;
|
| 2003 |
+
const left = (window.screen.width - width) / 2;
|
| 2004 |
+
const top = (window.screen.height - height) / 2;
|
| 2005 |
+
|
| 2006 |
+
window.open(
|
| 2007 |
+
data.auth_url,
|
| 2008 |
+
'SharePointLogin',
|
| 2009 |
+
`width=${width},height=${height},top=${top},left=${left}`
|
| 2010 |
+
);
|
| 2011 |
+
} catch (error) {
|
| 2012 |
+
showError('Failed to start login: ' + error.message);
|
| 2013 |
+
}
|
| 2014 |
+
});
|
| 2015 |
+
|
| 2016 |
+
// Listen for auth message from popup
|
| 2017 |
+
window.addEventListener('message', (event) => {
|
| 2018 |
+
if (event.data.type === 'SHAREPOINT_AUTH') {
|
| 2019 |
+
spState.token = event.data.token;
|
| 2020 |
+
localStorage.setItem('sharepoint_token', spState.token);
|
| 2021 |
+
updateSharePointUI();
|
| 2022 |
+
showError(''); // Clear errors
|
| 2023 |
+
}
|
| 2024 |
+
});
|
| 2025 |
+
|
| 2026 |
+
// Logout
|
| 2027 |
+
document.getElementById('logoutSharePointBtn').addEventListener('click', () => {
|
| 2028 |
+
spState.token = null;
|
| 2029 |
+
localStorage.removeItem('sharepoint_token');
|
| 2030 |
+
updateSharePointUI();
|
| 2031 |
+
});
|
| 2032 |
+
|
| 2033 |
+
// Browse Button
|
| 2034 |
+
document.getElementById('browseSharePointBtn').addEventListener('click', () => {
|
| 2035 |
+
document.getElementById('sharePointModal').style.display = 'flex';
|
| 2036 |
+
loadDrives();
|
| 2037 |
+
});
|
| 2038 |
+
|
| 2039 |
+
document.getElementById('closeSharePointModal').addEventListener('click', () => {
|
| 2040 |
+
document.getElementById('sharePointModal').style.display = 'none';
|
| 2041 |
+
});
|
| 2042 |
+
|
| 2043 |
+
// Load Drives (Root level)
|
| 2044 |
+
async function loadDrives() {
|
| 2045 |
+
showLoadingList();
|
| 2046 |
+
try {
|
| 2047 |
+
const response = await fetch(`/sharepoint/drives?token=${spState.token}`);
|
| 2048 |
+
if (!response.ok) throw new Error('Failed to load drives');
|
| 2049 |
+
const drives = await response.json();
|
| 2050 |
+
|
| 2051 |
+
spState.currentDriveId = null;
|
| 2052 |
+
spState.breadcrumbs = [{ name: 'Home', id: null }];
|
| 2053 |
+
updateBreadcrumbs();
|
| 2054 |
+
|
| 2055 |
+
renderList(drives.map(drive => ({
|
| 2056 |
+
id: drive.id,
|
| 2057 |
+
name: drive.name,
|
| 2058 |
+
type: 'drive',
|
| 2059 |
+
icon: '💽'
|
| 2060 |
+
})));
|
| 2061 |
+
} catch (error) {
|
| 2062 |
+
handleSPError(error);
|
| 2063 |
+
}
|
| 2064 |
+
}
|
| 2065 |
+
|
| 2066 |
+
// Load Items (Folder level)
|
| 2067 |
+
async function loadItems(driveId, folderId = null) {
|
| 2068 |
+
showLoadingList();
|
| 2069 |
+
try {
|
| 2070 |
+
let url = `/sharepoint/items?drive_id=${driveId}&token=${spState.token}`;
|
| 2071 |
+
if (folderId) url += `&folder_id=${folderId}`;
|
| 2072 |
+
|
| 2073 |
+
const response = await fetch(url);
|
| 2074 |
+
if (!response.ok) throw new Error('Failed to load items');
|
| 2075 |
+
const items = await response.json();
|
| 2076 |
+
|
| 2077 |
+
renderList(items.map(item => ({
|
| 2078 |
+
id: item.id,
|
| 2079 |
+
name: item.name,
|
| 2080 |
+
type: item.type || (item.folder ? 'folder' : 'file'),
|
| 2081 |
+
icon: item.folder ? '📁' : (item.name.endsWith('.pdf') ? '📄' : '📝'),
|
| 2082 |
+
size: item.size
|
| 2083 |
+
})));
|
| 2084 |
+
} catch (error) {
|
| 2085 |
+
handleSPError(error);
|
| 2086 |
+
}
|
| 2087 |
+
}
|
| 2088 |
+
|
| 2089 |
+
function renderList(items) {
|
| 2090 |
+
const list = document.getElementById('spFileList');
|
| 2091 |
+
list.innerHTML = '';
|
| 2092 |
+
|
| 2093 |
+
if (items.length === 0) {
|
| 2094 |
+
list.innerHTML = '<div style="text-align: center; color: #999; padding: 20px;">No items found</div>';
|
| 2095 |
+
return;
|
| 2096 |
+
}
|
| 2097 |
+
|
| 2098 |
+
items.forEach(item => {
|
| 2099 |
+
const div = document.createElement('div');
|
| 2100 |
+
div.style.padding = '10px';
|
| 2101 |
+
div.style.borderBottom = '1px solid #eee';
|
| 2102 |
+
div.style.display = 'flex';
|
| 2103 |
+
div.style.alignItems = 'center';
|
| 2104 |
+
div.style.cursor = 'pointer';
|
| 2105 |
+
div.className = 'sp-item';
|
| 2106 |
+
|
| 2107 |
+
// Selectable logic
|
| 2108 |
+
const isSelected = spState.selectedFiles.has(item.id);
|
| 2109 |
+
const isSelectable = item.type === 'file' && (item.name.endsWith('.pdf') || item.name.endsWith('.pptx') || item.name.endsWith('.docx'));
|
| 2110 |
+
|
| 2111 |
+
div.style.backgroundColor = isSelected ? '#e8f0fe' : 'white';
|
| 2112 |
+
|
| 2113 |
+
div.innerHTML = `
|
| 2114 |
+
<span style="font-size: 20px; margin-right: 10px;">${item.icon}</span>
|
| 2115 |
+
<span style="flex: 1;">${item.name}</span>
|
| 2116 |
+
${item.size ? `<span style="font-size: 12px; color: #999;">${formatSize(item.size)}</span>` : ''}
|
| 2117 |
+
`;
|
| 2118 |
+
|
| 2119 |
+
div.onclick = () => {
|
| 2120 |
+
if (item.type === 'drive') {
|
| 2121 |
+
spState.currentDriveId = item.id;
|
| 2122 |
+
spState.breadcrumbs.push({ name: item.name, id: item.id, type: 'drive' });
|
| 2123 |
+
loadItems(item.id);
|
| 2124 |
+
updateBreadcrumbs();
|
| 2125 |
+
} else if (item.type === 'folder') {
|
| 2126 |
+
spState.currentFolderId = item.id;
|
| 2127 |
+
spState.breadcrumbs.push({ name: item.name, id: item.id, type: 'folder' });
|
| 2128 |
+
loadItems(spState.currentDriveId, item.id);
|
| 2129 |
+
updateBreadcrumbs();
|
| 2130 |
+
} else if (isSelectable) {
|
| 2131 |
+
if (spState.selectedFiles.has(item.id)) {
|
| 2132 |
+
spState.selectedFiles.delete(item.id);
|
| 2133 |
+
div.style.backgroundColor = 'white';
|
| 2134 |
+
} else {
|
| 2135 |
+
spState.selectedFiles.add(item.id);
|
| 2136 |
+
div.style.backgroundColor = '#e8f0fe';
|
| 2137 |
+
}
|
| 2138 |
+
updateSelectionCount();
|
| 2139 |
+
}
|
| 2140 |
+
};
|
| 2141 |
+
|
| 2142 |
+
list.appendChild(div);
|
| 2143 |
+
});
|
| 2144 |
+
updateSelectionCount();
|
| 2145 |
+
}
|
| 2146 |
+
|
| 2147 |
+
function updateBreadcrumbs() {
|
| 2148 |
+
const container = document.getElementById('spBreadcrumbs');
|
| 2149 |
+
container.innerHTML = spState.breadcrumbs.map((b, i) => {
|
| 2150 |
+
const isLast = i === spState.breadcrumbs.length - 1;
|
| 2151 |
+
return `<span class="${!isLast ? 'breadcrumb-link' : ''}" style="${!isLast ? 'cursor: pointer; color: #0078d4; text-decoration: underline;' : 'font-weight: 600;'}" onclick="${!isLast ? `navigateBreadcrumb(${i})` : ''}">${b.name}</span>`;
|
| 2152 |
+
}).join(' > ');
|
| 2153 |
+
|
| 2154 |
+
document.getElementById('spBackBtn').disabled = spState.breadcrumbs.length <= 1;
|
| 2155 |
+
document.getElementById('spBackBtn').onclick = () => navigateBreadcrumb(spState.breadcrumbs.length - 2);
|
| 2156 |
+
}
|
| 2157 |
+
|
| 2158 |
+
window.navigateBreadcrumb = (index) => {
|
| 2159 |
+
if (index < 0) return;
|
| 2160 |
+
const target = spState.breadcrumbs[index];
|
| 2161 |
+
spState.breadcrumbs = spState.breadcrumbs.slice(0, index + 1);
|
| 2162 |
+
|
| 2163 |
+
if (target.id === null) { // Home
|
| 2164 |
+
loadDrives();
|
| 2165 |
+
} else if (target.type === 'drive') {
|
| 2166 |
+
spState.currentDriveId = target.id;
|
| 2167 |
+
spState.currentFolderId = null;
|
| 2168 |
+
loadItems(target.id);
|
| 2169 |
+
} else {
|
| 2170 |
+
spState.currentFolderId = target.id;
|
| 2171 |
+
loadItems(spState.currentDriveId, target.id);
|
| 2172 |
+
}
|
| 2173 |
+
updateBreadcrumbs();
|
| 2174 |
+
};
|
| 2175 |
+
|
| 2176 |
+
function updateSelectionCount() {
|
| 2177 |
+
const count = spState.selectedFiles.size;
|
| 2178 |
+
document.getElementById('spSelectionCount').textContent = `${count} files selected`;
|
| 2179 |
+
document.getElementById('spImportBtn').disabled = count === 0;
|
| 2180 |
+
}
|
| 2181 |
+
|
| 2182 |
+
function showLoadingList() {
|
| 2183 |
+
document.getElementById('spFileList').innerHTML = '<div style="text-align: center; padding: 20px;">Loading...</div>';
|
| 2184 |
+
}
|
| 2185 |
+
|
| 2186 |
+
function handleSPError(error) {
|
| 2187 |
+
if (error.message.includes('401') || error.message.includes('token')) {
|
| 2188 |
+
spState.token = null;
|
| 2189 |
+
localStorage.removeItem('sharepoint_token');
|
| 2190 |
+
updateSharePointUI();
|
| 2191 |
+
document.getElementById('sharePointModal').style.display = 'none';
|
| 2192 |
+
showError('Session expired. Please connect again.');
|
| 2193 |
+
} else {
|
| 2194 |
+
document.getElementById('spFileList').innerHTML = `<div style="text-align: center; color: red; padding: 20px;">Error: ${error.message}</div>`;
|
| 2195 |
+
}
|
| 2196 |
+
}
|
| 2197 |
+
|
| 2198 |
+
function formatSize(bytes) {
|
| 2199 |
+
if (bytes === 0) return '0 B';
|
| 2200 |
+
const k = 1024;
|
| 2201 |
+
const sizes = ['B', 'KB', 'MB', 'GB'];
|
| 2202 |
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
| 2203 |
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i];
|
| 2204 |
+
}
|
| 2205 |
+
|
| 2206 |
+
// Import Button
|
| 2207 |
+
document.getElementById('spImportBtn').addEventListener('click', async () => {
|
| 2208 |
+
const fileIds = Array.from(spState.selectedFiles);
|
| 2209 |
+
const btn = document.getElementById('spImportBtn');
|
| 2210 |
+
btn.disabled = true;
|
| 2211 |
+
btn.textContent = 'Importing...';
|
| 2212 |
+
|
| 2213 |
+
try {
|
| 2214 |
+
// Determine current project
|
| 2215 |
+
const projectId = document.getElementById('currentProject').value || null;
|
| 2216 |
+
|
| 2217 |
+
const response = await fetch('/sharepoint/download-and-validate', {
|
| 2218 |
+
method: 'POST',
|
| 2219 |
+
headers: { 'Content-Type': 'application/json' },
|
| 2220 |
+
body: JSON.stringify({
|
| 2221 |
+
drive_id: spState.currentDriveId,
|
| 2222 |
+
file_ids: fileIds,
|
| 2223 |
+
token: spState.token,
|
| 2224 |
+
project_id: projectId ? parseInt(projectId) : null
|
| 2225 |
+
})
|
| 2226 |
+
});
|
| 2227 |
+
|
| 2228 |
+
if (!response.ok) throw new Error('Import failed');
|
| 2229 |
+
|
| 2230 |
+
const result = await response.json();
|
| 2231 |
+
document.getElementById('sharePointModal').style.display = 'none';
|
| 2232 |
+
spState.selectedFiles.clear();
|
| 2233 |
+
updateSelectionCount();
|
| 2234 |
+
|
| 2235 |
+
// Show success or redirect to results
|
| 2236 |
+
showStatus('Successfully imported files! Check validation results below.', 'pass');
|
| 2237 |
+
|
| 2238 |
+
// Trigger refresh of validations (if implemented) or just alert
|
| 2239 |
+
alert('Files imported successfully! (Validation logic to be connected fully in next step)');
|
| 2240 |
+
|
| 2241 |
+
} catch (error) {
|
| 2242 |
+
showError('Import failed: ' + error.message);
|
| 2243 |
+
} finally {
|
| 2244 |
+
btn.disabled = false;
|
| 2245 |
+
btn.textContent = 'Import & Validate';
|
| 2246 |
+
}
|
| 2247 |
+
});
|
| 2248 |
+
|
| 2249 |
// Load templates when page loads
|
| 2250 |
loadProjects();
|
| 2251 |
loadTemplates();
|
requirements.txt
CHANGED
|
@@ -15,3 +15,5 @@ python-docx>=1.1.2
|
|
| 15 |
python-pptx>=0.6.23
|
| 16 |
lxml>=4.9.2
|
| 17 |
openpyxl>=3.1.0
|
|
|
|
|
|
|
|
|
| 15 |
python-pptx>=0.6.23
|
| 16 |
lxml>=4.9.2
|
| 17 |
openpyxl>=3.1.0
|
| 18 |
+
msal>=1.22.0
|
| 19 |
+
requests>=2.31.0
|