Skip to content

Feature: Ad-Hoc Notes on Assets #15525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jan 14, 2025
Merged

Conversation

akemidx
Copy link
Member

@akemidx akemidx commented Sep 19, 2024

The ability to add a note to an asset uncoupled from an action (such as Checkin)

A pop-up window will open, and the note will save to the Asset History (as well as the activity log)

This replaces #14987

Screenshot 2024-09-18 at 10 46 41 PM Screenshot 2024-06-27 at 5 38 05 PM Screenshot 2024-06-27 at 5 38 59 PM

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Ran snipe-it test suite through command line

Test Configuration:

  • PHP version: 8.1

Checklist:

Copy link

what-the-diff bot commented Sep 19, 2024

PR Summary

  • Introduction of Note Handling Functionality
    The system now has a capability to handle notes. A dedicated NoteAdded event is created which triggers upon the addition of notes.

  • Creation of NotesController
    A new controller is added to manage tasks related to notes. In its functionality, it includes the store method which is used for saving notes.

  • Update in Icon Representer
    An update for 'note' and 'notes' icons is added in the IconHelper. This implies a visual representation for notes can now be observed.

  • LogListener for noting actions
    A listener keeps the log whenever a note is added, ensuring traceability and accountability of note additions.

  • Development of Note Model
    Creation of a new model, Note, allows the system to maintain a morph relation for the commentable entity.

  • Localization Strings for Notes
    To support extended reach, localized strings for "Note Added" and "Add Note" are introduced.

  • Update in Modal Interface
    Update in the ModalController includes the 'add-note' entry, offering a more seamless interface for note addition.

  • New Modal View for Adding Notes
    A new modal view add-note.blade.php is created for adding notes, increasing usability and user experience.

  • JavaScript File Modification for Modal Note Addition
    The JavaScript file has been reconfigured to handle the modal interface for note additions, enhancing the fluidity in the operations.

  • API Routes for Note Handling
    New API routes for more efficient note handling are added under the 'notes' prefix, improving connectivity and response.

  • Update on Hardware View
    The hardware view is updated to include an option for adding notes, offered only to the ones with appropriate permissions, enhancing security and better organization of notes.

@akemidx
Copy link
Member Author

akemidx commented Sep 19, 2024

note: assets need to be rebuilt for note modal to close on save

@marcusmoore
Copy link
Collaborator

Taking a look at this now 👍🏾

Copy link
Collaborator

@marcusmoore marcusmoore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple minor notes but otherwise this is solid 💪🏾

@akemidx akemidx mentioned this pull request Sep 25, 2024
10 tasks
@marcusmoore marcusmoore self-requested a review September 26, 2024 16:37
Copy link
Member Author

@akemidx akemidx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes made

@marcusmoore marcusmoore requested a review from snipe September 26, 2024 19:50
Copy link
Collaborator

@marcusmoore marcusmoore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍🏾

@akemidx
Copy link
Member Author

akemidx commented Nov 26, 2024

@uberbrady
Screenshot 2024-11-26 at 3 12 47 PM
Screenshot 2024-11-26 at 3 12 58 PM
Screenshot 2024-11-26 at 3 13 16 PM
Screenshot 2024-11-26 at 3 13 44 PM

if(!id || !name) {
console.error("Could not find resulting name or ID from modal-create. Name: "+name+", id: "+id);
return false;
if(!hasnopayload) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we'd need this? The modal is just a form post

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The note that is added doesn't have an id (it's not an actual modal) and the existing code expects the response to have an id (var id = result.payload.id). The if check allows getting around that chunk of expectations without re-writing too much of the existing functionality.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should not require any payload. It should post to the controller, same as files and every other modal (except for the dynamic ones, via the "new" buttons).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without looking into it, I think this follows the same pattern, but I think we might be talking about different things?

The existing modal code expects an id to come back in the response after the thing is created:

https://github.com/snipe/snipe-it/blob/a0bab70def63f7d0994c517734ffda40963d9912/resources/assets/js/snipeit_modals.js#L125-L132

In this implementation, notes don't actually have an id because they are stored in the action log so the introduction of this parameter is to skip the existing logic that expects it in the response.

In other words, without the added if check we would hit the return false on line 129 and the modal wouldn't close even though the note was saved. I suggested this approach as a way to avoid re-writing too much of the existing modal code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re looking at the bespoke modal code - look at the regular file upload modal. There is no callback needed here. It’s just a regular form in a modal

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see what you're saying now. Thanks for diving deeper.

The benefit of the current approach is that we're exposing and hitting a dedicated API endpoint for creating notes but we can switch that over if we don't want to do that?

