Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/Http/Controllers/Api/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2007,6 +2007,7 @@ public function getLabels(Request $request): JsonResponse
// bulkedit=false and count=0 are default values for label generation
$label = $label->with('assets', $assets)
->with('settings', $settings)
->with('offset', max(0, (int) $request->input('offset', 0)))
->with('bulkedit', false)
->with('count', 0);

Expand Down
31 changes: 31 additions & 0 deletions app/Http/Controllers/Assets/BulkAssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,12 @@ public function edit(Request $request): View|RedirectResponse
switch ($request->input('bulk_actions')) {
case 'labels':
$this->authorize('view', Asset::class);
$offset = max(0, (int) $request->input('offset', 0));

return (new Label)
->with('assets', $assets)
->with('settings', Setting::getSettings())
->with('offset', $offset)
->with('bulkedit', true)
->with('count', 0);

Expand Down Expand Up @@ -923,6 +925,35 @@ public function storeCheckin(Request $request): RedirectResponse
->withErrors($errors);
}

/**
* Show Bulk Label Generator Page
*/
public function showLabels(): View
{
$this->authorize('view', Asset::class);
return view('hardware/bulk-labels', [
]);
}

/**
* Process Bulk Label Generator request
*/
public function printLabels(Request $request): View|RedirectResponse
{
$this->authorize('view', Asset::class);
$assets = collect($request->input('selected_assets'))->map(function($id) {
return Asset::find($id);
});

$offset = $request->input('labels_offset');
return (new Label)
->with('assets', $assets)
->with('settings', Setting::getSettings())
->with('offset', $offset)
->with('bulkedit', true)
->with('count', 0);
}

