# Path: BAC0/web/templates.py
# def create_sidebar(dash_class="", devices_class="", trends_class=""):
#     sb = """
#     <div class="wrapper">
#     <div class="sidebar" data-background-color="white" data-active-color="danger">
#     <!--
#     Tip 1: you can change the color of the sidebar's background using: data-background-color="white | black"
#     Tip 2: you can change the color of the active button using the data-active-color="primary | info | success | warning | danger"
#     -->
#     <div class="sidebar-wrapper">
#       <div class="logo">
#       <a href="https://github.com/ChristianTremblay/BAC0" class="simple-text">BAC0</a>
#       </div>
#       <ul class="nav">
#         <li {}><a href="/">
#                <i class="ti-panel"></i>
#                <p>Dashboard</p>
#                </a>
#         </li>
#         <li {}><a href="/trends">
#                <i class="ti-panel"></i>
#                <p>Trend</p>
#                </a>
#         </li>
#         <li {}><a href="/dash_devices">
#                <i class="ti-view-list-alt"></i>
#                <p>Devices</p>
#                </a>
#         </li>
#       </ul>
#       </div>
#     </div>
#     """.format(
#         dash_class, trends_class, devices_class
#     )
#     return sb
# 
# def create_card(
#     icon="ti-server",
#     title="title",
#     data="None",
#     id_data="generic_data",
#     foot_icon="ti-reload",
#     foot_data="None",
#     id_foot_data="generic_foot_data",
# ):
#     card = """
#         <div class="col-lg-3 col-sm-6">
#         <div class="card">
#           <div class="content">
#             <div class="row">
#               <div class="col-xs-5">
#                 <div class="icon-big icon-success text-center">
#                   <i class="{}"></i>
#                 </div>
#               </div>
#                 <div class="col-xs-7">
#                   <div class="numbers">
#                     <p>{}</p>
#                     <div id="{}">{}</div>
#                   </div>
#                 </div>
#               </div>
#             <div class="footer">
#             <hr />
#             <div class="stats">
#             <i class="{}"></i> <div id="{}">{}</div>
#             </div>
#             </div>
#             </div>
#         </div>
#         </div>
#         """.format(
#         icon, title, id_data, data, foot_icon, id_foot_data, foot_data
#     )
#     return card
# 
# def update_notifications(log, new_msg):
#     notif_log = log
#     max_notifications = 5
#     if new_msg:
#         notif_log.insert(0, new_msg)
#     if len(notif_log) > max_notifications:
#         notif_log.pop()
# 
#     notif_list = '<ul class="dropdown-menu">'
#     for notif in notif_log:
#         notif_list += '<li><a href="#">' + notif + "</a></li>"
#     if len(notif_log) == 0:
#         notif_list += '<li><a href="#">Nothing yet</a></li>'
#     notif_list += "</ul>"
#     return notif_list


from threading import Thread
from flask import Flask, render_template, jsonify, request
from flask_bootstrap import Bootstrap
from bokeh.embed import server_document
from .templates import create_sidebar, create_card, update_notifications
from flask.logging import default_handler
import weakref
import logging
import json

            else:
                script = "<div>No devices registered yet...</div>"
            return render_template(
                "trends.html",
                sidebar=create_sidebar(trends_class='class="active"'),
                bokeh_script=script,
                template="Flask",
            )

        #        @self.flask_app.route('/devices', methods=['GET'])
        #        def bkapp_devices_page():
        #            script = server_document('http://localhost:5006/devices')
        #            return render_template("embed.html", script=script, template="Flask")

        @self.flask_app.route("/notes", methods=["GET"])
        def bkapp_notes_page():
            script = server_document("http://{}:5006/notes".format(self.ip))
            return render_template("embed.html", script=script, template="Flask")

        @self.flask_app.route("/", methods=["GET"])
        def home_page():
            # Stat number of devices
            cnod = create_card(
                icon="ti-server",
                title="Number of devices",
                data=self.network.number_of_devices,
                id_data="devices",
                foot_icon="ti-reload",
                foot_data="Refresh to update",
            )

