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

How to ignore entries present in the filter URL? #25

Closed
ronaldaraujo opened this issue Jul 8, 2019 · 8 comments
Closed

How to ignore entries present in the filter URL? #25

ronaldaraujo opened this issue Jul 8, 2019 · 8 comments

Comments

@ronaldaraujo
Copy link

Hello! The tool you developed is incredible. Congrats on the job!

Now how can I ignore some variables in the entry of my URL?

For example, the number 1 in the image below shows the filters that are needed. The parameters of item 2 are only required to display some items in the PDF. That is, these parameters are used as flags (true or false).

image

Is it possible to do that?

My URL:

//Get /filter?year=2019&identification=9999&city_id=1&institution_id=4&movement_status=on&origin_resource=Com+emenda
[
    'year'  => '2019',
    'identification' => '9999',
    'city_id' => '1',
    'institution_id' => '4',

    // I want to ignore...
    'movement_status' => 'on',
    'origin_resource' => 'Com emenda'
]
@mohammad-fouladgar
Copy link
Owner

Hello! The tool you developed is incredible. Congrats on the job!

Thank you for your kind words.

Now how can I ignore some variables in the entry of my URL?

Each parameter that has a value applies as a filter.
If you want to ignore some filters set them with empty or null value.

For more info see ignore filters on null value in readme file.

@ronaldaraujo
Copy link
Author

@mohammad-fouladgar I got to see this section in the documentation. For the case of the parameter movement_status would work, because in it I only need two values (0 or 1; on or off; not empty or empty).

The problem is exactly in the origin_resource parameter. In it I need to identify the difference between 3 possibilities. That's when I can not ...

@mohammad-fouladgar
Copy link
Owner

mohammad-fouladgar commented Jul 9, 2019

@ronaldaraujo Normally, when a filter is displayed, submitted and has a value, it applies.
I think you should check this filter in your logic.

It's possible I see your 'Controller' and OriginResourceFilter?

What do you think we have a method to ignore some of the filters?

Like the following:

  • ignoreFilter()
  • ignoreOnlyFilter()
  • ignoreExceptFilter()
  • ...
$users = EloquentBuilder::to(User::class,$filters)->ignoreFilter('some_filter(s)')->get()

@ronaldaraujo
Copy link
Author

@mohammad-fouladgar maybe I have to fix my logic, but in my current scenario there are two inputs that are not part of any filter in the database. As I mentioned earlier, they would only be used to display a particular piece of content within the PDF.

This is the view:

{{ Form::open(array('role' => 'form', 'method' => 'GET', 'route' => 'processes.filter')) }}
    <div class="box-body">
        <h6 class="heading-small text-muted mb-4">Preencha uma ou todas as informações abaixo para filtrar</h6>
        <div class="row">
            <div class="col-md-4">
                <div class="form-group">
                    {{ Form::label('year', 'Ano') }}
                    <div class="input-group date">
                        <div class="input-group-addon">
                            <i class="fa fa-calendar"></i>
                        </div>
                        {{ Form::text('year', null, array('class' => 'form-control pull-right datepicker-only-year')) }}
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <label for="identification">Identificação</label>
                    {{ Form::text('identification', null, ['class' => 'form-control']) }}
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <label for="city_id">Município</label>
                    {{ Form::select('city_id', [], null, ['class' => 'form-control']) }}
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <label for="institution_id">Órgão</label>
                    {{ Form::select('institution_id', [], null, ['class' => 'form-control']) }}
                </div>
            </div>
        </div>
        <h6 class="heading-small text-muted mb-4">Filtros extras para a geração do relatório em PDF</h6>
        <div class="row">
            <div class="col-md-6">
                <div class="icheck-material-red">
                    <input type="checkbox" name="movement_status" id="movement_status">
                    <label for="movement_status">Marque para exibir o status da movimentação no relatório em PDF</label>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-6">
                <div class="icheck-material-red">
                    {{ Form::radio('origin_resource', 'Com emenda', null, ['id' => 'with_amendment', 'checked']) }}
                    <label for="with_amendment">Com emenda</label>
                </div>
                <div class="icheck-material-red">
                    {{ Form::radio('origin_resource', 'Com programação', null, ['id' => 'with_programming']) }}
                    <label for="with_programming">Com programação</label>
                </div>
                <div class="icheck-material-red">
                    {{ Form::radio('origin_resource', 'Com emenda e programação', null, ['id' => 'with_amendment_and_programming']) }}
                    <label for="with_amendment_and_programming">Com emenda e programação</label>
                </div>
            </div>
        </div>
    </div>
    <!-- /.box-body -->
    <div class="box-footer">
        {{ Form::submit('Filtrar', ['class' => 'btn btn-danger']) }}
        {{ Form::submit('Gerar PDF', ['formtarget' => '_blank', 'name' => 'pdf', 'class' => 'btn btn-danger']) }}
    </div>
{{ Form::close() }}

Note that there are two buttons:

  • "Filtrar": is used to filter the data and display on the screen;
  • "Gerar PDF": is also used to filter, but will open a new browser tab with the PDF content.

See my controller:

public function filter(Request $request)
{
    $processes = [];

    if (isset($request['pdf'])) {
        $processes = EloquentBuilder::to(Process::class, $request->all())->get();

        return PDF::loadView('dashboard.process.pdf', compact('processes'))
                    ->setPaper('A4', 'portrait')
                    ->stream('SAGCIC - Emendas.pdf');
    } else {
        $processes = EloquentBuilder::to(Process::class, $request->all())->paginate();
        
        return view('dashboard.process.index', ['processes' => $processes, 'filters' => $request->all()]);
    }
}

In summary, it would be amazing if we had some of the methods you mentioned:

  • ignoreFilter()
  • ignoreOnlyFilter()
  • ignoreExpectFilter()
  • ...

@joefazee
Copy link

joefazee commented Jul 9, 2019

@ronaldaraujo

Have you tried this $processes = EloquentBuilder::to(Process::class, $request->only('the_fields'))->get(); or ? Personally, I will not pass all the request data to the filtering methods.

@ronaldaraujo
Copy link
Author

@joefazee I had already thought of something similar:

$movementStatus = $request['movement_status'];
$originResource = $request['origin_resource'];        
$request = $request->except(['movement_status', 'origin_resource']);

However, I believe that there will be many fields in the front, so I was looking for something inside the library to leave the code clean.

But, thanks for the suggestion.

@mohammad-fouladgar
Copy link
Owner

mohammad-fouladgar commented Jul 9, 2019

Personally, I will not pass all the request data to the filtering methods.

@joefazee You pointed to a nice note.

@ronaldaraujo You must send the filters separately. Look at the example below:

/process?filters[identification]=999&filters[year]=2019&filters[city_id]=1&filters[institution_id]=4&movement_status=on&origin_resource=Com+emenda

Then usage like this below:

$processes = EloquentBuilder::to(
       Process::class,
       $request->filters
)->paginate();

Please feel free to any question 😉

@ronaldaraujo
Copy link
Author

Implemented successfully.

Thanks to all for your help :)

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

No branches or pull requests

3 participants