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

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Dec 30, 2013
1 parent 9537340 commit 180a2ef
Show file tree
Hide file tree
Showing 308 changed files with 118,996 additions and 0 deletions.
Empty file added app/css/.gitkeep
Empty file.
30 changes: 30 additions & 0 deletions app/css/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* app css stylesheet */

.menu {
list-style: none;
border-bottom: 0.1em solid black;
margin-bottom: 2em;
padding: 0 0 0.5em;
}

.menu:before {
content: "[";
}

.menu:after {
content: "]";
}

.menu > li {
display: inline;
}

.menu > li:before {
content: "|";
padding-right: 0.3em;
}

.menu > li:nth-child(1):before {
content: "";
padding: 0;
}
Empty file added app/img/.gitkeep
Empty file.
60 changes: 60 additions & 0 deletions app/index-async.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
[ng-cloak] {
display: none;
}
</style>
<script>
// include angular loader, which allows the files to load in any order
/*
AngularJS v1.2.6
(c) 2010-2014 Google, Inc. http://angularjs.org
License: MIT
*/
(function(){'use strict';function d(a){return function(){var c=arguments[0],b,c="["+(a?a+":":"")+c+"] http://errors.angularjs.org/1.2.6/"+(a?a+"/":"")+c;for(b=1;b<arguments.length;b++)c=c+(1==b?"?":"&")+"p"+(b-1)+"="+encodeURIComponent("function"==typeof arguments[b]?arguments[b].toString().replace(/ \{[\s\S]*$/,""):"undefined"==typeof arguments[b]?"undefined":"string"!=typeof arguments[b]?JSON.stringify(arguments[b]):arguments[b]);return Error(c)}}(function(a){var c=d("$injector"),b=d("ng");a=a.angular||
(a.angular={});a.$$minErr=a.$$minErr||d;return a.module||(a.module=function(){var a={};return function(e,d,f){if("hasOwnProperty"===e)throw b("badname","module");d&&a.hasOwnProperty(e)&&(a[e]=null);return a[e]||(a[e]=function(){function a(c,d,e){return function(){b[e||"push"]([c,d,arguments]);return g}}if(!d)throw c("nomod",e);var b=[],h=[],k=a("$injector","invoke"),g={_invokeQueue:b,_runBlocks:h,requires:d,name:e,provider:a("$provide","provider"),factory:a("$provide","factory"),service:a("$provide",
"service"),value:a("$provide","value"),constant:a("$provide","constant","unshift"),animation:a("$animateProvider","register"),filter:a("$filterProvider","register"),controller:a("$controllerProvider","register"),directive:a("$compileProvider","directive"),config:k,run:function(a){h.push(a);return this}};f&&k(f);return g}())}}())})(window)})(window);


// include a third-party async loader library
/*!
* $script.js v1.3
* https://github.com/ded/script.js
* Copyright: @ded & @fat - Dustin Diaz, Jacob Thornton 2011
* Follow our software http://twitter.com/dedfat
* License: MIT
*/
!function(a,b,c){function t(a,c){var e=b.createElement("script"),f=j;e.onload=e.onerror=e[o]=function(){e[m]&&!/^c|loade/.test(e[m])||f||(e.onload=e[o]=null,f=1,c())},e.async=1,e.src=a,d.insertBefore(e,d.firstChild)}function q(a,b){p(a,function(a){return!b(a)})}var d=b.getElementsByTagName("head")[0],e={},f={},g={},h={},i="string",j=!1,k="push",l="DOMContentLoaded",m="readyState",n="addEventListener",o="onreadystatechange",p=function(a,b){for(var c=0,d=a.length;c<d;++c)if(!b(a[c]))return j;return 1};!b[m]&&b[n]&&(b[n](l,function r(){b.removeEventListener(l,r,j),b[m]="complete"},j),b[m]="loading");var s=function(a,b,d){function o(){if(!--m){e[l]=1,j&&j();for(var a in g)p(a.split("|"),n)&&!q(g[a],n)&&(g[a]=[])}}function n(a){return a.call?a():e[a]}a=a[k]?a:[a];var i=b&&b.call,j=i?b:d,l=i?a.join(""):b,m=a.length;c(function(){q(a,function(a){h[a]?(l&&(f[l]=1),o()):(h[a]=1,l&&(f[l]=1),t(s.path?s.path+a+".js":a,o))})},0);return s};s.get=t,s.ready=function(a,b,c){a=a[k]?a:[a];var d=[];!q(a,function(a){e[a]||d[k](a)})&&p(a,function(a){return e[a]})?b():!function(a){g[a]=g[a]||[],g[a][k](b),c&&c(d)}(a.join("|"));return s};var u=a.$script;s.noConflict=function(){a.$script=u;return this},typeof module!="undefined"&&module.exports?module.exports=s:a.$script=s}(this,document,setTimeout)

// load all of the dependencies asynchronously.
$script([
'lib/angular/angular.js',
'lib/angular/angular-route.js',
'js/app.js',
'js/services.js',
'js/controllers.js',
'js/filters.js',
'js/directives.js'
], function() {
// when all is done, execute bootstrap angular application
angular.bootstrap(document, ['myApp']);
});
</script>
<title>My AngularJS App</title>
<link rel="stylesheet" href="css/app.css">
</head>
<body ng-cloak>
<ul class="menu">
<li><a href="#/view1">view1</a></li>
<li><a href="#/view2">view2</a></li>
</ul>

<div ng-view></div>

<div>Angular seed app: v<span app-version></span></div>

</body>
</html>
31 changes: 31 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!doctype html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="utf-8">
<title>My AngularJS App</title>
<link rel="stylesheet" href="css/app.css"/>
</head>
<body>
<ul class="menu">
<li><a href="#/view1">view1</a></li>
<li><a href="#/view2">view2</a></li>
</ul>

<div ng-view></div>


<!-- In production use:
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
-->
<script src="lib/angular/angular.js"></script>
<script src="lib/angular/angular-route.js"></script>
<script src="lib/angular/angular-resource.js"></script>
<script src="lib/rdf_store.js"></script>
<script src="lib/underscore.js"></script>
<script src="js/app.js"></script>
<script src="js/services.js"></script>
<script src="js/controllers.js"></script>
<script src="js/filters.js"></script>
<script src="js/directives.js"></script>
</body>
</html>
16 changes: 16 additions & 0 deletions app/js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';


// Declare app level module which depends on filters, and services
angular.module('myApp', [
'ngRoute',
'myApp.filters',
'myApp.services',
'myApp.directives',
'myApp.controllers'
]).
config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/view1', {templateUrl: 'partials/partial1.html', controller: 'MyCtrl1'});
$routeProvider.when('/view2', {templateUrl: 'partials/partial2.html', controller: 'MyCtrl2'});
$routeProvider.otherwise({redirectTo: '/view1'});
}]);
111 changes: 111 additions & 0 deletions app/js/controllers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
'use strict';

