Spaces:
Running
Running
Update app.js
Browse files
app.js
CHANGED
|
@@ -39,12 +39,12 @@ function normalizeTime(val){
|
|
| 39 |
}
|
| 40 |
function normalizeDate(v){
|
| 41 |
v=(v||"").trim();
|
| 42 |
-
let m=v.match(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2,4})/);
|
| 43 |
if(m){
|
| 44 |
let d=+m[1], mo=+m[2], y=+m[3]; if(y<100) y+=2000;
|
| 45 |
return `${y.toString().padStart(4,"0")}-${String(mo).padStart(2,"0")}-${String(d).padStart(2,"0")}`;
|
| 46 |
}
|
| 47 |
-
m=v.match(/(\d{4})[\/\-](\d{1,2})[\/\-](\d{1,2})/);
|
| 48 |
if(m){
|
| 49 |
let y=+m[1], mo=+m[2], d=+m[3];
|
| 50 |
return `${y.toString().padStart(4,"0")}-${String(mo).padStart(2,"0")}-${String(d).padStart(2,"0")}`;
|
|
@@ -111,7 +111,6 @@ function extractFields(ticketText){
|
|
| 111 |
}
|
| 112 |
return data;
|
| 113 |
}
|
| 114 |
-
|
| 115 |
function parseTickets(raw){ return splitTickets(raw||"").map(extractFields); }
|
| 116 |
|
| 117 |
function buildTable(rows){
|
|
@@ -135,7 +134,6 @@ function buildTable(rows){
|
|
| 135 |
tbody.appendChild(tr);
|
| 136 |
});
|
| 137 |
}
|
| 138 |
-
|
| 139 |
function readTable(){
|
| 140 |
const tbody = document.getElementById("tbody");
|
| 141 |
const rows = [];
|
|
@@ -146,25 +144,18 @@ function readTable(){
|
|
| 146 |
});
|
| 147 |
return rows;
|
| 148 |
}
|
| 149 |
-
|
| 150 |
-
function updateCount(n){
|
| 151 |
-
document.getElementById("countChip").textContent = `عدد التذاكر: ${n}`;
|
| 152 |
-
}
|
| 153 |
function setButtonsEnabled(hasRows){
|
| 154 |
document.getElementById("btn-export").disabled = !hasRows;
|
| 155 |
document.getElementById("btn-copy").disabled = !hasRows;
|
| 156 |
}
|
| 157 |
function toast(msg){
|
| 158 |
const t = document.getElementById("toast");
|
| 159 |
-
t.textContent = msg;
|
| 160 |
-
t.
|
| 161 |
-
t.classList.remove("show");
|
| 162 |
-
void t.offsetWidth; // reflow
|
| 163 |
-
t.classList.add("show");
|
| 164 |
setTimeout(()=>{ t.hidden = true; }, 2400);
|
| 165 |
}
|
| 166 |
-
|
| 167 |
-
/* تصدير/مشاركة Excel: يجرّب Web Share أولاً ثم تنزيل كبديل */
|
| 168 |
async function exportExcel(){
|
| 169 |
const rows = readTable();
|
| 170 |
if(!rows.length){ toast("لا يوجد بيانات لتصديرها."); return; }
|
|
@@ -181,27 +172,19 @@ async function exportExcel(){
|
|
| 181 |
const filename = `${base}_${ts}.xlsx`;
|
| 182 |
|
| 183 |
const wbArray = XLSX.write(wb, { bookType: "xlsx", type: "array" });
|
| 184 |
-
const blob = new Blob([wbArray], {
|
| 185 |
-
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
| 186 |
-
});
|
| 187 |
const file = new File([blob], filename, { type: blob.type });
|
| 188 |
|
| 189 |
if (navigator.canShare && navigator.canShare({ files: [file] })) {
|
| 190 |
-
try {
|
| 191 |
-
|
| 192 |
-
toast("تمت المشاركة/الحفظ بنجاح.");
|
| 193 |
-
return;
|
| 194 |
-
} catch(e) { /* أُغلقت ورقة المشاركة – نكمل بالتنزيل */ }
|
| 195 |
}
|
| 196 |
-
|
| 197 |
const url = URL.createObjectURL(blob);
|
| 198 |
-
const a = document.createElement("a");
|
| 199 |
-
a.href = url; a.download = filename;
|
| 200 |
document.body.appendChild(a); a.click(); a.remove();
|
| 201 |
setTimeout(()=>URL.revokeObjectURL(url), 1000);
|
| 202 |
toast("تم تنزيل الملف.");
|
| 203 |
}
|
| 204 |
-
|
| 205 |
/* نسخ الجدول كـTSV للصق مباشر في Excel */
|
| 206 |
async function copyToClipboardTSV(){
|
| 207 |
const rows = readTable();
|
|
@@ -209,17 +192,13 @@ async function copyToClipboardTSV(){
|
|
| 209 |
const header = EXPORT_COLUMNS.join("\t");
|
| 210 |
const body = rows.map(r=>EXPORT_COLUMNS.map(c=>(r[c]||"").replace(/\t/g," ")).join("\t")).join("\n");
|
| 211 |
const tsv = `${header}\n${body}`;
|
| 212 |
-
try{
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
}catch(e){
|
| 216 |
-
const ta = document.createElement("textarea");
|
| 217 |
-
ta.value = tsv; document.body.appendChild(ta);
|
| 218 |
ta.select(); document.execCommand("copy"); document.body.removeChild(ta);
|
| 219 |
toast("تم النسخ — الصق/ي مباشرة في Excel.");
|
| 220 |
}
|
| 221 |
}
|
| 222 |
-
|
| 223 |
/* المثال المطلوب */
|
| 224 |
const SAMPLE = `نوع المشكلة : لا استطيع اكمال الاستمارة بسبب تعليق
|
| 225 |
وقت حدوث المشكلة: 21/8/2025
|
|
@@ -229,34 +208,8 @@ const SAMPLE = `نوع المشكلة : لا استطيع اكمال الاست
|
|
| 229 |
رقم الجوال: 0558174717
|
| 230 |
اسم المسح: الخبر
|
| 231 |
المنطقة: الشرقية`;
|
| 232 |
-
|
| 233 |
document.addEventListener("DOMContentLoaded", ()=>{
|
| 234 |
const parseBtn = document.getElementById("btn-parse");
|
| 235 |
const exportBtn = document.getElementById("btn-export");
|
| 236 |
const copyBtn = document.getElementById("btn-copy");
|
| 237 |
-
const clearBtn = document.
|
| 238 |
-
const sampleBtn = document.getElementById("btn-sample");
|
| 239 |
-
const rawEl = document.getElementById("raw");
|
| 240 |
-
|
| 241 |
-
parseBtn.addEventListener("click", ()=>{
|
| 242 |
-
const raw = rawEl.value || SAMPLE;
|
| 243 |
-
const rows = parseTickets(raw);
|
| 244 |
-
buildTable(rows);
|
| 245 |
-
updateCount(rows.length);
|
| 246 |
-
setButtonsEnabled(rows.length>0);
|
| 247 |
-
toast(`تم استخراج ${rows.length} ${rows.length===1 ? "تذكرة" : "تذاكر"}.`);
|
| 248 |
-
});
|
| 249 |
-
|
| 250 |
-
exportBtn.addEventListener("click", exportExcel);
|
| 251 |
-
copyBtn.addEventListener("click", copyToClipboardTSV);
|
| 252 |
-
|
| 253 |
-
clearBtn.addEventListener("click", ()=>{
|
| 254 |
-
rawEl.value = "";
|
| 255 |
-
document.getElementById("tbody").innerHTML = "";
|
| 256 |
-
updateCount(0);
|
| 257 |
-
setButtonsEnabled(false);
|
| 258 |
-
});
|
| 259 |
-
|
| 260 |
-
sampleBtn.addEventListener("click", ()=>{ rawEl.value = SAMPLE; });
|
| 261 |
-
|
| 262 |
-
setButtonsEnabled(false);
|
|
|
|
| 39 |
}
|
| 40 |
function normalizeDate(v){
|
| 41 |
v=(v||"").trim();
|
| 42 |
+
let m=v.match(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2,4})/);
|
| 43 |
if(m){
|
| 44 |
let d=+m[1], mo=+m[2], y=+m[3]; if(y<100) y+=2000;
|
| 45 |
return `${y.toString().padStart(4,"0")}-${String(mo).padStart(2,"0")}-${String(d).padStart(2,"0")}`;
|
| 46 |
}
|
| 47 |
+
m=v.match(/(\d{4})[\/\-](\d{1,2})[\/\-](\d{1,2})/);
|
| 48 |
if(m){
|
| 49 |
let y=+m[1], mo=+m[2], d=+m[3];
|
| 50 |
return `${y.toString().padStart(4,"0")}-${String(mo).padStart(2,"0")}-${String(d).padStart(2,"0")}`;
|
|
|
|
| 111 |
}
|
| 112 |
return data;
|
| 113 |
}
|
|
|
|
| 114 |
function parseTickets(raw){ return splitTickets(raw||"").map(extractFields); }
|
| 115 |
|
| 116 |
function buildTable(rows){
|
|
|
|
| 134 |
tbody.appendChild(tr);
|
| 135 |
});
|
| 136 |
}
|
|
|
|
| 137 |
function readTable(){
|
| 138 |
const tbody = document.getElementById("tbody");
|
| 139 |
const rows = [];
|
|
|
|
| 144 |
});
|
| 145 |
return rows;
|
| 146 |
}
|
| 147 |
+
function updateCount(n){ document.getElementById("countChip").textContent = `عدد التذاكر: ${n}`; }
|
|
|
|
|
|
|
|
|
|
| 148 |
function setButtonsEnabled(hasRows){
|
| 149 |
document.getElementById("btn-export").disabled = !hasRows;
|
| 150 |
document.getElementById("btn-copy").disabled = !hasRows;
|
| 151 |
}
|
| 152 |
function toast(msg){
|
| 153 |
const t = document.getElementById("toast");
|
| 154 |
+
t.textContent = msg; t.hidden = false;
|
| 155 |
+
t.classList.remove("show"); void t.offsetWidth; t.classList.add("show");
|
|
|
|
|
|
|
|
|
|
| 156 |
setTimeout(()=>{ t.hidden = true; }, 2400);
|
| 157 |
}
|
| 158 |
+
/* تصدير/مشاركة Excel: Web Share أولاً ثم تنزيل كبديل */
|
|
|
|
| 159 |
async function exportExcel(){
|
| 160 |
const rows = readTable();
|
| 161 |
if(!rows.length){ toast("لا يوجد بيانات لتصديرها."); return; }
|
|
|
|
| 172 |
const filename = `${base}_${ts}.xlsx`;
|
| 173 |
|
| 174 |
const wbArray = XLSX.write(wb, { bookType: "xlsx", type: "array" });
|
| 175 |
+
const blob = new Blob([wbArray], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
|
|
|
|
|
|
|
| 176 |
const file = new File([blob], filename, { type: blob.type });
|
| 177 |
|
| 178 |
if (navigator.canShare && navigator.canShare({ files: [file] })) {
|
| 179 |
+
try { await navigator.share({ files: [file], title: "ملف التذاكر" }); toast("تمت المشاركة/الحفظ بنجاح."); return; }
|
| 180 |
+
catch(e){ /* المستخدم أغلق ورقة المشاركة */ }
|
|
|
|
|
|
|
|
|
|
| 181 |
}
|
|
|
|
| 182 |
const url = URL.createObjectURL(blob);
|
| 183 |
+
const a = document.createElement("a"); a.href = url; a.download = filename;
|
|
|
|
| 184 |
document.body.appendChild(a); a.click(); a.remove();
|
| 185 |
setTimeout(()=>URL.revokeObjectURL(url), 1000);
|
| 186 |
toast("تم تنزيل الملف.");
|
| 187 |
}
|
|
|
|
| 188 |
/* نسخ الجدول كـTSV للصق مباشر في Excel */
|
| 189 |
async function copyToClipboardTSV(){
|
| 190 |
const rows = readTable();
|
|
|
|
| 192 |
const header = EXPORT_COLUMNS.join("\t");
|
| 193 |
const body = rows.map(r=>EXPORT_COLUMNS.map(c=>(r[c]||"").replace(/\t/g," ")).join("\t")).join("\n");
|
| 194 |
const tsv = `${header}\n${body}`;
|
| 195 |
+
try{ await navigator.clipboard.writeText(tsv); toast("تم النسخ — الصق/ي مباشرة في Excel."); }
|
| 196 |
+
catch(e){
|
| 197 |
+
const ta = document.createElement("textarea"); ta.value = tsv; document.body.appendChild(ta);
|
|
|
|
|
|
|
|
|
|
| 198 |
ta.select(); document.execCommand("copy"); document.body.removeChild(ta);
|
| 199 |
toast("تم النسخ — الصق/ي مباشرة في Excel.");
|
| 200 |
}
|
| 201 |
}
|
|
|
|
| 202 |
/* المثال المطلوب */
|
| 203 |
const SAMPLE = `نوع المشكلة : لا استطيع اكمال الاستمارة بسبب تعليق
|
| 204 |
وقت حدوث المشكلة: 21/8/2025
|
|
|
|
| 208 |
رقم الجوال: 0558174717
|
| 209 |
اسم المسح: الخبر
|
| 210 |
المنطقة: الشرقية`;
|
|
|
|
| 211 |
document.addEventListener("DOMContentLoaded", ()=>{
|
| 212 |
const parseBtn = document.getElementById("btn-parse");
|
| 213 |
const exportBtn = document.getElementById("btn-export");
|
| 214 |
const copyBtn = document.getElementById("btn-copy");
|
| 215 |
+
const clearBtn = document.getElement
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|