Skip to content

Commit 1331b11

Browse files
committed
Merge branch 'master' into fixing-upload-multiple-column
2 parents 8ff23e5 + 5949095 commit 1331b11

File tree

12 files changed

+69
-37
lines changed

12 files changed

+69
-37
lines changed

src/app/Library/CrudPanel/CrudFilter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,12 @@ public function label($value)
280280
* For example, the dropdown, select2 and select2 filters let the user select
281281
* pre-determined values to filter with. This is how to set those values that will be picked up.
282282
*
283-
* @param array $value Key-value array with values for the user to pick from.
283+
* @param array|function $value Key-value array with values for the user to pick from, or a function which also return a Key-value array.
284284
* @return CrudFilter
285285
*/
286286
public function values($value)
287287
{
288-
$this->values = $value;
288+
$this->values = (! is_string($value) && is_callable($value)) ? $value() : $value;
289289

290290
return $this->save();
291291
}

src/app/Library/CrudPanel/Traits/Columns.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ public function makeSureColumnHasNeededAttributes($column)
366366
$column = $this->makeSureColumnHasLabel($column);
367367
$column = $this->makeSureColumnHasType($column);
368368
$column = $this->makeSureColumnHasKey($column);
369+
$column = $this->makeSureColumnHasPriority($column);
369370
$column = $this->makeSureColumnHasModel($column);
370371

371372
// check if the column exists in the database (as a db column)
@@ -387,6 +388,21 @@ public function makeSureColumnHasNeededAttributes($column)
387388
return $column;
388389
}
389390

391+
/**
392+
* Count the number of columns added so far.
393+
*
394+
* It will not take into account the action
395+
* columns (columns with buttons, checkbox).
396+
*
397+
* @return int
398+
*/
399+
public function countColumnsWithoutActions()
400+
{
401+
return collect($this->columns())->filter(function ($column, $key) {
402+
return ! isset($column['hasActions']) || $column['hasActions'] == false;
403+
})->count();
404+
}
405+
390406
/**
391407
* Create and return a CrudColumn object for that column name.
392408
*

src/app/Library/CrudPanel/Traits/ColumnsProtectedMethods.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,22 @@ protected function addColumnToOperationSettings($column)
1818
$allColumns = Arr::add($allColumns, $column['key'], $column);
1919

2020
$this->setOperationSetting('columns', $allColumns);
21+
}
2122

22-
// make sure the column has a priority in terms of visibility
23-
// if no priority has been defined, use the order in the array plus one
24-
if (! array_key_exists('priority', $column)) {
25-
$position_in_columns_array = (int) array_search($column['key'], array_keys($this->columns()));
26-
$allColumns[$column['key']]['priority'] = $position_in_columns_array + 1;
27-
}
23+
/**
24+
* If a column priority has not been defined, provide a default one.
25+
*
26+
* @param array $column Column definition array.
27+
* @return array Proper array defining the column.
28+
*/
29+
protected function makeSureColumnHasPriority($column)
30+
{
31+
$columns_count = $this->countColumnsWithoutActions();
32+
$assumed_priority = $columns_count ? $columns_count : 0;
2833

29-
$this->setOperationSetting('columns', $allColumns);
34+
$column['priority'] = $column['priority'] ?? $assumed_priority;
35+
36+
return $column;
3037
}
3138

3239
/**

src/app/Library/CrudPanel/Traits/Read.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,26 +143,28 @@ public function enableBulkActions()
143143
'type' => 'checkbox',
144144
'name' => 'bulk_actions',
145145
'label' => ' <input type="checkbox" class="crud_bulk_actions_main_checkbox" style="width: 16px; height: 16px;" />',
146-
'priority' => 1,
146+
'priority' => 0,
147147
'searchLogic' => false,
148148
'orderable' => false,
149149
'visibleInTable' => true,
150150
'visibleInModal' => false,
151151
'visibleInExport' => false,
152152
'visibleInShow' => false,
153+
'hasActions' => true,
153154
])->makeFirstColumn();
154155

155156
$this->addColumn([
156157
'type' => 'custom_html',
157158
'name' => 'blank_first_column',
158159
'label' => ' ',
159-
'priority' => 1,
160+
'priority' => 0,
160161
'searchLogic' => false,
161162
'orderable' => false,
162163
'visibleInTabel' => true,
163164
'visibleInModal' => false,
164165
'visibleInExport' => false,
165166
'visibleInShow' => false,
167+
'hasActions' => true,
166168
])->makeFirstColumn();
167169
}
168170

src/public/packages/backpack/crud/css/list.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
}
5555

5656
/* DataTables Loading State Visual Improvements */
57-
57+
table.dataTable.dtr-inline.collapsed>tbody>tr[role="row"]>td.dtr-control:before,
58+
table.dataTable.dtr-inline.collapsed>tbody>tr[role="row"]>th.dtr-control:before,
5859
#crudTable.dataTable.dtr-inline.collapsed>tbody>tr[role="row"]>td:first-child:before,
5960
#crudTable.dataTable.dtr-inline.collapsed>tbody>tr[role="row"]>th:first-child:before {
6061
background-color: transparent;

