mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 14:29:34 +00:00
[server links] description
This commit is contained in:
1 parent
1b7315617f
commit
484eca5548
4 files changed
+71
-121
No files matched your search
@@ -1,47 +1,7 @@
|
|||||||
export function getServerLinks(description) {
|
import { useToast } from 'vue-toast-notification';
|
||||||
const os = detectOS()
|
const toast = useToast();
|
||||||
|
|
||||||
// Create a temporary DOM element to manipulate the HTML content
|
window.toast = toast
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function detectOS() {
|
export function detectOS() {
|
||||||
const platform = window.navigator.platform
|
const platform = window.navigator.platform
|
||||||
@@ -54,4 +14,53 @@ export function detectOS() {
|
|||||||
return 'win'
|
return 'win'
|
||||||
}
|
}
|
||||||
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 <p> and </p> tags
|
||||||
|
const paragraphs = description.split('<p>').map(p => p.split('</p>')[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 `<span style="cursor: pointer" onclick="${getCopyFunction(link)}">${link}</span>`
|
||||||
|
})
|
||||||
|
|
||||||
|
return `<p>${modifiedWords.join(' ')}</p>`
|
||||||
|
})
|
||||||
|
|
||||||
|
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!')
|
||||||
|
});
|
||||||
|
`
|
||||||
}
|
}
|
||||||
@@ -1,26 +1,17 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="px-5 py-5 border-bottom" v-if="description" >
|
<div class="px-5 py-5 border-bottom" v-if="description" >
|
||||||
<p>Popis zadania</p>
|
<p>Popis zadania</p>
|
||||||
<section v-html="description" class="description-detail px-2 py-2 w-100 rounded mt-2" />
|
<section v-html="preparedDescription" class="description-detail px-2 py-2 w-100 rounded mt-2" />
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="masterTaskDescLinks?.length > 0" class="px-5 d-flex flex-column">
|
|
||||||
<p class="py-3">Odkazy na server</p>
|
|
||||||
<div v-for="index in masterTaskDescLinks" :key="index" class="server-links my-1 rounded-pill text-truncate position-relative">
|
|
||||||
<a :href="index">{{ index }}</a>
|
|
||||||
<p v-if="!copiedIndices.includes('subtask-' + index)" class="copy-btn" @click.stop="copyToClipboard('subtask-', index)">Copy</p>
|
|
||||||
<p v-else class="copying-btn">Copied!</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="px-5 py-5 border-bottom" v-if="inheritedDescription">
|
<div class="px-5 py-5 border-bottom" v-if="inheritedDescription">
|
||||||
<p>Popis mastertasku</p>
|
<p>Popis mastertasku</p>
|
||||||
<section v-html="inheritedDescription" class="description-detail px-2 py-2 w-100 rounded mt-2" />
|
<section v-html="preparedInheritedDescription" class="description-detail px-2 py-2 w-100 rounded mt-2" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { getServerLinks, detectOS } from '@/plugins/tm@_utils/server-links.utils'
|
import { prepareHTMLDescription } from '@/plugins/tm@_utils/server-links.utils'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
@@ -37,29 +28,15 @@ export default {
|
|||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
copiedIndices: []
|
copiedIndices: [],
|
||||||
|
preparedDescription: '',
|
||||||
|
preparedInheritedDescription: ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
mounted() {
|
||||||
masterTaskDescLinks() {
|
this.preparedDescription = prepareHTMLDescription(this.description)
|
||||||
return getServerLinks(this.description)
|
this.preparedInheritedDescription = prepareHTMLDescription(this.inheritedDescription)
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
|
||||||
copyToClipboard(prefix, index) {
|
|
||||||
const fullIndex = prefix + index
|
|
||||||
const os = detectOS()
|
|
||||||
navigator.clipboard.writeText(os + ': ' + index).then(() => {
|
|
||||||
this.copiedIndices.push(fullIndex)
|
|
||||||
setTimeout(() => {
|
|
||||||
const idx = this.copiedIndices.indexOf(fullIndex)
|
|
||||||
if (idx > -1)
|
|
||||||
this.copiedIndices.splice(idx, 1)
|
|
||||||
}, 1000)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -298,7 +298,7 @@ export default {
|
|||||||
async save() {
|
async save() {
|
||||||
if (this.mastertask.id) {
|
if (this.mastertask.id) {
|
||||||
this.mastertask.employees = this.mastertask.employees.map(employee => {
|
this.mastertask.employees = this.mastertask.employees.map(employee => {
|
||||||
const { duration } = this.mastertask.subtasks.find(({ employee_id }) => employee_id == employee.id)
|
const { duration } = this.mastertask.subtasks.find(({ employee_id }) => employee_id == employee.id) || {}
|
||||||
employee.duration = duration
|
employee.duration = duration
|
||||||
return employee
|
return employee
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,35 +1,17 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="px-5 py-5 border-bottom" v-if="description" >
|
<div class="px-5 py-5 border-bottom" v-if="description" >
|
||||||
<p>Popis zadania</p>
|
<p>Popis zadania</p>
|
||||||
<section v-html="description" class="description-detail px-2 py-2 w-100 rounded mt-2" />
|
<section v-html="preparedDescription" class="description-detail px-2 py-2 w-100 rounded mt-2" />
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="subtaskDescLinks?.length > 0" class="px-5 d-flex flex-column">
|
|
||||||
<p class="py-3">Odkazy na server</p>
|
|
||||||
<div v-for="index in subtaskDescLinks" :key="'subtask-' + index" class="server-links my-1 rounded-pill text-truncate position-relative">
|
|
||||||
<a :href="index">{{ index }}</a>
|
|
||||||
<p v-if="!copiedIndices.includes('subtask-' + index)" class="copy-btn" @click.stop="copyToClipboard('subtask-', index)">Copy</p>
|
|
||||||
<p v-else class="copying-btn">Copied!</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="px-5 py-5 border-bottom" v-if="mastertaskDescription">
|
<div class="px-5 py-5 border-bottom" v-if="mastertaskDescription">
|
||||||
<p>Popis mastertasku</p>
|
<p>Popis mastertasku</p>
|
||||||
<section v-html="mastertaskDescription" class="description-detail px-2 py-2 w-100 rounded mt-2" />
|
<section v-html="preparedMastertaskDescription" class="description-detail px-2 py-2 w-100 rounded mt-2" />
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="subtaskMTDecsLinks?.length > 0" class="px-5 d-flex flex-column">
|
|
||||||
<p class="py-3">Odkazy na server</p>
|
|
||||||
<div v-for="index in subtaskMTDecsLinks" :key="'mastertask-' + index" class="server-links my-1 rounded-pill text-truncate position-relative">
|
|
||||||
<a :href="index">{{ index }}</a>
|
|
||||||
<p v-if="!copiedIndices.includes('mastertask-' + index)" class="copy-btn" @click.stop="copyToClipboard('mastertask-', index)">Copy</p>
|
|
||||||
<p v-else class="copying-btn">Copied!</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { getServerLinks, detectOS } from '@/plugins/tm@_utils/server-links.utils'
|
import { prepareHTMLDescription } from '@/plugins/tm@_utils/server-links.utils'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
@@ -46,33 +28,15 @@ export default {
|
|||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
copiedIndices: []
|
copiedIndices: [],
|
||||||
|
preparedDescription: '',
|
||||||
|
preparedMastertaskDescription: ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
mounted() {
|
||||||
subtaskDescLinks() {
|
this.preparedDescription = prepareHTMLDescription(this.description)
|
||||||
return getServerLinks(this.description)
|
this.preparedMastertaskDescription = prepareHTMLDescription(this.mastertaskDescription)
|
||||||
},
|
|
||||||
|
|
||||||
subtaskMTDecsLinks() {
|
|
||||||
return getServerLinks(this.mastertaskDescription)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
|
||||||
copyToClipboard(prefix, index) {
|
|
||||||
const fullIndex = prefix + index
|
|
||||||
const os = detectOS()
|
|
||||||
navigator.clipboard.writeText(os + ': ' + index).then(() => {
|
|
||||||
this.copiedIndices.push(fullIndex)
|
|
||||||
setTimeout(() => {
|
|
||||||
const idx = this.copiedIndices.indexOf(fullIndex)
|
|
||||||
if (idx > -1)
|
|
||||||
this.copiedIndices.splice(idx, 1)
|
|
||||||
}, 1000)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
Reference in new issue
Block a user