From ea2c8fa9908f19f1ddd2ee0d78f9bb6d94519075 Mon Sep 17 00:00:00 2001 From: Aaron Boodman Date: Sun, 4 Jan 2015 20:21:14 -0800 Subject: [PATCH] Add a list of references to a blob to the blob aspect. Change-Id: I2fe96bc8f04f8137773aee393eb934e06517575d --- server/camlistored/ui/blob_detail.js | 66 +++++++++++++++++++++- server/camlistored/ui/server_connection.js | 4 +- 2 files changed, 65 insertions(+), 5 deletions(-) diff --git a/server/camlistored/ui/blob_detail.js b/server/camlistored/ui/blob_detail.js index ce75fd1be..7a81b32a2 100644 --- a/server/camlistored/ui/blob_detail.js +++ b/server/camlistored/ui/blob_detail.js @@ -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) { diff --git a/server/camlistored/ui/server_connection.js b/server/camlistored/ui/server_connection.js index b364ad033..9d73942d3 100644 --- a/server/camlistored/ui/server_connection.js +++ b/server/camlistored/ui/server_connection.js @@ -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))); };