ycs77 / laravel-wizard

A web Setup Wizard for Laravel application.
MIT License
122 stars 18 forks source link

Skip step #11

Closed ycs77 closed 2 years ago

veganista commented 4 years ago

I have a similar library to yours and implemented step skipping by introducing a skip() method on the step that would return true or false depending on whether the step should be skipped.

I've added a skip() method to your abstract Step class and updated your prev() and get() methods in StepRepository to:

    public function prev()
    {
        $index = $this
            ->steps
            ->reject
            ->skip()
            ->search(function($step, $index) {
                return $index < $this->currentIndex;
            });

        if ($index === false) {
            return $this->get($this->currentIndex - 1);
        }

        return $this->get($index);
        // return $this->get($this->currentIndex - 1);
    }

    public function next()
    {
        $index = $this
            ->steps
            ->reject
            ->skip()
            ->search(function($step, $index) {
                return $index > $this->currentIndex;
            });

        if ($index === false) {
            return $this->get($this->currentIndex + 1);
        }

        return $this->get($index);
        // return $this->currentIndex + 1;
    }

This seems to work with skipping steps. I'll try and put some more time into this if you would like to test and tidy it up.

Just thought I'd share what I'd done previously.

ycs77 commented 4 years ago

@veganista Thank you for your suggestions, I will use as a reference.

ycs77 commented 2 years ago

Released v2.3.3 added skip feature.