Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 82862b2d

Přidáno uživatelem Jan Šedivý před téměř 6 roky(ů)

Re #7328 změna počtu výsledků na stránku

Zobrazit rozdíly:

app/FrontModule/component/Transliteration/TransliterationSearchResultList.latte
75 75
            });
76 76

  
77 77
            $('select[name="lines"]').change(function () {
78
                let lines = this.value;
78 79

  
80
                $.nette.ajax({
81
                    url: {link changeLines!},
82
                    data: {'lines': lines}
83
                })
79 84
            });
80 85
        })
81 86
    </script>
app/FrontModule/component/Transliteration/TransliterationSearchResultList.php
3 3
namespace App\FrontModule\Components;
4 4

  
5 5

  
6
use App\Enum\EAdjacentLines;
7
use App\Enum\EPageLimit;
6 8
use App\Model\Repository\TransliterationRepository;
7 9
use App\Model\TransliterationSearchModel;
8 10
use App\Utils\Form;
......
30 32
    private $resultRows;
31 33
    private $totalCount;
32 34

  
35
    private $adjacentLines;
36

  
33 37
    /**
34 38
     * TransliterationSearchResultList constructor.
35 39
     * @param TransliterationSearchModel $transliterationSearchModel
......
80 84
    {
81 85
        $form = new Form();
82 86

  
83
        $form->addSelect('limit', 'Results per page: ', Paginator::ALLOWED_LIMITS);
84
        $form->addSelect('lines', 'Show adjacent lines', TransliterationRepository::ADJACENT_LINES);
87
        $form->addSelect('limit', 'Results per page: ', EPageLimit::$selectValues)
88
            ->setDefaultValue($this->paginator->getPageSize());
89
        $form->addSelect('lines', 'Show adjacent lines', EAdjacentLines::$selectValues)
90
            ->setDefaultValue($this->adjacentLines);
85 91

  
86 92
        return $form;
87 93
    }
......
92 98
        {
93 99
            $limit = $this->presenter->getParameter('limit');
94 100

  
95
            if($limit)
101
            if($limit !== null)
102
            {
103
                $this->paginator = new Paginator(1, $limit);
104
                $this['searchSettingsForm']->setDefaults(array('limit' => $limit));
105
                $this->redrawControl('resultList');
106
            }
107
        }
108
    }
109

  
110
    public function handleChangeLines()
111
    {
112
        if($this->presenter->isAjax())
113
        {
114
            $lines = $this->presenter->getParameter('lines');
115

  
116
            if($lines !== null)
96 117
            {
97
                $this->paginator = new Paginator(1, Paginator::ALLOWED_LIMITS[$limit]);
118
                $this->adjacentLines = $lines;
119
                $this['searchSettingsForm']->setDefaults(array('lines' => $lines));
98 120
                $this->redrawControl('resultList');
121

  
99 122
            }
100 123
        }
101 124
    }
app/enum/EAdjacentLines.php
1
<?php
2

  
3
namespace App\Enum;
4

  
5

  
6
class EAdjacentLines
7
{
8
    const LINES_0 = 0;
9
    const LINES_1 = 1;
10
    const LINES_2 = 2;
11
    const LINES_3 = 3;
12
    const LINES_5 = 5;
13
    const LINES_10 = 10;
14
    const LINES_15 = 15;
15

  
16
    public static $lines = [
17
        self::LINES_0,
18
        self::LINES_1,
19
        self::LINES_2,
20
        self::LINES_3,
21
        self::LINES_5,
22
        self::LINES_10,
23
        self::LINES_15
24
    ];
25

  
26
    public static $selectValues = [
27
        self::LINES_0 => '0',
28
        self::LINES_1 => '1',
29
        self::LINES_2 => '2',
30
        self::LINES_3 => '3',
31
        self::LINES_5 => '5',
32
        self::LINES_10 => '10',
33
        self::LINES_15 => '15'
34
    ];
35

  
36
    public static $defaultLines = self::LINES_0;
37
}
app/enum/EPageLimit.php
1
<?php
2

  
3
namespace App\Enum;
4

  
5

  
6
class EPageLimit
7
{
8
    const LIMIT_1 = 1;
9
    const LIMIT_2 = 2;
10
    const LIMIT_3 = 3;
11
    const LIMIT_5 = 5;
12
    const LIMIT_10 = 10;
13
    const LIMIT_15 = 15;
14
    const LIMIT_30 = 30;
15

  
16
    public static $limits = [
17
        self::LIMIT_1,
18
        self::LIMIT_2,
19
        self::LIMIT_3,
20
        self::LIMIT_5,
21
        self::LIMIT_10,
22
        self::LIMIT_15,
23
        self::LIMIT_30
24
    ];
25

  
26
    public static $selectValues = [
27
        self::LIMIT_1 => '1',
28
        self::LIMIT_2 => '2',
29
        self::LIMIT_3 => '3',
30
        self::LIMIT_5 => '5',
31
        self::LIMIT_10 => '10',
32
        self::LIMIT_15 => '15',
33
        self::LIMIT_30 => '30'
34
    ];
35

  
36
    public static $defaultLimit = self::LIMIT_5;
37
}
app/model/repository/TransliterationRepository.php
30 30
    const COLUMN_DATE = 'date';
31 31
    const COLUMN_NOTE = 'note';
32 32

  
33
    const ADJACENT_LINES = [0, 1, 2, 3, 5, 10, 15];
34

  
35 33
    /**
36 34
     * Vyhledává texty podle slov v řádcích textu
37 35
     * @param ArrayHash $queryParams objekt s podmínkami pro hledaný text
app/utils/Paginator.php
3 3
namespace App\Utils;
4 4

  
5 5

  
6
use App\Enum\EPageLimit;
7

  
6 8
class Paginator
7 9
{
8 10

  
......
15 17
    private $startingPage;
16 18
    private $endingPage;
17 19

  
18
    const ALLOWED_LIMITS = [10, 25, 50, 100];
19

  
20 20
    /**
21 21
     * Implementation of spring Data Pageable to paginate and sort JPA queries
22 22
     * @param $page int query offset
......
30 30
        }
31 31
        $this->page = $page;
32 32

  
33
        foreach (self::ALLOWED_LIMITS as $l)
33
        foreach (EPageLimit::$limits as $l)
34 34
        {
35 35
            if ($l == $limit)
36 36
            {
......
39 39
        }
40 40
        if ($this->limit == 0)
41 41
        {
42
            $this->limit = self::ALLOWED_LIMITS[0];
42
            $this->limit = EPageLimit::$defaultLimit;
43 43
        }
44 44
    }
45 45

  
......
135 135
        $this->setPagesList();
136 136
    }
137 137

  
138
    public function getAllowedLimits()
139
    {
140
        return self::ALLOWED_LIMITS;
141
    }
142

  
143 138
    /**
144 139
     * Sets starting and ending page number to be displayed in template
145 140
     */
www/css/front/style.css
30 30
    font-size: 2rem;
31 31
    font-weight: 300;
32 32
    line-height: 1.2;
33
    margin-bottom: 1rem;
33 34
}
34 35

  
35 36
.content {

Také k dispozici: Unified diff