snipe / snipe-it

A free open source IT asset/license management system
https://snipeitapp.com
GNU Affero General Public License v3.0
10.84k stars 3.14k forks source link

[Feature Request]: Asset History of a Location #13754

Open ntbutler-nbcs opened 11 months ago

ntbutler-nbcs commented 11 months ago

Is your feature request related to a problem? Please describe.

Snipe-IT has the ability to view the asset history of a user (e.g, via https://snipe.it.host/users/1000#history) and the history of a particular asset (e.g, via https://snipe.it.host/hardware/1000#history), but not for a location.

We assign assets to locations where that makes sense, e.g. a Television or phone to a meeting room. We are able to see the currently assigned assets, but not a history of what assets have been assigned to that location.

Describe the solution you'd like

We would like to see a view of the history of asset activity in a selected location, and not just the view of assets that are currently assigned

Describe alternatives you've considered

No response

Additional context

No response

ntbutler-nbcs commented 10 months ago

So I thought I'd give it a go to get this underway, but my Laravel-fu isn't quite there yet to get the activity report for a location from the Api\ReportsController.

In the resources\views\locations\view.blade.php file, I added the following to the nav UL for the tab:

                <li>
                  <a href="#history" data-toggle="tab">
                    <span class="hidden-lg hidden-md">
                        <i class="fas fa-hdd fa-2x" aria-hidden="true"></i>
                    </span>
                      <span class="hidden-xs hidden-sm">
                          {{ trans('general.history') }}
                    </span>
                  </a>
              </li>

And I added the following to the tab-content div for the table structure:

                <div class="tab-pane" id="history">
                    <h2 class="box-title">{{ trans('general.history') }}</h2>
                    <!-- checked out assets table -->
                    <div class="row">
                        <div class="col-md-12">
                            <table
                                    class="table table-striped snipe-table"
                                    id="assetHistory"
                                    data-pagination="true"
                                    data-id-table="assetHistory"
                                    data-search="true"
                                    data-side-pagination="server"
                                    data-show-columns="true"
                                    data-show-fullscreen="true"
                                    data-show-refresh="true"
                                    data-sort-order="desc"
                                    data-sort-name="created_at"
                                    data-show-export="true"
                                    data-export-options='{
                        "fileName": "export-location-asset-{{  $location->id }}-history",
                        "ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
                    }'

                    data-url="{{ route('api.activity.index', ['item_id' => $location->id, 'item_type' => 'location']) }}"
                    data-cookie-id-table="assetHistory"
                    data-cookie="true">
                                <thead>
                                    <tr>
                                        <th data-visible="true" data-field="icon" style="width: 40px;" class="hidden-xs" data-formatter="iconFormatter">{{ trans('admin/hardware/table.icon') }}</th>
                                        <th class="col-sm-2" data-visible="true" data-field="action_date" data-formatter="dateDisplayFormatter">{{ trans('general.date') }}</th>
                                        <th class="col-sm-1" data-visible="true" data-field="admin" data-formatter="usersLinkObjFormatter">{{ trans('general.admin') }}</th>
                                        <th class="col-sm-1" data-visible="true" data-field="action_type">{{ trans('general.action') }}</th>
                                        <th class="col-sm-2" data-visible="true" data-field="item" data-formatter="polymorphicItemFormatter">{{ trans('general.item') }}</th>
                                        <th class="col-sm-2" data-visible="true" data-field="target" data-formatter="polymorphicItemFormatter">{{ trans('general.target') }}</th>
                                        <th class="col-sm-2" data-field="note">{{ trans('general.notes') }}</th>
                                        <th class="col-md-3" data-field="signature_file" data-visible="false"  data-formatter="imageFormatter">{{ trans('general.signature') }}</th>
                                        <th class="col-md-3" data-visible="false" data-field="file" data-visible="false"  data-formatter="fileUploadFormatter">{{ trans('general.download') }}</th>
                                        <th class="col-sm-2" data-field="log_meta" data-visible="true" data-formatter="changeLogFormatter">{{ trans('admin/hardware/table.changed')}}</th>
                                    </tr>
                                </thead>
                            </table>
                        </div>
                    </div> <!-- /.row -->
                </div> <!-- /.tab-pane history -->

Now I'm quite sure the issue is just the data-URL line

   data-url="{{ route('api.activity.index', ['item_id' => $location->id, 'item_type' => 'location']) }}"

But I haven't yet got my head around how the Api\ReportsController can return the asset history for a location. Am I missing something basic, should I be trying to pull the data via another route, or does the ReportsController need further work for this?

ntbutler-nbcs commented 10 months ago

And wouldn't you know it - just after posting, I think I was able to track down the correct method:

data-url="{{ route('api.activity.index', ['target_id' => $location->id, 'target_type' => 'location']) }}"

I'll do a little more testing, but if all that is working as expected, I'll have a PR shortly