mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
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
This commit is contained in:
78
website/client-old/js/directives/task-list.directive.js
Normal file
78
website/client-old/js/directives/task-list.directive.js
Normal file
@@ -0,0 +1,78 @@
|
||||
'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");
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}());
|
||||
Reference in New Issue
Block a user