Merge branch 'main' of https://github.com/hackku22/Mathy
This commit is contained in:
commit
2213e576ec
@ -1,17 +1,17 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from "vue";
|
import {onMounted, ref} from 'vue'
|
||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from 'uuid'
|
||||||
import WrapperBox from "../components/WrapperBox.vue";
|
import WrapperBox from '../components/WrapperBox.vue'
|
||||||
import { MathPage } from "../support/page";
|
import {MathPage} from '../support/page'
|
||||||
import { MathStatement } from "../support/parse";
|
import {MathStatement} from '../support/parse'
|
||||||
import Katex from "../components/Katex.vue";
|
import Katex from '../components/Katex.vue'
|
||||||
import { EvaluationResult, StatementID } from "../types";
|
import {EvaluationResult, hasOwnProperty, StatementID} from '../support/types'
|
||||||
import Statement from "../components/Statement.vue";
|
import Statement from '../components/Statement.vue'
|
||||||
import VarDeclEditor from "./VarDeclEditor.vue";
|
import VarDeclEditor from './VarDeclEditor.vue'
|
||||||
import ExpressionEditor from "./ExpressionEditor.vue";
|
import ExpressionEditor from './ExpressionEditor.vue'
|
||||||
import TextBox from "../components/TextBox.vue";
|
import TextBox from '../components/TextBox.vue'
|
||||||
import { RichTextBox } from "../types.ts";
|
import {RichTextBox} from "../support/types";
|
||||||
import { stepX, stepY } from "../support/const.ts";
|
import { stepX, stepY } from "../support/const";
|
||||||
|
|
||||||
const math = new MathPage(uuidv4());
|
const math = new MathPage(uuidv4());
|
||||||
const statements = ref<MathStatement[]>([]);
|
const statements = ref<MathStatement[]>([]);
|
||||||
@ -19,6 +19,22 @@ const evaluation = ref<EvaluationResult | undefined>();
|
|||||||
const statementsKey = ref<string>(uuidv4());
|
const statementsKey = ref<string>(uuidv4());
|
||||||
const leftDrawerOpen = ref(false);
|
const leftDrawerOpen = ref(false);
|
||||||
|
|
||||||
|
const variableListingColumns = [
|
||||||
|
{
|
||||||
|
name: 'name',
|
||||||
|
field: 'name',
|
||||||
|
label: 'Variable',
|
||||||
|
sortable: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'value',
|
||||||
|
field: 'value',
|
||||||
|
label: 'Value',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
const variableListingRows = ref<({name: string, value: string})[]>([])
|
||||||
|
|
||||||
function toggleLeftDrawer() {
|
function toggleLeftDrawer() {
|
||||||
leftDrawerOpen.value = !leftDrawerOpen.value;
|
leftDrawerOpen.value = !leftDrawerOpen.value;
|
||||||
}
|
}
|
||||||
@ -36,13 +52,34 @@ const openNewExpressionModal = () => {
|
|||||||
const updateStatements = () => {
|
const updateStatements = () => {
|
||||||
statements.value = math.getStatements();
|
statements.value = math.getStatements();
|
||||||
try {
|
try {
|
||||||
evaluation.value = math.evaluate();
|
evaluation.value = math.evaluate()
|
||||||
|
const variableValues: ({name: string, value: string})[] = []
|
||||||
|
|
||||||
|
for ( const name in evaluation.value!.variables ) {
|
||||||
|
if ( !hasOwnProperty(evaluation.value!.variables, name) ) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
let value = String(evaluation.value!.variables[name] ?? '')
|
||||||
|
try {
|
||||||
|
value = MathStatement.temp(value).toHTMLString()
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
variableValues.push({
|
||||||
|
name,
|
||||||
|
value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
variableListingRows.value = variableValues
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
evaluation.value = undefined;
|
evaluation.value = undefined;
|
||||||
}
|
}
|
||||||
statementsKey.value = uuidv4();
|
statementsKey.value = uuidv4();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onMounted(updateStatements)
|
||||||
|
|
||||||
const saveNewVariable = (stmt: MathStatement) => {
|
const saveNewVariable = (stmt: MathStatement) => {
|
||||||
math.addStatement(stmt);
|
math.addStatement(stmt);
|
||||||
newVariableModalOpen.value = false;
|
newVariableModalOpen.value = false;
|
||||||
@ -109,10 +146,52 @@ const removeRichTextBox = (id: number) => {
|
|||||||
|
|
||||||
<q-drawer show-if-above v-model="leftDrawerOpen" side="left" bordered>
|
<q-drawer show-if-above v-model="leftDrawerOpen" side="left" bordered>
|
||||||
<div class="column" style="height: 100%">
|
<div class="column" style="height: 100%">
|
||||||
<div class="col">variables</div>
|
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<q-separator />
|
<q-table
|
||||||
function
|
flat
|
||||||
|
title="Variables"
|
||||||
|
:rows="variableListingRows"
|
||||||
|
:columns="variableListingColumns"
|
||||||
|
row-key="name"
|
||||||
|
hide-no-data
|
||||||
|
hide-bottom
|
||||||
|
:pagination="{rowsPerPage: 10000}"
|
||||||
|
style="height: 100%; border-radius: 0"
|
||||||
|
>
|
||||||
|
<template v-slot:body="props">
|
||||||
|
<q-tr :props="props">
|
||||||
|
<q-td key="name" :props="props">
|
||||||
|
{{ props.row.name }}
|
||||||
|
</q-td>
|
||||||
|
<q-td key="value" :props="props">
|
||||||
|
<div v-html="props.row.value"></div>
|
||||||
|
</q-td>
|
||||||
|
</q-tr>
|
||||||
|
</template>
|
||||||
|
</q-table>
|
||||||
|
</div>
|
||||||
|
<div class="col">
|
||||||
|
<!-- <q-separator />-->
|
||||||
|
<q-table
|
||||||
|
flat
|
||||||
|
title="Functions"
|
||||||
|
row-key="name"
|
||||||
|
hide-no-data
|
||||||
|
hide-bottom
|
||||||
|
:pagination="{rowsPerPage: 10000}"
|
||||||
|
style="height: 100%; border-top: 1px solid lightgrey; border-radius: 0"
|
||||||
|
>
|
||||||
|
<template v-slot:body="props">
|
||||||
|
<q-tr :props="props">
|
||||||
|
<q-td key="name" :props="props">
|
||||||
|
{{ props.row.name }}
|
||||||
|
</q-td>
|
||||||
|
<q-td key="value" :props="props">
|
||||||
|
<div v-html="props.row.value"></div>
|
||||||
|
</q-td>
|
||||||
|
</q-tr>
|
||||||
|
</template>
|
||||||
|
</q-table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user