@ -25,6 +25,7 @@ import axios from '@nextcloud/axios' 
			
		
	
		
			
				
					import  NcSelect  from  '@nextcloud/vue/dist/Components/NcSelect.js'  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					const  groups  =  [ ]  
			
		
	
		
			
				
					const  wantedGroups  =  [ ]  
			
		
	
		
			
				
					const  status  =  {  
			
		
	
		
			
				
						isLoading :  false ,  
			
		
	
		
			
				
					}  
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -49,6 +50,7 @@ export default { 
			
		
	
		
			
				
							return  {  
			
		
	
		
			
				
								groups ,  
			
		
	
		
			
				
								status ,  
			
		
	
		
			
				
								wantedGroups ,  
			
		
	
		
			
				
								newValue :  '' ,  
			
		
	
		
			
				
							}  
			
		
	
		
			
				
						} ,  
			
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
				@ -82,6 +84,13 @@ export default { 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							searchAsync ( searchQuery )  {  
			
		
	
		
			
				
								if  ( this . status . isLoading )  {  
			
		
	
		
			
				
									if  ( searchQuery )  {  
			
		
	
		
			
				
										/ /   T h e   f i r s t   2 0   g r o u p s   a r e   l o a d e d   u p   f r o n t   ( i n d i c a t e d   b y   a n  
			
		
	
		
			
				
										/ /   e m p t y   s e a r c h Q u e r y   p a r a m e t e r ) ,   a f t e r w a r d s   w e   m a y   l o a d  
			
		
	
		
			
				
										/ /   g r o u p s   t h a t   h a v e   n o t   b e e n   f e t c h e d   y e t ,   b u t   a r e   u s e d  
			
		
	
		
			
				
										/ /   i n   e x i s t i n g   r u l e s .  
			
		
	
		
			
				
										this . enqueueWantedGroup ( searchQuery )  
			
		
	
		
			
				
									}  
			
		
	
		
			
				
									return  
			
		
	
		
			
				
								}  
			
		
	
		
			
				
					
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -94,11 +103,15 @@ export default { 
			
		
	
		
			
				
										} )  
			
		
	
		
			
				
									} )  
			
		
	
		
			
				
									this . status . isLoading  =  false  
			
		
	
		
			
				
									this . findGroupByQueue ( )  
			
		
	
		
			
				
								} ,  ( error )  =>  {  
			
		
	
		
			
				
									console . error ( 'Error while loading group list' ,  error . response )  
			
		
	
		
			
				
								} )  
			
		
	
		
			
				
							} ,  
			
		
	
		
			
				
							updateInternalValue ( )  {  
			
		
	
		
			
				
							async  updateInternalValue ( )  {  
			
		
	
		
			
				
								if  ( ! this . newValue )  {  
			
		
	
		
			
				
									await  this . searchAsync ( this . modelValue )  
			
		
	
		
			
				
								}  
			
		
	
		
			
				
								this . newValue  =  this . modelValue  
			
		
	
		
			
				
							} ,  
			
		
	
		
			
				
							addGroup ( group )  {  
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -107,10 +120,32 @@ export default { 
			
		
	
		
			
				
									this . groups . push ( group )  
			
		
	
		
			
				
								}  
			
		
	
		
			
				
							} ,  
			
		
	
		
			
				
							hasGroup ( group )  {  
			
		
	
		
			
				
								const  index  =  this . groups . findIndex ( ( item )  =>  item . id  ===  group )  
			
		
	
		
			
				
								return  index  >  - 1  
			
		
	
		
			
				
							} ,  
			
		
	
		
			
				
							update ( value )  {  
			
		
	
		
			
				
								this . newValue  =  value . id  
			
		
	
		
			
				
								this . $emit ( 'update:model-value' ,  this . newValue )  
			
		
	
		
			
				
							} ,  
			
		
	
		
			
				
							enqueueWantedGroup ( expectedGroupId )  {  
			
		
	
		
			
				
								const  index  =  this . wantedGroups . findIndex ( ( groupId )  =>  groupId  ===  expectedGroupId )  
			
		
	
		
			
				
								if  ( index  ===  - 1 )  {  
			
		
	
		
			
				
									this . wantedGroups . push ( expectedGroupId )  
			
		
	
		
			
				
								}  
			
		
	
		
			
				
							} ,  
			
		
	
		
			
				
							async  findGroupByQueue ( )  {  
			
		
	
		
			
				
								let  nextQuery  
			
		
	
		
			
				
								do  {  
			
		
	
		
			
				
									nextQuery  =  this . wantedGroups . shift ( )  
			
		
	
		
			
				
									if  ( this . hasGroup ( nextQuery ) )  {  
			
		
	
		
			
				
										nextQuery  =  undefined  
			
		
	
		
			
				
									}  
			
		
	
		
			
				
								}  while  ( ! nextQuery  &&  this . wantedGroups . length  >  0 )  
			
		
	
		
			
				
								if  ( nextQuery )  {  
			
		
	
		
			
				
									await  this . searchAsync ( nextQuery )  
			
		
	
		
			
				
								}  
			
		
	
		
			
				
							} ,  
			
		
	
		
			
				
						} ,  
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					< / script >