mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	UI for export of OPML v2, WIP
This commit is contained in:
		| @@ -15,6 +15,7 @@ const $singleType = $("#export-type-single"); | |||||||
| const $exportProgressWrapper = $("#export-progress-count-wrapper"); | const $exportProgressWrapper = $("#export-progress-count-wrapper"); | ||||||
| const $exportProgressCount = $("#export-progress-count"); | const $exportProgressCount = $("#export-progress-count"); | ||||||
| const $exportButton = $("#export-button"); | const $exportButton = $("#export-button"); | ||||||
|  | const $opmlVersions = $("#opml-versions"); | ||||||
|  |  | ||||||
| let exportId = ''; | let exportId = ''; | ||||||
|  |  | ||||||
| @@ -27,6 +28,9 @@ async function showDialog(defaultType) { | |||||||
|  |  | ||||||
|     if (defaultType === 'subtree') { |     if (defaultType === 'subtree') { | ||||||
|         $subtreeType.prop("checked", true).change(); |         $subtreeType.prop("checked", true).change(); | ||||||
|  |  | ||||||
|  |         // to show/hide OPML versions | ||||||
|  |         $("input[name=export-subtree-format]:checked").change(); | ||||||
|     } |     } | ||||||
|     else if (defaultType === 'single') { |     else if (defaultType === 'single') { | ||||||
|         $singleType.prop("checked", true).change(); |         $singleType.prop("checked", true).change(); | ||||||
| @@ -61,17 +65,19 @@ $form.submit(() => { | |||||||
|         ? $("input[name=export-subtree-format]:checked").val() |         ? $("input[name=export-subtree-format]:checked").val() | ||||||
|         : $("input[name=export-single-format]:checked").val(); |         : $("input[name=export-single-format]:checked").val(); | ||||||
|  |  | ||||||
|  |     const exportVersion = exportFormat === 'opml' ? $dialog.find("input[name='opml-version']:checked").val() : "1.0"; | ||||||
|  |  | ||||||
|     const currentNode = treeService.getCurrentNode(); |     const currentNode = treeService.getCurrentNode(); | ||||||
|  |  | ||||||
|     exportBranch(currentNode.data.branchId, exportType, exportFormat); |     exportBranch(currentNode.data.branchId, exportType, exportFormat, exportVersion); | ||||||
|  |  | ||||||
|     return false; |     return false; | ||||||
| }); | }); | ||||||
|  |  | ||||||
| function exportBranch(branchId, type, format) { | function exportBranch(branchId, type, format, version) { | ||||||
|     exportId = utils.randomString(10); |     exportId = utils.randomString(10); | ||||||
|  |  | ||||||
|     const url = utils.getHost() + `/api/notes/${branchId}/export/${type}/${format}/${exportId}?protectedSessionId=` + encodeURIComponent(protectedSessionHolder.getProtectedSessionId()); |     const url = utils.getHost() + `/api/notes/${branchId}/export/${type}/${format}/${version}/${exportId}?protectedSessionId=` + encodeURIComponent(protectedSessionHolder.getProtectedSessionId()); | ||||||
|  |  | ||||||
|     utils.download(url); |     utils.download(url); | ||||||
| } | } | ||||||
| @@ -95,6 +101,15 @@ $('input[name=export-type]').change(function () { | |||||||
|     } |     } | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | $('input[name=export-subtree-format]').change(function () { | ||||||
|  |     if (this.value === 'opml') { | ||||||
|  |         $opmlVersions.slideDown(); | ||||||
|  |     } | ||||||
|  |     else { | ||||||
|  |         $opmlVersions.slideUp(); | ||||||
|  |     } | ||||||
|  | }); | ||||||
|  |  | ||||||
| messagingService.subscribeToMessages(async message => { | messagingService.subscribeToMessages(async message => { | ||||||
|     if (message.type === 'export-error') { |     if (message.type === 'export-error') { | ||||||
|         infoService.showError(message.message); |         infoService.showError(message.message); | ||||||
|   | |||||||
| @@ -813,6 +813,11 @@ div[data-notify="container"] { | |||||||
|     display: none; |     display: none; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | #export-form #opml-versions { | ||||||
|  |     padding-left: 60px; | ||||||
|  |     display: none; | ||||||
|  | } | ||||||
|  |  | ||||||
| #export-form .form-check-label { | #export-form .form-check-label { | ||||||
|     padding: 2px; |     padding: 2px; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -48,7 +48,7 @@ class ExportContext { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function exportBranch(req, res) { | async function exportBranch(req, res) { | ||||||
|     const {branchId, type, format, exportId} = req.params; |     const {branchId, type, format, version, exportId} = req.params; | ||||||
|     const branch = await repository.getBranch(branchId); |     const branch = await repository.getBranch(branchId); | ||||||
|  |  | ||||||
|     const exportContext = new ExportContext(exportId); |     const exportContext = new ExportContext(exportId); | ||||||
| @@ -61,7 +61,7 @@ async function exportBranch(req, res) { | |||||||
|             await singleExportService.exportSingleNote(exportContext, branch, format, res); |             await singleExportService.exportSingleNote(exportContext, branch, format, res); | ||||||
|         } |         } | ||||||
|         else if (format === 'opml') { |         else if (format === 'opml') { | ||||||
|             await opmlExportService.exportToOpml(exportContext, branch, res); |             await opmlExportService.exportToOpml(exportContext, branch, version, res); | ||||||
|         } |         } | ||||||
|         else { |         else { | ||||||
|             return [404, "Unrecognized export format " + format]; |             return [404, "Unrecognized export format " + format]; | ||||||
|   | |||||||
| @@ -128,7 +128,7 @@ function register(app) { | |||||||
|     apiRoute(PUT, '/api/notes/:noteId/clone-to/:parentNoteId', cloningApiRoute.cloneNoteToParent); |     apiRoute(PUT, '/api/notes/:noteId/clone-to/:parentNoteId', cloningApiRoute.cloneNoteToParent); | ||||||
|     apiRoute(PUT, '/api/notes/:noteId/clone-after/:afterBranchId', cloningApiRoute.cloneNoteAfter); |     apiRoute(PUT, '/api/notes/:noteId/clone-after/:afterBranchId', cloningApiRoute.cloneNoteAfter); | ||||||
|  |  | ||||||
|     route(GET, '/api/notes/:branchId/export/:type/:format/:exportId', [auth.checkApiAuthOrElectron], exportRoute.exportBranch); |     route(GET, '/api/notes/:branchId/export/:type/:format/:version/:exportId', [auth.checkApiAuthOrElectron], exportRoute.exportBranch); | ||||||
|     route(POST, '/api/notes/:parentNoteId/import/:importId/safe/:safeImport', [auth.checkApiAuthOrElectron, uploadMiddleware], importRoute.importToBranch, apiResultHandler); |     route(POST, '/api/notes/:parentNoteId/import/:importId/safe/:safeImport', [auth.checkApiAuthOrElectron, uploadMiddleware], importRoute.importToBranch, apiResultHandler); | ||||||
|  |  | ||||||
|     route(POST, '/api/notes/:parentNoteId/upload', [auth.checkApiAuthOrElectron, uploadMiddleware], |     route(POST, '/api/notes/:parentNoteId/upload', [auth.checkApiAuthOrElectron, uploadMiddleware], | ||||||
|   | |||||||
| @@ -3,7 +3,9 @@ | |||||||
| const repository = require("../repository"); | const repository = require("../repository"); | ||||||
| const utils = require('../utils'); | const utils = require('../utils'); | ||||||
|  |  | ||||||
| async function exportToOpml(exportContext, branch, res) { | async function exportToOpml(exportContext, branch, version, res) { | ||||||
|  |     console.log("EXPORTING VERSION ", version); | ||||||
|  |  | ||||||
|     const note = await branch.getNote(); |     const note = await branch.getNote(); | ||||||
|  |  | ||||||
|     async function exportNoteInner(branchId) { |     async function exportNoteInner(branchId) { | ||||||
|   | |||||||
| @@ -40,6 +40,18 @@ | |||||||
|                                 OPML - outliner interchange format for text only. Formatting, images and files are not included. |                                 OPML - outliner interchange format for text only. Formatting, images and files are not included. | ||||||
|                             </label> |                             </label> | ||||||
|                         </div> |                         </div> | ||||||
|  |  | ||||||
|  |                         <div id="opml-versions"> | ||||||
|  |                             <div class="form-check"> | ||||||
|  |                                 <input class="form-check-input" type="radio" name="opml-version" id="opml-v1" value="1.0"> | ||||||
|  |                                 <label class="form-check-label" for="opml-v1">OPML v1.0 - plain text only</label> | ||||||
|  |                             </div> | ||||||
|  |  | ||||||
|  |                             <div class="form-check"> | ||||||
|  |                                 <input class="form-check-input" type="radio" name="opml-version" id="opml-v2" value="2.0"> | ||||||
|  |                                 <label class="form-check-label" for="opml-v2">OMPL v2.0 - allows also HTML</label> | ||||||
|  |                             </div> | ||||||
|  |                         </div> | ||||||
|                     </div> |                     </div> | ||||||
|  |  | ||||||
|                     <div class="form-check"> |                     <div class="form-check"> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user