Skip to content

Instantly share code, notes, and snippets.

@obra
Created December 2, 2012 05:08
Show Gist options
  • Save obra/4187042 to your computer and use it in GitHub Desktop.
Save obra/4187042 to your computer and use it in GitHub Desktop.
horrible hack to get todayapp working with mongolab, sort of
diff --git a/samples/today-app/app/app.ls b/samples/today-app/app/app.ls
index 0bbcc7e..053358d 100644
--- a/samples/today-app/app/app.ls
+++ b/samples/today-app/app/app.ls
@@ -1,5 +1,5 @@
# Declare app level module which depends on filters, and services
-App = angular.module \app <[ngCookies ngResource app.controllers app.directives app.filters app.services]>
+App = angular.module \app <[ngCookies app.controllers app.directives app.filters app.services]>
App.config <[$routeProvider $locationProvider]> +++ ($routeProvider, $locationProvider, config) ->
$routeProvider
diff --git a/samples/today-app/app/app/controllers.ls b/samples/today-app/app/app/controllers.ls
index 2ffa682..dddd38a 100644
--- a/samples/today-app/app/app/controllers.ls
+++ b/samples/today-app/app/app/controllers.ls
@@ -1,17 +1,20 @@
mod = {}
-mod.ListController = <[$scope List Task $location $routeParams $timeout]> +++ ($scope, List, Task, $location, $routeParams, $timeout) ->
+mod.ListController = <[$scope List $location $routeParams $timeout]> +++ ($scope, List, $location, $routeParams, $timeout) ->
$scope <<< do
+
processList: (list) ->
list.CreatedAt = new Date(list.CreatedAt)
if list.NextList
- $scope.nextList = list.get { _id: list.NextList }, (nextList) -> (
+ $scope.nextList = List.get { _id: list.NextList }, (nextList) -> (
nextList.CreatedAt = new Date(nextList.CreatedAt))
if list.PreviousList
- $scope.previousList = List.get { _id: list.PreviousList }, (previousList) -> (
+ $scope.previousList = $scope.allLists.get { _id: list.PreviousList }, (previousList) -> (
previousList.CreatedAt = new Date(previousList.CreatedAt))
+ if ! list.tasks
+ list.tasks = []
for task in list.tasks
task.CreatedAt = new Date(task.CreatedAt) if task.CreatedAt
task.CompletedAt = new Date(task.CompletedAt) if task.CompletedAt
@@ -68,6 +71,7 @@ mod.ListController = <[$scope List Task $location $routeParams $timeout]> +++ ($
$scope.list.tasks.filter -> it.Complete
addTasks: (lines) ->
+ $scope.list.tasks = []
isLater = !!$scope.list.tasks.length
for item in lines / /[\r\n]+/
@@ -87,7 +91,7 @@ mod.ListController = <[$scope List Task $location $routeParams $timeout]> +++ ($
$scope.list.$update {}, ((resource) -> $scope.processList(resource))
redirectToNewList: ->
- List.create {PreviousList: $scope._id}, (resource) -> (
+ $scope.allLists.$save {PreviousList: $scope._id}, (resource) -> (
if $scope.list
$scope.list.NextList = resource._id
$scope.list.$update {}, ((resource) -> $scope.processList(resource))
@@ -96,11 +100,13 @@ mod.ListController = <[$scope List Task $location $routeParams $timeout]> +++ ($
$scope._id = $routeParams.listUuid
# Defined before we call it
+ $scope.allLists = List.query!;
if ($routeParams.listUuid == "")
$scope.redirectToNewList!
if $scope._id
+ console.log $scope.allLists
$scope.list = List.get {_id: $scope._id}, ((resource) ->
unless resource
$scope.redirectToNewList!
diff --git a/samples/today-app/app/app/services.ls b/samples/today-app/app/app/services.ls
index e98e488..ef40c7a 100644
--- a/samples/today-app/app/app/services.ls
+++ b/samples/today-app/app/app/services.ls
@@ -1,20 +1,9 @@
'use strict'
-const prefix = '/db/Today/collections'
-
# Services
-((angular.module 'app.services', ['ngResource']).value 'version', '0.1')
- .factory 'List', <[$resource]> +++ ($resource) ->
- $resource prefix + '/List/:_id', {_id: '@_id'}, {
- create: {method: 'POST'}
- show: {method: 'GET'}
- update: {method: 'PUT'}
- }
- .factory 'Task', <[$resource]> +++ ($resource) ->
- $resource prefix + '/List/:_List/tasks/:_id', {_id: '@_id', _List: '@_List'}, {
- index: { method: 'GET', isArray: true },
- create: {method: 'POST'}
- show: {method: 'GET'}
- update: {method: 'PUT'}
- }
+(angular.module 'app.services', ['mongolabResource'])
+ .constant('API_KEY', '50bad325e4b0afba6ecc59fd')
+ .constant('DB_NAME', 'today')
+ .factory 'List', <[$mongolabResource]> +++ ($mongolabResource) ->
+ return $mongolabResource 'List';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment