diff options
Diffstat (limited to 'public')
-rw-r--r-- | public/gallery.js | 230 |
1 files changed, 115 insertions, 115 deletions
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, }) }) |