Add a list of references to a blob to the blob aspect.

Change-Id: I2fe96bc8f04f8137773aee393eb934e06517575d
This commit is contained in:
Aaron Boodman 2015-01-04 20:21:14 -08:00
parent e40504a9b2
commit ea2c8fa990
2 changed files with 65 additions and 5 deletions

View File

@ -19,6 +19,8 @@ goog.provide('cam.BlobDetail');
goog.require('cam.blobref');
goog.require('cam.ServerConnection');
goog.require('goog.labs.Promise');
cam.BlobDetail = React.createClass({
displayName: 'BlobDetail',
@ -34,12 +36,25 @@ cam.BlobDetail = React.createClass({
content: null,
metadata: null,
claims: null,
refs: null,
};
},
componentWillMount: function() {
this.props.serverConnection.getBlobContents(this.props.meta.blobRef, this.handleBlobContents_);
this.props.serverConnection.permanodeClaims(this.props.meta.blobRef, this.handleClaims_);
var sc = this.props.serverConnection;
sc.getBlobContents(this.props.meta.blobRef, this.handleBlobContents_);
sc.permanodeClaims(this.props.meta.blobRef, this.handleClaims_);
goog.labs.Promise.all([
new goog.labs.Promise(sc.pathsOfSignerTarget.bind(sc, this.props.meta.blobRef)),
new goog.labs.Promise(sc.search.bind(sc, {
permanode: {
attr: 'camliMember',
value: this.props.meta.blobRef,
},
}, null, null, null))
]).then(this.handleRefs_);
},
render: function() {
@ -52,7 +67,37 @@ cam.BlobDetail = React.createClass({
},
this.getSection_("Blob content", this.state.content),
this.getSection_("Indexer metadata", this.props.meta),
this.getSection_("Mutation claims", this.state.claims)
this.getSection_("Mutation claims", this.state.claims),
this.getReferences_(this.state.refs)
);
},
getReferences_: function(refs) {
var content = 'Loading...';
if (refs) {
content = React.DOM.ul(
null,
refs.map(function(blobref) {
return React.DOM.li(
{},
React.DOM.a(
{
href: this.props.getDetailURL(blobref),
},
blobref
)
);
}, this)
);
}
return React.DOM.div(
{
key: 'References',
},
this.getHeader_('Referenced by'),
content
);
},
@ -110,6 +155,21 @@ cam.BlobDetail = React.createClass({
handleClaims_: function(data) {
this.setState({claims: data});
},
handleRefs_: function(results) {
var refs = [];
if (results[0].paths) {
refs = refs.concat(results[0].paths.map(function(path) {
return path.baseRef;
}));
}
if (results[1].blobs) {
refs = refs.concat(results[1].blobs.map(function(blob) {
return blob.blob;
}));
}
this.setState({refs: refs});
},
});
cam.BlobDetail.getAspect = function(getDetailURL, serverConnection, blobref, targetSearchSession) {

View File

@ -254,11 +254,11 @@ cam.ServerConnection.prototype.search = function(query, opt_describe, opt_limit,
// @param {string} target blobref of permanode we want to find paths to
// @param {Function} success.
// @param {Function=} opt_fail Optional fail callback.
cam.ServerConnection.prototype.pathsOfSignerTarget = function(signer, target, success, opt_fail) {
cam.ServerConnection.prototype.pathsOfSignerTarget = function(target, success, opt_fail) {
var path = goog.uri.utils.appendPath(
this.config_.searchRoot, 'camli/search/signerpaths'
);
path = goog.uri.utils.appendParams(path, 'signer', signer, 'target', target);
path = goog.uri.utils.appendParams(path, 'signer', this.config_.signing.publicKeyBlobRef, 'target', target);
this.sendXhr_(path,
goog.bind(this.genericHandleSearch_, this, success, this.safeFail_(opt_fail)));
};