feat: livecode settings

This commit is contained in:
Jannat Patel
2025-06-25 19:57:07 +05:30
parent e71275a0dc
commit b8981c249f
6 changed files with 92 additions and 35 deletions

View File

@@ -5,6 +5,20 @@
>
<Breadcrumbs :items="breadcrumbs" />
</header>
<div
v-if="falconError"
class="flex items-center justify-between p-3 text-sm bg-surface-amber-1 text-ink-amber-3"
>
<span>
{{ falconError }}
</span>
<Button v-if="user.data?.is_moderator" @click="openSettings('General')">
<template #prefix>
<Settings class="size-4 stroke-1.5" />
</template>
{{ __('Settings') }}
</Button>
</div>
<div class="grid grid-cols-2 h-[calc(100vh_-_3rem)]">
<div class="border-r py-5 px-8 h-full">
<div class="font-semibold mb-2">
@@ -29,7 +43,9 @@
</Badge>
<Button
v-if="
submissionID == 'new' || user.data?.name == submission.doc?.owner
!falconError &&
(submissionID == 'new' ||
user.data?.name == submission.doc?.owner)
"
variant="solid"
@click="submitCode"
@@ -131,9 +147,10 @@ import {
usePageMeta,
} from 'frappe-ui'
import { computed, inject, onMounted, ref, watch } from 'vue'
import { Play, X, Check } from 'lucide-vue-next'
import { Play, X, Check, Settings } from 'lucide-vue-next'
import { sessionStore } from '@/stores/session'
import { useRouter } from 'vue-router'
import { openSettings } from '@/utils'
const user = inject<any>('$user')
const code = ref<string | null>('')
@@ -141,19 +158,13 @@ const output = ref<string | null>(null)
const error = ref<boolean | null>(null)
const errorMessage = ref<string | null>(null)
const testCaseSection = ref<HTMLElement | null>(null)
const testCases = ref<
Array<{
input: string
output: string
expected_output: string
status: string
}>
>([])
const testCases = ref<TestCase[]>([])
const boilerplate = ref<string>('')
const { brand } = sessionStore()
const { brand, livecodeURL } = sessionStore()
const router = useRouter()
const fromLesson = ref(false)
const falconURL = 'https://falcon.frappe.io/'
const falconURL = ref<string>('https://falcon.frappe.io/')
const falconError = ref<string | null>(null)
const props = withDefaults(
defineProps<{
@@ -273,9 +284,23 @@ watch(
)
const loadFalcon = () => {
if (livecodeURL.data.includes('falcon.frappe.io') && !user.data?.is_fc_site) {
falconError.value = __(
'Only Frappe Cloud sites can use Falcon Live Code. Please migrate your site to Frappe Cloud or setup Falcon Live Code on your own server.'
)
return
} else if (livecodeURL.data) {
falconURL.value = livecodeURL.data
} else if (!livecodeURL.data && !user.data?.is_fc_site) {
falconError.value = __(
'Live Code URL is not set. Please set it from the Settings.'
)
return
}
return new Promise((resolve, reject) => {
const script = document.createElement('script')
script.src = `${falconURL}static/livecode.js`
script.src = `${falconURL.value}static/livecode.js`
script.onload = resolve
script.onerror = reject
document.head.appendChild(script)
@@ -351,7 +376,7 @@ const execute = (stdin = ''): Promise<string> => {
let hasError = false
let session = new LiveCodeSession({
base_url: 'https://falcon.frappe.io',
base_url: falconURL.value,
runtime: exercise.doc?.language.toLowerCase() || 'python',
code: code.value,
files: [{ filename: 'stdin', contents: stdin }],

View File

@@ -3,21 +3,35 @@
class="sticky flex items-center justify-between top-0 z-10 border-b bg-surface-white px-3 py-2.5 sm:px-5"
>
<Breadcrumbs :items="breadcrumbs" />
<Button
v-if="!readOnlyMode"
variant="solid"
@click="
() => {
exerciseID = 'new'
showForm = true
}
"
>
<template #prefix>
<Plus class="h-4 w-4 stroke-1.5" />
</template>
{{ __('New') }}
</Button>
<div class="space-x-2">
<router-link
:to="{
name: 'ProgrammingExerciseSubmissions',
}"
>
<Button>
<template #prefix>
<ClipboardList class="size-4 stroke-1.5" />
</template>
{{ __('Check All Submissions') }}
</Button>
</router-link>
<Button
v-if="!readOnlyMode"
variant="solid"
@click="
() => {
exerciseID = 'new'
showForm = true
}
"
>
<template #prefix>
<Plus class="h-4 w-4 stroke-1.5" />
</template>
{{ __('New') }}
</Button>
</div>
</header>
<div class="md:w-4/5 md:mx-auto p-5">
<div class="flex items-center justify-between mb-5">
@@ -89,7 +103,7 @@ import {
createListResource,
usePageMeta,
} from 'frappe-ui'
import { Plus } from 'lucide-vue-next'
import { ClipboardList, Plus } from 'lucide-vue-next'
import { sessionStore } from '@/stores/session'
import { useRouter } from 'vue-router'
import ProgrammingExerciseForm from '@/pages/ProgrammingExercises/ProgrammingExerciseForm.vue'