diff --git a/src/views/NewEditProjectView.vue b/src/views/NewEditProjectView.vue index 686232e61..47e71884a 100644 --- a/src/views/NewEditProjectView.vue +++ b/src/views/NewEditProjectView.vue @@ -67,6 +67,48 @@ import { useAppStore } from "@/store/app"; export default class NewEditProjectView extends Vue { projectName = ""; description = ""; + projectId = + localStorage.getItem("projectId") === null + ? "" + : localStorage.getItem("projectId"); + + async created() { + if (this.projectId === "") { + console.log("This is a new project"); + } else { + await db.open(); + const num_accounts = await db.accounts.count(); + if (num_accounts === 0) { + console.log("Problem! Should have a profile!"); + } else { + const accounts = await db.accounts.toArray(); + const identity = JSON.parse(accounts[0].identity); + this.LoadProject(identity); + } + } + } + + async LoadProject(identity: IIdentifier) { + const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; + const url = endorserApiServer + "/api/claim/" + this.projectId; + const token = await accessToken(identity); + const headers = { + "Content-Type": "application/json", + Authorization: "Bearer " + token, + }; + + try { + const resp = await this.axios.get(url, { headers }); + console.log(resp.status, resp.data); + if (resp.status === 200) { + const claim = resp.data.claim; + this.projectName = claim.name; + this.description = claim.description; + } + } catch (error) { + console.log(error); + } + } private async SaveProject(identity: IIdentifier) { const address = identity.did; diff --git a/src/views/ProjectViewView.vue b/src/views/ProjectViewView.vue index 6c3815da5..bb2deb863 100644 --- a/src/views/ProjectViewView.vue +++ b/src/views/ProjectViewView.vue @@ -93,6 +93,13 @@ + @@ -155,6 +162,15 @@ export default class ProjectViewView extends Vue { ? "" : localStorage.getItem("projectId"); + onEditClick() { + localStorage.setItem("projectId", this.projectId as string); + const route = { + name: "new-edit-project", + }; + console.log(route); + this.$router.push(route); + } + expandText() { this.expanded = true; } diff --git a/src/views/ProjectsView.vue b/src/views/ProjectsView.vue index 46aee208a..d2ba3d09a 100644 --- a/src/views/ProjectsView.vue +++ b/src/views/ProjectsView.vue @@ -122,6 +122,7 @@ export default class ProjectsView extends Vue { } onClickNewProject(): void { + localStorage.removeItem("projectId"); const route = { name: "new-edit-project", };