Skip to content

Commit

Permalink
Various improvements to templates
Browse files Browse the repository at this point in the history
  • Loading branch information
CPlusPatch committed Aug 13, 2023
1 parent 997d683 commit 6bd3860
Show file tree
Hide file tree
Showing 23 changed files with 187 additions and 50 deletions.
Binary file added bun.lockb
Binary file not shown.
10 changes: 3 additions & 7 deletions components/BlockRenderer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,16 @@ const createModalOpen = ref(false);
:defaults="
importedMeta.defaults
"
:names="importedMeta.names ?? {}"
@edit-slot="(slots: Block['slots']) => _block.slots = slots" />
</div>
</div>
<div
class="flex flex-shrink-0 justify-end px-4 py-4 gap-3">
<Button
theme="gray"
type="button"
@click="open = false">
Cancel
</Button>
class="flex px-4 py-4 gap-3">
<Button
theme="orange"
type="submit"
class="w-full"
@click="saveAll">
Save
</Button>
Expand Down
81 changes: 76 additions & 5 deletions components/SlotEditorRenderer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const props = defineProps<{
importedMeta: TemplateMetadata["inputs"];
defaults: TemplateMetadata["defaults"];
slots: Block["slots"];
names: TemplateMetadata["names"];
}>();
const emit = defineEmits(["editSlot"]);
Expand Down Expand Up @@ -74,6 +75,17 @@ const clickFileInput = () => {
// I have no idea why it needs the [0]
(fileInput.value as any)[0].click();
};
const getDisplayName = (name: string) => {
return props.names[name] ?? name;
}
const decomposeLink = (value?: string) => {
if (!value) return ["", ""];
// If there is more than 1 pipe, it's not a valid link
if (value.split("|").length > 2) return ["", ""];
return value.split("|");
}
</script>

<template>
Expand All @@ -82,7 +94,7 @@ const clickFileInput = () => {
<label
for="project-name"
class="block text-sm font-medium text-gray-900">
{{ name }}
{{ getDisplayName(name) }}
</label>
<div class="mt-1">
<InputCMInput
Expand All @@ -100,12 +112,70 @@ const clickFileInput = () => {
</div>
</template>

<template v-if="inputType === InputType.Url">
<label
for="project-name"
class="block text-sm font-medium text-gray-900">
{{ getDisplayName(name) }}
</label>
<div class="mt-1">
<InputCMInput
id="project-name"
:value="slots[name]"
type="text"
icon="tabler:link"
placeholder="URL address"
name="project-name"
class="!ring-orange-500 focus:!border-orange-500"
@input="
emit('editSlot', {
...slots,
[name]: ($event as any).target.value,
})
" />
</div>
</template>

<template v-if="inputType === InputType.Link">
<label
for="project-name"
class="block text-sm font-medium text-gray-900">
{{ getDisplayName(name) }}
</label>
<div class="mt-1">
<InputCMInput
id="project-name"
:value="decomposeLink(slots[name])[0]"
type="text"
name="project-name"
placeholder="Link text"
icon="tabler:cursor-text"
@input="emit('editSlot', {
...slots,
[name]: ($event as any).target.value.replace('|', '') + '|' + decomposeLink(slots[name])[1],
})"
class="!ring-orange-500 focus:!border-orange-500"/>
<InputCMInput
id="project-name"
:value="decomposeLink(slots[name])[1]"
type="text"
name="project-name"
icon="tabler:link"
placeholder="Link URL"
class="!ring-orange-500 focus:!border-orange-500 mt-1"
@input="emit('editSlot', {
...slots,
[name]: decomposeLink(slots[name])[0] + '|' + ($event as any).target.value.replace('|', ''),
})" />
</div>
</template>


