changed: save strategy! again!
This commit is contained in:
		
							parent
							
								
									88444f40fc
								
							
						
					
					
						commit
						f75c7b6bd2
					
				
							
								
								
									
										60
									
								
								main.js
								
								
								
								
							
							
						
						
									
										60
									
								
								main.js
								
								
								
								
							| 
						 | 
				
			
			@ -1348,38 +1348,23 @@ function postpone()
 | 
			
		|||
	});
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function waitpending()
 | 
			
		||||
{
 | 
			
		||||
	return new Promise(function(resolve)
 | 
			
		||||
	{
 | 
			
		||||
		if (!pending)
 | 
			
		||||
		{
 | 
			
		||||
			resolve();
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
			console.log("query already pending, waiting...");
 | 
			
		||||
			var id = setInterval(() =>
 | 
			
		||||
			{
 | 
			
		||||
				if (!pending)
 | 
			
		||||
				{
 | 
			
		||||
					console.log("...clear");
 | 
			
		||||
					clearInterval(id);
 | 
			
		||||
					resolve();
 | 
			
		||||
				}
 | 
			
		||||
			}, 100);
 | 
			
		||||
		}
 | 
			
		||||
	});	
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function save()
 | 
			
		||||
{
 | 
			
		||||
	clearTimeout(workerid);
 | 
			
		||||
	waitpending()
 | 
			
		||||
	.then(() =>
 | 
			
		||||
	{
 | 
			
		||||
		var content = getnotecontent();
 | 
			
		||||
 | 
			
		||||
	if (!localdata)
 | 
			
		||||
	{
 | 
			
		||||
		showtemporaryinfo("cannot push empty data");
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (pending)
 | 
			
		||||
	{
 | 
			
		||||
		console.log("pending query: save cancelled");
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var content = getnotecontent();
 | 
			
		||||
	if ((content == "" && backup != "") || content == "null" || content == "undefined")
 | 
			
		||||
	{
 | 
			
		||||
		showtemporaryinfo("Invalid content '" + content + "', file '" + currentnote.title + "' not saved");
 | 
			
		||||
| 
						 | 
				
			
			@ -1390,6 +1375,7 @@ function save()
 | 
			
		|||
	currentnote.content = content;
 | 
			
		||||
 | 
			
		||||
	window.localStorage.setItem(currentvault, JSON.stringify(localdata));
 | 
			
		||||
 | 
			
		||||
	if (currentnote.title == "settings.json")
 | 
			
		||||
	{
 | 
			
		||||
		settings = JSON.parse(content);
 | 
			
		||||
| 
						 | 
				
			
			@ -1401,31 +1387,33 @@ function save()
 | 
			
		|||
	{
 | 
			
		||||
		console.log("sending data to php server...");
 | 
			
		||||
 | 
			
		||||
			if (localdata)
 | 
			
		||||
			{
 | 
			
		||||
		pending = true;
 | 
			
		||||
		queryremote({action: "push", data: JSON.stringify(localdata)})
 | 
			
		||||
		.then(() =>
 | 
			
		||||
		{
 | 
			
		||||
					console.log("data saved on server.");
 | 
			
		||||
			console.log("...data saved on server");
 | 
			
		||||
			saved = true;
 | 
			
		||||
		})
 | 
			
		||||
		.catch(remotecallfailed)
 | 
			
		||||
		.finally(() =>
 | 
			
		||||
		{
 | 
			
		||||
			pending = false;
 | 
			
		||||
				});
 | 
			
		||||
			}
 | 
			
		||||
			else
 | 
			
		||||
			if (content != getnotecontent())
 | 
			
		||||
			{
 | 
			
		||||
				showtemporaryinfo("Cannot push empty data");
 | 
			
		||||
				console.log("but content changed: will save again");
 | 
			
		||||
				datachanged();
 | 
			
		||||
			}
 | 
			
		||||
			else if (!saved)
 | 
			
		||||
			{
 | 
			
		||||
				console.log("save failed. Data unsaved on server, manual action required.");
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		saved = true;
 | 
			
		||||
	}
 | 
			
		||||
	});
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function datachanged()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue