Files
habitica/website/client-old/js/directives/task-list.directive.js
Keith Holliday 30954fe7c5 Added support for grouping tasks by challenge (#8469)
* Added support for grouping tasks by chllenge

* Fixed tests and updated default challenge model name

* Fixed broken member test

* Updated setting string

* Changed to shortName

* Began abstracting task grouping

* Added initial task directive code

* Added new directives to help with grouping of tasks

* Removed random console.log
2017-02-27 11:34:03 -07:00

79 lines
2.3 KiB
JavaScript

'use strict';
(function(){
angular
.module('habitrpg')
.directive('taskList', taskList);
taskList.$inject = [
'$state',
'User',
'$rootScope',
];
function taskList($state, User, $rootScope) {
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) {
// @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'];
};
$scope.showNormalList = function () {
return !$state.includes("options.social.challenges") && !User.user.preferences.tasks.groupByChallenge;
};
$scope.showChallengeList = function () {
return $state.includes("options.social.challenges");
};
}
}
}
}());