1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Working on status selector

This commit is contained in:
Hillel Coren 2016-11-20 16:08:36 +02:00
parent 23c098014a
commit ccecb65f58
14 changed files with 88 additions and 27 deletions

View File

@ -250,7 +250,20 @@ class AccountController extends BaseController
$filter = ''; $filter = '';
} }
Session::put("entity_filter:{$entityType}", $filter); // separate state and status filters
$filters = explode(',', $filter);
$stateFilter = [];
$statusFilter = [];
foreach ($filters as $filter) {
if (in_array($filter, \App\Models\EntityModel::$statuses)) {
$stateFilter[] = $filter;
} else {
$statusFilter[] = $filter;
}
}
Session::put("entity_state_filter:{$entityType}", join(',', $stateFilter));
Session::put("entity_status_filter:{$entityType}", join(',', $statusFilter));
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }

View File

@ -295,7 +295,7 @@ class EntityModel extends Eloquent
return false; return false;
} }
public static function getStatuses($entityType = false) public static function getStates($entityType = false)
{ {
$data = []; $data = [];
@ -305,4 +305,24 @@ class EntityModel extends Eloquent
return $data; return $data;
} }
public static function getStatuses($entityType = false)
{
return [];
}
public static function getStatesFor($entityType = false)
{
$class = static::getClassName($entityType);
return $class::getStates($entityType);
}
public static function getStatusesFor($entityType = false)
{
$class = static::getClassName($entityType);
return $class::getStatuses($entityType);
}
} }

View File

