Переглянути джерело

Move notes from sessions to workouts.

Lee Morgan 1 рік тому
батько
коміт
eddc641a6f

+ 0 - 2
controllers/session.js

@@ -38,7 +38,6 @@ const createSession = (data)=>{
         workout: data.workout,
         start: new Date(data.start),
         end: new Date(data.end),
-        notes: data.notes,
         exercises: data.exercises
     });
 }
@@ -64,7 +63,6 @@ const responseSession = (session)=>{
         workout: session.workout,
         start: session.start,
         end: session.end,
-        notes: session.notes,
         exercises: session.exercises
     };
 }

+ 10 - 10
documentation/data.js

@@ -123,6 +123,11 @@ window.data = [
                 type: "String",
                 desc: "User given name of the exercise"
             },
+            {
+                name: "exercises.notes",
+                type: "String",
+                desc: "User created notes for the exercise"
+            },
             {
                 name: "exercises.type",
                 type: "String",
@@ -154,6 +159,11 @@ window.data = [
                 type: "String",
                 desc: "Name of the exercise"
             },
+            {
+                name: "exercises.notes",
+                type: "String (optional)",
+                desc: "User created notes for the exercise"
+            },
             {
                 name: "exercises.type",
                 type: "String",
@@ -202,11 +212,6 @@ window.data = [
                 type: "Date",
                 desc: "Date/Time when session finished"
             },
-            {
-                name: "notes",
-                type: "String",
-                desc: "Notes from the user about the session"
-            },
             {
                 name: "exercises",
                 type: "[Object]",
@@ -237,11 +242,6 @@ window.data = [
                 type: "Date",
                 desc: "Date/Time of session end"
             },
-            {
-                name: "notes",
-                type: "String, (optional)",
-                desc: "Any notes from user about the session"
-            },
             {
                 name: "exercises",
                 type: "[Object]",

+ 0 - 4
models/Session.js

@@ -13,10 +13,6 @@ const SessionSchema = mongoose.Schema({
         type: Date,
         required: true
     },
-    notes: {
-        type: String,
-        required: false
-    },
     exercises: [{}]
 });
 

+ 4 - 1
models/Workout.js

@@ -14,7 +14,10 @@ const WorkoutSchema = new mongoose.Schema({
             type: String,
             required: true
         },
-        //enum: weights
+        notes: {
+            type: String,
+            required: false
+        },
         type: {
             type: String,
             required: true

+ 30 - 1
views/css/session.css

@@ -4,12 +4,41 @@
     padding-bottom: 25px;
 }
 
-#sessionAddSet{
+#sessionButtonBox{
+    display: flex;
+    flex-direction: column;
     position: absolute;
     top: 15px;
     right: 15px;
 }
 
+#sessionNotesBtn{
+    margin-bottom: 5px;
+}
+
+#sessionNotesText{
+    display: flex;
+    flex-direction: column;
+    position: absolute;
+    top: 25%;
+    left: 2%;
+    height: 35%;
+    width: 95%;
+    padding: 25px 10px;
+    box-shadow: 0 0 5px var(--text);
+    background: var(--gray);
+    z-index: 2;
+}
+
+#sessionNotesText textarea{
+    height: 100%;
+    width: 100%;
+    font-size: 18px;
+    margin-bottom: 15px;
+    color: var(--gray);
+    padding: 5px;
+}
+
 #noSessionText{
     color: white;
     font-size: 18px;

+ 9 - 1
views/index.html

@@ -139,7 +139,15 @@
 
         <p id="previousSession"></p>
 
-        <button id="sessionAddSet" class="button">Add Set</button>
+        <div id="sessionButtonBox">
+            <button id="sessionNotesBtn" class="button">Notes</button>
+            <button id="sessionAddSet" class="button">Add Set</button>
+        </div>
+
+        <div id="sessionNotesText" style="display:none">
+            <textarea id="sessionTextArea"></textarea>
+            <button id="sessionNotesDone" class="button">Done</button>
+        </div>
 
         <div id="sessionSets"></div>
 

+ 15 - 0
views/js/pages/session.js

@@ -45,10 +45,25 @@ export default {
             nextSessionBtn.addEventListener("click", ()=>{this.changeExercise(1)});
             document.getElementById("finishSessionBtn").addEventListener("click", ()=>{this.finish()});
             document.getElementById("sessionAddSet").addEventListener("click", ()=>{this.addSet()});
+            document.getElementById("sessionNotesBtn").addEventListener("click", this.displayNotes.bind(this));
+            document.getElementById("sessionNotesDone").addEventListener("click", (event)=>{
+                event.target.parentElement.style.display = "none";
+            });
             this.rendered = true;
         }
     },
 
+    displayNotes: function(){
+        const container = document.getElementById("sessionNotesText");
+        container.style.display = "flex";
+
+        const textarea = container.querySelector("textarea");
+        textarea.textContent = this.currentSession.exercises[this.exerciseIndex].notes;
+        textarea.addEventListener("input", ()=>{
+            this.currentSession.exercises[this.exerciseIndex].notes = textarea.value;
+        });
+    },
+
     addSet: function(){
         const exercise = this.currentSession.exercises[this.exerciseIndex];
         const template = document.getElementById("weightSet").content.children[0];