Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
first changes in order run without state
Browse files Browse the repository at this point in the history
  • Loading branch information
bblfish committed Jan 23, 2014
1 parent b24897f commit 29e4d43
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 59 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<script src="lib/q.js"></script>
<script src="lib/JSXTransformer.js"></script>
<script src="lib/rdflib.js"></script>
<script src="scripts/Stample.rdfibutils.js"></script>
<script src="lib/pointedGraph.js"></script>
<script src="lib/fetcherWithPromise.js"></script>
<script src="lib/director.js"></script>
Expand Down
14 changes: 14 additions & 0 deletions lib/fetcherWithPromise.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ $rdf.Fetcher.prototype.requiresProxy = function(uri) {
return ($rdf.Fetcher.crossSiteProxyTemplate) && ((uri.indexOf($rdf.Fetcher.homeServer) !== 0) || (!uri.indexOf($rdf.Fetcher.crossSiteProxyTemplate) !== 0));
}

/**
*
* @param uri
* @returns {String} the original url or the proxies url
*/
$rdf.Fetcher.prototype.proxiedURL = function(uri) {
if ($rdf.Fetcher.prototype.requiresProxy(uri)) {
return $rdf.Fetcher.prototype.crossSiteProxy(uri)
} else return uri
}


/**
* return the Promise of a graph fro a given url
* @param {String} uri to fetch as string (!) (Not a $rdf.sym())
Expand All @@ -30,6 +42,8 @@ $rdf.Fetcher.prototype.fetch = function(uri, referringTerm, force) {
};

var sta = self.getState(uri);
if (force) sta='unrequested';

if (sta == 'fetched') {
return Q.fcall( function() { return $rdf.pointedGraph(self.store, uriSym, uriSym, uriSym) });
} else {
Expand Down
29 changes: 26 additions & 3 deletions lib/pointedGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ $rdf.PointedGraph = function() {
var check = existenceCheck?existenceCheck:true
if (this.isLocalPointer()) result = this
else {
var docURL = this.pointer.uri.split('#')[0];
var proxiedDoc = $rdf.sym($rdf.Fetcher.crossSiteProxy(docURL)); // TODO, do not force access though proxy
var docURL = $rdf.Stmpl.fragmentless(this.pointer.uri);
var proxiedDoc = $rdf.sym($rdf.Fetcher.crossSiteProxy(docURL)); // TODO, do not force access though proxy
if ( this.store.statementsMatching(undefined, undefined, undefined, proxiedDoc, true).size > 0
&& ( !check
|| this.store.statementsMatching(this.pointer, undefined, undefined, proxiedDoc, true).size > 0
Expand All @@ -185,9 +185,32 @@ $rdf.PointedGraph = function() {
}
debug("PG(_," + this.pointer + "," + this.internalGraph + ").jump = PG(_,_," + result.webGraph+",_)");
return result

}

/**
* find current jumped graph, but if it does not exist fetch it and return promise
* @param existenceCheck ( really check if
* @return ( PointedGraph | Promise[PointedGraph] )
*/
$rdf.PointedGraph.prototype.jumpNowOrLater = function(existenceCheck) {
var check = existenceCheck?existenceCheck:true
if (this.isLocalPointer()) return this;
else {
var docURL = $rdf.Stmpl.fragmentless(this.pointer.uri);
var proxiedDoc = $rdf.sym($rdf.Fetcher.crossSiteProxy(docURL)); // TODO, do not force access though proxy
if ( this.store.statementsMatching(undefined, undefined, undefined, proxiedDoc, true).size > 0
&& ( !check
|| this.store.statementsMatching(this.pointer, undefined, undefined, proxiedDoc, true).size > 0
|| this.store.statementsMatching(undefined, undefined, this.pointer, proxiedDoc, true).size > 0)
) {
return $rdf.pointedGraph(this.store, this.pointer, $rdf.sym(docUrl), proxiedDoc);
} else {
return this.jumpAsync(check);
}
}
}


/**
* This is the key async pointed graph relation. It returns the same PG
* if the pointer is defined in the named graph, and returns the PG in the remote
Expand Down
4 changes: 2 additions & 2 deletions scripts/AppConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ function FOAF(name) { return $rdf.sym("http://xmlns.com/foaf/0.1/"+name) }
function RDFS(name) { return $rdf.sym("http://www.w3.org/2000/01/rdf-schema#"+name) }


//var foafDocURL = "http://bblfish.net/people/henry/card#me";
var foafDocURL = "http://bblfish.net/people/henry/card#me";
//var foafDocURL = "https://my-profile.eu/people/deiu/card#me";
var foafDocURL = "https://localhost:8443/2013/backbone#me";
//var foafDocURL = "https://localhost:8443/2013/backbone#me";


// TODO need to add hash if needed: we do not look for primary topic anymore
Expand Down
15 changes: 15 additions & 0 deletions scripts/Stample.rdfibutils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Created by hjs on 23/01/2014.
*/

