mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 21:11:30 +08:00 
			
		
		
		
	add #sortLocale label for natural sort. rephrase feature description.
This commit is contained in:
		
							parent
							
								
									d3ec9f022c
								
							
						
					
					
						commit
						93ad83d2ae
					
				| @ -73,7 +73,16 @@ const TPL = `<div class="sort-child-notes-dialog modal mx-auto" tabindex="-1" ro | |||||||
|                     <div class="form-check"> |                     <div class="form-check"> | ||||||
|                         <label class="form-check-label"> |                         <label class="form-check-label"> | ||||||
|                             <input class="form-check-input" type="checkbox" name="sort-natural" value="1"> |                             <input class="form-check-input" type="checkbox" name="sort-natural" value="1"> | ||||||
|                             sort by alphanumeric order |                             sort with respect to different character sorting and collation rules in different languages or regions. | ||||||
|  |                         </label> | ||||||
|  |                     </div> | ||||||
|  |                     <br /> | ||||||
|  |                      | ||||||
|  |                     <div class="form-check"> | ||||||
|  |                         <label> | ||||||
|  |                             Natural sort language | ||||||
|  |                             <input class="form-control" name="sort-locale"> | ||||||
|  |                             The language code for natural sort, e.g. "zh-CN" for Chinese. | ||||||
|                         </label> |                         </label> | ||||||
|                     </div> |                     </div> | ||||||
|                 </div> |                 </div> | ||||||
| @ -95,8 +104,9 @@ export default class SortChildNotesDialog extends BasicWidget { | |||||||
|             const sortDirection = this.$form.find("input[name='sort-direction']:checked").val(); |             const sortDirection = this.$form.find("input[name='sort-direction']:checked").val(); | ||||||
|             const foldersFirst = this.$form.find("input[name='sort-folders-first']").is(":checked"); |             const foldersFirst = this.$form.find("input[name='sort-folders-first']").is(":checked"); | ||||||
|             const sortNatural = this.$form.find("input[name='sort-natural']").is(":checked"); |             const sortNatural = this.$form.find("input[name='sort-natural']").is(":checked"); | ||||||
|  |             const sortLocale = this.$form.find("input[name='sort-locale']").val(); | ||||||
| 
 | 
 | ||||||
|             await server.put(`notes/${this.parentNoteId}/sort-children`, {sortBy, sortDirection, foldersFirst, sortNatural}); |             await server.put(`notes/${this.parentNoteId}/sort-children`, {sortBy, sortDirection, foldersFirst, sortNatural, sortLocale}); | ||||||
| 
 | 
 | ||||||
|             utils.closeActiveDialog(); |             utils.closeActiveDialog(); | ||||||
|         }); |         }); | ||||||
|  | |||||||
| @ -94,13 +94,13 @@ function undeleteNote(req) { | |||||||
| 
 | 
 | ||||||
| function sortChildNotes(req) { | function sortChildNotes(req) { | ||||||
|     const noteId = req.params.noteId; |     const noteId = req.params.noteId; | ||||||
|     const {sortBy, sortDirection, foldersFirst, sortNatural} = req.body; |     const {sortBy, sortDirection, foldersFirst, sortNatural, sortLocale} = req.body; | ||||||
| 
 | 
 | ||||||
|     log.info(`Sorting '${noteId}' children with ${sortBy} ${sortDirection}, foldersFirst=${foldersFirst}, sortNatural=${sortNatural}`); |     log.info(`Sorting '${noteId}' children with ${sortBy} ${sortDirection}, foldersFirst=${foldersFirst}, sortNatural=${sortNatural}, sortLocale=${sortLocale}`); | ||||||
| 
 | 
 | ||||||
|     const reverse = sortDirection === 'desc'; |     const reverse = sortDirection === 'desc'; | ||||||
| 
 | 
 | ||||||
|     treeService.sortNotes(noteId, sortBy, reverse, foldersFirst, sortNatural); |     treeService.sortNotes(noteId, sortBy, reverse, foldersFirst, sortNatural, sortLocale); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function protectNote(req) { | function protectNote(req) { | ||||||
|  | |||||||
| @ -43,6 +43,7 @@ module.exports = [ | |||||||
|     { type: 'label', name: 'sortDirection' }, |     { type: 'label', name: 'sortDirection' }, | ||||||
|     { type: 'label', name: 'sortFoldersFirst' }, |     { type: 'label', name: 'sortFoldersFirst' }, | ||||||
|     { type: 'label', name: 'sortNatural' }, |     { type: 'label', name: 'sortNatural' }, | ||||||
|  |     { type: 'label', name: 'sortLocale' }, | ||||||
|     { type: 'label', name: 'top' }, |     { type: 'label', name: 'top' }, | ||||||
|     { type: 'label', name: 'fullContentWidth' }, |     { type: 'label', name: 'fullContentWidth' }, | ||||||
|     { type: 'label', name: 'shareHiddenFromTree' }, |     { type: 'label', name: 'shareHiddenFromTree' }, | ||||||
|  | |||||||
| @ -46,7 +46,7 @@ eventService.subscribe([ eventService.ENTITY_CHANGED, eventService.ENTITY_DELETE | |||||||
|     if (entityName === 'attributes') { |     if (entityName === 'attributes') { | ||||||
|         runAttachedRelations(entity.getNote(), 'runOnAttributeChange', entity); |         runAttachedRelations(entity.getNote(), 'runOnAttributeChange', entity); | ||||||
| 
 | 
 | ||||||
|         if (entity.type === 'label' && ['sorted', 'sortDirection', 'sortFoldersFirst', 'sortNatural'].includes(entity.name)) { |         if (entity.type === 'label' && ['sorted', 'sortDirection', 'sortFoldersFirst', 'sortNatural', 'sortLocale'].includes(entity.name)) { | ||||||
|             handleSortedAttribute(entity); |             handleSortedAttribute(entity); | ||||||
|         } else if (entity.type === 'label') { |         } else if (entity.type === 'label') { | ||||||
|             handleMaybeSortingLabel(entity); |             handleMaybeSortingLabel(entity); | ||||||
| @ -101,7 +101,7 @@ eventService.subscribe(eventService.ENTITY_CREATED, ({ entityName, entity }) => | |||||||
|                 noteService.duplicateSubtreeWithoutRoot(templateNote.noteId, note.noteId); |                 noteService.duplicateSubtreeWithoutRoot(templateNote.noteId, note.noteId); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         else if (entity.type === 'label' && ['sorted', 'sortDirection', 'sortFoldersFirst', 'sortNatural'].includes(entity.name)) { |         else if (entity.type === 'label' && ['sorted', 'sortDirection', 'sortFoldersFirst', 'sortNatural', 'sortLocale'].includes(entity.name)) { | ||||||
|             handleSortedAttribute(entity); |             handleSortedAttribute(entity); | ||||||
|         } |         } | ||||||
|         else if (entity.type === 'label') { |         else if (entity.type === 'label') { | ||||||
|  | |||||||
| @ -123,11 +123,16 @@ function loadSubtreeNoteIds(parentNoteId, subtreeNoteIds) { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function sortNotes(parentNoteId, customSortBy = 'title', reverse = false, foldersFirst = false, sortNatural = false) { | function sortNotes(parentNoteId, customSortBy = 'title', reverse = false, foldersFirst = false, sortNatural = false, sortLocale) { | ||||||
|     if (!customSortBy) { |     if (!customSortBy) { | ||||||
|         customSortBy = 'title'; |         customSortBy = 'title'; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     if (!sortLocale) { | ||||||
|  |         // sortLocale can not be empty string or null value, default value must be set to undefined.
 | ||||||
|  |         sortLocale = undefined; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     sql.transactional(() => { |     sql.transactional(() => { | ||||||
|         const notes = becca.getNote(parentNoteId).getChildNotes(); |         const notes = becca.getNote(parentNoteId).getChildNotes(); | ||||||
| 
 | 
 | ||||||
| @ -157,8 +162,8 @@ function sortNotes(parentNoteId, customSortBy = 'title', reverse = false, folder | |||||||
|                     // alphabetical sort
 |                     // alphabetical sort
 | ||||||
|                     return b === null || b === undefined || a < b ? -1 : 1; |                     return b === null || b === undefined || a < b ? -1 : 1; | ||||||
|                 } else { |                 } else { | ||||||
|                     // alphanumeric sort, or natural sort
 |                     // natural sort
 | ||||||
|                     return a.localeCompare(b, undefined, {numeric: true, sensitivity: 'base'}); |                     return a.localeCompare(b, sortLocale, {numeric: true, sensitivity: 'base'}); | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|             } |             } | ||||||
| @ -233,7 +238,9 @@ function sortNotesIfNeeded(parentNoteId) { | |||||||
|     const sortFoldersFirst = sortFoldersFirstLabel && sortFoldersFirstLabel.value.toLowerCase() !== "false"; |     const sortFoldersFirst = sortFoldersFirstLabel && sortFoldersFirstLabel.value.toLowerCase() !== "false"; | ||||||
|     const sortNaturalLabel = parentNote.getLabel('sortNatural'); |     const sortNaturalLabel = parentNote.getLabel('sortNatural'); | ||||||
|     const sortNatural = sortNaturalLabel && sortNaturalLabel.value.toLowerCase() !== "false"; |     const sortNatural = sortNaturalLabel && sortNaturalLabel.value.toLowerCase() !== "false"; | ||||||
|     sortNotes(parentNoteId, sortedLabel.value, sortReversed, sortFoldersFirst, sortNatural); |     const sortLocale = parentNote.getLabelValue('sortLocale'); | ||||||
|  | 
 | ||||||
|  |     sortNotes(parentNoteId, sortedLabel.value, sortReversed, sortFoldersFirst, sortNatural, sortLocale); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Nriver
						Nriver