Revert "Revert "fixes task edit cancellation commit (#7931)""

This reverts commit 2da9876e42.
This commit is contained in:
Blade Barringer
2016-09-13 11:52:47 -05:00
parent 25aaa351ee
commit cbefc13e25
12 changed files with 100 additions and 77 deletions

View File

@@ -158,11 +158,9 @@ describe('Tasks Service', function() {
task = specHelper.newTask(); task = specHelper.newTask();
}); });
it('toggles the _editing property', function() { it('sets _editing to true', function() {
tasks.editTask(task, user); tasks.editTask(task, user);
expect(task._editing).to.eql(true); expect(task._editing).to.eql(true);
tasks.editTask(task, user);
expect(task._editing).to.eql(false);
}); });
it('sets _tags to true by default', function() { it('sets _tags to true by default', function() {
@@ -200,6 +198,20 @@ describe('Tasks Service', function() {
}); });
}); });
describe('cancelTaskEdit', function() {
var task;
beforeEach(function(){
task = specHelper.newTask();
});
it('sets _editing to false', function() {
task._editing = true;
tasks.cancelTaskEdit(task);
expect(task._editing).to.eql(false);
});
});
describe('cloneTask', function() { describe('cloneTask', function() {
context('generic tasks', function() { context('generic tasks', function() {

View File

@@ -35,6 +35,7 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
} }
$scope.editTask = Tasks.editTask; $scope.editTask = Tasks.editTask;
$scope.cancelTaskEdit = Tasks.cancelTaskEdit;
$scope.canEdit = function(task) { $scope.canEdit = function(task) {
return true; return true;
@@ -304,8 +305,10 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
}; };
$scope.saveTask = function(task){ $scope.saveTask = function(task){
Tasks.updateTask(task._id, task); angular.copy(task._edit, task);
task._edit = undefined;
task._editing = false; task._editing = false;
Tasks.updateTask(task._id, task);
} }
$scope.toggleBulk = Tasks.toggleBulk; $scope.toggleBulk = Tasks.toggleBulk;

View File

@@ -99,17 +99,18 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
} }
}; };
$scope.removeTask = function(task) {
if (!confirm(window.env.t('sureDelete', {taskType: window.env.t(task.type), taskText: task.text}))) return;
User.deleteTask({params:{id: task._id, taskType: task.type}})
};
$scope.saveTask = function(task, stayOpen, isSaveAndClose) { $scope.saveTask = function(task, stayOpen, isSaveAndClose) {
if (task._edit) {
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
}); });
} }
User.updateTask(task, {body: task}); User.updateTask(task, {body: task});
if (!stayOpen) task._editing = false; if (!stayOpen) task._editing = false;
@@ -120,17 +121,19 @@ 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
*/ */
$scope.cancel = function() { $scope.cancelTaskEdit = Tasks.cancelTaskEdit;
var key;
for (key in $scope.task) { $scope.removeTask = function(task) {
$scope.task[key] = $scope.originalTask[key]; if (!confirm(window.env.t('sureDelete', {taskType: window.env.t(task.type), taskText: task.text}))) return;
} task._edit = undefined;
$scope.originalTask = null; User.deleteTask({params:{id: task._id, taskType: task.type}})
$scope.editedTask = null;
$scope.editing = false;
}; };
$scope.unlink = function(task, keep) { $scope.unlink = function(task, keep) {
@@ -193,16 +196,16 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
} }
$scope.addChecklist = function(task) { $scope.addChecklist = function(task) {
task.checklist = [{completed:false, text:""}]; task._edit.checklist = [{completed:false, text:""}];
focusChecklist(task,0); focusChecklist(task._edit,0);
} }
$scope.addChecklistItem = function(task, $event, $index) { $scope.addChecklistItem = function(task, $event, $index) {
if (task.checklist[$index].text) { if (task._edit.checklist[$index].text) {
$scope.saveTask(task, true); if ($index === task._edit.checklist.length - 1) {
if ($index === task.checklist.length - 1) task._edit.checklist.push({ completed: false, text: '' });
task.checklist.push({ completed: false, text: '' }); }
focusChecklist(task, $index + 1); focusChecklist(task._edit, $index + 1);
} else { } else {
// TODO Provide UI feedback that this item is still blank // TODO Provide UI feedback that this item is still blank
} }
@@ -211,24 +214,21 @@ 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.checklist[$index].id) Tasks.removeChecklistItem(task._id, task.checklist[$index].id); task._edit.checklist.splice($index, 1);
task.checklist.splice($index, 1); } else if (!task._edit.checklist[$index].text) {
} else if (!task.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.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, $index-1); focusChecklist(task._edit, $index-1);
// Don't allow the backspace key to navigate back now that the field is gone // Don't allow the backspace key to navigate back now that the field is gone
$event.preventDefault(); $event.preventDefault();
} }
} }
$scope.swapChecklistItems = function(task, oldIndex, newIndex) { $scope.swapChecklistItems = function(task, oldIndex, newIndex) {
var toSwap = task.checklist.splice(oldIndex, 1)[0]; var toSwap = task._edit.checklist.splice(oldIndex, 1)[0];
task.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){
@@ -332,7 +332,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);
@@ -340,6 +340,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);
} }
/* /*

View File

@@ -174,12 +174,18 @@ angular.module('habitrpg')
}; };
function editTask(task, user) { function editTask(task, user) {
task._editing = !task._editing; task._editing = true;
task._tags = !user.preferences.tagsCollapsed; task._tags = !user.preferences.tagsCollapsed;
task._advanced = !user.preferences.advancedCollapsed; task._advanced = !user.preferences.advancedCollapsed;
task._edit = angular.copy(task);
if($rootScope.charts[task._id]) $rootScope.charts[task.id] = false; if($rootScope.charts[task._id]) $rootScope.charts[task.id] = false;
} }
function cancelTaskEdit(task) {
task._edit = undefined;
task._editing = false;
};
function cloneTask(task) { function cloneTask(task) {
var clonedTask = _.cloneDeep(task); var clonedTask = _.cloneDeep(task);
clonedTask = _cleanUpTask(clonedTask); clonedTask = _cleanUpTask(clonedTask);
@@ -226,6 +232,7 @@ angular.module('habitrpg')
unlinkAllTasks: unlinkAllTasks, unlinkAllTasks: unlinkAllTasks,
clearCompletedTodos: clearCompletedTodos, clearCompletedTodos: clearCompletedTodos,
editTask: editTask, editTask: editTask,
cancelTaskEdit: cancelTaskEdit,
cloneTask: cloneTask cloneTask: cloneTask
}; };
}]); }]);

View File

@@ -1,22 +1,22 @@
div(ng-if='::task.type!="reward"') div(ng-if='::task.type!="reward"')
button.advanced-options-toggle.option-title.mega(type='button', button.advanced-options-toggle.option-title.mega(type='button',
ng-class='{active: task._advanced}', ng-class='{active: task._edit._advanced}',
ng-click='task._advanced = !task._advanced', tooltip=env.t('expandCollapse')) ng-click='task._edit._advanced = !task._edit._advanced', tooltip=env.t('expandCollapse'))
=env.t('advancedOptions') =env.t('advancedOptions')
fieldset.option-group.advanced-option(ng-if="task.userId" ng-show="task._advanced") fieldset.option-group.advanced-option(ng-if="task.userId" ng-show="task._edit._advanced")
legend.option-title legend.option-title
a.hint(href='http://habitica.wikia.com/wiki/Task_Alias', target='_blank', popover-trigger='mouseenter', popover="{{::env.t('taskAliasPopover')}} {{::task.alias ? '\n\n\' + env.t('taskAliasPopoverWarning') : ''}}")=env.t('taskAlias') a.hint(href='http://habitica.wikia.com/wiki/Task_Alias', target='_blank', popover-trigger='mouseenter', popover="{{::env.t('taskAliasPopover')}} {{::task._edit.alias ? '\n\n\' + env.t('taskAliasPopoverWarning') : ''}}")=env.t('taskAlias')
input.form-control(ng-model='task.alias' type='text' placeholder=env.t('taskAliasPlaceholder')) input.form-control(ng-model='task._edit.alias' type='text' placeholder=env.t('taskAliasPlaceholder'))
div(ng-show='task._advanced') div(ng-show='task._edit._advanced')
div(ng-if='::task.type == "daily"') div(ng-if='::task.type == "daily"')
.form-group .form-group
legend.option-title legend.option-title
span.hint(popover-title=env.t('startDateHelpTitle'), popover=env.t("startDateHelp"), popover-trigger='mouseenter') span.hint(popover-title=env.t('startDateHelpTitle'), popover=env.t("startDateHelp"), popover-trigger='mouseenter')
=env.t('startDate') =env.t('startDate')
input.form-control(type='text', ng-model='task.startDate', input.form-control(type='text', ng-model='task._edit.startDate',
datepicker-popup='{{::user.preferences.dateFormat}}', is-open='datepickerOpened', datepicker-popup='{{::user.preferences.dateFormat}}', is-open='datepickerOpened',
ng-click='datepickerOpened = true', ng-disabled='!canEdit(task)') ng-click='datepickerOpened = true', ng-disabled='!canEdit(task)')
@@ -24,7 +24,7 @@ div(ng-if='::task.type!="reward"')
.form-group .form-group
legend.option-title=env.t('repeat') legend.option-title=env.t('repeat')
select.form-control(ng-model='task.frequency', ng-disabled='!canEdit(task)') select.form-control(ng-model='task._edit.frequency', ng-disabled='!canEdit(task)')
option(value='weekly')=env.t('repeatWeek') option(value='weekly')=env.t('repeatWeek')
option(value='daily')=env.t('repeatDays') option(value='daily')=env.t('repeatDays')
@@ -32,38 +32,38 @@ div(ng-if='::task.type!="reward"')
hr hr
fieldset.option-group.advanced-option(ng-show="task._advanced") fieldset.option-group.advanced-option(ng-show="task._edit._advanced")
legend.option-title legend.option-title
a.hint.priority-multiplier-help(href='http://habitica.wikia.com/wiki/Difficulty', target='_blank', popover-title=env.t('difficultyHelpTitle'), popover-trigger='mouseenter', popover=env.t('difficultyHelpContent'))=env.t('difficulty') a.hint.priority-multiplier-help(href='http://habitica.wikia.com/wiki/Difficulty', target='_blank', popover-title=env.t('difficultyHelpTitle'), popover-trigger='mouseenter', popover=env.t('difficultyHelpContent'))=env.t('difficulty')
ul.priority-multiplier ul.priority-multiplier
li li
button(type='button', ng-class='{active: task.priority==0.1}', button(type='button', ng-class='{active: task._edit.priority==0.1}',
ng-click='!canEdit(task) || (task.priority=0.1)') ng-click='!canEdit(task) || (task._edit.priority=0.1)')
=env.t('trivial') =env.t('trivial')
li li
button(type='button', ng-class='{active: task.priority==1 || !task.priority}', button(type='button', ng-class='{active: task._edit.priority==1 || !task._edit.priority}',
ng-click='!canEdit(task) || (task.priority=1)') ng-click='!canEdit(task) || (task._edit.priority=1)')
=env.t('easy') =env.t('easy')
li li
button(type='button', ng-class='{active: task.priority==1.5}', button(type='button', ng-class='{active: task._edit.priority==1.5}',
ng-click='!canEdit(task) || (task.priority=1.5)') ng-click='!canEdit(task) || (task._edit.priority=1.5)')
=env.t('medium') =env.t('medium')
li li
button(type='button', ng-class='{active: task.priority==2}', button(type='button', ng-class='{active: task._edit.priority==2}',
ng-click='!canEdit(task) || (task.priority=2)') ng-click='!canEdit(task) || (task._edit.priority=2)')
=env.t('hard') =env.t('hard')
span(ng-if='task.type=="daily" && !$state.includes("options.social.challenges")') span(ng-if='task.type=="daily" && !$state.includes("options.social.challenges")')
legend.option-title.pull-left=env.t('restoreStreak') legend.option-title.pull-left=env.t('restoreStreak')
input.option-content(type='number', ng-model='task.streak') input.option-content(type='number', ng-model='task._edit.streak')
div(ng-if='::(user.preferences.allocationMode == "taskbased" && user.preferences.automaticAllocation) || $state.is("options.social.challenges")') div(ng-if='::(user.preferences.allocationMode == "taskbased" && user.preferences.automaticAllocation) || $state.is("options.social.challenges")')
legend.option-title.pull-left=env.t('attributes') legend.option-title.pull-left=env.t('attributes')
ul.task-attributes ul.task-attributes
each attribute, short in {str: 'strength', int: 'intelligence', con: 'constitution', per: 'perception'} each attribute, short in {str: 'strength', int: 'intelligence', con: 'constitution', per: 'perception'}
li li
button(type='button', ng-class='{active: task.attribute=="#{short}"}', button(type='button', ng-class='{active: task._edit.attribute=="#{short}"}',
ng-click='task.attribute="#{short}"', ng-click='task._edit.attribute="#{short}"',
popover=env.t('#{attribute}Example'), popover-trigger='mouseenter', popover-placement='top') popover=env.t('#{attribute}Example'), popover-trigger='mouseenter', popover-placement='top')
=env.t(attribute) =env.t(attribute)

View File

@@ -1,19 +1,19 @@
.task-checklist-edit(ng-if='::!$state.includes("options.social.challenges") && (task.type=="daily" || task.type=="todo")') .task-checklist-edit(ng-if='::!$state.includes("options.social.challenges") && (task.type=="daily" || task.type=="todo")')
ul ul
li li
button(type='button', ng-if='!task.checklist[0]' button(type='button', ng-if='!task._edit.checklist[0]'
popover=env.t('checklistText'), popover-trigger='mouseenter', popover-placement='bottom', popover=env.t('checklistText'), popover-trigger='mouseenter', popover-placement='bottom',
ng-click='addChecklist(task)') ng-click='addChecklist(task)')
span.glyphicon.glyphicon-tasks span.glyphicon.glyphicon-tasks
span=env.t('addChecklist') span=env.t('addChecklist')
.checklist-form(ng-if='task.checklist') .checklist-form(ng-if='task._edit.checklist')
fieldset.option-group(ng-if='!$state.includes("options.social.challenges")') fieldset.option-group(ng-if='!$state.includes("options.social.challenges")')
legend.option-title(ng-if='task.checklist[0]') legend.option-title(ng-if='task._edit.checklist[0]')
span.hint(popover=env.t('checklistText'), popover-trigger='mouseenter', popover-placement='bottom') span.hint(popover=env.t('checklistText'), popover-trigger='mouseenter', popover-placement='bottom')
=env.t('checklist') =env.t('checklist')
ul(hrpg-sort-checklist) ul(hrpg-sort-checklist)
li(ng-repeat='item in task.checklist') li(ng-repeat='item in task._edit.checklist')
//input(type='checkbox',ng-model='item.completed',ng-change='saveTask(task,true)') //input(type='checkbox',ng-model='item.completed',ng-change='saveTask(task,true)')
//-,ng-blur='saveTask(task,true)') //-,ng-blur='saveTask(task,true)')
span.checklist-icon.glyphicon.glyphicon-resize-vertical span.checklist-icon.glyphicon.glyphicon-resize-vertical

View File

@@ -1,22 +1,22 @@
legend.option-title legend.option-title
span.hint(popover-trigger='mouseenter', popover-title=env.t('repeatHelpTitle'), span.hint(popover-trigger='mouseenter', popover-title=env.t('repeatHelpTitle'),
popover='{{env.t(task.frequency + "RepeatHelpContent")}}')=env.t('repeatEvery') popover='{{env.t(task._edit.frequency + "RepeatHelpContent")}}')=env.t('repeatEvery')
// If frequency is daily // If frequency is daily
ng-form.form-group(name='everyX', ng-if='task.frequency=="daily"') ng-form.form-group(name='everyX', ng-if='task._edit.frequency=="daily"')
.input-group .input-group
input.form-control(type='number', ng-model='task.everyX', min='0', ng-disabled='!canEdit(task)', required) input.form-control(type='number', ng-model='task._edit.everyX', min='0', ng-disabled='!canEdit(task)', required)
span.input-group-addon {{task.everyX == 1 ? env.t('day') : env.t('days')}} span.input-group-addon {{task._edit.everyX == 1 ? env.t('day') : env.t('days')}}
// If frequency is weekly // If frequency is weekly
.form-group(ng-if='task.frequency=="weekly"') .form-group(ng-if='task._edit.frequency=="weekly"')
ul.repeat-days ul.repeat-days
// note, does not use data-toggle="buttons-checkbox" - it would interfere with our own click binding // note, does not use data-toggle="buttons-checkbox" - it would interfere with our own click binding
mixin dayOfWeek(day, num) mixin dayOfWeek(day, num)
li li
button(type='button', ng-class='{active: task.repeat.#{day}}', button(type='button', ng-class='{active: task._edit.repeat.#{day}}',
ng-disabled='!canEdit(task)', ng-click='task.repeat.#{day} = !task.repeat.#{day}', ng-disabled='!canEdit(task)', ng-click='task._edit.repeat.#{day} = !task._edit.repeat.#{day}',
tooltip='{{env.t((task.repeat.#{day}) ? "due" : "notDue")}}') tooltip='{{env.t((task._edit.repeat.#{day}) ? "due" : "notDue")}}')
| {{::moment.weekdaysMin(#{num})}} | {{::moment.weekdaysMin(#{num})}}
+dayOfWeek('su', 0) +dayOfWeek('su', 0)

View File

@@ -1,8 +1,8 @@
fieldset.option-group.plusminus(ng-if='task.type=="habit" && canEdit(task)') fieldset.option-group.plusminus(ng-if='task.type === "habit" && canEdit(task)')
legend.option-title=env.t('direction/Actions') legend.option-title=env.t('direction/Actions')
span.task-checker span.task-checker
input.visuallyhidden.focusable(id='{{obj._id}}_{{task._id}}-option-plus', type='checkbox', ng-model='task.up') input.visuallyhidden.focusable(id='{{obj._id}}_{{task._id}}-option-plus', type='checkbox', ng-model='task._edit.up')
label(for='{{obj._id}}_{{task._id}}-option-plus') label(for='{{obj._id}}_{{task._id}}-option-plus')
span.task-checker span.task-checker
input.visuallyhidden.focusable(id='{{obj._id}}_{{task._id}}-option-minus', type='checkbox', ng-model='task.down') input.visuallyhidden.focusable(id='{{obj._id}}_{{task._id}}-option-minus', type='checkbox', ng-model='task._edit.down')
label(for='{{obj._id}}_{{task._id}}-option-minus') label(for='{{obj._id}}_{{task._id}}-option-minus')

View File

@@ -1,5 +1,5 @@
fieldset.option-group.option-short(ng-if='task.type=="reward" && !task.challenge.id') fieldset.option-group.option-short(ng-if='task.type=="reward" && !task._edit.challenge.id')
legend.option-title=env.t('price') legend.option-title=env.t('price')
input.option-content(type='number', size='16', min='0', step='any', ng-model='task.value', required) input.option-content(type='number', size='16', min='0', step='any', ng-model='task._edit.value', required)
.money.input-suffix .money.input-suffix
span.shop_gold span.shop_gold

View File

@@ -1,7 +1,7 @@
fieldset.option-group fieldset.option-group
label.option-title=env.t('text') label.option-title=env.t('text')
input.form-control(type='text', ng-model='task.text', ng-disabled='!canEdit(task)', required) input.form-control(type='text', ng-model='task._edit.text', ng-disabled='!canEdit(task)', required)
fieldset.option-group fieldset.option-group
label.option-title=env.t('extraNotes') label.option-title=env.t('extraNotes')
textarea.form-control(rows='3', ng-model='task.notes', ng-model-options="{debounce: 1000}") textarea.form-control(rows='3', ng-model='task._edit.notes')

View File

@@ -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

View File

@@ -38,10 +38,10 @@
// main content // main content
.task-text(ng-dblclick='doubleClickTask(obj, task)') .task-text(ng-dblclick='doubleClickTask(obj, task)')
markdown(text='task.text',target='_blank') markdown(text='task._editing ? task._edit.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')
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')