public function testLostStatuslabelAdd() { $statuslabel = factory(Statuslabel::class, 'lost')->make(); $values = ['name' => $statuslabel->name]; Statuslabel::create($values); $this->tester->seeRecord('status_labels', $values); }
public function testLostStatuslabelAdd() { $statuslabel = factory(Statuslabel::class, 'lost')->make(); $values = ['name' => $statuslabel->name, 'deployable' => $statuslabel->deployable, 'pending' => $statuslabel->pending, 'archived' => $statuslabel->archived]; Statuslabel::create($values); $this->tester->seeRecord('status_labels', $values); }
public function run() { Statuslabel::truncate(); factory(Statuslabel::class, 'rtd')->create(); factory(Statuslabel::class, 'pending')->create(); factory(Statuslabel::class, 'archived')->create(); factory(Statuslabel::class, 'out_for_diagnostics')->create(); factory(Statuslabel::class, 'out_for_repair')->create(); factory(Statuslabel::class, 'broken')->create(); factory(Statuslabel::class, 'lost')->create(); }
public function getDatatable() { $statuslabels = Statuslabel::select(array('id', 'name', 'deployable', 'pending', 'archived', 'color', 'show_in_nav'))->whereNull('deleted_at'); if (Input::has('search')) { $statuslabels = $statuslabels->TextSearch(e(Input::get('search'))); } if (Input::has('offset')) { $offset = e(Input::get('offset')); } else { $offset = 0; } if (Input::has('limit')) { $limit = e(Input::get('limit')); } else { $limit = 50; } $allowed_columns = ['id', 'name']; $order = Input::get('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'created_at'; $statuslabels->orderBy($sort, $order); $statuslabelsCount = $statuslabels->count(); $statuslabels = $statuslabels->skip($offset)->take($limit)->get(); $rows = array(); foreach ($statuslabels as $statuslabel) { if ($statuslabel->deployable == 1) { $label_type = trans('admin/statuslabels/table.deployable'); } elseif ($statuslabel->pending == 1) { $label_type = trans('admin/statuslabels/table.pending'); } elseif ($statuslabel->archived == 1) { $label_type = trans('admin/statuslabels/table.archived'); } else { $label_type = trans('admin/statuslabels/table.undeployable'); } $actions = '<a href="' . route('update/statuslabel', $statuslabel->id) . '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('delete/statuslabel', $statuslabel->id) . '" data-content="' . trans('admin/statuslabels/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($statuslabel->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>'; if ($statuslabel->color != '') { $color = '<div class="pull-left" style="margin-right: 5px; height: 20px; width: 20px; background-color: ' . e($statuslabel->color) . '"></div>' . e($statuslabel->color); } else { $color = ''; } $rows[] = array('id' => e($statuslabel->id), 'type' => e($label_type), 'name' => e($statuslabel->name), 'color' => $color, 'show_in_nav' => $statuslabel->show_in_nav == '1' ? trans('general.yes') : trans('general.no'), 'actions' => $actions); } $data = array('total' => $statuslabelsCount, 'rows' => $rows); return $data; }
/** * Execute the console command. * * @return mixed */ public function handle() { if ($this->confirm("\n****************************************************\nTHIS WILL DELETE ALL OF THE DATA IN YOUR DATABASE. \nThere is NO undo. This WILL destroy ALL of your data. \n****************************************************\n\nDo you wish to continue? No backsies! [y|N]")) { if ($this->option('soft')) { Accessory::getQuery()->delete(); Asset::getQuery()->delete(); Category::getQuery()->delete(); Company::getQuery()->delete(); Component::getQuery()->delete(); Consumable::getQuery()->delete(); Depreciation::getQuery()->delete(); License::getQuery()->delete(); LicenseSeat::getQuery()->delete(); Location::getQuery()->delete(); Manufacturer::getQuery()->delete(); AssetModel::getQuery()->delete(); Statuslabel::getQuery()->delete(); Supplier::getQuery()->delete(); Group::getQuery()->delete(); DB::statement('delete from accessories_users'); DB::statement('delete from asset_logs'); DB::statement('delete from asset_maintenances'); DB::statement('delete from asset_uploads'); DB::statement('delete from consumables_users'); DB::statement('delete from custom_field_custom_fieldset'); DB::statement('delete from custom_fields'); DB::statement('delete from custom_fieldsets'); DB::statement('delete from components_assets'); DB::statement('delete from password_resets'); DB::statement('delete from requested_assets'); DB::statement('delete from requests'); DB::statement('delete from throttle'); DB::statement('delete from users_groups'); DB::statement('delete from users WHERE id!=1'); } else { \DB::statement('drop table IF EXISTS accessories_users'); \DB::statement('drop table IF EXISTS accessories'); \DB::statement('drop table IF EXISTS asset_logs'); \DB::statement('drop table IF EXISTS asset_maintenances'); \DB::statement('drop table IF EXISTS asset_uploads'); \DB::statement('drop table IF EXISTS assets'); \DB::statement('drop table IF EXISTS categories'); \DB::statement('drop table IF EXISTS companies'); \DB::statement('drop table IF EXISTS consumables_users'); \DB::statement('drop table IF EXISTS consumables'); \DB::statement('drop table IF EXISTS custom_field_custom_fieldset'); \DB::statement('drop table IF EXISTS custom_fields'); \DB::statement('drop table IF EXISTS custom_fieldsets'); \DB::statement('drop table IF EXISTS depreciations'); \DB::statement('drop table IF EXISTS groups'); \DB::statement('drop table IF EXISTS history'); \DB::statement('drop table IF EXISTS components'); \DB::statement('drop table IF EXISTS components_assets'); \DB::statement('drop table IF EXISTS license_seats'); \DB::statement('drop table IF EXISTS licenses'); \DB::statement('drop table IF EXISTS locations'); \DB::statement('drop table IF EXISTS manufacturers'); \DB::statement('drop table IF EXISTS models'); \DB::statement('drop table IF EXISTS migrations'); \DB::statement('drop table IF EXISTS password_resets'); \DB::statement('drop table IF EXISTS requested_assets'); \DB::statement('drop table IF EXISTS requests'); \DB::statement('drop table IF EXISTS settings'); \DB::statement('drop table IF EXISTS status_labels'); \DB::statement('drop table IF EXISTS suppliers'); \DB::statement('drop table IF EXISTS throttle'); \DB::statement('drop table IF EXISTS users_groups'); \DB::statement('drop table IF EXISTS users'); } } }
/** * Fetch the existing status label or create new if it doesn't exist. * * @author Daniel Melzter * @since 3.0 * @param string $asset_statuslabel_name * @return Company */ public function createOrFetchStatusLabel($asset_statuslabel_name) { if (empty($asset_statuslabel_name)) { return; } foreach ($this->status_labels as $tempstatus) { if (strcasecmp($tempstatus->name, $asset_statuslabel_name) == 0) { $this->log('A matching Status ' . $asset_statuslabel_name . ' already exists'); return $tempstatus; } } $status = new Statuslabel(); $status->name = $asset_statuslabel_name; if (!$this->option('testrun')) { if ($status->save()) { $this->status_labels->add($status); $this->log('Status ' . $asset_statuslabel_name . ' was created'); return $status; } else { $this->jsonError('Status "' . $asset_statuslabel_name . '"', $status->getErrors()); return $status; } } else { $this->status_labels->add($status); return $status; } }
/** * Execute the console command. * * @return mixed */ public function handle() { $force = $this->option('force'); if ($this->confirm("\n****************************************************\nTHIS WILL PURGE ALL SOFT-DELETED ITEMS IN YOUR SYSTEM. \nThere is NO undo. This WILL permanently destroy \nALL of your deleted data. \n****************************************************\n\nDo you wish to continue? No backsies! [y|N]") || $force == 'true') { /** * Delete assets */ $assets = Asset::whereNotNull('deleted_at')->withTrashed()->get(); $assetcount = $assets->count(); $this->info($assets->count() . ' assets purged.'); $asset_assoc = 0; $asset_maintenances = 0; foreach ($assets as $asset) { $this->info('- Asset "' . $asset->showAssetName() . '" deleted.'); $asset_assoc += $asset->assetlog()->count(); $asset->assetlog()->forceDelete(); $asset_maintenances += $asset->assetmaintenances()->count(); $asset->assetmaintenances()->forceDelete(); $asset->forceDelete(); } $this->info($asset_assoc . ' corresponding log records purged.'); $this->info($asset_maintenances . ' corresponding maintenance records purged.'); $locations = Location::whereNotNull('deleted_at')->withTrashed()->get(); $this->info($locations->count() . ' locations purged.'); foreach ($locations as $location) { $this->info('- Location "' . $location->name . '" deleted.'); $location->forceDelete(); } $accessories = Accessory::whereNotNull('deleted_at')->withTrashed()->get(); $accessory_assoc = 0; $this->info($accessories->count() . ' accessories purged.'); foreach ($accessories as $accessory) { $this->info('- Accessory "' . $accessory->name . '" deleted.'); $accessory_assoc += $accessory->assetlog()->count(); $accessory->assetlog()->forceDelete(); $accessory->forceDelete(); } $this->info($accessory_assoc . ' corresponding log records purged.'); $consumables = Consumable::whereNotNull('deleted_at')->withTrashed()->get(); $this->info($consumables->count() . ' consumables purged.'); foreach ($consumables as $consumable) { $this->info('- Consumable "' . $consumable->name . '" deleted.'); $consumable->assetlog()->forceDelete(); $consumable->forceDelete(); } $components = Component::whereNotNull('deleted_at')->withTrashed()->get(); $this->info($components->count() . ' components purged.'); foreach ($components as $component) { $this->info('- Component "' . $component->name . '" deleted.'); $component->assetlog()->forceDelete(); $component->forceDelete(); } $licenses = License::whereNotNull('deleted_at')->withTrashed()->get(); $this->info($licenses->count() . ' licenses purged.'); foreach ($licenses as $license) { $this->info('- License "' . $license->name . '" deleted.'); $license->assetlog()->forceDelete(); $license->licenseseats()->forceDelete(); $license->forceDelete(); } $models = AssetModel::whereNotNull('deleted_at')->withTrashed()->get(); $this->info($models->count() . ' asset models purged.'); foreach ($models as $model) { $this->info('- Asset Model "' . $model->name . '" deleted.'); $model->forceDelete(); } $categories = Category::whereNotNull('deleted_at')->withTrashed()->get(); $this->info($categories->count() . ' categories purged.'); foreach ($categories as $category) { $this->info('- Category "' . $category->name . '" deleted.'); $category->forceDelete(); } $suppliers = Supplier::whereNotNull('deleted_at')->withTrashed()->get(); $this->info($suppliers->count() . ' suppliers purged.'); foreach ($suppliers as $supplier) { $this->info('- Supplier "' . $supplier->name . '" deleted.'); $supplier->forceDelete(); } $users = User::whereNotNull('deleted_at')->where('show_in_list', '!=', '0')->withTrashed()->get(); $this->info($users->count() . ' users purged.'); $user_assoc = 0; foreach ($users as $user) { $this->info('- User "' . $user->username . '" deleted.'); $user_assoc += $user->userlog()->count(); $user->userlog()->forceDelete(); $user->forceDelete(); } $this->info($user_assoc . ' corresponding user log records purged.'); $manufacturers = Manufacturer::whereNotNull('deleted_at')->withTrashed()->get(); $this->info($manufacturers->count() . ' manufacturers purged.'); foreach ($manufacturers as $manufacturer) { $this->info('- Manufacturer "' . $manufacturer->name . '" deleted.'); $manufacturer->forceDelete(); } $status_labels = Statuslabel::whereNotNull('deleted_at')->withTrashed()->get(); $this->info($status_labels->count() . ' status labels purged.'); foreach ($status_labels as $status_label) { $this->info('- Status Label "' . $status_label->name . '" deleted.'); $status_label->forceDelete(); } } else { $this->info('Action canceled. Nothing was purged.'); } }
/* |-------------------------------------------------------------------------- | Admin API Routes |-------------------------------------------------------------------------- */ Route::group(['prefix' => 'api', 'middleware' => 'auth'], function () { /*---Hardware API---*/ Route::group(['prefix' => 'hardware', 'middleware' => ['web', 'auth', 'authorize:assets.view']], function () { Route::get('list/{status?}', ['as' => 'api.hardware.list', 'uses' => 'AssetsController@getDatatable']); Route::post('import', 'AssetsController@postAPIImportUpload'); }); /*---Status Label API---*/ Route::group(['prefix' => 'statuslabels', 'middleware' => ['web', 'auth', 'authorize:admin']], function () { Route::resource('/', 'StatuslabelsController'); Route::get('{statuslabelId}/deployable', function ($statuslabelId) { $statuslabel = Statuslabel::find($statuslabelId); if ($statuslabel->deployable == '1' && $statuslabel->pending != '1' && $statuslabel->archived != '1') { return '1'; } else { return '0'; } }); Route::get('list', ['as' => 'api.statuslabels.list', 'uses' => 'StatuslabelsController@getDatatable']); Route::get('assets', ['as' => 'api.statuslabels.assets', 'uses' => 'StatuslabelsController@getAssetCountByStatuslabel']); }); /*---Accessories API---*/ Route::group(['prefix' => 'accessories'], function () { Route::get('list', ['as' => 'api.accessories.list', 'uses' => 'AccessoriesController@getDatatable']); Route::get('{accessoryID}/view', ['as' => 'api.accessories.view', 'uses' => 'AccessoriesController@getDataView']); }); /*---Consumables API---*/
public static function statusLabelList() { $statuslabel_list = array('' => trans('general.select_statuslabel')) + Statuslabel::orderBy('name', 'asc')->pluck('name', 'id')->toArray(); return $statuslabel_list; }
</a> </li> @endcan @can('assets.view') <li class="treeview{{ (Request::is('hardware*') ? ' active' : '') }}"> <a href="#"><i class="fa fa-barcode"></i> <span>{{ trans('general.assets') }}</span> <i class="fa fa-angle-left pull-right"></i> </a> <ul class="treeview-menu"> <li> <a href="{{ URL::to('hardware') }}">@lang('general.list_all')</a> </li> <?php $status_navs = \App\Models\Statuslabel::where('show_in_nav', '=', 1)->get(); ?> @if (count($status_navs) > 0) <li class="divider"> </li> @foreach ($status_navs as $status_nav) <li><a href="{{ URL::to('hardware?status_id='.$status_nav->id) }}"}> {{ $status_nav->name }}</a></li> @endforeach @endif <li{!! (Request::query('status') == 'Deployed' ? ' class="active"' : '') !!}> <a href="{{ URL::to('hardware?status=Deployed') }}">@lang('general.deployed') </a> </li> <li{!! (Request::query('status') == 'RTD' ? ' class="active"' : '') !!}> <a href="{{ URL::to('hardware?status=RTD') }}">