Spaces:
Running
Running
Update app.js
Browse files
app.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
-
/*
|
|
|
|
| 2 |
const EXPORT_COLUMNS = [
|
| 3 |
"التصنيف",
|
| 4 |
"نوع المشكلة","وقت حدوث المشكلة","اسم صاحب المشكلة",
|
|
@@ -6,7 +7,7 @@ const EXPORT_COLUMNS = [
|
|
| 6 |
"اسم الدعم الفني","الحالة"
|
| 7 |
];
|
| 8 |
|
| 9 |
-
/*
|
| 10 |
const FIELD_ALIASES = {
|
| 11 |
"نوع المشكلة": ["نوع المشكله","نوع المشكلة","المشكلة"],
|
| 12 |
"وقت حدوث المشكلة": ["وقت حدوث المشكله","وقت حدوث المشكلة","وقت المشكلة","وقت حدوث"],
|
|
@@ -18,7 +19,7 @@ const FIELD_ALIASES = {
|
|
| 18 |
"المنطقة": ["المنطقة","المنطقه","اسم المنطقة","المدينة","المحافظة","منطقة"]
|
| 19 |
};
|
| 20 |
|
| 21 |
-
/* قواعد التصنيف */
|
| 22 |
const CLASS_RULES = {
|
| 23 |
"استفسار": ["استفسار","سؤال","استعلام","معلومة","استفسارات"],
|
| 24 |
"إضافة أجهزة": ["اضافة جهاز","إضافة أجهزة","اضافة اجهزة","تركيب جهاز","جهاز جديد","تسجيل جهاز","ربط جهاز","اضافة ماسح","إضافة ماسح"],
|
|
@@ -40,7 +41,7 @@ const CLASS_PRIORITY = [
|
|
| 40 |
"النظام المكتبي","تناقل البيانات","استفسار",
|
| 41 |
];
|
| 42 |
|
| 43 |
-
/* أدوات نص */
|
| 44 |
const TICKET_SEP = /\n\s*(?:\n|—+|-{3,}|={3,}|🔴+)+\s*\n/;
|
| 45 |
const arabicDigitsMap = {"٠":"0","١":"1","٢":"2","٣":"3","٤":"4","٥":"5","٦":"6","٧":"7","٨":"8","٩":"9"};
|
| 46 |
function normalizeText(s){
|
|
@@ -146,7 +147,7 @@ function extractFields(ticketText){
|
|
| 146 |
v = findAfterLabel(text, FIELD_ALIASES["اسم صاحب المشكلة"]);
|
| 147 |
if(v) out["اسم صاحب المشكلة"] = v;
|
| 148 |
|
| 149 |
-
// رقم الهوية: أرقام فقط (10 لاحقًا
|
| 150 |
v = findAfterLabel(text, FIELD_ALIASES["رقم الهوية"]);
|
| 151 |
if(v) out["رقم الهوية"] = digitsOnly(v);
|
| 152 |
if(!out["رقم الهوية"]){
|
|
@@ -166,7 +167,7 @@ function extractFields(ticketText){
|
|
| 166 |
v = findAfterLabel(text, FIELD_ALIASES["رقم الجوال"]);
|
| 167 |
if(v) out["رقم الجوال"] = digitsOnly(v);
|
| 168 |
if(!out["رقم الجوال"]){
|
| 169 |
-
const m = text.match(/(?:^|\D)(05\d{7,})(?:\D|$)/);
|
| 170 |
if(m) out["رقم الجوال"] = m[1];
|
| 171 |
}
|
| 172 |
|
|
@@ -201,7 +202,6 @@ function parseTicketsWithExtras(raw, agentName, defaultRegion){
|
|
| 201 |
const f = extractFields(t);
|
| 202 |
const cls = classifyTicket(t, f);
|
| 203 |
const region = regionChosen ? regionChosen : (f["المنطقة"] || "");
|
| 204 |
-
|
| 205 |
return {
|
| 206 |
"التصنيف": cls,
|
| 207 |
"نوع المشكلة": f["نوع المشكلة"] || "",
|
|
@@ -218,7 +218,7 @@ function parseTicketsWithExtras(raw, agentName, defaultRegion){
|
|
| 218 |
});
|
| 219 |
}
|
| 220 |
|
| 221 |
-
/* بناء الجدول
|
| 222 |
function buildTable(rows){
|
| 223 |
const theadRow = document.getElementById("theadRow");
|
| 224 |
const tbody = document.getElementById("tbody");
|
|
@@ -251,7 +251,7 @@ function readTable(){
|
|
| 251 |
return rows;
|
| 252 |
}
|
| 253 |
|
| 254 |
-
/*
|
| 255 |
function updateBadge(n){
|
| 256 |
const b = document.getElementById("countBadge");
|
| 257 |
b.textContent = n; b.hidden = (n===0);
|
|
@@ -290,7 +290,7 @@ document.addEventListener("input",(e)=>{
|
|
| 290 |
}
|
| 291 |
});
|
| 292 |
|
| 293 |
-
/* Toast */
|
| 294 |
function toast(msg){
|
| 295 |
const t = document.getElementById("toast");
|
| 296 |
t.textContent = msg; t.hidden = false;
|
|
@@ -298,7 +298,7 @@ function toast(msg){
|
|
| 298 |
setTimeout(()=>{ t.hidden = true; }, 2000);
|
| 299 |
}
|
| 300 |
|
| 301 |
-
/* تصدير Excel (حفظ الأصفار كنص للأعمدة الرقمية) */
|
| 302 |
async function exportExcel(){
|
| 303 |
const rows = readTable();
|
| 304 |
if(!rows.length){ toast("لا يوجد بيانات لتصديرها."); return; }
|
|
@@ -346,7 +346,7 @@ async function exportExcel(){
|
|
| 346 |
toast("تم تنزيل الملف.");
|
| 347 |
}
|
| 348 |
|
| 349 |
-
/* نسخ إلى الحافظة (TSV) */
|
| 350 |
async function copyToClipboardTSV(){
|
| 351 |
const rows = readTable();
|
| 352 |
if(!rows.length){ toast("لا يوجد بيانات لنسخها."); return; }
|
|
@@ -373,7 +373,7 @@ async function copyToClipboardTSV(){
|
|
| 373 |
}
|
| 374 |
}
|
| 375 |
|
| 376 |
-
/* مثال */
|
| 377 |
const SAMPLE = `نوع المشكلة : لا استطيع اكمال الاستمارة بسبب تعليق
|
| 378 |
وقت حدوث المشكلة: 21/8/2025 10:35 ص
|
| 379 |
اسم صاحب المشكلة : نوف الناصر
|
|
@@ -383,10 +383,9 @@ const SAMPLE = `نوع المشكلة : لا استطيع اكمال الاست
|
|
| 383 |
اسم المسح: الخبر 2025
|
| 384 |
اسم المنطقة: الشرقية`;
|
| 385 |
|
| 386 |
-
/*
|
| 387 |
-
const STATE_KEY = "
|
| 388 |
|
| 389 |
-
/* عند التحميل نضمن الأعمدة والقيم، ونُبقي المنطقة المختارة مطبّقة على كل الصفوف */
|
| 390 |
function ensureColumns(rows, agentName, defaultRegion){
|
| 391 |
if(!Array.isArray(rows)) return rows||[];
|
| 392 |
return rows.map(r=>{
|
|
@@ -430,28 +429,31 @@ function loadState(){
|
|
| 430 |
}catch{ return false; }
|
| 431 |
}
|
| 432 |
|
| 433 |
-
/* مسح
|
| 434 |
-
function
|
| 435 |
-
|
| 436 |
-
const
|
| 437 |
-
|
| 438 |
-
const rawEl = document.getElementById("raw");
|
| 439 |
-
const tbody = document.getElementById("tbody");
|
| 440 |
const fnameEl = document.getElementById("fname");
|
|
|
|
|
|
|
|
|
|
| 441 |
if(rawEl) rawEl.value = "";
|
| 442 |
if(tbody) tbody.innerHTML = "";
|
| 443 |
if(fnameEl) fnameEl.value = "Ticket";
|
|
|
|
|
|
|
|
|
|
|
|
|
| 444 |
updateBadge(0); setButtonsEnabled(false);
|
| 445 |
|
| 446 |
-
//
|
| 447 |
-
try{
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
}));
|
| 451 |
-
}catch{}
|
| 452 |
}
|
| 453 |
|
| 454 |
-
/* تهيئة */
|
| 455 |
function init(){
|
| 456 |
const parseBtn = document.getElementById("btn-parse");
|
| 457 |
const exportBtn = document.getElementById("btn-export");
|
|
@@ -478,12 +480,7 @@ function init(){
|
|
| 478 |
|
| 479 |
exportBtn.addEventListener("click", exportExcel);
|
| 480 |
copyBtn.addEventListener("click", copyToClipboardTSV);
|
| 481 |
-
|
| 482 |
-
clearBtn.addEventListener("click", ()=>{
|
| 483 |
-
clearKeepAgentRegion();
|
| 484 |
-
toast("تم مسح النص والجدول — تم الإبقاء على اسم الدعم والمنطقة.");
|
| 485 |
-
});
|
| 486 |
-
|
| 487 |
sampleBtn.addEventListener("click", ()=>{ rawEl.value = SAMPLE; saveState(); });
|
| 488 |
|
| 489 |
rawEl.addEventListener("input", saveState);
|
|
@@ -496,7 +493,7 @@ function init(){
|
|
| 496 |
if(ctrl && e.key === "Enter"){ e.preventDefault(); parseBtn.click(); }
|
| 497 |
else if(ctrl && e.key.toLowerCase() === "e"){ e.preventDefault(); exportBtn.click(); }
|
| 498 |
else if(ctrl && e.shiftKey && e.key.toLowerCase() === "c"){ e.preventDefault(); copyBtn.click(); }
|
| 499 |
-
else if(e.key === "Escape"){ e.preventDefault();
|
| 500 |
});
|
| 501 |
|
| 502 |
setButtonsEnabled(!!document.getElementById("tbody")?.children.length);
|
|
|
|
| 1 |
+
/* app.js — v8: Clear ALSO removes agent & region */
|
| 2 |
+
/* ========= أعمدة الجدول ========= */
|
| 3 |
const EXPORT_COLUMNS = [
|
| 4 |
"التصنيف",
|
| 5 |
"نوع المشكلة","وقت حدوث المشكلة","اسم صاحب المشكلة",
|
|
|
|
| 7 |
"اسم الدعم الفني","الحالة"
|
| 8 |
];
|
| 9 |
|
| 10 |
+
/* ========= مرادفات الحقول ========= */
|
| 11 |
const FIELD_ALIASES = {
|
| 12 |
"نوع المشكلة": ["نوع المشكله","نوع المشكلة","المشكلة"],
|
| 13 |
"وقت حدوث المشكلة": ["وقت حدوث المشكله","وقت حدوث المشكلة","وقت المشكلة","وقت حدوث"],
|
|
|
|
| 19 |
"المنطقة": ["المنطقة","المنطقه","اسم المنطقة","المدينة","المحافظة","منطقة"]
|
| 20 |
};
|
| 21 |
|
| 22 |
+
/* ========= قواعد التصنيف ========= */
|
| 23 |
const CLASS_RULES = {
|
| 24 |
"استفسار": ["استفسار","سؤال","استعلام","معلومة","استفسارات"],
|
| 25 |
"إضافة أجهزة": ["اضافة جهاز","إضافة أجهزة","اضافة اجهزة","تركيب جهاز","جهاز جديد","تسجيل جهاز","ربط جهاز","اضافة ماسح","إضافة ماسح"],
|
|
|
|
| 41 |
"النظام المكتبي","تناقل البيانات","استفسار",
|
| 42 |
];
|
| 43 |
|
| 44 |
+
/* ========= أدوات نص ========= */
|
| 45 |
const TICKET_SEP = /\n\s*(?:\n|—+|-{3,}|={3,}|🔴+)+\s*\n/;
|
| 46 |
const arabicDigitsMap = {"٠":"0","١":"1","٢":"2","٣":"3","٤":"4","٥":"5","٦":"6","٧":"7","٨":"8","٩":"9"};
|
| 47 |
function normalizeText(s){
|
|
|
|
| 147 |
v = findAfterLabel(text, FIELD_ALIASES["اسم صاحب المشكلة"]);
|
| 148 |
if(v) out["اسم صاحب المشكلة"] = v;
|
| 149 |
|
| 150 |
+
// رقم الهوية: أرقام فقط (التحقق 10 أرقام لاحقًا)
|
| 151 |
v = findAfterLabel(text, FIELD_ALIASES["رقم الهوية"]);
|
| 152 |
if(v) out["رقم الهوية"] = digitsOnly(v);
|
| 153 |
if(!out["رقم الهوية"]){
|
|
|
|
| 167 |
v = findAfterLabel(text, FIELD_ALIASES["رقم الجوال"]);
|
| 168 |
if(v) out["رقم الجوال"] = digitsOnly(v);
|
| 169 |
if(!out["رقم الجوال"]){
|
| 170 |
+
const m = text.match(/(?:^|\D)(05\d{7,})(?:\D|$)/);
|
| 171 |
if(m) out["رقم الجوال"] = m[1];
|
| 172 |
}
|
| 173 |
|
|
|
|
| 202 |
const f = extractFields(t);
|
| 203 |
const cls = classifyTicket(t, f);
|
| 204 |
const region = regionChosen ? regionChosen : (f["المنطقة"] || "");
|
|
|
|
| 205 |
return {
|
| 206 |
"التصنيف": cls,
|
| 207 |
"نوع المشكلة": f["نوع المشكلة"] || "",
|
|
|
|
| 218 |
});
|
| 219 |
}
|
| 220 |
|
| 221 |
+
/* ========= بناء الجدول/قراءة الجدول ========= */
|
| 222 |
function buildTable(rows){
|
| 223 |
const theadRow = document.getElementById("theadRow");
|
| 224 |
const tbody = document.getElementById("tbody");
|
|
|
|
| 251 |
return rows;
|
| 252 |
}
|
| 253 |
|
| 254 |
+
/* ========= شارة العدّاد + تمكين الأزرار + التحقق ========= */
|
| 255 |
function updateBadge(n){
|
| 256 |
const b = document.getElementById("countBadge");
|
| 257 |
b.textContent = n; b.hidden = (n===0);
|
|
|
|
| 290 |
}
|
| 291 |
});
|
| 292 |
|
| 293 |
+
/* ========= Toast ========= */
|
| 294 |
function toast(msg){
|
| 295 |
const t = document.getElementById("toast");
|
| 296 |
t.textContent = msg; t.hidden = false;
|
|
|
|
| 298 |
setTimeout(()=>{ t.hidden = true; }, 2000);
|
| 299 |
}
|
| 300 |
|
| 301 |
+
/* ========= تصدير Excel (حفظ الأصفار كنص للأعمدة الرقمية) ========= */
|
| 302 |
async function exportExcel(){
|
| 303 |
const rows = readTable();
|
| 304 |
if(!rows.length){ toast("لا يوجد بيانات لتصديرها."); return; }
|
|
|
|
| 346 |
toast("تم تنزيل الملف.");
|
| 347 |
}
|
| 348 |
|
| 349 |
+
/* ========= نسخ إلى الحافظة (TSV) ========= */
|
| 350 |
async function copyToClipboardTSV(){
|
| 351 |
const rows = readTable();
|
| 352 |
if(!rows.length){ toast("لا يوجد بيانات لنسخها."); return; }
|
|
|
|
| 373 |
}
|
| 374 |
}
|
| 375 |
|
| 376 |
+
/* ========= مثال ========= */
|
| 377 |
const SAMPLE = `نوع المشكلة : لا استطيع اكمال الاستمارة بسبب تعليق
|
| 378 |
وقت حدوث المشكلة: 21/8/2025 10:35 ص
|
| 379 |
اسم صاحب المشكلة : نوف الناصر
|
|
|
|
| 383 |
اسم المسح: الخبر 2025
|
| 384 |
اسم المنطقة: الشرقية`;
|
| 385 |
|
| 386 |
+
/* ========= تخزين الحالة ========= */
|
| 387 |
+
const STATE_KEY = "ticketParserState_v8";
|
| 388 |
|
|
|
|
| 389 |
function ensureColumns(rows, agentName, defaultRegion){
|
| 390 |
if(!Array.isArray(rows)) return rows||[];
|
| 391 |
return rows.map(r=>{
|
|
|
|
| 429 |
}catch{ return false; }
|
| 430 |
}
|
| 431 |
|
| 432 |
+
/* ========= مسح كل شيء بما فيه اسم الدعم والمنطقة ========= */
|
| 433 |
+
function clearAll(){
|
| 434 |
+
// نظّف الواجهة كاملة
|
| 435 |
+
const rawEl = document.getElementById("raw");
|
| 436 |
+
const tbody = document.getElementById("tbody");
|
|
|
|
|
|
|
| 437 |
const fnameEl = document.getElementById("fname");
|
| 438 |
+
const agentEl = document.getElementById("agentName");
|
| 439 |
+
const regionEl= document.getElementById("regionDefault");
|
| 440 |
+
|
| 441 |
if(rawEl) rawEl.value = "";
|
| 442 |
if(tbody) tbody.innerHTML = "";
|
| 443 |
if(fnameEl) fnameEl.value = "Ticket";
|
| 444 |
+
if(agentEl) agentEl.value = "";
|
| 445 |
+
if(regionEl) regionEl.value = "";
|
| 446 |
+
|
| 447 |
+
// عطّل الأزرار واصفر العداد
|
| 448 |
updateBadge(0); setButtonsEnabled(false);
|
| 449 |
|
| 450 |
+
// امسح التخزين كليًا
|
| 451 |
+
try{ localStorage.removeItem(STATE_KEY); }catch{}
|
| 452 |
+
|
| 453 |
+
toast("تم مسح كل البيانات بما فيها اسم الدعم والمنطقة.");
|
|
|
|
|
|
|
| 454 |
}
|
| 455 |
|
| 456 |
+
/* ========= تهيئة ========= */
|
| 457 |
function init(){
|
| 458 |
const parseBtn = document.getElementById("btn-parse");
|
| 459 |
const exportBtn = document.getElementById("btn-export");
|
|
|
|
| 480 |
|
| 481 |
exportBtn.addEventListener("click", exportExcel);
|
| 482 |
copyBtn.addEventListener("click", copyToClipboardTSV);
|
| 483 |
+
clearBtn.addEventListener("click", clearAll);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 484 |
sampleBtn.addEventListener("click", ()=>{ rawEl.value = SAMPLE; saveState(); });
|
| 485 |
|
| 486 |
rawEl.addEventListener("input", saveState);
|
|
|
|
| 493 |
if(ctrl && e.key === "Enter"){ e.preventDefault(); parseBtn.click(); }
|
| 494 |
else if(ctrl && e.key.toLowerCase() === "e"){ e.preventDefault(); exportBtn.click(); }
|
| 495 |
else if(ctrl && e.shiftKey && e.key.toLowerCase() === "c"){ e.preventDefault(); copyBtn.click(); }
|
| 496 |
+
else if(e.key === "Escape"){ e.preventDefault(); clearAll(); }
|
| 497 |
});
|
| 498 |
|
| 499 |
setButtonsEnabled(!!document.getElementById("tbody")?.children.length);
|