-
Notifications
You must be signed in to change notification settings - Fork 141
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
feat(gsoc'24): Implemented LayoutElements Panel vue component #317
Changes from all commits
ea03693
6fa85d9
4aadebe
449c215
86a0906
66d4585
0b4d82e
3a33e98
13ee548
ff8e072
7cb833c
8e0de4b
69e2762
35e65cf
203b0e9
aa95b42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<template> | ||
<div class="noSelect defaultCursor layoutElementPanel draggable-panel draggable-panel-css" | ||
ref="layoutElementPanelRef"> | ||
<div class="panel-header"> | ||
{{ $t('simulator.layout.layout_elements') }} | ||
<span class="fas fa-minus-square minimize"></span> | ||
<span class="fas fa-external-link-square-alt maximize"></span> | ||
</div> | ||
<div class="panel-body"> | ||
<v-expansion-panels id="menu" class="accordion" variant="accordion"> | ||
<v-expansion-panel v-for="(group, groupIndex) in SimulatorState.subCircuitElementList" :key="groupIndex"> | ||
<v-expansion-panel-title> | ||
{{ group.type }}s | ||
</v-expansion-panel-title> | ||
<v-expansion-panel-text eager> | ||
<div class="panel customScroll"> | ||
<div v-for="(element, elementIndex) in group.elements" class="icon subcircuitModule" | ||
:key="`${groupIndex}-${elementIndex}`" :id="`${group.type}-${elementIndex}`" | ||
:data-element-id="elementIndex" :data-element-name="group.type" | ||
@mousedown="dragElement(group.type, element, elementIndex)"> | ||
<div class="icon-image"> | ||
<img :src="getImgUrl(group.type)" /> | ||
<p class="img__description"> | ||
{{ element.label !== '' ? element.label : $t('simulator.unlabeled') }} | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
</v-expansion-panel-text> | ||
</v-expansion-panel> | ||
</v-expansion-panels> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { useState } from '#/store/SimulatorStore/state' | ||
import { simulationArea } from '#/simulator/src/simulationArea' | ||
import { useLayoutStore } from '#/store/layoutStore'; | ||
import { ref, onMounted } from 'vue'; | ||
|
||
const layoutStore = useLayoutStore() | ||
|
||
const layoutElementPanelRef = ref<HTMLElement | null>(null); | ||
|
||
onMounted(() => { | ||
layoutStore.layoutElementPanelRef = layoutElementPanelRef.value | ||
}) | ||
|
||
const SimulatorState = useState(); | ||
|
||
const dragElement = (groupType: string, element: any, index: number) => { | ||
element.subcircuitMetadata.showInSubcircuit = true | ||
element.newElement = true | ||
simulationArea.lastSelected = element | ||
|
||
// Remove the element from subCircuitElementList | ||
SimulatorState.subCircuitElementList.forEach((typeGroup) => { | ||
typeGroup.elements = typeGroup.elements.filter( | ||
(_, elementIndex) => { | ||
if(typeGroup.type === groupType && index === elementIndex) | ||
return false | ||
|
||
return true; | ||
} | ||
) | ||
}) | ||
|
||
// Remove the type group if its elements array is empty | ||
SimulatorState.subCircuitElementList = | ||
SimulatorState.subCircuitElementList.filter( | ||
(typeGroup) => typeGroup.elements.length > 0 | ||
) | ||
} | ||
|
||
function getImgUrl(elementName: string) { | ||
const elementImg = new URL( | ||
`../../../simulator/src/img/${elementName}.svg`, | ||
import.meta.url | ||
).href; | ||
return elementImg; | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
|
||
.layoutElementPanel { | ||
width: 220px; | ||
font: inherit; | ||
display: none; | ||
top: 90px; | ||
left: 10px; | ||
} | ||
</style> | ||
Comment on lines
+85
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review of the Style Section The scoped style section is concise and targets the
Suggestions:
Overall, the style section is well-implemented, but adding responsiveness could improve the component's usability across different devices. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review of the Script Section
The script section is well-organized and makes effective use of Vue's composition API and TypeScript. Here are some detailed observations:
layoutElementPanelRef
and their usage in lifecycle hooks (e.g.,onMounted
) is correctly implemented.dragElement
function on lines 52-74 handles the logic for dragging elements and updating the state accordingly. However, the logic inside this function is quite complex and could benefit from further decomposition or comments for clarity.getImgUrl
function on lines 76-82 is a utility function that constructs URLs for images. The use ofURL
andimport.meta.url
is appropriate for this purpose.Suggestions:
dragElement
for Clarity: Consider breaking down thedragElement
function into smaller, more manageable functions. This can improve readability and maintainability.dragElement
would help other developers understand the code more quickly.Overall, the script section is robust, but minor improvements could enhance its clarity and maintainability.