Skip to content

Commit

Permalink
feat(core): add selection for recommended apps
Browse files Browse the repository at this point in the history
Signed-off-by: Sanskar Soni <sanskarsoni300@gmail.com>
  • Loading branch information
sanskar-soni-9 committed Jun 20, 2024
1 parent c925290 commit e7b0d1a
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 24 deletions.
49 changes: 31 additions & 18 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 @@ -111,20 +111,23 @@ export default {
loadingApps: true,
loadingAppsError: false,
apps: [],
defaultPageUrl: loadState('core', 'defaultPageUrl')
defaultPageUrl: loadState('core', 'defaultPageUrl'),
}
},
computed: {
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 @@ -148,6 +150,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
- object-is
- version: 1.1.5
- license: MIT
Expand Down
2 changes: 1 addition & 1 deletion dist/core-recommendedapps.js.map

Large diffs are not rendered by default.

0 comments on commit e7b0d1a

Please sign in to comment.