mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-08-01 07:21:15 +00:00
_completedList working properly for todos, messes up dailies
This commit is contained in:
parent
aff781ad3d
commit
1eae25ae54
5 changed files with 79 additions and 64 deletions
|
|
@ -157,29 +157,6 @@ ready(function(model) {
|
|||
model.on('set', '*', function() {
|
||||
return $('[rel=popover]').popover();
|
||||
});
|
||||
model.on('set', '_user.tasks.*.completed', function(i, completed, previous, isLocal) {
|
||||
var direction, from, ids, index, shouldTransfer, to, _ref1, _ref2, _ref3;
|
||||
_ref1 = [null, null, false, null], from = _ref1[0], to = _ref1[1], shouldTransfer = _ref1[2], direction = _ref1[3];
|
||||
if (completed === true && previous === false && isLocal) {
|
||||
_ref2 = ['_todoList', '_completedList', true, 'up'], from = _ref2[0], to = _ref2[1], shouldTransfer = _ref2[2], direction = _ref2[3];
|
||||
} else if (completed === false && previous === true && isLocal) {
|
||||
_ref3 = ['_completedList', '_todoList', true, 'down'], from = _ref3[0], to = _ref3[1], shouldTransfer = _ref3[2], direction = _ref3[3];
|
||||
}
|
||||
if (shouldTransfer) {
|
||||
ids = _.map(model.get(from), function(obj) {
|
||||
return obj.id;
|
||||
});
|
||||
index = ids.indexOf(i);
|
||||
model.push(to, model.remove(from, index));
|
||||
score(model.at('_user'), model.at(i), direction);
|
||||
}
|
||||
return console.log({
|
||||
i: i,
|
||||
completed: completed,
|
||||
previous: previous,
|
||||
isLocal: isLocal
|
||||
}, 'on completed');
|
||||
});
|
||||
setupSortable = function(type) {
|
||||
return $("ul." + type + "s").sortable({
|
||||
dropOnEmpty: false,
|
||||
|
|
@ -219,6 +196,30 @@ ready(function(model) {
|
|||
});
|
||||
}
|
||||
tour.start();
|
||||
model.on('set', '_user.tasks.*.completed', function(i, completed, previous, isLocal) {
|
||||
var direction, from, ids, index, shouldTransfer, task, to, _ref3, _ref4, _ref5;
|
||||
_ref3 = [null, null, false, null], from = _ref3[0], to = _ref3[1], shouldTransfer = _ref3[2], direction = _ref3[3];
|
||||
if (completed === true && previous === false && isLocal) {
|
||||
_ref4 = ['_todoList', '_completedList', true, 'up'], from = _ref4[0], to = _ref4[1], shouldTransfer = _ref4[2], direction = _ref4[3];
|
||||
} else if (completed === false && previous === true && isLocal) {
|
||||
_ref5 = ['_completedList', '_todoList', true, 'down'], from = _ref5[0], to = _ref5[1], shouldTransfer = _ref5[2], direction = _ref5[3];
|
||||
}
|
||||
if (shouldTransfer) {
|
||||
task = model.at("_user.tasks." + i);
|
||||
score({
|
||||
user: model.at('_user'),
|
||||
task: task,
|
||||
direction: direction
|
||||
});
|
||||
ids = _.map(model.get(from), function(obj) {
|
||||
return obj.id;
|
||||
});
|
||||
index = ids.indexOf(i);
|
||||
return model.push(to, task.get(), function() {
|
||||
return model.remove(from, index);
|
||||
});
|
||||
}
|
||||
});
|
||||
exports.addTask = function(e, el, next) {
|
||||
var list, newModel, text;
|
||||
type = $(el).attr('data-task-type');
|
||||
|
|
@ -338,7 +339,11 @@ ready(function(model) {
|
|||
}
|
||||
user = model.at('_user');
|
||||
task = model.at($(el).parents('li')[0]);
|
||||
return score(user, task, direction);
|
||||
return score({
|
||||
user: user,
|
||||
task: task,
|
||||
direction: direction
|
||||
});
|
||||
};
|
||||
exports.endOfDayTally = endOfDayTally = function(e, el) {
|
||||
var absVal, completed, expTally, key, lvl, task, todoTally, user, value, _ref3;
|
||||
|
|
@ -349,7 +354,12 @@ ready(function(model) {
|
|||
_ref3 = [task.get('type'), task.get('value'), task.get('completed')], type = _ref3[0], value = _ref3[1], completed = _ref3[2];
|
||||
if (type === 'todo' || type === 'daily') {
|
||||
if (!completed) {
|
||||
score(user, task, 'down', true);
|
||||
score({
|
||||
user: user,
|
||||
task: task,
|
||||
direction: 'down',
|
||||
cron: true
|
||||
});
|
||||
}
|
||||
if (type === 'daily') {
|
||||
task.push("history", {
|
||||
|
|
|
|||
|
|
@ -55,8 +55,17 @@ updateStats = function(user, stats) {
|
|||
}
|
||||
};
|
||||
|
||||
module.exports = function(user, task, direction, cron) {
|
||||
var adjustvalue, completed, delta, exp, hp, lvl, money, sign, type, value, _ref;
|
||||
module.exports = function(spec) {
|
||||
var adjustvalue, cron, delta, direction, exp, hp, lvl, money, sign, task, type, user, value, _ref, _ref1;
|
||||
if (spec == null) {
|
||||
spec = {
|
||||
user: null,
|
||||
task: null,
|
||||
direction: null,
|
||||
cron: null
|
||||
};
|
||||
}
|
||||
_ref = [spec.user, spec.task, spec.direction, spec.cron], user = _ref[0], task = _ref[1], direction = _ref[2], cron = _ref[3];
|
||||
sign = direction === "up" ? 1 : -1;
|
||||
value = task.get('value');
|
||||
delta = value < 0 ? (-0.1 * value + 1) * sign : (Math.pow(0.9, value)) * sign;
|
||||
|
|
@ -68,15 +77,7 @@ module.exports = function(user, task, direction, cron) {
|
|||
if (adjustvalue) {
|
||||
value += delta;
|
||||
}
|
||||
completed = task.get("completed");
|
||||
if (type !== 'habit') {
|
||||
if (direction === "up") {
|
||||
completed = true;
|
||||
}
|
||||
if (direction === "down") {
|
||||
completed = false;
|
||||
}
|
||||
} else {
|
||||
if (type === 'habit') {
|
||||
if (task.get('value') !== value) {
|
||||
task.push('history', {
|
||||
date: new Date(),
|
||||
|
|
@ -85,8 +86,7 @@ module.exports = function(user, task, direction, cron) {
|
|||
}
|
||||
}
|
||||
task.set('value', value);
|
||||
task.set('completed', completed);
|
||||
_ref = [user.get('stats.money'), user.get('stats.hp'), user.get('stats.exp'), user.get('stats.lvl')], money = _ref[0], hp = _ref[1], exp = _ref[2], lvl = _ref[3];
|
||||
_ref1 = [user.get('stats.money'), user.get('stats.hp'), user.get('stats.exp'), user.get('stats.lvl')], money = _ref1[0], hp = _ref1[1], exp = _ref1[2], lvl = _ref1[3];
|
||||
if (type === 'reward') {
|
||||
money -= task.get('value');
|
||||
if (money < 0) {
|
||||
|
|
|
|||
|
|
@ -124,21 +124,6 @@ ready (model) ->
|
|||
model.on 'set', '*', ->
|
||||
$('[rel=popover]').popover()
|
||||
|
||||
model.on 'set', '_user.tasks.*.completed', (i, completed, previous, isLocal) ->
|
||||
[from, to, shouldTransfer, direction] = [null, null, false, null]
|
||||
if completed==true and previous==false and isLocal
|
||||
[from, to, shouldTransfer, direction] = ['_todoList', '_completedList', true, 'up']
|
||||
else if completed==false and previous==true and isLocal
|
||||
[from, to, shouldTransfer, direction] = ['_completedList', '_todoList', true, 'down']
|
||||
if shouldTransfer
|
||||
ids = _.map model.get(from), (obj) ->
|
||||
obj.id
|
||||
index = ids.indexOf(i)
|
||||
model.push to, model.remove(from, index)
|
||||
score(model.at('_user'), model.at(i), direction)
|
||||
|
||||
console.log {i:i, completed:completed, previous:previous, isLocal:isLocal}, 'on completed'
|
||||
|
||||
# Make the lists draggable using jQuery UI
|
||||
# Note, have to setup helper function here and call it for each type later
|
||||
# due to variable binding of "type"
|
||||
|
|
@ -178,6 +163,24 @@ ready (model) ->
|
|||
# @render()
|
||||
# return false
|
||||
|
||||
model.on 'set', '_user.tasks.*.completed', (i, completed, previous, isLocal) ->
|
||||
|
||||
[from, to, shouldTransfer, direction] = [null, null, false, null]
|
||||
if completed==true and previous==false and isLocal
|
||||
[from, to, shouldTransfer, direction] = ['_todoList', '_completedList', true, 'up']
|
||||
else if completed==false and previous==true and isLocal
|
||||
[from, to, shouldTransfer, direction] = ['_completedList', '_todoList', true, 'down']
|
||||
if shouldTransfer
|
||||
task = model.at("_user.tasks.#{i}")
|
||||
# Score the user based on todo task
|
||||
score({user:model.at('_user'), task:task, direction:direction})
|
||||
# Then move the task to/from _todoList/_completedList
|
||||
ids = _.map model.get(from), (obj) ->
|
||||
obj.id
|
||||
index = ids.indexOf(i)
|
||||
model.push to, task.get(), () ->
|
||||
model.remove from, index
|
||||
|
||||
exports.addTask = (e, el, next) ->
|
||||
type = $(el).attr('data-task-type')
|
||||
list = model.at "_#{type}List"
|
||||
|
|
@ -271,7 +274,7 @@ ready (model) ->
|
|||
user = model.at('_user')
|
||||
task = model.at $(el).parents('li')[0]
|
||||
|
||||
score(user, task, direction)
|
||||
score({user:user, task:task, direction:direction})
|
||||
|
||||
# Note: Set 12am daily cron for this
|
||||
# At end of day, add value to all incomplete Daily & Todo tasks (further incentive)
|
||||
|
|
@ -288,7 +291,7 @@ ready (model) ->
|
|||
if type in ['todo', 'daily']
|
||||
# Deduct experience for missed Daily tasks,
|
||||
# but not for Todos (just increase todo's value)
|
||||
score(user, task, 'down', true) unless completed
|
||||
score({user:user, task:task, direction:'down', cron:true}) unless completed
|
||||
if type == 'daily'
|
||||
task.push "history", { date: new Date(), value: value }
|
||||
else
|
||||
|
|
|
|||
|
|
@ -48,7 +48,8 @@ updateStats = (user, stats) ->
|
|||
money = 0.0 if (!money? or money<0)
|
||||
user.set 'stats.money', stats.money
|
||||
|
||||
module.exports = (user, task, direction, cron) ->
|
||||
module.exports = (spec = {user:null, task:null, direction:null, cron:null}) ->
|
||||
[user, task, direction, cron] = [spec.user, spec.task, spec.direction, spec.cron]
|
||||
|
||||
# For negative values, use a line: something like y=-.1x+1
|
||||
# For positibe values, taper off with inverse log: y=.9^x
|
||||
|
|
@ -65,16 +66,17 @@ module.exports = (user, task, direction, cron) ->
|
|||
adjustvalue = false
|
||||
value += delta if adjustvalue
|
||||
|
||||
# up/down -voting as checkbox & assigning as completed, 2 birds one stone
|
||||
completed = task.get("completed")
|
||||
if type != 'habit'
|
||||
completed = true if direction=="up"
|
||||
completed = false if direction=="down"
|
||||
else
|
||||
# # up/down -voting as checkbox & assigning as completed, 2 birds one stone
|
||||
# completed = task.get("completed")
|
||||
# if type != 'habit'
|
||||
# completed = true if direction=="up"
|
||||
# completed = false if direction=="down"
|
||||
# else
|
||||
if type == 'habit'
|
||||
# Add habit value to habit-history (if different)
|
||||
task.push 'history', { date: new Date(), value: value } if task.get('value') != value
|
||||
task.set('value', value)
|
||||
task.set('completed', completed)
|
||||
# task.set('completed', completed)
|
||||
|
||||
# Update the user's status
|
||||
[money, hp, exp, lvl] = [user.get('stats.money'), user.get('stats.hp'), user.get('stats.exp'), user.get('stats.lvl')]
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@
|
|||
<a x-bind=click:vote class="buy-link" data-direction=down>{:task.value}<img src="/img/coin_single_gold.png"/></a>
|
||||
<!-- Daily & Todos -->
|
||||
{else}
|
||||
<input type="checkbox" checked={:task.completed} x-bind=click:vote data-direction={:task.completed}/>
|
||||
<input type=checkbox checked="{:task.completed}"/>
|
||||
{/}
|
||||
</div>
|
||||
<div class="task-text">{:task.text}</div>
|
||||
|
|
|
|||
Loading…
Reference in a new issue