From bb57756cd921d0cc387e7e944f58b8c8dbc651a5 Mon Sep 17 00:00:00 2001 From: Ruben Vereecken Date: Thu, 29 May 2014 11:37:35 +0200 Subject: [PATCH] Processed Scott's feedback. Db endpoint slightly safer, some refactorings. --- app/application.coffee | 2 ++ .../NewAchievementCollection.coffee | 7 +++++++ app/initialize.coffee | 2 +- app/models/CocoModel.coffee | 4 +--- app/templates/achievement_notify.jade | 20 +++++++++---------- app/views/kinds/RootView.coffee | 6 +----- server/users/user_handler.coffee | 8 +------- 7 files changed, 23 insertions(+), 26 deletions(-) create mode 100644 app/collections/NewAchievementCollection.coffee diff --git a/app/application.coffee b/app/application.coffee index 4252c87c6..8486b876b 100644 --- a/app/application.coffee +++ b/app/application.coffee @@ -5,6 +5,7 @@ locale = require 'locale/locale' {me} = require 'lib/auth' Tracker = require 'lib/Tracker' CocoView = require 'views/kinds/CocoView' +AchievementNotify = require '../../templates/achievement_notify' marked.setOptions {gfm: true, sanitize: true, smartLists: true, breaks: false} @@ -39,6 +40,7 @@ Application = initialize: -> @facebookHandler = new FacebookHandler() @gplusHandler = new GPlusHandler() $(document).bind 'keydown', preventBackspace + $.notify.addStyle 'achievement', html: $(AchievementNotify()) @linkedinHandler = new LinkedInHandler() preload(COMMON_FILES) $.i18n.init { diff --git a/app/collections/NewAchievementCollection.coffee b/app/collections/NewAchievementCollection.coffee new file mode 100644 index 000000000..7b33d7d75 --- /dev/null +++ b/app/collections/NewAchievementCollection.coffee @@ -0,0 +1,7 @@ +CocoCollection = require 'collections/CocoCollection' + +class NewAchievementCollection extends CocoCollection + initialize: (me = require('lib/auth').me) -> + @url = "/db/user/#{me.id}/achievements?notified=false" + +module.exports = NewAchievementCollection diff --git a/app/initialize.coffee b/app/initialize.coffee index 76d4174c5..08e0a4b39 100644 --- a/app/initialize.coffee +++ b/app/initialize.coffee @@ -59,4 +59,4 @@ setUpChannels = -> setUpDefinitions = -> for definition of definitionSchemas - Backbone.Mediator.addDefSchemas definitionSchemas[definition] \ No newline at end of file + Backbone.Mediator.addDefSchemas definitionSchemas[definition] diff --git a/app/models/CocoModel.coffee b/app/models/CocoModel.coffee index 19530c174..f9b657ce8 100644 --- a/app/models/CocoModel.coffee +++ b/app/models/CocoModel.coffee @@ -1,9 +1,7 @@ storage = require 'lib/storage' deltasLib = require 'lib/deltas' -class NewAchievementCollection extends Backbone.Collection - initialize: (me = require('lib/auth').me) -> - @url = "/db/user/#{me.id}/achievements?notified=false" +NewAchievementCollection = require '../collections/NewAchievementCollection' class CocoModel extends Backbone.Model idAttribute: "_id" diff --git a/app/templates/achievement_notify.jade b/app/templates/achievement_notify.jade index b981d3e72..f7ce0eb9b 100644 --- a/app/templates/achievement_notify.jade +++ b/app/templates/achievement_notify.jade @@ -1,12 +1,12 @@ div - div.clearfix.achievement-body - div.achievement-image(data-notify-html="image") - div.achievement-content - div.achievement-title(data-notify-html="title") - div.achievement-description(data-notify-html="description") + .clearfix.achievement-body + .achievement-image(data-notify-html="image") + .achievement-content + .achievement-title(data-notify-html="title") + .achievement-description(data-notify-html="description") - div.achievement-progress - div.achievement-message(data-notify-html="message") - div.progress-wrapper - div.earned-exp(data-notify-html="earnedExp") - div.progress-bar-wrapper(data-notify-html="progressBar") \ No newline at end of file + .achievement-progress + .achievement-message(data-notify-html="message") + .progress-wrapper + .earned-exp(data-notify-html="earnedExp") + .progress-bar-wrapper(data-notify-html="progressBar") diff --git a/app/views/kinds/RootView.coffee b/app/views/kinds/RootView.coffee index e945d6fcd..b6becd78f 100644 --- a/app/views/kinds/RootView.coffee +++ b/app/views/kinds/RootView.coffee @@ -6,7 +6,6 @@ CocoView = require './CocoView' {logoutUser, me} = require('lib/auth') locale = require 'locale/locale' -AchievementNotify = require '../../templates/achievement_notify' Achievement = require '../../models/Achievement' User = require '../../models/User' @@ -28,10 +27,7 @@ module.exports = class RootView extends CocoView initialize: -> $ => - $.notify.addStyle 'achievement', - html: $(AchievementNotify()) - - # TODO Remove this. Allows for easy testing right now though + # TODO Ruben remove this. Allows for easy testing right now though #test = new Achievement(_id:'537ce4855c91b8d1dda7fda8') #test.fetch(success:@showNewAchievement) diff --git a/server/users/user_handler.coffee b/server/users/user_handler.coffee index 54f87aaf5..8bbf29739 100644 --- a/server/users/user_handler.coffee +++ b/server/users/user_handler.coffee @@ -21,12 +21,6 @@ candidateProperties = [ 'jobProfile', 'jobProfileApproved', 'jobProfileNotes' ] -parseLiteral = (literalString) -> - return true if literalString is 'true' - return false if literalString is 'false' - return number if (number = Number(literalString)) isnt NaN - literalString - UserHandler = class UserHandler extends Handler modelClass: User @@ -245,7 +239,7 @@ UserHandler = class UserHandler extends Handler getEarnedAchievements: (req, res, userID) -> queryObject = {$query: {user: userID}, $orderby: {changed: -1}} - queryObject.$query[key] = parseLiteral(val) for key, val of req.query + queryObject.$query.notified = false if req.query.notified is 'false' query = EarnedAchievement.find(queryObject) query.exec (err, documents) => return @sendDatabaseError(res, err) if err?