From 484eca554884ff0036c786499d8d5136a5c01b15 Mon Sep 17 00:00:00 2001 From: JakubPapso <“jakubpapso@gmail.com”> Date: Tue, 2 Jul 2024 22:25:29 +0200 Subject: [PATCH] [server links] description --- .../plugins/tm@_utils/server-links.utils.ts | 95 ++++++++++--------- .../_components/read-only/z-description.vue | 41 ++------ .../master-task/z-master-task-modal.vue | 2 +- .../_components/a-task-description.vue | 54 ++--------- 4 files changed, 71 insertions(+), 121 deletions(-) diff --git a/app/src/plugins/tm@_utils/server-links.utils.ts b/app/src/plugins/tm@_utils/server-links.utils.ts index a6a8be6..c45b814 100644 --- a/app/src/plugins/tm@_utils/server-links.utils.ts +++ b/app/src/plugins/tm@_utils/server-links.utils.ts @@ -1,47 +1,7 @@ -export function getServerLinks(description) { - const os = detectOS() +import { useToast } from 'vue-toast-notification'; +const toast = useToast(); - // Create a temporary DOM element to manipulate the HTML content - const tempDiv = document.createElement('div') - tempDiv.innerHTML = description - - const links = new Set() - const paragraphs = tempDiv.querySelectorAll('p') - - paragraphs.forEach(p => { - const text = p.textContent.trim() - - if (os === 'mac' && text.startsWith('smb://')) { - links.add(text) - } else if (os === 'win' && text.startsWith('\\\\')) { - links.add(`${text.replace(/\//g, '\\')}`) - } else if (os === 'mac' && text.startsWith('\\\\')) { - const smbLink = 'smb:' + text.replace(/\\/g, '/') - links.add(smbLink) - } else if (os === 'win' && text.startsWith('smb://')) { - const windowsLink = text.replace(/^smb:/, '').replace(/\//g, '\\') - links.add(`${windowsLink}`) - } - - const anchor = p.querySelector('a') - if (anchor) { - const href = anchor.getAttribute('href') - if (os === 'mac' && href.startsWith('smb://')) { - links.add(href) - } else if (os === 'win' && href.startsWith('\\\\')) { - links.add(`${href.replace(/\//g, '\\')}`) - } else if (os === 'mac' && href.startsWith('\\\\')) { - const smbLink = 'smb:' + href.replace(/\\/g, '/') - links.add(smbLink) - } else if (os === 'win' && href.startsWith('smb://')) { - const windowsLink = href.replace(/^smb:/, '').replace(/\//g, '\\') - links.add(`${windowsLink}`) - } - } - }) - - return Array.from(links) -} +window.toast = toast export function detectOS() { const platform = window.navigator.platform @@ -54,4 +14,53 @@ export function detectOS() { return 'win' } return 'win' +} + +export function prepareHTMLDescription(description) { + if (!description) return description + + const os = detectOS() + + // make an array from the description of strings from between
and
tags + const paragraphs = description.split('').map(p => p.split('
')[0]) + + const modifiedParagraphs = paragraphs.map(paragraph => { + const words = paragraph.split(' ') + + const modifiedWords = words.map(word => { + let link = null + + if (os === 'mac' && word.startsWith('smb://')) { + link = word + } else if (os === 'win' && word.startsWith('\\\\')) { + link = `${word.replace(/\//g, '\\')}` + } else if (os === 'mac' && word.startsWith('\\\\')) { + const smbLink = 'smb:' + word.replace(/\\/g, '/') + link = smbLink + } else if (os === 'win' && word.startsWith('smb://')) { + const windowsLink = word.replace(/^smb:/, '').replace(/\//g, '\\') + link = `${windowsLink}` + } + + if (!link) return word + + return `${link}` + }) + + return `${modifiedWords.join(' ')}
` + }) + + description = modifiedParagraphs.join('') + + return description; +} + +function getCopyFunction(text) { + return ` + navigator.clipboard.writeText('${text}').then(() => { + window.toast.success('Link copied to clipboard!') + }).catch(err => { + window.toast.error('Failed to copy link to clipboard!') + }); + ` } \ No newline at end of file diff --git a/app/src/plugins/tm@modal/_components/read-only/z-description.vue b/app/src/plugins/tm@modal/_components/read-only/z-description.vue index 57738af..e15160b 100644 --- a/app/src/plugins/tm@modal/_components/read-only/z-description.vue +++ b/app/src/plugins/tm@modal/_components/read-only/z-description.vue @@ -1,26 +1,17 @@Popis zadania
- -Odkazy na server
-Copy
- -Popis mastertasku
- +Popis zadania
- -Odkazy na server
-Copy
- -Popis mastertasku
- -Odkazy na server
-Copy
- -