Bladeren bron

feature: folderTree toolbar submit and change filename when edited and submitted successfully

Arsekl 3 jaren geleden
bovenliggende
commit
182ab4addc

+ 8 - 1
src/constant/index.ts

@@ -1,4 +1,4 @@
-import {IMenuItemProps} from "@dtinsight/molecule/esm/components";
+import {IActionBarItemProps , IMenuItemProps} from "@dtinsight/molecule/esm/components";
 import {IExplorerPanelItem} from "@dtinsight/molecule/esm/model";
 
 export enum ID_COLLECTIONS{
@@ -19,4 +19,11 @@ export const OPEN_IN_NEW_GROUP: IMenuItemProps = {
 export const QUESTION_LIST_PANEL: IExplorerPanelItem = {
     id: 'explorer.questionList',
     name: 'QUESTION LIST'
+}
+
+export const FOLDERTREE_SUBMIT_TOOLBAR: IActionBarItemProps = {
+    id: 'foldertree.submit',
+    name: 'submit',
+    title: 'submit',
+    icon: 'cloud-upload'
 }

+ 21 - 10
src/extensions/init.tsx

@@ -1,6 +1,12 @@
 import molecule from "@dtinsight/molecule";
 import {ColorThemeMode, IActivityMenuItemProps, IEditorGroup} from "@dtinsight/molecule/esm/model";
-import {DRAWER_MENU_ENUM, ID_COLLECTIONS, OPEN_IN_NEW_GROUP, QUESTION_LIST_PANEL} from "../constant";
+import {
+    DRAWER_MENU_ENUM,
+    FOLDERTREE_SUBMIT_TOOLBAR,
+    ID_COLLECTIONS,
+    OPEN_IN_NEW_GROUP,
+    QUESTION_LIST_PANEL
+} from "../constant";
 import {UniqueId} from "@dtinsight/molecule/esm/common/types";
 import {IExtension} from "@dtinsight/molecule/esm/model/extension";
 import LogPane from "@/components/logPane";
@@ -9,7 +15,7 @@ import {jumpToLogin} from "@/services/auth";
 import Api from "@/api";
 import {history} from "umi";
 import notification from "@/components/notification";
-import {deleteCookie, getQuestion, goToLogin, randomId, updateAccountContext} from "@/utils";
+import {deleteCookie, getQuestion, goToLogin, randomId, submitQuestion, updateAccountContext} from "@/utils";
 import {loadUser} from "@/redux/action/action";
 import {QuickTogglePanelAction} from "@dtinsight/molecule/esm/monaco/quickTogglePanelAction";
 import {Button} from "antd";
@@ -123,18 +129,23 @@ function initExplorer() {
         ),
     })
     const explorerData = molecule.explorer.getState().data?.concat() || [];
-    const { SAMPLE_FOLDER_PANEL_ID, EDITOR_PANEL_ID } = molecule.builtin.getConstants();
+    const { SAMPLE_FOLDER_PANEL_ID } = molecule.builtin.getConstants();
     const folderTreePane = explorerData.find((item) => item.id === SAMPLE_FOLDER_PANEL_ID);
-    const editorTreePane = explorerData.find((item) => item.id === EDITOR_PANEL_ID)
-    if (editorTreePane?.toolbar) {
-        editorTreePane.toolbar[0] = editorTreePane.toolbar[2]
-        editorTreePane.toolbar.pop()
-        editorTreePane.toolbar.pop()
-    }
+
+    console.log(folderTreePane)
+    molecule.explorer.onPanelToolbarClick((panel, toolbarId)=>{
+        switch (toolbarId) {
+            case FOLDERTREE_SUBMIT_TOOLBAR.id:
+                submitQuestion()
+                break;
+            default:
+                break;
+        }
+    })
     if (folderTreePane?.toolbar) {
         folderTreePane.toolbar[0] = folderTreePane.toolbar[2]
         folderTreePane.toolbar[1] = folderTreePane.toolbar[3]
-        folderTreePane.toolbar.pop()
+        folderTreePane.toolbar[2] = FOLDERTREE_SUBMIT_TOOLBAR
         folderTreePane.toolbar.pop()
     }
     molecule.explorer.setState({

+ 2 - 15
src/extensions/menubar/index.ts

@@ -9,6 +9,7 @@ import api from "@/api";
 import {store} from "@/redux/store";
 import {message} from "antd";
 import notification from "@/components/notification";
+import {submitQuestion} from "@/utils";
 
 function handleMenuBarEvents() {
     molecule.menuBar.onSelect((menuId) => {
@@ -21,21 +22,7 @@ function handleMenuBarEvents() {
                 });
                 break;
             case DRAWER_MENU_ENUM.SUBMIT:
-                const examId = store.getState().loadQuestion.examId
-                if (!examId) message.error("Please select an exam")
-                else {
-                    const questionId = store.getState().loadQuestion.codeList![0].questionId
-                    api.updateOnlineCodeByExamIdAndQuestionId(examId!, questionId!, {
-                        code: store.getState().loadQuestion.codeList![0].editable!
-                    }).then(r => {
-                        console.log(r)
-                        if (r.err === 0) message.success("Success")
-                        else {
-                            message.error("Failure")
-                            notification.error({key: "SubmitError", message: r.msg})
-                        }
-                    }).catch(r => message.error("Failure"))
-                }
+                submitQuestion()
                 break;
             case 'openFile': {
                 jumpToCoder()

+ 4 - 2
src/extensions/theFirstExtension/editorController.tsx

@@ -36,8 +36,10 @@ export function activateEditCallback() {
                         store.dispatch(loadQuestion(question))
                     }
                     if (location != null) {
-                        console.log(molecule.editor.editorInstance.getModel())
-                        console.log(monaco.editor.getModel(monaco.Uri.parse(location)))
+                        const el = window.document.querySelector(`div[data-key='${node.id}'].mo-tree__treenode span.mo-tree__treenode__title`) as HTMLElement | null;
+                        if (el) el.style.color = '#2491f7'
+                        // console.log(molecule.editor.editorInstance.getModel())
+                        // console.log(monaco.editor.getModel(monaco.Uri.parse(location)))
                     }
                     console.log('value update')
                 }

+ 25 - 0
src/utils/index.ts

@@ -8,6 +8,7 @@ import molecule from "@dtinsight/molecule";
 import {jumpToLogin} from "@/services/auth";
 import ex from "umi/dist";
 import {message} from "antd";
+import api from "@/api";
 
 export function randomId() {
     return Date.now() + Math.round(Math.random() * 1000);
@@ -176,6 +177,30 @@ function generateFileNodes(
     }
 }
 
+export function submitQuestion() {
+    const examId = store.getState().loadQuestion.examId
+    if (!examId) message.error("Please select an exam")
+    else {
+        const questionId = store.getState().loadQuestion.codeList![0].questionId
+        api.updateOnlineCodeByExamIdAndQuestionId(examId!, questionId!, {
+            code: store.getState().loadQuestion.codeList![0].editable!
+        }).then(r => {
+            if (r.err === 0) {
+                const elList = window.document.querySelectorAll("div.mo-tree__treenode span.mo-tree__treenode__title")
+                elList.forEach((el) => {
+                    const span = el as HTMLElement
+                    span.style.color = ''
+                })
+                message.success("Success")
+            }
+            else {
+                message.error("Failure")
+                notification.error({key: "SubmitError", message: r.msg})
+            }
+        }).catch(r => message.error("Failure"))
+    }
+}
+
 export function getQuestion(examId: string, questionId: string) {
     const hide = message.loading("Loading...", 0)
     const regPos = /^[0-9]+/;