Peach: Local-first video metadata scraper and media manager.
fix: 视图键并成一组,页头两组控件站同一块板
longmeidao9db0c2b6f098
diff --git a/tests/test_web_ui.py b/tests/test_web_ui.pyindex 1aac3490c..118e513d3 100644--- a/tests/test_web_ui.py+++ b/tests/test_web_ui.py@@ -3932,14 +3932,9 @@ class WebUiSourceTests(unittest.TestCase):def test_the_agency_page_opens_on_its_roster(self):"""这一页要回答的是「这家签了谁」,所以进页面先摆艺人,视频是另一个视图。"""- self.assertCode(- "const AGENCY_VIEWS=[['people','艺人','user-round'],['videos','视频','play']];")- self.assertPageContains("let agencyRosterView='people';")+ self.assertPageContains("let agencyRosterView='people',agencyRoster=[];")self.assertCode(" agencyRosterView='people';\n const seq=++entityRequestSeq;")- self.assertCode("if(rosterToggle&&agencyRosterView==='people')renderAgencyRoster(roster);")- # 两个互斥视图用 Switch,不是自造按钮组。- self.assertPageContains("iconSwitchHtml('agency-view','事务所页视图'")- self.assertPageContains("wireIconSwitch($('#index'),'data-agency-view'")+ self.assertCode("if(entityViewNow(kind)==='people')renderAgencyRoster(roster);")def test_the_agency_roster_reuses_the_people_index_cell_and_layout(self):"""名册和艺人索引摆的是同一格人,模板与版式设置都只有一份。"""@@ -3953,16 +3948,19 @@ class WebUiSourceTests(unittest.TestCase):self.assertCode("const roster=kind==='agency'?(d.related_performers||[]):[];")self.assertCode("const related=roster.length?'':(d.related_performers||[]).map(")- def test_the_agency_roster_and_the_media_switch_do_not_talk_over_each_other(self):- """名册不是一种媒体:正看着艺人时,「视频/照片」问的不是这一页在显示什么。"""+ def test_the_roster_and_the_media_keys_are_one_button_group(self):+ """三个键问的是同一件事——这一页现在显示什么,所以在同一组里、同一个尺寸。"""self.assertCode(- "controls.hidden=!photos||(kind==='agency'&&agencyRosterView==='people');")- # 有显式 display 的元素不吃浏览器默认的 [hidden],隐藏要自己写一条。- self.assertPageContains(".mediaviewbuttons[hidden]{display:none}")+ "${peopleValue?control(peopleValue,peopleLabel,peopleCount,'user-round','people'):''}")+ self.assertPageContains("peopleValue:roster.length?'people':'',peopleCount:roster.length,")+ # 当前视图只有一个来源,按下哪个键、下面画什么都读它。+ self.assertPageContains("const entityViewNow=kind=>kind==='agency'"+ "&&agencyRosterView==='people'&&agencyRoster.length")+ self.assertCode("button.setAttribute('aria-pressed',String(now===media));")+ # 没有照片的实体不出照片键,不是出一个按下去什么都不显示的键。+ self.assertPageContains("imageValue:photoCount?'photos':'',imageLabel:'照片',")# 标签筛的是作品,点了就回到视频视图,否则开关和内容各说各的。self.assertCode("agencyRosterView='videos';")- self.assertCode(- "const rosterInput=$('#index').querySelector('[data-agency-view][value=\"videos\"]');")def test_the_profile_rows_that_overflow_get_the_shared_drag_and_wheel(self):"""同台艺人和标签这两行没有滚动条,不接拖动就是看得见够不着。"""@@ -4005,6 +4003,16 @@ class WebUiSourceTests(unittest.TestCase):self.assertPageLacks("tagmodes")self.assertPageContains(".viewmodes{")+ def test_the_index_head_controls_stand_on_the_same_plate(self):+ """并排的两组控件底色一样、高度一样,否则一组读成凭空多出来的一圈线。"""+ # `--surface` 和 `--ground` 只差四级灰,铺在页头上只剩边框看得见。+ self.assertPageContains("border-radius:var(--surface-radius);background:var(--overlay-5)}")+ # 28 + 3 padding + 1 border = 36,和邻座 `.iconswitch` 同高。+ self.assertPageContains(".viewmodes button{border:0;border-radius:var(--control-radius);"+ "background:transparent;color:var(--muted);height:28px;padding:0 10px;")+ self.assertPageContains(".iconswitch label{position:relative;display:inline-grid;"+ "width:34px;height:28px;")+def test_entity_name_picker_offers_only_this_entity_existing_names(self):# 候选取的是身份契约 `aliases`(完整),不是收窄过的展示别名:罗马字也是# 这个人真的用过的写法,用户想拿它当统称就该能选。@@ -5342,10 +5350,10 @@ class WebUiSourceTests(unittest.TestCase):self.assertPageContains('id="i-pics" viewBox="-1.6 -1.6 19.2 19.2" fill="currentColor" stroke="none"')self.assertPageContains('export function mediaViewButtonsHtml({')self.assertPageContains('class="mediaviewbutton" type="button" data-media-view="${esc(value)}"')- self.assertPageContains("const mediaToggle=photoCount?mediaViewButtonsHtml({active:mediaSelected?'photos':'videos'")- self.assertPageContains("imageValue:'photos',imageLabel:'照片',videoCount:d.asset_count,imageCount:photoCount")- self.assertPageContains('<section class="entitytagbar" aria-label="媒体与标签"><div class="entitytags">${rosterToggle}${mediaToggle}${tags}</div></section>')- self.assertPageContains("controls.hidden=!photos")+ self.assertCode("const mediaToggle=(photoCount||roster.length)?mediaViewButtonsHtml({\n"+ " active:entityViewNow(kind),")+ self.assertPageContains("videoCount:d.asset_count,imageCount:photoCount,")+ self.assertPageContains('<section class="entitytagbar" aria-label="媒体与标签"><div class="entitytags">${mediaToggle}${tags}</div></section>')self.assertPageContains("button.dataset.mediaView")self.assertPageContains(".mediaviewbuttons .mediaviewbutton{display:grid;place-items:center;flex:0 0 var(--filterItemH);width:var(--filterItemH);height:var(--filterItemH);padding:0;")self.assertPageContains(".mediaviewbuttons .mediaviewbutton svg{width:20px;height:20px")diff --git a/web/app.js b/web/app.jsindex c3d2c8a3e..4e6dcc77c 100644--- a/web/app.js+++ b/web/app.js@@ -50,7 +50,7 @@ let entityPhotos=null,entityMediaView=emptyMediaView(),photoWallItems=[];/* 事务所页看的是它签了谁,所以进页面先摆艺人。视频照样在,只是换一个开关的距离:那批片是成员各自拍的,混成一条 feed 回答不了「这家有哪些人」。每次进页面都回到艺人,切到视频是这一次浏览的选择,不是这类页面的常态。 */-let agencyRosterView='people';+let agencyRosterView='people',agencyRoster=[];let sidebarDragKey=null;let edgeT=null;/* 搜索下拉里被键盘选中的那一项。列表每次重建都要归零,否则索引会指向已经不存在的行。 */@@ -5385,7 +5385,6 @@ function markEntityCollectionBusy(kind,name,filters){head.querySelector('h3').innerHTML='<span class="countskeleton"></span>';wireEntityCollectionHead(section,kind,name,filters);}-const AGENCY_VIEWS=[['people','艺人','user-round'],['videos','视频','play']];/* 事务所名册。和艺人索引摆的是同一格、同一套版式设置,只是这批人随资料页一起下来了,不再单独请求;读数写的是这个人有多少视频。 */function renderAgencyRoster(people){@@ -5433,8 +5432,6 @@ async function updateEntityCollection(kind,name,filters,push=true){// 标签是作品筛选,点了就回到作品视图:留在照片或名册里既不生效,标签条也会自相矛盾。entityMediaView=emptyMediaView();agencyRosterView='videos';- const rosterInput=$('#index').querySelector('[data-agency-view][value="videos"]');- if(rosterInput)rosterInput.checked=true;const search=entityFilterSearch(filters);if(push)route(entityPath(kind,name)+(search?'?'+search:''));barsContext={type:'entity',kind,name,filters:{...filters}};@@ -5466,22 +5463,31 @@ const routeEntityView=(kind,name,view)=>{route(entityPath(kind,name)+(search?'?'+search:''))};const photoTotalOf=()=>entityPhotos&&!entityPhotos.error?(entityPhotos.total||0):0;+/* 这一页当前是哪个视图。名册和媒体不共用 `entityMediaView`:地址栏只认 `media`,+ 而名册是事务所页的默认视图,进页面就该在那里,不靠一个参数撑着。 */+const entityViewNow=kind=>kind==='agency'&&agencyRosterView==='people'&&agencyRoster.length+ ?'people':(entityMediaView.media==='photos'?'photos':'videos');+function renderEntityMediaToggle(kind,name,filters){const controls=$('#index').querySelector('.entitymediaview');if(!controls)return;- const photos=photoTotalOf();- /* 名册不是一种媒体。正看着艺人时「视频/照片」问的不是这一页在显示什么,两个开关- 摆在一起只会各说各的;切到媒体那一半它才回来。 */- controls.hidden=!photos||(kind==='agency'&&agencyRosterView==='people');- if(controls.hidden)return;+ const now=entityViewNow(kind);controls.querySelectorAll('[data-media-view]').forEach(button=>{const media=button.dataset.mediaView;- button.setAttribute('aria-pressed',String(entityMediaView.media===media));+ button.setAttribute('aria-pressed',String(now===media));button.onclick=()=>switchEntityMedia(kind,name,filters,media);});}async function switchEntityMedia(kind,name,filters,media){- if((entityMediaView.media==='photos')===(media==='photos')&&!entityMediaView.set)return;+ if(entityViewNow(kind)===media&&!entityMediaView.set)return;+ agencyRosterView=media==='people'?'people':'videos';+ if(media==='people'){+ entityMediaView=emptyMediaView();+ routeEntityView(kind,name,entityMediaView);+ renderEntityMediaToggle(kind,name,filters);+ renderAgencyRoster(agencyRoster);+ return;+ }entityMediaView=media==='photos'?{media:'photos',set:0}:emptyMediaView();routeEntityView(kind,name,entityMediaView);renderEntityMediaToggle(kind,name,filters);@@ -5913,19 +5919,21 @@ async function openEntity(kind,name,push=true){/* 事务所名下的这批人不摆在这排小圆头像里:那是「同台艺人」,一条附注;名册是这一页的正文,占的是下面那整块。所以同一份 `related_performers` 在事务所页走另一条路。 */const roster=kind==='agency'?(d.related_performers||[]):[];+ agencyRoster=roster;const related=roster.length?'':(d.related_performers||[]).map(x=>`<button class="relatedperson" data-related-performer="${esc(x.k)}"><span class="ring"><span>${esc(x.k.slice(0,1))}</span>${entityFaceImg({id:x.id,hasImage:x.has_image,rep:x.has_avatar?x.rep:null})}</span><span class="nm">${esc(x.k)}</span></button>`).join('');const photoCount=photos&&!photos.error?(photos.total||0):0;- const mediaSelected=entityMediaView.media==='photos';- const mediaToggle=photoCount?mediaViewButtonsHtml({active:mediaSelected?'photos':'videos',- imageValue:'photos',imageLabel:'照片',videoCount:d.asset_count,imageCount:photoCount,- className:'entitymediaview'}):'';- /* 艺人名册和视频 feed 是同一页的两个互斥视图,两个就用 Switch。切换只重画下面那块,- 不重开这一页:名册已经随资料下来了,视频那一半本来也要请求。 */- const rosterToggle=roster.length?iconSwitchHtml('agency-view','事务所页视图',- AGENCY_VIEWS,agencyRosterView,{attr:'data-agency-view',className:'entityview'}):'';+ /* 艺人名册和视频、照片是这一页的三个互斥视图,共用一组按钮:它们回答的是同一个+ 问题,摆成两个控件只会各说各的。切换只重画下面那块,不重开这一页——名册已经随+ 资料下来了,视频那一半本来也要请求。 */+ const mediaToggle=(photoCount||roster.length)?mediaViewButtonsHtml({+ active:entityViewNow(kind),+ peopleValue:roster.length?'people':'',peopleCount:roster.length,+ imageValue:photoCount?'photos':'',imageLabel:'照片',+ videoCount:d.asset_count,imageCount:photoCount,+ label:roster.length?'页面视图':'媒体类型',className:'entitymediaview'}):'';/* 统称由用户自己定。同一个人在库里常有中文、日文、罗马字几种写法,哪一个该顶在标题上是他的偏好,账本里没有能推出答案的字段。菜单只列这条实体名下已有的写法:换统称是换显示的那一个,不是改名——改名要有来源和证据,不该由一次点击完成。@@ -5966,7 +5974,7 @@ async function openEntity(kind,name,push=true){<div class="alias">${(d.display_aliases||[]).length?`${d.display_aliases.map(esc).join(' / ')} · `:''}<b>${d.asset_count.toLocaleString()}</b> 个视频${memberHtml}${agencyHtml}</div>${links?`<div class="entitylinks">${links}</div>`:''}</div></div>${related?`<div class="entitymeta"><section aria-label="同台艺人"><div class="relatedpeople">${related}</div></section></div>`:''}- ${(tags||mediaToggle||rosterToggle)?`<section class="entitytagbar" aria-label="媒体与标签"><div class="entitytags">${rosterToggle}${mediaToggle}${tags}</div></section>`:''}+ ${(tags||mediaToggle)?`<section class="entitytagbar" aria-label="媒体与标签"><div class="entitytags">${mediaToggle}${tags}</div></section>`:''}<div class="entitysection"></div>`;// 资料页的标签和顶部标签条是同一个开关,读的写的都是这一页的筛选。$('#index').querySelectorAll('[data-entity-tag]').forEach(b=>b.onclick=()=>@@ -5985,13 +5993,7 @@ async function openEntity(kind,name,push=true){entityPhotos=photos&&!photos.error?photos:null;if(entityMediaView.media==='photos'&&!photoTotalOf())entityMediaView=emptyMediaView();renderEntityMediaToggle(kind,name,filters);- if(rosterToggle)wireIconSwitch($('#index'),'data-agency-view',value=>{- agencyRosterView=value;- renderEntityMediaToggle(kind,name,filters);- if(value==='people')renderAgencyRoster(roster);- else if(entityMediaView.media==='photos')renderPhotoWall(kind,name,filters,entityPhotos);- else renderEntityCollection(kind,name,items,filters)});- if(rosterToggle&&agencyRosterView==='people')renderAgencyRoster(roster);+ if(entityViewNow(kind)==='people')renderAgencyRoster(roster);else if(entityMediaView.media!=='photos')renderEntityCollection(kind,name,items,filters);else if(entityMediaView.set)await openPhotoSet(kind,name,filters,entityMediaView.set,false);else renderPhotoWall(kind,name,filters,entityPhotos);diff --git a/web/css/06-index.css b/web/css/06-index.cssindex eda5dc4e2..e0726b24a 100644--- a/web/css/06-index.css+++ b/web/css/06-index.css@@ -27,8 +27,11 @@ body.entity-open .index{overflow-x:visible}.igrid[data-layout="big"] .icell .nm{font-size:var(--fs-sm)}.index .ihead .iconswitch{flex:none}.tagwall{display:flex;flex-wrap:wrap;gap:7px}-.viewmodes{display:flex;gap:4px;padding:3px;border:1px solid var(--line-soft);border-radius:var(--surface-radius);background:var(--surface)}-.viewmodes button{border:0;border-radius:var(--control-radius);background:transparent;color:var(--muted);padding:6px 10px;cursor:pointer;display:inline-flex;align-items:center;gap:6px}+/* 页头这几组控件并排站着,得是同一块板:底色和 `--ground` 只差四级灰的话,剩下能看见的+ 只有那圈边框,读起来是凭空多出来的一条线,而邻座 `.iconswitch` 是有填充的一块。+ 高度也钉成和它一样的 36px(28 + 3 padding + 1 border),并排才谈得上底部对齐。 */+.viewmodes{display:flex;gap:4px;padding:3px;border:1px solid var(--line-soft);border-radius:var(--surface-radius);background:var(--overlay-5)}+.viewmodes button{border:0;border-radius:var(--control-radius);background:transparent;color:var(--muted);height:28px;padding:0 10px;cursor:pointer;display:inline-flex;align-items:center;gap:6px}.viewmodes button svg{width:15px;height:15px;stroke:currentColor;fill:none;stroke-width:1.8}/* 「Aa」是 1.4:1 的字形,宽高都锁 15px 只能按宽缩,画出来比邻座矮一截。 */.viewmodes button svg.iconwide{width:auto}diff --git a/web/css/07-entity.css b/web/css/07-entity.cssindex eed59bb62..8cab0e14b 100644--- a/web/css/07-entity.css+++ b/web/css/07-entity.css@@ -63,9 +63,7 @@/* 这条是横向滚动行,里面每一项都得拒绝被压扁——挤瘪的开关点不准,也读不出图标。 */.entitytags .iconswitch{flex:none}.entitytags small{color:var(--muted);margin-left:4px}-/* 有显式 display 的元素不会被浏览器默认的 [hidden]{display:none} 隐藏,得自己写。 */.mediaviewbuttons{display:inline-flex;align-items:center;gap:2px;flex:none}-.mediaviewbuttons[hidden]{display:none}.mediaviewbuttons .mediaviewbutton{display:grid;place-items:center;flex:0 0 var(--filterItemH);width:var(--filterItemH);height:var(--filterItemH);padding:0;border:0;border-radius:50%;background:transparent;color:var(--muted);cursor:pointer}.mediaviewbuttons .mediaviewbutton svg{width:20px;height:20px;stroke:currentColor;fill:none;stroke-width:2}diff --git a/web/js/ui-components.js b/web/js/ui-components.jsindex 193c26cfd..18afd0aa2 100644--- a/web/js/ui-components.js+++ b/web/js/ui-components.js@@ -188,21 +188,28 @@ export function fitSkeleton(root){}}-/** Shared video/image view buttons for entity profiles and the follow feed. */+/**+ * 资料页与关注列表共用的视图按钮:一排、一个尺寸。+ *+ * 这几个键问的是同一件事——这一页现在显示什么,所以都是这一组里的按钮,不另起控件。+ * 给空值的那一位不出按钮:没有照片的人不该看见照片键,不是事务所的实体没有名册。+ */export function mediaViewButtonsHtml({- active='videos',videoValue='videos',imageValue='images',videoLabel='视频',imageLabel='图片',- videoCount=null,imageCount=null,className='',+ active='videos',peopleValue='',videoValue='videos',imageValue='images',+ peopleLabel='艺人',videoLabel='视频',imageLabel='图片',+ peopleCount=null,videoCount=null,imageCount=null,label='媒体类型',className='',}={}){- const control=(value,label,count,symbol,kind)=>{- const text=count===null||count===undefined- ?label:`${label} ${Math.max(0,Number(count)||0).toLocaleString()}`;+ const control=(value,text,count,symbol,kind)=>{+ const title=count===null||count===undefined+ ?text:`${text} ${Math.max(0,Number(count)||0).toLocaleString()}`;return `<button class="mediaviewbutton" type="button" data-media-view="${esc(value)}"- data-media-icon="${kind}" aria-pressed="${active===value}" aria-label="${esc(text)}"- title="${esc(text)}">${icon(symbol)}</button>`;+ data-media-icon="${kind}" aria-pressed="${active===value}" aria-label="${esc(title)}"+ title="${esc(title)}">${icon(symbol)}</button>`;};- return `<div class="mediaviewbuttons${className?` ${esc(className)}`:''}" role="group" aria-label="媒体类型">- ${control(videoValue,videoLabel,videoCount,'play','video')}- ${control(imageValue,imageLabel,imageCount,'pics','image')}</div>`;+ return `<div class="mediaviewbuttons${className?` ${esc(className)}`:''}" role="group" aria-label="${esc(label)}">+ ${peopleValue?control(peopleValue,peopleLabel,peopleCount,'user-round','people'):''}+ ${videoValue?control(videoValue,videoLabel,videoCount,'play','video'):''}+ ${imageValue?control(imageValue,imageLabel,imageCount,'pics','image'):''}</div>`;}/** Geist Empty State: icon tile, title and explanatory copy stay one semantic unit. */