public function restore(Request $request): RedirectResponse
{
// Restore is a delete-level action across the codebase. The bulk
Expand Down
3 changes: 3 additions & 0 deletions resources/lang/en-US/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
'bulk_delete' => 'Bulk Delete',
'bulk_restore' => 'Bulk Restore',
'bulk_actions' => 'Bulk Actions',
'bulk_labels' => 'Bulk Label Generator',
'bulk_checkin_delete' => 'Bulk Checkin / Delete Users',
'byod' => 'BYOD',
'byod_help' => 'This device is owned by the user',
Expand Down Expand Up @@ -194,6 +195,8 @@
'import_type' => 'CSV import type',
'insufficient_permissions' => 'Insufficient permissions!',
'kits' => 'Predefined Kits',
'labels_offset' => 'Labels Offset',
'labels_offset_info' => 'Number of labels to skip when generating the print sheet',
'language' => 'Language',
'last' => 'Last',
'last_login' => 'Last Login',
Expand Down
16 changes: 16 additions & 0 deletions resources/views/blade/table/bulk-assets.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ class="form-inline"
@endif
</select>

<label for="table-label-offset" class="js-label-offset-toggle" style="margin-left: 8px; margin-right: 6px;">
{{trans('general.labels_offset')}}
</label>
<input
id="table-label-offset"
type="number"
name="offset"
class="form-control js-label-offset js-label-offset-toggle"
value="0"
min="0"
step="1"
style="width: 120px;"
aria-label="label offset"
title="{{ trans('general.labels_offset_info') }}"
>

<button class="btn btn-theme" id="{{ Illuminate\Support\Str::camel($name) }}Button" disabled>{{ trans('button.go') }}</button>
</label>
</div>
Expand Down
72 changes: 72 additions & 0 deletions resources/views/hardware/bulk-labels.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
@extends('layouts/default')

{{-- Page title --}}
@section('title')
{{ trans('general.bulk_labels') }}
@parent
@stop

{{-- Page content --}}
@section('content')

<style>
.input-group {
padding-left: 0px !important;
}
</style>

<x-container columns="2">
<x-page-column class="col-md-7">

<x-form id="checkout_form" route="{{ url()->current() }}" data-disable-empty-on-submit data-autofocus-select2-search>

<x-box header="{{ trans('general.bulk_labels') }}">

@include ('partials.forms.edit.asset-select', [
'translated_name' => trans('general.assets'),
'fieldname' => 'selected_assets[]',
'multiple' => true,
'required' => true,
'select_id' => 'assigned_assets_select',
'asset_selector_div_id' => 'assets_to_checkout_div',
'asset_ids' => old('selected_assets'),
])


<x-form.row
:label="trans('general.labels_offset')"
name="labels_offset"
>
<x-slot:input>
<input
class="form-control"
name="labels_offset"
id="labels_offset"
type="number"
:title="{{trans('general.labels_offset_info')}}"
value="0"
step="1"
min="0"
input_div_class="col-md-4"
/>
</x-slot:input>
</x-form.row>


<x-slot:customfooter>
<div class="box-footer">
<a class="btn btn-link" href="{{ URL::previous() }}">{{ trans('button.cancel') }}</a>
<button type="submit" class="btn btn-primary pull-right"><x-icon type="checkmark"/> {{ trans('general.generate_labels') }}</button>
</div>
</x-slot:customfooter>

</x-box>

</x-form>

</x-page-column>


</x-container>
@stop

15 changes: 15 additions & 0 deletions resources/views/hardware/labels.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
$settings->labels_height = $settings->labels_height - $settings->labels_display_bgutter;
// Leave space on bottom for 1D barcode if necessary
$qr_size = ($settings->alt_barcode_enabled=='1') && ($settings->label2_1d_type!='') ? $settings->labels_height - .3 : $settings->labels_height - 0.1;
$offset = max(0, (int) ($offset ?? 0));
$count = (int) ($count ?? 0);
$total_labels = (count($assets) + $offset);
?>

<style>
Expand Down Expand Up @@ -106,6 +109,18 @@
@endif
</style>


@for ($i = 0; $i < $offset; $i++)
<?php $count++; ?>
<div class="label"></div>

@if (($count % $settings->labels_per_page == 0) && $count!=$total_labels)
<div class="page-break"></div>
<div class="next-padding">&nbsp;</div>
@endif
@endfor


@foreach ($assets as $asset)
<?php $count++; ?>
<div class="label">
Expand Down
8 changes: 8 additions & 0 deletions resources/views/layouts/default.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,14 @@ class-name collides with the library's timepicker separator td. */
</li>
@endcan

@can('admin')
<li id="bulk-labels-sidenav-option" {!! (request()->is('hardware/bulklabels') ? ' class="active" aria-current="page"' : '') !!}>
<a href="{{ url('hardware/bulklabels') }}">
{{ trans('general.bulk_labels') }}
</a>
</li>
@endcan

</ul>
</li>
@endcan
Expand Down
17 changes: 17 additions & 0 deletions resources/views/partials/asset-bulk-actions.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ class="form-inline"
@endif
</select>

<label for="asset-label-offset" class="js-label-offset-toggle" style="margin-left: 8px; margin-right: 6px;">
{{trans('general.labels_offset')}}
</label>
<input
id="asset-label-offset"
type="number"
name="offset"
class="form-control js-label-offset js-label-offset-toggle"
value="0"
min="0"
step="1"
style="width: 120px;"
aria-label="label offset"
title="{{ trans('general.labels_offset_info') }}"
>


<button class="btn btn-theme" id="{{ (isset($id_button)) ? $id_button : 'bulkAssetEditButton' }}" disabled>{{ trans('button.go') }}</button>
</form>
</div>
22 changes: 22 additions & 0 deletions resources/views/partials/bootstrap-table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -1997,7 +1997,29 @@ function updateSelectedCount(table) {
domnode.elements.order.value = order;
}
});


function updateLabelOffsetInputState($form) {
var action = $form.find('select[name="bulk_actions"]').val();
var $offsetInput = $form.find('.js-label-offset');
var $offsetToggles = $form.find('.js-label-offset-toggle');

if ($offsetInput.length === 0) {
return;
}

var enabled = action === 'labels';
$offsetInput.prop('disabled', !enabled);
$offsetToggles.toggle(enabled);
}

$(document).on('change', 'form select[name="bulk_actions"]', function () {
updateLabelOffsetInputState($(this).closest('form'));
});

$('form').each(function () {
updateLabelOffsetInputState($(this));
});

// This specifies the footer columns that should have special styles associated
// (usually numbers)
Expand Down
9 changes: 9 additions & 0 deletions routes/web/hardware.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,15 @@ function () {
[BulkAssetsController::class, 'storeCheckin']
)->name('hardware.bulkcheckin.store');

Route::get('bulklabels', [BulkAssetsController::class, 'showLabels'])
->name('hardware.bulk_labels.show')
->breadcrumbs(fn (Trail $trail) => $trail->parent('hardware.index')
->push(trans('general.bulk_labels'), route('hardware.index'))
);

Route::post('bulklabels',
[BulkAssetsController::class, 'printLabels']
)->name('hardware.bulk_labels.print');
});

Route::resource('hardware',
Expand Down
Loading