feat(khira): simplify general form, reorder forms, and refine application form with image upload
This commit is contained in:
@@ -363,9 +363,12 @@ func (s *Server) handleCreateTicket(w http.ResponseWriter, r *http.Request) {
|
||||
Assistance string `json:"assistance"`
|
||||
AdditionalInfo string `json:"additional_info"`
|
||||
Context string `json:"context"`
|
||||
AssignedTo string `json:"assigned_to"`
|
||||
AssigneeUsername string `json:"assignee_username"`
|
||||
Links []string `json:"links"`
|
||||
AssignedTo string `json:"assigned_to"`
|
||||
AssigneeUsername string `json:"assignee_username"`
|
||||
DeveloperAccount string `json:"developer_account"`
|
||||
ImageURL string `json:"image_url"`
|
||||
Attachments []Attachment `json:"attachments"`
|
||||
Links []string `json:"links"`
|
||||
}
|
||||
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
@@ -395,6 +398,9 @@ func (s *Server) handleCreateTicket(w http.ResponseWriter, r *http.Request) {
|
||||
if assignedTo == "" {
|
||||
assignedTo = strings.TrimSpace(req.AssigneeUsername)
|
||||
}
|
||||
if assignedTo == "" {
|
||||
assignedTo = strings.TrimSpace(req.DeveloperAccount)
|
||||
}
|
||||
|
||||
appName := strings.TrimSpace(req.AppName)
|
||||
if appName == "" {
|
||||
@@ -443,6 +449,23 @@ func (s *Server) handleCreateTicket(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
var atts []Attachment
|
||||
for _, a := range req.Attachments {
|
||||
if strings.TrimSpace(a.URL) != "" {
|
||||
atts = append(atts, a)
|
||||
}
|
||||
}
|
||||
if req.ImageURL != "" {
|
||||
atts = append(atts, Attachment{
|
||||
ID: uuid.New().String(),
|
||||
Name: "screenshot",
|
||||
URL: strings.TrimSpace(req.ImageURL),
|
||||
Type: "image",
|
||||
UploadedBy: actor.Username,
|
||||
CreatedAt: time.Now(),
|
||||
})
|
||||
}
|
||||
|
||||
ticket := &Ticket{
|
||||
TicketType: ticketType,
|
||||
GeneralCategory: generalCategory,
|
||||
@@ -460,6 +483,7 @@ func (s *Server) handleCreateTicket(w http.ResponseWriter, r *http.Request) {
|
||||
AdditionalInfo: additionalInfo,
|
||||
AssignedTo: assignedTo,
|
||||
Links: req.Links,
|
||||
Attachments: atts,
|
||||
}
|
||||
|
||||
created, err := s.Store.CreateTicket(ticket, actor)
|
||||
|
||||
@@ -356,6 +356,28 @@ func (s *Store) CreateTicket(t *Ticket, actor *User) (*Ticket, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// Add Attachments if present
|
||||
for _, att := range t.Attachments {
|
||||
if strings.TrimSpace(att.URL) != "" {
|
||||
attID := att.ID
|
||||
if attID == "" {
|
||||
attID = uuid.New().String()
|
||||
}
|
||||
attType := att.Type
|
||||
if attType == "" {
|
||||
attType = "image"
|
||||
}
|
||||
attName := att.Name
|
||||
if attName == "" {
|
||||
attName = "uploaded_image"
|
||||
}
|
||||
_, _ = tx.Exec(`
|
||||
INSERT INTO ticket_attachments (id, ticket_id, name, url, size, type, uploaded_by, created_at)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
`, attID, t.ID, attName, att.URL, att.Size, attType, actor.Username, t.CreatedAt)
|
||||
}
|
||||
}
|
||||
|
||||
if err := tx.Commit(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,34 +0,0 @@
|
||||
import re
|
||||
|
||||
with open('app.js', 'r') as f:
|
||||
code = f.read()
|
||||
|
||||
# 1. _buildShell
|
||||
shell = """
|
||||
_buildShell() {
|
||||
if (!this.dom.mainPanel) return;
|
||||
this.dom.mainPanel.innerHTML = `
|
||||
<div id="content-area"></div>
|
||||
<div id="collections-list"></div>
|
||||
`;
|
||||
},
|
||||
"""
|
||||
code = code.replace('async init() {', shell + '\n async init() {')
|
||||
code = code.replace('this.cacheDOM();', 'this.cacheDOM();\n this._buildShell();')
|
||||
|
||||
# 2. Rename render() to _renderAll()
|
||||
code = code.replace('render() {', '_renderAll() {')
|
||||
|
||||
# 3. Targeted updates
|
||||
code = code.replace('this.render();', 'this._renderAll();')
|
||||
|
||||
# 4. Results: binaryData ALWAYS nulled after blobUrl created
|
||||
code = re.sub(r'(resultItem\.blobUrl = res\.blobUrl;)', r'\1\n resultItem.binaryData = null;', code)
|
||||
|
||||
# 5. saveState skip during bulk
|
||||
# Already in code: if (this.state.bulk && this.state.bulk.running) return;
|
||||
|
||||
with open('app.js', 'w') as f:
|
||||
f.write(code)
|
||||
|
||||
print("Rewrite done via Python")
|
||||
@@ -1,22 +0,0 @@
|
||||
import re
|
||||
|
||||
with open('app.js', 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
for func in ['renderSidebar', 'renderMain', 'renderResponse']:
|
||||
match = re.search(fr'{func}\(\)\s*\{{', content)
|
||||
if match:
|
||||
start = match.start()
|
||||
brace_count = 0
|
||||
started = False
|
||||
for i in range(start, len(content)):
|
||||
if content[i] == '{':
|
||||
brace_count += 1
|
||||
started = True
|
||||
elif content[i] == '}':
|
||||
brace_count -= 1
|
||||
if started and brace_count == 0:
|
||||
end = i + 1
|
||||
break
|
||||
with open(f'{func}.txt', 'w') as out:
|
||||
out.write(content[start:end])
|
||||
@@ -1,24 +0,0 @@
|
||||
render() {
|
||||
const root = document.getElementById('app-root');
|
||||
if (root) {
|
||||
// Reset base class first to prevent layout/theme clashing
|
||||
root.className = 'workspace';
|
||||
|
||||
if (this.state.bulk.results.length > 0 || this.state.bulk.running) {
|
||||
root.classList.add('bulk-active');
|
||||
}
|
||||
if (this.state.gridMaximized || !this.state.activeSpaceId) {
|
||||
root.classList.add('grid-maximized');
|
||||
}
|
||||
|
||||
// Add theme class for active space
|
||||
if (this.state.activeSpaceId) {
|
||||
const activeSpace = this.state.spaces.find(s => s.id === this.state.activeSpaceId);
|
||||
const theme = activeSpace && activeSpace.theme ? activeSpace.theme : 'violet';
|
||||
root.classList.add(`theme-${theme}`);
|
||||
}
|
||||
}
|
||||
this.renderSidebar();
|
||||
this.renderMain();
|
||||
this.renderResponse();
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
renderMain() {
|
||||
if (!this.state.activeSpaceId) {
|
||||
// Render Spaces Dashboard Grid View
|
||||
const spacesCardsHTML = this.state.spaces.map(s => {
|
||||
const count = s.collections ? s.collections.length : 0;
|
||||
const notifCount = s.notifications ? s.notifications.length : 0;
|
||||
const theme = s.theme || 'violet';
|
||||
return `
|
||||
<div class="space-card space-card-${theme}" onclick="App.openSpace('${s.id}')">
|
||||
<div class="space-card-icon">
|
||||
<i class="fa-solid fa-cubes"></i>
|
||||
${notifCount > 0 ? `<span class="space-card-notif-badge">${notifCount}</span>` : ''}
|
||||
</div>
|
||||
<div class="space-card-info">
|
||||
<h3>${this.escapeHTML(s.name)}</h3>
|
||||
<span>${count} Collections</span>
|
||||
</div>
|
||||
<div class="space-card-actions" onclick="event.stopPropagation();">
|
||||
<button class="btn btn-ghost" style="color:var(--text-muted); padding:4px;" onclick="App.renameSpace('${s.id}')" title="Rename Space">
|
||||
<i class="fa-solid fa-pencil" style="font-size:12px;"></i>
|
||||
</button>
|
||||
${this.state.spaces.length > 1 ? `
|
||||
<button class="btn btn-ghost" style="color:var(--danger); padding:4px;" onclick="App.deleteSpace('${s.id}')" title="Delete Space">
|
||||
<i class="fa-solid fa-trash" style="font-size:12px;"></i>
|
||||
</button>
|
||||
` : ''}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}).join('');
|
||||
|
||||
const dashboardHTML = `
|
||||
<div class="spaces-dashboard">
|
||||
<div class="spaces-dash-header">
|
||||
<h2>Workspaces</h2>
|
||||
<p>Select a workspace to access its collections, endpoints, and history.</p>
|
||||
</div>
|
||||
|
||||
<div class="spaces-grid">
|
||||
${spacesCardsHTML}
|
||||
|
||||
<div class="space-card create-space-card" onclick="App.createSpace()">
|
||||
<div class="space-card-icon"><i class="fa-solid fa-circle-plus"></i></div>
|
||||
<div class="space-card-info">
|
||||
<h3>Create New Space</h3>
|
||||
<span>Add a clean workspace</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
const headerHTML = `
|
||||
<div class="app-header">
|
||||
<div class="brand" style="cursor:pointer;" onclick="App.showSpacesDashboard()"><i class="fa-solid fa-fire"></i> PHOENIX</div>
|
||||
<div style="font-size:13px; color:var(--text-muted); font-weight:600;">
|
||||
Workspace Dashboard
|
||||
</div>
|
||||
<div></div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
this.dom.mainPanel.innerHTML = headerHTML + dashboardHTML;
|
||||
return;
|
||||
}
|
||||
|
||||
const isBulkStart = this.checkBulkStart();
|
||||
const bulk = this.state.bulk;
|
||||
const activeSpace = this.state.spaces.find(s => s.id === this.state.activeSpaceId);
|
||||
|
||||
// Tab Strip (Postman-like)
|
||||
const tabStripHTML = `
|
||||
<div class="main-tab-strip">
|
||||
${this.tabs.map((tab, i) => {
|
||||
const isActive = i === this.activeTabIndex;
|
||||
const tabName = tab.name || (tab.url ? tab.url.split('/').pop() || 'Request' : 'Untitled');
|
||||
const displayName = tabName.length > 20 ? tabName.substring(0, 20) + '…' : tabName;
|
||||
const method = tab.method || 'GET';
|
||||
const mc = { GET:'var(--m-get)', POST:'var(--m-post)', PUT:'var(--m-put)', DELETE:'var(--m-delete)', PATCH:'var(--m-patch)' }[method] || 'var(--text-3)';
|
||||
return `
|
||||
<div class="main-tab ${isActive ? 'active' : ''}"
|
||||
onclick="App.switchTab(${i})"
|
||||
title="${this.escapeHTML(tab.name || tab.url || 'Untitled')}"
|
||||
style="
|
||||
display:flex;align-items:center;gap:6px;
|
||||
padding:0 12px;min-width:120px;max-width:190px;
|
||||
height:100%;cursor:pointer;flex-shrink:0;
|
||||
position:relative;overflow:hidden;
|
||||
user-select:none;white-space:nowrap;
|
||||
border-right:1px solid var(--border-2);
|
||||
background:${isActive ? 'var(--bg-app)' : 'var(--bg-sidebar)'};
|
||||
color:${isActive ? 'var(--text-1)' : 'var(--text-3)'};
|
||||
border-bottom:2px solid ${isActive ? 'var(--ph)' : 'transparent'};
|
||||
transition:background 0.12s,color 0.12s;
|
||||
"
|
||||
onmouseover="if(!this.classList.contains('active')){this.style.background='var(--bg-elevated)';this.style.color='var(--text-2)';}"
|
||||
onmouseout="if(!this.classList.contains('active')){this.style.background='var(--bg-sidebar)';this.style.color='var(--text-3)';}">
|
||||
<span style="font-size:9px;font-weight:800;color:${mc};letter-spacing:0.03em;flex-shrink:0;font-family:var(--font-ui);">${method}</span>
|
||||
<span style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;flex:1;font-size:12px;font-weight:${isActive ? '600' : '500'};">${this.escapeHTML(displayName)}</span>
|
||||
<button onclick="event.stopPropagation();App.closeTab(${i})"
|
||||
style="background:none;border:none;cursor:pointer;color:${isActive ? 'var(--text-2)' : 'var(--text-4)'};padding:2px 3px;border-radius:3px;line-height:1;font-size:14px;flex-shrink:0;transition:background 0.1s,color 0.1s;"
|
||||
onmouseover="this.style.background='var(--danger-dim)';this.style.color='var(--danger)'"
|
||||
onmouseout="this.style.background='none';this.style.color='${isActive ? 'var(--text-2)' : 'var(--text-4)'}}'"
|
||||
title="Close tab">×</button>
|
||||
</div>
|
||||
`;
|
||||
}).join('')}
|
||||
@@ -1,3 +0,0 @@
|
||||
renderResponse() {
|
||||
// No-op: Single response and bulk results have been consolidated into renderMain()'s bottom panel.
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
renderSidebar() {
|
||||
const collectionsHTML = this.getCollectionsHTML();
|
||||
const activeSpace = this.state.spaces.find(s => s.id === this.state.activeSpaceId);
|
||||
|
||||
let notificationsBannerHTML = '';
|
||||
if (activeSpace && activeSpace.notifications && activeSpace.notifications.length > 0) {
|
||||
notificationsBannerHTML = `
|
||||
<div class="notifications-banner" onclick="App.openNotificationsModal()">
|
||||
<i class="fa-solid fa-bell"></i>
|
||||
<span>${activeSpace.notifications.length} pending share request${activeSpace.notifications.length > 1 ? 's' : ''}</span>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
const spaceOptionsHTML = `
|
||||
<option value="" ${!this.state.activeSpaceId ? 'selected' : ''}>⌂ Workspaces Dashboard</option>
|
||||
${this.state.spaces.map(s => `
|
||||
<option value="${s.id}" ${s.id === this.state.activeSpaceId ? 'selected' : ''}>
|
||||
${this.escapeHTML(s.name)}
|
||||
</option>
|
||||
`).join('')}
|
||||
`;
|
||||
|
||||
this.dom.sidebar.innerHTML = `
|
||||
<!-- Workspace Header -->
|
||||
<div class="sidebar-header" style="position:relative;z-index:1;">
|
||||
<div class="sidebar-ws-label-row">
|
||||
<div class="sidebar-ws-label-text">
|
||||
<i class="fa-solid fa-cube"></i> Workspace
|
||||
</div>
|
||||
<button class="btn btn-ghost" style="height:26px;padding:0 9px;font-size:10px;gap:4px;" onclick="App.createSpace()" title="New Workspace">
|
||||
<i class="fa-solid fa-plus" style="font-size:9px;"></i> New
|
||||
</button>
|
||||
</div>
|
||||
<div style="position:relative;">
|
||||
<select class="space-switcher-select" onchange="this.value ? App.openSpace(this.value) : App.showSpacesDashboard()">
|
||||
${spaceOptionsHTML}
|
||||
</select>
|
||||
<i class="fa-solid fa-chevron-down" style="position:absolute;right:11px;top:50%;transform:translateY(-50%);color:var(--text-3);pointer-events:none;font-size:9px;"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
${activeSpace ? `
|
||||
${notificationsBannerHTML}
|
||||
|
||||
<!-- Collections Section -->
|
||||
<div class="sidebar-collections-header">
|
||||
<div class="sidebar-section-label">
|
||||
<i class="fa-solid fa-layer-group" style="color:var(--warning);font-size:9px;"></i>
|
||||
Collections
|
||||
</div>
|
||||
<button class="btn btn-ghost" style="height:24px;padding:0 8px;font-size:10px;" onclick="App.createCollection()" title="New Collection">
|
||||
<i class="fa-solid fa-plus" style="font-size:9px;"></i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Search -->
|
||||
<div class="sidebar-search-container" style="padding:0 10px 8px;">
|
||||
<div style="position:relative;display:flex;align-items:center;">
|
||||
<i class="fa-solid fa-magnifying-glass" style="position:absolute;left:9px;color:var(--text-3);font-size:10px;pointer-events:none;z-index:1;"></i>
|
||||
<input type="text" class="sidebar-search-input" placeholder="Search…" value="${this.state.searchQuery || ''}"
|
||||
oninput="App.filterSidebarCollections(this.value)"
|
||||
style="padding-left:28px;padding-right:${this.state.searchQuery ? '28px' : '10px'};">
|
||||
${this.state.searchQuery ? `<i id="search-clear-btn" class="fa-solid fa-xmark" onclick="App.filterSidebarCollections(''); document.querySelector('.sidebar-search-input').value='';" style="position:absolute;right:9px;color:var(--text-3);font-size:10px;cursor:pointer;z-index:1;"></i>` : ''}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Collections List -->
|
||||
<div class="history-list" id="sidebar-collections-list">
|
||||
${collectionsHTML || `<div style="padding:20px 14px;font-size:11px;color:var(--text-3);text-align:center;line-height:1.6;">No requests yet.<br>Create a collection to get started.</div>`}
|
||||
</div>
|
||||
` : `
|
||||
<div style="flex:1;display:flex;align-items:center;justify-content:center;padding:24px;text-align:center;">
|
||||
<div>
|
||||
<i class="fa-solid fa-cubes" style="font-size:24px;color:var(--text-4);display:block;margin-bottom:12px;"></i>
|
||||
<div style="font-size:11.5px;color:var(--text-3);line-height:1.65;">Select a workspace<br>from the dashboard</div>
|
||||
</div>
|
||||
</div>
|
||||
`}
|
||||
|
||||
<!-- Footer -->
|
||||
<div style="padding:10px;border-top:1px solid var(--border-1);flex-shrink:0;">
|
||||
<button class="btn btn-ghost" style="width:100%;font-size:11px;" onclick="localStorage.removeItem('phoenix-state-v2'); location.reload();">
|
||||
<i class="fa-solid fa-rotate-right"></i> Reset App
|
||||
</button>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
import re
|
||||
import sys
|
||||
|
||||
with open('app.js', 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
# 1. Add _buildShell()
|
||||
shell_html = """
|
||||
_buildShell() {
|
||||
const root = document.getElementById('app-root');
|
||||
if (!root) return;
|
||||
|
||||
root.innerHTML = `
|
||||
<div id="sidebar" class="sidebar"></div>
|
||||
<div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
|
||||
<div id="main-panel" class="main-panel"></div>
|
||||
<div id="toast-container"></div>
|
||||
`;
|
||||
},
|
||||
"""
|
||||
|
||||
# Find init() and insert _buildShell() call and definition
|
||||
init_idx = content.find('async init() {')
|
||||
if init_idx != -1:
|
||||
content = content[:init_idx] + shell_html + content[init_idx:]
|
||||
content = content.replace('this.loadState();', 'this.loadState();\n this._buildShell();')
|
||||
|
||||
# 2. _renderAll() instead of render()
|
||||
content = content.replace('render() {', '_renderAll() {')
|
||||
|
||||
# 3. Surgical updates
|
||||
# We can replace 'this.render();' with selective calls, but the prompt says:
|
||||
# "6. Full _renderAll() called only on: tab switch, space switch, page init, bulk complete."
|
||||
# "5. saveState() must skip during bulk run." (already in code: if (this.state.bulk && this.state.bulk.running) return;)
|
||||
# "4. Results: binaryData ALWAYS nulled after blobUrl created"
|
||||
# "7. No this.dom.mainPanel.innerHTML = ... after init, except for Spaces Dashboard view"
|
||||
# "8. No this.dom.sidebar.innerHTML = ... after init."
|
||||
|
||||
with open('/tmp/app_new.js', 'w') as f:
|
||||
f.write(content)
|
||||
+139
-13
@@ -304,8 +304,19 @@ function nav(sec){
|
||||
function sheet(id){
|
||||
const t=S.t.find(x=>x.id===id);if(!t)return;S.tid=id;
|
||||
const p=pri(t),s=st(t),g=t.ticket_type==='general',rem=t.remarks||[],links=(t.links||[]).map(l=>l.url||l);
|
||||
const atts=t.attachments||[];
|
||||
const kv=(k,v,m)=>`<div><dt>${k}</dt><dd${m&&m!=='html'?' class="mono"':''}>${m==='html'?v:esc(v||'—')}</dd></div>`;
|
||||
const meta=g?kv('Category',t.general_category)+kv('Department',t.department):kv('Application',t.app||t.app_name)+kv('Version',t.version)+kv('Feature',t.feature||t.feature_name)+kv('API key / route',t.api_key,1);
|
||||
|
||||
let meta='';
|
||||
if(g){
|
||||
meta=kv('Reported by',who(t.reporter||{name:t.created_by_name,username:t.created_by,role:t.created_by_role},t.created_by_name),'html');
|
||||
}else{
|
||||
meta=(t.app||t.app_name?kv('Application',t.app||t.app_name):'')
|
||||
+(t.version?kv('Version',t.version):'')
|
||||
+(t.feature||t.feature_name?kv('Feature',t.feature||t.feature_name):'')
|
||||
+(t.api_key?kv('API key / route',t.api_key,1):'')
|
||||
+kv('Reported by',who(t.reporter||{name:t.created_by_name,username:t.created_by,role:t.created_by_role},t.created_by_name),'html');
|
||||
}
|
||||
|
||||
const isAdmin=S.u?.username==='admin'||S.u?.role==='team_lead'||S.u?.role==='lead';
|
||||
const isCreator=S.u?.username && (S.u.username.toLowerCase()===(t.created_by||t.reporter?.username||'').toLowerCase());
|
||||
@@ -316,9 +327,15 @@ function sheet(id){
|
||||
$('#sheet').innerHTML=`<div class="sbd"><header class="sh"><button class="ib" data-x aria-label="Close">${ms('close')}</button><span class="id">${esc(t.id)}</span><span class="pb ${p.toLowerCase()}">${p}</span>${t.archived?'<span class="stt archived"><span class="ms" style="font-size:14px">archive</span>Archived</span>':`<span class="stt ${s}">${STAT[s]||esc(s)}</span>`}</header>
|
||||
<div class="sb"><h2>${esc(t.title)}</h2>
|
||||
<div class="g2">${fld('a','Assignee',{t:'select',opts:usOpts(),v:t.assignee?.username||t.assigned_to||'',d:'data-act="assign"'})}${fld('p','Priority',{t:'select',opts:PRI,v:p,d:'data-act="prio"'})}</div>
|
||||
<dl>${meta}${kv('Reported by',who(t.reporter||{name:t.created_by_name,username:t.created_by,role:t.created_by_role},t.created_by_name),'html')}</dl>
|
||||
<div><h5>Assistance required</h5><p>${esc(t.assistance||t.assistance_required||'—')}</p></div>
|
||||
<div><h5>Diagnostic context<button class="ib" data-copy aria-label="Copy">${ms('content_copy')}</button></h5><pre class="code" id="ctx">${esc(t.context||t.additional_info||'No logs provided')}</pre></div>
|
||||
<dl>${meta}</dl>
|
||||
<div><h5>Description</h5><p style="white-space:pre-wrap">${esc(t.description||'No description provided')}</p></div>
|
||||
${atts.length?`<div><h5>Attached Images / Files</h5><div class="att-row">${atts.map(a=>{
|
||||
const isImg=a.type==='image'||/\.(png|jpe?g|webp|gif|svg)$/i.test(a.url);
|
||||
return isImg?`<div class="att-card"><a href="${esc(a.url)}" target="_blank" rel="noopener"><img src="${esc(a.url)}" alt="${esc(a.name)}" class="att-thumb"></a><span class="ell">${esc(a.name)}</span></div>`
|
||||
:`<div class="att-card"><a href="${esc(a.url)}" target="_blank" rel="noopener" class="tn" style="height:36px"><span class="ms">attachment</span><span class="ell">${esc(a.name)}</span></a></div>`;
|
||||
}).join('')}</div></div>`:''}
|
||||
${(t.assistance||t.assistance_required)?`<div><h5>Assistance required</h5><p>${esc(t.assistance||t.assistance_required)}</p></div>`:''}
|
||||
${(t.context||t.additional_info)?`<div><h5>Diagnostic context<button class="ib" data-copy aria-label="Copy">${ms('content_copy')}</button></h5><pre class="code" id="ctx">${esc(t.context||t.additional_info)}</pre></div>`:''}
|
||||
${links.length?`<div class="lk"><h5>Links</h5>${links.map(u=>`<a href="${esc(u)}" target="_blank" rel="noopener">${esc(String(u).replace(/^https?:\/\//,''))}</a>`).join('')}</div>`:''}
|
||||
<div><h5>Activity · ${rem.length}</h5>${rem.map(r=>{const sys=r.system||['created','hold','complete','reassigned','priority','resume','archive','unarchive'].includes(r.type);return`<div class="tle${sys?' sys':''}"><b>${sys?'Khira':who(r.author||{name:r.author_name,username:r.author_username,role:r.author_role},r.author_name)}</b><small>${ago(r.created_at)}</small><p>${esc(r.text||r.body)}</p></div>`}).join('')}
|
||||
<form class="cmp" id="rf"><textarea id="rt" rows="1" placeholder="Add a remark"></textarea><button class="ib" aria-label="Send">${ms('send')}</button></form></div></div>
|
||||
@@ -361,18 +378,127 @@ function deleteTicketD(id){
|
||||
|
||||
/* ── create ticket ── */
|
||||
function newTicket(){
|
||||
const appOpts=[['','Select application'],...Array.from(new Set([...APPS,...(S.t||[]).map(t=>t.app||t.app_name),...(S.e||[]).map(e=>e.app||e.app_name)].filter(Boolean)))];
|
||||
|
||||
dlg({wide:1,title:'New ticket',sub:`Reporting as ${esc(S.u.name)}`,ok:'Create ticket',
|
||||
body:`${rad('type',[['application','Application'],['general','General']],'application')}
|
||||
${fld('assignee_username','Assignee',{t:'select',opts:usOpts(1),req:1})}${fld('title','Title',{req:1})}
|
||||
<fieldset class="grp" data-g="application">${fld('app','Application',{t:'select',opts:[['','Select'],...APPS],req:1})}<div class="g2">${fld('version','Version',{req:1})}${fld('feature','Feature',{req:1})}</div>${fld('api_key','API key / route')}${fld('issue_type','Issue type',{t:'select',opts:[['','Select'],...ISS],req:1})}</fieldset>
|
||||
<fieldset class="grp" data-g="general" hidden disabled>${fld('general_category','Category',{t:'select',opts:[['','Select'],...CATS],req:1})}${fld('department','Department',{req:1})}</fieldset>
|
||||
<div><p class="lbl">Priority</p>${rad('priority',PRI,'P1')}</div>
|
||||
${fld('description','Description',{t:'area',rows:4,req:1})}${fld('assistance','Assistance required',{req:1})}${fld('context','Context (cURL, logs, stack trace)',{t:'area',rows:4,mono:1})}${fld('link','Reference link',{t:'url'})}`,
|
||||
init:f=>{const sw=()=>{const g=f.querySelector('[name=type]:checked').value;f.querySelectorAll('.grp').forEach(x=>{const on=x.dataset.g===g;x.hidden=!on;x.disabled=!on})};f.querySelectorAll('[name=type]').forEach(r=>r.onchange=sw);sw()},
|
||||
body:`${rad('type',[['general','General'],['application','Application']],'general')}
|
||||
<fieldset class="grp" data-g="general">
|
||||
${fld('assignee_username','Choose assignee',{t:'select',opts:usOpts(1),req:1})}
|
||||
${fld('title','Write title',{req:1})}
|
||||
${fld('description','Description',{t:'area',rows:5,req:1})}
|
||||
</fieldset>
|
||||
<fieldset class="grp" data-g="application" hidden disabled>
|
||||
${fld('assignee_username','Developer account',{t:'select',opts:usOpts(1),req:1})}
|
||||
${fld('app','App name',{t:'select',opts:appOpts,req:1})}
|
||||
${fld('version','Version',{req:1})}
|
||||
${fld('feature','Feature name')}
|
||||
${fld('api_key','API key')}
|
||||
${fld('title','Title',{req:1})}
|
||||
${fld('description','Description',{t:'area',rows:4,req:1})}
|
||||
<div class="fld-upload">
|
||||
<label class="upload-btn" id="lblImgUpload">
|
||||
<span class="ms">photo_camera</span>
|
||||
<span id="imgUploadTxt">Upload image (Optional)</span>
|
||||
<input type="file" id="appImgInput" accept="image/*" style="display:none">
|
||||
</label>
|
||||
<div id="imgPreviewWrap" class="img-preview-wrap" style="display:none">
|
||||
<img id="imgPreview" src="" alt="Screenshot preview">
|
||||
<button type="button" class="rm-btn" id="btnRemoveImg" title="Remove image" aria-label="Remove image"><span class="ms">close</span></button>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>`,
|
||||
init:f=>{
|
||||
let selectedImageFile=null;
|
||||
const sw=()=>{
|
||||
const g=f.querySelector('[name=type]:checked')?.value||'general';
|
||||
f.querySelectorAll('.grp').forEach(x=>{
|
||||
const on=x.dataset.g===g;
|
||||
x.hidden=!on;
|
||||
x.disabled=!on;
|
||||
});
|
||||
};
|
||||
f.querySelectorAll('[name=type]').forEach(r=>r.onchange=sw);
|
||||
sw();
|
||||
|
||||
const imgInput=f.querySelector('#appImgInput');
|
||||
const previewWrap=f.querySelector('#imgPreviewWrap');
|
||||
const previewImg=f.querySelector('#imgPreview');
|
||||
const uploadTxt=f.querySelector('#imgUploadTxt');
|
||||
const removeBtn=f.querySelector('#btnRemoveImg');
|
||||
|
||||
if(imgInput){
|
||||
imgInput.onchange=e=>{
|
||||
const file=e.target.files&&e.target.files[0];
|
||||
if(!file)return;
|
||||
selectedImageFile=file;
|
||||
const reader=new FileReader();
|
||||
reader.onload=ev=>{
|
||||
previewImg.src=ev.target.result;
|
||||
previewWrap.style.display='flex';
|
||||
uploadTxt.textContent=file.name;
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
};
|
||||
}
|
||||
|
||||
if(removeBtn){
|
||||
removeBtn.onclick=()=>{
|
||||
selectedImageFile=null;
|
||||
if(imgInput)imgInput.value='';
|
||||
previewImg.src='';
|
||||
previewWrap.style.display='none';
|
||||
uploadTxt.textContent='Upload image (Optional)';
|
||||
};
|
||||
}
|
||||
|
||||
f._getSelectedFile=()=>selectedImageFile;
|
||||
},
|
||||
go:async v=>{
|
||||
const f=$('#dlg form');
|
||||
const file=f._getSelectedFile?f._getSelectedFile():null;
|
||||
let uploadedAtt=null;
|
||||
if(file){
|
||||
const fd=new FormData();
|
||||
fd.append('file',file);
|
||||
const un=S.u?.username||ls('khira_active_user')||'admin';
|
||||
try{
|
||||
const upRes=await fetch('/khira/api/upload',{method:'POST',headers:{'X-Khira-User':un},body:fd});
|
||||
const upData=await upRes.json();
|
||||
if(upData.attachment){
|
||||
uploadedAtt=upData.attachment;
|
||||
}else if(upData.url){
|
||||
uploadedAtt={url:upData.url,name:file.name,type:'image'};
|
||||
}
|
||||
}catch(err){
|
||||
console.error('Upload failed',err);
|
||||
}
|
||||
}
|
||||
|
||||
const g=v.type==='general';
|
||||
const b=g?{ticket_type:'general',general_category:v.general_category,department:v.department,assignee_username:v.assignee_username,title:v.title,app:'General / Non-App',feature:v.general_category,priority:v.priority,description:v.description,assistance:v.assistance,context:v.context,links:v.link?[v.link]:[],files:[]}
|
||||
:{ticket_type:'application',assignee_username:v.assignee_username,title:v.title,app:v.app,version:v.version,feature:v.feature,api_key:v.api_key,issue_type:v.issue_type,priority:v.priority,description:v.description,assistance:v.assistance,context:v.context,links:v.link?[v.link]:[]};
|
||||
const b=g?{
|
||||
ticket_type:'general',
|
||||
assignee_username:v.assignee_username,
|
||||
title:v.title,
|
||||
description:v.description,
|
||||
general_category:'General',
|
||||
department:'General',
|
||||
priority:'P2'
|
||||
}:{
|
||||
ticket_type:'application',
|
||||
developer_account:v.assignee_username,
|
||||
assignee_username:v.assignee_username,
|
||||
app:v.app,
|
||||
app_name:v.app,
|
||||
version:v.version,
|
||||
feature:v.feature||'',
|
||||
feature_name:v.feature||'',
|
||||
api_key:v.api_key||'',
|
||||
title:v.title,
|
||||
description:v.description,
|
||||
priority:'P2',
|
||||
attachments:uploadedAtt?[uploadedAtt]:[]
|
||||
};
|
||||
|
||||
const r=await api('/khira/api/tickets','POST',b);
|
||||
if(!r.ticket){toast(r.error||'Could not create ticket','err');return false}
|
||||
toast(`${r.ticket.id} created`);await refresh();nav('tickets');sheet(r.ticket.id);
|
||||
|
||||
@@ -363,6 +363,20 @@ dt{font-size:12px;color:var(--on-sv)}dd{word-break:break-word}
|
||||
.cont-banner p{margin:2px 0 0;font-size:12px;color:var(--on-sv)}
|
||||
.cont-badge{display:inline-flex;align-items:center;gap:6px;background:var(--sec-c);color:var(--on-s);padding:2px 8px;border-radius:12px;font-size:11px;font-weight:600}
|
||||
|
||||
/* Ticket Image Upload & Attachments */
|
||||
.fld-upload{display:grid;gap:10px;margin:4px 0}
|
||||
.img-preview-wrap{position:relative;width:fit-content;max-width:100%;border-radius:12px;overflow:hidden;border:1px solid var(--out-v);background:var(--sc-hi);padding:6px;display:flex;align-items:center;gap:8px}
|
||||
.img-preview-wrap img{max-height:140px;max-width:240px;object-fit:cover;border-radius:8px;display:block}
|
||||
.img-preview-wrap .rm-btn{position:absolute;top:10px;right:10px;background:rgba(0,0,0,0.65);color:#fff;width:28px;height:28px;border-radius:50%;border:none;display:grid;place-items:center;cursor:pointer}
|
||||
.img-preview-wrap .rm-btn:hover{background:rgba(0,0,0,0.85)}
|
||||
|
||||
.att-row{display:flex;flex-wrap:wrap;gap:12px;margin-top:8px}
|
||||
.att-card{display:flex;flex-direction:column;gap:4px;width:140px}
|
||||
.att-thumb{width:140px;height:90px;object-fit:cover;border-radius:8px;border:1px solid var(--out-v);background:var(--sc-hi);transition:transform .2s;display:block}
|
||||
.att-thumb:hover{transform:scale(1.03)}
|
||||
.att-card .ell{font-size:12px;color:var(--on-sv)}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user