@akemidx if we do switch it over then instead of doing onsubmit="return false" in the add-note template we can do what the upload-file template does and fire off a regular form submission which results in the page refreshing. Then the new stuff in snipeit_modals.js can be removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did we net out on decisions here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...

@@ -184,7 +184,9 @@ public static function icon($type) {
return 'fa-regular fa-id-card';
case 'department' :
return 'fa-solid fa-building-user';

case 'note':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what this is doing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is called at line 260 on the hardware.view blade
<x-icon type="note" />
it gives us the icon on the Add Note button
Screenshot 2024-12-09 at 9 25 13 PM

Copy link
Member Author

@akemidx akemidx Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this mimics the rest of our icon typing in the IconHelper such as

case 'assets':
case 'asset':
     return 'fas fa-barcode';
case 'accessories':
case 'accessory':
     return 'far fa-keyboard';

@snipe
Copy link
Member

snipe commented Dec 9, 2024

See my comments. I also think probably "Add Note" as a title for the modal and "Add Note" as the form prompt seems redundant. I'd either change the text or remove the label.

@snipe
Copy link
Member

snipe commented Dec 16, 2024

@uberbrady and I have been discussing this PR (and feature overall) and I think we're sort of split on 1) whether the user should be able to edit a note and 2) if yes to the first question, are we actually going to edit the action_logs record, or mark the existing one as deleted and add a new one? In the system as it is, we never edit/delete log records, so if we did decide to allow editing (and if we don't, people will 100% ask for it as soon as this is released), we need to figure out the UI and the actual mechanics of how that looks.

I'm okay accepting it (when the outstanding questions have been addressed) without an edit function, but it will be something we'll need to add soon after IMHO.

We can discuss this on the dev meeting later today tho. I personally do not like to make exceptions except when absolutely necessary, and action_logs are - as of now - sacrosanct. My leaning is towards never actually deleting the note, but soft-deleting - and doing the same on an edit - a soft-delete of the old and a new record for the "updated" version, and we can handle the display accordingly.

@marcusmoore
Copy link
Collaborator

From a high level, to me, it seems like a user should be able to edit a note and have that logged as an action.

At a lower level, I heavily lean towards not modifying action logs.

As for the implementation, the original version of this had Note as an eloquent model. Maybe going back to that method would make this easier now and in the future? (I forget why we moved away from the eloquent model approach so it might be totally valid that it won't work.)

@snipe
Copy link
Member

snipe commented Dec 16, 2024

It does seem like it could make sense to have Notes be an eloquent model, since as soon as we release this for assets, folks are going to want it everywhere. Weird tho since it doesn't have its own table, as most Eloquent models do.

I agree on not changing the behavior of action_logs. It just feels kinda gross and weird. I think we mark the old one as deleted (also a first for us, but less destructive) and then add a new one.

@akemidx
Copy link
Member Author

akemidx commented Dec 16, 2024

We should definitely NOT edit the action logs. if anything it would be another entry to the action logs when note edit is made. And while this can get messy, at some point you just have to let people constantly edit their notes and make logs. (i've actually used logs to see users/sytem/etc fighting back and forth over an edit.) Soft delete could work. There is another idea that I have that is a separate feature, and I dare not unleash that can of worms just yet.

I think the Eloquent model approach was just overly complicated (at the time) for what we were doing and we kinda scoped down after a dev meeting or something. could also have been something to do with the modal, but my notes are a bit iffy about why we switched.

@snipe
Copy link
Member

snipe commented Dec 16, 2024

We probably also need a UI to delete notes. For a longer-lived device (not laptops, but, say, oil rigs or vehicles) those notes could get very out of hand. I think we need to log that as an event as well tho.

@snipe
Copy link
Member

snipe commented Dec 16, 2024

If we do the way we've just discussed, we'd need to introduce a few new actions. add_note, edit_note, and delete_note, since we want all of those actions reflected in the history, but also want to be able to filter on them for display and reporting purposes.

@snipe
Copy link
Member

snipe commented Dec 16, 2024

(Or, if Notes is its own model, we can use the regular create/update/delete action_types with App\Models\Notes as the target_type.)

@akemidx
Copy link
Member Author

akemidx commented Dec 16, 2024

Yes, I was thinking of something akin to reporting on the action log. and I agree on those actions.

@@ -31,4 +31,13 @@ public function store(Request $request)

return response()->json(Helper::formatStandardApiResponse('success'));
}

public function update(Request $request)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are stubs, yes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, those are not complete. that was all framing for my edification. Sorry for any confusion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries - just clarifying :)

@marcusmoore marcusmoore self-requested a review December 17, 2024 20:50
@snipe snipe merged commit 1c8d94c into grokability:develop Jan 14, 2025
8 of 9 checks passed
marcusmoore added a commit to marcusmoore/snipe-it that referenced this pull request Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants