Add direct Maps project chooser and refine editor navigation
This commit is contained in:
parent
6e2716190c
commit
688752626c
@ -1,6 +1,6 @@
|
||||
# Maps Stage 1
|
||||
|
||||
Maps is a project-scoped spatial writing workspace. Open **World → Maps**, choose a map, or create one. The project selector supplies `projectId` to `/Maps`; selected maps add `id`.
|
||||
Maps is a project-scoped spatial writing workspace. The direct `/Maps` address offers your active projects; it never selects another author’s project. Open **World → Maps**, choose a map, or create one. The project selector supplies `projectId` to `/Maps`; selected maps add `id`.
|
||||
|
||||
## Author workflows
|
||||
|
||||
|
||||
@ -16,6 +16,7 @@ const base='https://dev.plotdirector.com';
|
||||
await Promise.all([page.waitForURL('**/Projects'),page.locator('form[action="/Account/Login"] button[type=submit]').click()]);
|
||||
await page.goto(base+'/Projects/Create');await page.locator('#ProjectName').fill('Maps Development smoke '+Date.now());await page.getByRole('button',{name:'Save project',exact:true}).click();
|
||||
await page.waitForURL(/\/Projects(?:\/Details)?\//);const projectId=Number(page.url().match(/\/(\d+)(?:\?|$)/)[1]);
|
||||
await page.goto(base+'/Maps');assert(await page.locator(`a[href="/Maps?projectId=${projectId}"]`).isVisible(),'direct Maps launcher lists the signed-in author’s project');
|
||||
await page.goto(base+'/Maps?projectId='+projectId);await page.locator('#mapsNew').click();
|
||||
await page.locator('#mapsNewForm [name=Name]').fill('Working world');await page.locator('#mapsNewForm [name=Kind]').selectOption('World');await page.locator('#mapsNewForm [name=Starter]').selectOption('island');
|
||||
await Promise.all([page.waitForURL(/&id=\d+/),page.locator('#mapsNewForm button[type=submit]').click()]);
|
||||
@ -34,8 +35,9 @@ const base='https://dev.plotdirector.com';
|
||||
const locationID=await page.evaluate(id=>window.PlotDirectorMapWorkspace.document.features.find(f=>f.featureID===id).locationID,towns[0].featureID);assert(locationID>0);
|
||||
await page.reload();await page.waitForFunction(()=>!!window.PlotDirectorMapWorkspace);assert.equal(await page.locator('.maps-feature').count(),7);
|
||||
assert(await page.evaluate(({id,locationID})=>{const d=window.PlotDirectorMapWorkspace.document;return d.features.find(f=>f.featureID===id).locationID===locationID&&d.relationships[0].measuredDistance===126&&d.relationships[0].typicalTravelTime==='Two hours by car';},{id:towns[0].featureID,locationID}));
|
||||
// A second save must keep the same canonical Location ID.
|
||||
await page.locator('#mapsSave').click();await page.waitForFunction(()=>document.getElementById('mapsStatus').textContent==='Saved');
|
||||
// Save from a focused name field must commit the edit and reuse the same canonical Location ID.
|
||||
await page.evaluate(id=>window.PlotDirectorMapWorkspace.select(id),towns[0].featureID);await page.locator('[data-field=name]').fill('Harbour town revised');await page.keyboard.press('Control+s');await page.waitForFunction(()=>document.getElementById('mapsStatus').textContent==='Saved');
|
||||
assert(await page.evaluate(({id,locationID})=>{const f=window.PlotDirectorMapWorkspace.document.features.find(f=>f.featureID===id);return f.name==='Harbour town revised'&&f.locationID===locationID;},{id:towns[0].featureID,locationID}));
|
||||
await page.evaluate(id=>window.PlotDirectorMapWorkspace.select(id),towns[0].featureID);await page.locator('[data-action=child]').click();await page.locator('#mapsNewForm [name=Name]').fill('Harbour detail');
|
||||
const rootID=new URL(rootURL).searchParams.get('id');await page.locator('#mapsNewForm button[type=submit]').click();await page.waitForURL(url=>url.searchParams.get('id')!==rootID&&url.pathname==='/Maps');await page.waitForFunction(()=>!!window.PlotDirectorMapWorkspace);
|
||||
assert.equal(await page.locator('#mapsBreadcrumbs a').count(),3,'hierarchy breadcrumbs');const childURL=page.url();
|
||||
|
||||
@ -13,6 +13,7 @@ public sealed class MapsController(MapRepository maps, IProjectRepository projec
|
||||
private int UserID => currentUser.UserId!.Value;
|
||||
public async Task<IActionResult> Index(int projectId, int? id)
|
||||
{
|
||||
if (projectId == 0) return View("ChooseProject", await projects.ListActiveForUserAsync(UserID));
|
||||
if (!await access.CanAccessProjectAsync(projectId)) return NotFound();
|
||||
var project = await projects.GetForUserAsync(projectId, UserID);
|
||||
if (project is null) return NotFound();
|
||||
|
||||
22
PlotLine/Views/Maps/ChooseProject.cshtml
Normal file
22
PlotLine/Views/Maps/ChooseProject.cshtml
Normal file
@ -0,0 +1,22 @@
|
||||
@model IReadOnlyList<PlotLine.Models.Project>
|
||||
@{
|
||||
ViewData["Title"] = "Maps";
|
||||
ViewData["ProjectSection"] = "Maps";
|
||||
}
|
||||
<div data-pwa-task class="page-heading compact">
|
||||
<div><p class="eyebrow">Story geography</p><h1>Maps</h1><p>Choose the project whose world you want to explore.</p></div>
|
||||
</div>
|
||||
@if (Model.Count == 0)
|
||||
{
|
||||
<p>Create a project to start arranging your story world.</p>
|
||||
<a class="btn btn-primary" asp-controller="Projects" asp-action="Create">Create project</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="list-group">
|
||||
@foreach (var project in Model)
|
||||
{
|
||||
<a class="list-group-item list-group-item-action" asp-action="Index" asp-route-projectId="@project.ProjectID">@project.ProjectName</a>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
@ -43,7 +43,7 @@
|
||||
function world(event){const p=new DOMPoint(event.clientX,event.clientY).matrixTransform(svg.getScreenCTM().inverse());return [p.x,p.y];}
|
||||
function fit(items=doc?.features||[]){if(!items.length){view={x:-600,y:-400,w:1200,h:800};applyView();return;}
|
||||
let left=Infinity,top=Infinity,right=-Infinity,bottom=-Infinity;
|
||||
for(const f of items){let pts=f.geometryClass==='Path'?E.pathPoints(f,doc.features):[[f.x-f.width/2,f.y-f.height/2],[f.x+f.width/2,f.y+f.height/2]];for(const p of pts){left=Math.min(left,p[0]);right=Math.max(right,p[0]);top=Math.min(top,p[1]);bottom=Math.max(bottom,p[1]);}}
|
||||
for(const f of items){let pts=f.geometryClass==='Path'?E.pathPoints(f,doc.features):f.geometryClass==='Area'?(E.geometry(f).points||[[-.5,-.5],[.5,.5]]).map(p=>E.localToWorld(f,p)):[[f.x-f.width/2,f.y-f.height/2],[f.x+f.width/2,f.y+f.height/2]];for(const p of pts){left=Math.min(left,p[0]);right=Math.max(right,p[0]);top=Math.min(top,p[1]);bottom=Math.max(bottom,p[1]);}}
|
||||
let w=Math.max(350,right-left+180),h=Math.max(250,bottom-top+180),ratio=svg.clientWidth/Math.max(1,svg.clientHeight);if(w/h<ratio)w=h*ratio;else h=w/ratio;
|
||||
view={x:(left+right-w)/2,y:(top+bottom-h)/2,w,h};applyView();}
|
||||
function zoom(factor,point){const center=point||[view.x+view.w/2,view.y+view.h/2],w=Math.min(12000,Math.max(180,view.w*factor)),ratio=w/view.w;view={x:center[0]-(center[0]-view.x)*ratio,y:center[1]-(center[1]-view.y)*ratio,w,h:view.h*ratio};applyView();}
|
||||
@ -111,7 +111,7 @@
|
||||
if(selected.size>1){content.innerHTML=search+`<p>${selected.size} pieces selected.</p><div class="maps-edit-only"><button type="button" data-action="duplicate">Duplicate</button><button type="button" data-action="remove">Delete selection</button></div>`;return;}
|
||||
const child=boot.maps.find(m=>m.parentMapID===doc.map.mapID&&m.parentFeatureID===f.featureID),linked=boot.locations.find(l=>l.locationID===f.locationID);
|
||||
const readonly=mode!=='create';
|
||||
let html=search+`<h3>${esc(f.name)}</h3><p>${esc(f.type)}${f.isProvisional?' · ◇ Planning':''}${f.isLocked?' · Locked':''}</p>`;
|
||||
let html=search+`<h3>${esc(f.name)}</h3><p>${esc(f.type)}${f.isProvisional?' · ◇ Planning':''}${f.isLocked?' · Locked':''}${!f.isPlaced?' · Unplaced':''}</p>`;
|
||||
if(readonly){html+=f.notes?`<p>${esc(f.notes)}</p>`:'';if(linked)html+=`<a href="/Locations/Details/${f.locationID}">Open story Location: ${esc(linked.locationName)}</a>`;}
|
||||
else{
|
||||
html+=`<div class="maps-edit-only">${field('Name','name',f.name,'text','id="mapName" maxlength="200"')}`;
|
||||
@ -203,10 +203,10 @@
|
||||
svg.addEventListener('wheel',e=>{e.preventDefault();zoom(e.deltaY>0?1.12:1/1.12,world(e));},{passive:false});
|
||||
svg.addEventListener('contextmenu',e=>{e.preventDefault();const id=e.target.closest('[data-feature-id]')?.dataset.featureId;if(!id||mode!=='create')return;select(id);contextMenu?.remove();contextMenu=document.createElement('div');contextMenu.className='maps-context-menu';contextMenu.style.left=Math.min(e.clientX,window.innerWidth-180)+'px';contextMenu.style.top=Math.min(e.clientY,window.innerHeight-170)+'px';contextMenu.innerHTML='<button type="button" data-action="duplicate">Duplicate</button><button type="button" data-action="relationship">Add relationship</button><button type="button" data-action="child">Create detailed map</button><button type="button" data-action="remove">Delete</button>';app.append(contextMenu);});
|
||||
document.addEventListener('keydown',e=>{
|
||||
if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()==='s'&&!e.target.closest('dialog')){e.preventDefault();if(e.target.matches('[data-field]'))e.target.dispatchEvent(new Event('change',{bubbles:true}));save();return;}
|
||||
if(e.target.matches('input,textarea,select')||e.target.isContentEditable)return;
|
||||
if(e.key==='Escape'){if(drag&&drag.kind!=='pan'){doc=JSON.parse(history.pop());drag=null;}pending=null;selected.clear();shapeEdit=false;contextMenu?.remove();svg.classList.remove('placing');render();details();return;}
|
||||
if(e.target.closest('dialog'))return;
|
||||
if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()==='s'){e.preventDefault();save();return;}
|
||||
if(mode!=='create'||busy||preview)return;
|
||||
if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()==='z'){e.preventDefault();undo(e.shiftKey);}
|
||||
if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()==='y'){e.preventDefault();undo(true);}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user