---
title: How to Take Care of Your Dog
layout: single
tagline: "Treat your bud"
classes: wide
header:
  overlay_image: /assets/images/doctor.jpeg
  caption: "Photo credit: [**Live Material **](https://www.livescience.com/facts-about-dogs)"
  actions:
    - label: "Donate"
      url: "https://www.nationalhumanesociety.org/donations-helping-animals?gclid=Cj0KCQiA_bieBhDSARIsADU4zLevTGhcYmgdFMD1zp4eVCv6sy3HWt4q7cQZ24-GJ_OaOdyE9ubzYSwaAqajEALw_wcB"
---
<html>
<body>

<div class="tab">
    <button class="tablinks" onclick="openCity(event, 'Classes for Dog Training')">Classes for Dog Training</button>
    <button class="tablinks" onclick="openCity(event, 'Excercise')">Exercise</button>
    <button class="tablinks" onclick="openCity(event, 'Dieting')">Dieting</button>
    <button class="tablinks" onclick="openCity(event, 'Conditions')">Conditions</button>
    <button class="tablinks" onclick="openCity(event, 'Journal')">Journal</button>
</div>

<div id="Classes for Dog Training" class="tabcontent">
    <h3>Dog Training</h3>
    <p>Knowing how to train your dog is very important! That is why this shows the available classes for learning how to train your dog.</p>
    <input type="button" value="Generate Table" onclick="GenerateTable()" />
    <hr />
    <div id="dvTable"></div>
    <script>
    function GenerateTable() {
//Build an array containing Customer records.
        var customers = new Array();
//Create a HTML Table element.
        var table = document.createElement("TABLE");
        table.border = "1";
//Get the count of columns.
        var columnCount = customers[0].length;
//Add the header row.
        var row = table.insertRow(-1);
        for (var i = 0; i < columnCount; i++) {
            var headerCell = document.createElement("TH");
            headerCell.innerHTML = customers[0][i];
            row.appendChild(headerCell);
        }
 //Add the data rows.
        for (var i = 1; i < customers.length; i++) {
            row = table.insertRow(-1);
            for (var j = 0; j < columnCount; j++) {
                var cell = row.insertCell(-1);
                cell.innerHTML = customers[i][j];
            }
        }
 var dvTable = document.getElementById("dvTable");
        dvTable.innerHTML = "";
        dvTable.appendChild(table);
    }


</div>

<div id="Excercise" class="tabcontent">
    <h3>Excercise</h3>
    <p>Excercise for your dog is very important!</p>
    <hr>
    <p>Each and every dog needs their own unique excercise routine. Mostly bigger dogs need more walks and runs while smaller dogs are allowed to rest more.</p>
    <p>Bigger Dogs</p>
    <ul>
      <li>Five to six walks a day: after breakfast, lunch, dinner</li>
      <li>Three runs a day (playing fetch is also very good)</li>
      <li>If accessible, going swimming</li>
    </ul>
    <p>Smaller Dogs</p>
    <ul>
      <li>Two to four walks a day: after breakfast, lunch, dinner</li>
      <li>One run a day (playing fetch is also very good)</li>
      <li>If accessible, going swimming</li>
    </ul>
</div>

<div id="Dieting" class="tabcontent">
    <h3>Dieting</h3>
    <p>Your dog's diet is also very crucial.</p>
    <hr>
    <p>Each and every dog has different things it can eat. </p>
    <p>Absolutely Cannot Eat</p>
    <ul>
      <li>Chocolate</li>
      <li>Fruit</li>
    </ul>
    <p>Reccomended to Eat</p>
    <ul>
      <li>Kibble</li>
      <li>Meat</li>
      <li>Eggs</li>
    </ul>
</div>

<div id="Conditions" class="tabcontent">
    <h3>Conditions</h3>
    <p>Make sure to remember your dog's conditions and to give medicine by following instructions from the vet. </p>
</div>

