From bc037315470431ac1f1ba2c7365ca634895e113f Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch
Date: Mon, 25 Dec 2023 02:44:30 +0100 Subject: Shuffle code --- public/gallery.js | 230 +++++++++++++++++++++++++++--------------------------- 1 file changed, 115 insertions(+), 115 deletions(-) (limited to 'public/gallery.js') diff --git a/public/gallery.js b/public/gallery.js index 4933064..52a92ab 100644 --- a/public/gallery.js +++ b/public/gallery.js @@ -253,6 +253,120 @@ let Tags = { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +let DuplicatesModel = { + entries: [], + + async reload() { + this.entries = await call('duplicates', {}) + }, +} + +let DuplicatesThumbnail = { + view(vnode) { + const info = vnode.attrs.info + return [ + m(m.route.Link, {href: `/similar/${info.sha1}`}, + m(Thumbnail, {info})), + (info.occurences != 1) ? ` ×${info.occurences}` : [], + ] + }, +} + +let DuplicatesList = { + // See BrowseView. + oncreate(vnode) { vnode.dom.focus() }, + + view(vnode) { + let children = (DuplicatesModel.entries.length == 0) + ? "No duplicates" + : DuplicatesModel.entries.map(group => + m('.row', group.map(entry => + m(DuplicatesThumbnail, {info: entry})))) + return m('.duplicates[tabindex=0]', {}, children) + }, +} + +let Duplicates = { + oninit(vnode) { + DuplicatesModel.reload() + }, + + view(vnode) { + return m('.container', {}, [ + m(Header), + m('.body', {}, m(DuplicatesList)), + ]) + }, +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +let OrphansModel = { + entries: [], + + async reload() { + this.entries = await call('orphans', {}) + }, +} + +let OrphansReplacement = { + view(vnode) { + const info = vnode.attrs.info + if (!info) + return [] + + return [ + ` → `, + m(m.route.Link, {href: `/view/${info.sha1}`}, + m(Thumbnail, {info})), + `${info.tags} tags`, + ] + }, +} + +let OrphansRow = { + view(vnode) { + const info = vnode.attrs.info + return m('.row', [ + // It might not load, but still allow tag viewing. + m(m.route.Link, {href: `/view/${info.sha1}`}, + m(Thumbnail, {info})), + `${info.tags} tags`, + m(OrphansReplacement, {info: info.replacement}), + ]) + }, +} + +let OrphansList = { + // See BrowseView. + oncreate(vnode) { vnode.dom.focus() }, + + view(vnode) { + let children = (OrphansModel.entries.length == 0) + ? "No orphans" + : OrphansModel.entries.map(info => [ + m("h2", info.lastPath), + m(OrphansRow, {info}), + ]) + return m('.orphans[tabindex=0]', {}, children) + }, +} + +let Orphans = { + oninit(vnode) { + OrphansModel.reload() + }, + + view(vnode) { + return m('.container', {}, [ + m(Header), + m('.body', {}, m(OrphansList)), + ]) + }, +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + let ViewModel = { sha1: undefined, width: 0, @@ -427,120 +541,6 @@ let Similar = { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -let DuplicatesModel = { - entries: [], - - async reload() { - this.entries = await call('duplicates', {}) - }, -} - -let DuplicatesThumbnail = { - view(vnode) { - const info = vnode.attrs.info - return [ - m(m.route.Link, {href: `/similar/${info.sha1}`}, - m(Thumbnail, {info})), - (info.occurences != 1) ? ` ×${info.occurences}` : [], - ] - }, -} - -let DuplicatesList = { - // See BrowseView. - oncreate(vnode) { vnode.dom.focus() }, - - view(vnode) { - let children = (DuplicatesModel.entries.length == 0) - ? "No duplicates" - : DuplicatesModel.entries.map(group => - m('.row', group.map(entry => - m(DuplicatesThumbnail, {info: entry})))) - return m('.duplicates[tabindex=0]', {}, children) - }, -} - -let Duplicates = { - oninit(vnode) { - DuplicatesModel.reload() - }, - - view(vnode) { - return m('.container', {}, [ - m(Header), - m('.body', {}, m(DuplicatesList)), - ]) - }, -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -let OrphansModel = { - entries: [], - - async reload() { - this.entries = await call('orphans', {}) - }, -} - -let OrphansReplacement = { - view(vnode) { - const info = vnode.attrs.info - if (!info) - return [] - - return [ - ` → `, - m(m.route.Link, {href: `/view/${info.sha1}`}, - m(Thumbnail, {info})), - `${info.tags} tags`, - ] - }, -} - -let OrphansRow = { - view(vnode) { - const info = vnode.attrs.info - return m('.row', [ - // It might not load, but still allow tag viewing. - m(m.route.Link, {href: `/view/${info.sha1}`}, - m(Thumbnail, {info})), - `${info.tags} tags`, - m(OrphansReplacement, {info: info.replacement}), - ]) - }, -} - -let OrphansList = { - // See BrowseView. - oncreate(vnode) { vnode.dom.focus() }, - - view(vnode) { - let children = (OrphansModel.entries.length == 0) - ? "No orphans" - : OrphansModel.entries.map(info => [ - m("h2", info.lastPath), - m(OrphansRow, {info}), - ]) - return m('.orphans[tabindex=0]', {}, children) - }, -} - -let Orphans = { - oninit(vnode) { - OrphansModel.reload() - }, - - view(vnode) { - return m('.container', {}, [ - m(Header), - m('.body', {}, m(OrphansList)), - ]) - }, -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - window.addEventListener('load', () => { m.route(document.body, "/browse/", { // The path doesn't need to be escaped, perhaps change that (":key..."). @@ -554,6 +554,6 @@ window.addEventListener('load', () => { "/view/:key": View, "/similar/:key": Similar, - "/search/:space/:tag": undefined, + "/search/:key": undefined, }) }) -- cgit v1.2.3-70-g09d2