117117 <router-link :to =" { path: '/zone/' + record.zoneid }" >{{ text }}</router-link >
118118 </a >
119119
120+ <div slot =" order" slot-scope =" text, record" class =" shift-btns" >
121+ <a-tooltip placement =" top" >
122+ <template slot="title">Move to top</template >
123+ <a-button
124+ shape =" round"
125+ icon =" double-left"
126+ @click =" moveItemTop(record)"
127+ class =" shift-btn shift-btn--rotated" ></a-button >
128+ </a-tooltip >
129+ <a-tooltip placement =" top" >
130+ <template slot="title">Move to bottom</template >
131+ <a-button
132+ shape =" round"
133+ icon =" double-right"
134+ @click =" moveItemBottom(record)"
135+ class =" shift-btn shift-btn--rotated" ></a-button >
136+ </a-tooltip >
137+ <a-tooltip placement =" top" >
138+ <template slot="title">Move up one row</template >
139+ <a-button shape =" round" icon =" caret-up" @click =" moveItemUp(record)" class =" shift-btn" ></a-button >
140+ </a-tooltip >
141+ <a-tooltip placement =" top" >
142+ <template slot="title">Move down one row</template >
143+ <a-button shape =" round" icon =" caret-down" @click =" moveItemDown(record)" class =" shift-btn" ></a-button >
144+ </a-tooltip >
145+ </div >
146+
120147 <template slot="value" slot-scope="text, record">
121148 <a-input
122149 v-if =" editableValueKey === record.key"
@@ -181,6 +208,7 @@ export default {
181208 default: false
182209 }
183210 },
211+ inject: [' parentFetchData' , ' parentToggleLoading' ],
184212 data () {
185213 return {
186214 selectedRowKeys: [],
@@ -233,6 +261,90 @@ export default {
233261 editValue (record ) {
234262 this .editableValueKey = record .key
235263 this .editableValue = record .value
264+ },
265+ handleUpdateOrder (id , index ) {
266+ this .parentToggleLoading ()
267+ let apiString = ' '
268+ switch (this .$route .name ) {
269+ case ' template' :
270+ apiString = ' updateTemplate'
271+ break
272+ case ' iso' :
273+ apiString = ' updateIso'
274+ break
275+ case ' zone' :
276+ apiString = ' updateZone'
277+ break
278+ case ' computeoffering' :
279+ case ' systemoffering' :
280+ apiString = ' updateServiceOffering'
281+ break
282+ case ' diskoffering' :
283+ apiString = ' updateDiskOffering'
284+ break
285+ case ' networkoffering' :
286+ apiString = ' updateNetworkOffering'
287+ break
288+ case ' vpcoffering' :
289+ apiString = ' updateVPCOffering'
290+ break
291+ default :
292+ apiString = ' updateTemplate'
293+ }
294+
295+ api (apiString, {
296+ id,
297+ sortKey: index
298+ }).catch (error => {
299+ console .error (error)
300+ }).finally (() => {
301+ this .parentFetchData ()
302+ this .parentToggleLoading ()
303+ })
304+ },
305+ moveItemUp (record ) {
306+ const data = this .items
307+ const index = data .findIndex (item => item .id === record .id )
308+ if (index === 0 ) return
309+
310+ data .splice (index - 1 , 0 , data .splice (index, 1 )[0 ])
311+
312+ data .forEach ((item , index ) => {
313+ this .handleUpdateOrder (item .id , index + 1 )
314+ })
315+ },
316+ moveItemDown (record ) {
317+ const data = this .items
318+ const index = data .findIndex (item => item .id === record .id )
319+ if (index === data .length - 1 ) return
320+
321+ data .splice (index + 1 , 0 , data .splice (index, 1 )[0 ])
322+
323+ data .forEach ((item , index ) => {
324+ this .handleUpdateOrder (item .id , index + 1 )
325+ })
326+ },
327+ moveItemTop (record ) {
328+ const data = this .items
329+ const index = data .findIndex (item => item .id === record .id )
330+ if (index === 0 ) return
331+
332+ data .unshift (data .splice (index, 1 )[0 ])
333+
334+ data .forEach ((item , index ) => {
335+ this .handleUpdateOrder (item .id , index + 1 )
336+ })
337+ },
338+ moveItemBottom (record ) {
339+ const data = this .items
340+ const index = data .findIndex (item => item .id === record .id )
341+ if (index === data .length - 1 ) return
342+
343+ data .push (data .splice (index, 1 )[0 ])
344+
345+ data .forEach ((item , index ) => {
346+ this .handleUpdateOrder (item .id , index + 1 )
347+ })
236348 }
237349 }
238350}
@@ -255,3 +367,27 @@ export default {
255367 background-color : #f9f9f9 ;
256368}
257369 </style >
370+
371+ <style scoped lang="scss">
372+ .shift-btns {
373+ display : flex ;
374+ }
375+ .shift-btn {
376+ display : flex ;
377+ align-items : center ;
378+ justify-content : center ;
379+ width : 20px ;
380+ height : 20px ;
381+ font-size : 12px ;
382+
383+ & :not (:last-child ) {
384+ margin-right : 5px ;
385+ }
386+
387+ & --rotated {
388+ font-size : 10px ;
389+ transform : rotate (90deg );
390+ }
391+
392+ }
393+ </style >
0 commit comments