/* Controllers */

angular.module('myApp.controllers', [])


.controller('MyCtrl1', ['$scope', 'RdfStore','RdfHttpService',function($scope,RdfStore,RdfHttpService) {


$scope.$watch('profileUri', function() {
$scope.errorLogs.length = 0;
loadFullProfile($scope.profileUri);
})

$scope.errorLogs = [];
$scope.profileUri = 'https://my-profile.eu/people/deiu/card#me';


$scope.changeProfileUri = function(newUri) {
$scope.profileUri = newUri;
}


function loadFullProfile(uriWithFragment) {
console.info("will render profile: " + uriWithFragment)
$scope.profile = undefined;
$scope.relationships = [];
RdfHttpService.fetchPointedGraph(uriWithFragment).then(function(profileGraph) {
$scope.profile = toProfileModel(profileGraph,uriWithFragment);
getRelationshipGraphs(profileGraph,function(relationshipProfileGraph,uri) {
$scope.relationships.push( toProfileModel(relationshipProfileGraph,uri) );
});
},function(error) {
$scope.errorLogs.push("Can't retrieve full profile at "+uri+" because of: "+error);
});
}



function getRelationshipGraphs(profileGraph, onRelationshipFound) {
var uris = findAll(profileGraph,'foaf:knows')
console.debug("Relationships are: " + uris);
_.forEach(uris, function(uri) {
RdfHttpService.fetchPointedGraph(uri).then(function(profileGraph) {
if ( profileGraph.toArray().length > 0 ) {
onRelationshipFound(profileGraph,uri);
} else {
$scope.errorLogs.push("It seems the graph is empty for relationship uri "+uri);
}
},function(error) {
$scope.errorLogs.push("Can't retrieve relationship at "+uri+" because of: "+error);
});
});
}




function findAll(graph,predicate) {
var predicateNode = RdfStore.rdf.createNamedNode(RdfStore.rdf.resolve(predicate));
var triples = graph.match(null,predicateNode, null).toArray();
return _.map(triples, function(t){ return t.object.valueOf() });
}

function findFirst(graph,predicate) {
return getFirstOrUndefined(findAll(graph,predicate));
}

function getFirstOrUndefined(array) {
if ( array.length > 0 ) {
return array[0];
} else {
return undefined;
}
}

function toProfileModel(graph,uri) {
var name = findFirst(graph,"foaf:name");
var givenName = findFirst(graph,"foaf:givenName");
var familyName = findFirst(graph,"foaf:familyName");
var img = findFirst(graph,"foaf:img");
var nick = findFirst(graph,"foaf:nick");
var mbox = findFirst(graph,"foaf:mbox");
var homepage = findFirst(graph,"foaf:homepage");
return {
uri: uri,
name: name,
givenName: givenName,
familyName: familyName,
img: img,
nick: nick,
mbox: mbox,
homepage: homepage
}
}


}])









