2014-04-01 02:01:44 +00:00
/ *
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
Copyright 2014 The Perkeep Authors
2014-04-01 02:01:44 +00:00
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.BlobItemImageContent' ) ;
goog . require ( 'goog.math.Size' ) ;
goog . require ( 'cam.math' ) ;
2014-07-31 19:30:29 +00:00
goog . require ( 'cam.permanodeUtils' ) ;
2014-04-01 02:01:44 +00:00
goog . require ( 'cam.PyramidThrobber' ) ;
goog . require ( 'cam.Thumber' ) ;
// Renders image blob items. Handles the following cases:
// a) camliType == 'file', and also has an 'image' property.
// b) permanode with camliContent pointing to (a)
// c) permanode with 'camliImageContent' attribute pointing to (a)
cam . BlobItemImageContent = React . createClass ( {
displayName : 'BlobItemImageContent' ,
propTypes : {
aspect : React . PropTypes . number . isRequired ,
href : React . PropTypes . string . isRequired ,
size : React . PropTypes . instanceOf ( goog . math . Size ) . isRequired ,
src : React . PropTypes . string . isRequired ,
title : React . PropTypes . string ,
} ,
getInitialState : function ( ) {
return {
loaded : false ,
} ;
} ,
componentWillMount : function ( ) {
this . currentIntrinsicThumbHeight _ = 0 ;
} ,
componentDidUpdate : function ( prevProps , prevState ) {
// TODO(aa): It seems like we would not need this if we always use this component with the 'key' prop.
if ( prevProps . blobref != this . props . blobref ) {
this . currentIntrinsicThumbHeight _ = 0 ;
this . setState ( { loaded : false } ) ;
}
} ,
render : function ( ) {
var thumbClipSize = new goog . math . Size ( this . props . size . width , this . props . size . height ) ;
return React . DOM . a ( { href : this . props . href } ,
React . DOM . div ( { className : this . getThumbClipClassName _ ( ) , style : thumbClipSize } ,
this . getThrobber _ ( thumbClipSize ) ,
this . getThumb _ ( thumbClipSize )
)
) ;
} ,
onThumbLoad _ : function ( ) {
this . setState ( { loaded : true } ) ;
} ,
getThumbClipClassName _ : function ( ) {
2017-01-25 17:19:51 +00:00
return classNames ( {
2014-04-01 02:01:44 +00:00
'cam-blobitem-thumbclip' : true ,
'cam-blobitem-loading' : ! this . state . loaded ,
} ) ;
} ,
getThrobber _ : function ( thumbClipSize ) {
if ( this . state . loaded ) {
return null ;
}
2017-01-25 17:19:51 +00:00
return React . createElement ( cam . PyramidThrobber , {
pos : cam . math . center ( cam . PyramidThrobber . SIZE , thumbClipSize )
} ) ;
2014-04-01 02:01:44 +00:00
} ,
getThumb _ : function ( thumbClipSize ) {
var thumbSize = this . getThumbSize _ ( thumbClipSize ) ;
var pos = cam . math . center ( thumbSize , thumbClipSize ) ;
return React . DOM . img ( {
className : 'cam-blobitem-thumb' ,
2014-04-18 02:24:09 +00:00
onLoad : this . onThumbLoad _ ,
2014-04-01 02:01:44 +00:00
src : this . props . src ,
style : { left : pos . x , top : pos . y , visibility : ( this . state . loaded ? 'visible' : 'hidden' ) } ,
title : this . props . title ,
width : thumbSize . width ,
height : thumbSize . height ,
} )
} ,
getThumbSize _ : function ( thumbClipSize ) {
var bleed = true ;
return cam . math . scaleToFit ( new goog . math . Size ( this . props . aspect , 1 ) , thumbClipSize , bleed ) ;
} ,
} ) ;
cam . BlobItemImageContent . getHandler = function ( blobref , searchSession , href ) {
var rm = searchSession . getResolvedMeta ( blobref ) ;
if ( rm && rm . image ) {
return new cam . BlobItemImageContent . Handler ( rm , href , searchSession . getTitle ( blobref ) ) ;
}
var m = searchSession . getMeta ( blobref ) ;
2014-07-31 19:30:29 +00:00
if ( m . camliType != 'permanode' ) {
return null ;
}
// Sets can have the camliContentImage attr to indicate a user-chosen "cover image" for the entire set. Until we have some rendering for those, the folder in the generic handler is a better fit than the single image.
if ( cam . permanodeUtils . isContainer ( m . permanode ) ) {
return null ;
}
var cci = cam . permanodeUtils . getSingleAttr ( m . permanode , 'camliContentImage' ) ;
if ( cci ) {
var ccim = searchSession . getResolvedMeta ( cci ) ;
if ( ccim ) {
return new cam . BlobItemImageContent . Handler ( ccim , href , searchSession . getTitle ( blobref ) ) ;
2014-04-01 02:01:44 +00:00
}
}
return null ;
} ;
cam . BlobItemImageContent . Handler = function ( imageMeta , href , title ) {
this . imageMeta _ = imageMeta ;
this . href _ = href ;
this . title _ = title ;
this . thumber _ = cam . Thumber . fromImageMeta ( imageMeta ) ;
} ;
cam . BlobItemImageContent . Handler . prototype . getAspectRatio = function ( ) {
return this . imageMeta _ . image . width / this . imageMeta _ . image . height ;
} ;
cam . BlobItemImageContent . Handler . prototype . createContent = function ( size ) {
2017-01-25 17:19:51 +00:00
return React . createElement ( cam . BlobItemImageContent , {
2014-04-01 02:01:44 +00:00
aspect : this . getAspectRatio ( ) ,
href : this . href _ ,
size : size ,
src : this . thumber _ . getSrc ( size . height ) ,
title : this . title _ ,
} ) ;
} ;