Skip to content

Commit 3ff5656

Browse files
authored
Merge pull request #20 from oslabs-beta/bryan/noteFunction
Bryan/note function
2 parents b687164 + 9eec48b commit 3ff5656

File tree

8 files changed

+263
-33
lines changed

8 files changed

+263
-33
lines changed

src/components/ComponentDisplay.vue

Lines changed: 195 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,20 @@ Description:
3535
<div class="component-title">
3636
<p style="color: black">{{ componentData.componentName }}</p>
3737
</div>
38-
38+
<q-icon v-if="this.componentMap[componentData.componentName]?.noteList?.length > 0"
39+
color="red"
40+
size="30px"
41+
z-layer="0"
42+
name="edit_note"
43+
class="compNoteLogo"
44+
@click="handleAddNotes" />
45+
<q-icon v-else
46+
color="white"
47+
size="30px"
48+
z-layer="0"
49+
name="edit_note"
50+
class="compNoteLogo"
51+
@click="handleAddNotes" />
3952
<q-menu context-menu>
4053
<q-list color="black" class="menu">
4154
<q-item clickable v-ripple v-close-popup @click="handleExportComponent">
@@ -46,6 +59,14 @@ Description:
4659
<q-icon color="primary" name="upload" />
4760
</q-item-section>
4861
</q-item>
62+
<q-item clickable v-ripple v-close-popup @click="handleAddNotes">
63+
<q-item-section style="color: white"
64+
>Component Notes</q-item-section
65+
>
66+
<q-item-section avatar>
67+
<q-icon color="primary" name="edit_note" />
68+
</q-item-section>
69+
</q-item>
4970
<q-item clickable v-ripple v-close-popup @click="handleAddChild">
5071
<q-item-section style="color: menutext"
5172
>Update Children</q-item-section
@@ -76,9 +97,10 @@ Description:
7697
</q-item>
7798
</q-list>
7899
</q-menu>
100+
79101
</vue-draggable-resizable>
80102
<div>
81-
<q-dialog v-model="modalOpen">
103+
<q-dialog v-model="modalOpen" persistent>
82104
<q-select
83105
@select="handleSelect"
84106
id="dropdown"
@@ -92,6 +114,68 @@ Description:
92114
style="width: 250px; background-color: #fd5f00"
93115
/>
94116
</q-dialog>
117+
<!-- some irregularity (delete event listener firing on bkspc/del) with the modal when stored locally, so modal open stored in state, and triggers to local reflect only stateful change.-->
118+
<q-dialog v-model="noteModal" @update:model-value="this.handleAddNotes">
119+
<div class="noteBox">
120+
<div class="noteHolder">
121+
<p class="title">Adding notes to {{ this.activeComponent }}</p>
122+
<div class="noteContainer">
123+
<li v-for="(note, index) in this.componentMap[this.activeComponent].noteList" :key="note" @click="deleteNote">
124+
Note #{{index}}:
125+
<div class="noteblock">{{ note }}</div>
126+
</li>
127+
</div>
128+
<q-form class="formBox" autofocus>
129+
<q-input
130+
v-model="noteText"
131+
label="Add your note here"
132+
filled
133+
dark
134+
max-height=15%
135+
autofocus true
136+
></q-input>
137+
<q-btn
138+
color="secondary"
139+
label="Submit Note"
140+
type="submit"
141+
:disable="noteText.length > 0 ? false : true"
142+
@click="submitNote"
143+
/>
144+
</q-form>
145+
</div>
146+
</div>
147+
</q-dialog>
148+
<!-- some irregularity (delete event listener firing on bkspc/del) with the modal when stored locally, so modal open stored in state, and triggers to local reflect only stateful change.-->
149+
<q-dialog v-model="noteModal" @update:model-value="this.handleAddNotes">
150+
<div class="noteBox">
151+
<div class="noteHolder">
152+
<p class="title">Adding notes to {{ this.activeComponent }}</p>
153+
<div class="noteContainer">
154+
<li v-for="(note, index) in this.componentMap[this.activeComponent].noteList" :key="note" @click="deleteNote">
155+
Note #{{index}}:
156+
<div class="noteblock">{{ note }}</div>
157+
</li>
158+
</div>
159+
<q-form class="formBox" autofocus>
160+
<q-input
161+
v-model="noteText"
162+
label="Add your note here"
163+
filled
164+
dark
165+
max-height=15%
166+
autofocus true
167+
></q-input>
168+
<q-btn
169+
color="secondary"
170+
label="Submit Note"
171+
type="submit"
172+
:disable="noteText.length > 0 ? false : true"
173+
@click="submitNote"
174+
/>
175+
</q-form>
176+
</div>
177+
</div>
178+
</q-dialog>
95179
</div>
96180
</div>
97181
</template>
@@ -114,8 +198,10 @@ export default {
114198
data() {
115199
return {
116200
modalOpen: false,
117-
abilityToDelete: false,
201+
noteText: '',
202+
wasDragged: false,
118203
testModel: [],
204+
noteModal: false,
119205
mockImg: false,
120206
initialPosition: { x: 0, y: 0 },
121207
initialSize: { w: 0, h: 0 },
@@ -126,27 +212,29 @@ export default {
126212
// when component is mounted, add ability to delete
127213
window.addEventListener("keyup", (event) => {
128214
if (event.key === "Backspace") {
129-
if (this.activeComponent) {
215+
if (this.activeComponent !== '' && this.noteModalOpen === false) {
130216
this.$store.dispatch("deleteActiveComponent");
131217
}
132218
}
133219
});
134220
window.addEventListener("keyup", (event) => {
135221
if (event.key === "Delete") {
136-
if (this.activeComponent) {
222+
if (this.activeComponent !== '' && this.noteModalOpen === false) {
137223
this.$store.dispatch("deleteActiveComponent");
138224
}
139225
}
140226
});
141227
// listener for the copy
142228
window.addEventListener("copy", () => {
143229
// if there is an activeComponent, copy info to state using dispatch
144-
if (this.activeComponent) {
230+
if (this.activeComponent !== '' && this.noteModalOpen === false) {
145231
this.$store.dispatch("copyActiveComponent");
146232
}
147233
});
148234
window.addEventListener("paste", () => {
149-
this.$store.dispatch("pasteActiveComponent");
235+
if (this.noteModalOpen === false){
236+
this.$store.dispatch("pasteActiveComponent");
237+
}
150238
});
151239
},
152240
computed: {
@@ -159,6 +247,8 @@ export default {
159247
"imagePath",
160248
"activeComponentObj",
161249
"exportAsTypescript",
250+
"noteModalOpen"
251+
162252
]),
163253
// used in VueDraggableResizeable component
164254
activeRouteArray() {
@@ -248,11 +338,19 @@ export default {
248338
"updateComponentLayer",
249339
"updateStartingSize",
250340
"updateComponentSize",
341+
"addActiveComponentNote",
342+
"deleteActiveComponentNote",
343+
"openNoteModal",
251344
]),
252345
// records component's initial position in case of drag
253346
recordInitialPosition: function (e) {
254347
if (this.activeComponent !== e.target.id) {
255-
this.setActiveComponent(e.target.id);
348+
if (e.target.parentElement?.classList.contains('draggable')){
349+
//console.log("using vanilla JS to WIN")
350+
this.setActiveComponent(e.target.parentElement.id)
351+
} else {
352+
this.setActiveComponent(e.target.id);
353+
}
256354
}
257355
this.initialPosition.x = this.activeComponentData.x;
258356
this.initialPosition.y = this.activeComponentData.y;
@@ -298,31 +396,9 @@ export default {
298396
) {
299397
this.updateComponentPosition(payload);
300398
}
399+
this.wasDragged = true;
400+
setTimeout(()=>this.wasDragged = false, 100)
301401
},
302-
/* Records size/position
303-
Add @resizing="onResize" to VueDraggableResizable #component-box to use
304-
onResize: function (x, y, width, height) {
305-
this.activeComponentData.x = x
306-
this.activeComponentData.y = y
307-
this.activeComponentData.w = width
308-
this.activeComponentData.h = height
309-
this.componentMap[this.activeComponent].x = x
310-
this.componentMap[this.activeComponent].y = y
311-
this.componentMap[this.activeComponent].w = width
312-
this.componentMap[this.activeComponent].h = height
313-
},
314-
*/
315-
/* Records component's position
316-
Add @dragging="onDrag" to VueDraggableResizable #component-box to use
317-
onDrag: function (x, y) {
318-
console.log('ondrag')
319-
this.activeComponentData.x = x
320-
this.activeComponentData.y = y
321-
this.componentMap[this.activeComponent].x = x
322-
this.componentMap[this.activeComponent].y = y
323-
},
324-
*/
325-
// unhighlights all inactive components
326402
onActivated(componentData) {
327403
if (!componentData){
328404
return;
@@ -358,9 +434,26 @@ export default {
358434
}
359435
},
360436
// renders modal with Update Children and Layer in it
437+
handleAddNotes(){
438+
if (this.wasDragged === false){
439+
this.openNoteModal();
440+
}
441+
},
361442
handleAddChild() {
362443
this.modalOpen = true;
363444
},
445+
submitNote(e){
446+
e.preventDefault()
447+
if (this.noteText === ''){
448+
return;
449+
}
450+
this.addActiveComponentNote(this.noteText);
451+
this.noteText = '';
452+
},
453+
deleteNote(e){
454+
//currently just deletes the note based on the text alone.
455+
this.deleteActiveComponentNote(e.target.innerText);
456+
},
364457
// used when user selects to add child from dropdown
365458
handleSelect(value) {
366459
this.updateActiveComponentChildrenValue(value);
@@ -387,6 +480,10 @@ export default {
387480
copyActiveComponent() {},
388481
},
389482
watch: {
483+
noteModalOpen (){
484+
console.log('display note, prevent delete?', this.noteModalOpen)
485+
this.noteModal = this.noteModalOpen;
486+
},
390487
activeComponent: {
391488
handler(){
392489
this.onActivated(this.activeComponentObj);
@@ -398,6 +495,54 @@ export default {
398495
</script>
399496
400497
<style scoped lang="scss">
498+
li{
499+
display: flex;
500+
font-weight: bold;
501+
padding: 3px;
502+
}
503+
504+
li:hover{
505+
background-color: $negative;
506+
}
507+
.noteblock{
508+
white-space: pre-wrap;
509+
font-weight: normal;
510+
width: 85%;
511+
margin-left: 10px;
512+
align-self: flex-end;
513+
}
514+
.noteBox{
515+
background-color: $subprimary;
516+
color: $menutext;
517+
width: 65%;
518+
height: 60vh;
519+
padding: 15px;
520+
}
521+
.noteHolder{
522+
background-color: $subsecondary;
523+
width: 100%;
524+
height: 100%;
525+
padding: 10px;
526+
display: flex;
527+
flex-direction: column;
528+
flex-wrap: nowrap;
529+
border-radius: 4px;
530+
overflow-y: hidden;
531+
}
532+
.noteDisplay{
533+
min-height: 30%;
534+
}
535+
.noteContainer{
536+
max-height: 400px;
537+
border: 1px solid $primary;
538+
border-radius: 4px;
539+
overflow-y: auto;
540+
}
541+
.formBox{
542+
max-height: 15%;
543+
justify-self: flex-end;
544+
}
545+
401546
.component-title {
402547
position: relative;
403548
font-size: 16px;
@@ -459,6 +604,19 @@ export default {
459604
.menu {
460605
margin-bottom: 0px !important;
461606
}
607+
608+
.compNoteLogo{
609+
background: $subprimary;
610+
opacity: 90%;
611+
border-radius: 4px;
612+
position: absolute;
613+
top: 4px;
614+
left: 4px;
615+
}
616+
.compNoteLogo:hover{
617+
background: $primary;
618+
}
619+
462620
.component-box {
463621
color: $menutext;
464622
border: 1.2px dashed $darktext;
@@ -488,4 +646,9 @@ export default {
488646
#counter {
489647
margin-top: 20px;
490648
}
649+
.title {
650+
font-size: 20px;
651+
font-weight: bold;
652+
color: white;
653+
}
491654
</style>

src/components/ExportComponentMixin.vue

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export default {
1818
createComponentCode(componentLocation, componentName, children) {
1919
fs.writeFileSync(
2020
componentLocation + ".vue",
21-
this.writeTemplate(componentName, children) +
21+
this.writeComments(componentName) +
22+
this.writeTemplate(componentName, children) +
2223
this.writeScript(componentName, children) +
2324
this.writeStyle(componentName)
2425
);
@@ -90,6 +91,18 @@ export default {
9091
}
9192
return outputStr;
9293
},
94+
95+
writeComments(componentName){
96+
if (this.componentMap[componentName]?.noteList?.length > 0){
97+
let commentStr = '<!--'
98+
this.componentMap[componentName].noteList.forEach((el)=>{
99+
commentStr += "\n"
100+
commentStr += el;
101+
})
102+
commentStr += '\n-->\n\n'
103+
return commentStr;
104+
}
105+
},
93106
/**
94107
* @description creates the <router-link> boilerplate for /views/components
95108
* also creates the <template></template> tag for each component

0 commit comments

Comments
 (0)