@ -214,8 +214,7 @@ class Expense extends EntityModel
public static function getStatuses($entityType = false) public static function getStatuses($entityType = false)
{ {
$statuses = parent::getStatuses($entityType); $statuses = [];
$statuses[EXPENSE_STATUS_LOGGED] = trans('texts.logged'); $statuses[EXPENSE_STATUS_LOGGED] = trans('texts.logged');
$statuses[EXPENSE_STATUS_INVOICED] = trans('texts.invoiced'); $statuses[EXPENSE_STATUS_INVOICED] = trans('texts.invoiced');
$statuses[EXPENSE_STATUS_PAID] = trans('texts.paid'); $statuses[EXPENSE_STATUS_PAID] = trans('texts.paid');

View File

@ -48,9 +48,9 @@ class ExpenseCategory extends EntityModel
return "/expense_categories/{$this->public_id}/edit"; return "/expense_categories/{$this->public_id}/edit";
} }
public static function getStatuses($entityType = false) public static function getStates($entityType = false)
{ {
$statuses = parent::getStatuses($entityType); $statuses = parent::getStates($entityType);
unset($statuses[STATUS_DELETED]); unset($statuses[STATUS_DELETED]);

View File

@ -1252,7 +1252,7 @@ class Invoice extends EntityModel implements BalanceAffecting
public static function getStatuses($entityType = false) public static function getStatuses($entityType = false)
{ {
$statuses = parent::getStatuses($entityType); $statuses = [];
if ($entityType == ENTITY_RECURRING_INVOICE) { if ($entityType == ENTITY_RECURRING_INVOICE) {
return $statuses; return $statuses;
@ -1263,6 +1263,10 @@ class Invoice extends EntityModel implements BalanceAffecting
if (in_array($status->id, [INVOICE_STATUS_PAID, INVOICE_STATUS_PARTIAL])) { if (in_array($status->id, [INVOICE_STATUS_PAID, INVOICE_STATUS_PARTIAL])) {
continue; continue;
} }
} elseif ($entityType == ENTITY_INVOICE) {
if (in_array($status->id, [INVOICE_STATUS_APPROVED])) {
continue;
}
} }
$statuses[$status->id] = trans('texts.status_' . strtolower($status->name)); $statuses[$status->id] = trans('texts.status_' . strtolower($status->name));

View File

@ -88,9 +88,9 @@ class Product extends EntityModel
return $this->belongsTo('App\Models\TaxRate'); return $this->belongsTo('App\Models\TaxRate');
} }
public static function getStatuses($entityType = false) public static function getStates($entityType = false)
{ {
$statuses = parent::getStatuses($entityType); $statuses = parent::getStates($entityType);
unset($statuses[STATUS_DELETED]); unset($statuses[STATUS_DELETED]);

View File

@ -198,8 +198,7 @@ class Task extends EntityModel
public static function getStatuses($entityType = false) public static function getStatuses($entityType = false)
{ {
$statuses = parent::getStatuses($entityType); $statuses = [];
$statuses[TASK_STATUS_LOGGED] = trans('texts.logged'); $statuses[TASK_STATUS_LOGGED] = trans('texts.logged');
$statuses[TASK_STATUS_RUNNING] = trans('texts.running'); $statuses[TASK_STATUS_RUNNING] = trans('texts.running');
$statuses[TASK_STATUS_INVOICED] = trans('texts.invoiced'); $statuses[TASK_STATUS_INVOICED] = trans('texts.invoiced');

View File

@ -120,7 +120,8 @@ class BaseRepository
{ {
$table = Utils::pluralizeEntityType($table ?: $entityType); $table = Utils::pluralizeEntityType($table ?: $entityType);
if ($filters = explode(',', session('entity_filter:' . $entityType, STATUS_ACTIVE))) { if ($filter = session('entity_state_filter:' . $entityType, STATUS_ACTIVE)) {
$filters = explode(',', $filter);
$query->where(function ($query) use ($filters, $table) { $query->where(function ($query) use ($filters, $table) {
$query->whereNull($table . '.id'); $query->whereNull($table . '.id');
@ -128,13 +129,16 @@ class BaseRepository
$query->orWhereNull($table . '.deleted_at'); $query->orWhereNull($table . '.deleted_at');
} }
if (in_array(STATUS_ARCHIVED, $filters)) { if (in_array(STATUS_ARCHIVED, $filters)) {
$query->orWhereNotNull($table . '.deleted_at'); $query->orWhere(function ($query) use ($table) {
if ( ! in_array(STATUS_DELETED, $filters) && ! in_array($table, ['products', 'expense_categories', 'users'])) { $query->whereNotNull($table . '.deleted_at')
$query->where($table . '.is_deleted', '=', 0); ->where($table . '.is_deleted', '=', 0);
} });
} }
if (in_array(STATUS_DELETED, $filters)) { if (in_array(STATUS_DELETED, $filters)) {
$query->orWhere($table . '.is_deleted', '=', 1); $query->orWhere(function ($query) use ($table) {
$query->whereNotNull($table . '.deleted_at')
->where($table . '.is_deleted', '=', 1);
});
} }
}); });
} }

View File

@ -96,8 +96,11 @@ class ExpenseRepository extends BaseRepository
$this->applyFilters($query, ENTITY_EXPENSE); $this->applyFilters($query, ENTITY_EXPENSE);
if ($statuses = explode(',', session('entity_filter:' . ENTITY_EXPENSE))) { if ($statuses = session('entity_status_filter:' . ENTITY_EXPENSE)) {
$statuses = explode(',', $statuses);
$query->where(function ($query) use ($statuses) { $query->where(function ($query) use ($statuses) {
$query->whereNull('expenses.id');
if (in_array(EXPENSE_STATUS_LOGGED, $statuses)) { if (in_array(EXPENSE_STATUS_LOGGED, $statuses)) {
$query->orWhere('expenses.invoice_id', '=', 0) $query->orWhere('expenses.invoice_id', '=', 0)
->orWhereNull('expenses.invoice_id'); ->orWhereNull('expenses.invoice_id');

View File

@ -78,7 +78,8 @@ class InvoiceRepository extends BaseRepository
$this->applyFilters($query, $entityType, ENTITY_INVOICE); $this->applyFilters($query, $entityType, ENTITY_INVOICE);
if ($statuses = explode(',', session('entity_filter:' . $entityType))) { if ($statuses = session('entity_status_filter:' . $entityType)) {
$statuses = explode(',', $statuses);
$query->where(function ($query) use ($statuses) { $query->where(function ($query) use ($statuses) {
foreach ($statuses as $status) { foreach ($statuses as $status) {
if (in_array($status, \App\Models\EntityModel::$statuses)) { if (in_array($status, \App\Models\EntityModel::$statuses)) {

View File

@ -53,7 +53,8 @@ class TaskRepository extends BaseRepository
$this->applyFilters($query, ENTITY_TASK); $this->applyFilters($query, ENTITY_TASK);
if ($statuses = explode(',', session('entity_filter:' . ENTITY_TASK))) { if ($statuses = session('entity_status_filter:' . ENTITY_TASK)) {
$statuses = explode(',', $statuses);
$query->where(function ($query) use ($statuses) { $query->where(function ($query) use ($statuses) {
if (in_array(TASK_STATUS_LOGGED, $statuses)) { if (in_array(TASK_STATUS_LOGGED, $statuses)) {
$query->orWhere('tasks.invoice_id', '=', 0) $query->orWhere('tasks.invoice_id', '=', 0)

View File

@ -2222,6 +2222,9 @@ $LANG = array(
'bluevine_weekly_draw_rate' => 'Weekly Draw Rate', 'bluevine_weekly_draw_rate' => 'Weekly Draw Rate',
'bluevine_continue' => 'Continue to BlueVine', 'bluevine_continue' => 'Continue to BlueVine',
'bluevine_completed' => 'BlueVine signup completed', 'bluevine_completed' => 'BlueVine signup completed',
'entity_state' => 'State',
); );
return $LANG; return $LANG;

View File

@ -16,7 +16,7 @@
<label for="trashed" style="font-weight:normal; margin-left: 10px;"> <label for="trashed" style="font-weight:normal; margin-left: 10px;">
<input id="trashed" type="checkbox" onclick="setTrashVisible()" <input id="trashed" type="checkbox" onclick="setTrashVisible()"
{!! Session::get('entity_filter:user') != 'active' ? 'checked' : ''!!}/> {!! trans('texts.show_archived_users')!!} {!! Session::get('entity_state_filter:user') != 'active' ? 'checked' : ''!!}/> {!! trans('texts.show_archived_users')!!}
</label> </label>
@include('partials.bulk_form', ['entityType' => ENTITY_USER]) @include('partials.bulk_form', ['entityType' => ENTITY_USER])

View File

@ -46,10 +46,24 @@
&nbsp; &nbsp;
<span id="statusWrapper" style="display:none"> <span id="statusWrapper" style="display:none">
{!! Former::multiselect('statuses') <select class="form-control" style="width: 220px" id="statuses" multiple="true">
->style('width: 220px') @if (count(\App\Models\EntityModel::getStatusesFor($entityType)))
->options(\App\Models\EntityModel::getClassName($entityType)::getStatuses($entityType)) <optgroup label="{{ trans('texts.entity_state') }}">
->raw() !!} @foreach (\App\Models\EntityModel::getStatesFor($entityType) as $key => $value)
<option value="{{ $key }}">{{ $value }}</option>
@endforeach
</optgroup>
<optgroup label="{{ trans('texts.status') }}">
@foreach (\App\Models\EntityModel::getStatusesFor($entityType) as $key => $value)
<option value="{{ $key }}">{{ $value }}</option>
@endforeach
</optgroup>
@else
@foreach (\App\Models\EntityModel::getStatesFor($entityType) as $key => $value)
<option value="{{ $key }}">{{ $value }}</option>
@endforeach
@endif
</select>
</span> </span>
<div id="top_right_buttons" class="pull-right"> <div id="top_right_buttons" class="pull-right">
@ -254,7 +268,7 @@
$('#statuses').select2({ $('#statuses').select2({
placeholder: "{{ trans('texts.status') }}", placeholder: "{{ trans('texts.status') }}",
}).val('{{ session('entity_filter:' . $entityType, STATUS_ACTIVE) }}'.split(',')) }).val('{{ session('entity_state_filter:' . $entityType, STATUS_ACTIVE) . ',' . session('entity_status_filter:' . $entityType) }}'.split(','))
.trigger('change') .trigger('change')
.on('change', function() { .on('change', function() {
var filter = $('#statuses').val(); var filter = $('#statuses').val();