[getServerLinks] added utils, links in task view

This commit is contained in:
romankko2 committed 2024-06-28 17:05:24 +02:00
1 parent f3d3aa916e
commit c74f875571
5 files changed
+109 -1

No files matched your search

@@ -1,5 +1,5 @@
<template>
<header class="login-header-border hover">
<header class="login-header-border">
<v-container>
<img :src="require('@/plugins/app/_img/jandl-logo.svg')" alt="jandl-logo" @click="$router.push({name: 'Login'})">
</v-container>
+4
View File
@@ -105,6 +105,10 @@ input[type="time"]::-webkit-calendar-picker-indicator
.v-input
height: 40px !important
.server-links
a
text-decoration: underline
@media (max-width: 534px)
.mobile-view
flex-direction: column
@@ -0,0 +1,57 @@
export function getServerLinks(description) {
const os = detectOS()
// 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(`<a href="${text}" target="_blank" rel="noopener noreferrer">${text}</a>`)
} else if (os === 'win' && text.startsWith('\\\\')) {
links.add(`<a href="file://${text.replace(/\\/g, '/')}" target="_blank" rel="noopener noreferrer">${text}</a>`)
} else if (os === 'mac' && text.startsWith('\\\\')) {
const smbLink = 'smb:' + text.replace(/\\/g, '/')
links.add(`<a href="${smbLink}" target="_blank" rel="noopener noreferrer">${smbLink}</a>`)
} else if (os === 'win' && text.startsWith('smb://')) {
const windowsLink = text.replace(/^smb:/, '').replace(/\//g, '\\')
links.add(`<a href="file://${windowsLink}" target="_blank" rel="noopener noreferrer">${windowsLink}</a>`)
}
const anchor = p.querySelector('a')
if (anchor) {
const href = anchor.getAttribute('href')
if (os === 'mac' && href.startsWith('smb://')) {
links.add(`<a href="${href}" target="_blank" rel="noopener noreferrer">${href}</a>`)
} else if (os === 'win' && href.startsWith('\\\\')) {
links.add(`<a href="file://${href.replace(/\\/g, '/')}" target="_blank" rel="noopener noreferrer">${href}</a>`)
} else if (os === 'mac' && href.startsWith('\\\\')) {
const smbLink = 'smb:' + href.replace(/\\/g, '/')
links.add(`<a href="${smbLink}" target="_blank" rel="noopener noreferrer">${smbLink}</a>`)
} else if (os === 'win' && href.startsWith('smb://')) {
const windowsLink = href.replace(/^smb:/, '').replace(/\//g, '\\')
links.add(`<a href="file://${windowsLink}" target="_blank" rel="noopener noreferrer">${windowsLink}</a>`)
}
}
})
return Array.from(links).join('<br>')
}
export function detectOS() {
const platform = window.navigator.platform
const macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K']
const windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE']
if (macosPlatforms.indexOf(platform) !== -1) {
return 'mac'
} else if (windowsPlatforms.indexOf(platform) !== -1) {
return 'win'
}
return 'win'
}
@@ -4,6 +4,11 @@
<section v-html="description" class="description-detail px-2 py-2 w-100 rounded mt-2" />
</div>
<div v-if="hasMasterTaskDescLinks" class="px-5">
<p class="py-3">Odkazy na server</p>
<p class="server-links" v-html="masterTaskDescLinks" />
</div>
<div class="px-5 py-5 border-bottom" v-if="inheritedDescription">
<p>Popis mastertasku</p>
<section v-html="inheritedDescription" class="description-detail px-2 py-2 w-100 rounded mt-2" />
@@ -11,6 +16,8 @@
</template>
<script>
import { getServerLinks } from '@/plugins/tm@_utils/server-links.utils'
export default {
props: {
description: {
@@ -22,6 +29,16 @@ export default {
type: String || null,
default: () => null
}
},
computed: {
masterTaskDescLinks() {
return getServerLinks(this.description)
},
hasMasterTaskDescLinks() {
return this.masterTaskDescLinks.trim().length > 0
}
}
}
</script>
@@ -4,13 +4,25 @@
<section v-html="description" class="description-detail px-2 py-2 w-100 rounded mt-2" />
</div>
<div v-if="hasSubtaskDescLinks" class="px-5">
<p class="py-3">Odkazy na server</p>
<p class="server-links" v-html="subtaskDescLinks" />
</div>
<div class="px-5 py-5 border-bottom" v-if="mastertaskDescription">
<p>Popis mastertasku</p>
<section v-html="mastertaskDescription" class="description-detail px-2 py-2 w-100 rounded mt-2" />
</div>
<div v-if="hasSubtaskMTDescLinks" class="px-5">
<p class="py-3">Odkazy na server</p>
<p class="server-links" v-html="subtaskMTDecsLinks" />
</div>
</template>
<script>
import { getServerLinks } from '@/plugins/tm@_utils/server-links.utils'
export default {
props: {
description: {
@@ -22,6 +34,24 @@ export default {
type: String || null,
default: () => null
}
},
computed: {
subtaskDescLinks() {
return getServerLinks(this.description)
},
subtaskMTDecsLinks() {
return getServerLinks(this.mastertaskDescription)
},
hasSubtaskDescLinks() {
return this.subtaskDescLinks.trim().length > 0
},
hasSubtaskMTDescLinks() {
return this.subtaskMTDecsLinks.trim().length > 0
}
}
}
</script>