<div id="Journal" class="tabcontent">
    <body> 
    <header>
      <!-- Pressing Submit will change the title of the journal to [insert name]'s Journal to make it more personal -->
      <h1 class="title" id="journal-name">My Dog's Journal</h1>
    </header>

  <!-- Create New Journal Entry Section -->
  <section class="section journal-section">
      <div class="container">
        <div class="container-row container-row-journal">
          <div class="container-item container-item-journal">
                
  <form id="entryForm" action="">

  <!-- Journal Entry Name -->
  <label for="entry-title" class="journal-label"></label>
                    <p class="description">Name Idea: Funny Event that happened today</p>
                    <input type="text" name="entry-title" id="entry-title" class="entry-text-title" placeholder="Name of entry "/>
                    
  <!-- Date -->
  <label for="entry-title" class="journal-label">Date</label>
                    <input type="text" name="entry-title" id="entry-title" class="date" placeholder="Date "/>

  <br><br>
                    
  <!-- Here's the main section of the journal, where the user writes about their dog's day for the journal -->
  <label for="entry" class="journal-label">Journal about your dog's day here...</label>
                    <textarea name="daily-entry" id="entry" class="entry-text-box" placeholder="What happened to your dog today?"></textarea>

  <!-- Here the user can enter three meals that their dog ate -->
  <label for="entry" class="journal-label">What did it eat today</label>
                    <p class="description">By putting down what they ate, you can track their diet. </p>
                    <textarea id="entry1" class="gratitude-text-box" placeholder="Breakfast"></textarea>
                    <textarea id="entry2" class="gratitude-text-box" placeholder="Lunch"></textarea>
                    <textarea id="entry3" class="gratitude-text-box" placeholder="Dinner"></textarea>

  <br><br>

  <!-- This is an API that generates a random dog fact -->
  <label for="entry" class="journal-label">Here are some dog facts!</label>
                     <button onclick="myFunction()">Click me</button>
    <p id="demo"></p>
    <script>
      function myFunction() {
        document.getElementById("demo").innerHTML = dogGen();
      }
    </script>

  <br><br><br>

  <br><br>
  <div>
  <!-- Submit button -->
  <button class="btn-main entry-submit-btn" type="submit">Submit</button>

  <!-- Here are all the journal entries that the user submitted -->
  <section class="section sectionEntryResults" id="entryResultsSection">
      <h2>Journal Entries</h2>
      <div class="container">
        <div class="container-row entryResultRow"></div>
      </div>
    </section>

  <script>
          /* eslint-disable */

      // Journal Entry Form
      // Here is getting all the variables and content from the journal entry form

      const entryForm = document.querySelector("#entryForm");
      const entryResultsSection = document.querySelector("#entryResultsSection");
      const entryResultRow = document.querySelector(".entryResultRow");

      const getEntryTitle = document.getElementsByClassName("entry-text-title");
      const getEntryText = document.getElementsByClassName("entry-text-box");
      const getEntryDate = document.getElementsByClassName("date");
      const getEntry1 = document.getElementById("entry1");
      const getEntry2 = document.getElementById("entry2");
      const getEntry3 = document.getElementById("entry3");
      const getEntryMeals = [getEntry1, getEntry2, getEntry3];


      // This adds the journal entry to the list
      function addEntryToDom(event) {
        event.preventDefault();

        const heading = document.createElement("h2");
        heading.className = "heading-results";
        entryResultRow.insertAdjacentElement("beforebegin", heading)

        // Adding Div
        const entryDiv = document.createElement("div");
        entryDiv.className = "single-entry-div";
        entryResultRow.appendChild(entryDiv);

        // Add entry title
        const entryHeading = document.createElement("h3");
        entryHeading.className = "single-entry-heading";
        entryHeading.textContent = getEntryTitle[0].value;
        entryDiv.appendChild(entryHeading);

        // Add entry date
        const entryDate = document.createElement("h4");
        entryDate.className = "single-entry-date";
        entryDate.textContent = getEntryDate[0].value;
        entryDiv.appendChild(entryDate);

        // Adding journal meal plans
        const entryMeals = document.createElement("p");
        entryMeals.className = "single-entry-date";
        entryMeals.textContent = "Meals: " + getEntryMeals[0].value + ", " + getEntryMeals[1].value + ", " + getEntryMeals[2].value;
        entryDiv.appendChild(entryMeals);

        // Adding journal body
        const entryParagraph = document.createElement("p");
        entryParagraph.className = "single-entry-text";
        entryParagraph.textContent = getEntryText[0].value;
        entryDiv.appendChild(entryParagraph);
        getEntryText[0].value = "";
        }
        

      // When the submit button is clicked, the addEntryToDom function will be executed
      entryForm.addEventListener("submit", addEntryToDom);

      // Dog Fact Generator
      function dogGen() {
          const options = {
	    method: 'GET',
	    headers: {
    		'X-RapidAPI-Key': '217acfa59emsh9a56b5c7ec9c672p11520bjsnbe23d137f1c8',
	    	'X-RapidAPI-Host': 'dogs6.p.rapidapi.com'
	    }
    };

    fetch('https://dogs6.p.rapidapi.com/facts', options)
	    .then(dogresponse => dogresponse.json())
	    .then(dogresponse => console.log(dogresponse))
	    .catch(err => console.error(err));
      }
  </script>

