Compare commits
12 Commits
smaller-ap
...
features/s
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28e8db400a | ||
|
|
cde1ab241b | ||
|
|
cc1f9451da | ||
|
|
5d16f5d0d8 | ||
|
|
1d47e87d54 | ||
|
|
d2ab358c6a | ||
|
|
6a6c356cf3 | ||
|
|
262204568e | ||
|
|
3340d8ffcf | ||
|
|
dd3fcdf018 | ||
|
|
be404d34c5 | ||
|
|
79b9b097a8 |
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Transformers\ComponentsTransformer;
|
||||
use App\Http\Transformers\ConsumablesTransformer;
|
||||
use App\Http\Transformers\SelectlistTransformer;
|
||||
use App\Models\Company;
|
||||
@@ -209,37 +210,23 @@ class ConsumablesController extends Controller
|
||||
* @param int $consumableId
|
||||
* @return array
|
||||
*/
|
||||
public function getDataView($consumableId)
|
||||
public function checkedout($consumableId)
|
||||
{
|
||||
$consumable = Consumable::with(['consumableAssignments'=> function ($query) {
|
||||
$query->orderBy($query->getModel()->getTable().'.created_at', 'DESC');
|
||||
},
|
||||
'consumableAssignments.admin'=> function ($query) {
|
||||
},
|
||||
'consumableAssignments.user'=> function ($query) {
|
||||
},
|
||||
])->find($consumableId);
|
||||
|
||||
$consumable = Consumable::with('users')->findOrFail($consumableId);
|
||||
if (! Company::isCurrentUserHasAccess($consumable)) {
|
||||
return ['total' => 0, 'rows' => []];
|
||||
}
|
||||
$this->authorize('view', Consumable::class);
|
||||
$rows = [];
|
||||
|
||||
foreach ($consumable->consumableAssignments as $consumable_assignment) {
|
||||
$rows[] = [
|
||||
'avatar' => ($consumable_assignment->user) ? e($consumable_assignment->user->present()->gravatar) : '',
|
||||
'name' => ($consumable_assignment->user) ? $consumable_assignment->user->present()->nameUrl() : 'Deleted User',
|
||||
'created_at' => Helper::getFormattedDateObject($consumable_assignment->created_at, 'datetime'),
|
||||
'note' => ($consumable_assignment->note) ? e($consumable_assignment->note) : null,
|
||||
'admin' => ($consumable_assignment->admin) ? $consumable_assignment->admin->present()->nameUrl() : null,
|
||||
];
|
||||
$offset = request('offset', 0);
|
||||
$limit = request('limit', 50);
|
||||
|
||||
$consumables_users = $consumable->users;
|
||||
$total = $consumables_users->count();
|
||||
|
||||
if ($total < $offset) {
|
||||
$offset = 0;
|
||||
}
|
||||
|
||||
$consumableCount = $consumable->users->count();
|
||||
$data = ['total' => $consumableCount, 'rows' => $rows];
|
||||
|
||||
return $data;
|
||||
return (new ConsumablesTransformer)->transformCheckedoutConsumables($consumable, $consumables_users, $total);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -340,6 +340,7 @@ class SettingsController extends Controller
|
||||
$setting->email_format = $request->input('email_format');
|
||||
$setting->username_format = $request->input('username_format');
|
||||
$setting->require_accept_signature = $request->input('require_accept_signature');
|
||||
$setting->display_username = $request->input('display_username', 0);
|
||||
$setting->show_assigned_assets = $request->input('show_assigned_assets', '0');
|
||||
if (! config('app.lock_passwords')) {
|
||||
$setting->login_note = $request->input('login_note');
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Transformers;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Accessory;
|
||||
use App\Models\Setting;
|
||||
use Gate;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@@ -22,6 +23,7 @@ class AccessoriesTransformer
|
||||
|
||||
public function transformAccessory(Accessory $accessory)
|
||||
{
|
||||
|
||||
$array = [
|
||||
'id' => $accessory->id,
|
||||
'name' => e($accessory->name),
|
||||
@@ -66,6 +68,8 @@ class AccessoriesTransformer
|
||||
|
||||
public function transformCheckedoutAccessory($accessory, $accessory_users, $total)
|
||||
{
|
||||
$setting = Setting::getSettings();
|
||||
|
||||
$array = [];
|
||||
|
||||
foreach ($accessory_users as $user) {
|
||||
@@ -74,7 +78,7 @@ class AccessoriesTransformer
|
||||
'assigned_pivot_id' => $user->pivot->id,
|
||||
'id' => (int) $user->id,
|
||||
'username' => e($user->username),
|
||||
'name' => e($user->getFullNameAttribute()),
|
||||
'name' => ($setting->display_username == '1') ? e($user->getCompleteNameAttribute()) : e($user->getFullNameAttribute()),
|
||||
'first_name'=> e($user->first_name),
|
||||
'last_name'=> e($user->last_name),
|
||||
'employee_number' => e($user->employee_num),
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Transformers;
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Actionlog;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class ActionlogsTransformer
|
||||
@@ -113,9 +114,7 @@ class ActionlogsTransformer
|
||||
'log_meta' => ((isset($clean_meta)) && (is_array($clean_meta))) ? $clean_meta: null,
|
||||
'action_date' => ($actionlog->action_date) ? Helper::getFormattedDateObject($actionlog->action_date, 'datetime'): Helper::getFormattedDateObject($actionlog->created_at, 'datetime'),
|
||||
];
|
||||
//\Log::info("Clean Meta is: ".print_r($clean_meta,true));
|
||||
|
||||
//dd($array);
|
||||
return $array;
|
||||
}
|
||||
|
||||
@@ -126,7 +125,7 @@ class ActionlogsTransformer
|
||||
|
||||
$array = array();
|
||||
foreach ($accessories_users as $user) {
|
||||
$array[] = (new UsersTransformer)->transformUser($user);
|
||||
$array[] = (new UsersTransformer)->transformUserCompact($user);
|
||||
}
|
||||
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ class AssetsTransformer
|
||||
'image' => ($asset->getImageUrl()) ? $asset->getImageUrl() : null,
|
||||
'qr' => ($setting->qr_code=='1') ? config('app.url').'/uploads/barcodes/qr-'.str_slug($asset->asset_tag).'-'.str_slug($asset->id).'.png' : null,
|
||||
'alt_barcode' => ($setting->alt_barcode_enabled=='1') ? config('app.url').'/uploads/barcodes/'.str_slug($setting->alt_barcode).'-'.str_slug($asset->asset_tag).'.png' : null,
|
||||
'assigned_to' => $this->transformAssignedTo($asset),
|
||||
'assigned_to' => $this->transformAssignedTo($asset, $setting),
|
||||
'warranty_months' => ($asset->warranty_months > 0) ? e($asset->warranty_months.' '.trans('admin/hardware/form.months')) : null,
|
||||
'warranty_expires' => ($asset->warranty_months > 0) ? Helper::getFormattedDateObject($asset->warranty_expires, 'date') : null,
|
||||
'created_at' => Helper::getFormattedDateObject($asset->created_at, 'datetime'),
|
||||
@@ -180,19 +180,10 @@ class AssetsTransformer
|
||||
return (new DatatablesTransformer)->transformDatatables($assets);
|
||||
}
|
||||
|
||||
public function transformAssignedTo($asset)
|
||||
public function transformAssignedTo($asset, $setting)
|
||||
{
|
||||
if ($asset->checkedOutToUser()) {
|
||||
return $asset->assigned ? [
|
||||
'id' => (int) $asset->assigned->id,
|
||||
'username' => e($asset->assigned->username),
|
||||
'name' => e($asset->assigned->getFullNameAttribute()),
|
||||
'first_name'=> e($asset->assigned->first_name),
|
||||
'last_name'=> ($asset->assigned->last_name) ? e($asset->assigned->last_name) : null,
|
||||
'email'=> ($asset->assigned->email) ? e($asset->assigned->email) : null,
|
||||
'employee_number' => ($asset->assigned->employee_num) ? e($asset->assigned->employee_num) : null,
|
||||
'type' => 'user',
|
||||
] : null;
|
||||
return (new UsersTransformer)->transformUserCompact($asset->assigned);
|
||||
}
|
||||
|
||||
return $asset->assigned ? [
|
||||
|
||||
@@ -60,11 +60,11 @@ class ConsumablesTransformer
|
||||
return $array;
|
||||
}
|
||||
|
||||
public function transformCheckedoutConsumables(Collection $consumables_users, $total)
|
||||
public function transformCheckedoutConsumables(Consumable $consumable, $consumables_users, $total)
|
||||
{
|
||||
$array = [];
|
||||
foreach ($consumables_users as $user) {
|
||||
$array[] = (new UsersTransformer)->transformUser($user);
|
||||
foreach ($consumables_users as $consumables_user) {
|
||||
$array[] = (new UsersTransformer)->transformUserCompact($consumables_user);
|
||||
}
|
||||
|
||||
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Transformers;
|
||||
|
||||
use App\Models\License;
|
||||
use App\Models\LicenseSeat;
|
||||
use App\Models\Setting;
|
||||
use Gate;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
@@ -23,19 +24,12 @@ class LicenseSeatsTransformer
|
||||
|
||||
public function transformLicenseSeat(LicenseSeat $seat, $seat_count = 0)
|
||||
{
|
||||
$setting = Setting::getSettings();
|
||||
|
||||
$array = [
|
||||
'id' => (int) $seat->id,
|
||||
'license_id' => (int) $seat->license->id,
|
||||
'assigned_user' => ($seat->user) ? [
|
||||
'id' => (int) $seat->user->id,
|
||||
'name'=> e($seat->user->present()->fullName),
|
||||
'department'=> ($seat->user->department) ?
|
||||
[
|
||||
'id' => (int) $seat->user->department->id,
|
||||
'name' => e($seat->user->department->name),
|
||||
|
||||
] : null,
|
||||
] : null,
|
||||
'assigned_user' => ($seat->user) ? (new UsersTransformer)->transformUserCompact($seat->user) : null,
|
||||
'assigned_asset' => ($seat->asset) ? [
|
||||
'id' => (int) $seat->asset->id,
|
||||
'name'=> e($seat->asset->present()->fullName),
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Transformers;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Gate;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
@@ -21,6 +22,7 @@ class UsersTransformer
|
||||
|
||||
public function transformUser(User $user)
|
||||
{
|
||||
|
||||
$array = [
|
||||
'id' => (int) $user->id,
|
||||
'avatar' => e($user->present()->gravatar),
|
||||
@@ -101,6 +103,34 @@ class UsersTransformer
|
||||
return $array;
|
||||
}
|
||||
|
||||
public function transformUserCompact(User $user) {
|
||||
$setting = Setting::getSettings();
|
||||
return [
|
||||
'new' => 'yep', // remove me
|
||||
'id' => (int) $user->id,
|
||||
'avatar' => e($user->present()->gravatar),
|
||||
'username' => e($user->username),
|
||||
'name' => ($setting->display_username == '1') ? e($user->getCompleteNameAttribute()) : e($user->getFullNameAttribute()),
|
||||
'first_name'=> e($user->first_name),
|
||||
'last_name'=> ($user->last_name) ? e($user->last_name) : null,
|
||||
'email'=> ($user->email) ? e($user->email) : null,
|
||||
'employee_num' => ($user->employee_num) ? e($user->employee_num) : null,
|
||||
'manager' => ($user->manager) ? [
|
||||
'id' => (int) $user->manager->id,
|
||||
'name'=> e($user->manager->first_name).' '.e($user->manager->last_name),
|
||||
] : null,
|
||||
'department' => ($user->department) ? [
|
||||
'id' => (int) $user->department->id,
|
||||
'name'=> e($user->department->name),
|
||||
] : null,
|
||||
'location' => ($user->userloc) ? [
|
||||
'id' => (int) $user->userloc->id,
|
||||
'name'=> e($user->userloc->name),
|
||||
] : null,
|
||||
'type' => 'user',
|
||||
];
|
||||
}
|
||||
|
||||
public function transformUsersDatatable($users)
|
||||
{
|
||||
return (new DatatablesTransformer)->transformDatatables($users);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddUsernameDisplayToSettings extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('settings', function (Blueprint $table) {
|
||||
$table->boolean('display_username')->after('show_archived_in_list')->default(1)->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('settings', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('assets', 'display_username_in_list')) {
|
||||
$table->dropColumn('display_username');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -397,6 +397,8 @@ return [
|
||||
'placeholder_kit' => 'Select a kit',
|
||||
'file_not_found' => 'File not found',
|
||||
'preview_not_available' => '(no preview)',
|
||||
'display_username' => 'Display Username',
|
||||
'display_username_help_text' => 'Checking this box will cause listings to display the username in addition to the first and last name for users on listing pages.',
|
||||
'setup' => 'Setup',
|
||||
'pre_flight' => 'Pre-Flight',
|
||||
'skip_to_main_content' => 'Skip to main content',
|
||||
|
||||
@@ -327,10 +327,6 @@
|
||||
item_icon = '';
|
||||
}
|
||||
|
||||
// display the username if it's checked out to a user, but don't do it if the username's there already
|
||||
if (value.username && !value.name.match('\\(') && !value.name.match('\\)')) {
|
||||
value.name = value.name + ' (' + value.username + ')';
|
||||
}
|
||||
|
||||
return '<nobr><a href="{{ url('/') }}/' + item_destination +'/' + value.id + '" data-tooltip="true" title="' + value.type + '"><i class="' + item_icon + ' text-{{ $snipeSettings->skin!='' ? $snipeSettings->skin : 'blue' }} "></i> ' + value.name + '</a></nobr>';
|
||||
|
||||
|
||||
@@ -114,6 +114,22 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Include username in listings -->
|
||||
<div class="form-group {{ $errors->has('display_username') ? 'error' : '' }}">
|
||||
<div class="col-md-3">
|
||||
{{ Form::label('display_username',
|
||||
trans('general.display_username')) }}
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
{{ Form::checkbox('display_username', '1', Request::old('display_username', $setting->display_username),array('class' => 'minimal')) }}
|
||||
{{ trans('general.yes') }}
|
||||
{!! $errors->first('display_username', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
|
||||
<p class="help-block">{{ trans('general.display_username_help_text') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.form-group -->
|
||||
|
||||
|
||||
<!-- Load images in emails -->
|
||||
<div class="form-group {{ $errors->has('show_images_in_email') ? 'error' : '' }}">
|
||||
<div class="col-md-3">
|
||||
|
||||
@@ -283,19 +283,10 @@ Route::group(['prefix' => 'v1', 'middleware' => ['api', 'throttle:api']], functi
|
||||
Route::get('{id}/users',
|
||||
[
|
||||
Api\ConsumablesController::class,
|
||||
'getDataView'
|
||||
'checkedout'
|
||||
]
|
||||
)->name('api.consumables.showUsers');
|
||||
|
||||
|
||||
// This is LEGACY endpoint URL and should be removed in the next major release
|
||||
Route::get('view/{id}/users',
|
||||
[
|
||||
Api\ConsumablesController::class,
|
||||
'getDataView'
|
||||
]
|
||||
)->name('api.consumables.showUsers');
|
||||
|
||||
Route::post('{consumable}/checkout',
|
||||
[
|
||||
Api\ConsumablesController::class,
|
||||
|
||||
Reference in New Issue
Block a user