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.BlobItemGenericContent' ) ;
goog . require ( 'goog.math.Size' ) ;
goog . require ( 'cam.math' ) ;
goog . require ( 'cam.object' ) ;
goog . require ( 'cam.permanodeUtils' ) ;
// Renders the content of blob items that are not known to be some more specific type. A generic file or folder icon is shown, along with a title if one can be determined.
cam . BlobItemGenericContent = React . createClass ( {
displayName : 'BlobItemGenericContent' ,
TITLE _HEIGHT : 22 ,
propTypes : {
href : React . PropTypes . string . isRequired ,
size : React . PropTypes . instanceOf ( goog . math . Size ) . isRequired ,
thumbSrc : React . PropTypes . string . isRequired ,
thumbAspect : React . PropTypes . number . isRequired ,
title : React . PropTypes . string . isRequired ,
} ,
render : function ( ) {
var thumbClipSize = this . getThumbClipSize _ ( ) ;
// TODO(aa): I think we don't need/want the thumb clip div anymore. We can just make the anchor position:relative position the thumb inside it.
return React . DOM . a ( { href : this . props . href } ,
React . DOM . div ( { className : this . getThumbClipClassName _ ( ) , style : thumbClipSize } ,
this . getThumb _ ( thumbClipSize )
) ,
this . getLabel _ ( )
) ;
} ,
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' : false ,
} ) ;
} ,
getThumb _ : function ( thumbClipSize ) {
var thumbSize = this . getThumbSize _ ( thumbClipSize ) ;
var pos = cam . math . center ( thumbSize , thumbClipSize ) ;
return React . DOM . img ( {
className : 'cam-blobitem-thumb' ,
ref : 'thumb' ,
src : this . props . thumbSrc ,
style : { left : pos . x , top : pos . y } ,
width : thumbSize . width ,
height : thumbSize . height ,
} )
} ,
getLabel _ : function ( ) {
return React . DOM . span ( { className : 'cam-blobitem-thumbtitle' , style : { width : this . props . size . width } } , this . props . title ) ;
} ,
getThumbSize _ : function ( available ) {
var bleed = false ;
return cam . math . scaleToFit ( new goog . math . Size ( this . props . thumbAspect , 1 ) , available , bleed ) ;
} ,
getThumbClipSize _ : function ( ) {
return new goog . math . Size ( this . props . size . width , this . props . size . height - this . TITLE _HEIGHT ) ;
} ,
} ) ;
cam . BlobItemGenericContent . getHandler = function ( blobref , searchSession , href ) {
return new cam . BlobItemGenericContent . Handler ( blobref , searchSession , href ) ;
} ;
cam . BlobItemGenericContent . Handler = function ( blobref , searchSession , href ) {
this . blobref _ = blobref ;
this . searchSession _ = searchSession ;
this . href _ = href ;
this . thumbType _ = this . getThumbType _ ( ) ;
} ;
cam . BlobItemGenericContent . Handler . ICON _ASPECT = {
FILE : 260 / 300 ,
FOLDER : 300 / 300 ,
} ;
cam . BlobItemGenericContent . Handler . prototype . getAspectRatio = function ( ) {
return this . thumbType _ == 'folder' ? this . constructor . ICON _ASPECT . FOLDER : this . constructor . ICON _ASPECT . FILE ;
} ;
cam . BlobItemGenericContent . Handler . prototype . createContent = function ( size ) {
2014-07-31 19:30:29 +00:00
// TODO(aa): In the case of a permanode that is a container (cam.permanodeUtils.isContainer()) and has a camliContentImage, it would be nice to show that image somehow along with the folder icon.
2017-01-25 17:19:51 +00:00
return React . createElement ( cam . BlobItemGenericContent , {
2014-04-01 02:01:44 +00:00
href : this . href _ ,
size : size ,
thumbSrc : this . thumbType _ + '.png' ,
thumbAspect : this . getAspectRatio ( ) ,
title : this . searchSession _ . getTitle ( this . blobref _ ) ,
} ) ;
} ;
cam . BlobItemGenericContent . Handler . prototype . getThumbType _ = function ( ) {
var m = this . searchSession _ . getMeta ( this . blobref _ ) ;
var rm = this . searchSession _ . getResolvedMeta ( this . blobref _ ) ;
if ( rm ) {
if ( rm . camliType == 'file' ) {
return 'file' ;
}
if ( rm . camliType == 'directory' || rm . camliType == 'static-set' ) {
return 'folder' ;
}
}
// Using the directory icon for any random permanode is a bit weird. Ideally we'd use file for that. The problem is that we can't tell the difference between a permanode that is representing an empty dynamic set and a permanode that is representing something else entirely.
2014-07-31 19:30:29 +00:00
// And unfortunately, the UI has a big prominent button that says 'new set', and it looks funny if the new set is shown as a file icon :(
2014-04-01 02:01:44 +00:00
if ( m . camliType == 'permanode' ) {
return 'folder' ;
}
return 'file' ;
} ;