</div>


<script>
// Creating the tabs at the top of the site
function openCity(evt, cityName) {
  var i, tabcontent, tablinks;
  tabcontent = document.getElementsByClassName("tabcontent");
  for (i = 0; i < tabcontent.length; i++) {
    tabcontent[i].style.display = "none";
  }
  tablinks = document.getElementsByClassName("tablinks");
  for (i = 0; i < tablinks.length; i++) {
    tablinks[i].className = tablinks[i].className.replace(" active", "");
  }
  document.getElementById(cityName).style.display = "block";
  evt.currentTarget.className += " active";
}
</script>
""" database dependencies to support sqliteDB examples """
from random import randrange
from datetime import date
import os, base64
import json

from __init__ import app, db
from sqlalchemy.exc import IntegrityError
from werkzeug.security import generate_password_hash, check_password_hash


''' Tutorial: https://www.sqlalchemy.org/library.html#tutorials, try to get into Python shell and follow along '''

# Define the Post class to manage actions in 'posts' table,  with a relationship to 'users' table
class post(db.Model):
    __tablename__ = 'class'

    # Define the Notes schema
    id = db.Column(db.Integer, primary_key=True)
    note = db.Column(db.Text, unique=False, nullable=False)
    image = db.Column(db.String, unique=False)
    # Define a relationship in Notes Schema to userID who originates the note, many-to-one (many notes to one user)
    userID = db.Column(db.Integer, db.ForeignKey('class.id'))

    # Constructor of a Notes object, initializes of instance variables within object
    def __init__(self, id, note, image):
        self.userID = id
        self.note = note
        self.image = image

    # Returns a string representation of the Notes object, similar to java toString()
    # returns string
    def __repr__(self):
        return "Notes(" + str(self.id) + "," + self.note + "," + str(self.userID) + ")"

    # CRUD create, adds a new record to the Notes table
    # returns the object added or None in case of an error
    def create(self):
        try:
            # creates a Notes object from Notes(db.Model) class, passes initializers
            db.session.add(self)  # add prepares to persist person object to Notes table
            db.session.commit()  # SqlAlchemy "unit of work pattern" requires a manual commit
            return self
        except IntegrityError:
            db.session.remove()
            return None

    # CRUD read, returns dictionary representation of Notes object
    # returns dictionary
    def read(self):
        # encode image
        path = app.config['UPLOAD_FOLDER']
        file = os.path.join(path, self.image)
        file_text = open(file, 'rb')
        file_read = file_text.read()
        file_encode = base64.encodebytes(file_read)
        
        return {
            "id": self.id,
            "userID": self.userID,
            "note": self.note,
            "image": self.image,
            "base64": str(file_encode)
        }


