mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
Merge remote-tracking branch 'origin/7688' into 7688
This commit is contained in:
@@ -30,89 +30,11 @@ describe('Tasks Controller', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('editTask', function() {
|
describe('editTask', function() {
|
||||||
|
it('is Tasks.editTask', function() {
|
||||||
var task;
|
inject(function(Tasks) {
|
||||||
|
expect(scope.editTask).to.eql(Tasks.editTask);
|
||||||
beforeEach(function(){
|
});
|
||||||
task = specHelper.newTask();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('toggles the _editing property', function() {
|
|
||||||
scope.editTask(task, user);
|
|
||||||
expect(task._editing).to.eql(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets _tags to true by default', function() {
|
|
||||||
scope.editTask(task, user);
|
|
||||||
|
|
||||||
expect(task._tags).to.eql(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets _tags to false if preference for collapsed tags is turned on', function() {
|
|
||||||
user.preferences.tagsCollapsed = true;
|
|
||||||
scope.editTask(task, user);
|
|
||||||
|
|
||||||
expect(task._tags).to.eql(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets _advanced to true by default', function(){
|
|
||||||
user.preferences.advancedCollapsed = true;
|
|
||||||
scope.editTask(task, user);
|
|
||||||
|
|
||||||
expect(task._advanced).to.eql(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sets _advanced to false if preference for collapsed advance menu is turned on', function() {
|
|
||||||
user.preferences.advancedCollapsed = false;
|
|
||||||
scope.editTask(task, user);
|
|
||||||
|
|
||||||
expect(task._advanced).to.eql(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('cancelEdit', function() {
|
|
||||||
|
|
||||||
var task;
|
|
||||||
|
|
||||||
beforeEach(function(){
|
|
||||||
task = specHelper.newTask();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('resets the task text', function() {
|
|
||||||
let originalText = task.text;
|
|
||||||
scope.editTask(task, user);
|
|
||||||
task.text = 'test';
|
|
||||||
scope.cancelTaskEdit(task)
|
|
||||||
expect(task.text).to.be.eql(originalText);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('resets the task notes', function() {
|
|
||||||
let originalNotes = task.notes;
|
|
||||||
scope.editTask(task, user);
|
|
||||||
task.notes = 'test';
|
|
||||||
scope.cancelTaskEdit(task)
|
|
||||||
expect(task.notes).to.be.eql(originalNotes);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('resets the task alias', function() {
|
|
||||||
task.alias = 'alias';
|
|
||||||
let originalAlias = task.alias;
|
|
||||||
scope.editTask(task, user);
|
|
||||||
task.alias = 'test';
|
|
||||||
scope.cancelTaskEdit(task)
|
|
||||||
expect(task.alias).to.be.eql(originalAlias);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('resets the task priority', function() {
|
|
||||||
let originalPriority = task.priority;
|
|
||||||
scope.editTask(task, user);
|
|
||||||
task.priority = 'test';
|
|
||||||
scope.cancelTaskEdit(task)
|
|
||||||
expect(task.priority).to.be.eql(originalPriority);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('removeTask', function() {
|
describe('removeTask', function() {
|
||||||
|
|||||||
@@ -150,6 +150,56 @@ describe('Tasks Service', function() {
|
|||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('editTask', function() {
|
||||||
|
|
||||||
|
var task;
|
||||||
|
|
||||||
|
beforeEach(function(){
|
||||||
|
task = specHelper.newTask();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('toggles the _editing property', function() {
|
||||||
|
tasks.editTask(task, user);
|
||||||
|
expect(task._editing).to.eql(true);
|
||||||
|
tasks.editTask(task, user);
|
||||||
|
expect(task._editing).to.eql(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets _tags to true by default', function() {
|
||||||
|
tasks.editTask(task, user);
|
||||||
|
|
||||||
|
expect(task._tags).to.eql(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets _tags to false if preference for collapsed tags is turned on', function() {
|
||||||
|
user.preferences.tagsCollapsed = true;
|
||||||
|
tasks.editTask(task, user);
|
||||||
|
|
||||||
|
expect(task._tags).to.eql(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets _advanced to true by default', function(){
|
||||||
|
user.preferences.advancedCollapsed = true;
|
||||||
|
tasks.editTask(task, user);
|
||||||
|
|
||||||
|
expect(task._advanced).to.eql(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets _advanced to false if preference for collapsed advance menu is turned on', function() {
|
||||||
|
user.preferences.advancedCollapsed = false;
|
||||||
|
tasks.editTask(task, user);
|
||||||
|
|
||||||
|
expect(task._advanced).to.eql(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('closes task chart if it exists', function() {
|
||||||
|
rootScope.charts[task.id] = true;
|
||||||
|
|
||||||
|
tasks.editTask(task, user);
|
||||||
|
expect(rootScope.charts[task.id]).to.eql(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('cloneTask', function() {
|
describe('cloneTask', function() {
|
||||||
|
|
||||||
context('generic tasks', function() {
|
context('generic tasks', function() {
|
||||||
|
|||||||
@@ -99,17 +99,18 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.editTask = Tasks.editTask;
|
$scope.editTask = Tasks.editTask;
|
||||||
|
|
||||||
$scope.saveTask = function saveTask(task, stayOpen, isSaveAndClose) {
|
$scope.saveTask = function(task, stayOpen, isSaveAndClose) {
|
||||||
|
angular.copy(task._edit, task);
|
||||||
|
task._edit = undefined;
|
||||||
|
|
||||||
if (task.checklist) {
|
if (task.checklist) {
|
||||||
task.checklist = _.filter(task.checklist, function (i) {
|
task.checklist = _.filter(task.checklist, function (i) {
|
||||||
return !!i.text
|
return !!i.text
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
angular.copy(task._edit, task);
|
User.updateTask(task, {body: task});
|
||||||
var output = User.updateTask(task, {body: task});
|
|
||||||
console.log( output );
|
|
||||||
if (!stayOpen) task._editing = false;
|
if (!stayOpen) task._editing = false;
|
||||||
|
|
||||||
if (isSaveAndClose) {
|
if (isSaveAndClose) {
|
||||||
@@ -119,6 +120,10 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
|
|||||||
if (task.type == 'habit') Guide.goto('intro', 3);
|
if (task.type == 'habit') Guide.goto('intro', 3);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.completeChecklistItem = function completeChecklistItem(task) {
|
||||||
|
User.updateTask(task, {body: task});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset $scope.task to $scope.originalTask
|
* Reset $scope.task to $scope.originalTask
|
||||||
*/
|
*/
|
||||||
@@ -203,12 +208,10 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
|
|||||||
$scope.removeChecklistItem = function(task, $event, $index, force) {
|
$scope.removeChecklistItem = function(task, $event, $index, force) {
|
||||||
// Remove item if clicked on trash icon
|
// Remove item if clicked on trash icon
|
||||||
if (force) {
|
if (force) {
|
||||||
// if (task._edit.checklist[$index].id) Tasks.removeChecklistItem(task._id, task.checklist[$index].id);
|
|
||||||
task._edit.checklist.splice($index, 1);
|
task._edit.checklist.splice($index, 1);
|
||||||
} else if (!task._edit.checklist[$index].text) {
|
} else if (!task._edit.checklist[$index].text) {
|
||||||
// User deleted all the text and is now wishing to delete the item
|
// User deleted all the text and is now wishing to delete the item
|
||||||
// saveTask will prune the empty item
|
// saveTask will prune the empty item
|
||||||
// if (task._edit.checklist[$index].id) Tasks.removeChecklistItem(task._id, task.checklist[$index].id);
|
|
||||||
// Move focus if the list is still non-empty
|
// Move focus if the list is still non-empty
|
||||||
if ($index > 0)
|
if ($index > 0)
|
||||||
focusChecklist(task._edit, $index-1);
|
focusChecklist(task._edit, $index-1);
|
||||||
@@ -220,7 +223,6 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
|
|||||||
$scope.swapChecklistItems = function(task, oldIndex, newIndex) {
|
$scope.swapChecklistItems = function(task, oldIndex, newIndex) {
|
||||||
var toSwap = task._edit.checklist.splice(oldIndex, 1)[0];
|
var toSwap = task._edit.checklist.splice(oldIndex, 1)[0];
|
||||||
task._edit.checklist.splice(newIndex, 0, toSwap);
|
task._edit.checklist.splice(newIndex, 0, toSwap);
|
||||||
// $scope.saveTask(task, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.navigateChecklist = function(task,$index,$event){
|
$scope.navigateChecklist = function(task,$index,$event){
|
||||||
@@ -324,7 +326,7 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
$scope.updateTaskTags = function (tagId, task) {
|
$scope.updateTaskTags = function (tagId, task) {
|
||||||
var tagIndex = task.tags.indexOf(tagId);
|
var tagIndex = task._edit.tags.indexOf(tagId);
|
||||||
if (tagIndex === -1) {
|
if (tagIndex === -1) {
|
||||||
Tasks.addTagToTask(task._id, tagId);
|
Tasks.addTagToTask(task._id, tagId);
|
||||||
task.tags.push(tagId);
|
task.tags.push(tagId);
|
||||||
@@ -332,6 +334,7 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
|
|||||||
Tasks.removeTagFromTask(task._id, tagId);
|
Tasks.removeTagFromTask(task._id, tagId);
|
||||||
task.tags.splice(tagIndex, 1);
|
task.tags.splice(tagIndex, 1);
|
||||||
}
|
}
|
||||||
|
angular.copy(task.tags, task._edit.tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -163,6 +163,7 @@ angular.module('habitrpg')
|
|||||||
task._editing = false;
|
task._editing = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
function cloneTask(task) {
|
function cloneTask(task) {
|
||||||
var clonedTask = _.cloneDeep(task);
|
var clonedTask = _.cloneDeep(task);
|
||||||
clonedTask = _cleanUpTask(clonedTask);
|
clonedTask = _cleanUpTask(clonedTask);
|
||||||
|
|||||||
@@ -43,5 +43,5 @@
|
|||||||
div(ng-if='task.checklist && !$state.includes("options.social.challenges") && !task.collapseChecklist && !task._editing')
|
div(ng-if='task.checklist && !$state.includes("options.social.challenges") && !task.collapseChecklist && !task._editing')
|
||||||
fieldset.option-group.task-checklist
|
fieldset.option-group.task-checklist
|
||||||
label.checkbox(ng-repeat='item in task.checklist')
|
label.checkbox(ng-repeat='item in task.checklist')
|
||||||
input(type='checkbox', ng-model='item.completed', ng-change='saveTask(task,true)')
|
input(type='checkbox', ng-model='item.completed', ng-change='completeChecklistItem(task)')
|
||||||
markdown(text='item.text', target='_blank')
|
markdown(text='item.text', target='_blank')
|
||||||
|
|||||||
Reference in New Issue
Block a user