-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8382ffa
commit 604aa3c
Showing
11 changed files
with
233 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<script lang="ts" setup> | ||
import { ref } from 'vue'; | ||
import { RouterLink } from 'vue-router'; | ||
const formFixtureGlobImports = import.meta.glob<true, 'raw', string>('../../../ui-solid/fixtures/xforms/**/*.xml', { | ||
query: '?raw' | ||
}); | ||
type CategoryType = Record<string, string[]>; | ||
const categories = Object.keys(formFixtureGlobImports) | ||
.map(f => f.replace('../../../ui-solid/fixtures/xforms/', '').replace('.xml', '')) | ||
.reduce((result: CategoryType, f:string) => { | ||
const parts = f.split('/'); | ||
const category = parts.length == 2 ? parts[0] : 'Other'; | ||
if(!result[category]){ | ||
result[category] = []; | ||
} | ||
result[category].push(parts.length == 2 ? parts[1]: parts[0]) | ||
return result; | ||
}, {}); | ||
const expandedCategories = ref(new Set()); | ||
const toggleCategory = (category:string) => { | ||
if(expandedCategories.value.has(category)) { | ||
expandedCategories.value.delete(category); | ||
} | ||
else { | ||
expandedCategories.value.add(category); | ||
} | ||
} | ||
</script> | ||
|
||
<template> | ||
<div class="component-root"> | ||
<h1>Demo Forms</h1> | ||
<ul class="category-list"> | ||
<li | ||
v-for="(category,categoryName) in categories" | ||
:key="categoryName" | ||
:class="{ 'expanded': expandedCategories.has(categoryName) }" | ||
@click="toggleCategory(categoryName)" | ||
> | ||
{{ categoryName }} | ||
<ul class="form-list"> | ||
<li v-for="form in category" :key="form"> | ||
<RouterLink :to="`/form/${categoryName}/${form}`"> | ||
{{ form }} | ||
</RouterLink> | ||
</li> | ||
</ul> | ||
</li> | ||
</ul> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.component-root { | ||
background: white; | ||
height: 100vh; | ||
margin-top: -25px; | ||
} | ||
h1 { | ||
margin-left: 10px; | ||
padding-top: 20px; | ||
} | ||
.category-list { | ||
padding: 0; | ||
> li { | ||
list-style: none; | ||
cursor: pointer; | ||
margin: 10px; | ||
text-transform: capitalize; | ||
font-size: 20px; | ||
padding: 10px; | ||
&:hover { | ||
background-color: var(--gray-100); | ||
} | ||
&::before { | ||
content: '▶︎'; | ||
margin-right: 10px; | ||
} | ||
ul.form-list { | ||
display: none; | ||
padding: 0 0 0 20px; | ||
li { | ||
list-style: none; | ||
margin: 10px; | ||
border: 1px solid var(--primary-500); | ||
border-radius: 10px; | ||
cursor: pointer; | ||
background-color: var(--surface-0); | ||
font-size: 16px; | ||
a { | ||
display: block; | ||
padding: 10px; | ||
text-decoration: none; | ||
color: var(--gray-900); | ||
&:visited { | ||
color: var(--gray-900) | ||
} | ||
} | ||
} | ||
li:hover { | ||
background-color: var(--primary-50); | ||
} | ||
} | ||
&.expanded { | ||
&::before { | ||
content: '▼'; | ||
} | ||
ul.form-list { | ||
display: block; | ||
} | ||
} | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<script setup lang="ts"> | ||
import { ref } from 'vue'; | ||
import { useRoute } from 'vue-router'; | ||
import OdkWebForm from '../components/OdkWebForm.vue'; | ||
const route = useRoute() | ||
const formFixtureGlobImports = import.meta.glob<false, 'raw', string>('../../../ui-solid/fixtures/xforms/**/*.xml', { | ||
query: '?raw', | ||
import: 'default', | ||
eager: false, | ||
}); | ||
const categoryParam = route.params.category as string; | ||
const formParam = route.params.form as string; | ||
const formPath = '../../../ui-solid/fixtures/xforms/' + (route.params.category != 'Other' ? `${categoryParam}/${formParam}` : formParam) + '.xml'; | ||
const form = ref(); | ||
formFixtureGlobImports[formPath]() | ||
.then((xml:string) => { | ||
form.value = xml; | ||
}) | ||
.catch(() => { | ||
alert('Failed to load the Form XML'); | ||
}); | ||
const handleSubmit = () => { | ||
alert(`Submit button was pressed`); | ||
} | ||
</script> | ||
|
||
<template> | ||
<OdkWebForm v-if="form" :form-xml="form" @submit="handleSubmit" /> | ||
<div v-else> | ||
Loading... | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<template> | ||
<RouterView /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { Component } from 'vue'; | ||
import { createRouter, createWebHashHistory } from 'vue-router'; | ||
import FormList from './FormList.vue'; | ||
import FormPreview from './FormPreview.vue'; | ||
|
||
const routes = [ | ||
{ path: '/', component: FormList as Component }, | ||
{ path: '/form/:category/:form', component: FormPreview as Component }, | ||
]; | ||
|
||
const router = createRouter({ | ||
history: createWebHashHistory(), | ||
routes, | ||
}); | ||
|
||
export default router; |
Oops, something went wrong.