diff --git a/frontend/components.d.ts b/frontend/components.d.ts index 09f63fdd..8df8bed5 100644 --- a/frontend/components.d.ts +++ b/frontend/components.d.ts @@ -77,6 +77,7 @@ declare module 'vue' { PageModal: typeof import('./src/components/Modals/PageModal.vue')['default'] PaymentSettings: typeof import('./src/components/Settings/PaymentSettings.vue')['default'] Play: typeof import('./src/components/Icons/Play.vue')['default'] + ProgrammingExerciseModal: typeof import('./src/components/Modals/ProgrammingExerciseModal.vue')['default'] ProgressBar: typeof import('./src/components/ProgressBar.vue')['default'] Question: typeof import('./src/components/Modals/Question.vue')['default'] Quiz: typeof import('./src/components/Quiz.vue')['default'] diff --git a/frontend/src/components/Modals/ProgrammingExerciseModal.vue b/frontend/src/components/Modals/ProgrammingExerciseModal.vue new file mode 100644 index 00000000..fd30be91 --- /dev/null +++ b/frontend/src/components/Modals/ProgrammingExerciseModal.vue @@ -0,0 +1,53 @@ + + + + diff --git a/frontend/src/pages/ProgrammingExercise.vue b/frontend/src/pages/ProgrammingExercise.vue new file mode 100644 index 00000000..d34b999f --- /dev/null +++ b/frontend/src/pages/ProgrammingExercise.vue @@ -0,0 +1,44 @@ + + {{ exercise }} + + + diff --git a/frontend/src/utils/program.ts b/frontend/src/utils/program.ts new file mode 100644 index 00000000..5e36a2ec --- /dev/null +++ b/frontend/src/utils/program.ts @@ -0,0 +1,75 @@ +import { createApp, h } from 'vue' +import { Code } from 'lucide-vue-next' +import translationPlugin from '@/translation' +import ProgrammingExerciseModal from '@/components/Modals/ProgrammingExerciseModal.vue'; + +export class Program { + + data: any; + api: any; + readOnly: boolean; + wrapper: HTMLDivElement; + + constructor({ data, api, readOnly }: { data: any; api: any; readOnly: boolean }) { + this.data = data; + this.api = api; + this.readOnly = readOnly; + } + + static get toolbox() { + const app = createApp({ + render: () => h(Code, { size: 5, strokeWidth: 1.5 }), + }) + + const div = document.createElement('div') + app.mount(div) + + return { + title: __('Programming Exercise'), + icon: div.innerHTML, + } + } + + static get isReadOnlySupported() { + return true + } + + render() { + this.wrapper = document.createElement('div') + if (Object.keys(this.data).length) { + this.renderExercise(this.data.exercise) + } else { + this.renderModal() + } + return this.wrapper + } + + renderModal() { + if (this.readOnly) { + return + } + const app = createApp(ProgrammingExerciseModal, { + onSave: (exercise: string) => { + this.data.exercise = exercise + this.renderExercise(exercise) + }, + }) + app.use(translationPlugin) + app.mount(this.wrapper) + } + + renderExercise(exercise: string) { + this.wrapper.innerHTML = `
` + return + } + + save() { + return { + exercise: this.data.exercise, + } + } +} \ No newline at end of file