@@ -134,10 +134,50 @@ public function addLink(request $request)
134134 $ links ->title = $ title ;
135135 $ links ->button_id = $ buttonId ;
136136 $ links ->save ();
137+ $ links ->order = ($ links ->id - 1 );
138+ $ links ->save ();
137139
138140 return back ();
139141 }
140142
143+ public function sortLinks (Request $ request )
144+ {
145+ $ linkOrders = $ request ->input ("linkOrders " , []);
146+ $ currentPage = $ request ->input ("currentPage " , 1 );
147+ $ perPage = $ request ->input ("perPage " , 0 );
148+
149+ if ($ perPage == 0 ) {
150+ $ currentPage = 1 ;
151+ }
152+
153+ $ linkOrders = array_unique (array_filter ($ linkOrders ));
154+ if (!$ linkOrders || $ currentPage < 1 ) {
155+ return response ()->json ([
156+ 'status ' => 'ERROR ' ,
157+ ]);
158+ }
159+
160+ $ newOrder = $ perPage * ($ currentPage - 1 );
161+ $ linkNewOrders = [];
162+ foreach ($ linkOrders as $ linkId ) {
163+ if ($ linkId < 0 ) {
164+ continue ;
165+ }
166+
167+ $ linkNewOrders [$ linkId ] = $ newOrder ;
168+ Link::where ("id " , $ linkId )
169+ ->update ([
170+ 'order ' => $ newOrder
171+ ]);
172+ $ newOrder ++;
173+ }
174+
175+ return response ()->json ([
176+ 'status ' => 'OK ' ,
177+ 'linkOrders ' => $ linkNewOrders ,
178+ ]);
179+ }
180+
141181 //Count the number of clicks and redirect to link
142182 public function clickNumber (request $ request )
143183 {
@@ -165,6 +205,7 @@ public function clickNumber(request $request)
165205 public function showLinks ()
166206 {
167207 $ userId = Auth::user ()->id ;
208+ $ data ['pagePage ' ] = 10 ;
168209
169210 $ data ['links ' ] = Link::select ('id ' , 'link ' , 'title ' , 'order ' , 'click_number ' , 'up_link ' , 'links.button_id ' )->where ('user_id ' , $ userId )->orderBy ('up_link ' , 'asc ' )->orderBy ('order ' , 'asc ' )->paginate (10 );
170211 return view ('studio/links ' , $ data );
@@ -174,6 +215,7 @@ public function showLinks()
174215 public function showLinks20 ()
175216 {
176217 $ userId = Auth::user ()->id ;
218+ $ data ['pagePage ' ] = 20 ;
177219
178220 $ data ['links ' ] = Link::select ('id ' , 'link ' , 'title ' , 'order ' , 'click_number ' , 'up_link ' , 'links.button_id ' )->where ('user_id ' , $ userId )->orderBy ('up_link ' , 'asc ' )->orderBy ('order ' , 'asc ' )->paginate (20 );
179221 return view ('studio/links ' , $ data );
@@ -183,6 +225,7 @@ public function showLinks20()
183225 public function showLinks30 ()
184226 {
185227 $ userId = Auth::user ()->id ;
228+ $ data ['pagePage ' ] = 30 ;
186229
187230 $ data ['links ' ] = Link::select ('id ' , 'link ' , 'title ' , 'order ' , 'click_number ' , 'up_link ' , 'links.button_id ' )->where ('user_id ' , $ userId )->orderBy ('up_link ' , 'asc ' )->orderBy ('order ' , 'asc ' )->paginate (30 );
188231 return view ('studio/links ' , $ data );
@@ -192,6 +235,7 @@ public function showLinks30()
192235 public function showLinksAll ()
193236 {
194237 $ userId = Auth::user ()->id ;
238+ $ data ['pagePage ' ] = 0 ;
195239
196240 $ data ['links ' ] = Link::select ('id ' , 'link ' , 'title ' , 'order ' , 'click_number ' , 'up_link ' , 'links.button_id ' )->where ('user_id ' , $ userId )->orderBy ('up_link ' , 'asc ' )->orderBy ('order ' , 'asc ' )->paginate (10000000000 );
197241 return view ('studio/links ' , $ data );
0 commit comments