-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
185: Initial setup for generic data model editor (#186)
Enabled ModelEditor for Course for the time being
- Loading branch information
1 parent
5023935
commit 0789936
Showing
13 changed files
with
133 additions
and
147 deletions.
There are no files selected for viewing
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
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,61 @@ | ||
<template> | ||
<div v-if="AuthService.isAdmin(auth0)" | ||
class="bg-mysticStone text-white border-slate-400 border-2 rounded p-1 pl-2 my-2"> | ||
<div class="text-2xl">Model Editor</div> | ||
<input type="checkbox" id="edit-mode" name="editMode" v-model="state.isEditMode"> | ||
<label for="edit-mode"> {{ handlerText }} mode?</label> | ||
<span class="inline-block" :class="{ invisible: !state.isEditMode }"> | ||
<Button :handler="() => handler(state.viewModel)" :text="handlerText"></Button> | ||
</span> | ||
<div :class="{ invisible: !state.isEditMode }"> | ||
<input type="checkbox" id="show-preview" name="showPreview" | ||
v-model="state.showPreview"> | ||
<label for="show-preview"> Show preview?</label> | ||
</div> | ||
<div v-if="AuthService.isAdmin(auth0) && state.isEditMode"> | ||
<div v-for="viewKey in modelService.objectViewKeys"> | ||
<div class="capitalize text-white border-white border-2 rounded p-1 pl-2 my-2 mr-12">{{ viewKey.key }}</div> | ||
<input v-if="viewKey.kind !== 'code'" v-model="(state.viewModel as any)[viewKey.key]" :type="viewKey.kind"> | ||
<CodeEditor v-if="viewKey.kind === 'code'" v-model="(state.viewModel as any)[viewKey.key]" :height="viewKey.height ?? 2"></CodeEditor> | ||
</div> | ||
|
||
<!-- TODO: Enable preview by embedding the View component for the type --> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import Button from '@/components/Button.vue'; | ||
import CodeEditor from '@/components/CodeEditor.vue'; | ||
import { reactive, type UnwrapRef } from 'vue'; | ||
import AuthService from '@/services/AuthService'; | ||
import { useAuth0 } from '@auth0/auth0-vue'; | ||
import { useToast } from 'vue-toastification'; | ||
import ModelService from '@/services/ModelService'; | ||
import type { ViewModel } from '@/models'; | ||
const auth0 = useAuth0(); | ||
const toast = useToast(); | ||
const props = defineProps<{ | ||
handler: (viewModel: UnwrapRef<ViewModel>) => void, | ||
handlerText: string, | ||
modelKind: string | ||
}>(); | ||
type EditorState = { | ||
isEditMode: boolean, | ||
showPreview: boolean, | ||
viewModel: ViewModel, | ||
}; | ||
const modelService = ModelService.inject(props.modelKind) as ModelService<ViewModel>; | ||
const state = reactive<EditorState>({ | ||
isEditMode: false, | ||
showPreview: false, | ||
viewModel: modelService.make() | ||
}); | ||
const token = await AuthService.getAccessTokenAsync(auth0, { toast: toast }); | ||
</script> |
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 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,50 @@ | ||
import type { ViewKey } from "@/models"; | ||
import BlobService from "./BlobService"; | ||
import type { HttpOptions } from "./HttpServiceV1"; | ||
import SectionService from "./SectionService"; | ||
import CourseService from "./CourseService"; | ||
import AssignmentService from "./AssignmentService"; | ||
import BlogService from "./BlogService"; | ||
|
||
abstract class ModelService<T> { | ||
abstract objectViewKeys: ViewKey[]; | ||
|
||
static inject(kind: string) { | ||
switch (kind) { | ||
case 'assignment': | ||
return new AssignmentService(); | ||
case 'blog': | ||
return new BlogService(); | ||
case 'course': | ||
return new CourseService(); | ||
case 'section': | ||
return new SectionService(); | ||
default: | ||
throw new Error(`Unknown kind: ${kind}`); | ||
} | ||
} | ||
|
||
abstract make(): T; | ||
|
||
static async fillTemplateAsync(template: string, options: HttpOptions = {}): Promise<string> { | ||
if (!template) { | ||
return ''; | ||
} | ||
// NOTE: Match and captures what is between ${}, to replace with presigned URLs | ||
const re = /"\${([0-9a-zA-Z_\-\/\.]+)}"/g; | ||
const presignedUrls = new Map<string, string>(); | ||
for (let match of template.matchAll(re)) { | ||
const textToReplace = match[0]; | ||
const filePath = match[1]; | ||
if (!(textToReplace in presignedUrls)) { | ||
presignedUrls.set(textToReplace, await BlobService.getPresignedUrlAsync(filePath, options)); | ||
} | ||
} | ||
for (let [key, value] of presignedUrls) { | ||
template = template.replace(key, value); | ||
} | ||
return template; | ||
} | ||
} | ||
|
||
export default ModelService; |
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