Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

185: Add a generic model editor for any data type #190

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 3 additions & 1 deletion client/src/components/ModelEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
<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">
<input v-if="viewKey.kind === 'text'" v-model="(state.viewModel as any)[viewKey.key]" type="text">
<input v-if="viewKey.kind === 'number'" v-model="(state.viewModel as any)[viewKey.key]" type="number">
<input v-if="viewKey.kind === 'select'" v-model="(state.viewModel as any)[viewKey.key]" type="text" placeholder="TODO: NOT IMPLEMENTED">
<CodeEditor v-if="viewKey.kind === 'code'" v-model="(state.viewModel as any)[viewKey.key]" :height="viewKey.height ?? 2"></CodeEditor>
</div>

Expand Down
2 changes: 1 addition & 1 deletion client/src/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type Id = string;
export type InputKind = 'text' | 'number' | 'code';
export type InputKind = 'text' | 'number' | 'code' | 'select';

export type ViewKey = {
key: string
Expand Down
5 changes: 5 additions & 0 deletions client/src/services/AssignmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import type ModelService from './ModelService';
export default class AssignmentService implements ModelService<Assignment> {
objectViewKeys: ViewKey[] = [
{ key: 'id', kind: 'text' },
{ key: 'name', kind: 'text' },
{ key: 'description', kind: 'code' },
{ key: 'problemExplanation', kind: 'code' },
{ key: 'requiredSectionIds', kind: 'select' },
{ key: 'courseId', kind: 'select' },
];

make(): Assignment {
Expand Down
5 changes: 5 additions & 0 deletions client/src/services/SectionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import type ModelService from './ModelService';
export default class SectionService implements ModelService<Section> {
objectViewKeys: ViewKey[] = [
{ key: 'id', kind: 'text' },
{ key: 'content', kind: 'code' },
{ key: 'difficulty', kind: 'number' },
{ key: 'description', kind: 'code' },
{ key: 'name', kind: 'text' },
{ key: 'courseId', kind: 'select'},
];

make(): Section {
Expand Down
8 changes: 3 additions & 5 deletions client/src/views/AssignmentView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
:handler="async () => await deleteAssignmentAsync(id)" text="Delete?"
class="w-20"></Button>
</span>
<AssignmentEditor :handler="createAssignmentAsync" handlerText="Create" assignmentId=""
assignmentProblemExplanation="" assignmentDescription="" assignmentName="" :assignmentSectionIds="[]">
</AssignmentEditor>
<ModelEditor :handler="createAssignmentAsync" handlerText="Create" modelKind="assignment"></ModelEditor>
</div>
</div>
</div>
Expand All @@ -25,9 +23,9 @@
<script setup lang="ts">
import AuthService from '@/services/AuthService';
import Button from '@/components/Button.vue';
import AssignmentEditor, { type AssignmentEditorState } from '@/components/AssignmentEditor.vue';
import AssignmentLink from '@/components/AssignmentLink.vue';
import AssignmentService from '@/services/AssignmentService';
import ModelEditor from '@/components/ModelEditor.vue';
import Spinner from '@/components/Spinner.vue';
import type { AssignmentIndex } from '@/models';
import { onMounted, reactive } from 'vue';
Expand All @@ -45,7 +43,7 @@ const state = reactive({
assignmentIndex: {} as AssignmentIndex,
});

async function createAssignmentAsync(state: AssignmentEditorState) {
async function createAssignmentAsync(state: any) {
const assignmentToCreate = {
id: state.id,
problemExplanation: state.problemExplanation,
Expand Down
3 changes: 2 additions & 1 deletion client/src/views/CourseView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const state = reactive({
});

async function createCourseAsync(state: any) {
// TODO: Move these kind of functions out
// of the view and into their corresponding Service
state.metadata = {
name: state.name,
description: state.description,
Expand All @@ -49,7 +51,6 @@ async function createCourseAsync(state: any) {
content: state.content,
metadata: state.metadata,
};
console.log(courseToCreate);
await CourseService.createAsync(
courseToCreate,
{
Expand Down