Skip to content

Commit

Permalink
Check Contao compatibility of suggestions and remove suggestions if u…
Browse files Browse the repository at this point in the history
…ploaded package is unconfirmed
  • Loading branch information
aschempp committed Aug 22, 2024
1 parent d5165e4 commit 65e416d
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/components/fragments/PackageConstraint.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/routes/PackageListRoute.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
},
confirmUploads() {
this.$store.commit('packages/uploads/confirmAll');
this.$store.dispatch('packages/uploads/confirmAll');
},
async removeUploads() {
Expand All @@ -145,7 +145,7 @@
resetChanges() {
this.$store.commit('packages/reset');
this.$store.commit('packages/uploads/unconfirmAll');
this.$store.dispatch('packages/uploads/unconfirmAll');
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/routes/Packages/ComposerPackage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/components/routes/Packages/UploadedPackage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/mixins/packageStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},
Expand Down
110 changes: 66 additions & 44 deletions src/store/packages/uploads.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 }) {
Expand Down

0 comments on commit 65e416d

Please # to comment.