Skip to content
Browse files

Able to change states to archived and starred

  • Loading branch information...
1 parent c8737c9 commit 420bfe9c73559049b277cda060cc52ad3642e89a Michael Hughes committed Mar 23, 2013
View
49 src/client/EntryListController.coffee
@@ -0,0 +1,49 @@
+controller = exports ? this
+
+states = {
+ NEW:"new"
+ ARCHIVED:"archived"
+ STARRED:"starred"
+}
+
+controller.EntryListCtrl = ($scope,$http)->
+
+ $scope.entries = []
+ if $http
+ $http.get("/latest/json")
+ .success (data,status)->
+ $scope.entries = data
+ .error (data,status)->
+
+ ignoreOutput = (data,status)->
+
+ $scope.encode = (url)->
+ encodeURIComponent url
+
+ $scope.plusMinus = (open)->
+ if open then "minus" else "plus"
+
+ $scope.remove = (index)->
+ entry = $scope.entries[index]
+ $scope.entries.splice index,1
+ if $http
+ $http.get("/changeState?state=" + states.ARCHIVED + "&id=" + $scope.encode(entry.id))
+ .success(ignoreOutput)
+ .error(ignoreOutput)
+
+ $scope.star = (index)->
+ entry = $scope.entries[index]
+ if entry.state==states.STARRED
+ entry.state=states.NEW
+ else
+ entry.state=states.STARRED
+ if $http
+ $http.get("/changeState?state="+ entry.state + "&id=" + $scope.encode(entry.id))
+ .success(ignoreOutput)
+ .error(ignoreOutput)
+
+ $scope.status = (state)->
+ if state==states.STARRED then "" else "-empty"
+
+
+ scope:$scope
View
16 src/client/FeedListController.coffee
@@ -14,19 +14,3 @@ controller.FeedListCtrl = ($scope)->
scope:$scope
-controller.EntryListCtrl = ($scope,$http)->
-
- $scope.entries = []
-
- $http.get("/latest/json")
- .success (data,status)->
- $scope.entries = data
- .error (data,status)->
-
- $scope.plusMinus = (bool)->
- if(bool) then "minus" else "plus"
-
- $scope.encode = (url)->
- encodeURIComponent url
-
- scope:$scope
View
10 src/resources/views/index.jade
@@ -13,12 +13,12 @@ block content
div(class="btn-group btns-right")
a(class="btn",ng-click="e.open = !e.open",ng-init="e.open=false")
i(class="icon-{{plusMinus(e.open)}}")
- a(class="btn")
+ a(class="btn",ng-click="remove($index)")
i(class="icon-trash")
- a(class="btn")
- i(class="icon-star-empty")
- a(href="redirect?to={{encode(e.link)}}&id={{encode(e.id)}}")
+ a(class="btn",ng-click="star($index)")
+ i(class="icon-star{{status(e.state)}}")
+ a(href="redirect?to={{encode(e.link)}}&id={{encode(e.id)}}",target="_new")
h3 {{e.title}}
- span{{e.date}}
+ span{{e.date | date:'medium'}}
p(class="toggle-{{e.open}}",ng-bind-html-unsafe="e.summary")
View
2 src/server/MongoStore.coffee
@@ -55,7 +55,7 @@ exports.createMongostore = (connectionString)->
@connect (err,collection)->
if err then fun err,null
else
- collection.find({state:"new"}).sort({date:-1}).limit(amount).toArray fun
+ collection.find({$or: [{state:"new"},{state:"starred"}]}).sort({date:-1}).limit(amount).toArray fun
updateEntryState:(id,state,fun)->
@connect (err,collection)->
View
5 src/server/Webserver.coffee
@@ -25,6 +25,11 @@ exports.createWebServer = (port,connectionString)->
res.end(err) if err
res.redirect(req.query.to) unless err
+ app.get '/changeState', (req,res)->
+ ms = store.createMongostore(connectionString)
+ ms.updateEntryState req.query.id,req.query.state,(err,result)->
+ res.end(err) if err
+ res.end() unless err
# Start Server
app.listen port, -> console.log "Server is listening on #{port}\nPress CTRL-C to stop server."
View
18 test/client/unit/EntryListController_test.coffee
@@ -0,0 +1,18 @@
+controller = require '../../../src/client/EntryListController.coffee'
+expect = (require 'chai').expect
+
+describe 'A EntryListCtrl controller', ->
+ it 'should be able to remove entries from a list', ()->
+ c = new controller.EntryListCtrl({})
+ c.scope.entries = [
+ {title:"a",id:"aa"},
+ {title:"b",id:"bb"},
+ {title:"c",id:"cc"}
+ ]
+ c.scope.remove(1)
+ expect(c.scope.entries).to.eql [
+ {title:"a",id:"aa"},
+ {title:"c",id:"cc"}
+ ]
+
+
View
12 test/server/integration/MongoStore_test.coffee
@@ -7,8 +7,8 @@ after = andAlso = require '../shared/Feed_steps.coffee'
connectionString = "mongodb://localhost:27000/feeds"
feedData = [
- {"title":"A news story","link":"http://a.news.story/","tag"}
- {"title":"Another news story","link":"http://another.news.story/"}
+ {"title":"A news story","link":"http://a.news.story/","tag","id":"1"}
+ {"title":"Another news story","link":"http://another.news.story/","id":"2"}
]
similarData = [
@@ -94,3 +94,11 @@ describe 'A mongodb store', ->
@database.getLatestNew 10,(err,result)->
expect(result.length).to.equal 10
done()
+
+ it 'should return both new and starred entries',(done)->
+ after.insertingSome(entriesWithDates).intoThe @database,(result)=>
+ @database.updateEntryState "aNewerEntry","starred",(err,result)=>
+ @database.getLatestNew 10,(err,result)->
+ expect(result.length).to.equal 3
+ expect(result[0].title).to.equal "a newer entry"
+ done()

0 comments on commit 420bfe9

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