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

[4.0][Bug] Print button is missing from the Show view #2296

Closed
tifaahmed opened this issue Dec 15, 2019 · 6 comments · Fixed by #2389
Closed

[4.0][Bug] Print button is missing from the Show view #2296

tifaahmed opened this issue Dec 15, 2019 · 6 comments · Fixed by #2389

Comments

@tifaahmed
Copy link

Bug report

What I did

    $this->crud->enableExportButtons();

What I expected to happen

like version 3.6
after click the (show button) see page with (print button) to print the data in the page

What happened

(print button) not exists in the new version

What I've already tried to fix it

    $this->crud->enableExportButtons();

Backpack, Laravel, PHP, DB version

@ziming
Copy link
Contributor

ziming commented Dec 16, 2019

Press Ctrl P in the show page.

@karandatwani92
Copy link
Contributor

To Maintain Genericity and to print each Item as per it's own layout. It did the following:

1)Created Print Operation

<?php

namespace App\Http\Controllers\Admin\Operations;

use Illuminate\Support\Facades\Route;

trait PrintOperation
{
    /**
     * Define which routes are needed for this operation.
     *
     * @param string $segment    Name of the current entity (singular). Used as first URL segment.
     * @param string $routeName  Prefix of the route name.
     * @param string $controller Name of the current CrudController.
     */
    protected function setupPrintRoutes($segment, $routeName, $controller)
    {
        Route::get($segment.'/{id}/print', [
            'as'        => $routeName.'.print',
            'uses'      => $controller.'@print',
            'operation' => 'print',
        ]);
    }

    /**
     * Add the default settings, buttons, etc that this operation needs.
     */
    protected function setupPrintDefaults()
    {
        $this->crud->allowAccess('print');

        $this->crud->operation('print', function () {
            $this->crud->loadDefaultOperationSettingsFromConfig();
        });

        $this->crud->operation(['list', 'show'], function () {
            // $this->crud->addButton('top', 'print', 'view', 'crud::buttons.print');
            $this->crud->addButton('line', 'print', 'view', 'crud::buttons.print');
        });
    }

    /**
     * Show the view for performing the operation.
     *
     * @return Response
     */
    public function print($id)
    {
        $this->crud->hasAccessOrFail('print');

        // prepare the fields you need to show
        $this->data['crud'] = $this->crud;
        $this->data['title'] = $this->crud->getTitle() ?? 'print '.$this->crud->entity_name;

        // load the view
        return view("crud::operations.print", $this->data);
    }
}

2)Created An Iframe Widget:

<iframe name="print_frame" onload="if(window.printval)window.frames['print_frame'].print();" width=0 height=0 frameborder=0 ></iframe>
@push('after_scripts')
<script type="text/javascript">
	window.printval = true;
</script>
@endpush

3)Created Print Button

@if ($crud->hasAccess('print'))
	<a href="{{ url($crud->route.'/'.$entry->getKey().'/print') }}" target="print_frame" class="btn btn-sm btn-link"><i class="fa fa-eye"></i> Print</a>
@endif

4)Added Widget & Operation in the Controller:

use \App\Http\Controllers\Admin\Operations\PrintOperation;
$this->data['widgets']['before_content'] = [
            [
                'type' => 'iframe',
            ],
        ];

This works like ajax printing ;)

@tabacitu
Copy link
Member

@tifaahmed you're right. It looks like we've mistakenly removed the Print button from the Show operation in the 4.0 rewrite. We'll fix this ASAP.

In the meantime - OMFG @karandatwani92 ! This is EXACTLY why I worked so hard at the 4.0 operations and widgets, so you can do that kind of stuff. I'm so glad you put that together, even though the documentation on doing this kind of thing is sparse at the moment. How do you feel about writing a short blog article / tutorial about the operation? Just a small intro and screenshots , in addition to the code, would be enough in my opinion. If you have a blog yourself, you could post there, please give us the link. If not, we could post it on backpackforlaravel.com in your name. Please reach out to hello@tabacitu.ro - I think many people would love to see this new operation you build. Plus, having a little publicity to your name couldn't hurt right? 😄

Cheers!

@tabacitu tabacitu changed the title print button in version 4 [4.0][Bug] Print button is missing from the Show view Dec 16, 2019
@tabacitu tabacitu added the Bug label Dec 16, 2019
@tifaahmed tifaahmed changed the title [4.0][Bug] Print button is missing from the Show view [4.0][Bug] Print button is missing from the Show view Dec 16, 2019
@tifaahmed
Copy link
Author

thanks for help my problem solved

@tabacitu tabacitu reopened this Dec 16, 2019
@karandatwani92
Copy link
Contributor

@tabacitu I would love to work for backpackforlaravel.com. I will reach out to you soon over mail. Thanks :)

@tabacitu
Copy link
Member

@karandatwani92 please do.

Let's leave this open until we fix it. The way I see it, the print button above is VERY nice but it shouldn't be the default feature. The default feature should be the exact same that was present in 3.6: a simple button like <a href="#" onclick="window.print()"><i class="fa fa-print"></i></a> that will print the current page.

Of course, because we've suffered a redesign, we have to test thoroughly and see what else needs changing so that the Print view looks good.

@pxpm can you please take a look and create a PR to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants