Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add selection for recommended apps #47055

Merged
merged 1 commit into from
Aug 6, 2024
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
47 changes: 30 additions & 17 deletions core/src/components/setup/RecommendedApps.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,12 @@
<p v-else-if="loadingAppsError" class="loading-error text-center">
{{ t('core', 'Could not fetch list of apps from the App Store.') }}
</p>
<p v-else-if="installingApps" class="text-center">
{{ t('core', 'Installing apps …') }}
</p>

<div v-for="app in recommendedApps" :key="app.id" class="app">
<template v-if="!isHidden(app.id)">
<img :src="customIcon(app.id)" alt="">
<div class="info">
<h3>
{{ customName(app) }}
<span v-if="app.loading" class="icon icon-loading-small-dark" />
<span v-else-if="app.active" class="icon icon-checkmark-white" />
</h3>
<h3>{{ customName(app) }}</h3>
<p v-html="customDescription(app.id)" />
<p v-if="app.installationError">
<strong>{{ t('core', 'App download or installation failed') }}</strong>
Expand All @@ -36,11 +29,15 @@
<strong>{{ t('core', 'Cannot install this app') }}</strong>
</p>
</div>
<NcCheckboxRadioSwitch :checked="app.isSelected || app.active"
:disabled="!app.isCompatible || app.active"
:loading="app.loading"
@update:checked="toggleSelect(app.id)" />
</template>
</div>

<div class="dialog-row">
<NcButton v-if="showInstallButton"
<NcButton v-if="showInstallButton && !installingApps"
type="tertiary"
role="link"
:href="defaultPageUrl">
Expand All @@ -49,8 +46,9 @@

<NcButton v-if="showInstallButton"
type="primary"
:disabled="installingApps || !isAnyAppSelected"
@click.stop.prevent="installApps">
{{ t('core', 'Install recommended apps') }}
{{ installingApps ? t('core', 'Installing apps …') : t('core', 'Install recommended apps') }}
</NcButton>
</div>
</div>
Expand All @@ -63,6 +61,7 @@ import { loadState } from '@nextcloud/initial-state'
import pLimit from 'p-limit'
import { translate as t } from '@nextcloud/l10n'

import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'

import logger from '../../logger.js'
Expand Down Expand Up @@ -102,6 +101,7 @@ const recommendedIds = Object.keys(recommended)
export default {
name: 'RecommendedApps',
components: {
NcCheckboxRadioSwitch,
NcButton,
},
data() {
Expand All @@ -118,13 +118,16 @@ export default {
recommendedApps() {
return this.apps.filter(app => recommendedIds.includes(app.id))
},
isAnyAppSelected() {
return this.recommendedApps.some(app => app.isSelected)
},
},
async mounted() {
try {
const { data } = await axios.get(generateUrl('settings/apps/list'))
logger.info(`${data.apps.length} apps fetched`)

this.apps = data.apps.map(app => Object.assign(app, { loading: false, installationError: false }))
this.apps = data.apps.map(app => Object.assign(app, { loading: false, installationError: false, isSelected: app.isCompatible }))
logger.debug(`${this.recommendedApps.length} recommended apps found`, { apps: this.recommendedApps })

this.showInstallButton = true
Expand All @@ -138,23 +141,24 @@ export default {
},
methods: {
installApps() {
this.showInstallButton = false
this.installingApps = true

const limit = pLimit(1)
const installing = this.recommendedApps
.filter(app => !app.active && app.isCompatible && app.canInstall)
.map(app => limit(() => {
.filter(app => !app.active && app.isCompatible && app.canInstall && app.isSelected)
.map(app => limit(async () => {
logger.info(`installing ${app.id}`)
app.loading = true
return axios.post(generateUrl('settings/apps/enable'), { appIds: [app.id], groups: [] })
.catch(error => {
logger.error(`could not install ${app.id}`, { error })
app.isSelected = false
app.installationError = true
})
.then(() => {
logger.info(`installed ${app.id}`)
app.loading = false
app.active = true
})
}))
logger.debug(`installing ${installing.length} recommended apps`)
Expand Down Expand Up @@ -192,6 +196,14 @@ export default {
}
return !!recommended[appId].hidden
},
toggleSelect(appId) {
// disable toggle when installButton is disabled
if (!(appId in recommended) || !this.showInstallButton) {
return
}
const index = this.apps.findIndex(app => app.id === appId)
this.$set(this.apps[index], 'isSelected', !this.apps[index].isSelected)
},
},
}
</script>
Expand Down Expand Up @@ -240,10 +252,11 @@ p {
h3 {
margin-top: 0;
}
}

h3 > span.icon {
display: inline-block;
}
.checkbox-radio-switch {
margin-left: auto;
padding: 0 2px;
}
}
</style>
4 changes: 2 additions & 2 deletions dist/core-common.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-common.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/core-recommendedapps.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions dist/core-recommendedapps.js.license
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ SPDX-FileCopyrightText: Matt Zabriskie
SPDX-FileCopyrightText: Joyent
SPDX-FileCopyrightText: Jordan Harband <ljharb@gmail.com>
SPDX-FileCopyrightText: Jordan Harband
SPDX-FileCopyrightText: John-David Dalton <john.david.dalton@gmail.com> (http://allyoucanleet.com/)
SPDX-FileCopyrightText: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
SPDX-FileCopyrightText: GitHub Inc.
SPDX-FileCopyrightText: Feross Aboukhadijeh
SPDX-FileCopyrightText: Evan You
SPDX-FileCopyrightText: Dr.-Ing. Mario Heiderich, Cure53 <mario@cure53.de> (https://cure53.de/)
SPDX-FileCopyrightText: Christoph Wurst
SPDX-FileCopyrightText: Andris Reinman


This file is generated from multiple sources. Included packages:
Expand Down Expand Up @@ -139,6 +141,12 @@ This file is generated from multiple sources. Included packages:
- is-typed-array
- version: 1.1.13
- license: MIT
- lodash.get
- version: 4.4.2
- license: MIT
- node-gettext
- version: 3.0.0
- license: MIT
- buffer
- version: 6.0.3
- license: MIT
Expand Down
2 changes: 1 addition & 1 deletion dist/core-recommendedapps.js.map

Large diffs are not rendered by default.

Loading