Skip to content

A free open source IT asset/license management system

Predefined kits test

Minaev Dmitriy0e66c3cb5604
diff --git a/app/Http/Controllers/Api/PredefinedKitsController.php b/app/Http/Controllers/Api/PredefinedKitsController.php
new file mode 100644
index 0000000000..72b99aa973
--- /dev/null
+++ b/app/Http/Controllers/Api/PredefinedKitsController.php
@@ -0,0 +1,300 @@
+<?php
+
+namespace App\Http\Controllers\Api;
+
+use Illuminate\Http\Request;
+use App\Http\Controllers\Controller;
+use App\Helpers\Helper;
+use App\Models\PredefinedKit;
+use App\Http\Transformers\PredefinedKitsTransformer;
+
+class PredefinedKitsController extends Controller
+{
+ /**
+ * Display a listing of the resource.
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v4.0]
+ * @return \Illuminate\Http\Response
+ */
+ public function index(Request $request)
+ {
+ $this->authorize('view', PredefinedKit::class);
+ $allowed_columns = ['id', 'name'];
+
+ $kits = PredefinedKit::query();
+
+ if ($request->filled('search')) {
+ $kits = $kits->TextSearch($request->input('search'));
+ }
+
+ $offset = $request->input('offset', 0);
+ $limit = $request->input('limit', 50);
+ $order = $request->input('order') === 'asc' ? 'asc' : 'desc';
+ $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'assets_count';
+ $kits->orderBy($sort, $order);
+
+ $total = $kits->count();
+ $kits = $kits->skip($offset)->take($limit)->get();
+ return (new PredefinedKitsTransformer)->transformPrdefinedKits($kits, $total);
+
+ }
+
+
+ /**
+ * Store a newly created resource in storage.
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v4.0]
+ * @param \Illuminate\Http\Request $request
+ * @return \Illuminate\Http\Response
+ */
+ public function store(Request $request)
+ {
+ $this->authorize('create', PredefinedKit::class);
+ $kit = new PredefinedKit;
+ $kit->fill($request->all());
+
+ if ($kit->save()) {
+ return response()->json(Helper::formatStandardApiResponse('success', $kit, 'Created was successfull')); // TODO: trans
+ }
+ return response()->json(Helper::formatStandardApiResponse('error', null, $kit->getErrors()));
+
+ }
+
+ /**
+ * Display the specified resource.
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v4.0]
+ * @param int $id
+ * @return \Illuminate\Http\Response
+ */
+ public function show($id)
+ {
+ $this->authorize('view', PredefinedKit::class);
+ $kit = PredefinedKit::findOrFail($id);
+ return (new PredefinedKitsTransformer)->transformPrdefinedKit($kit);
+ }
+
+
+ /**
+ * Update the specified resource in storage.
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v4.0]
+ * @param \Illuminate\Http\Request $request
+ * @param int $id
+ * @return \Illuminate\Http\Response
+ */
+ public function update(Request $request, $id)
+ {
+ $this->authorize('update', PredefinedKit::class);
+ $kit = PredefinedKit::findOrFail($id);
+ $kit->fill($request->all());
+
+ if ($kit->save()) {
+ return response()->json(Helper::formatStandardApiResponse('success', $kit, 'Update was successfull')); // TODO: trans
+ }
+
+ return response()->json(Helper::formatStandardApiResponse('error', null, $kit->getErrors()));
+ }
+
+ /**
+ * Remove the specified resource from storage.
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v4.0]
+ * @param int $id
+ * @return \Illuminate\Http\Response
+ */
+ public function destroy($id)
+ {
+ $this->authorize('delete', PredefinedKit::class);
+ $kit = PredefinedKit::findOrFail($id);
+
+ $kit->delete();
+ return response()->json(Helper::formatStandardApiResponse('success', null, 'Delete was successfull')); // TODO: trans
+
+ }
+
+
+ /**
+ * Gets a paginated collection for the select2 menus
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v4.0.16]
+ * @see \App\Http\Transformers\SelectlistTransformer
+ *
+ */
+ public function selectlist(Request $request)
+ {
+
+ $kits = PredefinedKit::select([
+ 'id',
+ 'name'
+ ]);
+
+ if ($request->filled('search')) {
+ $kits = $kits->where('name', 'LIKE', '%'.$request->get('search').'%');
+ }
+
+ $kits = $kits->orderBy('name', 'ASC')->paginate(50);
+
+ return (new SelectlistTransformer)->transformSelectlist($kits);
+
+ }
+
+ /**
+ * Display the specified resource.
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v4.0]
+ * @param int $id
+ * @return \Illuminate\Http\Response
+ */
+ public function indexLicenses($kit_id) {
+ $this->authorize('view', PredefinedKit::class);
+ $kit = PredefinedKit::findOrFail($kit_id);
+ $licenses = $kit->licenses;
+ return (new PredefinedKitsTransformer)->transformElements($licenses, $licenses->count());
+ }
+
+
+ /**
+ * Display the specified resource.
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v4.0]
+ * @param int $id
+ * @return \Illuminate\Http\Response
+ */
+ public function storeLicense(Request $request, $kit_id)
+ {
+ $this->authorize('update', PredefinedKit::class);
+
+ $kit = PredefinedKit::findOrFail($kit_id);
+ $quantity = $request->input('quantity', 1);
+ if( $quantity < 1) {
+ $quantity = 1;
+ }
+ $kit->licenses()->attach( $request->get('license'), ['quantity' => $quantity]);
+
+ return response()->json(Helper::formatStandardApiResponse('success', $kit, 'License added successfull')); // TODO: trans
+ }
+
+ /**
+ * Update the specified resource in storage.
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v4.0]
+ * @param \Illuminate\Http\Request $request
+ * @param int $id
+ * @return \Illuminate\Http\Response
+ */
+ public function updateLicense(Request $request, $kit_id, $license_id)
+ {
+ $this->authorize('update', PredefinedKit::class);
+ $kit = PredefinedKit::findOrFail($id);
+ $quantity = $request->input('quantity', 1);
+ if( $quantity < 1) {
+ $quantity = 1;
+ }
+ $kit->licenses()->sync([$license_id => ['quantity' => $quantity]]);
+
+ return response()->json(Helper::formatStandardApiResponse('success', null, 'License updated')); // TODO: trans
+ }
+
+ /**
+ * Remove the specified resource from storage.
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v4.0]
+ * @param int $kit_id
+ * @return \Illuminate\Http\Response
+ */
+ public function destroyLicense($kit_id, $license_id)
+ {
+ $this->authorize('update', PredefinedKit::class);
+ $kit = PredefinedKit::findOrFail($id);
+
+ $kit->licenses()->detach($license_id);
+ return response()->json(Helper::formatStandardApiResponse('success', null, 'Delete was successfull')); // TODO: trans
+ }
+
+ /**
+ * Display the specified resource.
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v4.0]
+ * @param int $id
+ * @return \Illuminate\Http\Response
+ */
+ public function indexModels($kit_id) {
+ $this->authorize('view', PredefinedKit::class);
+ $kit = PredefinedKit::findOrFail($kit_id);
+ $models = $kit->models;
+ return (new PredefinedKitsTransformer)->transformElements($models, $models->count());
+ }
+
+ /**
+ * Display the specified resource.
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v4.0]
+ * @param int $id
+ * @return \Illuminate\Http\Response
+ */
+ public function storeModel(Request $request, $kit_id)
+ {
+ $this->authorize('update', PredefinedKit::class);
+
+ $kit = PredefinedKit::findOrFail($kit_id);
+ $quantity = $request->input('quantity', 1);
+ if( $quantity < 1) {
+ $quantity = 1;
+ }
+ $kit->models()->attach( $request->get('model'), ['quantity' => $quantity]);
+
+ return response()->json(Helper::formatStandardApiResponse('success', $kit, 'License added successfull')); // TODO: trans
+ }
+
+ /**
+ * Update the specified resource in storage.
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v4.0]
+ * @param \Illuminate\Http\Request $request
+ * @param int $id
+ * @return \Illuminate\Http\Response
+ */
+ public function updateModel(Request $request, $kit_id, $model_id)
+ {
+ $this->authorize('update', PredefinedKit::class);
+ $kit = PredefinedKit::findOrFail($id);
+ $quantity = $request->input('quantity', 1);
+ if( $quantity < 1) {
+ $quantity = 1;
+ }
+ $kit->models()->sync([$model_id => ['quantity' => $quantity]]);
+
+ return response()->json(Helper::formatStandardApiResponse('success', null, 'License updated')); // TODO: trans
+ }
+
+ /**
+ * Remove the specified resource from storage.
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v4.0]
+ * @param int $kit_id
+ * @return \Illuminate\Http\Response
+ */
+ public function destroyModel($kit_id, $model_id)
+ {
+ $this->authorize('update', PredefinedKit::class);
+ $kit = PredefinedKit::findOrFail($id);
+
+ $kit->models()->detach($model_id);
+ return response()->json(Helper::formatStandardApiResponse('success', null, 'Delete was successfull')); // TODO: trans
+ }
+}
diff --git a/app/Http/Controllers/Kits/PredefinedKitsController.php b/app/Http/Controllers/Kits/PredefinedKitsController.php
new file mode 100644
index 0000000000..36ebb27d5c
--- /dev/null
+++ b/app/Http/Controllers/Kits/PredefinedKitsController.php
@@ -0,0 +1,244 @@
+<?php
+namespace App\Http\Controllers;
+
+use App\Models\PredefinedKit;
+use App\Models\AssetModel;
+use App\Models\PredefinedModel;
+use App\Models\License;
+use App\Models\PredefinedLicence;
+use Illuminate\Support\Facades\DB;
+
+
+/**
+ * This controller handles all access kits management:
+ * list, add/remove/change
+ *
+ * @version v2.0
+ */
+class PredefinedKitsController extends Controller
+{
+ public function index()
+ {
+ //$this->authorize('index', PredefinedKit::class);
+ return view('kits/index');
+ }
+
+ /**
+ * Returns a form view to create a new asset maintenance.
+ *
+ * @see AssetMaintenancesController::postCreate() method that stores the data
+ * @author Vincent Sposato <[email protected]>
+ * @version v1.0
+ * @since [v1.8]
+ * @return mixed
+ */
+ public function create()
+ {
+ //$this->authorize('create', PredefinedKit::class);
+
+ return view('kits/edit')->with('item', new PredefinedKit);
+ }
+
+ /**
+ * Validate and process the new Predefined Kit data.
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v1.0]
+ * @return Redirect
+ */
+ public function store(ImageUploadRequest $request)
+ {
+ //$this->authorize('create', AssetModel::class);
+ // Create a new Predefined Kit
+ $kit = new PredefinedKit;
+
+ // Save the model data
+ $kit->name = $request->input('name');
+
+ if(!$kit->save()) {
+ return redirect()->back()->withInput()->withErrors($kit->getErrors());
+ }
+
+ $model_ids = $request->input('models');
+ if (!is_array($model_ids)) {
+ $model_ids = [];
+ }
+ $model_ids = array_filter($model_ids);
+
+ $license_ids = $request->get('selected_licenses');
+ if (!is_array($license_ids)) {
+ $license_ids = [];
+ }
+ $license_ids = array_filter($license_ids);
+
+ $success = DB::transaction(function() use($kit, $model_ids, $license_ids) {
+ $ret = $kit->save();
+ if($ret) {
+ $kit->models()->attach($model_ids); // MYTODO: проверить, что работает перед сохранением
+ $kit->licenses()->attach($license_ids);
+ }
+ return $ret;
+ });
+
+ if(!$success) {
+ return redirect()->back()->withInput()->withErrors($kit->getErrors());
+ }
+ return redirect()->route("models.index")->with('success', 'Kit was successfully created.'); // TODO: trans()
+ }
+
+ /**
+ * Returns a view containing the Predefined Kit edit form.
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v1.0]
+ * @param int $kitId
+ * @return View
+ */
+ public function edit($kitId = null)
+ {
+ $this->authorize('update', PredefinedKit::class);
+ if ($kit = PredefinedKit::find($kitId)) {
+ return view('kits/edit')
+ ->with('item', $kit)
+ ->with('models', $kit->models)
+ ->with('licenses', $kit->licenses);
+ }
+ return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans
+ }
+
+
+ /**
+ * Validates and processes form data from the edit
+ * Predefined Kit form based on the kit ID passed.
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v1.0]
+ * @param int $kitId
+ * @return Redirect
+ */
+ public function update(ImageUploadRequest $request, $kitId = null)
+ {
+ $this->authorize('update', PredefinedKit::class);
+ // Check if the kit exists
+ if (is_null($kit = PredefinedKit::find($kitId))) {
+ // 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) {
+ return redirect()->route("kits.index")->with('success', 'Kit was successfully updated'); // TODO: trans
+ }
+ return redirect()->back()->withInput()->withErrors($kit->getErrors());
+ }
+
+ /**
+ * Validate and delete the given Predefined Kit.
+ * Also delete all contained helping items
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v1.0]
+ * @param int $kitId
+ * @return Redirect
+ */
+ public function destroy($kitId)
+ {
+ $this->authorize('delete', PredefinedKit::class);
+ // Check if the kit exists
+ if (is_null($kit = PredefinedKit::find($kitId))) {
+ return redirect()->route('kits.index')->with('error', 'Kit not found'); // TODO: trans
+ }
+
+ // Delete childs
+ $kit->models()->delete();
+ $kit->licenses()->delete();
+ // Delete the kit
+ $kit->delete();
+
+ // Redirect to the kit management page
+ return redirect()->route('kits.index')->with('success', 'Kit was successfully deleted'); // TODO: trans
+ }
+
+ /**
+ * Get the model information to present to the model view page
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @since [v1.0]
+ * @param int $modelId
+ * @return View
+ */
+ public function show($modelId = null)
+ {
+ $this->authorize('view', AssetModel::class);
+ $model = AssetModel::withTrashed()->find($modelId);
+
+ if (isset($model->id)) {
+ return view('models/view', compact('model'));
+ }
+ // Prepare the error message
+ $error = trans('admin/models/message.does_not_exist', compact('id'));
+
+ // Redirect to the user management page
+ return redirect()->route('models.index')->with('error', $error);
+ }
+
+ /**
+ * Returns true if a fieldset is set, 'add default values' is ticked and if
+ * any default values were entered into the form.
+ *
+ * @param array $input
+ * @return boolean
+ */
+ private function shouldAddDefaultValues(array $input)
+ {
+ return !empty($input['add_default_values'])
+ && !empty($input['default_values'])
+ && !empty($input['custom_fieldset']);
+ }
+
+ /**
+ * Adds default values to a model (as long as they are truthy)
+ *
+ * @param AssetModel $model
+ * @param array $defaultValues
+ * @return void
+ */
+ private function assignCustomFieldsDefaultValues(AssetModel $model, array $defaultValues)
+ {
+ foreach ($defaultValues as $customFieldId => $defaultValue) {
+ if ($defaultValue) {
+ $model->defaultValues()->attach($customFieldId, ['default_value' => $defaultValue]);
+ }
+ }
+ }
+
+ /**
+ * Removes all default values
+ *
+ * @return void
+ */
+ private function removeCustomFieldsDefaultValues(AssetModel $model)
+ {
+ $model->defaultValues()->detach();
+ }
+}
diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php
index 94f5ca0bf3..02bf3dc072 100644
--- a/app/Providers/RouteServiceProvider.php
+++ b/app/Providers/RouteServiceProvider.php
@@ -63,6 +63,7 @@ class RouteServiceProvider extends ServiceProvider
require base_path('routes/web/fields.php');
require base_path('routes/web/components.php');
require base_path('routes/web/users.php');
+ require base_path('routes/web/kits.php');
require base_path('routes/web.php');
});
}
diff --git a/database/migrations/2018_10_18_191228_add_kits_licenses_table.php b/database/migrations/2018_10_18_191228_add_kits_licenses_table.php
new file mode 100644
index 0000000000..b600cad3af
--- /dev/null
+++ b/database/migrations/2018_10_18_191228_add_kits_licenses_table.php
@@ -0,0 +1,38 @@
+<?php
+
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddKitsLicensesTable extends Migration {
+
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ //
+ Schema::create('kits_licenses', function ($table) {
+ $table->increments('id');
+ $table->integer('kit_id')->nullable()->default(NULL);
+ $table->integer('license_id')->nullable()->default(NULL);
+ $table->integer('quantity')->default(1);
+ $table->timestamps();
+ });
+
+
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ //
+ Schema::drop('kits_licenses');
+ }
+
+}
diff --git a/database/migrations/2018_10_19_153910_add_kits_table.php b/database/migrations/2018_10_19_153910_add_kits_table.php
new file mode 100644
index 0000000000..949c150146
--- /dev/null
+++ b/database/migrations/2018_10_19_153910_add_kits_table.php
@@ -0,0 +1,37 @@
+<?php
+
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddKitsTable extends Migration {
+
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ //
+ Schema::create('kits', function ($table) {
+ $table->increments('id');
+ $table->string('name')->nullable()->default(NULL);
+ $table->timestamps();
+ $table->engine = 'InnoDB';
+ });
+
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ //
+ Schema::drop('kits');
+
+ }
+
+}
diff --git a/database/migrations/2018_10_19_154013_add_kits_models_table.php b/database/migrations/2018_10_19_154013_add_kits_models_table.php
new file mode 100644
index 0000000000..6f80df2da6
--- /dev/null
+++ b/database/migrations/2018_10_19_154013_add_kits_models_table.php
@@ -0,0 +1,38 @@
+<?php
+
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddKitsModelsTable extends Migration {
+
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ //
+ Schema::create('kits_models', function ($table) {
+ $table->increments('id');
+ $table->integer('kit_id')->nullable()->default(NULL);
+ $table->integer('model_id')->nullable()->default(NULL);
+ $table->integer('quantity')->default(1);
+ $table->timestamps();
+ });
+
+
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ //
+ Schema::drop('kits_models');
+ }
+
+}
diff --git a/resources/views/kits/edit.blade.php b/resources/views/kits/edit.blade.php
new file mode 100644
index 0000000000..d16d63e11a
--- /dev/null
+++ b/resources/views/kits/edit.blade.php
@@ -0,0 +1,79 @@
+@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')
+@stop
+
+@section('content')
+@parent
+<div class="row">
+ <div class="col-md-12">
+ <div class="box box-default">
+ <div class="box-header with-border">
+ <h3 class="box-title">Models</h3>
+ </div>
+ <div class="box-body">
+ <div class="table-responsive">
+ <table
+ data-cookie-id-table="kitModelsTable"
+ data-columns="{{ \App\Presenters\::modelsDataTableLayout() }}"
+ 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') }}"
+ 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-->
+</div>
+<div class="row">
+ <div class="col-md-12">
+ <div class="box box-default">
+ <div class="box-header with-border">
+ <h3 class="box-title">Licenses</h3>
+ </div>
+ <div class="box-body">
+ <div class="table-responsive">
+
+ <table
+ data-cookie-id-table="kitLicensesTable"
+ data-columns="{{ \App\Presenters\::licensesDataTableLayout() }}"
+ 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="kitLicensesTable"
+ class="table table-striped snipe-table"
+ data-url="{{ route('api.kits.licenses.index') }}"
+ 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-->
+ </div>
+@stop
\ No newline at end of file
diff --git a/resources/views/kits/index.blade.php b/resources/views/kits/index.blade.php
new file mode 100644
index 0000000000..c5e492f7bb
--- /dev/null
+++ b/resources/views/kits/index.blade.php
@@ -0,0 +1,49 @@
+@extends('layouts/default')
+
+{{-- Web site Title --}}
+@section('title')
+Kits
+@parent
+@stop
+
+@section('header_right')
+<a href="{{ route('kits.create') }}" class="btn btn-primary text-right">{{ trans('general.create') }}</a>
+@stop
+
+
+{{-- Content --}}
+@section('content')
+<div class="row">
+ <div class="col-md-12">
+ <div class="box box-default">
+ <div class="box-body">
+ <div class="table-responsive">
+
+ <table
+ data-cookie-id-table="kitsTable"
+ data-columns="{{ \App\Presenters\::dataTableLayout() }}"
+ 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="kitsTable"
+ class="table table-striped snipe-table"
+ data-url="{{ route('api.kits.index') }}"
+ data-export-options='{
+ "fileName": "export-kits-{{ date('Y-m-d') }}",
+ "ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
+ }'>
+ </table>
+ </div>
+ </div> <!--.box-body-->
+ </div> <!-- /.box.box-default-->
+ </div> <!-- .col-md-12-->
+</div>
+@stop
+@section('moar_scripts')
+@include ('partials.bootstrap-table', ['exportFile' => 'kits-export', 'search' => true])
+@stop
diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php
index 65ddfa4045..66a6d6360d 100644
--- a/resources/views/partials/bootstrap-table.blade.php
+++ b/resources/views/partials/bootstrap-table.blade.php
@@ -192,6 +192,52 @@
};
}
+ // 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 ((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-tooltip="true" '
+ + ' 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 handles the icons and display of polymorphic entries
function polymorphicItemFormatter(value) {
@@ -320,7 +366,11 @@
'companies',
'depreciations',
'fieldsets',
- 'groups'
+ 'groups',
+ 'kits',
+ // METODO: проверить, что эти пути работают
+ 'kits.models',
+ 'kits.licenses',
];
for (var i in formatters) {
@@ -330,6 +380,18 @@
window[formatters[i] + 'InOutFormatter'] = genericCheckinCheckoutFormatter(formatters[i]);
}
+ var childFormatters = [
+ ['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]);
+ }
+
+
// This is gross, but necessary so that we can package the API response
// for custom fields in a more useful way.
diff --git a/resources/views/partials/forms/edit/model-select.blade.php b/resources/views/partials/forms/edit/model-select.blade.php
index 48385b6a7a..0fd438acfb 100644
--- a/resources/views/partials/forms/edit/model-select.blade.php
+++ b/resources/views/partials/forms/edit/model-select.blade.php
@@ -5,12 +5,19 @@
<div class="col-md-7{{ ((isset($required) && ($required =='true'))) ? ' required' : '' }}">
<select class="js-data-ajax" data-endpoint="models" data-placeholder="{{ trans('general.select_model') }}" name="{{ $fieldname }}" style="width: 100%" id="model_select_id">
- @if ($model_id = Input::old($fieldname, (isset($item)) ? $item->{$fieldname} : ''))
+ @if (!isset($multiple)
+ && ($model_id = Input::old($fieldname, (isset($item)) ? $item->{$fieldname} : '')) )
<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>
+ @if (isset($multiple) && $models)
+ @foreach ($models as $model)
+ <option value="{{$model->id}}">{{$model->name}}</option>
+ @endforeach
+ @else
+ <option value="">{{ trans('general.select_model') }}</option>
+ @endif
@endif
</select>
diff --git a/routes/api.php b/routes/api.php
index d23adb046c..f5300b1e38 100644
--- a/routes/api.php
+++ b/routes/api.php
@@ -751,6 +751,82 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () {
[ 'as' => 'api.activity.index', 'uses' => 'ReportsController@index' ]
);
+ // kits
+ Route::resource('kits', 'PredefinedKitsController',
+ [
+ 'names' =>
+ [
+ 'index' => 'api.kits.index',
+ 'show' => 'api.kits.show',
+ 'store' => 'api.kits.store',
+ 'update' => 'api.kits.update',
+ 'destroy' => 'api.kits.destroy',
+ ],
+ 'except' => ['create', 'edit'],
+ 'parameters' => ['kit' => 'kit_id']
+ ]
+ );
+
+
+ Route::group([ 'prefix' => 'kits/{kit_id}' ], function () {
+
+ Route::get('licenses',
+ [
+ 'as' => 'api.kits.licenses.index',
+ 'uses' => 'PredefinedKitsController@indexLicenses',
+ ]
+ );
+
+ Route::post('licenses',
+ [
+ 'as' => 'api.kits.licenses.store',
+ 'uses' => 'PredefinedKitsController@storeLicense',
+ ]
+ );
+
+ Route::put('licenses/{license_id}',
+ [
+ 'as' => 'api.kits.licenses.update',
+ 'uses' => 'PredefinedKitsController@updateLicense',
+ ]
+ );
+
+ Route::delete('licenses/{license_id}',
+ [
+ 'as' => 'api.kits.licenses.destroy',
+ 'uses' => 'PredefinedKitsController@destroyLicense',
+ ]
+ );
+
+
+ Route::get('models',
+ [
+ 'as' => 'api.kits.models.index',
+ 'uses' => 'PredefinedKitsController@indexModels',
+ ]
+ );
+
+ Route::post('models',
+ [
+ 'as' => 'api.kits.models.store',
+ 'uses' => 'PredefinedKitsController@storeModel',
+ ]
+ );
+
+ Route::put('models/{model_id}',
+ [
+ 'as' => 'api.kits.models.update',
+ 'uses' => 'PredefinedKitsController@updateModel',
+ ]
+ );
+ Route::delete('models/{model_id}',
+ [
+ 'as' => 'api.kits.models.destroy',
+ 'uses' => 'PredefinedKitsController@destroyModel',
+ ]
+ );
+ }); // kits
+
});
diff --git a/routes/web/kits.php b/routes/web/kits.php
new file mode 100644
index 0000000000..cecd86f597
--- /dev/null
+++ b/routes/web/kits.php
@@ -0,0 +1,70 @@
+<?php
+
+// Predefined Kit Management
+Route::resource('kit', 'Kits\PredefinedKitController', [
+ 'middleware' => ['auth'],
+ 'parameters' => ['kit' => 'kit_id']
+]);
+
+
+
+Route::group([ 'prefix' => 'kits/{kit_id}', 'middleware' => ['auth'] ], function () {
+
+ Route::get('licenses',
+ [
+ 'as' => 'kits.licenses.index',
+ 'uses' => 'Kits\PredefinedKitsController@indexLicenses',
+ ]
+ );
+
+ Route::post('licenses',
+ [
+ 'as' => 'kits.licenses.store',
+ 'uses' => 'Kits\PredefinedKitsController@storeLicense',
+ ]
+ );
+
+ Route::put('licenses/{license_id}',
+ [
+ 'as' => 'kits.licenses.update',
+ 'uses' => 'Kits\PredefinedKitsController@updateLicense',
+ ]
+ );
+
+ Route::delete('licenses/{license_id}',
+ [
+ 'as' => 'kits.licenses.destroy',
+ 'uses' => 'Kits\PredefinedKitsController@destroyLicense',
+ ]
+ );
+
+
+ Route::get('models',
+ [
+ 'as' => 'kits.models.index',
+ 'uses' => 'Kits\PredefinedKitsController@indexModels',
+ ]
+ );
+
+ Route::post('models',
+ [
+ 'as' => 'kits.models.store',
+ 'uses' => 'Kits\PredefinedKitsController@storeModel',
+ ]
+ );
+
+ Route::put('models/{model_id}',
+ [
+ 'as' => 'kits.models.update',
+ 'uses' => 'Kits\PredefinedKitsController@updateModel',
+ ]
+ );
+
+ Route::delete('models/{model_id}',
+ [
+ 'as' => 'kits.models.destroy',
+ 'uses' => 'Kits\PredefinedKitsController@destroyModel',
+ ]
+ );
+
+}); // kits
\ No newline at end of file