Sortable transactions.

This commit is contained in:
James Cole 2015-03-26 22:52:49 +01:00
parent e0730c7b39
commit 544ffca3a5
6 changed files with 105 additions and 13 deletions

View File

@ -287,7 +287,6 @@ class TransactionController extends Controller
* @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
*
* @return $this
* @throws FireflyException
*/
public function update(TransactionJournal $journal, JournalFormRequest $request, JournalRepositoryInterface $repository)
{

View File

@ -9,7 +9,7 @@ use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\Reminder;
use Illuminate\Contracts\Auth\Guard;
use View;
use Illuminate\Support\Collection;
/**
* Class Reminders
*
@ -67,10 +67,10 @@ class Reminders
}
}
// delete invalid reminders
$set = $this->auth->user()->reminders()->
leftJoin('piggy_banks','piggy_banks.id','=','remindersable_id')->
whereNull('piggy_banks.id')->get(['reminders.id']);
foreach($set as $reminder) {
$set = $this->auth->user()->reminders()->leftJoin('piggy_banks', 'piggy_banks.id', '=', 'remindersable_id')->whereNull('piggy_banks.id')->get(
['reminders.id']
);
foreach ($set as $reminder) {
$reminder->delete();
}

7
public/js/jquery-ui.min.js vendored Executable file

File diff suppressed because one or more lines are too long

View File

@ -14,8 +14,88 @@ if ($('input[name="category"]').length > 0) {
});
}
// Return a helper with preserved width of cells
var fixHelper = function (e, ui) {
ui.children().each(function () {
$(this).width($(this).width());
});
return ui;
};
$(document).ready(function () {
if(typeof googleTablePaged != 'undefined') {
googleTablePaged('table/transactions/' + what,'transaction-table');
if (typeof googleTablePaged != 'undefined') {
googleTablePaged('table/transactions/' + what, 'transaction-table');
}
});
// sortable!
$(".sortable-table tbody").sortable(
{
helper: fixHelper,
connectWith: '.sortable-table tbody',
//stop: stopSorting,
items: 'tr:not(.ignore)',
stop: sortStop,
//revert: 'invalid'
}
).disableSelection();
});
function sortChange() {
//console.log("change");
}
function sortSort(event, ui) {
//var current = $(ui.item);
//var thisDate = current.data('date');
//if(current.prev().data('date') != thisDate && current.next().data('date') != thisDate) {
// console.log('FALSE ['+current.prev().data('date')+'] ['+thisDate+'] ['+current.next().data('date')+'] ('+current.index()+')');
// return true;
// return false;
//}
//console.log('TRUE ['+current.prev().data('date')+'] ['+thisDate+'] ['+current.next().data('date')+'] ('+current.index()+')');
}
function sortStop(event, ui) {
console.log("stop");
var current = $(ui.item);
var thisDate = current.data('date');
var originalBG = current.css('backgroundColor');
if (current.prev().data('date') != thisDate && current.next().data('date') != thisDate) {
console.log('False!');
console.log('[' + current.prev().data('date') + '] [' + thisDate + '] [' + current.next().data('date') + ']');
// animate something with color:
current.animate({
backgroundColor: "#d9534f"
}, 200, function () {
$(this).animate({
backgroundColor: originalBG
}, 200);
});
// fade back to original
return false;
}
console.log('TRUE!');
console.log('[' + current.prev().data('date') + '] [' + thisDate + '] [' + current.next().data('date') + ']');
current.animate({
backgroundColor: "#5cb85c"
}, 200, function () {
$(this).animate({
backgroundColor: originalBG
}, 200);
});
//else update some order thing bla bla.
//check if the item above OR under this one have the same date
//if not. return false
}

View File

@ -1,8 +1,8 @@
@if(is_object($journals) && method_exists($journals, 'render'))
{!! $journals->render() !!}
@endif
<table class="table table-striped table-bordered">
<tr>
<table class="table table-striped table-bordered sortable-table">
<tr class="ignore">
<th colspan="2">&nbsp;</th>
<th>Description</th>
<th>Amount</th>
@ -21,7 +21,7 @@
</tr>
@foreach($journals as $journal)
@if(!isset($journal->transactions[1]) || !isset($journal->transactions[0]))
<tr>
<tr class="ignore">
<td>
<div class="btn-group btn-group-xs">
<a href="{{route('transactions.delete',$journal->id)}}" class="btn btn-xs btn-danger"><i class="fa fa-fw fa-trash-o"></i></a>
@ -32,9 +32,10 @@
<td colspan="7"><em>Invalid journal: Found {{$journal->transactions()->count()}} transaction(s)</td>
</tr>
@else
<tr>
<tr class="drag" data-date="{{$journal->date->format('Y-m-d')}}">
<td>
<div class="btn-group btn-group-xs">
<a href="#" class="btn btn-default btn-xs"><i class="fa fa-fw fa-arrows-v"></i></a>
<a href="{{route('transactions.edit',$journal->id)}}" class="btn btn-xs btn-default"><i class="fa fa-fw fa-pencil"></i></a>
<a href="{{route('transactions.delete',$journal->id)}}" class="btn btn-xs btn-danger"><i class="fa fa-fw fa-trash-o"></i></a>
</div>

View File

@ -14,3 +14,8 @@
@stop
@section('scripts')
<script src="js/jquery-ui.min.js" type="text/javascript"></script>
<script src="js/transactions.js" type="text/javascript"></script>
@stop