mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-30 04:01:31 +08:00 
			
		
		
		
	Updated all scripts to current versions working with current script API
This commit is contained in:
		
							parent
							
								
									755c0f3ce2
								
							
						
					
					
						commit
						44bcdedaba
					
				
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								src/scripts/Today.tar
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/scripts/Today.tar
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								src/scripts/Weight Tracker.tar
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/scripts/Weight Tracker.tar
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -1,13 +0,0 @@ | |||||||
| api.addButtonToToolbar('go-today', $('<button class="btn btn-xs" onclick="goToday();"><span class="ui-icon ui-icon-calendar"></span> Today</button>')); |  | ||||||
| 
 |  | ||||||
| window.goToday = async function() { |  | ||||||
|     const todayDateStr = formatDateISO(new Date()); |  | ||||||
| 
 |  | ||||||
|     const todayNoteId = await server.exec([todayDateStr], async todayDateStr => { |  | ||||||
|         return await this.getDateNoteId(todayDateStr); |  | ||||||
|     }); |  | ||||||
| 
 |  | ||||||
|     api.activateNote(todayNoteId); |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| $(document).bind('keydown', "alt+t", window.goToday); |  | ||||||
| @ -1,146 +0,0 @@ | |||||||
| <form id="weight-form" style="display: flex; width: 700px; justify-content: space-around; align-items: flex-end;"> |  | ||||||
|     <div> |  | ||||||
|         <label for="weight-date">Date</label> |  | ||||||
|         <input type="text" id="weight-date" class="form-control" style="width: 150px; text-align: center;" /> |  | ||||||
|     </div> |  | ||||||
|     <div> |  | ||||||
|         <label for="weight">Weight</label> |  | ||||||
|         <input type="number" id="weight" value="80.0" step="0.1" class="form-control" style="text-align: center; width: 100px;" /> |  | ||||||
|     </div> |  | ||||||
|     <div> |  | ||||||
|         <label for="comment">Comment</label> |  | ||||||
|         <input type="text" id="comment" class="form-control" style="width: 200px;" /> |  | ||||||
|     </div> |  | ||||||
| 
 |  | ||||||
|     <button type="submit" class="btn btn-primary">Add</button> |  | ||||||
| </form> |  | ||||||
| 
 |  | ||||||
| <br/><br/> |  | ||||||
| 
 |  | ||||||
| <canvas id="canvas"></canvas> |  | ||||||
| 
 |  | ||||||
| <script> |  | ||||||
|     (async function() { |  | ||||||
|         const $form = $("#weight-form"); |  | ||||||
|         const $date = $("#weight-date"); |  | ||||||
|         const $weight = $("#weight"); |  | ||||||
|         const $comment = $("#comment"); |  | ||||||
|         let chart; |  | ||||||
| 
 |  | ||||||
|         $date.datepicker(); |  | ||||||
|         $date.datepicker('option', 'dateFormat', 'yy-mm-dd'); |  | ||||||
|         $date.datepicker('setDate', new Date()); |  | ||||||
| 
 |  | ||||||
|         async function saveWeight() { |  | ||||||
|             await server.exec([$date.val(), parseFloat($weight.val()), $comment.val()], async (date, weight, comment) => { |  | ||||||
|                 const dataNote = await this.getNoteWithAttribute('date_data', date); |  | ||||||
| 
 |  | ||||||
|                 if (dataNote) { |  | ||||||
|                     dataNote.jsonContent.weight = weight; |  | ||||||
| 
 |  | ||||||
|                     if (comment) { |  | ||||||
|                         dataNote.jsonContent.weight_comment = comment; |  | ||||||
|                     } |  | ||||||
| 
 |  | ||||||
|                     await this.updateEntity(dataNote); |  | ||||||
|                 } |  | ||||||
|                 else { |  | ||||||
|                     const parentNoteId = await this.getDateNoteId(date); |  | ||||||
|                     const jsonContent = { weight: weight }; |  | ||||||
| 
 |  | ||||||
|                     if (comment) { |  | ||||||
|                         jsonContent.weight_comment = comment; |  | ||||||
|                     } |  | ||||||
| 
 |  | ||||||
|                     await this.createNote(parentNoteId, 'data', jsonContent, { |  | ||||||
|                         json: true, |  | ||||||
|                         attributes: { |  | ||||||
|                             date_data: date, |  | ||||||
|                             hide_in_autocomplete: null |  | ||||||
|                         } |  | ||||||
|                     }); |  | ||||||
|                 } |  | ||||||
|             }); |  | ||||||
| 
 |  | ||||||
|             showMessage("Weight has been saved"); |  | ||||||
| 
 |  | ||||||
|             chart.data = await getData(); |  | ||||||
|             chart.update(); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         async function drawChart() { |  | ||||||
|             const data = await getData(); |  | ||||||
| 
 |  | ||||||
|             const ctx = $("#canvas")[0].getContext("2d"); |  | ||||||
| 
 |  | ||||||
|             chart = new Chart(ctx, { |  | ||||||
|                 type: 'line', |  | ||||||
|                 data: data, |  | ||||||
|                 options: { |  | ||||||
|                     tooltips: { |  | ||||||
|                         enabled: true, |  | ||||||
|                         mode: 'single', |  | ||||||
|                         callbacks: { |  | ||||||
|                             label: function (tooltipItem, data) { |  | ||||||
|                                 const multistringText = [tooltipItem.yLabel]; |  | ||||||
|                                 const comment = data.comments[tooltipItem['index']]; |  | ||||||
| 
 |  | ||||||
|                                 if (comment) { |  | ||||||
|                                     multistringText.push(comment); |  | ||||||
|                                 } |  | ||||||
| 
 |  | ||||||
|                                 return multistringText; |  | ||||||
|                             } |  | ||||||
|                         } |  | ||||||
|                     }, |  | ||||||
|                 } |  | ||||||
|             }); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         async function getData() { |  | ||||||
|             const data = await server.exec([], async () => { |  | ||||||
|                 const notes = await this.getNotesWithAttribute('date_data'); |  | ||||||
|                 const data = []; |  | ||||||
| 
 |  | ||||||
|                 for (const note of notes) { |  | ||||||
|                     const dateAttr = await note.getAttribute('date_data'); |  | ||||||
| 
 |  | ||||||
|                     data.push({ |  | ||||||
|                         date: dateAttr.value, |  | ||||||
|                         weight: note.jsonContent.weight, |  | ||||||
|                         comment: note.jsonContent.weight_comment |  | ||||||
|                     }); |  | ||||||
|                 } |  | ||||||
| 
 |  | ||||||
|                 data.sort((a, b) => a.date < b.date ? -1 : +1); |  | ||||||
| 
 |  | ||||||
|                 return data; |  | ||||||
|             }); |  | ||||||
| 
 |  | ||||||
|             const datasets = [{ |  | ||||||
|                 label: "Weight", |  | ||||||
|                 backgroundColor: 'red', |  | ||||||
|                 borderColor: 'red', |  | ||||||
|                 data: data.map(row => row.weight), |  | ||||||
|                 fill: false |  | ||||||
|             }]; |  | ||||||
| 
 |  | ||||||
|             const labels = data.map(row => row.date); |  | ||||||
|             const comments = data.map(row => row.comment); |  | ||||||
| 
 |  | ||||||
|             return { |  | ||||||
|                 labels: labels, |  | ||||||
|                 datasets: datasets, |  | ||||||
|                 comments: comments |  | ||||||
|             }; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         $form.submit(event => { |  | ||||||
|             saveWeight(); |  | ||||||
| 
 |  | ||||||
|             event.preventDefault(); |  | ||||||
|         }); |  | ||||||
| 
 |  | ||||||
|         drawChart(); |  | ||||||
|     })(); |  | ||||||
| </script> |  | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 azivner
						azivner