timesafari
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
3.9 KiB

<template>
<!-- CONTENT -->
<section id="Content" class="p-6 pb-24">
<!-- Breadcrumb -->
<div id="ViewBreadcrumb" class="mb-8">
<h1 class="text-lg text-center font-light relative px-7">
2 years ago
<!-- Cancel -->
<router-link
:to="{ name: 'project' }"
class="text-lg text-center px-2 py-1 absolute -left-2 -top-1"
><fa icon="chevron-left" class="fa-fw"></fa
></router-link>
2 years ago
[New/Edit] Project
</h1>
</div>
<!-- Project Details -->
<!-- Image - (see design model) Empty -->
2 years ago
<!-- Image - Populated -->
<div class="relative mb-4 rounded-md overflow-hidden">
<div class="absolute top-3 right-3 flex gap-2">
<button
class="text-md font-bold uppercase bg-blue-600 text-white px-3 py-2 rounded"
>
<fa icon="pen" class="fa-fw"></fa>
</button>
2 years ago
<button
class="text-md font-bold uppercase bg-red-600 text-white px-3 py-2 rounded"
2 years ago
>
<fa icon="trash-can" class="fa-fw"></fa>
2 years ago
</button>
</div>
<img src="https://picsum.photos/800/400" class="w-full" />
</div>
<input
type="text"
placeholder="Project Name"
class="block w-full rounded border border-slate-400 mb-4 px-3 py-2"
v-modal="projectName"
/>
<textarea
placeholder="Description"
class="block w-full rounded border border-slate-400 mb-4 px-3 py-2"
rows="5"
v-model="description"
></textarea>
<div class="text-xs text-slate-500 italic -mt-3 mb-4">
88/500 max. characters
</div>
<div class="mt-8">
<button
class="block w-full text-center text-lg font-bold uppercase bg-blue-600 text-white px-2 py-3 rounded-md mb-2"
@click="onSaveProjectClick()"
>
Save Project
</button>
<button
type="button"
class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md"
@click="onCancelClick()"
>
Cancel
</button>
</div>
</section>
</template>
<script lang="ts">
import { Options, Vue } from "vue-class-component";
2 years ago
import { AppString } from "@/constants/app";
import { db } from "../db";
2 years ago
import { accessToken, sign } from "@/libs/crypto";
import * as didJwt from 'did-jwt'
@Options({
2 years ago
components: {},
})
export default class NewEditProjectView extends Vue {
projectName = "";
description = "";
2 years ago
public async onSaveProjectClick() {
2 years ago
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);
const address = identity.did;
const vcClaim = {
"@context": "https://schema.org",
2 years ago
"@type": "PlanAction",
2 years ago
identifier: address,
name: this.projectName,
description: this.description,
};
2 years ago
const vcPayload = {
sub: "PlanAction",
vc: {
'@context': ['https://www.w3.org/2018/credentials/v1'],
type: ['VerifiableCredential'],
credentialSubject: vcClaim,
}
};
const signer = await sign(identity.keys[0].privateKeyHex);
const alg = undefined;
const vcJwt: string = await didJwt.createJWT(vcClaim,{ alg, issuer: identity, signer });
const payload = JSON.stringify({ jwtEncoded: vcJwt});
2 years ago
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER;
const url = endorserApiServer + "/api/claim";
2 years ago
const token = await accessToken(identity);
2 years ago
const headers = {
'Content-Type': 'application/json',
2 years ago
'Authorization': "Bearer " + token
};
2 years ago
try {
let resp = await this.axios.post(url, payload, { headers });
} catch (error) {
console.log(error);
}
}
}
2 years ago
public onCancelClick() {
this.$router.back();
}
}
</script>