Skip to content

Commit b0fa059

Browse files
authored
Merge pull request #16285 from marcusmoore/bug/sc-28148
Re-added ability to add notes to assets
2 parents 3fb00a9 + c6bee0c commit b0fa059

File tree

12 files changed

+156
-232
lines changed

12 files changed

+156
-232
lines changed

app/Events/NoteAdded.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

app/Http/Controllers/Api/NotesController.php

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Models\Actionlog;
6+
use App\Models\Asset;
7+
use Illuminate\Http\Request;
8+
use Illuminate\Support\Facades\Auth;
9+
use Illuminate\Validation\Rule;
10+
11+
class NotesController extends Controller
12+
{
13+
public function store(Request $request)
14+
{
15+
$this->authorize('update', Asset::class);
16+
17+
$validated = $request->validate([
18+
'id' => 'required',
19+
'note' => 'required|string|max:500',
20+
'type' => [
21+
'required',
22+
Rule::in(['asset']),
23+
],
24+
]);
25+
26+
$item = Asset::findOrFail($validated['id']);
27+
28+
$this->authorize('update', $item);
29+
30+
$logaction = new Actionlog;
31+
$logaction->item_id = $item->id;
32+
$logaction->item_type = get_class($item);
33+
$logaction->note = $validated['note'];
34+
$logaction->created_by = Auth::id();
35+
$logaction->logaction('note added');
36+
37+
return redirect()
38+
->route('hardware.show', $validated['id'])
39+
->withFragment('history')
40+
->with('success', trans('general.note_added'));
41+
}
42+
}

app/Listeners/LogListener.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use App\Events\ItemDeclined;
1818
use App\Events\LicenseCheckedIn;
1919
use App\Events\LicenseCheckedOut;
20-
use App\Events\NoteAdded;
2120
use App\Models\Actionlog;
2221
use App\Models\User;
2322
use App\Models\LicenseSeat;
@@ -129,23 +128,6 @@ public function onUserMerged(UserMerged $event)
129128

130129
}
131130

