@@ -21,19 +21,18 @@ | |||
--> | |||
<template> | |||
<MultiselectTag v-model="newValue" | |||
<MultiselectTags v-model="newValue" | |||
:multiple="false" | |||
:label="t('workflowengine', 'Select a tag')" | |||
@input="update" /> | |||
</template> | |||
<script> | |||
import { MultiselectTag } from './MultiselectTag' | |||
import MultiselectTags from '@nextcloud/vue/dist/Components/NcMultiselectTags.js' | |||
export default { | |||
name: 'FileSystemTag', | |||
components: { | |||
MultiselectTag, | |||
MultiselectTags, | |||
}, | |||
props: { | |||
value: { |
@@ -1,130 +0,0 @@ | |||
<!-- | |||
- @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net> | |||
- | |||
- @author Julius Härtl <jus@bitgrid.net> | |||
- | |||
- @license GNU AGPL version 3 or any later version | |||
- | |||
- This program is free software: you can redistribute it and/or modify | |||
- it under the terms of the GNU Affero General Public License as | |||
- published by the Free Software Foundation, either version 3 of the | |||
- License, or (at your option) any later version. | |||
- | |||
- This program is distributed in the hope that it will be useful, | |||
- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
- GNU Affero General Public License for more details. | |||
- | |||
- You should have received a copy of the GNU Affero General Public License | |||
- along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
- | |||
--> | |||
<template> | |||
<NcMultiselect v-model="inputValObjects" | |||
:options="tags" | |||
:options-limit="5" | |||
:placeholder="label" | |||
track-by="id" | |||
:custom-label="tagLabel" | |||
class="multiselect-vue" | |||
:multiple="multiple" | |||
:close-on-select="false" | |||
:tag-width="60" | |||
:disabled="disabled" | |||
@input="update"> | |||
<span slot="noResult">{{ t('core', 'No results') }}</span> | |||
<template #option="scope"> | |||
{{ tagLabel(scope.option) }} | |||
</template> | |||
</NcMultiselect> | |||
</template> | |||
<script> | |||
import NcMultiselect from '@nextcloud/vue/dist/Components/NcMultiselect' | |||
import { searchTags } from './api' | |||
let uuid = 0 | |||
export default { | |||
name: 'MultiselectTag', | |||
components: { | |||
NcMultiselect, | |||
}, | |||
props: { | |||
label: { | |||
type: String, | |||
required: true, | |||
}, | |||
value: { | |||
type: [String, Array], | |||
default: null, | |||
}, | |||
disabled: { | |||
type: Boolean, | |||
default: false, | |||
}, | |||
multiple: { | |||
type: Boolean, | |||
default: false, | |||
}, | |||
}, | |||
data() { | |||
return { | |||
inputValObjects: [], | |||
tags: [], | |||
} | |||
}, | |||
computed: { | |||
id() { | |||
return 'settings-input-text-' + this.uuid | |||
}, | |||
}, | |||
watch: { | |||
value(newVal) { | |||
this.inputValObjects = this.getValueObject() | |||
}, | |||
}, | |||
beforeCreate() { | |||
this.uuid = uuid.toString() | |||
uuid += 1 | |||
searchTags().then((result) => { | |||
this.tags = result | |||
this.inputValObjects = this.getValueObject() | |||
}).catch(console.error.bind(this)) | |||
}, | |||
methods: { | |||
getValueObject() { | |||
if (this.tags.length === 0) { | |||
return [] | |||
} | |||
if (this.multiple) { | |||
return this.value.filter((tag) => tag !== '').map( | |||
(id) => this.tags.find((tag2) => tag2.id === id) | |||
) | |||
} else { | |||
return this.tags.find((tag) => tag.id === this.value) | |||
} | |||
}, | |||
update() { | |||
if (this.multiple) { | |||
this.$emit('input', this.inputValObjects.map((element) => element.id)) | |||
} else { | |||
if (this.inputValObjects === null) { | |||
this.$emit('input', '') | |||
} else { | |||
this.$emit('input', this.inputValObjects.id) | |||
} | |||
} | |||
}, | |||
tagLabel({ displayName, userVisible, userAssignable }) { | |||
if (userVisible === false) { | |||
return t('systemtags', '%s (invisible)').replace('%s', displayName) | |||
} | |||
if (userAssignable === false) { | |||
return t('systemtags', '%s (restricted)').replace('%s', displayName) | |||
} | |||
return displayName | |||
}, | |||
}, | |||
} | |||
</script> |
@@ -1,115 +0,0 @@ | |||
/** | |||
* @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net> | |||
* | |||
* @author Christoph Wurst <christoph@winzerhof-wurst.at> | |||
* @author John Molakvoæ <skjnldsv@protonmail.com> | |||
* @author Julius Härtl <jus@bitgrid.net> | |||
* @author Roeland Jago Douma <roeland@famdouma.nl> | |||
* | |||
* @license AGPL-3.0-or-later | |||
* | |||
* This program is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU Affero General Public License as | |||
* published by the Free Software Foundation, either version 3 of the | |||
* License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU Affero General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Affero General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
* | |||
*/ | |||
import axios from '@nextcloud/axios' | |||
import { generateRemoteUrl } from '@nextcloud/router' | |||
const xmlToJson = (xml) => { | |||
let obj = {} | |||
if (xml.nodeType === 1) { | |||
if (xml.attributes.length > 0) { | |||
obj['@attributes'] = {} | |||
for (let j = 0; j < xml.attributes.length; j++) { | |||
const attribute = xml.attributes.item(j) | |||
obj['@attributes'][attribute.nodeName] = attribute.nodeValue | |||
} | |||
} | |||
} else if (xml.nodeType === 3) { | |||
obj = xml.nodeValue | |||
} | |||
if (xml.hasChildNodes()) { | |||
for (let i = 0; i < xml.childNodes.length; i++) { | |||
const item = xml.childNodes.item(i) | |||
const nodeName = item.nodeName | |||
if (typeof (obj[nodeName]) === 'undefined') { | |||
obj[nodeName] = xmlToJson(item) | |||
} else { | |||
if (typeof obj[nodeName].push === 'undefined') { | |||
const old = obj[nodeName] | |||
obj[nodeName] = [] | |||
obj[nodeName].push(old) | |||
} | |||
obj[nodeName].push(xmlToJson(item)) | |||
} | |||
} | |||
} | |||
return obj | |||
} | |||
const parseXml = (xml) => { | |||
let dom = null | |||
try { | |||
dom = (new DOMParser()).parseFromString(xml, 'text/xml') | |||
} catch (e) { | |||
console.error('Failed to parse xml document', e) | |||
} | |||
return dom | |||
} | |||
const xmlToTagList = (xml) => { | |||
const json = xmlToJson(parseXml(xml)) | |||
const list = json['d:multistatus']['d:response'] | |||
const result = [] | |||
for (const index in list) { | |||
const tag = list[index]['d:propstat'] | |||
if (tag['d:status']['#text'] !== 'HTTP/1.1 200 OK') { | |||
continue | |||
} | |||
result.push({ | |||
id: tag['d:prop']['oc:id']['#text'], | |||
displayName: tag['d:prop']['oc:display-name']['#text'], | |||
canAssign: tag['d:prop']['oc:can-assign']['#text'] === 'true', | |||
userAssignable: tag['d:prop']['oc:user-assignable']['#text'] === 'true', | |||
userVisible: tag['d:prop']['oc:user-visible']['#text'] === 'true', | |||
}) | |||
} | |||
return result | |||
} | |||
const searchTags = function() { | |||
return axios({ | |||
method: 'PROPFIND', | |||
url: generateRemoteUrl('dav') + '/systemtags/', | |||
data: `<?xml version="1.0"?> | |||
<d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns"> | |||
<d:prop> | |||
<oc:id /> | |||
<oc:display-name /> | |||
<oc:user-visible /> | |||
<oc:user-assignable /> | |||
<oc:can-assign /> | |||
</d:prop> | |||
</d:propfind>`, | |||
}).then((response) => { | |||
return xmlToTagList(response.data) | |||
}) | |||
} | |||
export { | |||
searchTags, | |||
} |
@@ -1,27 +0,0 @@ | |||
/** | |||
* @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net> | |||
* | |||
* @author John Molakvoæ <skjnldsv@protonmail.com> | |||
* @author Julius Härtl <jus@bitgrid.net> | |||
* | |||
* @license AGPL-3.0-or-later | |||
* | |||
* This program is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU Affero General Public License as | |||
* published by the Free Software Foundation, either version 3 of the | |||
* License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU Affero General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Affero General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
* | |||
*/ | |||
import MultiselectTag from './MultiselectTag' | |||
export default MultiselectTag | |||
export { MultiselectTag } |
@@ -360,6 +360,8 @@ | |||
/*! For license information please see NcMultiselect.js.LICENSE.txt */ | |||
/*! For license information please see NcMultiselectTags.js.LICENSE.txt */ | |||
/*! For license information please see NcPasswordField.js.LICENSE.txt */ | |||
/*! For license information please see NcRichContenteditable.js.LICENSE.txt */ |