Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 80 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"mitt": "^3.0.1",
"moment": "^2.30.1",
"p-limit": "^5.0.0",
"pinia": "^2.1.7",
"qr-image": "^3.2.0",
"string-natural-compare": "^3.0.1",
"uuid": "^9.0.1",
Expand Down
28 changes: 23 additions & 5 deletions src/components/AppNavigation/Settings/SettingsAddressbook.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,16 @@
</template>
</ActionInput>
</template>

<!-- delete addressbook -->
<ActionButton v-if="hasMultipleAddressbooks"
<ActionButton v-if="hasMultipleAddressbooks && addressbook.owner !== principalUrl && addressbook.owner !== '/remote.php/dav/principals/system/system/'"
@click="confirmUnshare">
<template #icon>
<IconLoading v-if="deleteAddressbookLoading" :size="20" />
<IconDelete :size="20" />
</template>
{{ t('contacts', 'Unshare from me') }}
</ActionButton>
<ActionButton v-else-if="hasMultipleAddressbooks && addressbook.owner !== '/remote.php/dav/principals/system/system/'"
@click="confirmDeletion">
<template #icon>
<IconLoading v-if="deleteAddressbookLoading" :size="20" />
Expand All @@ -116,7 +123,6 @@
{{ t('contacts', 'Delete') }}
</ActionButton>
</Actions>

<!-- sharing input -->
<ShareAddressBook v-if="shareOpen && !addressbook.readOnly" :addressbook="addressbook" />
</li>
Expand All @@ -143,6 +149,8 @@ import { showError } from '@nextcloud/dialogs'

import CopyToClipboardMixin from '../../../mixins/CopyToClipboardMixin.js'

import usePrincipalsStore from '../../../store/principals.js'

export default {
name: 'SettingsAddressbook',

Expand Down Expand Up @@ -241,6 +249,10 @@ export default {
groupsCount() {
return this.groups.length
},
principalUrl() {
const principalsStore = usePrincipalsStore()
return principalsStore.currentUserPrincipal.principalUrl
},
},
watch: {
menuOpen() {
Expand Down Expand Up @@ -277,7 +289,6 @@ export default {
this.toggleEnabledLoading = false
}
},

confirmDeletion() {
OC.dialogs.confirm(
t('contacts', 'This will delete the address book and every contacts within it'),
Expand All @@ -286,7 +297,14 @@ export default {
true,
)
},

confirmUnshare() {
OC.dialogs.confirm(
t('contacts', 'This will unshare the address book and every contacts within it'),
t('contacts', 'Unshare {addressbook}?', { addressbook: this.addressbook.displayName }),
this.deleteAddressbook,
true,
)
},
async deleteAddressbook(confirm) {
if (confirm) {
// change to loading status
Expand Down
6 changes: 6 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import '../css/contacts.scss'
// Dialogs css
import '@nextcloud/dialogs/style.css'

import { createPinia, PiniaVuePlugin } from 'pinia'

// CSP config for webpack dynamic chunk loading
// eslint-disable-next-line
__webpack_nonce__ = btoa(getRequestToken())
Expand All @@ -51,6 +53,9 @@ __webpack_nonce__ = btoa(getRequestToken())
// eslint-disable-next-line
__webpack_public_path__ = generateFilePath('contacts', '', 'js/')

Vue.use(PiniaVuePlugin)
const pinia = createPinia()

// Register global directives
Vue.directive('ClickOutside', ClickOutside)
Vue.directive('Tooltip', VTooltip)
Expand Down Expand Up @@ -81,4 +86,5 @@ export default new Vue({
router,
store,
render: h => h(App),
pinia,
})
34 changes: 34 additions & 0 deletions src/store/principals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @copyright Copyright (c) 2024 Grigory Vodyanov <scratchx@gmx.com>
*
* @author Grigory Vodyanov <scratchx@gmx.com>
*
* @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/>.
*
*/

import { defineStore } from 'pinia'

export default defineStore('principals', {
state: () => ({
currentUserPrincipal: null,
}),
actions: {
setCurrentUserPrincipal(client) {
this.currentUserPrincipal = client?.currentUserPrincipal
},
},
})
4 changes: 4 additions & 0 deletions src/views/Contacts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ import rfcProps from '../models/rfcProps.js'
import client from '../services/cdav.js'
import isCirclesEnabled from '../services/isCirclesEnabled.js'

import usePrincipalsStore from '../store/principals.js'

export default {
name: 'Contacts',

Expand Down Expand Up @@ -250,6 +252,8 @@ export default {
// get addressbooks then get contacts
client.connect({ enableCardDAV: true }).then(() => {
this.logger.debug('Connected to dav!', { client })
const principalsStore = usePrincipalsStore()
principalsStore.setCurrentUserPrincipal(client)
this.$store.dispatch('getAddressbooks')
.then((addressbooks) => {
const writeableAddressBooks = addressbooks.filter(addressbook => !addressbook.readOnly)
Expand Down