Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial commit

  • Loading branch information...
commit 4d58d31557b0d3822a0ca51a8bc03d6425f22145 0 parents
@chrismatthieu authored
Showing with 129 additions and 0 deletions.
  1. +27 −0 detail.html
  2. +14 −0 index.html
  3. +19 −0 list.html
  4. +21 −0 mongolab.js
  5. +48 −0 project.js
27 detail.html
@@ -0,0 +1,27 @@
+<form name="myForm">
+ <div class="control-group" ng-class="{error: myForm.name.$invalid}">
+ <label>Name</label>
+ <input type="text" name="name" ng-model="project.name" required>
+ <span ng-show="myForm.name.$error.required" class="help-inline">
+ Required</span>
+ </div>
+
+ <div class="control-group" ng-class="{error: myForm.site.$invalid}">
+ <label>Website</label>
+ <input type="url" name="site" ng-model="project.site" required>
+ <span ng-show="myForm.site.$error.required" class="help-inline">
+ Required</span>
+ <span ng-show="myForm.site.$error.url" class="help-inline">
+ Not a URL</span>
+ </div>
+
+ <label>Description</label>
+ <textarea name="description" ng-model="project.description"></textarea>
+
+ <br>
+ <a href="#/" class="btn">Cancel</a>
+ <button ng-click="save()" ng-disabled="isClean() || myForm.$invalid"
+ class="btn btn-primary">Save</button>
+ <button ng-click="destroy()"
+ ng-show="project._id" class="btn btn-danger">Delete</button>
+</form>
14 index.html
@@ -0,0 +1,14 @@
+<!doctype html>
+<html ng-app="project">
+ <head>
+ <script src="http://code.angularjs.org/angular-1.0.1.min.js"></script>
+ <script src="http://code.angularjs.org/angular-resource-1.0.1.min.js">
+ </script>
+ <script src="project.js"></script>
+ <script src="mongolab.js"></script>
+ </head>
+ <body>
+ <h2>JavaScript Projects</h2>
+ <div ng-view></div>
+ </body>
+</html>
19 list.html
@@ -0,0 +1,19 @@
+<input type="text" ng-model="search" class="search-query" placeholder="Search">
+<table>
+ <thead>
+ <tr>
+ <th>Project</th>
+ <th>Description</th>
+ <th><a href="#/new"><i class="icon-plus-sign"></i></a></th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr ng-repeat="project in projects | filter:search | orderBy:'name'">
+ <td><a href="{{project.site}}" target="_blank">{{project.name}}</a></td>
+ <td>{{project.description}}</td>
+ <td>
+ <a href="#/edit/{{project._id.$oid}}"><i class="icon-pencil"></i></a>
+ </td>
+ </tr>
+ </tbody>
+</table>
21 mongolab.js
@@ -0,0 +1,21 @@
+// This is a module for cloud persistance in mongolab - https://mongolab.com
+angular.module('mongolab', ['ngResource']).
+ factory('Project', function($resource) {
+ var Project = $resource('https://api.mongolab.com/api/1/databases' +
+ '/angularjs/collections/projects/:id',
+ { apiKey: '4f847ad3e4b08a2eed5f3b54' }, {
+ update: { method: 'PUT' }
+ }
+ );
+
+ Project.prototype.update = function(cb) {
+ return Project.update({id: this._id.$oid},
+ angular.extend({}, this, {_id:undefined}), cb);
+ };
+
+ Project.prototype.destroy = function(cb) {
+ return Project.remove({id: this._id.$oid}, cb);
+ };
+
+ return Project;
+ });
48 project.js
@@ -0,0 +1,48 @@
+angular.module('project', ['mongolab']).
+ config(function($routeProvider) {
+ $routeProvider.
+ when('/', {controller:ListCtrl, templateUrl:'list.html'}).
+ when('/edit/:projectId', {controller:EditCtrl, templateUrl:'detail.html'}).
+ when('/new', {controller:CreateCtrl, templateUrl:'detail.html'}).
+ otherwise({redirectTo:'/'});
+ });
+
+
+function ListCtrl($scope, Project) {
+ $scope.projects = Project.query();
+}
+
+
+function CreateCtrl($scope, $location, Project) {
+ $scope.save = function() {
+ Project.save($scope.project, function(project) {
+ $location.path('/edit/' + project._id.$oid);
+ });
+ }
+}
+
+
+function EditCtrl($scope, $location, $routeParams, Project) {
+ var self = this;
+
+ Project.get({id: $routeParams.projectId}, function(project) {
+ self.original = project;
+ $scope.project = new Project(self.original);
+ });
+
+ $scope.isClean = function() {
+ return angular.equals(self.original, $scope.project);
+ }
+
+ $scope.destroy = function() {
+ self.original.destroy(function() {
+ $location.path('/list');
+ });
+ };
+
+ $scope.save = function() {
+ $scope.project.update(function() {
+ $location.path('/');
+ });
+ };
+}

0 comments on commit 4d58d31

Please sign in to comment.
Something went wrong with that request. Please try again.