bmc_hub/static/js/case-command-suggestions.js
Christian 4871dd2d9e Add comprehensive test coverage for various modules
- Introduced tests for mail templates including ranking, rendering, and attachment handling.
- Added tests for time billing selection and approval processes, ensuring proper validation and state management.
- Implemented tests for case types in JavaScript, focusing on loading and editing functionality.
- Created tests for contact mail AI integration, ensuring proper parsing and error handling.
- Developed tests for dark theme CSS contrast and loading order.
- Added tests for invoice fee service, covering various scenarios including exemptions and invalid inputs.
- Implemented vendor resource tests, ensuring proper file handling and query validation.
2026-10-08 08:58:02 +02:00

37 lines
4.2 KiB
JavaScript

/* Completion is read-only; insertion replaces only the current argument. */
(function(root,factory){const api=factory();if(typeof module==='object'&&module.exports)module.exports=api;if(root)root.CaseCommandSuggestions=api;})(typeof window!=='undefined'?window:globalThis,function(){
'use strict';
const names=['tid','tildel','forventet','undersag','mig','todo','afventer','løsning','deadline','udsat','fil','hjælp','timer','relation','prioritet','gruppe','mail','note'];
const descriptions={tid:'Registrer tid',tildel:'Vælg medarbejder',forventet:'Forventet tid',undersag:'Ny undersag',mig:'Tildel mig',todo:'Ny opgave',afventer:'Afventer kunde',løsning:'Ny løsning',deadline:'Deadline',udsat:'Udsæt sagen',fil:'Vedhæft filer',hjælp:'Vis hjælp',timer:'Start eller pause',relation:'Kobl sag',prioritet:'Prioritet',gruppe:'Vælg gruppe',mail:'Mailkladde',note:'Intern note'};
const quote=value=>'"'+String(value).replace(/\\/g,'\\\\').replace(/"/g,'\\"')+'"';
function suggest(line,cursor,values={}){
const before=line.slice(0,cursor),match=/^(\s*)(\/\/|\/)([^\s]*)/.exec(before);if(!match)return [];
const start=match[1].length,prefix=match[2],name=match[3].toLowerCase(),commandEnd=start+prefix.length+(/^(?:\s*)(?:\/\/|\/)([^\s]*)/.exec(line)?.[1] || name).length;
if(cursor<=commandEnd)return names.filter(n=>n.startsWith(name)).map(n=>({label:`${prefix}${n}`,hint:descriptions[n],value:`${prefix}${n} `,from:start,to:commandEnd}));
const argsStart=commandEnd+1;
const matches=[...line.slice(argsStart).matchAll(/"(?:\\.|[^"\\])*(?:"|$)|\S+/g)].map(m=>({text:m[0],start:argsStart+m.index,end:argsStart+m.index+m[0].length}));
let index=matches.findIndex(t=>cursor>=t.start&&cursor<=t.end);if(index<0)index=matches.filter(t=>t.end<cursor).length;
const token=matches[index],from=token?.start??cursor,to=token?.end??cursor;
const query=line.slice(from,cursor).replace(/^[@"]|"$/g,'').toLocaleLowerCase('da');
let options=[];
const durations=['15m','30m','45m','1h','1,5h','2h'];
if((name==='tid'||name==='forventet')&&index===0)options=durations.map(v=>[v,v,'Minutter eller timer']);
if(name==='tid'&&index===1)options=['research','support','development','troubleshooting','on_site','meeting','other'].map(v=>[v,v,'Arbejdets kategori']);
if((name==='tildel'&&index===0)||(name==='todo'&&index===1&&(query.startsWith('@')||token?.text.startsWith('@')||!query)))options=(values.users||[]).map(u=>[u.full_name||u.username,`${name==='todo'?'@':''}${u.user_id}`,u.username||'Medarbejder']);
if(name==='gruppe'&&index===0)options=(values.groups||[]).map(g=>[g.name,quote(g.name),'Gruppe']);
if(name==='prioritet'&&index===0)options=['lav','normal','høj','kritisk'].map(v=>[v,v,'Prioritet']);
if(name==='afventer'&&index===0)options=[['kunde','kunde','Afvent kunden og opret todo']];
if(name==='timer'&&index===0)options=[['start','start','Start ny timer'],['pause','pause','Pause din aktive timer']];
if(name==='relation'&&index===0)options=(values.cases||[]).map(c=>[`#${c.id} · ${c.titel}`,`#${c.id}`,'Eksisterende sag']);
if(['deadline','udsat'].includes(name)){
const q=before.slice(argsStart).toLowerCase();return ['i dag','i morgen','mandag','tirsdag','onsdag','torsdag','fredag','lørdag','søndag'].filter(v=>v.startsWith(q)).map(v=>({label:v,hint:'Dato vises i forhåndsvisningen',value:v,from:argsStart,to:line.length}));
}
if(name==='todo'&&((index===1&&!token?.text.startsWith('@'))||index===2))options.push(...['i morgen','fredag','mandag'].map(v=>[v,v,'Opgavens frist']));
const textFields={undersag:[0,'Titel'],todo:[0,'Opgave'],note:[0,'Intern note'],mail:[0,'Mailtekst'],løsning:[0,'Løsning'],tildel:[1,'Begrundelse'],gruppe:[1,'Begrundelse'],prioritet:[1,'Begrundelse'],afventer:[1,'Begrundelse'],tid:[2,'Beskrivelse']};
const field=textFields[name] || (name==='timer' && matches[0]?.text==='start' ? [1,'Beskrivelse'] : null);
if(field && index===field[0] && !query)options.push([`Skriv ${field[1].toLowerCase()}`,quote(field[1]),'Tekst i dobbelte anførselstegn']);
return options.filter(([label,value,hint])=>`${label} ${value} ${hint}`.toLocaleLowerCase('da').includes(query)).slice(0,30).map(([label,value,hint])=>({label,hint,value:value+' ',from,to}));
}
return {suggest};
});