Merge remote-tracking branch 'origin/7688' into 7688

This commit is contained in:
Husman
2016-06-21 20:41:44 -07:00
5 changed files with 69 additions and 93 deletions

View File

@@ -30,89 +30,11 @@ describe('Tasks Controller', function() {
});
describe('editTask', function() {
var task;
beforeEach(function(){
task = specHelper.newTask();
it('is Tasks.editTask', function() {
inject(function(Tasks) {
expect(scope.editTask).to.eql(Tasks.editTask);
});
});
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() {

View File

@@ -150,6 +150,56 @@ describe('Tasks Service', function() {
$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() {
context('generic tasks', function() {

View File

@@ -100,16 +100,17 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
$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) {
task.checklist = _.filter(task.checklist, function (i) {
return !!i.text
});
}
angular.copy(task._edit, task);
var output = User.updateTask(task, {body: task});
console.log( output );
User.updateTask(task, {body: task});
if (!stayOpen) task._editing = false;
if (isSaveAndClose) {
@@ -119,6 +120,10 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
if (task.type == 'habit') Guide.goto('intro', 3);
};
$scope.completeChecklistItem = function completeChecklistItem(task) {
User.updateTask(task, {body: task});
};
/**
* 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) {
// Remove item if clicked on trash icon
if (force) {
// if (task._edit.checklist[$index].id) Tasks.removeChecklistItem(task._id, task.checklist[$index].id);
task._edit.checklist.splice($index, 1);
} else if (!task._edit.checklist[$index].text) {
// User deleted all the text and is now wishing to delete the 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
if ($index > 0)
focusChecklist(task._edit, $index-1);
@@ -220,7 +223,6 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
$scope.swapChecklistItems = function(task, oldIndex, newIndex) {
var toSwap = task._edit.checklist.splice(oldIndex, 1)[0];
task._edit.checklist.splice(newIndex, 0, toSwap);
// $scope.saveTask(task, true);
}
$scope.navigateChecklist = function(task,$index,$event){
@@ -324,7 +326,7 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
*/
$scope.updateTaskTags = function (tagId, task) {
var tagIndex = task.tags.indexOf(tagId);
var tagIndex = task._edit.tags.indexOf(tagId);
if (tagIndex === -1) {
Tasks.addTagToTask(task._id, tagId);
task.tags.push(tagId);
@@ -332,6 +334,7 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
Tasks.removeTagFromTask(task._id, tagId);
task.tags.splice(tagIndex, 1);
}
angular.copy(task.tags, task._edit.tags);
}
/*

View File

@@ -163,6 +163,7 @@ angular.module('habitrpg')
task._editing = false;
};
function cloneTask(task) {
var clonedTask = _.cloneDeep(task);
clonedTask = _cleanUpTask(clonedTask);

View File

@@ -43,5 +43,5 @@
div(ng-if='task.checklist && !$state.includes("options.social.challenges") && !task.collapseChecklist && !task._editing')
fieldset.option-group.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')