$rdf.Stmpl = {

/**
* remove hash from URL - this gets the document location
* @param url
* @returns {*}
*/
fragmentless: function(url) {
return url.split('#')[0];
}
}
109 changes: 55 additions & 54 deletions scripts/contacts/PersonContactOnProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,24 @@ var PersonContactOnProfile = React.createClass({
mixins: [WithLogger,WithLifecycleLoggingLite],
componentName: "PersonContactOnProfile",

getInitialState: function() {
return {
jumpedPointedGraph: this.props.personPG.jump()
}
},

componentDidMount: function () {
var self = this;
this.props.personPG.jumpAsync(false).then(
function (jumpedPersonPG) {
self.debug("Setting jumpedPersonPG: ", self.state.jumpedPointedGraph.pointer.toNT(), "->", jumpedPersonPG);
self.replaceState({
jumpedPointedGraph: jumpedPersonPG
})
},
function (err) {
self.error("error:", component.state.jumpedPointedGraph.pointer.toNT(), "->", err);
self.replaceState({
jumpedPointedGraph: this.props.personPG,
error: err
})
}
)
},
// componentDidMount: function () {
// var self = this;
// this.props.personPG.jumpAsync(false).then(
// function (jumpedPersonPG) {
// self.debug("Setting jumpedPersonPG: ", self.state.jumpedPointedGraph.pointer.toNT(), "->", jumpedPersonPG);
// self.replaceState({
// jumpedPointedGraph: jumpedPersonPG
// })
// },
// function (err) {
// self.error("error:", component.state.jumpedPointedGraph.pointer.toNT(), "->", err);
// self.replaceState({
// jumpedPointedGraph: this.props.personPG,
// error: err
// })
// }
// )
// },

handleClick: function(e) {
// TODO maybe not appropriate?
Expand All @@ -47,40 +41,48 @@ var PersonContactOnProfile = React.createClass({
},

setElementClasses: function() {
var loadingStr = "";
var info = undefined;
if (this.props.personPG.isLocalPointer()) {
if (this.props.personPG.pointer.termType === "bnode") {
info = (<p>not a webid</p>)
} else if (this.props.personPG.pointer.termType === "literal") {
info = (<p>a literal!!!</p>)
} else {
info = (<p>locally defined</p>)
}
} else {
jumpedState = this.state.jumpedPointedGraph;
if (jumpedState) {
if (jumpedState.isLocalPointer()) {
info = (<p>definitional info, page was loaded</p>)
} else {
info = (<p>there was not definitional info in the remote graph</p>)
}
} else {
info = (<p>no remote info yet</p>);
loadingStr = "loading"
}
}

// Set appropriate class of li items.
return "contact clearfix float-left "+ loadingStr + ((this.state.error)?" error":"");
// var loadingStr = "";
// var info = undefined;
// if (this.props.personPG.isLocalPointer()) {
// if (this.props.personPG.pointer.termType === "bnode") {
// info = (<p>not a webid</p>)
// } else if (this.props.personPG.pointer.termType === "literal") {
// info = (<p>a literal!!!</p>)
// } else {
// info = (<p>locally defined</p>)
// }
// } else {
// jumpedState = this.state.jumpedPointedGraph;
// if (jumpedState) {
// if (jumpedState.isLocalPointer()) {
// info = (<p>definitional info, page was loaded</p>)
// } else {
// info = (<p>there was not definitional info in the remote graph</p>)
// }
// } else {
// info = (<p>no remote info yet</p>);
// loadingStr = "loading"
// }
// }
//
// // Set appropriate class of li items.
// return "contact clearfix float-left "+ loadingStr + ((this.state.error)?" error":"");
},

render: function() {
var originalAndJumpedPG = [ this.props.personPG ]
var jumpedPointedGraphPromise = this.props.personPG.jumpNowOrLater()
console.info("jumpedPointedGraphPr",jumpedPointedGraphPromise)
if (Q.isPromise(jumpedPointedGraphPromise)) {
console.info("we came back with a promise")
} else {
console.info("we received the jumpedpointedgraph")
originalAndJumpedPG.push(jumpedPointedGraphPromise)
}
// Check if user should be displayed.
var show = {display: (this.displayUser()) ? 'block' : 'none'};
var show = {display: (this.displayUser(originalAndJumpedPG)) ? 'block' : 'none'};

// Set appropriate Pgs.
var originalAndJumpedPG = _.compact([this.props.personPG, this.state.jumpedPointedGraph ]);

// Define appropriate class for the view.
var clazz = this.setElementClasses();
Expand All @@ -97,8 +99,7 @@ var PersonContactOnProfile = React.createClass({
);
},

displayUser: function() {
var originalAndJumpedPG = _.compact([this.props.personPG, this.state.jumpedPointedGraph ]);
displayUser: function(originalAndJumpedPG) {
var userName = foafUtils.getName(originalAndJumpedPG).toString().toLowerCase();
var filterText = this.props.filterText;
if (!filterText) return true;
Expand Down

0 comments on commit 29e4d43

Please sign in to comment.