Skip to content

A free open source IT asset/license management system

New save mechanic

Minaev Dmitriy9d5cd2757546
diff --git a/app/Http/Controllers/Api/PredefinedKitsController.php b/app/Http/Controllers/Api/PredefinedKitsController.php
index 72b99aa973..03740bfc33 100644
--- a/app/Http/Controllers/Api/PredefinedKitsController.php
+++ b/app/Http/Controllers/Api/PredefinedKitsController.php
@@ -36,7 +36,7 @@ class PredefinedKitsController extends Controller
$total = $kits->count();
$kits = $kits->skip($offset)->take($limit)->get();
- return (new PredefinedKitsTransformer)->transformPrdefinedKits($kits, $total);
+ return (new PredefinedKitsTransformer)->transformPredefinedKits($kits, $total);
}
@@ -74,7 +74,7 @@ class PredefinedKitsController extends Controller
{
$this->authorize('view', PredefinedKit::class);
$kit = PredefinedKit::findOrFail($id);
- return (new PredefinedKitsTransformer)->transformPrdefinedKit($kit);
+ return (new PredefinedKitsTransformer)->transformPredefinedKit($kit);
}
@@ -247,16 +247,20 @@ class PredefinedKitsController extends Controller
*/
public function storeModel(Request $request, $kit_id)
{
+ //return response()->json(Helper::formatStandardApiResponse('error', 'string11', dd($request))); // TODO: trans
+
$this->authorize('update', PredefinedKit::class);
$kit = PredefinedKit::findOrFail($kit_id);
+
$quantity = $request->input('quantity', 1);
if( $quantity < 1) {
$quantity = 1;
}
+ //echo $request->get('model');
$kit->models()->attach( $request->get('model'), ['quantity' => $quantity]);
-
- return response()->json(Helper::formatStandardApiResponse('success', $kit, 'License added successfull')); // TODO: trans
+
+ return response()->json(Helper::formatStandardApiResponse('success', $kit, 'Model added successfull')); // TODO: trans
}
/**
diff --git a/app/Http/Controllers/Kits/PredefinedKitsController.php b/app/Http/Controllers/Kits/PredefinedKitsController.php
index 36ebb27d5c..93c64553f7 100644
--- a/app/Http/Controllers/Kits/PredefinedKitsController.php
+++ b/app/Http/Controllers/Kits/PredefinedKitsController.php
@@ -1,5 +1,5 @@
<?php
-namespace App\Http\Controllers;
+namespace App\Http\Controllers\Kits;
use App\Models\PredefinedKit;
use App\Models\AssetModel;
@@ -7,6 +7,11 @@ use App\Models\PredefinedModel;
use App\Models\License;
use App\Models\PredefinedLicence;
use Illuminate\Support\Facades\DB;
+use App\Http\Controllers\Controller;
+use App\Http\Requests\ImageUploadRequest;
+use App\Models\Accessory;
+use App\Models\SnipeItPivot;
+use Illuminate\Http\Request;
/**
@@ -36,7 +41,7 @@ class PredefinedKitsController extends Controller
{
//$this->authorize('create', PredefinedKit::class);
- return view('kits/edit')->with('item', new PredefinedKit);
+ return view('kits/create')->with('item', new PredefinedKit);
}
/**
@@ -83,7 +88,7 @@ class PredefinedKitsController extends Controller
if(!$success) {
return redirect()->back()->withInput()->withErrors($kit->getErrors());
}
- return redirect()->route("models.index")->with('success', 'Kit was successfully created.'); // TODO: trans()
+ return redirect()->route("kits.index")->with('success', 'Kit was successfully created.'); // TODO: trans()
}
/**
@@ -91,13 +96,13 @@ class PredefinedKitsController extends Controller
*
* @author [A. Gianotto] [<[email protected]>]
* @since [v1.0]
- * @param int $kitId
+ * @param int $kit_id
* @return View
*/
- public function edit($kitId = null)
+ public function edit($kit_id = null)
{
$this->authorize('update', PredefinedKit::class);
- if ($kit = PredefinedKit::find($kitId)) {
+ if ($kit = PredefinedKit::find($kit_id)) {
return view('kits/edit')
->with('item', $kit)
->with('models', $kit->models)
@@ -113,40 +118,21 @@ class PredefinedKitsController extends Controller
*
* @author [A. Gianotto] [<[email protected]>]
* @since [v1.0]
- * @param int $kitId
+ * @param int $kit_id
* @return Redirect
*/
- public function update(ImageUploadRequest $request, $kitId = null)
+ public function update(ImageUploadRequest $request, $kit_id = null)
{
$this->authorize('update', PredefinedKit::class);
// Check if the kit exists
- if (is_null($kit = PredefinedKit::find($kitId))) {
+ if (is_null($kit = PredefinedKit::find($kit_id))) {
// Redirect to the kits management page
return redirect()->route('kits.index')->with('error','Kit does not exist'); // TODO: trans
}
$kit->name = $request->input('name');
-
- // update models
- $new_model_ids = $request->input('models');
- $old_model_ids = $kit->models()->pluck('id'); // METODO: проверить
- // для получения ид надо что-то такое https://stackoverflow.com/questions/34308169/eloquent-orm-laravel-5-get-array-of-ids
- // project built on Laravel 5.4
- list($add_model_ids, $remove_model_ids) = $this->getAddingDeletingElements($new_model_ids, $old_model_ids); // METODO: тут ошибка, надо именно ид-шки получать, а не сами модели
-
- $new_licence_ids = $request->input('licences');
- $old_licence_ids = $kit->licences()->pluck('id'); // METODO: проверить
- list($add_licence_ids, $remove_licence_ids) = $this->getAddingDeletingElements($new_licence_ids, $old_licence_ids);
-
- $success = DB::transaction(function() use($kit, $add_models, $remove_models, $add_licences, $remove_licences) {
- $kit->models()->detach($remove_models);
- $kit->models()->attach($add_models);
- $kit->licenses()->detach($remove_licenses);
- $kit->licenses()->attach($add_licenses);
- return $kit->save();
- });
-
- if ($success) {
+
+ if ($kit->save()) {
return redirect()->route("kits.index")->with('success', 'Kit was successfully updated'); // TODO: trans
}
return redirect()->back()->withInput()->withErrors($kit->getErrors());
@@ -158,14 +144,14 @@ class PredefinedKitsController extends Controller
*
* @author [A. Gianotto] [<[email protected]>]
* @since [v1.0]
- * @param int $kitId
+ * @param int $kit_id
* @return Redirect
*/
- public function destroy($kitId)
+ public function destroy($kit_id)
{
$this->authorize('delete', PredefinedKit::class);
// Check if the kit exists
- if (is_null($kit = PredefinedKit::find($kitId))) {
+ if (is_null($kit = PredefinedKit::find($kit_id))) {
return redirect()->route('kits.index')->with('error', 'Kit not found'); // TODO: trans
}
@@ -180,28 +166,123 @@ class PredefinedKitsController extends Controller
}
/**
- * Get the model information to present to the model view page
+ * Get the kit information to present to the kit view page
*
* @author [A. Gianotto] [<[email protected]>]
* @since [v1.0]
* @param int $modelId
* @return View
*/
- public function show($modelId = null)
+ public function show($kit_id = null)
{
- $this->authorize('view', AssetModel::class);
- $model = AssetModel::withTrashed()->find($modelId);
+ $this->authorize('view', PredefinedKit::class);
+ $kit = PredefinedKit::find($kit_id);
- if (isset($model->id)) {
- return view('models/view', compact('model'));
+ if (isset($kit->id)) {
+ return view('kits/view', compact('kit'));
}
// Prepare the error message
- $error = trans('admin/models/message.does_not_exist', compact('id'));
+ $error = 'Kit does not exist.'; // TODO: trans
// Redirect to the user management page
- return redirect()->route('models.index')->with('error', $error);
+ return redirect()->route('kits.index')->with('error', $error);
+ }
+
+
+ /**
+ * Returns a view containing the Predefined Kit edit form.
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v1.0]
+ * @param int $kit_id
+ * @return View
+ */
+ public function editModel($kit_id, $model_id)
+ {
+ $this->authorize('update', PredefinedKit::class);
+ if ( ($kit = PredefinedKit::find($kit_id))
+ && ($model = $kit->models()->find($model_id)) ) {
+ // $item = $model->pivot;
+ // $item->name1 = 'tesn1';
+ // dd($item);
+ //dd($model->pivot);
+ // $item = $model->pivot;
+
+ return view('kits/model-edit', [
+ 'kit' => $kit,
+ 'model' => $model,
+ 'item' => $model->pivot
+ ]);
+ }
+ return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans
+ }
+
+ /**
+ * Get the kit information to present to the kit view page
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v1.0]
+ * @param int $modelId
+ * @return View
+ */
+ public function updateModel(Request $request, $kit_id) {
+ $this->authorize('update', PredefinedKit::class);
+ if (is_null($kit = PredefinedKit::find($kit_id))) {
+ // Redirect to the kits management page
+ return redirect()->route('kits.index')->with('error','Kit does not exist'); // TODO: trans
+ }
+ //return view('kits/create-model')->with('item', $kit);
+
+
+ // $quantity = $request->input('quantity', 1);
+ // if( $quantity < 1) {
+ // $quantity = 1;
+ // }
+
+ $validator = \Validator::make($request->all(), $kit->modelRules);
+ if ($validator->fails()) {
+ return redirect()->back()->withInput()->withErrors($validator);
+ }
+ // $kit->models()->sync([$request->input('model_id') => ['quantity' => $request->input('quantity')]]);
+ // $kit->models()->updateExistingPivot($request->input('pivot_id'), ['model_id' => $request->input('model_id'), 'quantity' => $request->input('quantity')]);
+ // $s = [$request->input('pivot_id') => ['model_id' => $request->input('model_id'), 'quantity' => $request->input('quantity')]];
+ //dd($s);
+ // $changes = $kit->models()->syncWithoutDetaching([$request->input('pivot_id') => ['model_id' => $request->input('model_id'), 'quantity' => $request->input('quantity')]]);
+ // $changes = $kit->models()->syncWithoutDetaching(['1' => ['model_id' => '2', 'quantity' => '35']]);
+ $pivot = $kit->models()->wherePivot('id', $request->input('pivot_id'))->first()->pivot;
+ // $pivot = $kit->models()->newPivotStatement()->find('1');
+ // $ret = $kit->models()->newPivotStatement()->find('1');
+ $pivot->model_id = $request->input('model_id');
+ $pivot->quantity = $request->input('quantity');
+ $pivot->save();
+
+ // return $this->edit($kit_id)->with('success', 'Model updated successfully.');
+ return redirect()->route('kits.edit', $kit_id)->with('success', 'Model updated successfully.'); // TODO: trans
+ }
+
+ /**
+ * Get the kit information to present to the kit view page
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v1.0]
+ * @param int $modelId
+ * @return View
+ */
+ public function detachModel($kit_id, $model_id) {
+ $this->authorize('update', PredefinedKit::class);
+ if (is_null($kit = PredefinedKit::find($kit_id))) {
+ // Redirect to the kits management page
+ return redirect()->route('kits.index')->with('error','Kit does not exist'); // TODO: trans
+ }
+
+ // Delete childs
+ $kit->models()->detach($model_id);
+
+ // Redirect to the kit management page
+ return redirect()->route('kits.index')->with('success', 'Kit was successfully deleted'); // TODO: trans
}
+
/**
* Returns true if a fieldset is set, 'add default values' is ticked and if
* any default values were entered into the form.
diff --git a/app/Http/Controllers/ModalController.php b/app/Http/Controllers/ModalController.php
index c55ad04a4d..791d342a8f 100644
--- a/app/Http/Controllers/ModalController.php
+++ b/app/Http/Controllers/ModalController.php
@@ -36,4 +36,11 @@ class ModalController extends Controller
return view('modals.manufacturer');
}
+ function kitModel() {
+ return view('modals.kit-model');
+ }
+
+ function kitLicense() {
+ return view('modals.kit-license');
+ }
}
diff --git a/app/Http/Transformers/PredefinedKitsTransformer.php b/app/Http/Transformers/PredefinedKitsTransformer.php
new file mode 100644
index 0000000000..9efa11fc4a
--- /dev/null
+++ b/app/Http/Transformers/PredefinedKitsTransformer.php
@@ -0,0 +1,72 @@
+<?php
+namespace App\Http\Transformers;
+
+use App\Models\PredefinedKit;
+use Illuminate\Database\Eloquent\Collection;
+use Gate;
+use App\Helpers\Helper;
+use Illuminate\Support\Facades\Storage;
+use App\Models\SnipeModel;
+
+class PredefinedKitsTransformer
+{
+
+ public function transformPredefinedKits (Collection $kits, $total)
+ {
+ $array = array();
+ foreach ($kits as $kit) {
+ $array[] = self::transformPredefinedKit($kit);
+ }
+ return (new DatatablesTransformer)->transformDatatables($array, $total);
+ }
+
+ public function transformPredefinedKit (PredefinedKit $kit)
+ {
+ $array = [
+ 'id' => (int) $kit->id,
+ 'name' => e($kit->name)
+ ];
+
+ $permissions_array['available_actions'] = [
+ 'update' => Gate::allows('update', PredefinedKit::class),
+ 'delete' => Gate::allows('delete', PredefinedKit::class),
+ // 'clone' => Gate::allows('create', PredefinedKit::class),
+ // 'restore' => Gate::allows('create', PredefinedKit::class),
+ ];
+
+ $array += $permissions_array;
+ return $array;
+ }
+
+ public function transformElements(Collection $elements, $total) {
+ $array = array();
+ foreach ($elements as $element) {
+ $array[] = self::transformElement($element);
+ }
+ return (new DatatablesTransformer)->transformDatatables($array, $total);
+ }
+
+ public function transformElement(SnipeModel $element) {
+ $array = [
+ 'id' => (int) $element->id,
+ 'pivot_id' => (int) $element->pivot->id,
+ 'owner_id' => (int) $element->pivot->kit_id,
+ 'quantity' => (int) $element->pivot->quantity,
+ 'name' => e($element->name)
+ ];
+
+ $permissions_array['available_actions'] = [
+ 'update' => Gate::allows('update', PredefinedKit::class),
+ 'delete' => Gate::allows('delete', PredefinedKit::class),
+ ];
+
+ $array += $permissions_array;
+ return $array;
+ }
+
+ public function transformPredefinedKitsDatatable($kits) {
+ return (new DatatablesTransformer)->transformDatatables($kits);
+ }
+
+
+}
diff --git a/app/Models/PredefinedKit.php b/app/Models/PredefinedKit.php
new file mode 100644
index 0000000000..5f2b46f4c2
--- /dev/null
+++ b/app/Models/PredefinedKit.php
@@ -0,0 +1,106 @@
+<?php
+namespace App\Models;
+
+use App\Http\Traits\UniqueUndeletedTrait;
+use App\Models\SnipeModel;
+use App\Models\Traits\Searchable;
+use App\Presenters\Presentable;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+use Watson\Validating\ValidatingTrait;
+
+/**
+ * Model for Categories. Categories are a higher-level group
+ * than Asset Models, and handle things like whether or not
+ * to require acceptance from the user, whether or not to
+ * send a EULA to the user, etc.
+ *
+ * @version v1.0
+ */
+class PredefinedKit extends SnipeModel
+{
+ protected $presenter = 'App\Presenters\PredefinedKitPresenter';
+ use Presentable;
+ protected $table = 'kits';
+
+ /**
+ * Category validation rules
+ */
+ public $rules = array(
+ 'name' => 'required|min:1|max:255|unique'
+ );
+
+ use ValidatingTrait;
+
+ public $modelRules = [
+ 'model_id' => 'required|exists:models,id',
+ 'quantity' => 'required|integer|min:1',
+ 'pivot_id' => 'integer|exists:kits_models,id'
+ ];
+
+ public $licenseRules = [
+ 'license_id' => 'required|exists:licenses,id',
+ 'quantity' => 'required|integer|min:1',
+ 'pivot_id' => 'integer|exists:kits_licenses,id'
+ ];
+
+
+ /**
+ * The attributes that are mass assignable.
+ *
+ * @var array
+ */
+ protected $fillable = [
+ 'name'
+ ];
+
+ use Searchable;
+
+ /**
+ * The attributes that should be included when searching the model.
+ *
+ * @var array
+ */
+ protected $searchableAttributes = ['name'];
+
+ /**
+ * The relations and their attributes that should be included when searching the model.
+ *
+ * @var array
+ */
+ protected $searchableRelations = [];
+
+
+ /**
+ * Establishes the kits -> models relationship
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v2.0]
+ * @return \Illuminate\Database\Eloquent\Relations\Relation
+ */
+ public function models()
+ {
+ return $this->belongsToMany('\App\Models\AssetModel', 'kits_models', 'kit_id', 'model_id')->withPivot('id', 'quantity');
+ }
+
+ /**
+ * Establishes the kits -> licenses relationship
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v4.3]
+ * @return \Illuminate\Database\Eloquent\Relations\Relation
+ */
+ public function licenses()
+ {
+ return $this->belongsToMany('\App\Models\License', 'kits_licenses', 'kit_id', 'license_id')->withPivot('id', 'quantity');
+ }
+
+
+
+ /**
+ * -----------------------------------------------
+ * BEGIN QUERY SCOPES
+ * -----------------------------------------------
+ **/
+
+}
diff --git a/app/Models/SnipeItPivot.php b/app/Models/SnipeItPivot.php
new file mode 100644
index 0000000000..1431854200
--- /dev/null
+++ b/app/Models/SnipeItPivot.php
@@ -0,0 +1,11 @@
+<?php
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Relations\Pivot;
+
+class SnipeItPivot extends Pivot
+{
+
+ use ValidatingTrait;
+ public $rules = [];
+}
\ No newline at end of file
diff --git a/app/Presenters/PredefinedKitPresenter.php b/app/Presenters/PredefinedKitPresenter.php
new file mode 100644
index 0000000000..0a679174fc
--- /dev/null
+++ b/app/Presenters/PredefinedKitPresenter.php
@@ -0,0 +1,178 @@
+<?php
+
+namespace App\Presenters;
+
+use App\Helpers\Helper;
+use Illuminate\Support\Facades\Gate;
+
+/**
+ * Class LicensePresenter
+ * @package App\Presenters
+ */
+class PredefinedKitPresenter extends Presenter
+{
+ /**
+ * Json Column Layout for bootstrap table
+ * @return string
+ */
+ public static function dataTableLayout()
+ {
+ $layout = [
+ [
+ "field" => "id",
+ "searchable" => false,
+ "sortable" => true,
+ "switchable" => true,
+ "title" => trans('general.id'),
+ "visible" => false
+ ], [
+ "field" => "name",
+ "searchable" => true,
+ "sortable" => true,
+ "title" => 'Name', // TODO: trans
+ "formatter" => "kitsLinkFormatter"
+ ]
+ ];
+
+ $layout[] = [
+ "field" => "actions",
+ "searchable" => false,
+ "sortable" => false,
+ "switchable" => false,
+ "title" => trans('table.actions'),
+ "formatter" => "kitsActionsFormatter",
+ ];
+
+
+ return json_encode($layout);
+ }
+
+
+ /**
+ * Json Column Layout for bootstrap table
+ * @return string
+ */
+ public static function dataTableModels()
+ {
+ $layout = [
+ [
+ "field" => "id",
+ "searchable" => false,
+ "sortable" => true,
+ "switchable" => true,
+ "title" => trans('general.id'),
+ "visible" => false
+ ], [
+ "field" => "pivot_id",
+ "searchable" => false,
+ "sortable" => true,
+ "switchable" => true,
+ "title" => trans('general.id'),
+ "visible" => false
+ ], [
+ "field" => "owner_id",
+ "searchable" => false,
+ "sortable" => true,
+ "switchable" => true,
+ "title" => trans('general.id'),
+ "visible" => false
+ ], [
+ "field" => "name",
+ "searchable" => true,
+ "sortable" => true,
+ "title" => 'Name', // TODO: trans
+ "formatter" => "modelsLinkFormatter"
+ ], [
+ "field" => "quantity",
+ "searchable" => false,
+ "sortable" => false,
+ "title" => 'Quantity', // TODO: trans
+ ], [
+ "field" => "actions",
+ "searchable" => false,
+ "sortable" => false,
+ "switchable" => false,
+ "title" => trans('table.actions'),
+ "formatter" => "kits_modelsActionsFormatter",
+ ]
+ ];
+
+ return json_encode($layout);
+ }
+
+ /**
+ * Json Column Layout for bootstrap table
+ * @return string
+ */
+ public static function dataTableLicenses()
+ {
+ $layout = [
+ [
+ "field" => "id",
+ "searchable" => false,
+ "sortable" => true,
+ "switchable" => true,
+ "title" => trans('general.id'),
+ "visible" => false
+ ], [
+ "field" => "pivot_id",
+ "searchable" => false,
+ "sortable" => true,
+ "switchable" => true,
+ "title" => trans('general.id'),
+ "visible" => false
+ ], [
+ "field" => "owner_id",
+ "searchable" => false,
+ "sortable" => true,
+ "switchable" => true,
+ "title" => trans('general.id'),
+ "visible" => false
+ ], [
+ "field" => "name",
+ "searchable" => true,
+ "sortable" => true,
+ "title" => 'Name', // TODO: trans
+ "formatter" => "licensesLinkFormatter"
+ ], [
+ "field" => "actions",
+ "searchable" => false,
+ "sortable" => false,
+ "switchable" => false,
+ "title" => trans('table.actions'),
+ "formatter" => "kits_licensesActionsFormatter",
+ ]
+ ];
+
+ return json_encode($layout);
+ }
+
+
+
+ /**
+ * Link to this kit Name
+ * @return string
+ */
+ public function nameUrl()
+ {
+ return (string)link_to_route('kits.show', $this->name, $this->id);
+ }
+
+ /**
+ * Link to this kit Name
+ * @return string
+ */
+ public function fullName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * Url to view this item.
+ * @return string
+ */
+ public function viewUrl()
+ {
+ return route('kits.show', $this->id);
+ }
+}
diff --git a/resources/views/kits/create.blade.php b/resources/views/kits/create.blade.php
new file mode 100644
index 0000000000..4be2bb5dca
--- /dev/null
+++ b/resources/views/kits/create.blade.php
@@ -0,0 +1,10 @@
+@extends('layouts/edit-form', [
+ 'createText' => 'Create kit',
+ 'updateText' => 'Update kit',
+ 'formAction' => ($item) ? route('kits.update', ['kit' => $item->id]) : route('kits.store'),
+])
+
+{{-- Page content --}}
+@section('inputFields')
+@include ('partials.forms.edit.name', ['translated_name' => 'Name']) {{-- TODO: trans --}}
+@stop
\ No newline at end of file
diff --git a/resources/views/kits/edit.blade.php b/resources/views/kits/edit.blade.php
index d16d63e11a..6e6ab87421 100644
--- a/resources/views/kits/edit.blade.php
+++ b/resources/views/kits/edit.blade.php
@@ -6,7 +6,7 @@
{{-- Page content --}}
@section('inputFields')
-@include ('partials.forms.edit.name')
+@include ('partials.forms.edit.name', ['translated_name' => 'Name']) {{-- TODO: trans --}}
@stop
@section('content')
@@ -15,13 +15,14 @@
<div class="col-md-12">
<div class="box box-default">
<div class="box-header with-border">
- <h3 class="box-title">Models</h3>
+ {{-- <h3 class="box-title"><span>Models </span><a href="{{ route('modal.kit.model', ['kit' => $item->id]) }}" data-toggle="modal" data-target="#createModal" class="btn btn-sm btn-primary"><i class="fa fa-plus icon-white"></i> Append</a></h3> --}}
+ <h3 class="box-title"><span>Models </span></h3>
</div>
<div class="box-body">
<div class="table-responsive">
<table
data-cookie-id-table="kitModelsTable"
- data-columns="{{ \App\Presenters\::modelsDataTableLayout() }}"
+ data-columns="{{ \App\Presenters\PredefinedKitPresenter::dataTableModels() }}"
data-pagination="true"
data-search="true"
data-side-pagination="server"
@@ -32,12 +33,13 @@
data-sort-name="name"
id="kitModelsTable"
class="table table-striped snipe-table"
- data-url="{{ route('api.kits.models.index') }}"
+ data-url="{{ route('api.kits.models.index', $item->id) }}"
data-export-options='{
"fileName": "export-kit-models-{{ date('Y-m-d') }}",
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
}'>
</table>
+ <a href="{{ route('modal.kit.model', ['kit' => $item->id]) }}" data-toggle="modal" data-target="#createModal" class="btn btn-primary pull-right"><i class="fa fa-plus icon-white"></i> Append</a>
</div>
</div> <!--.box-body-->
</div> <!-- /.box.box-default-->
@@ -54,7 +56,7 @@
<table
data-cookie-id-table="kitLicensesTable"
- data-columns="{{ \App\Presenters\::licensesDataTableLayout() }}"
+ data-columns="{{ \App\Presenters\PredefinedKitPresenter::dataTableLicenses() }}"
data-pagination="true"
data-search="true"
data-side-pagination="server"
@@ -65,7 +67,7 @@
data-sort-name="name"
id="kitLicensesTable"
class="table table-striped snipe-table"
- data-url="{{ route('api.kits.licenses.index') }}"
+ data-url="{{ route('api.kits.licenses.index', $item->id) }}"
data-export-options='{
"fileName": "export-kit-models-{{ date('Y-m-d') }}",
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
@@ -76,4 +78,8 @@
</div> <!-- /.box.box-default-->
</div> <!-- .col-md-12-->
</div>
+@stop
+
+@section('moar_scripts')
+@include ('partials.bootstrap-table')
@stop
\ No newline at end of file
diff --git a/resources/views/kits/index.blade.php b/resources/views/kits/index.blade.php
index c5e492f7bb..6cf41e73f7 100644
--- a/resources/views/kits/index.blade.php
+++ b/resources/views/kits/index.blade.php
@@ -21,7 +21,7 @@ Kits
<table
data-cookie-id-table="kitsTable"
- data-columns="{{ \App\Presenters\::dataTableLayout() }}"
+ data-columns="{{ \App\Presenters\PredefinedKitPresenter::dataTableLayout() }}"
data-pagination="true"
data-search="true"
data-side-pagination="server"
@@ -39,6 +39,28 @@ Kits
}'>
</table>
</div>
+ {{-- <h2>Test</h2>
+ <div class="table-responsive">
+ <table
+ data-cookie-id-table="kitModelsTable"
+ data-columns="{{ \App\Presenters\PredefinedKitPresenter::dataTableModels() }}"
+ data-pagination="true"
+ data-search="true"
+ data-side-pagination="server"
+ data-show-columns="true"
+ data-show-export="true"
+ data-show-refresh="true"
+ data-sort-order="asc"
+ data-sort-name="name"
+ id="kitModelsTable"
+ class="table table-striped snipe-table"
+ data-url="{{ route('api.kits.models.index', 1) }}"
+ data-export-options='{
+ "fileName": "export-kit-models-{{ date('Y-m-d') }}",
+ "ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
+ }'>
+ </table>
+ </div> --}}
</div> <!--.box-body-->
</div> <!-- /.box.box-default-->
</div> <!-- .col-md-12-->
diff --git a/resources/views/kits/model-edit.blade.php b/resources/views/kits/model-edit.blade.php
new file mode 100644
index 0000000000..7a283c580d
--- /dev/null
+++ b/resources/views/kits/model-edit.blade.php
@@ -0,0 +1,58 @@
+@extends('layouts/edit-form', [
+ 'createText' => 'Append model', // TODO: trans
+ 'updateText' => 'Update appended model', // TODO: trans
+ 'formAction' => ($item) ? route('kits.models.update', ['kit_id' => $kit->id, 'model_id' => $item->model_id]) : route('kits.models.store', ['kit_id' => $kit->id]),
+])
+
+{{-- Page content --}}
+@section('inputFields')
+{{-- <div class="form-group {{ $errors->has('name') ? ' has-error' : '' }}">
+ <label for="model_id">{{ trans('general.asset_model') }}:</label>
+ <div class="col-md-8 col-xs-12 required">
+ <select class="js-data-ajax select2" data-endpoint="models" name="model" style="width: 100%" id="model_id" value="{{ Input::old('name', $pivot->model_id) }}" data-validation="required" />
+ {{ Form::select('model_id', [] , Input::old('name', $pivot->model_id), array('class'=>'select2', 'style'=>'width:100%')) }}
+ </div>
+</div> --}}
+{{-- At first, I tried to use partials.forms.edit.model-select. But, it required ValidatingTrait (rules method). Pivot class doesn't have it. --}}
+@include ('partials.forms.edit.model-select', ['translated_name' => trans('admin/hardware/form.model'), 'fieldname' => 'model_id', 'required' => 'true'])
+{{-- <div id="model_id" class="form-group{{ $errors->has('model_id') ? ' has-error' : '' }}">
+
+ {{ Form::label('model_id', trans('admin/hardware/form.model'), array('class' => 'col-md-3 control-label')) }}
+
+ <div class="col-md-7 required">
+ <select class="js-data-ajax" data-endpoint="models" data-placeholder="{{ trans('general.select_model') }}" name="model_id" style="width: 100%" id="model_select_id" data-validation="required">
+ @if ($model_id = Input::old('model_id', (isset($item)) ? $item->model_id : ''))
+ <option value="{{ $model_id }}" selected="selected">
+ {{ (\App\Models\AssetModel::find($model_id)) ? \App\Models\AssetModel::find($model_id)->name : '' }}
+ </option>
+ @else
+ <option value="">{{ trans('general.select_model') }}</option>
+ @endif
+
+ </select>
+ </div>
+ <div class="col-md-1 col-sm-1 text-left">
+ @can('create', \App\Models\AssetModel::class)
+ @if ((!isset($hide_new)) || ($hide_new!='true'))
+ <a href='{{ route('modal.model') }}' data-toggle="modal" data-target="#createModal" data-select='model_select_id' class="btn btn-sm btn-default">New</a>
+ <span class="mac_spinner" style="padding-left: 10px; color: green; display:none; width: 30px;"><i class="fa fa-spinner fa-spin"></i> </span>
+ @endif
+ @endcan
+ </div>
+
+ {!! $errors->first('model_id', '<div class="col-md-8 col-md-offset-3"><span class="alert-msg"><i class="fa fa-times"></i> :message</span></div>') !!}
+ </div> --}}
+<div class="form-group {{ $errors->has('quantity') ? ' has-error' : '' }}">
+ <label for="quantity" class="col-md-3 control-label">{{ trans('general.quantity') }}</label>
+ <div class="col-md-7 required">
+ <div class="col-md-2" style="padding-left:0px">
+ <input class="form-control" type="text" name="quantity" id="quantity" value="{{ Input::old('quantity', $item->quantity) }}" />
+ </div>
+ {!! $errors->first('quantity', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
+ </div>
+</div>
+
+<input type="hidden" name="pivot_id" value="{{$item->id}}">
+{{-- <input class="form-control" type="text" name="quantity" id="quantity" value="{{ Input::old('quantity', $item->quantity) }}" /> --}}
+
+@stop
diff --git a/resources/views/modals/kit-model.blade.php b/resources/views/modals/kit-model.blade.php
new file mode 100644
index 0000000000..4f90f25724
--- /dev/null
+++ b/resources/views/modals/kit-model.blade.php
@@ -0,0 +1,38 @@
+{{-- See snipeit_modals.js for what powers this --}}
+<div class="modal-dialog">
+ <div class="modal-content">
+ <div class="modal-header">
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+ <span aria-hidden="true">&times;</span></button>
+ <h4 class="modal-title">Append model{{-- TODO: trans --}}</h4>
+ </div>
+ <div class="modal-body">
+ <form action="{{ route('api.kits.models.store', ['kit_id' => request('kit')]) }}" onsubmit="return false">
+ {{ csrf_field() }}
+ <div class="alert alert-danger" id="modal_error_msg" style="display:none">
+ </div>
+
+ <div class="dynamic-form-row">
+ <div class="col-md-4 col-xs-12"><label for="modal-model_id">{{ trans('general.asset_model') }}:
+ </label></div>
+ <div class="col-md-8 col-xs-12 required">
+ <select class="js-data-ajax" data-endpoint="models" name="model" style="width: 100%" id="modal-model_id" />
+ </div>
+ </div>
+
+ <div class="dynamic-form-row">
+ <div class="col-md-4 col-xs-12"><label for="modal-quantity_id">Quantity{{-- TODO: trans --}}:
+ </label></div>
+ <div class="col-md-8 col-xs-12 required">
+ <input type='text' name='quantity' id='modal-quantity_id' class="form-control">
+ </div>
+ </div>
+
+ </form>
+ </div>
+ <div class="modal-footer">
+ <button type="button" class="btn btn-default" data-dismiss="modal">{{ trans('button.cancel') }}</button>
+ <button type="button" class="btn btn-primary" id="modal-save">{{ trans('general.save') }}</button>
+ </div>
+ </div><!-- /.modal-content -->
+</div><!-- /.modal-dialog -->
diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php
index e96f88d1af..28f93dad77 100644
--- a/resources/views/partials/bootstrap-table.blade.php
+++ b/resources/views/partials/bootstrap-table.blade.php
@@ -150,66 +150,24 @@
}
// Make the edit/delete buttons
- function genericActionsFormatter(destination) {
+ function genericActionsFormatter(owner_name, element_name = '') {
return function (value,row) {
var actions = '<nobr>';
// Add some overrides for any funny urls we have
- var dest = destination;
+ var dest = owner_name;
- if (destination=='groups') {
+ if (dest =='groups') {
var dest = 'admin/groups';
}
- if (destination=='maintenances') {
+ if (dest =='maintenances') {
var dest = 'hardware/maintenances';
}
- if ((row.available_actions) && (row.available_actions.clone === true)) {
- actions += '<a href="{{ url('/') }}/' + dest + '/' + row.id + '/clone" class="btn btn-sm btn-info" data-toggle="tooltip" title="Clone"><i class="fa fa-copy"></i></a>&nbsp;';
- }
-
- if ((row.available_actions) && (row.available_actions.update === true)) {
- actions += '<a href="{{ url('/') }}/' + dest + '/' + row.id + '/edit" class="btn btn-sm btn-warning" data-toggle="tooltip" title="Update"><i class="fa fa-pencil"></i></a>&nbsp;';
- }
-
- if ((row.available_actions) && (row.available_actions.delete === true)) {
- actions += '<a href="{{ url('/') }}/' + dest + '/' + row.id + '" '
- + ' class="btn btn-danger btn-sm delete-asset" data-toggle="tooltip" '
- + ' data-toggle="modal" '
- + ' data-content="{{ trans('general.sure_to_delete') }} ' + row.name + '?" '
- + ' data-title="{{ trans('general.delete') }}" onClick="return false;">'
- + '<i class="fa fa-trash"></i></a>&nbsp;';
- } else {
- actions += '<a class="btn btn-danger btn-sm delete-asset disabled" onClick="return false;"><i class="fa fa-trash"></i></a>&nbsp;';
- }
-
- if ((row.available_actions) && (row.available_actions.restore === true)) {
- actions += '<a href="{{ url('/') }}/' + dest + '/' + row.id + '/restore" class="btn btn-sm btn-warning" data-toggle="tooltip" title="Restore"><i class="fa fa-retweet"></i></a>&nbsp;';
- }
-
- actions +='</nobr>';
- return actions;
-
- };
- }
-
- // This only works for model index pages because it uses the row's model ID
- function genericChildActionsFormatter(parent, child) {
- return function (value,row) {
-
- var actions = '<nobr>';
-
- // Add some overrides for any funny urls we have
- var dest = destination;
-
- if (destination=='groups') {
- var dest = 'admin/groups';
- }
-
- if (destination=='maintenances') {
- var dest = 'hardware/maintenances';
+ if(element_name != '') {
+ dest = dest + '/' + row.owner_id + '/' + element_name;
}
if ((row.available_actions) && (row.available_actions.clone === true)) {
@@ -222,7 +180,7 @@
if ((row.available_actions) && (row.available_actions.delete === true)) {
actions += '<a href="{{ url('/') }}/' + dest + '/' + row.id + '" '
- + ' class="btn btn-danger btn-sm delete-asset" data-tooltip="true" '
+ + ' class="btn btn-danger btn-sm delete-asset" data-toggle="tooltip" '
+ ' data-toggle="modal" '
+ ' data-content="{{ trans('general.sure_to_delete') }} ' + row.name + '?" '
+ ' data-title="{{ trans('general.delete') }}" onClick="return false;">'
@@ -370,10 +328,7 @@
'depreciations',
'fieldsets',
'groups',
- 'kits',
- // METODO: проверить, что эти пути работают
- 'kits.models',
- 'kits.licenses',
+ 'kits'
];
for (var i in formatters) {
@@ -383,15 +338,15 @@
window[formatters[i] + 'InOutFormatter'] = genericCheckinCheckoutFormatter(formatters[i]);
}
- var childFormatters = [
+ var child_formatters = [
['kits', 'models'],
['kits', 'licenses'],
];
- for (var i in childFormatters) {
- var parentName = childFormatters[i][0];
- var childName = childFormatters[i][2];
- window[childFormatters[i][0] + 'ChildsActionsFormatter'] = genericChildActionsFormatter(childFormatters[i][0], childFormatters[i][1]);
+ for (var i in child_formatters) {
+ var owner_name = child_formatters[i][0];
+ var child_name = child_formatters[i][1];
+ window[owner_name + '_' + child_name + 'ActionsFormatter'] = genericActionsFormatter(owner_name, child_name);
}
diff --git a/routes/web.php b/routes/web.php
index f59362c767..827088ed8c 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -87,6 +87,8 @@ Route::group(['middleware' => 'auth','prefix' => 'modals'], function () {
Route::get('statuslabel',['as' => 'modal.statuslabel','uses' => 'ModalController@statuslabel']);
Route::get('supplier',['as' => 'modal.supplier','uses' => 'ModalController@supplier']);
Route::get('user',['as' => 'modal.user','uses' => 'ModalController@user']);
+ Route::get('kit-model',['as' => 'modal.kit.model','uses' => 'ModalController@kitModel']);
+ Route::get('kit-license',['as' => 'modal.kit.license','uses' => 'ModalController@kitLicense']);
});
/*
diff --git a/routes/web/kits.php b/routes/web/kits.php
index cecd86f597..204af83f84 100644
--- a/routes/web/kits.php
+++ b/routes/web/kits.php
@@ -1,7 +1,7 @@
<?php
// Predefined Kit Management
-Route::resource('kit', 'Kits\PredefinedKitController', [
+Route::resource('kits', 'Kits\PredefinedKitsController', [
'middleware' => ['auth'],
'parameters' => ['kit' => 'kit_id']
]);
@@ -10,12 +10,12 @@ Route::resource('kit', 'Kits\PredefinedKitController', [
Route::group([ 'prefix' => 'kits/{kit_id}', 'middleware' => ['auth'] ], function () {
- Route::get('licenses',
- [
- 'as' => 'kits.licenses.index',
- 'uses' => 'Kits\PredefinedKitsController@indexLicenses',
- ]
- );
+ // Route::get('licenses',
+ // [
+ // 'as' => 'kits.licenses.index',
+ // 'uses' => 'Kits\PredefinedKitsController@indexLicenses',
+ // ]
+ // );
Route::post('licenses',
[
@@ -33,18 +33,18 @@ Route::group([ 'prefix' => 'kits/{kit_id}', 'middleware' => ['auth'] ], function
Route::delete('licenses/{license_id}',
[
- 'as' => 'kits.licenses.destroy',
- 'uses' => 'Kits\PredefinedKitsController@destroyLicense',
+ 'as' => 'kits.licenses.detach',
+ 'uses' => 'Kits\PredefinedKitsController@detachLicense',
]
);
- Route::get('models',
- [
- 'as' => 'kits.models.index',
- 'uses' => 'Kits\PredefinedKitsController@indexModels',
- ]
- );
+ // Route::get('models',
+ // [
+ // 'as' => 'kits.models.index',
+ // 'uses' => 'Kits\PredefinedKitsController@indexModels',
+ // ]
+ // );
Route::post('models',
[
@@ -59,11 +59,18 @@ Route::group([ 'prefix' => 'kits/{kit_id}', 'middleware' => ['auth'] ], function
'uses' => 'Kits\PredefinedKitsController@updateModel',
]
);
+
+ Route::get('models/{model_id}/edit',
+ [
+ 'as' => 'kits.models.edit',
+ 'uses' => 'Kits\PredefinedKitsController@editModel',
+ ]
+ );
Route::delete('models/{model_id}',
[
- 'as' => 'kits.models.destroy',
- 'uses' => 'Kits\PredefinedKitsController@destroyModel',
+ 'as' => 'kits.models.detach',
+ 'uses' => 'Kits\PredefinedKitsController@detachModel',
]
);