mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-08-01 11:40:25 +00:00
rewrite: fix sortables. we need to change the way this api route handles
sorting, it's really inconsistent - especially for the batch-update routec
This commit is contained in:
parent
1b22928c0a
commit
bbab8eb73c
4 changed files with 18 additions and 11 deletions
|
|
@ -54,19 +54,20 @@ habitrpg.directive('whenScrolled', function() {
|
|||
/**
|
||||
* Add sortable
|
||||
*/
|
||||
habitrpg.directive('sort', function (User) {
|
||||
return ['$scope', 'element', 'attrs', 'ngModel', function($scope, element, attrs, ngModel) {
|
||||
habitrpg.directive('habitrpgSortable', function (User) {
|
||||
return function($scope, element, attrs, ngModel) {
|
||||
$(element).sortable({
|
||||
axis: "y",
|
||||
start: function (event, ui) {
|
||||
ui.item.data('startIndex', ui.item.index());
|
||||
},
|
||||
stop: function (event, ui) {
|
||||
var taskType = angular.element(ui.item[0]).scope().task.type + 's'
|
||||
var taskType = angular.element(ui.item[0]).scope().task.type + 's';
|
||||
var startIndex = ui.item.data('startIndex');
|
||||
var task = User.user[taskType][startIndex];
|
||||
User.log({op: 'sortTask', data: task, from: startIndex, to: ui.item.index()});
|
||||
// FIXME - this is a really inconsistent way of API handling. we need to fix the batch-update route
|
||||
User.log({op: 'sortTask', data: _.defaults({from: startIndex, to: ui.item.index()}, task)});
|
||||
}
|
||||
});
|
||||
}]
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -204,13 +204,13 @@ api.createTask = (req, res, next) ->
|
|||
|
||||
api.sortTask = (req, res, next) ->
|
||||
{id} = req.params
|
||||
{to, from, type} = res.locals.task
|
||||
{to, from, type} = req.body
|
||||
{user} = res.locals
|
||||
path = "#{type}Ids"
|
||||
user[path].splice(to, 0, user[path].splice(from, 1)[0])
|
||||
user.save (err) ->
|
||||
user.save (err, saved) ->
|
||||
return res.json(500,{err}) if err
|
||||
res.json 200, user[path]
|
||||
res.json 200, saved.toJSON()[path]
|
||||
|
||||
###
|
||||
------------------------------------------------------------------------
|
||||
|
|
@ -377,7 +377,6 @@ api.revive = (req, res, next) ->
|
|||
###
|
||||
api.batchUpdate = (req, res, next) ->
|
||||
{user} = res.locals
|
||||
#console.log {user}
|
||||
|
||||
oldSend = res.send
|
||||
oldJson = res.json
|
||||
|
|
@ -402,7 +401,7 @@ api.batchUpdate = (req, res, next) ->
|
|||
when "buy"
|
||||
api.buy(req, res)
|
||||
when "sortTask"
|
||||
api.verifyTaskExists (req, res) ->
|
||||
api.verifyTaskExists req, res, ->
|
||||
api.sortTask(req, res)
|
||||
when "addTask"
|
||||
api.createTask(req, res)
|
||||
|
|
|
|||
|
|
@ -31,6 +31,13 @@ html
|
|||
script(type='text/javascript', src='/bower_components/angular-bootstrap/ui-bootstrap.js')
|
||||
script(type='text/javascript', src='/bower_components/angular-bootstrap/ui-bootstrap-tpls.js')
|
||||
|
||||
// Sortable
|
||||
script(type='text/javascript', src='/bower_components/jquery-ui/ui/minified/jquery.ui.core.min.js')
|
||||
script(type='text/javascript', src='/bower_components/jquery-ui/ui/minified/jquery.ui.widget.min.js')
|
||||
script(type='text/javascript', src='/bower_components/jquery-ui/ui/minified/jquery.ui.mouse.min.js')
|
||||
script(type='text/javascript', src='/bower_components/jquery-ui/ui/minified/jquery.ui.sortable.min.js')
|
||||
|
||||
|
||||
script(type='text/javascript', src='/bower_components/habitrpg-shared/dist/habitrpg-shared.js')
|
||||
|
||||
!= js('app')
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ div(ng-controller='TasksCtrl')
|
|||
hr
|
||||
|
||||
// Actual List
|
||||
ul(class='{{list.type}}s', ng-show='user[list.type + "s"]')
|
||||
ul(class='{{list.type}}s', ng-show='user[list.type + "s"]', habitrpg-sortable)
|
||||
include ./task
|
||||
|
||||
// Static Rewards
|
||||
|
|
|
|||
Loading…
Reference in a new issue