Thing with order and should fix Travis.

This commit is contained in:
James Cole 2015-03-27 07:20:32 +01:00
parent f80de12cb5
commit 6dddd6629d
14 changed files with 103 additions and 46 deletions

View File

@ -210,6 +210,15 @@ class TransactionController extends Controller
}
/**
* Reorder transactions (which all must have the same date)
*/
public function reorder()
{
$ids = Input::get('items');
}
/**
* @param TransactionJournal $journal
*

View File

@ -366,6 +366,7 @@ Route::group(
);
Route::post('/transaction/update/{tj}', ['uses' => 'TransactionController@update', 'as' => 'transactions.update']);
Route::post('/transaction/destroy/{tj}', ['uses' => 'TransactionController@destroy', 'as' => 'transactions.destroy']);
Route::post('/transaction/reorder', ['uses' => 'TransactionController@reorder', 'as' => 'transactions.reorder']);
/**
* Auth\Auth Controller

View File

@ -80,18 +80,36 @@ class FireflyValidator extends Validator
public function validateUniqueAccountForUser($attribute, $value, $parameters)
{
// get account type from data, we must have this:
$type = isset($this->data['what']) ? $this->data['what'] : Input::get('what');
$longType = Config::get('firefly.accountTypeByIdentifier.' . $type);
$dbType = AccountType::whereType($longType)->first();
if (!$dbType) {
$type = isset($this->data['what']) ? $this->data['what'] : null;
// some fallback:
if(is_null($type)) {
$type = Input::get('what');
}
// still null?
if(is_null($type)) {
// find by other field:
$type = isset($this->data['account_type_id']) ? $this->data['account_type_id'] : 0;
$dbType = AccountType::find($type);
} else {
$longType = Config::get('firefly.accountTypeByIdentifier.' . $type);
$dbType = AccountType::whereType($longType)->first();
}
if (is_null($dbType)) {
return false;
}
$query = DB::table('accounts')->where('name', $value)->where('account_type_id', $dbType->id)->where('user_id', Auth::user()->id);
// user id?
$userId = Auth::check() ? Auth::user()->id : $this->data['user_id'];
$query = DB::table('accounts')->where('name', $value)->where('account_type_id', $dbType->id)->where('user_id', $userId);
if (isset($parameters[0])) {
$query->where('id', '!=', $parameters[0]);
}
$count = $query->count();
if ($count == 0) {
return true;
}

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class ChangesForV333 extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table(
'transaction_journals', function (Blueprint $table) {
$table->smallInteger('order',false,true)->default(0);
}
);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}

View File

@ -31,45 +31,23 @@ $(document).ready(function () {
$(".sortable-table tbody").sortable(
{
helper: fixHelper,
connectWith: '.sortable-table tbody',
//stop: stopSorting,
items: 'tr:not(.ignore)',
stop: sortStop,
handle: '.handle'
//revert: 'invalid'
handle: '.handle',
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') + ']');
//console.log('False!');
//console.log('[' + current.prev().data('date') + '] [' + thisDate + '] [' + current.next().data('date') + ']');
// animate something with color:
current.animate({
backgroundColor: "#d9534f"
@ -79,13 +57,23 @@ function sortStop(event, ui) {
}, 200);
});
// fade back to original
return false;
}
console.log('TRUE!');
console.log('[' + current.prev().data('date') + '] [' + thisDate + '] [' + current.next().data('date') + ']');
// do update
var list = $('tr[data-date="' + thisDate + '"]');
var submit = [];
$.each(list, function (i, v) {
var row = $(v);
var id = row.data('id');
submit.push(id);
});
$.post('/transaction/reorder',{items: submit,_token:token});
console.log(submit);
//console.log('TRUE!');
//console.log('[' + current.prev().data('date') + '] [' + thisDate + '] [' + current.next().data('date') + ']');
current.animate({
backgroundColor: "#5cb85c"
@ -95,6 +83,9 @@ function sortStop(event, ui) {
}, 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

@ -37,7 +37,7 @@
<i class="fa fa-repeat fa-fw"></i> Transactions
</div>
<div class="panel-body">
@include('list.journals-full')
@include('list.journals-full',['sorting' => false])
</div>
</div>
</div>

View File

@ -94,7 +94,7 @@
Connected transaction journals
</div>
<div class="panel-body">
@include('list.journals-full')
@include('list.journals-full',['sorting' => false])
</div>
</div>
</div>

View File

@ -8,7 +8,7 @@
{{{$subTitle}}}
</div>
<div class="panel-body">
@include('list.journals-full',['journals' => $list])
@include('list.journals-full',['journals' => $list,'sorting' => false])
</div>
</div>
</div>

View File

@ -16,7 +16,7 @@
<div class="panel-heading">
Transactions
</div>
@include('list.journals-full')
@include('list.journals-full',['sorting' => false])
</div>
</div>
<div class="col-lg-3 col-md-3 col-sm-5">

View File

@ -8,7 +8,7 @@
{{{$subTitle}}}
</div>
<div class="panel-body">
@include('list.journals-full',['journals' => $list])
@include('list.journals-full',['journals' => $list,'sorting' => false])
</div>
</div>
</div>

View File

@ -34,7 +34,7 @@
Transactions
</div>
<div class="panel-body">
@include('list.journals-full')
@include('list.journals-full',['sorting' => false])
</div>
</div>
</div>

View File

@ -32,10 +32,12 @@
<td colspan="7"><em>Invalid journal: Found {{$journal->transactions()->count()}} transaction(s)</td>
</tr>
@else
<tr class="drag" data-date="{{$journal->date->format('Y-m-d')}}">
<tr class="drag" data-date="{{$journal->date->format('Y-m-d')}}" data-id="{{$journal->id}}">
<td>
<div class="btn-group btn-group-xs">
<a href="#" class="handle btn btn-default btn-xs"><i class="fa fa-fw fa-arrows-v"></i></a>
@if($sorting === true)
<a href="#" class="handle btn btn-default btn-xs"><i class="fa fa-fw fa-arrows-v"></i></a>
@endif
<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

@ -5,7 +5,7 @@
<h4 class="modal-title">No budget bla bla.</h4>
</div>
<div class="modal-body">
@include('list.journals-full')
@include('list.journals-full',['sorting' => false])
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>

View File

@ -7,7 +7,7 @@
<div class="panel-heading">
<i class="fa {{$subTitleIcon}}"></i> {{{$subTitle}}}
</div>
@include('list.journals-full')
@include('list.journals-full',['sorting' => true])
</div>
</div>
</div>
@ -15,6 +15,9 @@
@stop
@section('scripts')
<script type="text/javascript">
var token = "{{csrf_token()}}";
</script>
<script src="js/jquery-ui.min.js" type="text/javascript"></script>
<script src="js/transactions.js" type="text/javascript"></script>