# Define the User class to manage actions in the 'users' table
# -- Object Relational Mapping (ORM) is the key concept of SQLAlchemy
# -- a.) db.Model is like an inner layer of the onion in ORM
# -- b.) User represents data we want to store, something that is built on db.Model
# -- c.) SQLAlchemy ORM is layer on top of SQLAlchemy Core, then SQLAlchemy engine, SQL
class User(db.Model):
    __tablename__ = 'users'  # table name is plural, class name is singular

    # Define the User schema with "vars" from object
    id = db.Column(db.Integer, primary_key=True)
    _date = db.Column(db.String(255), unique=False, nullable=False)
    _time = db.Column(db.String(255), unique=True, nullable=False)
    _location = db.Column(db.String(255), unique=True, nullable=False)
    _nameOfClass = db.Column(db.String(255), unique=True, nullable=False)

    # Defines a relationship between User record and Notes table, one-to-many (one user to many notes)
    posts = db.relationship("Post", cascade='all, delete', backref='users', lazy=True)

    # constructor of a User object, initializes the instance variables within object (self)
    def __init__(self, date, time, location, nameOfClass):
        self._date = date    # variables with self prefix become part of the object, 
        self._time = time
        self._location = location
        self._nameOfClass = nameOfClass

    # a name getter method, extracts name from object
    @property
    def date(self):
        return self._date
    
    # a setter function, allows name to be updated after initial object creation
    @date.setter
    def date(self, date):
        self._date = date

    # a name getter method, extracts name from object
    @property
    def time(self):
        return self._time
    
    # a setter function, allows name to be updated after initial object creation
    @time.setter
    def time(self, time):
        self._time = time
    
    # a getter method, extracts email from object
    @property
    def location(self):
        return self._location
    
    # a setter function, allows name to be updated after initial object creation
    @location.setter
    def location(self, location):
        self._location = location
        
        # a name getter method, extracts name from object
    @property
    def nameOfClass(self):
        return self._nameOfClass
    
    # a setter function, allows name to be updated after initial object creation
    @nameOfClass.setter
    def nameOfClass(self, nameOfClass):
        self._nameOfClass = nameOfClass
    
    # output content using str(object) in human readable form, uses getter
    # output content using json dumps, this is ready for API response
    def __str__(self):
        return json.dumps(self.read())

    # CRUD create/add a new record to the table
    # returns self or None on error
    def create(self):
        try:
            # creates a person object from User(db.Model) class, passes initializers
            db.session.add(self)  # add prepares to persist person object to Users table
            db.session.commit()  # SqlAlchemy "unit of work pattern" requires a manual commit
            return self
        except IntegrityError:
            db.session.remove()
            return None

    # CRUD read converts self to dictionary
    # returns dictionary
    def read(self):
        return {
            "date": self.date,
            "time": self.time,
            "location": self.location,
            "nameOfClass": self.nameOfClass,
        }

    # CRUD update: updates user name, password, phone
    # returns self
    def update(self, date="", time="", location="", nameOfClass=""):
        """only updates values with length"""
        if len(date) > 0:
            self.date = date
        if len(time) > 0:
            self.time = time
        if len(location) > 0:
            self.location = location
        if len(nameOfClass) > 0:
            self.nameOfClass = nameOfClass
        db.session.commit()
        return self

    # CRUD delete: remove self
    # None
    def delete(self):
        db.session.delete(self)
        db.session.commit()
        return None


"""Database Creation and Testing """


# Builds working data for testing
def initUsers():
    """Create database and tables"""
    db.create_all()
    """Tester data for table"""
    u1 = User(date='2/23/23', time='10:00', location='4s Ranch', classname='Small Dogs')
    u2 = User(date='2/24/23', time='12:00', location='San Diego', classname='Medium Dogs')
    u3 = User(date='2/25/23', time='8:00', location='Poway', classname='Big Dogs')
    u4 = User(date='2/26/23', time='11:00', location='Los Angeles', classname='Large Dogs')

    users = [u1, u2, u3, u4]

    """Builds sample user/note(s) data"""
    for user in users:
        try:
            '''add a few 1 to 4 notes per user'''
            for num in range(randrange(1, 4)):
                note = "#### " + user.date + " note " + str(num) + ". \n Generated by test data."
                user.posts.append(Post(id=user.id, note=note, image='ncs_logo.png'))
            '''add user/post data to table'''
            user.create()
        except IntegrityError:
            '''fails with bad or duplicate data'''
            db.session.remove()
            print(f"Records exist, duplicate email, or error: {user.date}")