src/resources/views/crud/columns/text.blade.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
66
$column['escaped'] = $column['escaped'] ?? true;
77
$column['limit'] = $column['limit'] ?? 40;
8-
$column['text'] = Str::limit($value, $column['limit'], '[...]');
8+
$column['prefix'] = $column['prefix'] ?? '';
9+
$column['suffix'] = $column['suffix'] ?? '';
10+
$column['text'] = $column['prefix'].Str::limit($value, $column['limit'], '[...]').$column['suffix'];
911
@endphp
1012

1113
<span>

src/resources/views/crud/create.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<small>{!! $crud->getSubheading() ?? trans('backpack::crud.add').' '.$crud->entity_name !!}.</small>
1919

2020
@if ($crud->hasAccess('list'))
21-
<small><a href="{{ url($crud->route) }}" class="hidden-print font-sm"><i class="la la-angle-double-{{ config('backpack.base.html_direction') == 'rtl' ? 'right' : 'left' }}"></i> {{ trans('backpack::crud.back_to_all') }} <span>{{ $crud->entity_name_plural }}</span></a></small>
21+
<small><a href="{{ url($crud->route) }}" class="d-print-none font-sm"><i class="la la-angle-double-{{ config('backpack.base.html_direction') == 'rtl' ? 'right' : 'left' }}"></i> {{ trans('backpack::crud.back_to_all') }} <span>{{ $crud->entity_name_plural }}</span></a></small>
2222
@endif
2323
</h2>
2424
</section>

src/resources/views/crud/edit.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<small>{!! $crud->getSubheading() ?? trans('backpack::crud.edit').' '.$crud->entity_name !!}.</small>
1919

2020
@if ($crud->hasAccess('list'))
21-
<small><a href="{{ url($crud->route) }}" class="hidden-print font-sm"><i class="la la-angle-double-{{ config('backpack.base.html_direction') == 'rtl' ? 'right' : 'left' }}"></i> {{ trans('backpack::crud.back_to_all') }} <span>{{ $crud->entity_name_plural }}</span></a></small>
21+
<small><a href="{{ url($crud->route) }}" class="d-print-none font-sm"><i class="la la-angle-double-{{ config('backpack.base.html_direction') == 'rtl' ? 'right' : 'left' }}"></i> {{ trans('backpack::crud.back_to_all') }} <span>{{ $crud->entity_name_plural }}</span></a></small>
2222
@endif
2323
</h2>
2424
</section>

src/resources/views/crud/inc/datatables_logic.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ functionsToRunOnDataTablesDrawEvent: [],
209209
"type": "POST"
210210
},
211211
dom:
212-
"<'row hidden'<'col-sm-6 hidden-xs'i><'col-sm-6 hidden-print'f>>" +
212+
"<'row hidden'<'col-sm-6'i><'col-sm-6 d-print-none'f>>" +
213213
"<'row'<'col-sm-12'tr>>" +
214-
"<'row mt-2 '<'col-sm-6 col-md-4'l><'col-sm-2 col-md-4 text-center'B><'col-sm-6 col-md-4 hidden-print'p>>",
214+
"<'row mt-2 d-print-none '<'col-sm-12 col-md-4'l><'col-sm-0 col-md-4 text-center'B><'col-sm-12 col-md-4 'p>>",
215215
}
216216
}
217217
</script>

src/resources/views/crud/inc/export_buttons.blade.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ function moveExportButtonsToTopRight() {
111111
}
112112
})
113113
$(".dt-buttons").appendTo($('#datatable_button_stack' ));
114-
$('.dt-buttons').css('display', 'inline-block');
114+
$('.dt-buttons').addClass('d-xs-block')
115+
.addClass('d-sm-inline-block')
116+
.addClass('d-md-inline-block')
117+
.addClass('d-lg-inline-block');
115118
}
116119
117120
crud.addFunctionToDataTablesDrawEventQueue('moveExportButtonsToTopRight');

0 commit comments

Comments
 (0)