From acdf4d154fd99d389e5b0b72db7d4cf28e3dab5e Mon Sep 17 00:00:00 2001 From: Kar Date: Sat, 5 Nov 2022 19:22:16 +0530 Subject: [PATCH] notice with attachments download --- index.html | 2 +- src/pages/notice/[id].vue | 74 ++++++++++++++++++++++----------------- 2 files changed, 42 insertions(+), 34 deletions(-) diff --git a/index.html b/index.html index 364212b..9457766 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - Vite, Vue3, Tailwind CSS + Sreechaitanya College, Habra @@ -38,33 +36,43 @@ export default { }, mounted: function () { fetch('https://api8.siliconpin.com/items/scc22?filter[slug][_eq]=' + this.$route.params.id) - .then(response => response.json()) - .then(data => { - this.page = data.data - this.isLoading = false - - fetch('https://api8.siliconpin.com/items/scc22_files_1?filter[scc22_id][_in]=' + this.page[0].id) - .then(resp => resp.json()) - .then(file => { - this.files = file.data - // this.files = file.data - this.fileAttached=true - // attach.data.forEach(fileID=> this.files.push(fileID.directus_files_id)) - // console.log(file.data) - // this.attachments.push(attach.data[0].directus_files_id) - }) - let attIDs = '' - let t = 0 - this.files.forEach(ids => { - if (t == 0) attIDs = ids - else attIDs = attIDs + ',' + ids - t++ - console.log(attIDs) - }); - if(this.fileAttached){} - // console.log(Object.assign({}, this.files)) - // console.log(this.files) + .then((response) => { + if (response.ok) { + return response.json(); + } + throw new Error('Something went wrong'); }) + .then(jsonPageData => { + this.page = jsonPageData.data + this.isLoading = false + return jsonPageData.data[0].id + } + ) + .then((pageID) => { + fetch('https://api8.siliconpin.com/items/scc22_files_1?filter[scc22_id][_in]=' + pageID) + .then(resp => resp.json()) + .then(file => { + let attIDs = '' + let t = 0 + file.data.forEach(ids => { + if (t == 0) attIDs = ids.directus_files_id + else attIDs = attIDs + ',' + ids.directus_files_id + t++ + }); + if(t>0) this.fileAttached=true + return attIDs + }) + .then((attIDs) => { + fetch('https://api8.siliconpin.com/files?filter[id][_in]=' + attIDs) + .then(resp => resp.json()) + .then(file => { + this.files = file.data + }) + }) + }) + .catch((error) => { + console.log(error) + }); }, methods: { // getAttachments(att) {