mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-10-28 03:32:29 +01:00
105 lines
3.4 KiB
JavaScript
105 lines
3.4 KiB
JavaScript
'use strict';
|
|
|
|
(function(){
|
|
angular
|
|
.module('habitrpg')
|
|
.directive('taskList', taskList);
|
|
|
|
taskList.$inject = [
|
|
'$state',
|
|
'User',
|
|
'$rootScope',
|
|
'Tasks',
|
|
];
|
|
|
|
function taskList($state, User, $rootScope, Tasks) {
|
|
return {
|
|
restrict: 'EA',
|
|
templateUrl: 'templates/task-list.html',
|
|
transclude: true,
|
|
scope: true,
|
|
// scope: {
|
|
// taskList: '=list',
|
|
// list: '=listDetails',
|
|
// obj: '=object',
|
|
// user: "=",
|
|
// },
|
|
link: function($scope, element, attrs) {
|
|
$scope.checklistCompletion = Tasks.checklistCompletion;
|
|
|
|
$scope.completeChecklistItem = function completeChecklistItem(task) {
|
|
User.updateTask(task, {body: task});
|
|
};
|
|
// @TODO: The use of scope with tasks is incorrect. We need to fix all task ctrls to use directives/services
|
|
// $scope.obj = {};
|
|
function setObj (obj, force) {
|
|
if (!force && ($scope.obj || $scope.obj !== {} || !obj)) return;
|
|
$scope.obj = obj;
|
|
setUpGroupedList();
|
|
setUpTaskWatch();
|
|
}
|
|
|
|
$rootScope.$on('obj-updated', function (event, obj) {
|
|
setObj(obj, true);
|
|
});
|
|
|
|
function setUpGroupedList () {
|
|
if (!$scope.obj) return;
|
|
$scope.groupedList = {};
|
|
['habit', 'daily', 'todo', 'reward'].forEach(function (listType) {
|
|
groupTasksByChallenge($scope.obj[listType + 's'], listType);
|
|
});
|
|
}
|
|
setUpGroupedList();
|
|
|
|
function groupTasksByChallenge (taskList, type) {
|
|
$scope.groupedList[type] = _.groupBy(taskList, 'challenge.shortName');
|
|
};
|
|
|
|
function setUpTaskWatch () {
|
|
if (!$scope.obj) return;
|
|
$scope.$watch(function () { return $scope.obj.tasksOrder; }, function () {
|
|
setUpGroupedList();
|
|
}, true);
|
|
}
|
|
setUpTaskWatch();
|
|
|
|
$scope.getTaskList = function (list, taskList, obj) {
|
|
setObj(obj);
|
|
if (!$scope.obj) return [];
|
|
if (taskList) return taskList;
|
|
return $scope.obj[list.type+'s'];
|
|
};
|
|
|
|
function objIsGroup (obj) {
|
|
return obj && obj.type && (obj.type === 'guild' || obj.type === 'party');
|
|
}
|
|
|
|
$scope.showNormalList = function (obj) {
|
|
return objIsGroup(obj) || (!$state.includes("options.social.challenges") && !User.user.preferences.tasks.groupByChallenge);
|
|
}
|
|
|
|
$scope.showChallengeList = function () {
|
|
return $state.includes("options.social.challenges");
|
|
};
|
|
|
|
$scope.showGroupedList = function (obj) {
|
|
return User.user.preferences.tasks.groupByChallenge && !$state.includes("options.social.challenges") && !objIsGroup(obj);
|
|
}
|
|
|
|
$scope.showDoubleTaskCounter = function (task, obj) {
|
|
var objectIsGroup = obj.type && (obj.type === 'guild' || obj.type === 'party');
|
|
var objectIsChallenge = $state.includes("options.social.challenges");
|
|
return !objectIsGroup && !objectIsChallenge && task.up && task.down;
|
|
};
|
|
|
|
$scope.showSingleTaskCounter = function (task, obj) {
|
|
var objectIsGroup = obj.type && (obj.type === 'guild' || obj.type === 'party');
|
|
var objectIsChallenge = $state.includes("options.social.challenges");
|
|
return !objectIsGroup && !objectIsChallenge && task.type === "habit" && (!task.up || !task.down);
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}());
|