diff --git a/src/components/fragments/PackageConstraint.vue b/src/components/fragments/PackageConstraint.vue index a727bb78..11dcd6f3 100644 --- a/src/components/fragments/PackageConstraint.vue +++ b/src/components/fragments/PackageConstraint.vue @@ -95,7 +95,7 @@ ) ) { this.$store.commit('packages/restore', this.data.name); - this.$store.commit('packages/uploads/unconfirm', this.data.name); + this.$store.dispatch('packages/uploads/unconfirm', this.data.name); this.resetConstraint(); return; } diff --git a/src/components/routes/PackageListRoute.vue b/src/components/routes/PackageListRoute.vue index b01b0fc4..0f43e8ce 100644 --- a/src/components/routes/PackageListRoute.vue +++ b/src/components/routes/PackageListRoute.vue @@ -118,7 +118,7 @@ }, confirmUploads() { - this.$store.commit('packages/uploads/confirmAll'); + this.$store.dispatch('packages/uploads/confirmAll'); }, async removeUploads() { @@ -145,7 +145,7 @@ resetChanges() { this.$store.commit('packages/reset'); - this.$store.commit('packages/uploads/unconfirmAll'); + this.$store.dispatch('packages/uploads/unconfirmAll'); }, }, diff --git a/src/components/routes/Packages/ComposerPackage.vue b/src/components/routes/Packages/ComposerPackage.vue index 05d06637..33d47ebc 100644 --- a/src/components/routes/Packages/ComposerPackage.vue +++ b/src/components/routes/Packages/ComposerPackage.vue @@ -198,7 +198,7 @@ methods: { restore() { this.$store.commit('packages/restore', this.data.name); - this.$store.commit('packages/uploads/unconfirm', this.data.name); + this.$store.dispatch('packages/uploads/unconfirm', this.data.name); }, datimFormat: (value) => datimFormat(value), diff --git a/src/components/routes/Packages/UploadedPackage.vue b/src/components/routes/Packages/UploadedPackage.vue index 8c219cfc..4846b578 100644 --- a/src/components/routes/Packages/UploadedPackage.vue +++ b/src/components/routes/Packages/UploadedPackage.vue @@ -126,7 +126,7 @@ methods: { addPackage() { - this.$store.commit('packages/uploads/confirm', this.upload.id); + this.$store.dispatch('packages/uploads/confirm', this.upload.id); }, removeUpload() { diff --git a/src/mixins/packageStatus.js b/src/mixins/packageStatus.js index 276c1bce..13bda13e 100644 --- a/src/mixins/packageStatus.js +++ b/src/mixins/packageStatus.js @@ -85,7 +85,7 @@ export default { this.$store.commit('packages/restore', this.data.name); } else { this.$store.commit('packages/restore', this.data.name); - this.$store.commit('packages/uploads/unconfirm', this.data.name); + this.$store.dispatch('packages/uploads/unconfirm', this.data.name); this.$store.commit('packages/remove', this.data.name); } }, diff --git a/src/store/packages/uploads.js b/src/store/packages/uploads.js index bd6a6818..b9d0d163 100644 --- a/src/store/packages/uploads.js +++ b/src/store/packages/uploads.js @@ -54,52 +54,12 @@ export default { state.files = value; }, - confirm(state, id) { - const pkg = state.uploads[id].package; - - if (!pkg) { - return; - } - - if (this.getters['packages/packageInstalled'](pkg.name)) { - this.commit('packages/change', pkg); - } else { - this.commit('packages/add', Object.assign({}, pkg, { constraint: pkg.version })); - } - - if (pkg.suggest) { - Object.keys(pkg.suggest).forEach((name) => { - if (!this.getters['packages/packageInstalled'](pkg.name)) { - this.commit('packages/add', { name }); - } - }); - } - + setConfirmed(state, id) { state.confirmed.push(id); }, - unconfirm(state, idOrName) { - if (state.confirmed.includes[idOrName]) { - Vue.delete(state.confirmed, state.confirmed.indexOf(idOrName)); - return; - } - - Object.keys(state.uploads).forEach((id) => { - if (state.uploads[id].package - && state.uploads[id].package.name === idOrName - && state.confirmed.includes(id) - ) { - Vue.delete(state.confirmed, state.confirmed.indexOf(id)); - } - }); - }, - - confirmAll(state) { - Object.keys(state.uploads).forEach(id => this.commit('packages/uploads/confirm', id)); - }, - - unconfirmAll(state) { - state.confirmed = []; + setUnconfirmed(state, id) { + Vue.delete(state.confirmed, state.confirmed.indexOf(id)); }, setRemoving(state, id) { @@ -124,12 +84,74 @@ export default { } }, + async confirm({ state, commit }, id) { + const pkg = state.uploads[id].package; + + if (!pkg) { + return; + } + + if (this.getters['packages/packageInstalled'](pkg.name)) { + this.commit('packages/change', pkg); + } else { + this.commit('packages/add', Object.assign({}, pkg, { constraint: pkg.version })); + } + + if (pkg.suggest) { + await Promise.all(Object.keys(pkg.suggest).map( + async (name) => { + if (!this.getters['packages/packageInstalled'](name)) { + const metadata = await this.dispatch('packages/metadata', { name }); + + if (!metadata.contaoConstraint || this.getters['packages/contaoSupported'](metadata.contaoConstraint)) { + this.commit('packages/add', { name }); + } + } + } + )); + } + + commit('setConfirmed', id); + }, + + confirmAll({ state, dispatch }) { + Object.keys(state.uploads).forEach(id => dispatch('confirm', id)); + }, + + unconfirm({ state, commit }, idOrName) { + const id = state.confirmed.includes(idOrName) + ? idOrName + : Object.keys(state.uploads).find( + (id) => state.uploads[id].package && state.uploads[id].package.name === idOrName && state.confirmed.includes(id) + ); + + if (!id) { + return; + } + + commit('setUnconfirmed', id); + + const pkg = state.uploads[id].package; + + if (pkg && pkg.suggest) { + Object.keys(pkg.suggest).forEach((name) => { + if (this.getters['packages/packageAdded'](name)) { + this.commit('packages/restore', name); + } + }); + } + }, + + unconfirmAll({ state, dispatch }) { + Object.keys(state.uploads).forEach(id => dispatch('unconfirm', id)); + }, + async remove({ commit, dispatch }, id) { commit('setRemoving', id); await Vue.http.delete(`api/packages/uploads/${id}`); await dispatch('load'); commit('setRemoved', id); - commit('unconfirm', id); + await dispatch('unconfirm', id); }, async removeAll({ state, commit, dispatch }) {