From c1fe8216f689a754185d6c8e77137368cf1a1b50 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Fri, 26 Apr 2024 15:44:09 -0600 Subject: [PATCH] allow loading more gives & offers & plans when limits are hit on project view --- src/views/ContactsView.vue | 7 +- src/views/ProjectViewView.vue | 150 ++++++++++++++++++++++++++-------- 2 files changed, 120 insertions(+), 37 deletions(-) diff --git a/src/views/ContactsView.vue b/src/views/ContactsView.vue index 26c8fa7..6b6d54c 100644 --- a/src/views/ContactsView.vue +++ b/src/views/ContactsView.vue @@ -68,11 +68,12 @@ > {{ showGiveTotals - ? "Showing Totals" + ? "Totals" : showGiveConfirmed - ? "Showing Confirmed Amounts" - : "Showing Unconfirmed Amounts" + ? "Confirmed Amounts" + : "Unconfirmed Amounts" }} + diff --git a/src/views/ProjectViewView.vue b/src/views/ProjectViewView.vue index ef0fb0b..d4597ec 100644 --- a/src/views/ProjectViewView.vue +++ b/src/views/ProjectViewView.vue @@ -243,6 +243,9 @@ +
+ +
@@ -290,12 +293,18 @@ - +
+
+ +
@@ -316,6 +325,7 @@ {{ plan.name }}
+
Load More
@@ -388,12 +398,15 @@ export default class ProjectViewView extends Vue { expanded = false; fulfilledByThis: PlanSummaryRecord | null = null; fulfillersToThis: Array = []; + fulfillersToHitLimit = false; givesToThis: Array = []; + givesHitLimit = false; issuer = ""; latitude = 0; longitude = 0; name = ""; offersToThis: Array = []; + offersHitLimit = false; projectId = localStorage.getItem("projectId") || ""; // handle ID showDidCopy = false; startTime = ""; @@ -523,21 +536,32 @@ export default class ProjectViewView extends Vue { } } - const givesInUrl = + this.loadGives(); + + this.loadOffers(); + + this.loadFulfillersTo(); + + // now load fulfilled-by, a single project + if (identity) { + const token = await accessToken(identity); + headers["Authorization"] = "Bearer " + token; + } + const fulfilledByUrl = this.apiServer + - "/api/v2/report/givesToPlans?planIds=" + - encodeURIComponent(JSON.stringify([projectId])); + "/api/v2/report/planFulfilledByPlan?planHandleId=" + + encodeURIComponent(projectId); try { - const resp = await this.axios.get(givesInUrl, { headers }); - if (resp.status === 200 && resp.data.data) { - this.givesToThis = resp.data.data; + const resp = await this.axios.get(fulfilledByUrl, { headers }); + if (resp.status === 200) { + this.fulfilledByThis = resp.data.data; } else { this.$notify( { group: "alert", type: "danger", title: "Error", - text: "Failed to retrieve gives to this project.", + text: "Failed to retrieve plans fulfilled by this project.", }, -1, ); @@ -549,31 +573,50 @@ export default class ProjectViewView extends Vue { group: "alert", type: "danger", title: "Error", - text: "Something went wrong retrieving gives to this project.", + text: "Something went wrong retrieving plans fulfilled by this project.", }, -1, ); console.error( - "Error retrieving gives to this project:", + "Error retrieving plans fulfilled by this project:", serverError.message, ); } + } - const offersToUrl = + async loadGives() { + const givesUrl = this.apiServer + - "/api/v2/report/offersToPlans?planIds=" + - encodeURIComponent(JSON.stringify([projectId])); + "/api/v2/report/givesToPlans?planIds=" + + encodeURIComponent(JSON.stringify([this.projectId])); + let postfix = ""; + if (this.givesToThis.length > 0) { + postfix = + "&beforeId=" + this.givesToThis[this.givesToThis.length - 1].jwtId; + } + const givesInUrl = givesUrl + postfix; + + const headers: RawAxiosRequestHeaders = { + "Content-Type": "application/json", + }; + const identity = await this.getIdentity(this.activeDid); + if (identity) { + const token = await accessToken(identity); + headers["Authorization"] = "Bearer " + token; + } + try { - const resp = await this.axios.get(offersToUrl, { headers }); + const resp = await this.axios.get(givesInUrl, { headers }); if (resp.status === 200 && resp.data.data) { - this.offersToThis = resp.data.data; + this.givesToThis = this.givesToThis.concat(resp.data.data); + this.givesHitLimit = resp.data.hitLimit; } else { this.$notify( { group: "alert", type: "danger", title: "Error", - text: "Failed to retrieve offers to this project.", + text: "Failed to retrieve more gives to this project.", }, -1, ); @@ -585,31 +628,50 @@ export default class ProjectViewView extends Vue { group: "alert", type: "danger", title: "Error", - text: "Something went wrong retrieving offers to this project.", + text: "Something went wrong retrieving more gives to this project.", }, -1, ); console.error( - "Error retrieving offers to this project:", + "Something went wrong retrieving more gives to this project:", serverError.message, ); } + } - const fulfilledByUrl = + async loadOffers() { + const offersUrl = this.apiServer + - "/api/v2/report/planFulfilledByPlan?planHandleId=" + - encodeURIComponent(projectId); + "/api/v2/report/offersToPlans?planIds=" + + encodeURIComponent(JSON.stringify([this.projectId])); + let postfix = ""; + if (this.offersToThis.length > 0) { + postfix = + "&beforeId=" + this.offersToThis[this.offersToThis.length - 1].jwtId; + } + const offersInUrl = offersUrl + postfix; + + const headers: RawAxiosRequestHeaders = { + "Content-Type": "application/json", + }; + const identity = await this.getIdentity(this.activeDid); + if (identity) { + const token = await accessToken(identity); + headers["Authorization"] = "Bearer " + token; + } + try { - const resp = await this.axios.get(fulfilledByUrl, { headers }); - if (resp.status === 200) { - this.fulfilledByThis = resp.data.data; + const resp = await this.axios.get(offersInUrl, { headers }); + if (resp.status === 200 && resp.data.data) { + this.offersToThis = this.offersToThis.concat(resp.data.data); + this.offersHitLimit = resp.data.hitLimit; } else { this.$notify( { group: "alert", type: "danger", title: "Error", - text: "Failed to retrieve plans fulfilled by this project.", + text: "Failed to retrieve more offers to this project.", }, -1, ); @@ -621,31 +683,51 @@ export default class ProjectViewView extends Vue { group: "alert", type: "danger", title: "Error", - text: "Something went wrong retrieving plans fulfilled by this project.", + text: "Something went wrong retrieving more offers to this project.", }, -1, ); console.error( - "Error retrieving plans fulfilled by this project:", + "Something went wrong retrieving more offers to this project:", serverError.message, ); } + } - const fulfillersToUrl = + async loadFulfillersTo() { + const fulfillsUrl = this.apiServer + "/api/v2/report/planFulfillersToPlan?planHandleId=" + - encodeURIComponent(projectId); + encodeURIComponent(this.projectId); + let postfix = ""; + if (this.fulfillersToThis.length > 0) { + postfix = + "&beforeId=" + + this.fulfillersToThis[this.fulfillersToThis.length - 1].jwtId; + } + const fulfillsInUrl = fulfillsUrl + postfix; + + const headers: RawAxiosRequestHeaders = { + "Content-Type": "application/json", + }; + const identity = await this.getIdentity(this.activeDid); + if (identity) { + const token = await accessToken(identity); + headers["Authorization"] = "Bearer " + token; + } + try { - const resp = await this.axios.get(fulfillersToUrl, { headers }); + const resp = await this.axios.get(fulfillsInUrl, { headers }); if (resp.status === 200) { - this.fulfillersToThis = resp.data.data; + this.fulfillersToThis = this.fulfillersToThis.concat(resp.data.data); + this.fulfillersToHitLimit = resp.data.hitLimit; } else { this.$notify( { group: "alert", type: "danger", title: "Error", - text: "Failed to retrieve plan fulfillers to this project.", + text: "Failed to retrieve more plans that fullfill this project.", }, -1, ); @@ -657,12 +739,12 @@ export default class ProjectViewView extends Vue { group: "alert", type: "danger", title: "Error", - text: "Something went wrong retrieving plan fulfillers to this project.", + text: "Something went wrong retrieving more plans that fulfull this project.", }, -1, ); console.error( - "Error retrieving plan fulfillers to this project:", + "Something went wrong retrieving more plans that fulfill this project:", serverError.message, ); }