.controller('MyCtrl2', [function() {

}]);
11 changes: 11 additions & 0 deletions app/js/directives.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

/* Directives */


angular.module('myApp.directives', []).
directive('appVersion', ['version', function(version) {
return function(scope, elm, attrs) {
elm.text(version);
};
}]);
10 changes: 10 additions & 0 deletions app/js/filters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

/* Filters */

angular.module('myApp.filters', []).
filter('interpolate', ['version', function(version) {
return function(text) {
return String(text).replace(/\%VERSION\%/mg, version);
}
}]);
95 changes: 95 additions & 0 deletions app/js/services.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
'use strict';

/* Services */


// Demonstrate how to register services
// In this case it is a simple value service.
angular.module('myApp.services', [])

.value('version',
'0.1'
)

.factory('RdfStore',
rdfstore.create
)

.service('RdfHttpService',['$http','$q','RdfStore',function($http,$q,RdfStore) {

// TODO, for now we only accept turtle, no content negociation
var todoOnlyMimeType = 'text/turtle'

var config =
{
headers: {
'Accept': todoOnlyMimeType
}
};

var self = this;

this.fetchPointedGraph = function(uriWithFragment) {
var fragmentlessUri = removeFragment(uriWithFragment);
console.info("Will fetch profile "+fragmentlessUri)
return self.fetchGraph(fragmentlessUri)
.then(function(graph) {
return pointed(graph,uriWithFragment);
});
};


this.fetchGraph = function fetchGraph(uri) {
return $http.get(uri,config)
.then(function(response) {
var contentType = response.headers("Content-Type");
console.debug("It seems we got a response with mimeType "+contentType + " from "+ uri+" - will try to parse it as a graph");
return loadGraph(uri,response.data,contentType);
})
.then(function(triplesLoaded) {
return getGraph(uri);
});
};

function loadGraph(graphUri,graphData,graphMimeType) {
var deferred = $q.defer();
RdfStore.load(graphMimeType,graphData,graphUri,function(success, results) {
if ( success ) {
deferred.resolve(results);
} else {
deferred.reject("Can't LOAD graph with GraphURI="+graphUri+" and graphMimeType="+graphMimeType+" -> "+results);
}
});
return deferred.promise;
}

function getGraph(graphUri) {
var deferred = $q.defer();
RdfStore.graph(graphUri,function(success,graph){
if ( success ) {
deferred.resolve(graph);
} else {
deferred.reject("Can't GET graph with GraphURI="+graphUri);
}
});
return deferred.promise;
}

function pointed(graph,subject) {
var subjectNode = RdfStore.rdf.createNamedNode(subject);
return graph.match(subjectNode,null,null);
}

function removeFragment(uri) {
var index = uri.indexOf('#');
if (index > 0) {
return uri.substring(0, index);
} else {
return uri;
}
}


}])

;
Loading

0 comments on commit 180a2ef

Please sign in to comment.