Skip to content

A free open source IT asset/license management system

Implement ability to delete templates

Marcus Moore0504c09a9a12
diff --git a/app/Http/Controllers/ReportTemplatesController.php b/app/Http/Controllers/ReportTemplatesController.php
index daefab2219..f4d9ac02fe 100644
--- a/app/Http/Controllers/ReportTemplatesController.php
+++ b/app/Http/Controllers/ReportTemplatesController.php
@@ -76,4 +76,22 @@ class ReportTemplatesController extends Controller
return redirect()->route('report-templates.show', $reportTemplate->id);
}
+
+ public function destroy($reportId)
+ {
+ $this->authorize('reports.view');
+
+ $reportTemplate = ReportTemplate::find($reportId);
+
+ if (!$reportTemplate) {
+ // @todo: what is the behavior we want?
+ return redirect()->route('reports/custom')
+ ->with('error', 'Template does not exist or you do not have permission to delete it.');
+ }
+
+ $reportTemplate->delete();
+
+ return redirect()->route('reports/custom')
+ ->with('success', 'Template deleted.');
+ }
}
diff --git a/resources/views/reports/custom.blade.php b/resources/views/reports/custom.blade.php
index d9da2d61d7..305104c02d 100644
--- a/resources/views/reports/custom.blade.php
+++ b/resources/views/reports/custom.blade.php
@@ -47,26 +47,16 @@
<i class="fas fa-pencil-alt" aria-hidden="true"></i>
<span class="sr-only">{{ trans('general.update') }}</span>
</a>
-
-{{-- This is from the license.view page--
- See line 1077 in routes.api for example of routing
-{{-- <a class="btn delete-asset btn-danger btn-sm" href="{{ route('delete/licensefile', [$license->id, $file->id]) }}" data-content="{{ trans('general.delete_confirm', ['item' => $file->filename]) }}" data-title="{{ trans('general.delete') }}">--}}
-{{-- <i class="fas fa-trash icon-white" aria-hidden="true"></i>--}}
-{{-- <span class="sr-only">{{ trans('general.delete') }}</span>--}}
-{{-- </a>--}}
-
- {{-- these were pulled from hardware.index and the one below doesn't work...--}}
- <a
- href="#"
- class="actions btn btn-danger btn-sm delete-report" {{--This was delete-asset as a class. We'd need to make a delete-report class--}}
- data-tooltip="true"
+ <button
+ class="btn btn-sm btn-danger delete-asset"
data-toggle="modal"
- data-content="Are you sure you wish to delete 1260505622?"
- data-title="Delete"
- onclick="return false;"
+ data-title="{{ trans('general.delete') }}"
+ data-content="{{ trans('general.delete_confirm', ['item' => $reportTemplate->name]) }}"
+ data-target="#dataConfirmModal"
+ type="button"
>
- <i class="fas fa-trash" aria-hidden="true"></i><span class="sr-only">{{ trans('general.delete') }}</span>
- </a>
+ <i class="fas fa-trash" aria-hidden="true"></i><span class="sr-only">{{ trans('general.delete') }}</span>
+ </button>
</div>
@endif
</div><!-- /.box-header -->
@@ -518,5 +508,12 @@
form.attr('action', '{{ route('report-templates.store') }}').submit();
});
+ $('#dataConfirmModal').on('show.bs.modal', function (event) {
+ var content = $(event.relatedTarget).data('content');
+ var title = $(event.relatedTarget).data('title');
+ $(this).find(".modal-body").text(content);
+ $(this).find(".modal-header").text(title);
+ });
+
</script>
@stop
diff --git a/routes/web.php b/routes/web.php
index 7e19306c19..32263816aa 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -360,7 +360,8 @@ Route::group(['middleware' => ['auth']], function () {
Route::post('reports/saved-templates', [ReportTemplatesController::class, 'store'])->name('report-templates.store');
Route::get('reports/saved-templates/{reportId}', [ReportTemplatesController::class, 'show'])->name('report-templates.show');
Route::get('reports/saved-templates/{reportId}/edit', [ReportTemplatesController::class, 'edit'])->name('report-templates.edit');
- Route::post('report/saved-templates/{reportId}', [ReportTemplatesController::class, 'update'])->name('report-templates.update');
+ Route::post('reports/saved-templates/{reportId}', [ReportTemplatesController::class, 'update'])->name('report-templates.update');
+ Route::delete('reports/saved-templates/{reportId}', [ReportTemplatesController::class, 'destroy'])->name('report-templates.destroy');
Route::get(
'reports/activity',