(function () {
    "use strict";

    var gpii = fluid.registerNamespace("gpii");

    fluid.defaults("gpii.nexusScienceLabTable", {
        gradeNames: ["gpii.nexusWebSocketBoundComponent", "fluid.viewComponent"],
        numberLocale: "en",
        maximumFractionDigits: 2,
        members: {
            nexusPeerComponentPath: "scienceLabCollector",
            nexusBoundModelPath: "sensors",
            receivesChangesFromNexus: true,
            sendsChangesToNexus: false
        },
        strings: {
            noSensorsConnected: "No sensors connected"
        },
        modelListeners: {
            sensors: {
                funcName: "gpii.nexusScienceLabTable.updateTable",
                args: [
                    "{that}.container",
                    "{that}.options.numberLocale",
                    "{that}.options.maximumFractionDigits",
                    "{that}.options.strings.noSensorsConnected",
                    "{change}.value"
                ]
            }
        }
    });

    // TODO: Don't rebuild the table for every update:
    //       If a value is in the table, update it
    //       If a value is not in the table, add it at the appropriate column
    //       If a column is in the table but not in the data, remove it

    gpii.nexusScienceLabTable.updateTable = function (container, numberLocale, maximumFractionDigits, noSensorsConnectedMessage, sensors) {
        var sensorsArray = fluid.hashToArray(
            sensors,
            "sensor"
        );

        if (sensorsArray.length === 0) {
            container.html(fluid.stringTemplate("<p>%message</p>", {
                message: noSensorsConnectedMessage
            }));
        } else {
            fluid.stableSort(sensorsArray, function (a, b) {
                return a.name.localeCompare(b.name);
            });

            container.html("<table><thead><tr class='flc-nexus-science-lab-table-head'></tr></thead><tbody><tr class='flc-nexus-science-lab-table-body'></tr></tbody></table>");
            var tableHead = container.find(".flc-nexus-science-lab-table-head");
            var tableBody = container.find(".flc-nexus-science-lab-table-body");

            fluid.each(sensorsArray, function (sensor) {
                tableHead.append(gpii.nexusScienceLabTable.buildTableHeading(sensor));
                tableBody.append(fluid.stringTemplate("<td>%sensorValue</td>", {
                    sensorValue: sensor.value.toLocaleString(numberLocale, {
                        maximumFractionDigits: maximumFractionDigits
                    })
                }));
            });
        }
    };

    gpii.nexusScienceLabTable.buildTableHeading = function (sensorData) {
        if (sensorData.units) {
            return fluid.stringTemplate("<th>%sensorName (%units)</th>", {
                sensorName: sensorData.name,
                units: sensorData.units
            });
        } else {
            return fluid.stringTemplate("<th>%sensorName</th>", {
                sensorName: sensorData.name
            });
        }
    };

}());

@@ -72,24 +72,60 @@
 e(%22gpii%22);%0A%0A
+    // TODO: Rename to %22Dashboard%22%0A%0A
     fluid.de
@@ -1047,24 +1047,182 @@
  %7D%0A    %7D);%0A%0A
+    // TODO: Change from a table to headings and paragraphs for values%0A    // TODO: Include a hidden h1 %22Dashboard%22%0A    // TODO: Use h2s for the sensor names%0A
     // TODO:
@@ -1240,21 +1240,23 @@
 ild the 
-table
+content
  for eve
@@ -1268,17 +1268,16 @@
 date
-:
 %0A    // 
     
@@ -1264,37 +1264,37 @@
 y update%0A    // 
-     
+TODO:
  If a value is i
@@ -1292,28 +1292,23 @@
 alue is 
-in the table
+present
 , update
@@ -1314,29 +1314,29 @@
 e it%0A    // 
-     
+TODO:
  If a value 
@@ -1342,28 +1342,23 @@
  is not 
-in the table
+present
 , add it
@@ -1377,21 +1377,23 @@
 opriate 
-colum
+positio
 n%0A    //
@@ -1397,40 +1397,38 @@
  // 
-     
+TODO:
  If a 
-column
+value
  is 
-i
+o
 n the 
-tabl
+pag
 e bu
@@ -1440,16 +1440,23 @@
  in the 
+latest 
 data, re

Add some TODOs