mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Moved clone tasks function to task service
This commit is contained in:
@@ -52,7 +52,7 @@
|
||||
"challengedOwnedFilterHeader": "Ownership",
|
||||
"challengedOwnedFilter": "Owned",
|
||||
"challengedNotOwnedFilter": "Not Owned",
|
||||
"challengedEitherOwnedFilter": "Either",,
|
||||
"challengedEitherOwnedFilter": "Either",
|
||||
"backToChallenges": "Back to all challenges",
|
||||
"prizeValue": "<%= gemcount %> <%= gemicon %> Prize",
|
||||
"clone": "Clone"
|
||||
|
||||
@@ -49,8 +49,6 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
|
||||
});
|
||||
};
|
||||
|
||||
$scope.editTask = Tasks.editTask;
|
||||
|
||||
/**
|
||||
* Create
|
||||
*/
|
||||
@@ -101,21 +99,10 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
|
||||
reward: []
|
||||
};
|
||||
|
||||
function cloneTask(taskToClone, index, array) {
|
||||
var tmpTask = {};
|
||||
for( var property in taskToClone ) {
|
||||
if ( property !== "_id" && property !== "id" && property !== "dateCreated" ) {
|
||||
tmpTask[property] = taskToClone[property];
|
||||
}
|
||||
}
|
||||
var task = Shared.taskDefaults(tmpTask);
|
||||
clonedTasks[taskToClone.type].push(task);
|
||||
}
|
||||
|
||||
challenge.habits.forEach(cloneTask);
|
||||
challenge.dailys.forEach(cloneTask);
|
||||
challenge.todos.forEach(cloneTask);
|
||||
challenge.rewards.forEach(cloneTask);
|
||||
Tasks.cloneTasks(challenge.habits, clonedTasks);
|
||||
Tasks.cloneTasks(challenge.dailys, clonedTasks);
|
||||
Tasks.cloneTasks(challenge.todos, clonedTasks);
|
||||
Tasks.cloneTasks(challenge.rewards, clonedTasks);
|
||||
|
||||
$scope.obj = $scope.newChallenge = new Challenges.Challenge({
|
||||
name: challenge.name,
|
||||
|
||||
@@ -6,10 +6,11 @@ angular
|
||||
|
||||
tasksFactory.$inject = [
|
||||
'$rootScope',
|
||||
'User'
|
||||
'User',
|
||||
'Shared'
|
||||
];
|
||||
|
||||
function tasksFactory($rootScope, User) {
|
||||
function tasksFactory($rootScope, User, Shared) {
|
||||
|
||||
function editTask(task) {
|
||||
task._editing = !task._editing;
|
||||
@@ -18,7 +19,23 @@ function tasksFactory($rootScope, User) {
|
||||
if($rootScope.charts[task.id]) $rootScope.charts[task.id] = false;
|
||||
}
|
||||
|
||||
function cloneTasks(tasksToClone, arrayWithClonedTasks) {
|
||||
var len = tasksToClone.length;
|
||||
for (var i = 0; i < len; i+=1) {
|
||||
var tmpTask = {};
|
||||
var task = tasksToClone[i];
|
||||
for( var property in task ) {
|
||||
if ( property !== "_id" && property !== "id" && property !== "dateCreated" ) {
|
||||
tmpTask[property] = task[property];
|
||||
}
|
||||
}
|
||||
var newTask = Shared.taskDefaults(tmpTask);
|
||||
arrayWithClonedTasks[newTask.type].push(newTask);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
editTask: editTask
|
||||
editTask: editTask,
|
||||
cloneTasks: cloneTasks,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user