2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								import  utils  from  '../../services/utils.js' ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  server  from  '../../services/server.js' ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  toastService  from  "../../services/toast.js" ;  
						 
					
						
							
								
									
										
										
										
											2022-12-01 13:07:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  appContext  from  "../../components/app_context.js" ;  
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								import  libraryLoader  from  "../../services/library_loader.js" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  openService  from  "../../services/open.js" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  protectedSessionHolder  from  "../../services/protected_session_holder.js" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  BasicWidget  from  "../basic_widget.js" ;  
						 
					
						
							
								
									
										
										
										
											2022-11-25 15:29:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  dialogService  from  "../../services/dialog.js" ;  
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const  TPL  =  ` 
  
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:02:49 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< div  class = "revisions-dialog modal fade mx-auto"  tabindex = "-1"  role = "dialog" >  
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    < style > 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:02:49 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        . revisions - dialog  . revision - content - wrapper  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            flex - grow :  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            margin - left :  20 px ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            display :  flex ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            flex - direction :  column ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            min - width :  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:02:49 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        . revisions - dialog  . revision - content  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            overflow :  auto ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            word - break :  break - word ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:02:49 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        . revisions - dialog  . revision - content  img  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            max - width :  100 % ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            object - fit :  contain ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:02:49 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        . revisions - dialog  . revision - content  pre  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            max - width :  100 % ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            word - break :  break - all ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            white - space :  pre - wrap ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < / s t y l e > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < div  class = "modal-dialog modal-xl"  role = "document" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        < div  class = "modal-content" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            < div  class = "modal-header" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                < h5  class = "modal-title mr-auto" > Note  revisions < / h 5 > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 00:31:15 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                < button  class = "revisions-erase-all-revisions-button btn btn-sm" 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                        title = "Delete all revisions of this note" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        style = "padding: 0 10px 0 10px;"  type = "button" > Delete  all  revisions < / b u t t o n > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                < button  class = "help-button"  type = "button"  data - help - page = "Note-revisions"  title = "Help on Note revisions" > ? < / b u t t o n > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                < button  type = "button"  class = "close"  data - dismiss = "modal"  aria - label = "Close"  style = "margin-left: 0 !important;" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    < span  aria - hidden = "true" > & times ; < / s p a n > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                < / b u t t o n > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            < / d i v > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            < div  class = "modal-body"  style = "display: flex; height: 80vh;" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                < div  class = "dropdown" > 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:02:49 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    < button  class = "revision-list-dropdown"  type = "button"  style = "display: none;"  data - toggle = "dropdown" > Dropdown  trigger < / b u t t o n > 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:02:49 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    < div  class = "revision-list dropdown-menu"  style = "position: static; height: 100%; overflow: auto;" > < / d i v > 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                < / d i v > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:02:49 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                < div  class = "revision-content-wrapper" > 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                    < div  style = "flex-grow: 0; display: flex; justify-content: space-between;" > 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:02:49 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                        < h3  class = "revision-title"  style = "margin: 3px; flex-grow: 100;" > < / h 3 > 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:02:49 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                        < div  class = "revision-title-buttons" > < / d i v > 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                    < / d i v > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:02:49 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    < div  class = "revision-content" > < / d i v > 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                < / d i v > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            < / d i v > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        < / d i v > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < / d i v > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / d i v > ` ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:01:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								export  default  class  RevisionsDialog  extends  BasicWidget  {  
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    constructor ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        super ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . revisionItems  =  [ ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . note  =  null ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:01:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        this . revisionId  =  null ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    doRender ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . $widget  =  $ ( TPL ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:02:49 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        this . $list  =  this . $widget . find ( ".revision-list" ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . $listDropdown  =  this . $widget . find ( ".revision-list-dropdown" ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . $content  =  this . $widget . find ( ".revision-content" ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . $title  =  this . $widget . find ( ".revision-title" ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . $titleButtons  =  this . $widget . find ( ".revision-title-buttons" ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . $eraseAllRevisionsButton  =  this . $widget . find ( ".revisions-erase-all-revisions-button" ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . $listDropdown . dropdown ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . $listDropdown . parent ( ) . on ( 'hide.bs.dropdown' ,  e  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // prevent closing dropdown by clicking outside
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( e . clickEvent )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                e . preventDefault ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . $widget . on ( 'shown.bs.modal' ,  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:02:49 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            this . $list . find ( ` [data-revision-id=" ${ this . revisionId } "] ` ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                . trigger ( 'focus' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . $eraseAllRevisionsButton . on ( 'click' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  text  =  'Do you want to delete all revisions of this note? This action will erase revision title and content, but still preserve revision metadata.' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 20:19:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( await  dialogService . confirm ( text ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                await  server . remove ( ` notes/ ${ this . note . noteId } /revisions ` ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                this . $widget . modal ( 'hide' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                toastService . showMessage ( 'Note revisions has been deleted.' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . $list . on ( 'click' ,  '.dropdown-item' ,  e  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            e . preventDefault ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . $list . on ( 'focus' ,  '.dropdown-item' ,  e  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            this . $list . find ( '.dropdown-item' ) . each ( ( i ,  el )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                $ ( el ) . toggleClass ( 'active' ,  el  ===  e . target ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            this . setContentPane ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:01:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    async  showRevisionsEvent ( { noteId  =  appContext . tabManager . getActiveContextNoteId ( ) } )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        utils . openDialog ( this . $widget ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:01:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        await  this . loadRevisions ( noteId ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:01:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    async  loadRevisions ( noteId )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        this . $list . empty ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . $content . empty ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . $titleButtons . empty ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . note  =  appContext . tabManager . getActiveContextNote ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . revisionItems  =  await  server . get ( ` notes/ ${ noteId } /revisions ` ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        for  ( const  item  of  this . revisionItems )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            this . $list . append ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                $ ( '<a class="dropdown-item" tabindex="0">' ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-29 23:32:19 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    . text ( ` ${ item . dateLastEdited . substr ( 0 ,  16 ) }  ( ${ utils . formatSize ( item . contentLength ) } ) ` ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:02:49 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    . attr ( 'data-revision-id' ,  item . revisionId ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-21 15:19:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    . attr ( 'title' ,  ` This revision was last edited on  ${ item . dateLastEdited } ` ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . $listDropdown . dropdown ( 'show' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( this . revisionItems . length  >  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:01:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( ! this . revisionId )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                this . revisionId  =  this . revisionItems [ 0 ] . revisionId ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            this . $title . text ( "No revisions for this note yet..." ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:01:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            this . revisionId  =  null ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . $eraseAllRevisionsButton . toggle ( this . revisionItems . length  >  0 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async  setContentPane ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:02:49 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        const  revisionId  =  this . $list . find ( ".active" ) . attr ( 'data-revision-id' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:01:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        const  revisionItem  =  this . revisionItems . find ( r  =>  r . revisionId  ===  revisionId ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . $title . html ( revisionItem . title ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-27 22:58:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        this . renderContentButtons ( revisionItem ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        await  this . renderContent ( revisionItem ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    renderContentButtons ( revisionItem )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . $titleButtons . empty ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        const  $restoreRevisionButton  =  $ ( '<button class="btn btn-sm" type="button">Restore this revision</button>' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $restoreRevisionButton . on ( 'click' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  text  =  'Do you want to restore this revision? This will overwrite current title/content of the note with this revision.' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 20:19:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( await  dialogService . confirm ( text ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:01:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                await  server . post ( ` revisions/ ${ revisionItem . revisionId } /restore ` ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                this . $widget . modal ( 'hide' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                toastService . showMessage ( 'Note revision has been restored.' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  $eraseRevisionButton  =  $ ( '<button class="btn btn-sm" type="button">Delete this revision</button>' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $eraseRevisionButton . on ( 'click' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  text  =  'Do you want to delete this revision? This action will delete revision title and content, but still preserve revision metadata.' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 20:19:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( await  dialogService . confirm ( text ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:01:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                await  server . remove ( ` revisions/ ${ revisionItem . revisionId } ` ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:01:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                this . loadRevisions ( revisionItem . noteId ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                toastService . showMessage ( 'Note revision has been deleted.' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! revisionItem . isProtected  ||  protectedSessionHolder . isProtectedSessionAvailable ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            this . $titleButtons 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                . append ( $restoreRevisionButton ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                . append ( '   ' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . $titleButtons 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            . append ( $eraseRevisionButton ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            . append ( '   ' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  $downloadButton  =  $ ( '<button class="btn btn-sm btn-primary" type="button">Download</button>' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:01:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        $downloadButton . on ( 'click' ,  ( )  =>  openService . downloadRevision ( revisionItem . noteId ,  revisionItem . revisionId ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! revisionItem . isProtected  ||  protectedSessionHolder . isProtectedSessionAvailable ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            this . $titleButtons . append ( $downloadButton ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-27 22:58:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    async  renderContent ( revisionItem )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this . $content . empty ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:01:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        const  fullRevision  =  await  server . get ( ` revisions/ ${ revisionItem . revisionId } ` ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( revisionItem . type  ===  'text' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:01:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            this . $content . html ( fullRevision . content ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( this . $content . find ( 'span.math-tex' ) . length  >  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                await  libraryLoader . requireLibrary ( libraryLoader . KATEX ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-04-15 09:57:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                renderMathInElement ( this . $content [ 0 ] ,  { trust :  true } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-21 00:23:16 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        }  else  if  ( revisionItem . type  ===  'code' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:01:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            this . $content . html ( $ ( "<pre>" ) . text ( fullRevision . content ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-27 22:58:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        }  else  if  ( revisionItem . type  ===  'image' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            this . $content . html ( $ ( "<img>" ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-30 11:18:34 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                // the reason why we put this inline as base64 is that we do not want to let user copy this
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                // as a URL to be used in a note. Instead, if they copy and paste it into a note, it will be uploaded as a new note
 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:01:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                . attr ( "src" ,  ` data: ${ fullRevision . mime } ;base64, ${ fullRevision . content } ` ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                . css ( "max-width" ,  "100%" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                . css ( "max-height" ,  "100%" ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-27 22:58:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        }  else  if  ( revisionItem . type  ===  'file' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            const  $table  =  $ ( "<table cellpadding='10'>" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                . append ( $ ( "<tr>" ) . append ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    $ ( "<th>" ) . text ( "MIME: " ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    $ ( "<td>" ) . text ( revisionItem . mime ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                . append ( $ ( "<tr>" ) . append ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    $ ( "<th>" ) . text ( "File size:" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-29 23:32:19 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    $ ( "<td>" ) . text ( utils . formatSize ( revisionItem . contentLength ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:01:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( fullRevision . content )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                $table . append ( $ ( "<tr>" ) . append ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    $ ( '<td colspan="2">' ) . append ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        $ ( '<div style="font-weight: bold;">' ) . text ( "Preview:" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        $ ( '<pre class="file-preview-content"></pre>' ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 23:01:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                            . text ( fullRevision . content ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            this . $content . html ( $table ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-27 22:58:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        }  else  if  ( revisionItem . type  ===  'canvas' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-02 15:24:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            const  sanitizedTitle  =  revisionItem . title . replace ( /[^a-z0-9-.]/gi ,  "" ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            this . $content . html ( $ ( "<img>" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                . attr ( "src" ,  ` api/revisions/ ${ revisionItem . revisionId } /image/ ${ sanitizedTitle } ? ${ Math . random ( ) } ` ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                . css ( "max-width" ,  "100%" ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-21 00:23:16 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        }  else  if  ( revisionItem . type  ===  'mermaid' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  sanitizedTitle  =  revisionItem . title . replace ( /[^a-z0-9-.]/gi ,  "" ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            this . $content . html ( $ ( "<img>" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                . attr ( "src" ,  ` api/revisions/ ${ revisionItem . revisionId } /image/ ${ sanitizedTitle } ? ${ Math . random ( ) } ` ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                . css ( "max-width" ,  "100%" ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            this . $content . append ( $ ( "<pre>" ) . text ( fullRevision . content ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-27 22:58:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-16 19:29:18 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            this . $content . text ( "Preview isn't available for this note type." ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}