feat(khira): application-oriented error form with drafts and database cleanup

This commit is contained in:
2026-10-28 11:11:51 +05:30
parent db9c1a5840
commit 1bcc0d5dda
7 changed files with 943 additions and 90 deletions
+428 -44
View File
@@ -66,7 +66,7 @@ const PRI=[['P0','P0 · Critical'],['P1','P1 · High'],['P2','P2 · Medium'],['P
const SEV=[['CRITICAL','Critical'],['HIGH','High'],['MEDIUM','Medium'],['LOW','Low']];
const STAT={open:'Open',progress:'In progress',hold:'On hold',completed:'Completed'};
const COLS=[['open','var(--out)'],['progress','var(--pri)'],['hold','var(--on-warn-c)'],['completed','var(--on-ter-c)']];
const EL={unresolved:'Unresolved',escalated:'Escalated',resolved:'Resolved'};
const EL={draft:'Drafts',unresolved:'Unresolved',escalated:'Escalated',resolved:'Resolved'};
const EMOJIS=['⚡','👩‍💻','👨‍💻','🕵️‍♂️','👤','🚀','🛡️','🎨','🤖','🦊','🦉','🦁','🔥','💡','🎯','⚙️','🌟','💻'];
/* ── API ── */
@@ -99,7 +99,7 @@ const priFull=t=>{
return 'Low';
};
const st=t=>{const s=(t.status||'open').toLowerCase();return s==='in_progress'?'progress':s==='on_hold'?'hold':s};
const ek=e=>e.status==='resolved'?'resolved':e.escalated_ticket_id?'escalated':'unresolved';
const ek=e=>(e.is_draft||e.status==='draft')?'draft':e.status==='resolved'?'resolved':(e.escalated_ticket_id||e.linked_ticket_id)?'escalated':'unresolved';
const isAdmin=u=>u&&(u.username==='admin'||u.role==='team_lead'||u.role==='lead');
const roleClass=u=>{
@@ -290,7 +290,7 @@ async function refresh(anim){
const [tr,ts,er,es,nr,ur]=await Promise.all([
api('/khira/api/tickets?limit=100'),
api('/khira/api/stats'),
api('/khira/api/errors?limit=100'),
api('/khira/api/errors?status=all_with_drafts&limit=100'),
api('/khira/api/errors/stats'),
api('/khira/api/notifications'),
api('/khira/api/users')
@@ -497,28 +497,91 @@ function initBoardDragDrop(){
});
}
const verFmt=v=>!v?'':(String(v).toLowerCase().startsWith('v')?' ':' v')+esc(v);
/* ── Errors View ── */
function renderE(anim){
const s=S.es;
put('#estats',tile(s.total,'Total','et')+tile(s.unresolved,'Unresolved','eu')+tile(s.escalated,'Escalated','ee')+tile(s.resolved,'Resolved','er'));
const archErrCount=S.e.filter(e=>e.archived).length;
const eChips=[['','All'],...Object.entries(EL),['archived',`Archived (${archErrCount})`]];
const draftCount=S.e.filter(e=>e.is_draft||e.status==='draft').length;
put('#estats',tile(s.total,'Total','et')+tile(s.unresolved,'Unresolved','eu')+tile(draftCount,'Drafts','ed')+tile(s.resolved,'Resolved','er'));
const archErrCount=S.e.filter(e=>e.archived&&!e.is_draft).length;
const eChips=[['','All Published'],['draft',`Drafts (${draftCount})`],['unresolved','Unresolved'],['escalated','Escalated'],['resolved','Resolved'],['archived',`Archived (${archErrCount})`]];
put('#eChips',chipRow(eChips,S.ef,'data-ef'));
const f=S.e.filter(e=>{
if(S.ef==='archived'){
if(!e.archived)return false;
const isDr=e.is_draft||e.status==='draft';
if(S.ef==='draft'){
if(!isDr)return false;
}else if(S.ef==='archived'){
if(!e.archived||isDr)return false;
}else if(!S.ef){
if(e.archived||isDr)return false;
}else{
if(e.archived)return false;
if(S.ef&&ek(e)!==S.ef)return false;
if(e.archived||isDr||ek(e)!==S.ef)return false;
}
return!S.q||[e.id,e.exception_type,e.message,e.endpoint,e.app,e.app_name].join(' ').toLowerCase().includes(S.q);
return!S.q||[e.id,e.exception_type,e.message,e.description,e.endpoint,e.app,e.app_name,e.feature_name,e.error_screen,e.platform,e.assigned_to].join(' ').toLowerCase().includes(S.q);
});
const draftBannerHtml=(draftCount>0&&S.ef!=='draft')?`
<div class="draft-banner">
<span>📝 You have <b>${draftCount}</b> saved error draft(s) available to edit and send.</span>
<button type="button" class="chip draft-btn" id="btnViewDrafts">View Drafts (${draftCount})</button>
</div>`:'' ;
$('#elist').classList.toggle('anim',!!anim);
put('#elist',f.length?f.map((e,i)=>{
put('#elist',draftBannerHtml+(f.length?f.map((e,i)=>{
const sev=(e.severity||'MEDIUM').toUpperCase(),k=ek(e);
const isArch=!!e.archived;
return`<div class="li" tabindex="0" role="button" data-e="${esc(e.id)}" style="--i:${Math.min(i,12)}"><span class="lead sv ${sev}">${ic('error',16)}</span><div class="ell"><h4 class="ell mono" style="font-size:14px">${esc(e.exception_type)}</h4><p class="ell">${esc(e.message)}</p><p class="ell">${esc(e.id)} · ${esc(e.app||e.app_name||'—')} · ${esc(e.endpoint||'—')}</p></div><div class="tl2"><span class="stt ${isArch?'archived':k}">${isArch?'Archived':EL[k]}</span><span>${e.events||e.occurrences||1} events · ${ago(e.last_seen)}</span></div></div>`;
}).join(''):`<div class="big">${ic('bug_report',36)}<p>No errors tracked.</p></div>`);
const isDr=e.is_draft||e.status==='draft';
const platChip=`<span class="meta-chip ${e.platform==='Android'?'android':'ios'}">${e.platform==='Android'?'🤖 Android':'🍏 iOS'}</span>`;
const typeChip=`<span class="meta-chip ${e.error_type==='Crash'?'crash':'bug'}">${esc(e.error_type||'Bug')}</span>`;
const phaseChip=e.current_phase?`<span class="meta-chip">${esc(e.current_phase)}</span>`:'';
if(isDr){
return`<div class="li" tabindex="0" role="button" data-e="${esc(e.id)}" style="--i:${Math.min(i,12)}">
<span class="lead sv" style="background:rgba(245,158,11,0.2);color:#fbbf24">${ic('ticket',16)}</span>
<div class="ell">
<div style="display:flex;gap:6px;align-items:center;margin-bottom:3px">
<span class="stt draft">Draft</span>
${platChip}
${typeChip}
${phaseChip}
</div>
<h4 class="ell" style="font-size:14px">${esc(e.app_name||'Draft Application')}${verFmt(e.version)}${e.error_screen?' · '+esc(e.error_screen):''}</h4>
<p class="ell">${esc(e.description||e.message||'(No description provided)')}</p>
<p class="ell" style="font-size:11px;color:var(--on-sv)">${esc(e.id)}${e.assigned_to?' · Sent to @'+esc(e.assigned_to):' · Unassigned'}${e.image_url?' · 📷 Image attached':''}</p>
</div>
<div class="tl2">
<button type="button" class="tn draft-btn" style="height:26px;font-size:11px" onclick="event.stopPropagation();reportErr(S.e.find(x=>x.id==='${esc(e.id)}'))">✏️ Edit & Send</button>
<span>${ago(e.last_seen||e.created_at)}</span>
</div>
</div>`;
}
return`<div class="li" tabindex="0" role="button" data-e="${esc(e.id)}" style="--i:${Math.min(i,12)}">
<span class="lead sv ${sev}">${ic('error',16)}</span>
<div class="ell">
<div style="display:flex;gap:6px;align-items:center;margin-bottom:3px">
${platChip}
${typeChip}
${phaseChip}
</div>
<h4 class="ell" style="font-size:14px">${esc(e.app_name||e.app||'Application')}${verFmt(e.version)}${e.error_screen?' · '+esc(e.error_screen):''}${e.feature_name?' ('+esc(e.feature_name)+')':''}</h4>
<p class="ell">${esc(e.description||e.message)}</p>
<p class="ell" style="font-size:11px;color:var(--on-sv)">${esc(e.id)}${e.assigned_to?' · Assigned to @'+esc(e.assigned_to):''}${e.image_url?' · 📷 Image attached':''}</p>
</div>
<div class="tl2">
<span class="stt ${isArch?'archived':k}">${isArch?'Archived':EL[k]||k}</span>
<span>${e.events||e.occurrences||1} events · ${ago(e.last_seen||e.created_at)}</span>
</div>
</div>`;
}).join(''):`<div class="big">${ic('bug_report',36)}<p>No errors tracked.</p></div>`));
$('#btnViewDrafts')?.addEventListener('click',()=>{
S.ef='draft';
renderE(true);
});
put('#title','Error Tracking');
}
@@ -1275,14 +1338,44 @@ function newTicket(){
/* ── Error Details & Escalation ── */
function errD(id){
const e=S.e.find(x=>x.id===id);if(!e)return;const k=ek(e);
const e=S.e.find(x=>x.id===id);if(!e)return;
if(e.is_draft||e.status==='draft'){
return reportErr(e);
}
const k=ek(e);
const blk=(l,v)=>v?`<div><p class="lbl">${l}</p><pre class="code">${esc(v)}</pre></div>`:'';
const appName=e.app||e.app_name||'';
const appName=e.app_name||e.app||'';
const isArch=!!e.archived;
dlg({wide:1,title:esc(e.exception_type),sub:esc(`${e.id} · ${appName}${e.environment?' · '+e.environment:''}`),
body:`<div class="r"><span class="sv ${(e.severity||'').toUpperCase()}">${esc(e.severity)}</span><span class="stt ${isArch?'archived':k}">${isArch?'Archived':EL[k]}</span><span class="id">${e.events||e.occurrences||1} events · ${ago(e.last_seen)}</span></div>
${appName?`<div style="margin:10px 0"><button type="button" class="chip" id="btnLogMoreForApp" style="background:var(--sec-c);font-weight:500"><svg class="btn-ic" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:middle;margin-right:6px"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="16"/><line x1="8" y1="12" x2="16" y2="12"/></svg>Log another error for ${esc(appName)}</button></div>`:''}
<p>${esc(e.message)}</p>${blk('Endpoint',e.endpoint)}${blk('Stack trace',e.stack_trace)}${blk('Payload',e.payload||e.request_payload)}${e.escalated_ticket_id||e.linked_ticket_id?`<p class="sub">Escalated as ${esc(e.escalated_ticket_id||e.linked_ticket_id)}</p>`:''}${e.resolution_notes?`<p class="sub">Resolution: ${esc(e.resolution_notes)}</p>`:''}`,
const platChip=`<span class="meta-chip ${e.platform==='Android'?'android':'ios'}">${e.platform==='Android'?'🤖 Android':'🍏 iOS'}</span>`;
const typeChip=`<span class="meta-chip ${e.error_type==='Crash'?'crash':'bug'}">${esc(e.error_type||'Bug')}</span>`;
const phaseChip=e.current_phase?`<span class="meta-chip">${esc(e.current_phase)}</span>`:'';
const imgHtml=e.image_url?`<div style="margin:12px 0">
<p class="lbl">Attached Image / Screenshot</p>
<a href="${esc(e.image_url)}" target="_blank" rel="noopener">
<img src="${esc(e.image_url)}" alt="Error attachment" style="max-width:100%;max-height:260px;border-radius:12px;border:1px solid rgba(255,255,255,0.15);box-shadow:0 4px 16px rgba(0,0,0,0.6)">
</a>
</div>`:'';
dlg({wide:1,title:esc(e.exception_type||e.error_type||'Application Error'),sub:esc(`${e.id} · ${appName}${verFmt(e.version)}${e.error_screen?' · Screen: '+e.error_screen:''}`),
body:`<div class="r" style="gap:8px;align-items:center;margin-bottom:8px">
<span class="sv ${(e.severity||'MEDIUM').toUpperCase()}">${esc(e.severity||'Medium')}</span>
<span class="stt ${isArch?'archived':k}">${isArch?'Archived':EL[k]||k}</span>
${platChip}
${typeChip}
${phaseChip}
<span class="id" style="margin-left:auto">${e.events||e.occurrences||1} events · ${ago(e.last_seen||e.created_at)}</span>
</div>
${e.feature_name?`<p style="font-size:12px;color:var(--pri);margin-bottom:6px"><b>Feature:</b> ${esc(e.feature_name)}</p>`:''}
${e.assigned_to?`<p style="font-size:12px;color:#a78bfa;margin-bottom:8px"><b>Assigned to Developer:</b> @${esc(e.assigned_to)}</p>`:''}
<div style="font-size:14px;line-height:1.6;color:var(--on-s);margin:10px 0;white-space:pre-wrap"><b>Description:</b><br>${esc(e.description||e.message)}</div>
${imgHtml}
${blk('Additional Info & Reproduction',e.additional_info)}
${blk('Endpoint / Route',e.endpoint)}
${blk('Stack Trace / Logs',e.stack_trace)}
${e.escalated_ticket_id||e.linked_ticket_id?`<p class="sub">Escalated as ${esc(e.escalated_ticket_id||e.linked_ticket_id)}</p>`:''}
${e.resolution_notes?`<p class="sub">Resolution: ${esc(e.resolution_notes)}</p>`:''}`,
ok:k==='resolved'?'Close':'Escalate to ticket',
alt:k==='unresolved'?['Resolve',()=>resolveD(id)]:(k==='resolved'?[(isArch?'Restore':'Archive'),async()=>{
const actName=isArch?'unarchive':'archive';
@@ -1292,19 +1385,13 @@ function errD(id){
$('#dlg').close();
await refresh();
}]:undefined),
init:f=>{
f.querySelector('#btnLogMoreForApp')?.addEventListener('click',()=>{
$('#dlg').close();
reportErr({app_name:appName,environment:e.environment,service:e.service,continue_app:true});
});
},
go:()=>k!=='resolved'&&escD(id)});
}
function escD(id){
const e=S.e.find(x=>x.id===id);
dlg({title:'Escalate error to ticket',sub:e.id,
body:fld('title','Ticket title',{req:1,v:`[${e.app||e.app_name}] ${e.exception_type}: ${e.message.slice(0,60)}`})+fld('priority','Priority',{t:'select',opts:PRI,v:'P1'})+fld('assignee','Assign to',{t:'select',opts:usOpts(1),req:1}),
body:fld('title','Ticket title',{req:1,v:`[${e.platform||'App'} · ${e.app||e.app_name}] ${e.exception_type||e.error_type}: ${e.message.slice(0,60)}`})+fld('priority','Priority',{t:'select',opts:PRI,v:'P1'})+fld('assignee','Assign to',{t:'select',opts:usOpts(1),req:1,v:e.assigned_to||''}),
ok:'Escalate',go:async v=>{
const r=await api(`/khira/api/errors/${encodeURIComponent(id)}/escalate`,'POST',{title:v.title,priority:v.priority,assigned_to:v.assignee});
if(r._f){toast(r.error,'err');return false}
@@ -1321,27 +1408,324 @@ function resolveD(id){
}});
}
/* ── Application-Oriented Error Reporting Form with Drafts ── */
function reportErr(prefill={}){
const currentApp=prefill.app_name||prefill.app||'';
const continueMode=!!prefill.continue_app;
const isEdit=!!prefill.id;
const isDraft=!!(prefill.is_draft||prefill.status==='draft');
const d=$('#dlg');
d.className='wide';
dlg({title:continueMode&&currentApp?`Testing Phase: Assigning Errors for ${esc(currentApp)}`:'Report runtime error',
sub:continueMode?'Log continuous errors for this application with automatic re-prompting.':'Simulate an exception from a service.',
body:fld('app','Application',{t:'select',opts:EAPPS,req:1,v:currentApp})+fld('exception_type','Exception type',{req:1,v:'InternalServerError',opts:['CrashException','NetworkTimeoutException','AuthTokenExpiredException','TextureBindingException','ShaderCompileError','OutOfMemoryError']})+fld('message','Message',{t:'area',rows:2,req:1,v:'Unexpected fatal crash on render loop'})+fld('severity','Severity',{t:'select',opts:SEV,v:'HIGH'})+fld('environment','Environment',{req:1,v:prefill.environment||'Production'})+fld('endpoint','Endpoint',{v:prefill.endpoint||'/api/v1/render'})+fld('stack_trace','Stack trace',{t:'area',rows:3,mono:1,v:'Error at Engine.render (engine.js:42:15)'}),
ok:continueMode?'Submit & Log Another':'Report error',
alt:continueMode?['Submit & Done',null]:undefined,
go:async v=>{
const r=await api('/khira/api/errors','POST',{app_name:v.app,exception_type:v.exception_type,message:v.message,severity:v.severity.toLowerCase(),environment:v.environment,service:v.app,endpoint:v.endpoint,stack_trace:v.stack_trace});
if(r._f){toast(r.error,'err');return false}
toast('Error reported');
await refresh();
const curPlatform=prefill.platform||'iOS';
const curPhase=prefill.current_phase||'development phase';
const curErrorType=prefill.error_type||'Bug';
const curAppName=prefill.app_name||prefill.app||'';
const curVersion=prefill.version||'';
const curScreen=prefill.error_screen||'';
const curFeature=prefill.feature_name||prefill.service||'';
const curDesc=prefill.description||prefill.message||'';
const curAddInfo=prefill.additional_info||prefill.stack_trace||'';
const curImg=prefill.image_url||'';
const curAssignee=prefill.assigned_to||'';
if(continueMode){
setTimeout(()=>{
reportErr({app_name:v.app,environment:v.environment,endpoint:v.endpoint,continue_app:true});
},150);
const titleText=isEdit?(isDraft?`Edit Error Draft · ${esc(prefill.id)}`:`Edit Error · ${esc(prefill.id)}`):'Report Application Error';
const subText=isDraft?'Edit draft fields and send to developer or save for later.':'Submit application bugs and crashes, or save as draft before final publishing.';
d.innerHTML=`<form class="dc" id="errReportForm" novalidate>
<h3>${titleText}</h3>
<p class="sub">${subText}</p>
<div class="db" style="padding-top:14px">
<!-- Platform & Current Phase Selection -->
<div class="err-form-grid">
<div class="form-seg-group">
<label class="form-seg-label">Platform *</label>
<div class="seg-pills" id="platformPills">
<button type="button" class="seg-pill ${curPlatform==='iOS'?'on':''}" data-v="iOS">
<svg class="ic" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20.94c1.5 0 2.75 1.06 4 1.06 3 0 6-8 6-12.22A4.91 4.91 0 0 0 17 5c-2.22 0-4 1.44-5 2-1-.56-2.78-2-5-2a4.9 4.9 0 0 0-5 4.78C2 14 5 22 8 22c1.25 0 2.5-1.06 4-1.06Z"/><path d="M10 2c1 .5 2 2 2 5"/></svg>
iOS
</button>
<button type="button" class="seg-pill ${curPlatform==='Android'?'on':''}" data-v="Android">
<svg class="ic" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 18a5 5 0 0 0-10 0"/><line x1="12" y1="2" x2="12" y2="4"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="19.78" y1="4.22" x2="18.36" y2="5.64"/><circle cx="9" cy="9" r="1"/><circle cx="15" cy="9" r="1"/></svg>
Android
</button>
</div>
<input type="hidden" name="platform" id="inputPlatform" value="${esc(curPlatform)}">
</div>
<div class="form-seg-group">
<label class="form-seg-label">Current Phase *</label>
<div class="seg-pills" id="phasePills">
<button type="button" class="seg-pill ${curPhase==='development phase'?'on':''}" data-v="development phase">Development Phase</button>
<button type="button" class="seg-pill ${curPhase==='ready to live'?'on':''}" data-v="ready to live">Ready to Live</button>
</div>
<input type="hidden" name="current_phase" id="inputPhase" value="${esc(curPhase)}">
</div>
</div>
<!-- App Name & Version -->
<div class="err-form-grid">
<label class="fld">
<input name="app_name" id="errAppName" list="appNameSuggestions" placeholder=" " value="${esc(curAppName)}" required>
<span>App name *</span>
<datalist id="appNameSuggestions">
<option value="Creator Suite iOS">
<option value="Creator Suite Android">
<option value="Image Manipulator Pro">
<option value="Unified Dashboard Client">
<option value="Khira Issue Tracker">
<option value="FastAPI Backend">
</datalist>
</label>
<label class="fld">
<input name="version" id="errVersion" placeholder=" " value="${esc(curVersion)}">
<span>Version (e.g. 1.0.0)</span>
</label>
</div>
<!-- Error Screen & Feature Name -->
<div class="err-form-grid">
<label class="fld">
<input name="error_screen" id="errScreen" placeholder=" " value="${esc(curScreen)}">
<span>Error screen (e.g. Login, Canvas, Settings)</span>
</label>
<label class="fld">
<input name="feature_name" id="errFeature" placeholder=" " value="${esc(curFeature)}">
<span>Feature name (e.g. Biometric Auth, Face Swap)</span>
</label>
</div>
<!-- Error Type -->
<div class="form-seg-group">
<label class="form-seg-label">Error Type *</label>
<div class="seg-pills" id="errTypePills">
<button type="button" class="seg-pill bug-pill ${curErrorType==='Bug'?'on':''}" data-v="Bug">
${ic('bug', 15)} Bug
</button>
<button type="button" class="seg-pill crash-pill ${curErrorType==='Crash'?'on':''}" data-v="Crash">
${ic('warning', 15)} Crash
</button>
</div>
<input type="hidden" name="error_type" id="inputErrType" value="${esc(curErrorType)}">
</div>
<!-- Description (Describe error) -->
<label class="fld">
<textarea name="description" id="errDesc" rows="3" placeholder=" " required>${esc(curDesc)}</textarea>
<span>Description (Describe error) *</span>
</label>
<!-- Attach image if you want to -->
<div class="err-attach-group">
<label class="form-seg-label">Attach image (Optional)</label>
<div class="err-upload-box" id="errImgUploadBox">
<input type="file" id="errImgFileInput" accept="image/*" style="display:none">
<input type="hidden" name="image_url" id="errImgUrlInput" value="${esc(curImg)}">
<div id="errImgPlaceholder" class="err-upload-placeholder" ${curImg?'hidden':''}>
<svg class="ic" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>
<span>Click to attach screenshot or drag &amp; drop</span>
</div>
<div id="errImgPreviewWrap" class="err-upload-preview" ${curImg?'':'hidden'}>
<img id="errImgThumb" src="${esc(curImg)}" alt="Attached preview">
<div class="err-upload-meta">
<span id="errImgName" class="ell">${curImg?esc(curImg.split('/').pop()):''}</span>
<button type="button" class="tn err-rm-img-btn" id="btnRmErrImg">&times; Remove image</button>
</div>
</div>
</div>
</div>
<!-- Any additional info -->
<label class="fld">
<textarea name="additional_info" id="errAddInfo" rows="2" placeholder=" ">${esc(curAddInfo)}</textarea>
<span>Any additional info (Device model, OS build, reproduction steps)</span>
</label>
<!-- Send to Developer or another person -->
<label class="fld sel">
<select name="assigned_to" id="errAssigneeSelect">
<option value="">None (Unassigned)</option>
${S.us.map(u=>`<option value="${esc(u.username)}"${u.username===curAssignee?' selected':''}>${esc(u.name)} · ${esc(u.role_display)}</option>`).join('')}
</select>
<span>Send / Assign to Developer (Optional)</span>
</label>
</div>
<!-- Actions Bar -->
<div class="da" style="align-items:center;padding:12px 24px 0">
<button type="button" class="tb" data-x>Cancel</button>
${isEdit?`<button type="button" class="tb del-draft-btn" id="btnDeleteErr" style="color:#ef4444">${ic('delete',15)} Delete</button>`:''}
<div style="flex:1"></div>
<button type="button" class="tb draft-btn" id="btnSaveDraft">
<svg class="ic" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:middle;margin-right:4px"><path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/><polyline points="17 21 17 13 7 13 7 21"/><polyline points="7 3 7 8 15 8"/></svg>
Save as draft
</button>
<button type="submit" class="fb submit-err-btn" id="btnSubmitErr">
<svg class="ic" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:middle;margin-right:4px"><line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/></svg>
${isEdit&&isDraft?'Publish & Send':'Submit'}
</button>
</div>
</form>`;
const form=$('#errReportForm');
// Interactive Pill Switchers
const bindPillGroup=(containerId, hiddenInputId)=>{
const wrap=form.querySelector(containerId);
const inp=form.querySelector(hiddenInputId);
if(!wrap||!inp)return;
wrap.querySelectorAll('.seg-pill').forEach(btn=>{
btn.onclick=()=>{
wrap.querySelectorAll('.seg-pill').forEach(b=>b.classList.remove('on'));
btn.classList.add('on');
inp.value=btn.dataset.v;
};
});
};
bindPillGroup('#platformPills','#inputPlatform');
bindPillGroup('#phasePills','#inputPhase');
bindPillGroup('#errTypePills','#inputErrType');
// Image Upload Binding
const uploadBox=form.querySelector('#errImgUploadBox');
const fileInput=form.querySelector('#errImgFileInput');
const imgUrlInput=form.querySelector('#errImgUrlInput');
const placeholder=form.querySelector('#errImgPlaceholder');
const previewWrap=form.querySelector('#errImgPreviewWrap');
const thumb=form.querySelector('#errImgThumb');
const imgName=form.querySelector('#errImgName');
const rmBtn=form.querySelector('#btnRmErrImg');
uploadBox.onclick=(e)=>{
if(e.target.closest('#btnRmErrImg'))return;
fileInput.click();
};
fileInput.onchange=async()=>{
const file=fileInput.files[0];
if(!file)return;
const fd=new FormData();
fd.append('file',file);
try{
toast('Uploading image...');
const res=await fetch('/khira/api/upload',{
method:'POST',
headers:{'X-Khira-User':S.u?.username||''},
body:fd
});
const data=await res.json();
if(data.status==='ok'&&data.attachment){
imgUrlInput.value=data.attachment.url;
thumb.src=data.attachment.url;
imgName.textContent=file.name;
placeholder.hidden=true;
previewWrap.hidden=false;
toast('Image attached');
}else{
toast(data.error||'Failed to upload image','err');
}
}catch(err){
toast('Upload failed','err');
}
}});
};
rmBtn.onclick=(e)=>{
e.stopPropagation();
imgUrlInput.value='';
fileInput.value='';
thumb.src='';
imgName.textContent='';
placeholder.hidden=false;
previewWrap.hidden=true;
};
// Helper to collect payload
const getPayload=(asDraft)=>{
const app=form.querySelector('#errAppName').value.trim()||(asDraft?'Draft Application':'');
const desc=form.querySelector('#errDesc').value.trim()||(asDraft?'(Draft description)':'');
const errType=form.querySelector('#inputErrType').value||'Bug';
return {
platform:form.querySelector('#inputPlatform').value||'iOS',
current_phase:form.querySelector('#inputPhase').value||'development phase',
app_name:app,
version:form.querySelector('#errVersion').value.trim(),
error_screen:form.querySelector('#errScreen').value.trim(),
feature_name:form.querySelector('#errFeature').value.trim(),
error_type:errType,
exception_type:errType,
description:desc,
message:desc,
image_url:imgUrlInput.value,
additional_info:form.querySelector('#errAddInfo').value.trim(),
assigned_to:form.querySelector('#errAssigneeSelect').value,
is_draft:asDraft
};
};
// Save as draft handler
form.querySelector('#btnSaveDraft')?.addEventListener('click',async()=>{
const payload=getPayload(true);
const saveBtn=form.querySelector('#btnSaveDraft');
await busy(saveBtn,async()=>{
let r;
if(isEdit){
r=await api(`/khira/api/errors/${encodeURIComponent(prefill.id)}`,'PUT',payload);
}else{
r=await api('/khira/api/errors','POST',payload);
}
if(r._f||typeof r.error==='string'){
toast((typeof r.error==='string'?r.error:'')||'Failed to save draft','err');
return;
}
toast('Draft saved successfully');
d.close();
await refresh();
});
});
// Submit handler (Publish)
form.onsubmit=async(e)=>{
e.preventDefault();
const app=form.querySelector('#errAppName').value.trim();
const desc=form.querySelector('#errDesc').value.trim();
if(!app){toast('Please enter an app name','err');return}
if(!desc){toast('Please describe the error','err');return}
const payload=getPayload(false);
const submitBtn=form.querySelector('#btnSubmitErr');
await busy(submitBtn,async()=>{
let r;
if(isEdit){
r=await api(`/khira/api/errors/${encodeURIComponent(prefill.id)}`,'PUT',payload);
}else{
r=await api('/khira/api/errors','POST',payload);
}
if(r._f||typeof r.error==='string'){
toast((typeof r.error==='string'?r.error:'')||'Failed to submit error','err');
return;
}
const sentNotice=payload.assigned_to?` and sent to @${payload.assigned_to}`:'';
toast(isEdit&&isDraft?`Draft published${sentNotice}`:`Error submitted${sentNotice}`);
d.close();
await refresh();
});
};
// Delete draft / error handler
form.querySelector('#btnDeleteErr')?.addEventListener('click',async()=>{
if(!confirm(`Are you sure you want to delete this ${isDraft?'draft':'error'}?`))return;
const r=await api(`/khira/api/errors/${encodeURIComponent(prefill.id)}`,'DELETE');
if(r._f||r.error){
toast(r.error||'Delete failed','err');
return;
}
toast('Error removed');
d.close();
await refresh();
});
if(!d.open)d.showModal();
}
/* ── Bulk Actions Management ── */
+2 -2
View File
@@ -9,7 +9,7 @@
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto+Flex:wght@400;500;600;700&family=Roboto+Mono:wght@400;500&display=swap" rel="stylesheet">
<link rel="stylesheet" href="/khira/styles.css?v=4">
<link rel="stylesheet" href="/khira/styles.css?v=5">
<script>try{document.documentElement.dataset.theme=localStorage.khira_theme||'dark'}catch(e){}</script>
</head>
<body>
@@ -246,6 +246,6 @@
<dialog id="sheet"></dialog>
<dialog id="dlg"></dialog>
<div class="snack" id="snack" role="status"></div>
<script src="/khira/app.js?v=4" defer></script>
<script src="/khira/app.js?v=6" defer></script>
</body>
</html>
+203
View File
@@ -2394,3 +2394,206 @@ dd { word-break: break-word; }
border: 1px dashed rgba(56, 189, 248, 0.5) !important;
border-radius: 18px !important;
}
/* ── Application-Oriented Error Form & Drafts System ── */
#dlg.wide {
width: min(720px, calc(100% - 32px));
}
.err-form-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 16px;
}
@media (max-width: 640px) {
.err-form-grid {
grid-template-columns: 1fr;
}
}
.err-form-full {
grid-column: 1 / -1;
}
.form-seg-group {
display: flex;
flex-direction: column;
gap: 6px;
}
.form-seg-label {
font-size: 11px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.05em;
color: var(--on-sv);
}
.seg-pills {
display: flex;
gap: 6px;
background: rgba(255, 255, 255, 0.04);
padding: 4px;
border-radius: 12px;
border: 1px solid rgba(255, 255, 255, 0.08);
}
.seg-pill {
flex: 1;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 6px;
padding: 8px 12px;
font-size: 12px;
font-weight: 500;
border-radius: 8px;
border: none;
background: transparent;
color: var(--on-sv);
cursor: pointer;
transition: all 0.2s ease;
}
.seg-pill:hover {
color: var(--on-s);
background: rgba(255, 255, 255, 0.06);
}
.seg-pill.on {
background: rgba(255, 255, 255, 0.14);
color: #fff;
font-weight: 600;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.seg-pill.bug-pill.on {
background: linear-gradient(135deg, rgba(234, 179, 8, 0.35) 0%, rgba(202, 138, 4, 0.2) 100%);
color: #fef08a;
border: 1px solid rgba(250, 204, 21, 0.4);
}
.seg-pill.crash-pill.on {
background: linear-gradient(135deg, rgba(239, 68, 68, 0.4) 0%, rgba(185, 28, 28, 0.25) 100%);
color: #fca5a5;
border: 1px solid rgba(248, 113, 113, 0.4);
}
/* Image Attachment Dropzone */
.err-attach-group {
display: flex;
flex-direction: column;
gap: 6px;
}
.err-upload-box {
background: rgba(255, 255, 255, 0.03);
border: 1px dashed rgba(255, 255, 255, 0.18);
border-radius: 14px;
padding: 14px;
text-align: center;
cursor: pointer;
transition: all 0.2s ease;
}
.err-upload-box:hover {
background: rgba(255, 255, 255, 0.06);
border-color: var(--pri);
}
.err-upload-placeholder {
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
color: var(--on-sv);
font-size: 13px;
}
.err-upload-placeholder svg {
stroke: var(--pri);
}
.err-upload-preview {
display: flex;
align-items: center;
gap: 12px;
text-align: left;
}
.err-upload-preview img {
width: 60px;
height: 60px;
object-fit: cover;
border-radius: 10px;
border: 1px solid rgba(255, 255, 255, 0.15);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}
.err-upload-meta {
flex: 1;
display: flex;
flex-direction: column;
gap: 4px;
min-width: 0;
}
.err-upload-meta span {
font-size: 13px;
color: var(--on-s);
font-weight: 500;
}
.err-rm-img-btn {
align-self: flex-start;
color: #ef4444 !important;
font-size: 11px !important;
padding: 2px 8px !important;
height: 24px !important;
}
/* Draft Banner in Errors View */
.draft-banner {
display: flex;
align-items: center;
justify-content: space-between;
padding: 12px 18px;
border-radius: 16px;
background: linear-gradient(135deg, rgba(245, 158, 11, 0.15) 0%, rgba(217, 119, 6, 0.08) 100%);
border: 1px solid rgba(245, 158, 11, 0.3);
margin-bottom: 16px;
font-size: 13px;
color: #fde68a;
}
.draft-banner b {
color: #fff;
}
.draft-btn {
background: rgba(245, 158, 11, 0.16) !important;
color: #fde68a !important;
border: 1px solid rgba(245, 158, 11, 0.35) !important;
}
.draft-btn:hover {
background: rgba(245, 158, 11, 0.28) !important;
color: #fff !important;
}
.stt.draft {
background: rgba(245, 158, 11, 0.2);
color: #fbbf24;
border: 1px solid rgba(245, 158, 11, 0.4);
}
.meta-chip {
display: inline-flex;
align-items: center;
gap: 4px;
font-size: 11px;
padding: 2px 8px;
border-radius: 6px;
background: rgba(255, 255, 255, 0.06);
color: var(--on-sv);
border: 1px solid rgba(255, 255, 255, 0.08);
}
.meta-chip.ios {
color: #38bdf8;
border-color: rgba(56, 189, 248, 0.3);
background: rgba(56, 189, 248, 0.1);
}
.meta-chip.android {
color: #4ade80;
border-color: rgba(74, 222, 128, 0.3);
background: rgba(74, 222, 128, 0.1);
}
.meta-chip.crash {
color: #f87171;
border-color: rgba(248, 113, 113, 0.3);
background: rgba(248, 113, 113, 0.1);
}
.meta-chip.bug {
color: #facc15;
border-color: rgba(250, 204, 21, 0.3);
background: rgba(250, 204, 21, 0.1);
}