# Path: BAC0/web/templates.py
# def create_sidebar(dash_class="", devices_class="", trends_class=""):
#     sb = """
#     <div class="wrapper">
#     <div class="sidebar" data-background-color="white" data-active-color="danger">
#     <!--
#     Tip 1: you can change the color of the sidebar's background using: data-background-color="white | black"
#     Tip 2: you can change the color of the active button using the data-active-color="primary | info | success | warning | danger"
#     -->
#     <div class="sidebar-wrapper">
#       <div class="logo">
#       <a href="https://github.com/ChristianTremblay/BAC0" class="simple-text">BAC0</a>
#       </div>
#       <ul class="nav">
#         <li {}><a href="/">
#                <i class="ti-panel"></i>
#                <p>Dashboard</p>
#                </a>
#         </li>
#         <li {}><a href="/trends">
#                <i class="ti-panel"></i>
#                <p>Trend</p>
#                </a>
#         </li>
#         <li {}><a href="/dash_devices">
#                <i class="ti-view-list-alt"></i>
#                <p>Devices</p>
#                </a>
#         </li>
#       </ul>
#       </div>
#     </div>
#     """.format(
#         dash_class, trends_class, devices_class
#     )
#     return sb
# 
# def create_card(
#     icon="ti-server",
#     title="title",
#     data="None",
#     id_data="generic_data",
#     foot_icon="ti-reload",
#     foot_data="None",
#     id_foot_data="generic_foot_data",
# ):
#     card = """
#         <div class="col-lg-3 col-sm-6">
#         <div class="card">
#           <div class="content">
#             <div class="row">
#               <div class="col-xs-5">
#                 <div class="icon-big icon-success text-center">
#                   <i class="{}"></i>
#                 </div>
#               </div>
#                 <div class="col-xs-7">
#                   <div class="numbers">
#                     <p>{}</p>
#                     <div id="{}">{}</div>
#                   </div>
#                 </div>
#               </div>
#             <div class="footer">
#             <hr />
#             <div class="stats">
#             <i class="{}"></i> <div id="{}">{}</div>
#             </div>
#             </div>
#             </div>
#         </div>
#         </div>
#         """.format(
#         icon, title, id_data, data, foot_icon, id_foot_data, foot_data
#     )
#     return card
# 
# def update_notifications(log, new_msg):
#     notif_log = log
#     max_notifications = 5
#     if new_msg:
#         notif_log.insert(0, new_msg)
#     if len(notif_log) > max_notifications:
#         notif_log.pop()
# 
#     notif_list = '<ul class="dropdown-menu">'
#     for notif in notif_log:
#         notif_list += '<li><a href="#">' + notif + "</a></li>"
#     if len(notif_log) == 0:
#         notif_list += '<li><a href="#">Nothing yet</a></li>'
#     notif_list += "</ul>"
#     return notif_list


# Path: BAC0/web/FlaskServer.py
from threading import Thread
from flask import Flask, render_template, jsonify, request
from flask_bootstrap import Bootstrap
from bokeh.embed import server_document
from .templates import create_sidebar, create_card, update_notifications
from flask.logging import default_handler
import weakref
import logging
import json

            else:
                script = "<div>No devices registered yet...</div>"
            return render_template(
                "trends.html",
                sidebar=create_sidebar(trends_class='class="active"'),
                bokeh_script=script,
                template="Flask",
            )

        #        @self.flask_app.route('/devices', methods=['GET'])
        #        def bkapp_devices_page():
        #            script = server_document('http://localhost:5006/devices')
        #            return render_template("embed.html", script=script, template="Flask")

        @self.flask_app.route("/notes", methods=["GET"])
        def bkapp_notes_page():
            script = server_document("http://{}:5006/notes".format(self.ip))
            return render_template("embed.html", script=script, template="Flask")

        @self.flask_app.route("/", methods=["GET"])
        def home_page():
            # Stat number of devices
            cnod = create_card(
                icon="ti-server",
                title="Number of devices",
                data=self.network.number_of_devices,
                id_data="devices",
                foot_icon="ti-reload",
                foot_data="Refresh to update",
            )

            cnot = create_card(