132-
133-
/**
134-
* Note is added to action log
135-
*
136-
*/
137-
public function onNoteAdded(NoteAdded $event)
138-
{
139-
$logaction = new Actionlog();
140-
$logaction->item_id = $event->itemNoteAddedOn->id;
141-
$logaction->item_type = get_class($event->itemNoteAddedOn);
142-
$logaction->note = $event->note; //this is the received alphanumeric text from the box
143-
$logaction->created_by = $event->noteAddedBy->id;
144-
$logaction->action_type = 'note_added';
145-
$logaction->save();
146-
}
147-
148-
149131
/**
150132
* Register the listeners for the subscriber.
151133
*

resources/assets/js/snipeit_modals.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ $(function () {
2828

2929
var baseUrl = $('meta[name="baseUrl"]').attr('content');
3030
//handle modal-add-interstitial calls
31-
var model, select, refreshSelector, hasnopayload;
31+
var model, select, refreshSelector;
3232

3333
if($('#createModal').length == 0) {
3434
$('body').append('<div class="modal fade" id="createModal"></div><!-- /.modal -->');
@@ -40,8 +40,6 @@ $(function () {
4040
select = link.data("select");
4141
refreshSelector = link.data("refresh");
4242

43-
hasnopayload = link.data("hasnopayload");
44-
4543
$('#createModal').load(link.attr('href'),function () {
4644

4745
// this sets the focus to be the name field
@@ -123,13 +121,12 @@ $(function () {
123121
$('#modal_error_msg').html(error_message).show();
124122
return false;
125123
}
126-
if(!hasnopayload) {
127-
var id = result.payload.id;
128-
var name = result.payload.name || (result.payload.first_name + " " + result.payload.last_name);
129-
if (!id || !name) {
130-
console.error("Could not find resulting name or ID from modal-create. Name: " + name + ", id: " + id);
131-
return false;
132-
}
124+
125+
var id = result.payload.id;
126+
var name = result.payload.name || (result.payload.first_name + " " + result.payload.last_name);
127+
if (!id || !name) {
128+
console.error("Could not find resulting name or ID from modal-create. Name: " + name + ", id: " + id);
129+
return false;
133130
}
134131
$('#createModal').modal('hide');
135132
$('#createModal').html("");

resources/views/hardware/view.blade.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,13 @@
217217

218218
<!-- Add notes -->
219219
@can('update', \App\Models\Asset::class)
220-
<!--
221-
222220
<div class="col-md-12 hidden-print" style="padding-top: 5px;">
223-
<a href='{{ route('modal.show', 'add-note') }}?type=asset&id={{$asset->id}}' style="width: 100%" data-toggle="modal" data-target="#createModal" data-select='add-note_select_id' data-refresh="assetHistory" data-hasnopayload="true" class="btn btn-sm btn-primary btn-block btn-social hidden-print">
221+
<a href="#" style="width: 100%" data-toggle="modal" data-target="#createNoteModal" class="btn btn-sm btn-primary btn-block btn-social hidden-print">
224222
<x-icon type="note" />
225-
{{ trans('general.add_note') }}</a>
223+
{{ trans('general.add_note') }}
224+
</a>
225+
@include ('modals.add-note', ['type' => 'asset', 'id' => $asset->id])
226226
</div>
227-
-->
228227
@endcan
229228

230229

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
11
{{-- See snipeit_modals.js for what powers this --}}
2-
<div class="modal-dialog">
3-
<div class="modal-content">
4-
<div class="modal-header">
5-
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
6-
<h2 class="modal-title">{{ trans('general.add_note') }}</h2>
7-
</div>
2+
<div class="modal fade" id="createNoteModal" tabindex="-1" role="dialog" aria-labelledby="createNoteModalLabel" aria-hidden="true">
3+
<div class="modal-dialog">
4+
<div class="modal-content">
5+
<div class="modal-header">
6+
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
7+
<h2 class="modal-title" id="createNoteModalLabel">{{ trans('general.add_note') }}</h2>
8+
</div>
9+
<form
10+
method="POST"
11+
action="{{ route('notes.store') }}"
12+
accept-charset="UTF-8"
13+
>
14+
@csrf
15+
<input type="hidden" name="type" value="{{$type}}"/>
16+
<input type="hidden" name="id" value="{{$id}}"/>
817

9-
<div class="modal-body">
10-
<form action="{{ route('api.notes.store') }}" onsubmit="return false">
11-
<input type="hidden" name="type" value="{{request("type")}}"/>
12-
<input type="hidden" name="id" value="{{request("id")}}"/>
13-
<div class="alert alert-danger" id="modal_error_msg" style="display:none"></div>
18+
<div class="modal-body">
19+
<div class="alert alert-danger" id="modal_error_msg" style="display:none"></div>
1420

15-
<div class="row">
16-
<div class="col-md-12">
17-
<textarea class="form-control" id="note" name="note">{{ old('note') }}</textarea>
18-
{!! $errors->first('note', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
21+
<div class="row">
22+
<div class="col-md-12">
23+
<textarea class="form-control" id="note" name="note" required>{{ old('note') }}</textarea>
24+
{!! $errors->first('note', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
25+
</div>
1926
</div>
2027
</div>
28+
<div class="modal-footer">
29+
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">{{ trans('button.cancel') }}</button>
30+
<button type="submit" class="btn btn-primary pull-right" id="modal-save">{{ trans('general.save') }}</button>
31+
</div>
2132
</form>
22-
</div>
23-
<div class="modal-footer">
24-
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">{{ trans('button.cancel') }}</button>
25-
<button type="button" class="btn btn-primary pull-right" id="modal-save">{{ trans('general.save') }}</button>
26-
</div>
27-
</div><!-- /.modal-content -->
28-
</div><!-- /.modal-dialog -->
33+
</div><!-- /.modal-content -->
34+
</div><!-- /.modal-dialog -->
35+
</div>

routes/api.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,20 +1302,6 @@
13021302
)->name('api.activity.index');
13031303
}); // end reports api routes
13041304

1305-
/**
1306-
* Notes API routes
1307-
*/
1308-
1309-
Route::group(['prefix' => 'notes'], function () {
1310-
1311-
Route::post(
1312-
'/',
1313-
[ Api\NotesController::class,
1314-
'store'
1315-
]
1316-
)->name('api.notes.store');
1317-
}); // end notes api routes
1318-
13191305

13201306

13211307
/**

routes/web.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use App\Http\Controllers\LocationsController;
1717
use App\Http\Controllers\ManufacturersController;
1818
use App\Http\Controllers\ModalController;
19+
use App\Http\Controllers\NotesController;
1920
use App\Http\Controllers\ProfileController;
2021
use App\Http\Controllers\ReportTemplatesController;
2122
use App\Http\Controllers\ReportsController;
@@ -468,6 +469,9 @@
468469

469470
});
470471

472+
Route::group(['middleware' => ['auth']], function () {
473+
Route::post('notes', [NotesController::class, 'store'])->name('notes.store');
474+
});
471475

472476
Route::group(['prefix' => 'reports', 'middleware' => ['auth']], function () {
473477

tests/Feature/Notes/AssetNotesTest.php

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)