Route saved investigation continuation and explicit new starts into Explore
This commit is contained in:
parent
25a151f958
commit
c868eb475a
@ -48,7 +48,7 @@ public sealed class InvestigationCompanionController(InvestigationAccess gate,II
|
||||
if(operation=="progress"){if(capability==null||!InvestigationGuidanceService.ProgressStates.Contains(progress))throw new ArgumentException("Choose a progress state.");s.Progress[InvestigationGuidanceService.Key(finding!,capability)]=progress!;}
|
||||
}else if(operation is not("activate" or "dismiss" or "finish"))throw new ArgumentException("Unknown guidance action.");
|
||||
await service.Save(Author,r,s,operation is "select" or "progress"?"save":operation);
|
||||
if(operation=="activate"&&Request.Headers["X-Requested-With"]!="XMLHttpRequest")return RedirectToAction("Index","WriterInvestigations",new{bookId,id});
|
||||
if(operation=="activate"&&Request.Headers["X-Requested-With"]!="XMLHttpRequest")return RedirectToAction("Explore","Writer",new{bookId,investigation=id});
|
||||
return Json(new{ok=true});
|
||||
});
|
||||
[HttpPost("/InvestigationCompanion/Open"),ValidateAntiForgeryToken]
|
||||
|
||||
@ -140,6 +140,7 @@
|
||||
var shortcut = command.ToolbarKey is null ? null : ToolbarCommands.All.Single(x => x.Key == command.ToolbarKey);
|
||||
var available = shortcut?.IsAvailable(Model) ?? command.Available(Model);
|
||||
var url = available ? Url.Action(command.Action, command.Controller, shortcut?.RouteValues(Model) ?? command.Values(Model)) : null;
|
||||
if(command.Label=="Guided investigation"&&url!=null)url+="#new-investigation";
|
||||
var active = available && (controller=="WriterInvestigations" && command.Controller=="Writer" && command.Action=="Explore" || (shortcut?.IsActive(controller, action, Model.ActiveSection) ?? (controller == command.Controller && action == command.Action)));
|
||||
var bookScoped = command.Scope is "book" or "chapter" or "writerBook";
|
||||
var presentationIcon = RibbonPresentation.IconFor(RibbonPresentation.Operation(command.Controller, command.Action)) ?? command.IconKey;
|
||||
|
||||
@ -64,5 +64,5 @@
|
||||
async function discover(){const area=document.querySelector('[data-my-investigations]');if(!area)return;const list=area.querySelector('[data-saved-investigations]');try{const rows=await saved(area.dataset.book);list.replaceChildren();if(!rows.length)list.append(element('p','No saved investigations for this book yet. Begin a concern above.'));for(const item of rows){const card=element('article');card.append(element('h3',item.concern),element('p',item.status+' · Last activity: '+new Date(item.updatedUtc).toLocaleString()+' · '+item.id.slice(0,8)));const form=element('form');form.method='post';form.action=item.continueUrl;form.dataset.guidanceActivate='';for(const[name,value]of Object.entries({__RequestVerificationToken:token,bookId:item.bookID,id:item.id,version:item.guidanceVersion,operation:'activate'})){const input=element('input');input.type='hidden';input.name=name;input.value=value;form.append(input);}form.append(element('button','Continue','btn btn-primary'));const results=element('a',item.hasResults?'Original results':'View saved investigation');results.href=item.resultsUrl;card.append(form,results);list.append(card);}}catch{list.replaceChildren(element('p','Your saved investigations could not be loaded.'),btn('Retry',discover));}}
|
||||
document.addEventListener('submit',e=>{const form=e.target;if(!form.matches('[data-guidance-navigation],[data-guidance-activate]'))return;if(form.dataset.pending==='true'){e.preventDefault();return;}form.dataset.pending='true';form.setAttribute('aria-busy','true');const submit=e.submitter;if(submit?.name){const hidden=element('input');hidden.type='hidden';hidden.name=submit.name;hidden.value=submit.value;form.append(hidden);}const id=form.querySelector('[name=id]')?.value||new URL(form.action).searchParams.get('id');if(id)try{sessionStorage.setItem(pendingKey,id);}catch{}requestAnimationFrame(()=>{form.querySelectorAll('button').forEach(b=>{b.dataset.originalText=b.textContent;b.textContent='Opening…';b.disabled=true;});});});
|
||||
window.addEventListener('pageshow',()=>document.querySelectorAll('[data-pending=true]').forEach(f=>{delete f.dataset.pending;f.removeAttribute('aria-busy');f.querySelectorAll('button').forEach(b=>{b.disabled=false;b.textContent=b.dataset.originalText||b.textContent;});}));discover();
|
||||
window.addEventListener('pageshow',e=>{if(e.persisted)load();});load();
|
||||
window.addEventListener('investigation-guidance-updated',()=>load());window.addEventListener('pageshow',e=>{if(e.persisted)load();});load();
|
||||
})();
|
||||
|
||||
@ -6,8 +6,8 @@ async function history(){const scroll=saved.scrollTop;try{const response=await f
|
||||
async function load(url,options={}){if(busy)return;busy=true;root.setAttribute('aria-busy','true');message.textContent='Loading investigation…';try{const response=await fetch(url,{...options,cache:'no-store',headers:{'X-Writer-Explore':'inline','X-Requested-With':'XMLHttpRequest'}});if(!response.ok)throw Error(response.status===409?'Another window changed this investigation. Your text is retained. Open Saved investigations to resume the latest version.':response.status===401?'Sign in again, then resume your saved investigation.':'The investigation could not be updated. Your entered answer remains here. Retry when connected.');const doc=new DOMParser().parseFromString(await response.text(),'text/html'),inline=doc.querySelector('[data-inline-investigation]');if(!inline&&!doc.querySelector('form[action*="Investigate/Start"]'))throw Error('Your session may have expired. Sign in and resume from Saved investigations.');journey.replaceChildren(...(inline?[inline]:doc.body.childNodes));current=inline?.dataset.inlineInvestigation||null;workspace.classList.toggle('writer21-investigating',!!current);dirty=false;tab('new');message.textContent='';const address=new URL(location.href);if(current)address.searchParams.set('investigation',current);else address.searchParams.delete('investigation');window.history.replaceState(window.history.state,'',address);try{if(current)sessionStorage.setItem('writer.explore.active.'+root.dataset.book,current);else sessionStorage.removeItem('writer.explore.active.'+root.dataset.book);}catch{}await history();}catch(error){message.textContent=error.message;}finally{busy=false;root.removeAttribute('aria-busy');}}
|
||||
for(const b of root.querySelectorAll('[data-explore-tab]'))b.addEventListener('click',()=>{tab(b.dataset.exploreTab);if(b.dataset.exploreTab==='saved')void history();});
|
||||
root.addEventListener('input',()=>dirty=true);
|
||||
root.addEventListener('submit',event=>{const form=event.target;if(!form.closest('[data-explore-journey]')||form.matches('[data-guidance-navigation],[data-guidance-activate]'))return;event.preventDefault();event.stopPropagation();if(busy)return;if(!form.reportValidity())return;const data=new FormData(form);if(event.submitter?.name)data.set(event.submitter.name,event.submitter.value);if(event.submitter?.value==='answer'&&!data.get('option')){message.textContent='Choose an answer before continuing.';return;}void load(form.action,{method:'POST',body:data});},true);
|
||||
root.addEventListener('submit',event=>{const form=event.target;if(form.matches('[data-guidance-activate]')){event.preventDefault();event.stopPropagation();if(busy)return;busy=true;fetch(form.action,{method:'POST',headers:{'X-Requested-With':'XMLHttpRequest'},body:new FormData(form)}).then(response=>{if(!response.ok)throw Error();message.textContent='This investigation is saved alongside your work.';window.dispatchEvent(new Event('investigation-guidance-updated'));}).catch(()=>message.textContent='Saved guidance could not be updated. Your investigation is retained; reload Saved investigations before retrying.').finally(()=>busy=false);return;}if(!form.closest('[data-explore-journey]')||form.matches('[data-guidance-navigation]'))return;event.preventDefault();event.stopPropagation();if(busy)return;if(!form.reportValidity())return;const data=new FormData(form);if(event.submitter?.name)data.set(event.submitter.name,event.submitter.value);if(event.submitter?.value==='answer'&&!data.get('option')){message.textContent='Choose an answer before continuing.';return;}void load(form.action,{method:'POST',body:data});},true);
|
||||
root.addEventListener('click',event=>{const a=event.target.closest('a');if(!a)return;const url=new URL(a.href,location.href);if(url.origin!==location.origin||!url.pathname.startsWith('/Writer/Explore/Investigate'))return;event.preventDefault();if(dirty&&!confirm('Leave your unsaved answer and load this investigation?'))return;void load(url);});
|
||||
window.addEventListener('beforeunload',event=>{if(dirty||busy){event.preventDefault();event.returnValue='';}});
|
||||
let id=new URLSearchParams(location.search).get('investigation');if(!id&&document.referrer.startsWith(location.origin))try{id=sessionStorage.getItem('writer.explore.active.'+root.dataset.book);}catch{}void load(id?'/Writer/Explore/Investigate?bookId='+root.dataset.book+'&id='+encodeURIComponent(id):journey.dataset.openingUrl);
|
||||
window.addEventListener('hashchange',()=>{if(location.hash==='#new-investigation'&&(!dirty||confirm('Leave your unsaved answer and start another investigation?')))void load(journey.dataset.openingUrl);});let id=new URLSearchParams(location.search).get('investigation');if(location.hash==='#new-investigation')id=null;else if(!id&&document.referrer.startsWith(location.origin))try{id=sessionStorage.getItem('writer.explore.active.'+root.dataset.book);}catch{}void load(id?'/Writer/Explore/Investigate?bookId='+root.dataset.book+'&id='+encodeURIComponent(id):journey.dataset.openingUrl);
|
||||
})();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user