challenges: sync score to challenge, lotsa bug fixes

This commit is contained in:
Tyler Renelle
2013-10-27 15:27:01 -07:00
parent e52d0a156a
commit a078889d58
7 changed files with 45 additions and 83 deletions

View File

@@ -119,50 +119,6 @@ habitrpg.controller("ChallengesCtrl", ['$scope', '$rootScope', 'User', 'Challeng
// chart = new google.visualization.LineChart $(".challenge-#{chal.id}-member-#{member.id}-history-#{task.id}")[0]
// chart.draw(data, options)
/**
* Sync user to challenge (when they score, add to statistics)
*/
// TODO this needs to be moved to the server. Either:
// 1. Calculate on load (simplest, but bad performance)
// 2. Updated from user score API
// app.model.on("change", "_page.user.priv.tasks.*.value", function(id, value, previous, passed) {
// /* Sync to challenge, but do it later*/
//
// var _this = this;
// return async.nextTick(function() {
// var chal, chalTask, chalUser, ctx, cu, model, pub, task, tobj;
// model = app.model;
// ctx = {
// model: model
// };
// task = model.at("_page.user.priv.tasks." + id);
// tobj = task.get();
// pub = model.get("_page.user.pub");
// if (((chalTask = helpers.taskInChallenge.call(ctx, tobj)) != null) && chalTask.get()) {
// chalTask.increment("value", value - previous);
// chal = model.at("groups." + tobj.group.id + ".challenges." + tobj.challenge);
// chalUser = function() {
// return helpers.indexedAt.call(ctx, chal.path(), 'members', {
// id: pub.id
// });
// };
// cu = chalUser();
// if (!(cu != null ? cu.get() : void 0)) {
// chal.push("members", {
// id: pub.id,
// name: model.get(pub.profile.name)
// });
// cu = model.at(chalUser());
// } else {
// cu.set('name', pub.profile.name);
// }
// return cu.set("" + tobj.type + "s." + tobj.id, {
// value: tobj.value,
// history: tobj.history
// });
// }
// });
// });
/*
--------------------------
@@ -170,15 +126,6 @@ habitrpg.controller("ChallengesCtrl", ['$scope', '$rootScope', 'User', 'Challeng
--------------------------
*/
$scope.unlink = function(task, keep) {
// TODO move this to userServices, turn userSerivces.user into ng-resource
$http.post(API_URL + '/api/v1/user/task/' + task.id + '/unlink', {keep:keep})
.success(function(){
debugger
User.log({});
});
};
$scope.unsubscribe = function(keep) {
if (keep == 'cancel') {
$scope.selectedChal = undefined;

View File

@@ -1,7 +1,7 @@
"use strict";
habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User', 'Algos', 'Helpers', 'Notification',
function($scope, $rootScope, $location, User, Algos, Helpers, Notification) {
habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User', 'Algos', 'Helpers', 'Notification', '$http', 'API_URL',
function($scope, $rootScope, $location, User, Algos, Helpers, Notification, $http, API_URL) {
$scope.score = function(task, direction) {
if (task.type === "reward" && User.user.stats.gp < task.value){
return Notification.text('Not enough GP.');
@@ -94,6 +94,14 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User', '
$scope.editing = false;
};
$scope.unlink = function(task, keep) {
// TODO move this to userServices, turn userSerivces.user into ng-resource
$http.post(API_URL + '/api/v1/user/task/' + task.id + '/unlink?keep=' + keep)
.success(function(){
User.log({});
});
};
/*
------------------------
Items