diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 180a51f7ae..3381df3822 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -263,6 +263,61 @@ class AssetsController extends Controller return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.does_not_exist')), 200); } + /** + * Display a formatted JSON response for the select2 menus + * + * @todo: create a transformer for handling these responses + * @author [A. Gianotto] [] + * @since [v4.0] + * + * @return \Illuminate\Http\Response + */ + public function selectlist(Request $request) + { + $this->authorize('view', Asset::class); + + $assets = Company::scopeCompanyables(Asset::select([ + 'assets.id', + 'assets.name', + 'assets.asset_tag', + 'assets.model_id', + ]))->with('model')->RTD(); + + + if ($request->has('search')) { + $assets = $assets->where('assets.name', 'LIKE', '%'.$request->get('search').'%') + ->orWhere('assets.asset_tag', 'LIKE', '%'.$request->get('search').'%') + ->join('models AS assets_models',function ($join) use ($request) { + $join->on('assets_models.id', "=", "assets.model_id"); + })->orWhere('assets_models.name','LIKE','%'.$request->get('search').'%'); + } + + $assets = $assets->paginate(50); + $assets_array = []; + + foreach ($assets as $asset) { + $assets_array[] = + [ + 'id' => (int) $asset->id, + 'text' => e($asset->present()->fullName), + 'image' => ($asset->getImageUrl()) ? $asset->getImageUrl() : null, + ]; + } + $results = [ + 'items' => $assets_array, + 'pagination' => + [ + 'more' => ($assets->currentPage() >= $assets->lastPage()) ? false : true, + 'per_page' => $assets->perPage() + ], + 'total_count' => $assets->total(), + 'page' => $assets->currentPage(), + 'page_count' => $assets->lastPage() + ]; + + return $results; + } + /** * Accepts a POST request to create a new asset diff --git a/app/Http/Controllers/Api/LocationsController.php b/app/Http/Controllers/Api/LocationsController.php index ae4ad5eb7c..60bcd1de61 100644 --- a/app/Http/Controllers/Api/LocationsController.php +++ b/app/Http/Controllers/Api/LocationsController.php @@ -139,4 +139,55 @@ class LocationsController extends Controller $location->delete(); return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/locations/message.delete.success'))); } + + /** + * Display a formatted JSON response for the select2 menus + * + * @todo: create a transformer for handling these responses + * @author [A. Gianotto] [] + * @since [v4.0] + * + * @return \Illuminate\Http\Response + */ + public function selectlist(Request $request) + { + $this->authorize('view', Location::class); + + $locations = Location::select([ + 'locations.id', + 'locations.name', + 'locations.image', + ]); + + + if ($request->has('search')) { + $locations = $locations->where('locations.name', 'LIKE', '%'.$request->get('search').'%'); + } + + $locations = $locations->paginate(50); + $locations_array = []; + + foreach ($locations as $location) { + $locations_array[] = + [ + 'id' => (int) $location->id, + 'text' => e($location->name), + 'image' => ($location->image) ? url('/').'/uploads/locations/'.$location->image : null, + ]; + } + $results = [ + 'items' => $locations_array, + 'pagination' => + [ + 'more' => ($locations->currentPage() >= $locations->lastPage()) ? false : true, + 'per_page' => $locations->perPage() + ], + 'total_count' => $locations->total(), + 'page' => $locations->currentPage(), + 'page_count' => $locations->lastPage() + ]; + + return $results; + } + } diff --git a/app/Presenters/AssetPresenter.php b/app/Presenters/AssetPresenter.php index 42d4e92b1d..d685dab938 100644 --- a/app/Presenters/AssetPresenter.php +++ b/app/Presenters/AssetPresenter.php @@ -273,14 +273,16 @@ class AssetPresenter extends Presenter **/ public function name() { - if (empty($this->name)) { - if (isset($this->model)) { - return $this->model->name.' ('.$this->asset_tag.')'; + + if (empty($this->model->name)) { + if (isset($this->model->model)) { + return $this->model->model->name.' ('.$this->model->asset_tag.')'; } - return $this->asset_tag; + return $this->model->asset_tag; } else { - return $this->name.' ('.$this->asset_tag.')'; + return $this->model->name . ' (' . $this->model->asset_tag . ')'; } + } /** @@ -289,7 +291,18 @@ class AssetPresenter extends Presenter */ public function fullName() { - return $this->name(); + $str = ''; + if ($this->model->name) { + $str .= $this->name; + } + + if ($this->asset_tag) { + $str .= ' ('.$this->model->asset_tag.')'; + } + if ($this->model->model) { + $str .= ' - '.$this->model->model->name; + } + return $str; } /** * Returns the date this item hits EOL. diff --git a/public/css/AdminLTE.css b/public/css/AdminLTE.css index dd3eb5e016..9219746bcf 100755 Binary files a/public/css/AdminLTE.css and b/public/css/AdminLTE.css differ diff --git a/public/css/app.css b/public/css/app.css index 89a60fedb2..77b31b0671 100644 Binary files a/public/css/app.css and b/public/css/app.css differ diff --git a/public/css/build/all.css b/public/css/build/all.css index b2c93cb859..d8b0975bc0 100644 Binary files a/public/css/build/all.css and b/public/css/build/all.css differ diff --git a/public/css/dist/all.css b/public/css/dist/all.css index b2c93cb859..d8b0975bc0 100644 Binary files a/public/css/dist/all.css and b/public/css/dist/all.css differ diff --git a/public/css/overrides.css b/public/css/overrides.css index 4db8c5ee3b..a5294436d3 100644 Binary files a/public/css/overrides.css and b/public/css/overrides.css differ diff --git a/public/js/build/all.js b/public/js/build/all.js index 77b01e8123..118e2e4dd1 100644 Binary files a/public/js/build/all.js and b/public/js/build/all.js differ diff --git a/public/js/build/vue.js b/public/js/build/vue.js index 0ea1a765e0..1bc38465da 100644 Binary files a/public/js/build/vue.js and b/public/js/build/vue.js differ diff --git a/public/js/dist/all.js b/public/js/dist/all.js index 77b01e8123..118e2e4dd1 100644 Binary files a/public/js/dist/all.js and b/public/js/dist/all.js differ diff --git a/public/mix-manifest.json b/public/mix-manifest.json index 0d1c1b7ee3..529fe35864 100644 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -1,14 +1,10 @@ { - "/js/build/vue.js": "/js/build/vue.js?id=e6804371942215bd1d7d", - "/css/AdminLTE.css": "/css/AdminLTE.css?id=b8be19a285eaf44eec37", - "/css/app.css": "/css/app.css?id=407edb63cc6b6dc62405", - "/css/overrides.css": "/css/overrides.css?id=9ae1a3c861441320c5a1", - "/js/build/vue.js.map": "/js/build/vue.js.map?id=3b3d417664a61dcce3e9", - "/css/AdminLTE.css.map": "/css/AdminLTE.css.map?id=99f5a5a03c4155cf69f6", - "/css/app.css.map": "/css/app.css.map?id=bdbe05e6ecd70ccfac72", - "/css/overrides.css.map": "/css/overrides.css.map?id=898c91d4a425b01b589b", - "/css/dist/all.css": "/css/dist/all.css?id=7c3842d2639193ac7e88", - "/js/dist/all.js": "/js/dist/all.js?id=f14abfc2506d42ffb0f5", - "/css/build/all.css": "/css/build/all.css?id=7c3842d2639193ac7e88", - "/js/build/all.js": "/js/build/all.js?id=f14abfc2506d42ffb0f5" + "/js/build/vue.js": "/js/build/vue.js?id=e9504cad01a748f9b0fa", + "/css/AdminLTE.css": "/css/AdminLTE.css?id=889dc040f2ddfca6efde", + "/css/app.css": "/css/app.css?id=3a1e8c168fa8714043a6", + "/css/overrides.css": "/css/overrides.css?id=3911514a8a64a4247483", + "/css/dist/all.css": "/css/dist/all.css?id=f2d4896e67e878a47434", + "/js/dist/all.js": "/js/dist/all.js?id=b967aad5fdaca0a91359", + "/css/build/all.css": "/css/build/all.css?id=f2d4896e67e878a47434", + "/js/build/all.js": "/js/build/all.js?id=b967aad5fdaca0a91359" } \ No newline at end of file diff --git a/resources/assets/js/snipeit.js b/resources/assets/js/snipeit.js index 1d4d3d99b6..bad715b012 100755 --- a/resources/assets/js/snipeit.js +++ b/resources/assets/js/snipeit.js @@ -180,14 +180,78 @@ $(document).ready(function () { } $('.datepicker').datepicker(); - $(document).ready(function() { - $("#toggle_nav").toggle(function() { + var datepicker = $.fn.datepicker.noConflict(); // return $.fn.datepicker to previously assigned value + $.fn.bootstrapDP = datepicker; + $('.datepicker').datepicker(); + + // Crazy select2 rich dropdowns with images! + $('.js-data-ajax').each( function (i,item) { + var link = $(item); + var endpoint = link.data("endpoint"); + var select = link.data("select"); + + link.select2({ + + ajax: { + url: baseUrl + '/api/v1/' + endpoint + '/selectlist', + dataType: 'json', + delay: 250, + headers: { + "X-Requested-With": 'XMLHttpRequest', + "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content') + }, + data: function (params) { + var data = { + search: params.term, + page: params.page || 1 + }; + return data; + }, + processResults: function (data, params) { + + params.page = params.page || 1; + + var answer = { + results: data.items, + pagination: { + more: "true" //(params.page < data.page_count) + } + }; + + return answer; + }, + cache: true + }, + escapeMarkup: function (markup) { return markup; }, // let our custom formatter work + templateResult: formatDatalist, + templateSelection: formatDataSelection }); + }); + function formatDatalist (datalist) { + var loading_markup = ' Loading...'; + if (datalist.loading) { + return loading_markup; + } + var markup = "
" ; + markup +="
"; + if (datalist.image) { + markup += ""; + } else { + markup += "
"; + } + markup += "
" + datalist.text + "
"; + markup += "
"; + return markup; + } + + function formatDataSelection (datalist) { + return datalist.text; + } diff --git a/resources/assets/js/snipeit_modals.js b/resources/assets/js/snipeit_modals.js index 3aefffb894..8863a45216 100644 --- a/resources/assets/js/snipeit_modals.js +++ b/resources/assets/js/snipeit_modals.js @@ -95,10 +95,14 @@ // clicked 'add' on to add a new 'thing' // this code adds the newly created object to that select var selector = document.getElementById(select); + console.warn("The selector we should've selecte dis: "+select); + console.dir(selector); if(!selector) { return false; } + console.warn("onChange Selector Thing should've activated? Here's the selector"); + console.dir(selector); selector.options[selector.length] = new Option(name, id); selector.selectedIndex = selector.length - 1; $(selector).trigger("change"); diff --git a/resources/views/hardware/checkout.blade.php b/resources/views/hardware/checkout.blade.php index 3bd46d985c..f82e12b908 100755 --- a/resources/views/hardware/checkout.blade.php +++ b/resources/views/hardware/checkout.blade.php @@ -47,45 +47,58 @@ -
- - - +
{{ Form::label('assigned_user', trans('admin/hardware/form.checkout_to'), array('class' => 'col-md-3 control-label')) }}
-
- {!! $errors->first('assigned_user', ' :message') !!} -
@can('create', \App\Models\User::class) New @endcan
-
- @if (!$asset->requireAcceptance()) - -
- {{ Form::label('assigned_asset', trans('admin/hardware/form.checkout_to'), array('class' => 'col-md-3 control-label')) }} -
- {{ Form::select('assigned_asset', $assets_list , Input::old('assigned_asset', $asset->assigned_type == 'App\Models\Asset' ? $asset->assigned_to : 0), array('class'=>'select2', 'id'=>'assigned_asset', 'style'=>'width:100%')) }} - {!! $errors->first('assigned_asset', ' :message') !!} -
-
- -
- {{ Form::label('assigned_location', trans('admin/hardware/form.checkout_to'), array('class' => 'col-md-3 control-label')) }} -
- {{ Form::select('assigned_location', $locations_list , Input::old('assigned_location', $asset->assigned_type == 'App\Models\Asset' ? $asset->assigned_to : 0), array('class'=>'select2', 'id'=>'assigned_location', 'style'=>'width:100%')) }} - {!! $errors->first('assigned_location', ' :message') !!} -
-
+ {!! $errors->first('assigned_user', '
:message
') !!} + +
+ + @if (!$asset->requireAcceptance()) + + +
+ {{ Form::label('assigned_asset', trans('admin/hardware/form.checkout_to'), array('class' => 'col-md-3 control-label')) }} +
+ +
+ {!! $errors->first('assigned_asset', '
:message
') !!} + +
+ + +
+ {{ Form::label('assigned_location', trans('admin/hardware/form.checkout_to'), array('class' => 'col-md-3 control-label')) }} +
+ +
+ +
+ @can('create', \App\Models\Location::class) + New + @endcan +
+ + {!! $errors->first('assigned_location', '
:message
') !!} + +
@endif
@@ -164,9 +177,12 @@ @section('moar_scripts') - - - - @section('moar_scripts') @show diff --git a/routes/api.php b/routes/api.php index 176c905695..0d72b78001 100644 --- a/routes/api.php +++ b/routes/api.php @@ -226,6 +226,12 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () { Route::group(['prefix' => 'hardware'], function () { + Route::get( 'selectlist', [ + 'as' => 'assets.selectlist', + 'uses' => 'AssetsController@selectlist' + ]); + + Route::post('audit', [ 'as' => 'api.asset.audit', 'uses' => 'AssetsController@audit' @@ -331,21 +337,6 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () { /*--- Locations API ---*/ - Route::resource('locations', 'LocationsController', - [ - 'names' => - [ - 'index' => 'api.locations.index', - 'show' => 'api.locations.show', - 'store' => 'api.locations.store', - 'update' => 'api.locations.update', - 'destroy' => 'api.locations.destroy' - ], - 'except' => ['create', 'edit'], - 'parameters' => ['location' => 'location_id'] - ] - ); // Locations resource - Route::group(['prefix' => 'locations'], function () { Route::get('{location}/users', @@ -369,9 +360,33 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () { 'uses' => 'LocationsController@show' ] ); + + Route::get( 'selectlist', [ + 'as' => 'locations.selectlist', + 'uses' => 'LocationsController@selectlist' + ]); }); // Locations group + + Route::resource('locations', 'LocationsController', + [ + 'names' => + [ + 'index' => 'api.locations.index', + 'show' => 'api.locations.show', + 'store' => 'api.locations.store', + 'update' => 'api.locations.update', + 'destroy' => 'api.locations.destroy' + ], + 'except' => ['create', 'edit'], + 'parameters' => ['location' => 'location_id'] + ] + ); // Locations resource + + + + /*--- Manufacturers API ---*/ Route::resource('manufacturers', 'ManufacturersController',