Skip to content
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

Saved Custom Report Templates #15714

Merged
merged 178 commits into from
Dec 19, 2024
Merged

Conversation

marcusmoore
Copy link
Collaborator

@marcusmoore marcusmoore commented Oct 22, 2024

Description

This PR introduces the concept of Saved Custom Asset Report Templates so users that frequently run Custom Asset Reports can load a customized pre-defined template instead of having to select all of the options they want each time.


Overview of Feature

New Custom Asset Report page with new options to open saved template or created a new one with the selected options
New Custom Report page

So if you select some options, enter a name and hit save
Populated before saving

You'll be redirected to the saved template and can hit Generate like normal at the bottom of the page
Viewing Saved Template

You can select existing saved templates upon returning the Custom Asset Report page in the future from the menu on the top left of the page
Open Saved Template menu

Templates can be updated by clicking the yellow pencil icon, updating selections, and hitting the Save button at the bottom of the page
Updating Saved template

Templates can also be (soft) deleted by clicking the red trash icon
Delete Modal

Technical Details / Decisions

Here are some decisions that were made in this PR that we might want to change before merging:

  • The newly introduced ReportTemplate
    • Uses soft deletes but there is not currently a way to restore deleted templates
    • Is scoped to the user for this first pass at the feature
    • An observer for the model was not added and activity reporting is done inside the model via the booted() method.
    • Similarly, A dedicated form request class was not created and inline validation is used instead.
    • The ReportTemplate model's name field does not have a unique constraint on it. This will make it easier to handle any duplicate names issues when reports are eventually sharable.
  • The reports.view permission was re-used for managing saved templates.
  • The null-object pattern (an empty ReportTemplate) was used to simplify changes to the view (avoid adding a bunch of if checks to see if the user is working with a saved template or generating a report on the fly). This is seen in the modifications to the existing ReportsController.

(Potential) Future Improvements

  • Allow sharing templates between either globally or per user/company/etc
  • Allow duplicating templates
  • Allow scheduling reports

Big shoutout to @akemidx for kicking this off and pairing throughout!


Fixes #4616

Type of change

  • New feature (non-breaking change which adds functionality)

@mcarasso-PPD
Copy link

mcarasso-PPD commented Nov 7, 2024

can the save templates be used to automate weekly reports?

@marcusmoore
Copy link
Collaborator Author

@mcarasso-PPD not in this first version of the feature but it's something we're exploring for a future release.

Comment on lines +48 to +84
static::created(function (ReportTemplate $reportTemplate) {
$logAction = new Actionlog([
'item_type' => ReportTemplate::class,
'item_id' => $reportTemplate->id,
'created_by' => auth()->id(),
]);

$logAction->logaction('create');
});

static::updated(function (ReportTemplate $reportTemplate) {
$changed = [];

foreach ($reportTemplate->getDirty() as $key => $value) {
$changed[$key] = [
'old' => $reportTemplate->getOriginal($key),
'new' => $reportTemplate->getAttribute($key),
];
}

$logAction = new Actionlog();
$logAction->item_type = ReportTemplate::class;
$logAction->item_id = $reportTemplate->id;
$logAction->created_by = auth()->id();
$logAction->log_meta = json_encode($changed);
$logAction->logaction('update');
});

static::deleted(function (ReportTemplate $reportTemplate) {
$logAction = new Actionlog([
'item_type' => ReportTemplate::class,
'item_id' => $reportTemplate->id,
'created_by' => auth()->id(),
]);

$logAction->logaction('delete');
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Understandable if we want to move these to an observer.

@marcusmoore marcusmoore marked this pull request as ready for review November 19, 2024 22:53
@marcusmoore marcusmoore requested a review from snipe as a code owner November 19, 2024 22:53
@marcusmoore
Copy link
Collaborator Author

@snipe friendly ping on this PR. I know it's a lot of changes but it is mostly additions for the new feature so hopefully it is easier to review.

@snipe snipe changed the title WIP: Saved Custom Report Templates Saved Custom Report Templates Dec 19, 2024
@snipe snipe merged commit 15296d2 into snipe:develop Dec 19, 2024
8 of 9 checks passed
@marcusmoore marcusmoore deleted the saving_custom_report_template branch December 19, 2024 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants