mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
Improving cancel task edit functionality. closes #7688
This commit is contained in:
@@ -30,11 +30,89 @@ describe('Tasks Controller', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('editTask', function() {
|
describe('editTask', function() {
|
||||||
it('is Tasks.editTask', function() {
|
|
||||||
inject(function(Tasks) {
|
var task;
|
||||||
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,56 +150,6 @@ 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() {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
|
|||||||
$scope.user = User.user;
|
$scope.user = User.user;
|
||||||
|
|
||||||
var CTRL_KEYS = [17, 224, 91];
|
var CTRL_KEYS = [17, 224, 91];
|
||||||
|
var originalTasks = [];
|
||||||
|
|
||||||
$scope.armoireCount = function(gear) {
|
$scope.armoireCount = function(gear) {
|
||||||
return Shared.count.remainingGearInSet(gear, 'armoire');
|
return Shared.count.remainingGearInSet(gear, 'armoire');
|
||||||
@@ -68,8 +69,6 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
|
|||||||
list.focus = true;
|
list.focus = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.editTask = Tasks.editTask;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the new task to the actions log
|
* Add the new task to the actions log
|
||||||
*/
|
*/
|
||||||
@@ -100,8 +99,17 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.editTask = function(task, user) {
|
||||||
|
originalTasks.push(_.cloneDeep(task));
|
||||||
|
task._editing = !task._editing;
|
||||||
|
task._tags = !user.preferences.tagsCollapsed;
|
||||||
|
task._advanced = !user.preferences.advancedCollapsed;
|
||||||
|
if($rootScope.charts[task._id]) $rootScope.charts[task.id] = false;
|
||||||
|
}
|
||||||
|
|
||||||
$scope.removeTask = function(task) {
|
$scope.removeTask = function(task) {
|
||||||
if (!confirm(window.env.t('sureDelete', {taskType: window.env.t(task.type), taskText: task.text}))) return;
|
if (!confirm(window.env.t('sureDelete', {taskType: window.env.t(task.type), taskText: task.text}))) return;
|
||||||
|
_.remove(originalTasks, {'_id': task._id})
|
||||||
User.deleteTask({params:{id: task._id, taskType: task.type}})
|
User.deleteTask({params:{id: task._id, taskType: task.type}})
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -111,6 +119,7 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
|
|||||||
return !!i.text
|
return !!i.text
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
_.remove(originalTasks, {'_id': task._id})
|
||||||
User.updateTask(task, {body: task});
|
User.updateTask(task, {body: task});
|
||||||
if (!stayOpen) task._editing = false;
|
if (!stayOpen) task._editing = false;
|
||||||
|
|
||||||
@@ -124,14 +133,11 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
|
|||||||
/**
|
/**
|
||||||
* Reset $scope.task to $scope.originalTask
|
* Reset $scope.task to $scope.originalTask
|
||||||
*/
|
*/
|
||||||
$scope.cancel = function() {
|
$scope.cancelTaskEdit = function(task) {
|
||||||
var key;
|
var unedittedTask = _.find(originalTasks, {'_id': task._id})
|
||||||
for (key in $scope.task) {
|
_.remove(originalTasks, {'_id': task._id})
|
||||||
$scope.task[key] = $scope.originalTask[key];
|
_.assign(task, unedittedTask);
|
||||||
}
|
task._editing = false;
|
||||||
$scope.originalTask = null;
|
|
||||||
$scope.editedTask = null;
|
|
||||||
$scope.editing = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.unlink = function(task, keep) {
|
$scope.unlink = function(task, keep) {
|
||||||
|
|||||||
@@ -150,13 +150,6 @@ angular.module('habitrpg')
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function editTask(task, user) {
|
|
||||||
task._editing = !task._editing;
|
|
||||||
task._tags = !user.preferences.tagsCollapsed;
|
|
||||||
task._advanced = !user.preferences.advancedCollapsed;
|
|
||||||
if($rootScope.charts[task._id]) $rootScope.charts[task.id] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function cloneTask(task) {
|
function cloneTask(task) {
|
||||||
var clonedTask = _.cloneDeep(task);
|
var clonedTask = _.cloneDeep(task);
|
||||||
clonedTask = _cleanUpTask(clonedTask);
|
clonedTask = _cleanUpTask(clonedTask);
|
||||||
@@ -200,7 +193,6 @@ angular.module('habitrpg')
|
|||||||
unlinkOneTask: unlinkOneTask,
|
unlinkOneTask: unlinkOneTask,
|
||||||
unlinkAllTasks: unlinkAllTasks,
|
unlinkAllTasks: unlinkAllTasks,
|
||||||
clearCompletedTodos: clearCompletedTodos,
|
clearCompletedTodos: clearCompletedTodos,
|
||||||
editTask: editTask,
|
|
||||||
cloneTask: cloneTask
|
cloneTask: cloneTask
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|||||||
@@ -27,11 +27,11 @@
|
|||||||
|
|
|
|
||||||
span.glyphicon.glyphicon-pencil(ng-hide='task._editing')
|
span.glyphicon.glyphicon-pencil(ng-hide='task._editing')
|
||||||
|
|
|
|
||||||
a(ng-hide='!task._editing', ng-click='editTask(task, user)', tooltip=env.t('cancel'))
|
a(ng-hide='!task._editing', ng-click='cancelTaskEdit(task)', tooltip=env.t('cancel'))
|
||||||
span.glyphicon.glyphicon-remove(ng-hide='!task._editing')
|
span.glyphicon.glyphicon-remove(ng-hide='!task._editing')
|
||||||
|
|
|
|
||||||
// save
|
// save
|
||||||
a(ng-hide='!task._editing', ng-click='editTask(task, user);saveTask(task)', tooltip=env.t('save'))
|
a(ng-hide='!task._editing', ng-click='saveTask(task)', tooltip=env.t('save'))
|
||||||
span.glyphicon.glyphicon-ok(ng-hide='!task._editing')
|
span.glyphicon.glyphicon-ok(ng-hide='!task._editing')
|
||||||
|
|
|
|
||||||
//challenges
|
//challenges
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
label(for='box-{{::obj._id}}_{{::task._id}}')
|
label(for='box-{{::obj._id}}_{{::task._id}}')
|
||||||
|
|
||||||
// main content
|
// main content
|
||||||
.task-text(ng-dblclick='task._editing ? saveTask(task) : editTask(task)')
|
.task-text(ng-dblclick='task._editing ? saveTask(task) : editTask(task, user)')
|
||||||
markdown(text='task.text',target='_blank')
|
markdown(text='task.text',target='_blank')
|
||||||
|
|
||||||
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')
|
||||||
|
|||||||
Reference in New Issue
Block a user