Skip to content

Commit

Permalink
/galleries/:id expands upon /search/G321
Browse files Browse the repository at this point in the history
truncate the gallery panel text on search pages, it gets a bit wordy. Show full text on dedicated gallery pages
  • Loading branch information
kjell committed Dec 28, 2015
1 parent aff65cd commit 3fc6144
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 8 deletions.
2 changes: 2 additions & 0 deletions routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var Curators = require('./src/curators')
var Explore = require('./src/explore')
var Page = require('./src/page')
var Info = require('./src/info')
var Gallery = require('./src/gallery')

var routes = (
<Route handler={App} path="/">
Expand All @@ -34,6 +35,7 @@ var routes = (
<Route name="objectsById" path="/search/ids/:ids" handler={ObjectsById} />
<Route name="page" path="/info/:name" handler={Page} />
<Route name="info" path="/info" handler={Info} />
<Route name="gallery" path="/galleries/:gallery" handler={Gallery} />
</Route>
);

Expand Down
7 changes: 4 additions & 3 deletions src/decorate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var Decorate = React.createClass({
render() {
var {query, filters} = this.props.search
if(!query && !filters) return <span />
var decorations = DecorationFinder(query, filters, this.props.params)
var decorations = DecorationFinder(query, filters, this.props)
var {showDecorators} = this.state

return decorations.length > 0 && <div
Expand Down Expand Up @@ -49,13 +49,14 @@ var Decorate = React.createClass({

module.exports = Decorate

var DecorationFinder = (search, filters, params) => {
var DecorationFinder = (search, filters, props) => {
let {params} = props
let terms = search.match(/\w+.+|"(?:\\"|[^"])+"/g) || search.split(' ')
if(filters) terms = terms.concat(filters.split('" ').map(f => f.trim()))

var Decor = {
"department:": (term) => <DepartmentDecorator department={term} params={params} />,
"g[0-9]{3}a?": (gallery) => <GalleryDecorator gallery={gallery[0]} />,
"g[0-9]{3}a?": (gallery) => <GalleryDecorator gallery={gallery[0]} {...props} />,
"Not on View": (gallery) => <GalleryDecorator notOnView={true} />,
"highlight:": () => <HighlightsDecorator />,
"recent:": () => <RecentDecorator />,
Expand Down
23 changes: 20 additions & 3 deletions src/decorate/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,38 @@ var GalleryDecorator = React.createClass({
render() {
if(this.props.notOnView) return <NotOnViewGalleryDecorator />
var {number, gallery, panel} = this.state
var showFullInfo = this.props.showFullGalleryInfo
if(panel && !showFullInfo) {
panel = panel.slice(0, 200) + '…'
}

let [prevLink, nextLink] = this.nextPrevLinks()

return <div style={{clear: 'both'}} className="decorator d-gallery">
<div className="info">
<img src={`http://artsmia.github.io/map/galleries/${number}.png`} />
<div>
<Link to='searchResults' params={{terms: `G${gallery.prev}`}}>&larr; G{gallery.prev}</Link>
{prevLink}
<span> G{number} </span>
<Link to='searchResults' params={{terms: `G${gallery.next}`}}>G{gallery.next} &rarr;</Link>
{nextLink}
</div>
</div>
{panel && <Markdown>{panel}</Markdown>}
{panel && <div>
<Markdown>{panel}</Markdown>
{!showFullInfo && <Link to='gallery' params={{gallery: number}}>More info</Link>}
</div>}
<hr style={{clear: 'both', visibility: 'hidden'}} />
</div>
},

nextPrevLinks() {
var {number, gallery, panel} = this.state

return this.props.showFullGalleryInfo ?
[<Link to='gallery' params={{gallery: gallery.prev}}>&larr; G{gallery.prev}</Link>, <Link to='gallery' params={{gallery: gallery.next}}>G{gallery.next} &rarr;</Link>] :
[<Link to='searchResults' params={{terms: `G${gallery.prev}`}}>&larr; G{gallery.prev}</Link>, <Link to='searchResults' params={{terms: `G${gallery.next}`}}>G{gallery.next} &rarr;</Link>]
},

fetchData(number) {
rest(`https://cdn.rawgit.com/artsmia/mia-gallery-panels/master/${number || this.state.number}.md`)
.then((result) => {
Expand Down
47 changes: 47 additions & 0 deletions src/gallery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var React = require('react')
var Router = require('react-router')
var Helmet = require('react-helmet')

var rest = require('rest')

var Search = require('./search')
var SearchResults = require('./search-results')
var GalleryDecorator = require('./decorate/gallery.js')
var Markdown = require('./markdown')
var Peek = require('./peek')

var Gallery = React.createClass({
mixins: [Router.State],

statics: {
fetchData: {
gallery: (params, query) => {
var id = params.gallery.replace(/g/i, '')
var url = `https://cdn.rawgit.com/artsmia/mia-gallery-panels/master/${id}.md`
return rest(url).then(result => result.entity)
},
searchResults: (params, query) => {
if(!params.gallery.match(/g/i)) params.gallery = `G${params.gallery}`
params.terms = '*'
params.splat = 'room:"'+params.gallery+'"'
return SearchResults.fetchData.searchResults(params, query)
},
// departments: (params, query) => {
// return rest(endpoint).then((r) => JSON.parse(r.entity))
// }
},
},

render() {
var {gallery} = this.props.params
var facet = `room:"${gallery}"`

return <Search
facet={facet}
{...this.props}
summaryProps={{showFullGalleryInfo: true}}
/>
},
})

module.exports = Gallery
1 change: 1 addition & 0 deletions src/search-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ var SearchResults = React.createClass({
showAggs: this.props.showAggs,
toggleAggs: this.props.toggleAggs,
showMoreLink,
...this.props.summaryProps
}

return <div>
Expand Down
4 changes: 2 additions & 2 deletions src/search-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const SearchSummary = React.createClass({
</h2></div><div className="mdl-cell mdl-cell--2-col">{toggleAggs}</div>
</div>
{showAggs && <Aggregations search={search} />}
<Decorate search={search} params={this.props.params} />
<Decorate search={search} params={this.props.params} {...this.props} />
<Helmet
title={`${search.query}`}
meta={[
Expand All @@ -60,7 +60,7 @@ const SearchSummary = React.createClass({
</div>

{showAggs && <Aggregations search={search} />}
<Decorate search={search} params={this.props.params} />
<Decorate search={search} params={this.props.params} {...this.props} />
<Helmet
title={`${search.query}`}
meta={[
Expand Down

0 comments on commit 3fc6144

Please sign in to comment.