@@ -91,7 +91,7 @@ public function createComponentGrid($name)
9191 {
9292 $ grid = $ this ->baseGridFactory ->create ($ this , $ name );
9393
94- $ grid ->setModel ($ this ->articleRepository ->getArticleQueryBuilder ($ this ->group ));
94+ $ grid ->setDataSource ($ this ->articleRepository ->getArticleQueryBuilder ($ this ->group ));
9595
9696 if ($ this ->group ->getSortBy () == Group::SORT_BY_POSITION ) {
9797 $ grid ->setDefaultSort (['position ' => 'ASC ' ]);
@@ -103,70 +103,56 @@ public function createComponentGrid($name)
103103
104104 $ grid ->addColumnText ('identifier ' , 'Identifier ' )
105105 ->setSortable ()
106- ->setFilterText ()
107- ->setSuggestion ();
106+ ->setFilterText ();
108107
109108 $ grid ->addColumnBoolean ('isActive ' , 'Active ' );
110109 $ grid ->addColumnBoolean ('isShowName ' , 'Show name ' );
111110
112111 if ($ this ->group ->getSortBy () == Group::SORT_BY_POSITION )
113112 {
114- $ grid ->addColumnNumber ('position ' , 'Position ' )
115- ->setSortable ()
116- ->setFilterNumber ()
117- ->setSuggestion ();
118- $ grid ->getColumn ('position ' )->cellPrototype ->class [] = 'center ' ;
113+ $ grid ->addColumnPosition ('position ' , 'Position ' , 'up! ' , 'down! ' );
119114 }
120115 elseif ($ this ->group ->getSortBy () == Group::SORT_BY_CREATED_AT )
121116 {
122- $ grid ->addColumnDate ('createdAt ' , 'Created ' , $ this ->currentLocale ->getDateTimeFormat ())
117+ $ grid ->addColumnDateTime ('updatedAt ' , 'Last edit ' )
118+ ->setFormat ($ this ->currentLocale ->getDateTimeFormat ())
119+ ->setAlign ('center ' )
123120 ->setSortable ()
124121 ->setFilterDate ();
125- $ grid ->getColumn ('createdAt ' )->cellPrototype ->class [] = 'center ' ;
126122 }
127123
128124 if ($ this ->presenter ->isAllowed ('article ' , 'edit ' )) {
125+
126+ $ grid ->addAction ('edit ' , 'Upravit ' , 'edit ' , ['groupId ' => 'group.id ' , 'id ' ])
127+ ->setIcon ('pencil ' )
128+ ->setTitle ('Upravit ' )
129+ ->setClass ('btn btn-xs btn-primary ' );
130+
131+ /*
129132 $grid->addActionHref('edit', 'Upravit')
130133 ->setCustomHref(function($row){
131134 return $this->presenter->link('edit', ['id' => $row->getId(), 'groupId' => $this->group->getId()]);
132135 })
133136 ->setIcon('pencil');
137+ */
134138 }
135139
136140 if ($ this ->presenter ->isAllowed ('article ' , 'delete ' )) {
137- $ grid ->addActionHref ('delete ' , 'Smazat ' , 'delete! ' )
138- ->setCustomHref (function ($ row ){
139- return $ this ->link ('delete! ' , $ row ->getId ());
140- })
141- ->setIcon ('trash-o ' )
142- ->setConfirm (function ($ row ) {
143- return ['Opravdu chcete smazat article %s ? ' , $ row ->getIdentifier ()];
144- });
145-
146-
147- $ operations = ['delete ' => 'Smazat ' ];
148- $ grid ->setOperation ($ operations , [$ this , 'gridOperationsHandler ' ])
149- ->setConfirm ('delete ' , 'Opravu chcete smazat %i articles ? ' );
141+ $ grid ->addAction ('delete ' , '' , 'delete! ' )
142+ ->setIcon ('trash ' )
143+ ->setTitle ('Smazat ' )
144+ ->setClass ('btn btn-xs btn-danger ajax ' )
145+ ->setConfirm ('Do you really want to delete row %s? ' , 'identifier ' );
146+ $ grid ->addGroupAction ('Smazat ' )->onSelect [] = [$ this , 'handleDelete ' ];
150147 }
151- $ grid ->setExport ();
148+ $ grid ->addExportCsvFiltered ('Csv export (filtered) ' , 'articles_filtered.csv ' )
149+ ->setTitle ('Csv export (filtered) ' );
150+ $ grid ->addExportCsv ('Csv export ' , 'articlesall.csv ' )
151+ ->setTitle ('Csv export ' );
152152
153153 return $ grid ;
154154 }
155155
156- /**
157- * @param $action
158- * @param $ids
159- */
160- public function gridOperationsHandler ($ action , $ ids )
161- {
162- switch ($ action )
163- {
164- case 'delete ' :
165- $ this ->handleDelete ($ ids );
166- break ;
167- }
168- }
169-
170156 /**
171157 * @param $id
172158 * @throws \Exception
@@ -184,6 +170,24 @@ public function handleDelete($id)
184170 $ this ->onDelete ();
185171 }
186172
173+ /**
174+ * @param $id
175+ */
176+ public function handleUp ($ id )
177+ {
178+ $ articleItem = $ this ->articleRepository ->getOneById ($ id );
179+ $ this ->articleRepository ->moveUp ($ articleItem , 1 );
180+ }
181+
182+ /**
183+ * @param $id
184+ */
185+ public function handleDown ($ id )
186+ {
187+ $ articleItem = $ this ->articleRepository ->getOneById ($ id );
188+ $ this ->articleRepository ->moveDown ($ articleItem , 1 );
189+ }
190+
187191 public function render ()
188192 {
189193 $ template = $ this ->template ;
0 commit comments