Skip to content

Commit

Permalink
Trying to find why update doesnt redeemed
Browse files Browse the repository at this point in the history
  • Loading branch information
srenault committed Sep 25, 2012
1 parent f8de873 commit e393849
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 63 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/playstory/dashboard/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
type: 'POST',
dataType: 'json',
success: function() {
console.log('success');
next(bookmark);
}
});
Expand Down
25 changes: 10 additions & 15 deletions app/assets/javascripts/playstory/dashboard/feeds/feedsPastDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@
};
};

var preventDefault = function(callback) {
return function(evt) {
evt.preventDefault();
callback(evt);
};
};

this.onMoreFeedsClick = function(next) {
elts.$moreFeeds().click(preventDefault(next));
};
Expand Down Expand Up @@ -163,10 +156,11 @@
feed: feed,
commentView: function(comment) {
return commentTmpl({
author: comment.author || { avatar: '/assets/images/avatars/srenault.contact@gmail.com.png',
firstname: 'Sébastien',
lastname: 'RENAULT'
}, //TODO
author: comment.author ||
{ avatar: '/assets/images/avatars/srenault.contact@gmail.com.png',
firstname: 'Sébastien',
lastname: 'RENAULT'
}, //TODO
message: comment.message
});
}
Expand All @@ -185,10 +179,11 @@
feed: feed,
commentView: function(comment) {
return commentTmpl({
author: comment.author || { avatar: '/assets/images/avatars/srenault.contact@gmail.com.png',
firstname: 'Sébastien',
lastname: 'RENAULT'
}, //TODO
author: comment.author ||
{ avatar: '/assets/images/avatars/srenault.contact@gmail.com.png',
firstname: 'Sébastien',
lastname: 'RENAULT'
}, //TODO
message: comment.message
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@
server.streamFeeds
).and(server.fetchFeedWithContext);

/**
* Binding to DOM
*/

When(this.pastDOM.onNewCommentClick)
.await(this.pastDOM.displayNewComment)
.subscribe();
Expand Down Expand Up @@ -206,7 +210,7 @@
for(var p in params) {
paramsAsArray.push(params[p]);
}
return params;
return paramsAsArray;
})
.await(server.fetchLastFeeds.then(self.pastDOM.resetMoreFeeds))
.subscribe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
this.destroyAsAction = asAction(self.destroy);

var summup = function($counter) {
console.log('summup');
var currentCounter = $counter.text().replace('(','')
.replace(')','');

Expand Down
7 changes: 7 additions & 0 deletions app/assets/javascripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,11 @@
next(any);
});
};

window.preventDefault = function(callback) {
return function(evt) {
evt.preventDefault();
callback(evt);
};
};
})();
33 changes: 28 additions & 5 deletions app/controllers/Dashboard.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,33 @@ object Dashboard extends Controller with Secured with Pulling {
} getOrElse BadRequest
}

// def simpleUpdate() = Action { implicit request =>
// import reactivemongo.bson._
// import reactivemongo.bson.handlers.DefaultBSONHandlers._

// val byLevel = BSONDocument("level" -> BSONString("WARN"))
// val $setMessage = BSONDocument("message" -> BSONString("I was updated"))

// Async {
// Log.collectAsync.update(byLevel, $setMessage).map {
// case e: LastError => Ok(e.toString)
// }
// }
// }

def comment(project: String, id: String) = Authenticated { implicit request =>
Logger.info("[Dashboard] Comment log #%s from project %s".format(id, project))
val logId = new ObjectId(id)
request.body.asJson.map { comment =>
Async {

Log.byId(logId).flatMap { logOpt =>
logOpt.map { _ =>
Log.comment(logId, comment).map {
case LastError(true, _, _, _, _) => Ok
case LastError(false, Some(errMsg), code, errorMsg, doc) => InternalServerError(errMsg)
logOpt.map { _ =>
Log.comment(logId, comment).orTimeout(5).map { //TODO
case Right(number) => println("right: " + number)
case Left(e) => println("left " + e)
}
Promise.pure(Ok)
} getOrElse Promise.pure(
BadRequest("Failed to comment log. The follow log was not found: " + id)
)
Expand All @@ -102,7 +118,14 @@ object Dashboard extends Controller with Secured with Pulling {
if(!request.user.hasBookmark(logId)) {
Async {
Log.byId(logId).flatMap {
case Some(foundLog) => request.user.bookmark(logId).map(_ => Ok)
case Some(foundLog) => {
request.user.bookmark(logId).onComplete {
case Right(LastError(true, _, _, _, _)) => println("ok....")
case Right(LastError(false, Some(errMsg), code, errorMsg, doc)) => println("aie aie aie")
case Left(e) => println("mamamilla")
}
Promise.pure(Ok)
}
case _ => Promise.pure(
BadRequest("Failed to bookmark a log. It was not found")
)
Expand Down
2 changes: 1 addition & 1 deletion app/models/Comment.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object Comment {
(
(__).json.pick and
(__ \ "_id").json.put(
Json.obj("_id" -> Json.obj("$oid" -> id.toString))
Json.obj("$oid" -> id.toString)
)
) join
}
Expand Down
10 changes: 2 additions & 8 deletions app/models/Log.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import play.api.libs.json._
import play.api.libs.json.Json._
import play.api.libs.json.util._
import play.modules.reactivemongo.PlayBsonImplicits.JsValueWriter
import reactivemongo.api.{QueryBuilder, QueryOpts}
import reactivemongo.api.{QueryBuilder, QueryOpts, FailoverStrategy}
import reactivemongo.api.SortOrder.Descending
import reactivemongo.bson.handlers.DefaultBSONHandlers._
import reactivemongo.core.commands.LastError
Expand Down Expand Up @@ -187,17 +187,11 @@ object Log extends MongoDB("logs") with Searchable {
}

def uncheckedCreate(log: JsObject) {
println("---------------------")
println(log)
println("---------------------")
val mongoLog = Log.writeForMongo.writes(log)
println("---------------------")
println(mongoLog)
println("---------------------")
collectAsync.uncheckedInsert(mongoLog)
}

def comment(id: ObjectId, comment: JsValue) = {
def comment(id: ObjectId, comment: JsValue): Future[LastError] = {
val byId = Json.obj("_id" -> Json.obj("$oid" -> id.toString))
val toComments = Json.obj(
"$push" -> Json.obj("comments" -> Comment.writeForMongo.writes(comment))
Expand Down
4 changes: 2 additions & 2 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ application.secret="cpx`s5u;4Nnuxwni]wof6ew/Xl3IUIENMFEV9?@bwF=XlQwVAnbc[P8dmOib
# You can also configure logback (http://logback.qos.ch/), by providing a logger.xml file in the conf directory .

# Root logger:
#logger.root=ERROR
logger.root=DEBUG

# Logger used by the framework:
#logger.play=INFO
logger.play=DEBUG

# Logger provided to your application:
#logger.application=DEBUG
Expand Down
31 changes: 0 additions & 31 deletions conf/logback.xml

This file was deleted.

2 changes: 2 additions & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ POST /dashboard/:project/log/:id/comment controllers.Dashboard.comment(pr
POST /dashboard/:project/log/:id/bookmark controllers.Dashboard.bookmark(project: String, id: String)
POST /dashboard/eval controllers.Dashboard.eval()

#GET /simpleUpdate controllers.Dashboard.simpleUpdate()

# Map static resources from the /public folder to the /assets URL path

GET /assets/*file controllers.Assets.at(path="/public", file)

0 comments on commit e393849

Please sign in to comment.