Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Nice Simple AngularJS + Firebase + C# REST PoC.
<h5>Current messages:</h5>
<table class="table table-striped">
<thead>
<tr>
<th>message</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="message in messages" >
<td>{{message}}</td>
</tr>
</tbody>
</table>
<h5>Request Urls:</h5>
<ul>
<li ng-repeat="url in urls" class="list-unstyled">
{{url}}
</li>
</ul>
// Firebase REST API helpers
Action<string,string,string,string> sendData_Raw =
(app,token, area, data)=>
{
ThreadPool.QueueUserWorkItem((o)=>
{
var url = "https://{0}.firebaseio.com/{1}.json?auth={2}".format(app, area, token);
var now = DateTime.Now.ToShortTimeString(); // DateTime.Now. TimeOfDay;
var postData = "\"{0}: {1}\"".format(now, data.replace("\"", "'"));
url.POST(postData);
});
};
Action<string,string> sendData =
(area, data) => {
var app = "tm-admin-test";
var authToken = "11uXXuQHpzhrG2LzV1DNu17tOBu0psTqR6bNhFZm";
sendData_Raw(app, authToken, area, data);
};
Action<string> logDebugMsg =
(message) =>{
sendData("debugMsg", message);
};
Action<string> logRequestURL =
(url) =>{
sendData("requestUrl", url);
};
//Add hook into current ASP.NET Request pipeline
if (TMEvents.OnApplication_BeginRequest.size() > 1) //removes previous one (only during dev)
TMEvents.OnApplication_BeginRequest.remove(1);
logDebugMsg("mapping TMEvents.OnApplication_BeginRequest to send url to Firebase");
TMEvents.OnApplication_BeginRequest.Add(
() =>{
logRequestURL(HttpContextFactory.Request.Url.str());
});
return TMEvents.OnApplication_BeginRequest.size();
//using System.Threading;
//using TeamMentor.CoreLib;
//O2Ref:TeamMentor.CoreLib.dll
<ol class="breadcrumb">
<li><a href="#/messages" >All Messages</a></li>
<li><a href="#/requestUrls">Request Urls</a></li>
<li><a href="#/debug" >Debug</a></li>
</ol>
<!doctype html>
<html ng-app="project">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js" type='text/javascript'></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular-route.js" type='text/javascript'></script>
<script src="https://cdn.firebase.com/v0/firebase.js" type='text/javascript'></script>
<script src="https://cdn.firebase.com/libs/angularfire/0.5.0/angularfire.js" type='text/javascript'></script>
<script src='https://cdn.firebase.com/js/simple-login/1.2.5/firebase-simple-login.js' type='text/javascript'></script>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel ="stylesheet" >
<script src="js/app.js" ></script>
<script src="js/factories.js" ></script>
<script src="js/controllers.js"></script>
<script src="js/directives.js" ></script>
<script src="js/routes.js" ></script>
</head>
<body>
<div class="container">
<h3 class="alert alert-success">TeamMentor Data (in Realtime)</h3>
<div top-Menu></div>
<div ng-view></div>
</div>
</body>
</html>
angular.module ('project' , ['ngRoute' , 'firebase'])
.value ('fbAuthToken', '11uXXuQHpzhrG2LzV1DNu17tOBu0psTqR6bNhFZm')
.value ('fbURL' , 'https://tm-admin-test.firebaseio.com');
var project = angular.module ('project');
project.controller('DebugCtrl' , function($scope, fbDebugMsg, fbRequestUrl)
{
$scope.fbDebugMsg = fbDebugMsg;
$scope.fbRequestUrl = fbRequestUrl;
});
project.controller('MessagesCtrl' , function($scope, fbaDebugMsg)
{
$scope.messages = fbaDebugMsg;
});
project.controller('RequestUrlsCtrl', function($scope, fbRequestUrl)
{
$scope.urls = [".... Loading data ..."];
$scope.count = 0;
fbRequestUrl.on("child_added", function(childSnapshot, prevChildName)
{
var text = "[#" + ++$scope.count + "] " + childSnapshot.val();
$scope.urls.splice(0,0,text);
$scope.$apply();
});
scope = $scope;
});
angular.module ('project' )
.directive('topMenu', function()
{
return {
restrict: 'A',
templateUrl: 'directives/topMenu.html'
};
});
angular.module ('project' )
.factory('fbDebugMsg' , function($firebase, fbURL, fbAuthToken)
{
var firebase = new Firebase(fbURL + "/debugMsg");
firebase.auth(fbAuthToken);
return firebase;
})
.factory('fbRequestUrl' , function($firebase, fbURL, fbAuthToken)
{
var firebase = new Firebase(fbURL + "/requestUrl");
firebase.auth(fbAuthToken);
return firebase;
})
.factory('fbaDebugMsg' , function($firebase, fbDebugMsg)
{
return $firebase(fbDebugMsg);
});
angular.module ('project')
.config(function($routeProvider)
{
$routeProvider.when ('/messages' , { templateUrl :'views/messages.html' , controller: 'MessagesCtrl' })
.when ('/requestUrls', { templateUrl :'views/requestUrls.html', controller: 'RequestUrlsCtrl' })
.when ('/debug' , { templateUrl :'views/debug.html' , controller: 'DebugCtrl' })
.otherwise( { redirectTo :'/requestUrls' });
});
<h4>Debug (Firebase objects)</h4>
<b>$fbDebugMsg:</b>
<pre class="prettyprint">
{{fbDebugMsg | json}}
</pre>
<b>$fbRequestUrl:</b>
<pre class="prettyprint">
{{fbRequestUrl | json}}
</pre>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment