Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { createApp, reactive } from 'https://unpkg.com/petite-vue?module'

import { prettyXML } from './helpers.js';

// Production URL
const examplesBaseUrl = 'https://examples.vcplayground.org/credentials/';
// Development URL
//const examplesBaseUrl = 'http://localhost:8788/credentials/';

// global state
const store = reactive({
credential: {}
Expand All @@ -16,7 +21,7 @@ function SVGViewer({idx}) {
return {
$template: '#svg-viewer',
// local state
currentTab: 'code', // rendered or code
currentTab: 'rendered', // rendered or code
code: '',
// methods
mustache(template, credential) {
Expand Down Expand Up @@ -73,6 +78,12 @@ function SVGViewer({idx}) {
}
}

async function fetchExamples() {
const examples = await fetch(`${examplesBaseUrl}index.json`)
.then((r) => r.json());
return examples;
}

window.app = createApp({
// components
SVGViewer,
Expand All @@ -86,6 +97,7 @@ window.app = createApp({
landscape: "",
landscapeSVG: "",
parseError: "",
examples: await fetchExamples(),

// methods
async pickFile() {
Expand All @@ -110,6 +122,7 @@ window.app = createApp({
.then((r) => r.json())
.then((credential) => {
store.credential = credential;
this.credentialString = JSON.stringify(credential, null, 2);
})
.catch(console.error);
},
Expand All @@ -121,5 +134,8 @@ window.app = createApp({
this.parseError = error.message;
console.error(error);
}
},
loadExampleCredential(event) {
this.loadCredential(`${examplesBaseUrl}${event.target.value}`);
}
}).mount();
}).mount();
18 changes: 17 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,27 @@
</div>
</template>

<!-- main appication -->
<main class="ui basic segment" v-scope>
<div class="ui one column grid">
<div class="column">
<div class="ui form">
<button class="ui button" @click="pickFile()">Choose Credential...</button>
<div class="ui grid">
<div class="two wide column">
<button class="ui button" @click="pickFile()">Choose Credential...</button>
</div>
<div class="fourteen wide column">
<div class="inline field">
<label for="examples">Examples:</label>
<select id="examples" @change="loadExampleCredential">
<option value="" disabled selected>Select an example</option>
<option
v-for="(paths, name) in examples" :value="paths.credential"
v-text="name"></option>
</select>
</div>
</div>
</div>
<span v-text="filename"></span>
<div class="field">
<textarea v-model="credentialString" @input="getCredential" placeholder="Credential"></textarea>
Expand Down