mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
challenges: back to dealing with taskLists from scopes, rather than the
habitrpg-tasks directive. Was having trouble accessing it by reference otherwise. Would love to move off of the directive entirely and use ng-include instead, but some scope issues with lists
This commit is contained in:
@@ -115,18 +115,12 @@ window.habitrpg = angular.module('habitrpg',
|
||||
.state('options.challenges.detail', {
|
||||
url: '/:cid',
|
||||
templateUrl: 'partials/options.challenges.detail.html',
|
||||
// resolve: {
|
||||
// challenge: ['$scope', 'Challenges', '$stateParams', '$q',
|
||||
// function($scope, Challenges, $stateParams, $q){
|
||||
// // FIXME does ui-router not work with ng-resource by default?
|
||||
// var challenge = $q.defer();
|
||||
// Challenges.Challenge.get({cid:$stateParams.cid}, function(_challenge){
|
||||
// challenge._locked = true;
|
||||
// challenge.resolve(_challenge);
|
||||
// });
|
||||
// return challenge.promise;
|
||||
// }]
|
||||
// }
|
||||
controller: ['$scope', 'Challenges', '$stateParams',
|
||||
function($scope, Challenges, $stateParams){
|
||||
$scope.obj = $scope.challenge = Challenges.Challenge.get({cid:$stateParams.cid}, function(){
|
||||
$scope.challenge._locked = true;
|
||||
});
|
||||
}]
|
||||
})
|
||||
|
||||
// Options > Settings
|
||||
|
||||
@@ -73,11 +73,11 @@ habitrpg.controller("ChallengesCtrl", ['$scope', 'User', 'Challenges', 'Notifica
|
||||
// Tasks
|
||||
//------------------------------------------------------------
|
||||
|
||||
$scope.addTask = function(list) {
|
||||
var task = window.habitrpgShared.helpers.taskDefaults({text: list.newTask, type: list.type}, User.user.filters);
|
||||
list.tasks.unshift(task);
|
||||
$scope.addTask = function(addTo, listDef) {
|
||||
var task = window.habitrpgShared.helpers.taskDefaults({text: listDef.newTask, type: listDef.type});
|
||||
addTo.unshift(task);
|
||||
//User.log({op: "addTask", data: task}); //TODO persist
|
||||
delete list.newTask;
|
||||
delete listDef.newTask;
|
||||
};
|
||||
|
||||
$scope.removeTask = function(list, $index) {
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
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.obj = User.user; // used for task-lists
|
||||
|
||||
$scope.score = function(task, direction) {
|
||||
if (task.type === "reward" && User.user.stats.gp < task.value){
|
||||
return Notification.text('Not enough GP.');
|
||||
@@ -11,11 +13,11 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User', '
|
||||
|
||||
};
|
||||
|
||||
$scope.addTask = function(list) {
|
||||
var task = window.habitrpgShared.helpers.taskDefaults({text: list.newTask, type: list.type}, User.user.filters);
|
||||
list.tasks.unshift(task);
|
||||
$scope.addTask = function(addTo, listDef) {
|
||||
var task = window.habitrpgShared.helpers.taskDefaults({text: listDef.newTask, type: listDef.type}, User.user.filters);
|
||||
addTo.unshift(task);
|
||||
User.log({op: "addTask", data: task});
|
||||
delete list.newTask;
|
||||
delete listDef.newTask;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,15 +29,15 @@ habitrpg.directive('habitrpgAdsense', function() {
|
||||
})
|
||||
|
||||
habitrpg.directive('whenScrolled', function() {
|
||||
return function(scope, elm, attr) {
|
||||
var raw = elm[0];
|
||||
return function(scope, elm, attr) {
|
||||
var raw = elm[0];
|
||||
|
||||
elm.bind('scroll', function() {
|
||||
if (raw.scrollTop + raw.offsetHeight >= raw.scrollHeight) {
|
||||
scope.$apply(attr.whenScrolled);
|
||||
}
|
||||
});
|
||||
};
|
||||
elm.bind('scroll', function() {
|
||||
if (raw.scrollTop + raw.offsetHeight >= raw.scrollHeight) {
|
||||
scope.$apply(attr.whenScrolled);
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -127,32 +127,28 @@ habitrpg
|
||||
};
|
||||
},
|
||||
link: function(scope, element, attrs) {
|
||||
scope.obj = scope[attrs.obj];
|
||||
// $scope.obj needs to come from controllers, so we can pass by ref
|
||||
scope.main = attrs.main;
|
||||
|
||||
scope.lists = [
|
||||
$rootScope.lists = [
|
||||
{
|
||||
header: 'Habits',
|
||||
type: 'habit',
|
||||
placeHolder: 'New Habit',
|
||||
tasks: scope.obj.habits
|
||||
placeHolder: 'New Habit'
|
||||
}, {
|
||||
header: 'Dailies',
|
||||
type: 'daily',
|
||||
placeHolder: 'New Daily',
|
||||
tasks: scope.obj.dailys
|
||||
placeHolder: 'New Daily'
|
||||
}, {
|
||||
header: 'Todos',
|
||||
type: 'todo',
|
||||
placeHolder: 'New Todo',
|
||||
tasks: scope.obj.todos
|
||||
placeHolder: 'New Todo'
|
||||
}, {
|
||||
header: 'Rewards',
|
||||
type: 'reward',
|
||||
placeHolder: 'New Reward',
|
||||
tasks: scope.obj.rewards
|
||||
placeHolder: 'New Reward'
|
||||
}
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
}]);
|
||||
|
||||
@@ -18,9 +18,9 @@ script(type='text/ng-template', id='partials/options.challenges.detail.html')
|
||||
div(ng-if='challenge.description') {{challenge.description}}
|
||||
habitrpg-tasks(obj='challenge', main=false)
|
||||
h3 Statistics
|
||||
div(ng-repeat='member in challenge.members', ng-init='member._locked = true')
|
||||
div(ng-repeat='member in challenge.members', ng-init='member._locked = true; obj=member')
|
||||
h4 {{member.profile.name}}
|
||||
habitrpg-tasks(main=false, obj='member')
|
||||
habitrpg-tasks(main=false)
|
||||
|
||||
script(type='text/ng-template', id='partials/options.challenges.html')
|
||||
.row-fluid
|
||||
|
||||
@@ -31,7 +31,7 @@ script(id='templates/habitrpg-tasks.html', type="text/ng-template")
|
||||
.todos-chart(ng-if='list.type == "todo"', ng-show='charts.todos')
|
||||
|
||||
// Add New
|
||||
form.addtask-form.form-inline.new-task-form(name='new{{list.type}}form', ng-hide='obj._locked || (list.showCompleted && list.type=="todo")', ng-submit='addTask(list)')
|
||||
form.addtask-form.form-inline.new-task-form(name='new{{list.type}}form', ng-hide='obj._locked || (list.showCompleted && list.type=="todo")', ng-submit='addTask(obj[list.type+"s"],list)')
|
||||
span.addtask-field
|
||||
input(type='text', ng-model='list.newTask', placeholder='{{list.placeHolder}}', required)
|
||||
input.addtask-btn(type='submit', value='+', ng-disabled='new{{list.type}}form.$invalid')
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
li(ng-repeat='task in list.tasks', class='task {{taskClasses(task, user.filters, user.preferences.dayStart, user.lastCron, list.showCompleted, main)}}', data-id='{{task.id}}')
|
||||
li(ng-repeat='task in obj[list.type+"s"]', class='task {{taskClasses(task, user.filters, user.preferences.dayStart, user.lastCron, list.showCompleted, main)}}', data-id='{{task.id}}')
|
||||
// right-hand side control buttons
|
||||
.task-meta-controls
|
||||
|
||||
@@ -26,7 +26,7 @@ li(ng-repeat='task in list.tasks', class='task {{taskClasses(task, user.filters,
|
||||
span(ng-if='!task.challenge.broken')
|
||||
i.icon-bullhorn(tooltip="Challenge Task")
|
||||
// delete
|
||||
a(ng-if='!task.challenge.id', ng-click='removeTask(list.tasks, $index)', tooltip='Delete')
|
||||
a(ng-if='!task.challenge.id', ng-click='removeTask(obj[list.type+"s"], $index)', tooltip='Delete')
|
||||
i.icon-trash
|
||||
|
||||
// chart
|
||||
|
||||
Reference in New Issue
Block a user