Skip to content

Instantly share code, notes, and snippets.

@ryepup
Last active December 19, 2015 22:49
Show Gist options
  • Save ryepup/6030357 to your computer and use it in GitHub Desktop.
Save ryepup/6030357 to your computer and use it in GitHub Desktop.
very simple development log app in angular; a poor-mans one-note or org-mode
<!doctype html>
<html lang="en" ng-app>
<head>
<meta charset="utf-8">
<title>Dev log</title>
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
</head>
<body>
<div class="container" ng-controller="DevLogController">
<h2>Dev Log</h2>
<!-- had trouble with `| orderBy:'t':true` filter, wasn't re-sorting when we added to the list-->
<table class="table table-striped table-bordered">
<thead>
<tr>
<th><a href="#" ng-click="posts.reverse()">Date</a></th>
<th width="85%">Log</th>
</tr>
</thead>
<tbody>
<tr>
<td>Now</td>
<td colspan="3">
<textarea placeholder="Enter notes..." style="width:98%" ng-model="post" ng-keydown="maybePost($event)"></textarea><br/>
<small>Ctrl-Enter to post</small>
</td>
</tr>
<tr ng-repeat="p in posts">
<td>{{ p.t | date:'yyyy-MM-dd HH:mm' }}</td>
<td style="whitespace:pre;">{{ p.content }}</td>
<td><button class="close" ng-click="deletePost(p)">&times;</button></td>
</tr>
</tbody>
</table>
</div>
</body>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.1.3/angular.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<script>
function DevLogController($scope){
$scope.posts = JSON.parse(localStorage.getItem('devlog')) || [];
function savePosts(){
localStorage.setItem('devlog', JSON.stringify($scope.posts));
};
$scope.addPost = function(){
$scope.posts.unshift({content:$scope.post, t:new Date()});
$scope.post = '';
savePosts();
};
$scope.deletePost = function(postToDelete){
$scope.posts = $scope.posts.filter(function(p){return p != postToDelete;});
savePosts();
};
$scope.maybePost = function($event){
if($event.ctrlKey && $event.keyCode==13){
$scope.addPost();
}
};
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment