mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-08-01 03:30:25 +00:00
move everything to lodash, since we're using it for other things
anyway (cloneDeep, findIndex, etc). make sure to return `true` explicitly after all _.each functions! if you accidently return false (happens more often than you'd think), it kills the loop. As a result, I'm using .forEach() native function where i can for simplicity, but many of our _.each iterate object keys
This commit is contained in:
parent
a31eb184a2
commit
1596808c25
12 changed files with 28 additions and 28 deletions
|
|
@ -1,4 +1,4 @@
|
|||
_ = require 'underscore'
|
||||
_ = require 'lodash'
|
||||
moment = require 'moment'
|
||||
|
||||
###
|
||||
|
|
@ -35,7 +35,7 @@ loadJavaScripts = (model) ->
|
|||
###
|
||||
setupSortable = (model) ->
|
||||
unless (model.get('_mobileDevice') is true) #don't do sortable on mobile
|
||||
_.each ['habit', 'daily', 'todo', 'reward'], (type) ->
|
||||
['habit', 'daily', 'todo', 'reward'].forEach (type) ->
|
||||
$("ul.#{type}s").sortable
|
||||
dropOnEmpty: false
|
||||
cursor: "move"
|
||||
|
|
@ -109,8 +109,7 @@ setupTour = (model) ->
|
|||
|
||||
$('.main-herobox').popover('destroy') #remove previous popovers
|
||||
tour = new Tour()
|
||||
_.each tourSteps, (step) ->
|
||||
tour.addStep _.defaults step, {html:true}
|
||||
tourSteps.forEach (step) -> tour.addStep _.defaults step, {html:true}
|
||||
tour._current = 0 if isNaN(tour._current) #bootstrap-tour bug
|
||||
tour.start()
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@ items = require './items'
|
|||
algos = require 'habitrpg-shared/script/algos'
|
||||
|
||||
moment = require 'moment'
|
||||
_ = require 'underscore'
|
||||
lodash = require 'lodash'
|
||||
_ = require 'lodash'
|
||||
derby = require 'derby'
|
||||
|
||||
module.exports.app = (appExports, model) ->
|
||||
|
|
@ -36,7 +35,7 @@ module.exports.app = (appExports, model) ->
|
|||
batch.startTransaction()
|
||||
taskTypes = ['habit', 'daily', 'todo', 'reward']
|
||||
batch.set 'tasks', {}
|
||||
_.each taskTypes, (type) -> batch.set "#{type}Ids", []
|
||||
taskTypes.forEach (type) -> batch.set "#{type}Ids", []
|
||||
#batch.set 'balance', 1 if user.get('balance') < 1 #only if they haven't manually bought gems
|
||||
|
||||
# Reset stats
|
||||
|
|
@ -105,7 +104,7 @@ userSchema =
|
|||
|
||||
module.exports.newUserObject = ->
|
||||
# deep clone, else further new users get duplicate objects
|
||||
newUser = lodash.cloneDeep userSchema
|
||||
newUser = _.cloneDeep userSchema
|
||||
newUser.apiToken = derby.uuid()
|
||||
|
||||
repeat = {m:true,t:true,w:true,th:true,f:true,s:true,su:true}
|
||||
|
|
@ -180,7 +179,7 @@ module.exports.BatchUpdate = BatchUpdate = (model) ->
|
|||
setStats: (stats) ->
|
||||
stats ?= obj.stats
|
||||
that = @
|
||||
_.each Object.keys(stats), (key) -> that.set "stats.#{key}", stats[key]
|
||||
_.each Object.keys(stats), (key) -> that.set "stats.#{key}", stats[key]; true
|
||||
|
||||
# queue: (path, val) ->
|
||||
# # Special function for setting object properties by string dot-notation. See http://stackoverflow.com/a/6394168/362790
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
_ = require 'underscore'
|
||||
_ = require 'lodash'
|
||||
browser = require './browser'
|
||||
|
||||
module.exports.app = (appExports, model) ->
|
||||
|
|
@ -37,5 +37,5 @@ module.exports.app = (appExports, model) ->
|
|||
tag.remove()
|
||||
|
||||
# remove tag from all tasks
|
||||
_.each user.get("tasks"), (task) -> user.del "tasks.#{task.id}.tags.#{tagId}"
|
||||
_.each user.get("tasks"), (task) -> user.del "tasks.#{task.id}.tags.#{tagId}"; true
|
||||
|
||||
|
|
|
|||
|
|
@ -38,12 +38,12 @@ cleanupCorruptTasks = (model) ->
|
|||
unless task?.id? and task?.type?
|
||||
user.del("tasks.#{key}")
|
||||
delete tasks[key]
|
||||
true
|
||||
true
|
||||
|
||||
batch = null
|
||||
|
||||
## Task List Cleanup
|
||||
_.each ['habit','daily','todo','reward'], (type) ->
|
||||
['habit','daily','todo','reward'].forEach (type) ->
|
||||
|
||||
# 1. remove duplicates
|
||||
# 2. restore missing zombie tasks back into list
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
items = require 'habitrpg-shared/script/items'
|
||||
_ = require 'underscore'
|
||||
_ = require 'lodash'
|
||||
|
||||
###
|
||||
server exports
|
||||
|
|
@ -17,7 +17,7 @@ module.exports.app = (appExports, model) ->
|
|||
appExports.buyItem = (e, el) ->
|
||||
[type, value, index] = [ $(el).attr('data-type'), $(el).attr('data-value'), $(el).attr('data-index') ]
|
||||
if changes = items.buyItem(user.get(), type, value, index)
|
||||
_.each changes, (v,k) -> user.set k,v
|
||||
_.each changes, (v,k) -> user.set k,v; true
|
||||
updateStore(model)
|
||||
|
||||
appExports.activateRewardsTab = ->
|
||||
|
|
@ -29,7 +29,7 @@ module.exports.app = (appExports, model) ->
|
|||
|
||||
module.exports.updateStore = updateStore = (model) ->
|
||||
nextItems = items.updateStore(model.get('_user'))
|
||||
_.each nextItems, (v,k) -> model.set("_items.next.#{k}",v)
|
||||
_.each nextItems, (v,k) -> model.set("_items.next.#{k}",v); true
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
_ = require('underscore')
|
||||
_ = require('lodash')
|
||||
helpers = require('habitrpg-shared/script/helpers')
|
||||
|
||||
module.exports.app = (appExports, model, app) ->
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
_ = require 'underscore'
|
||||
_ = require 'lodash'
|
||||
{ randomVal } = require 'habitrpg-shared/script/helpers'
|
||||
{ pets, hatchingPotions } = require('habitrpg-shared/script/items').items
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ module.exports.app = (appExports, model) ->
|
|||
|
||||
paths = {}
|
||||
algos.score(uObj, tObj, direction, {paths:paths})
|
||||
_.each paths, (v,k) -> user.set(k,helpers.dotGet(k, uObj))
|
||||
_.each paths, (v,k) -> user.set(k,helpers.dotGet(k, uObj)); true
|
||||
|
||||
appExports.addTask = (e, el) ->
|
||||
type = $(el).attr('data-task-type')
|
||||
|
|
@ -85,7 +85,7 @@ module.exports.app = (appExports, model) ->
|
|||
completedIds = _.pluck( _.where(model.get('_todoList'), {completed:true}), 'id')
|
||||
todoIds = user.get('todoIds')
|
||||
|
||||
_.each completedIds, (id) -> user.del "tasks.#{id}"
|
||||
_.each completedIds, (id) -> user.del "tasks.#{id}"; true
|
||||
user.set 'todoIds', _.difference(todoIds, completedIds)
|
||||
|
||||
appExports.toggleDay = (e, el) ->
|
||||
|
|
@ -159,14 +159,15 @@ module.exports.app = (appExports, model) ->
|
|||
batch = character.BatchUpdate(model)
|
||||
batch.startTransaction()
|
||||
model.del '_undo'
|
||||
_.each undo.stats, (val, key) -> batch.set "stats.#{key}", val
|
||||
_.each undo.stats, (val, key) -> batch.set "stats.#{key}", val; true
|
||||
taskPath = "tasks.#{undo.task.id}"
|
||||
_.each undo.task, (val, key) ->
|
||||
return if key in ['id', 'type'] # strange bugs in this world: https://workflowy.com/shared/a53582ea-43d6-bcce-c719-e134f9bf71fd/
|
||||
return true if key in ['id', 'type'] # strange bugs in this world: https://workflowy.com/shared/a53582ea-43d6-bcce-c719-e134f9bf71fd/
|
||||
if key is 'completed'
|
||||
user.pass({cron:true}).set("#{taskPath}.completed",val)
|
||||
else
|
||||
batch.set "#{taskPath}.#{key}", val
|
||||
true
|
||||
batch.commit()
|
||||
|
||||
appExports.tasksToggleAdvanced = (e, el) ->
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
_ = require 'underscore'
|
||||
_ = require 'lodash'
|
||||
{ randomVal } = require 'habitrpg-shared/script/helpers'
|
||||
{ pets, hatchingPotions } = require('habitrpg-shared/script/items').items
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
express = require 'express'
|
||||
router = new express.Router()
|
||||
|
||||
_ = require 'underscore'
|
||||
_ = require 'lodash'
|
||||
algos = require 'habitrpg-shared/script/algos'
|
||||
{ tnl } = algos
|
||||
validator = require 'derby-auth/node_modules/validator'
|
||||
|
|
@ -83,7 +83,7 @@ router.put '/user', auth, (req, res) ->
|
|||
acceptableAttrs = ['flags', 'history', 'items', 'preferences', 'profile', 'stats']
|
||||
user.set 'lastCron', partialUser.lastCron if partialUser.lastCron?
|
||||
_.each acceptableAttrs, (attr) ->
|
||||
_.each partialUser[attr], (val, key) -> user.set("#{attr}.#{key}", val)
|
||||
_.each partialUser[attr], (val, key) -> user.set("#{attr}.#{key}", val);true
|
||||
|
||||
updateTasks partialUser.tasks, req.user, req.getModel() if partialUser.tasks?
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
express = require 'express'
|
||||
router = new express.Router()
|
||||
|
||||
_ = require 'underscore'
|
||||
_ = require 'lodash'
|
||||
icalendar = require('icalendar')
|
||||
api = require './api'
|
||||
|
||||
|
|
@ -44,6 +44,7 @@ router.get '/v1/users/:uid/calendar.ics', (req, res) ->
|
|||
d.date_only = true
|
||||
event.setDate d
|
||||
ical.addComponent event
|
||||
true
|
||||
res.type('text/calendar')
|
||||
formattedIcal = ical.toString().replace(/DTSTART\:/g, 'DTSTART;VALUE=DATE:')
|
||||
res.send(200, formattedIcal)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
_ = require 'underscore'
|
||||
_ = require 'lodash'
|
||||
character = require "../app/character"
|
||||
|
||||
module.exports.middleware = (req, res, next) ->
|
||||
|
|
@ -37,7 +37,7 @@ module.exports.app = (appExports, model) ->
|
|||
batch = new character.BatchUpdate(model)
|
||||
obj = model.get('_user')
|
||||
batch.set 'balance', obj.balance-1
|
||||
_.each obj.tasks, (task) -> batch.set("tasks.#{task.id}.value", 0) unless task.type == 'reward'
|
||||
_.each obj.tasks, (task) -> batch.set("tasks.#{task.id}.value", 0) unless task.type is 'reward';true
|
||||
batch.commit()
|
||||
|
||||
module.exports.routes = (expressApp) ->
|
||||
|
|
|
|||
Loading…
Reference in a new issue