2014-03-26 04:41:31 +00:00
/ *
Copyright 2014 The Camlistore Authors
Licensed under the Apache License , Version 2.0 ( the "License" ) ;
you may not use this file except in compliance with the License .
You may obtain a copy of the License at
http : //www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing , software
distributed under the License is distributed on an "AS IS" BASIS ,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
See the License for the specific language governing permissions and
limitations under the License .
* /
goog . provide ( 'cam.ImageDetail' ) ;
2014-05-18 19:16:35 +00:00
goog . require ( 'cam.BlobItemVideoContent' ) ;
2014-04-01 02:01:44 +00:00
goog . require ( 'cam.Thumber' ) ;
// Renders the guts of the detail view for images.
2014-03-26 04:41:31 +00:00
cam . ImageDetail = React . createClass ( {
displayName : 'ImageDetail' ,
IMG _MARGIN : 20 ,
PIGGY _WIDTH : 88 ,
PIGGY _HEIGHT : 62 ,
propTypes : {
2014-04-18 02:24:09 +00:00
backwardPiggy : React . PropTypes . bool . isRequired ,
2014-03-26 04:41:31 +00:00
height : React . PropTypes . number . isRequired ,
2014-04-01 02:01:44 +00:00
permanodeMeta : React . PropTypes . object ,
resolvedMeta : React . PropTypes . object . isRequired ,
2014-03-26 04:41:31 +00:00
width : React . PropTypes . number . isRequired ,
} ,
2014-05-18 19:16:35 +00:00
isVideo _ : function ( ) {
return ! this . isImage _ ( ) ;
} ,
isImage _ : function ( ) {
return Boolean ( this . props . resolvedMeta . image ) ;
} ,
2014-03-26 04:41:31 +00:00
componentWillReceiveProps : function ( nextProps ) {
2014-04-01 02:01:44 +00:00
if ( this . props == nextProps || this . props . resolvedMeta . blobRef != nextProps . resolvedMeta . blobRef ) {
2014-05-18 19:16:35 +00:00
this . thumber _ = nextProps . resolvedMeta . image && cam . Thumber . fromImageMeta ( nextProps . resolvedMeta ) ;
2014-03-26 04:41:31 +00:00
this . setState ( { imgHasLoaded : false } ) ;
}
} ,
2014-04-01 02:01:44 +00:00
componentWillMount : function ( ) {
this . componentWillReceiveProps ( this . props , true ) ;
} ,
2014-03-26 04:41:31 +00:00
render : function ( ) {
this . imgSize _ = this . getImgSize _ ( ) ;
return React . DOM . div ( { className : 'detail-view' , style : this . getStyle _ ( ) } , [
this . getImg _ ( ) ,
this . getPiggy _ ( ) ,
] ) ;
} ,
getSinglePermanodeAttr _ : function ( name ) {
2014-04-01 02:01:44 +00:00
return cam . permanodeUtils . getSingleAttr ( this . props . permanodeMeta . permanode , name ) ;
2014-03-26 04:41:31 +00:00
} ,
onImgLoad _ : function ( ) {
this . setState ( { imgHasLoaded : true } ) ;
} ,
getImg _ : function ( ) {
var transition = React . addons . TransitionGroup ( { transitionName : 'detail-img' } , [ ] ) ;
if ( this . imgSize _ ) {
2014-05-18 19:16:35 +00:00
var ctor = this . props . resolvedMeta . image ? React . DOM . img : React . DOM . video ;
2014-03-26 04:41:31 +00:00
transition . props . children . push (
2014-05-18 19:16:35 +00:00
ctor ( {
2014-03-26 04:41:31 +00:00
className : React . addons . classSet ( {
'detail-view-img' : true ,
2014-05-18 19:16:35 +00:00
'detail-view-img-loaded' : this . isImage _ ( ) ? this . state . imgHasLoaded : true ,
2014-03-26 04:41:31 +00:00
} ) ,
2014-05-18 19:16:35 +00:00
controls : true ,
2014-03-26 04:41:31 +00:00
// We want each image to have its own node in the DOM so that during the crossfade, we don't see the image jump to the next image's size.
2014-04-18 02:24:09 +00:00
key : 'img' + this . props . resolvedMeta . blobRef ,
2014-05-18 19:16:35 +00:00
onLoad : this . isImage _ ( ) ? this . onImgLoad _ : null ,
src : this . isImage _ ( ) ? this . thumber _ . getSrc ( this . imgSize _ . height ) : './download/' + this . props . resolvedMeta . blobRef + '/' + this . props . resolvedMeta . file . fileName ,
2014-03-26 04:41:31 +00:00
style : this . getCenteredProps _ ( this . imgSize _ . width , this . imgSize _ . height )
} )
) ;
}
return transition ;
} ,
getPiggy _ : function ( ) {
var transition = React . addons . TransitionGroup ( { transitionName : 'detail-piggy' } , [ ] ) ;
2014-05-18 19:16:35 +00:00
if ( this . isImage _ ( ) && ! this . state . imgHasLoaded ) {
2014-03-26 04:41:31 +00:00
transition . props . children . push (
cam . SpritedAnimation ( {
src : 'glitch/npc_piggy__x1_walk_png_1354829432.png' ,
className : React . addons . classSet ( {
'detail-view-piggy' : true ,
'detail-view-piggy-backward' : this . props . backwardPiggy
} ) ,
2014-08-10 03:17:10 +00:00
numFrames : 24 ,
2014-03-26 04:41:31 +00:00
spriteWidth : this . PIGGY _WIDTH ,
spriteHeight : this . PIGGY _HEIGHT ,
sheetWidth : 8 ,
style : this . getCenteredProps _ ( this . PIGGY _WIDTH , this . PIGGY _HEIGHT )
} ) ) ;
}
return transition ;
} ,
getCenteredProps _ : function ( w , h ) {
2014-08-10 03:17:10 +00:00
var avail = new goog . math . Size ( this . props . width , this . props . height ) ;
2014-03-26 04:41:31 +00:00
return {
top : ( avail . height - h ) / 2 ,
left : ( avail . width - w ) / 2 ,
width : w ,
height : h
}
} ,
getImgSize _ : function ( ) {
2014-05-18 19:16:35 +00:00
if ( this . isVideo _ ( ) ) {
return new goog . math . Size ( this . props . width , this . props . height ) ;
2014-03-26 04:41:31 +00:00
}
2014-04-01 02:01:44 +00:00
var rawSize = new goog . math . Size ( this . props . resolvedMeta . image . width , this . props . resolvedMeta . image . height ) ;
2014-03-26 04:41:31 +00:00
var available = new goog . math . Size (
2014-08-10 03:17:10 +00:00
this . props . width - this . IMG _MARGIN * 2 ,
2014-03-26 04:41:31 +00:00
this . props . height - this . IMG _MARGIN * 2 ) ;
if ( rawSize . height <= available . height && rawSize . width <= available . width ) {
return rawSize ;
}
return rawSize . scaleToFit ( available ) ;
} ,
getStyle _ : function ( ) {
return {
width : this . props . width ,
height : this . props . height
}
} ,
} ) ;
Aspects: A new idea for the detail page.
http://imgur.com/Re14XKc,6fYHJqp,39nnQiT#0
Camlistore is built around the idea that every object is a blob,
but blobs can also self-describe themselves as more than a blob.
For example, some blobs are also files, or images, or sets, or
permanodes, or movies, or foursquare checkins. Etc.
Here is an idea for the detail page that reflects that underlying
reality of Camlistore.
Each blob has a single canonical URL in the web UI for its detail
page. Currently this is /?p=<...>, but should ideally be just
/<blobref>.
Within the web UI, many "aspects" register interest in providing
views on blobs. Each time the user navigates to a detail page,
each aspects gets to say whether it can provide a useful view on
the blob.
Aspects are currently rendered (crappily) as tabs along the bottom
of the UI. I'm not sure how they should actually be rendered, this
is temporary.
This patch includes the following aspects:
- image (the old image detail)
- permanode (the old old permanode page)
- blob (the old old blob page)
Change-Id: Idb3cdbb203799a5d9c113d1b37b67a2724040085
2014-04-14 16:20:22 +00:00
cam . ImageDetail . getAspect = function ( blobref , searchSession ) {
2014-08-10 03:17:10 +00:00
if ( ! blobref ) {
return null ;
}
Aspects: A new idea for the detail page.
http://imgur.com/Re14XKc,6fYHJqp,39nnQiT#0
Camlistore is built around the idea that every object is a blob,
but blobs can also self-describe themselves as more than a blob.
For example, some blobs are also files, or images, or sets, or
permanodes, or movies, or foursquare checkins. Etc.
Here is an idea for the detail page that reflects that underlying
reality of Camlistore.
Each blob has a single canonical URL in the web UI for its detail
page. Currently this is /?p=<...>, but should ideally be just
/<blobref>.
Within the web UI, many "aspects" register interest in providing
views on blobs. Each time the user navigates to a detail page,
each aspects gets to say whether it can provide a useful view on
the blob.
Aspects are currently rendered (crappily) as tabs along the bottom
of the UI. I'm not sure how they should actually be rendered, this
is temporary.
This patch includes the following aspects:
- image (the old image detail)
- permanode (the old old permanode page)
- blob (the old old blob page)
Change-Id: Idb3cdbb203799a5d9c113d1b37b67a2724040085
2014-04-14 16:20:22 +00:00
var rm = searchSession . getResolvedMeta ( blobref ) ;
var pm = searchSession . getMeta ( blobref ) ;
2014-08-10 03:17:10 +00:00
if ( ! pm ) {
return null ;
}
Aspects: A new idea for the detail page.
http://imgur.com/Re14XKc,6fYHJqp,39nnQiT#0
Camlistore is built around the idea that every object is a blob,
but blobs can also self-describe themselves as more than a blob.
For example, some blobs are also files, or images, or sets, or
permanodes, or movies, or foursquare checkins. Etc.
Here is an idea for the detail page that reflects that underlying
reality of Camlistore.
Each blob has a single canonical URL in the web UI for its detail
page. Currently this is /?p=<...>, but should ideally be just
/<blobref>.
Within the web UI, many "aspects" register interest in providing
views on blobs. Each time the user navigates to a detail page,
each aspects gets to say whether it can provide a useful view on
the blob.
Aspects are currently rendered (crappily) as tabs along the bottom
of the UI. I'm not sure how they should actually be rendered, this
is temporary.
This patch includes the following aspects:
- image (the old image detail)
- permanode (the old old permanode page)
- blob (the old old blob page)
Change-Id: Idb3cdbb203799a5d9c113d1b37b67a2724040085
2014-04-14 16:20:22 +00:00
if ( pm . camliType != 'permanode' ) {
pm = null ;
}
// We don't handle camliContentImage like BlobItemImage.getHandler does because that only tells us what image to display in the search results. It doesn't actually make the permanode an image or anything.
2014-08-15 06:04:37 +00:00
if ( rm && ( rm . image || cam . BlobItemVideoContent . isVideo ( rm ) ) ) {
return {
fragment : 'image' ,
title : 'Image' ,
createContent : function ( size ) {
return cam . ImageDetail ( {
backwardPiggy : false ,
key : 'image' ,
height : size . height ,
permanodeMeta : pm ,
resolvedMeta : rm ,
width : size . width ,
} ) ;
} ,
} ;
} else {
return null ;
}
Aspects: A new idea for the detail page.
http://imgur.com/Re14XKc,6fYHJqp,39nnQiT#0
Camlistore is built around the idea that every object is a blob,
but blobs can also self-describe themselves as more than a blob.
For example, some blobs are also files, or images, or sets, or
permanodes, or movies, or foursquare checkins. Etc.
Here is an idea for the detail page that reflects that underlying
reality of Camlistore.
Each blob has a single canonical URL in the web UI for its detail
page. Currently this is /?p=<...>, but should ideally be just
/<blobref>.
Within the web UI, many "aspects" register interest in providing
views on blobs. Each time the user navigates to a detail page,
each aspects gets to say whether it can provide a useful view on
the blob.
Aspects are currently rendered (crappily) as tabs along the bottom
of the UI. I'm not sure how they should actually be rendered, this
is temporary.
This patch includes the following aspects:
- image (the old image detail)
- permanode (the old old permanode page)
- blob (the old old blob page)
Change-Id: Idb3cdbb203799a5d9c113d1b37b67a2724040085
2014-04-14 16:20:22 +00:00
} ;