From 3cd6d7ad4d21cc4bfb5c356acee129888508b9c6 Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Tue, 2 Jul 2024 09:13:35 +0200 Subject: [PATCH 1/3] feat(NcCollectionList): merge nextcloud-vue-collections into nextcloud/vue Signed-off-by: Maksim Sukharev (cherry picked from commit 0637422d32574e72319338d3b3177e7b36a507d6) Signed-off-by: Maksim Sukharev --- .../NcCollectionList/NcCollectionList.vue | 345 ++++++++++++++++++ .../NcCollectionList/NcCollectionListItem.vue | 313 ++++++++++++++++ .../NcCollectionList/collectionservice.js | 71 ++++ .../NcCollectionList/collectionstore.js | 82 +++++ src/components/NcCollectionList/index.js | 6 + src/components/index.ts | 1 + 6 files changed, 818 insertions(+) create mode 100644 src/components/NcCollectionList/NcCollectionList.vue create mode 100644 src/components/NcCollectionList/NcCollectionListItem.vue create mode 100644 src/components/NcCollectionList/collectionservice.js create mode 100644 src/components/NcCollectionList/collectionstore.js create mode 100644 src/components/NcCollectionList/index.js diff --git a/src/components/NcCollectionList/NcCollectionList.vue b/src/components/NcCollectionList/NcCollectionList.vue new file mode 100644 index 00000000..483ff886 --- /dev/null +++ b/src/components/NcCollectionList/NcCollectionList.vue @@ -0,0 +1,345 @@ + + + + + + + diff --git a/src/components/NcCollectionList/NcCollectionListItem.vue b/src/components/NcCollectionList/NcCollectionListItem.vue new file mode 100644 index 00000000..b9171365 --- /dev/null +++ b/src/components/NcCollectionList/NcCollectionListItem.vue @@ -0,0 +1,313 @@ + + + + + + + diff --git a/src/components/NcCollectionList/collectionservice.js b/src/components/NcCollectionList/collectionservice.js new file mode 100644 index 00000000..d49dfab5 --- /dev/null +++ b/src/components/NcCollectionList/collectionservice.js @@ -0,0 +1,71 @@ +/** + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import axios from '@nextcloud/axios' +import { generateOcsUrl } from '@nextcloud/router' + +class CollectionService { + + constructor() { + this.http = axios + } + + listCollection(collectionId) { + return this.http.get(generateOcsUrl('collaboration/resources/collections/{collectionId}', { collectionId })) + } + + renameCollection(collectionId, collectionName) { + return this.http.put(generateOcsUrl('collaboration/resources/collections/{collectionId}', { collectionId }), { + collectionName, + }).then(result => { + return result.data.ocs.data + }) + } + + getCollectionsByResource(resourceType, resourceId) { + return this.http.get(generateOcsUrl('collaboration/resources/{resourceType}/{resourceId}', { resourceType, resourceId })) + .then(result => { + return result.data.ocs.data + }) + } + + createCollection(resourceType, resourceId, name) { + return this.http.post(generateOcsUrl('collaboration/resources/{resourceType}/{resourceId}', { resourceType, resourceId }), { + name, + }) + .then((response) => { + return response.data.ocs.data + }) + } + + addResource(collectionId, resourceType, resourceId) { + resourceId = '' + resourceId + return this.http.post(generateOcsUrl('collaboration/resources/collections/{collectionId}', { collectionId }), { + resourceType, + resourceId, + }).then((response) => { + return response.data.ocs.data + }) + } + + removeResource(collectionId, resourceType, resourceId) { + return this.http.delete(generateOcsUrl('collaboration/resources/collections/{collectionId}', { collectionId }), { params: { resourceType, resourceId } }) + .then((response) => { + return response.data.ocs.data + }) + } + + search(query) { + return this.http.get(generateOcsUrl('collaboration/resources/collections/search/{query}', { query })) + .then((response) => { + return response.data.ocs.data + }) + } + +} + +const service = new CollectionService() + +export default service diff --git a/src/components/NcCollectionList/collectionstore.js b/src/components/NcCollectionList/collectionstore.js new file mode 100644 index 00000000..e6aa1c67 --- /dev/null +++ b/src/components/NcCollectionList/collectionstore.js @@ -0,0 +1,82 @@ +/** + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import { reactive, set } from 'vue' +import service from './collectionservice.js' + +const state = reactive({ + collections: [], +}) + +const mutations = { + addCollections(collections) { + set(state, 'collections', collections) + }, + addCollection(collection) { + state.collections.push(collection) + }, + removeCollection(collectionId) { + set(state, 'collections', state.collections.filter(item => item.id !== collectionId)) + }, + updateCollection(collection) { + const index = state.collections.findIndex((_item) => _item.id === collection.id) + if (index !== -1) { + set(state.collections, index, collection) + } else { + state.collections.push(collection) + } + }, +} + +const actions = { + fetchCollectionsByResource({ resourceType, resourceId }) { + return service.getCollectionsByResource(resourceType, resourceId).then((collections) => { + mutations.addCollections(collections) + return collections + }) + }, + createCollection({ baseResourceType, baseResourceId, resourceType, resourceId, name }) { + return service.createCollection(baseResourceType, baseResourceId, name).then((collection) => { + mutations.addCollection(collection) + actions.addResourceToCollection({ + collectionId: collection.id, + resourceType, + resourceId, + }) + }) + }, + renameCollection({ collectionId, name }) { + return service.renameCollection(collectionId, name).then((collection) => { + mutations.updateCollection(collection) + return collection + }) + }, + addResourceToCollection({ collectionId, resourceType, resourceId }) { + return service.addResource(collectionId, resourceType, resourceId).then((collection) => { + mutations.updateCollection(collection) + return collection + }) + }, + removeResource({ collectionId, resourceType, resourceId }) { + return service.removeResource(collectionId, resourceType, resourceId).then((collection) => { + if (collection.resources.length > 0) { + mutations.updateCollection(collection) + } else { + mutations.removeCollection(collection) + } + }) + }, + search(query) { + return service.search(query) + }, + +} + +const store = { + actions, + state, +} +export default store +export { actions, state } diff --git a/src/components/NcCollectionList/index.js b/src/components/NcCollectionList/index.js new file mode 100644 index 00000000..98ca1dea --- /dev/null +++ b/src/components/NcCollectionList/index.js @@ -0,0 +1,6 @@ +/** + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +export { default as NcCollectionListItem } from './NcCollectionListItem.vue' +export { default } from './NcCollectionList.vue' diff --git a/src/components/index.ts b/src/components/index.ts index 7e4628d9..fd7a2419 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -37,6 +37,7 @@ export { default as NcBreadcrumbs } from './NcBreadcrumbs/index.js' export { default as NcButton } from './NcButton/index' export { default as NcCheckboxRadioSwitch } from './NcCheckboxRadioSwitch/index.js' export { default as NcChip } from './NcChip/index' +export { default as NcCollectionList, NcCollectionListItem } from './NcCollectionList/index.js' export { default as NcColorPicker } from './NcColorPicker/index.js' export { default as NcContent } from './NcContent/index.js' export { default as NcCounterBubble } from './NcCounterBubble/index.js' From 100bb3a6f8860d26f5c2f1450546119ee862021b Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Tue, 2 Jul 2024 11:05:58 +0200 Subject: [PATCH 2/3] refactor(NcCollectionList): refactor code - migrate service from Class to simple functions - migrate store to composable - make NcCollectionListItem a visual component - update avatar styles - use RouterLink for relative paths in the same app - update message.pot translations - add docs Signed-off-by: Maksim Sukharev (cherry picked from commit 94177fec585e2b5c3e0e8262382cc9d37d295c36) Signed-off-by: Maksim Sukharev --- l10n/messages.pot | 27 +++ .../NcCollectionList/NcCollectionList.vue | 188 ++++++++++-------- .../NcCollectionList/NcCollectionListItem.vue | 93 +++++---- .../NcCollectionList/collectionservice.js | 71 ------- .../NcCollectionList/collectionstore.js | 82 -------- src/components/NcCollectionList/index.js | 1 - src/components/NcCollectionList/service.ts | 80 ++++++++ .../NcCollectionList/useCollections.js | 92 +++++++++ src/components/index.ts | 2 +- styleguide.config.cjs | 1 + 10 files changed, 362 insertions(+), 275 deletions(-) delete mode 100644 src/components/NcCollectionList/collectionservice.js delete mode 100644 src/components/NcCollectionList/collectionstore.js create mode 100644 src/components/NcCollectionList/service.ts create mode 100644 src/components/NcCollectionList/useCollections.js diff --git a/l10n/messages.pot b/l10n/messages.pot index a5069f70..59eba91a 100644 --- a/l10n/messages.pot +++ b/l10n/messages.pot @@ -27,6 +27,9 @@ msgstr "" msgid "Activities" msgstr "" +msgid "Add to a project" +msgstr "" + msgid "Animals & Nature" msgstr "" @@ -102,6 +105,9 @@ msgstr "" msgid "Confirm changes" msgstr "" +msgid "Connect items to a project to make them easier to find" +msgstr "" + msgid "Custom" msgstr "" @@ -136,6 +142,15 @@ msgstr "" msgid "External documentation for {name}" msgstr "" +msgid "Failed to add the item to the project" +msgstr "" + +msgid "Failed to create a project" +msgstr "" + +msgid "Failed to rename the project" +msgstr "" + msgid "Favorite" msgstr "" @@ -161,6 +176,9 @@ msgstr "" msgid "Gold" msgstr "" +msgid "Hide details" +msgstr "" + msgid "Hide password" msgstr "" @@ -295,6 +313,9 @@ msgstr "" msgid "Related team resources" msgstr "" +msgid "Rename project" +msgstr "" + #. TRANSLATORS: A color name for RGB(191, 103, 139) msgid "Rosy brown" msgstr "" @@ -337,6 +358,9 @@ msgstr "" msgid "Settings navigation" msgstr "" +msgid "Show details" +msgstr "" + msgid "Show password" msgstr "" @@ -370,6 +394,9 @@ msgstr "" msgid "Travel & Places" msgstr "" +msgid "Type to search for existing projects" +msgstr "" + msgid "Type to search time zone" msgstr "" diff --git a/src/components/NcCollectionList/NcCollectionList.vue b/src/components/NcCollectionList/NcCollectionList.vue index 483ff886..85058240 100644 --- a/src/components/NcCollectionList/NcCollectionList.vue +++ b/src/components/NcCollectionList/NcCollectionList.vue @@ -3,6 +3,19 @@ - SPDX-License-Identifier: AGPL-3.0-or-later --> + +Provides a Vue standalone component for Nextcloud Projects feature introduced in Nextcloud 16. Replaces deprecated `nextcloud-vue-collections` library. + +Projects feature is deprecated since Nextcloud 25, and superseded by Related resources. See [NcRelatedResourcesPanel](#/Components/NcRelatedResourcesPanel) documentation for more information. + +### Usage + +To enable feature in Nextcloud, run following command: +```sh +occ config:system:set --value true 'projects.enabled' +``` + +

- {{ t('core', 'Connect items to a project to make them easier to find') }} + {{ t('Connect items to a project to make them easier to find') }}

@@ -44,37 +57,30 @@ {{ error }} - + @@ -267,11 +293,11 @@ export default { .collection-list > li { display: flex; - align-items: start; + align-items: center; gap: 12px; & > .avatar { - margin-top: auto; + margin-top: 0; } } @@ -326,6 +352,8 @@ div.avatar { .avatar { display: block; + width: 32px; + height: 32px; background-color: var(--color-background-darker) !important; } diff --git a/src/components/NcCollectionList/NcCollectionListItem.vue b/src/components/NcCollectionList/NcCollectionListItem.vue index b9171365..efb95a8c 100644 --- a/src/components/NcCollectionList/NcCollectionListItem.vue +++ b/src/components/NcCollectionList/NcCollectionListItem.vue @@ -10,7 +10,7 @@ class="collection-item-name" title="" @click="showDetails">{{ collection.name }} -
+
- + :to="getComponent(resource).to" + :href="getComponent(resource).href" + :class="typeClass(resource)"> + +
- {{ detailsOpen ? t('core', 'Hide details') : t('core', 'Show details') }} + {{ detailsOpen ? t('Hide details') : t('Show details') }} - {{ t('core', 'Rename project') }} + {{ t('Rename project') }} -
- {{ error.rename }} +
+ {{ error }}
@@ -57,15 +66,13 @@