<template v-if="inputType === InputType.Image">
<label
for="project-name"
class="block text-sm font-medium text-gray-900">
{{ name }}
{{ getDisplayName(name) }}
</label>
<div
class="mt-1 ring-1 ring-gray-200 flex items-center justify-center gap-x-3 relative h-15 w-15 rounded overflow-hidden group">
Expand Down Expand Up @@ -148,7 +218,7 @@ const clickFileInput = () => {
<label
for="project-name"
class="block text-sm font-medium text-gray-900">
{{ name }}
{{ getDisplayName(name) }}
</label>
<div class="mt-1">
<textarea
Expand All @@ -171,7 +241,7 @@ const clickFileInput = () => {
<label
for="project-name"
class="block text-sm font-medium text-gray-900">
{{ name }}
{{ getDisplayName(name) }}
</label>
<div class="mt-1">
<input
Expand All @@ -195,7 +265,7 @@ const clickFileInput = () => {
@click="expanded = !expanded"
for="project-name"
class="block text-sm font-medium text-gray-900">
{{ name }}
{{ getDisplayName(name) }}
<Icon
:name="
expanded
Expand All @@ -214,6 +284,7 @@ const clickFileInput = () => {
class="mt-2 flex flex-col gap-1">
<SlotEditorRenderer
:slots="element"
:names="names"
:imported-meta="importedMeta[name][0]"
:defaults="defaults[name][0]"
@edit-slot="(newSlots: Block['slots']) => emit('editSlot', {
Expand Down
3 changes: 1 addition & 2 deletions pages/account/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ const save = (e: Event) => {
});
};
const oidc = (useFetch<Config["oidc_providers"]>("/api/internal/oidc-config")).data;
const oidc = (await useFetch("/api/config/oidc")).data;
const linkOIDC = async (oidcProvider: Config["oidc_providers"][0]) => {
const userManager = new UserManager({
authority: oidcProvider.authority,
client_id: oidcProvider.client_id,
redirect_uri: `${useRequestURL().origin}/auth/callback`,
response_type: "code",
scope: oidcProvider.scopes.join(" "),
});
Expand Down
7 changes: 1 addition & 6 deletions pages/auth/callback/[provider].vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@ import { UserManager } from 'oidc-client-ts';
import { Config } from '~/types/config';
const oidc = (await useFetch<Config["oidc_providers"]>("/api/internal/oidc-config")).data;
const oidc = (await useFetch("/api/config/oidc")).data;
onMounted(() => {
const oidcProvider = oidc.value?.find(o => o.id === useRoute().params.provider);
console.log(useRoute().params.provider);
console.log(oidc);
console.log(oidcProvider);
if (!oidcProvider) return false;
const userManager = new UserManager({
authority: oidcProvider.authority,
client_id: oidcProvider.client_id,
redirect_uri: `${useRequestURL().origin}/auth/callback`,
response_type: "code",
scope: oidcProvider.scopes.join(" "),
});
Expand Down
4 changes: 1 addition & 3 deletions pages/auth/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,14 @@ onMounted(async () => {
loading.value = false;
});
const oidc = (useFetch<Config["oidc_providers"]>("/api/internal/oidc-config")).data;
const oidc = (await useFetch("/api/config/oidc")).data;
const oidcSignIn = async (oidcProvider: Config["oidc_providers"][0]) => {
loading.value = true;
const userManager = new UserManager({
authority: oidcProvider.authority,
client_id: oidcProvider.client_id,
redirect_uri: `${useRequestURL().origin}/auth/callback/${oidcProvider.id}/`,
response_type: "code",
scope: oidcProvider.scopes.join(" "),
});
Expand Down
2 changes: 0 additions & 2 deletions server/api/auth/login-openid.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export default defineEventHandler(async event => {
provider: string;
}>(event);

console.log(oidc);

const provider = oidc.find(o => o.id === body.provider);
if (!provider) throw createError("Invalid OIDC provider!");

Expand Down
File renamed without changes.
10 changes: 9 additions & 1 deletion templates/carousels/GradientCarousel.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"category": "carousels",
"name": "GradientCarousel",
"displayName": "Card Grid",
"description": "Grid of cards with an avatars",
"description": "Grid of cards with an avatar",
"inputs": {
"list": [
{
Expand Down Expand Up @@ -31,5 +31,13 @@
"text": ""
}
]
},
"names": {
"list": "Cards",
"id": "ID",
"name": "Header",
"profession": "Subtext",
"avatar": "Avatar",
"text": "Text"
}
}
7 changes: 7 additions & 0 deletions templates/dropdowns/DropdownList.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,12 @@
"answer": ""
}
]
},
"names": {
"text-header": "Header",
"list": "List",
"id": "ID",
"question": "Dropdown Title",
"answer": "Dropdown Content"
}
}
20 changes: 13 additions & 7 deletions templates/featuresets/ImagesWithText.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
"id": "string",
"title": "string",
"desc": "paragraph",
"image": "string",
"linkHref": "string",
"linkText": "string"
"image": "image",
"link": "link"
}
]
},
Expand All @@ -24,17 +23,24 @@
"title": "",
"desc": "string",
"image": "",
"linkHref": "",
"linkText": ""
"link": ""
},
{
"id": "#ID#",
"title": "",
"desc": "string",
"image": "",
"linkHref": "",
"linkText": ""
"link": ""
}
]
},
"names": {
"text-header": "Text Header",
"list": "List",
"id": "ID",
"title": "Title",
"desc": "Description",
"image": "Image",
"link": "Link"
}
}
9 changes: 4 additions & 5 deletions templates/featuresets/ImagesWithText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ defineProps<{
title: string;
desc: string;
image: string;
linkText: string;
linkHref: string;
link: string;
}[];
}>();
</script>
Expand Down Expand Up @@ -44,13 +43,13 @@ defineProps<{
</p>

<a
v-if="element.linkText"
v-if="element.link"
class="text-lg text-blue-600 font-inter"
:href="element.linkHref"
:href="element.link.split('|')[1]"
target="_blank"
data-placeholder="Link text"
rel="noreferrer">
{{ element.linkText }}
{{ element.link.split("|")[0] }}
<Icon
name="tabler:external-link"
class="inline mb-1 w-5 h-5" />
Expand Down
14 changes: 12 additions & 2 deletions templates/grids/CardGridWithTags.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"description": "paragraph",
"name": "string",
"href": "string"
"href": "url"
}
]
},
Expand All @@ -37,8 +37,18 @@
],
"description": "",
"name": "",
"href": "#"
"href": ""
}
]
},
"names": {
"text-header": "Header",
"grid": "Grid",
"tags": "Tags",
"name": "Name",
"href": "Link",
"description": "Description",
"color": "Color",
"text-color": "Text Color"
}
}
Loading

0 comments on commit 6bd3860

Please sign in to comment.