Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!-- Note stuff hidden in CodePen -->

<script src="https://kit.fontawesome.com/6873aa3c17.js" crossorigin="anonymous"></script>

  <!-- Sortable -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/Sortable/1.10.1/Sortable.min.js"></script>

<!-- Plotly -->
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>

<!-- Clocklet -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/clocklet@0.2.4/css/clocklet.min.css">
<script src="https://cdn.jsdelivr.net/npm/clocklet@0.2.4"></script>

  <!-- List with handle -->
<div id="dashboard" class="list-group">
    
    <div class="list-group-item">
      <div id='add' class='add-button'><i class="fas fa-plus fa-xs"></i></div>
      <a style="font-size: 1em; padding-left: 35px">Add Schedule</a>
    </div>
  
</div>

<div id="modal" class="modal">
  <div class="modal-content">
    <div>
      <h1 style='display: inline'>Edit Schedule</h1>
      <div class="close"><i class="fas fa-times"></i></div>
    </div>
    
    <form>
      <input id='schedule-name' type='text' value='Test'></input>
      <label for='startTime'>Start Time</label>
      <input id='startTime' class="clock" value="12:34 A.M."
             data-clocklet="class-name: clocklet-color-example; format: h:mm AA; alignment: center; placement: bottom;"
             placeholder="h:mm AA">
      <label for='endTime'>End Time</label>
      <input id='endTime' class="clock" value="1:35 P.M."
             data-clocklet="class-name: clocklet-color-example; format: h:mm AA; alignment: center; placement: bottom;"
             placeholder="h:mm AA">
      
      <div class="form-group">
        <input type="checkbox" id="Sunday" checked='true'>
        <label for="Sunday">Sunday</label>
      </div>
      <div class="form-group">
        <input type="checkbox" id="Monday">
        <label for="Monday">Monday</label>
      </div>
      <div class="form-group">
        <input type="checkbox" id="Tuesday">
        <label for="Tuesday">Tuesday</label>
      </div>
      <div class="form-group">
        <input type="checkbox" id="Wednesday">
        <label for="Wednesday">Wednesday</label>
      </div>
      <div class="form-group">
        <input type="checkbox" id="Thursday">
        <label for="Thursday">Thursday</label>
      </div>
      <div class="form-group">
        <input type="checkbox" id="Friday">
        <label for="Friday">Friday</label>
      </div>
      <div class="form-group">
        <input type="checkbox" id="Saturday">
        <label for="Saturday">Saturday</label>
      </div>
    </form>
    
    <!--  Add temperature selector => slider? -->
    <!--  Add ability to select room/zones for schedule -->
    <a id='warning' style='color: Red'></a>
    <button id='submit-schedule' class="submit-button">Create Schedule</button>
  <button id='overwrite-schedule' class="submit-buttom" style='display: none'>Overwrite Schedule</button>
    
  </div>
</div>

<div id='graph'></div>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Open+Sans:700,300);
 body {
	 background: white;
	 font-family: 'Open Sans', Helvetica, sans-serif;
	 -webkit-font-smoothing: antialiased;
	 -moz-osx-font-smoothing: grayscale;
}

.add-button {
  display: inline-block;
  height: 50px;
  width: 50px;
  color: orange;
  padding-left: 18px;
  padding-top: 10px;
  background: white;
  border: 2px solid orange;
  border-radius: 25px;
  cursor: pointer;
}

.name-font {
  font-size: 2em;
  padding-left: 35px;
}

.submit-button {
  display: inline-block;
  border: 1px solid orange;
  border-radius: 5px;
  height: 40px;
  background-color: white;
  cursor: pointer;
}

.submit-button:hover {
  background-color: #ffd796
}

.clickable {
  cursor: pointer;
}

.right-align {
  float: right;
}

/* The Modal (background) */
.modal {
  position: fixed;
  display: none;
  padding: 5% 35%;
  left: 0;
  top: 0;
  width: 100%; 
  height: 100%; 
  overflow: auto; 
  background-color: rgba(255,255,255,0.5); 
}

/* Modal Content */
.modal-content {
  padding: 20px;
  border: 2px solid orange;
  height: 525px;
  overflow: auto;
}

/* The Close Button */
.close {
  display: inline;
  color: gray;
  float: right;
}

.close:hover,
.close:focus {
  color: #000;
  text-decoration: none;
  cursor: pointer;
}

/* Checkboxes */
.form-group {
  display: block;
  margin-bottom: 5px;
}

.form-group input {
  padding: 0;
  height: initial;
  width: initial;
  margin-bottom: 0;
  display: none;
  cursor: pointer;
}

.form-group label {
  position: relative;
  cursor: pointer;
}

.form-group label:before {
  content:'';
  -webkit-appearance: none;
  background-color: transparent;
  border: 2px solid orange;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), inset 0px -15px 10px -12px rgba(0, 0, 0, 0.05);
  padding: 10px;
  display: inline-block;
  position: relative;
  vertical-align: middle;
  cursor: pointer;
  margin-right: 5px;
}

.form-group input:checked + label:after {
  content: '';
  display: block;
  position: absolute;
  top: 4px;
  left: 9px;
  width: 6px;
  height: 14px;
  border: solid orange;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* Clocklet */
 .clock {
  z-index: 10000;
  position: relative;
  left: 45%;
  top: 15%;
}

 /* minute - dial, hand, selected tick, hovered tick */
.clocklet-color-example .clocklet-plate {
  box-shadow: 1px 2px 4px 0 rgba(0, 0, 0, 0.2);
  border: 1px solid gray;
}
.clocklet-color-example[data-clocklet-placement="bottom"] {
  background-color: transparent;
  border: none;
  box-shadow: none;
}
  .clocklet-color-example .clocklet-dial--minute { background-color: orange; color: white;}
  .clocklet-color-example .clocklet-hand--minute { background-color: white; border: 1px solid gray; width: 3px;}
  .clocklet-color-example .clocklet-tick--minute.clocklet-tick--selected { background-color: white; color: orange;}
  .clocklet-color-example.clocklet--hoverable:not(.clocklet--dragging) .clocklet-tick--minute:hover { background-color: white; color: orange;}

  /* hour - dial, hand, selected tick, hovered tick */
  .clocklet-color-example .clocklet-dial--hour { background-color: white; }
  .clocklet-color-example .clocklet-hand--hour { background-color: white; border: 1px solid gray; width: 3px;}
  .clocklet-color-example .clocklet-tick--hour.clocklet-tick--selected { background-color: orange; }
  .clocklet-color-example.clocklet--hoverable:not(.clocklet--dragging) .clocklet-tick--hour:hover { background-color: orange; }

  /* hand origin */
  .clocklet-color-example .clocklet-hand-origin { background-color: gray; }

  /* ampm */
  .clocklet-color-example .clocklet-ampm::before { background-color: orange; }
  .clocklet-color-example .clocklet-ampm:hover::before { background-color: white; color: orange; border: 1px solid orange;}
  .clocklet-color-example .clocklet-ampm[data-clocklet-ampm="pm"]::before { background-color: orange; }
  .clocklet-color-example .clocklet-ampm[data-clocklet-ampm="pm"]:hover::before { background-color: white; }
              
            
!

JS

              
                // TODO: https://codereview.stackexchange.com/questions/240011/js-schedule-conflict-detection-algorithm-logic-length

// List with handle
Sortable.create(dashboard, {
  handle: '.fa-bars',
  animation: 150
});

// To Instantiate & Control the Modal 
var modal = document.getElementById("modal");
var addSchedule = document.getElementById('add');
var scheduleCount = 0;
var trackedSchedule;

addSchedule.addEventListener('click', function (event) {
  scheduleCount += 1;
  // console.log(event.target.id); // Anomoly Here
  trackedSchedule = `schedule-${scheduleCount}`;
  console.log(trackedSchedule);
  // Change modal to load with default values (prefill name with scheduleCount)
  // Change Text to Read "Create Schedule" instead of "Edit Schedule"
  modal.style.display = "block";  
});


var span = document.getElementsByClassName("close")[0];
span.onclick = function() {
  modal.style.display = "none";
  scheduleCount -= 1;
}

window.onclick = function(event) {
  if (event.target == modal) {
    modal.style.display = "none";
    scheduleCount -= 1;
  }
}

function getDate() {
  var today = new Date();
  var dd = String(today.getDate()).padStart(2, '0');
  var mm = String(today.getMonth() + 1).padStart(2, '0');
  var yyyy = today.getFullYear();
  today = `${yyyy}-${mm}-${dd}`;
  return today;
}

var savedSchedules = {};
var data = [];

var layout = {
  showlegend: false,
  xaxis: {range: ['2020-01-01 00:00:00', '2020-01-01 23:59:59'],
          showgrid: false,
          zeroline: false,
          showline: true,
          tickformat: '%H:%M:%S'
         },
  yaxis: {rangemode: 'tozero',
          range: [-0.75, 6.5],
          showline: true,
          zeroline: false,
          tickvals: [0, 1, 2, 3, 4, 5, 6],
          ticktext: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
         }
};

// To Save the Schedule Data from the Modal
var scheduleName = document.getElementById('schedule-name');
var warningMsg = document.getElementById('warning');
var saveButton = document.getElementById('submit-schedule');
var overwriteButton = document.getElementById('overwrite-schedule');
var sunday = document.getElementById('Sunday');
var monday = document.getElementById('Monday');
var tuesday = document.getElementById('Tuesday');
var wednesday = document.getElementById('Wednesday');
var thursday = document.getElementById('Thursday');
var friday = document.getElementById('Friday');
var saturday = document.getElementById('Saturday');
var daysOfWeek = {'Sunday': sunday,
                  'Monday': monday,
                  'Tuesday': tuesday,
                  'Wednesday': wednesday,
                  'Thursday': thursday,
                  'Friday': friday,
                  'Saturday': saturday}
var startTime;
var endTime;

document.getElementById('startTime').addEventListener("input", function (event) {
      startTime = event.target.value;
});

document.getElementById('endTime').addEventListener("input", function (event) {
      endTime = event.target.value;
});


function editSchedule(event) {
  console.log(event.target.id);
  // Init Modal from saved dict
  schedule = savedSchedules[event.target.id];
  Object.entries(schedule).forEach(function([key, value]) {
    if (value) {
      if (key != 'Name') {
         var day = document.getElementById(key);
         day.checked = true;
      }
      else {
        scheduleName.value = value;
      }
      var startTime_ = document.getElementById('startTime');
      var endTime_ = document.getElementById('endTime');
      startTime_.value = value.StartTime;
      endTime_.value = value.EndTime;
    }
  });
  modal.style.display = 'block';
};

// Need to validate logical comparators for provided time format?
function checkForConflict(c1s, c1e, c2s, c2e) { // case 1 start time, case 1 end time, case 2 start time, case 2 end time
  // if (c1 intersects c2) or (c2 intersects c1) or (c2 contained in c1) or (c1 contained in c2) or (anything else?)
  if ( (c1s >= c2s && c1e >= c2s) || (c1s <= c2s && c1e <= c2e) || (c1s <= c2s && c1e >= c2e) || (c1s >= c2s && c1e <= c2e) ) {
    return true;
  } else {return false};
}

saveButton.onclick = function() {
  // Disable save if not all reqd fields filled -> https://stackoverflow.com/questions/39880389/disable-button-until-fields-are-full-pure-js
  // while (!scheduleName || !startTime || !endTime || !(sunday.checked&&monday.checked&&tuesday.checked&&wednesday.checked&&thursday.checked&&friday.checked&&saturday.checked)) {
  //     saveButton.disabled = true;
  //   } 
  
  // Check that fields are filled
  if (!scheduleName || !startTime || !endTime || !sunday.checked&&!monday.checked&&!tuesday.checked&&!wednesday.checked&&!thursday.checked&&!friday.checked&&!saturday.checked) {
    warningMsg.textContent = "All required fields must contain data";
  } 
  
  // Try to Save the Schedule
  else {           
    // Check for Schedule Conflicts
    var conflictData;
    if (savedSchedules && Object.keys(savedSchedules).length >= 1) {
        console.log("At least one schedule detected");
        // Loop through saved schedules (key = 'schedule-x')
        Object.entries(savedSchedules).forEach(function([key, value]) {
          schedule_ = savedSchedules[key];
          // Loop through the schedule (key_ = 'Name', 'Sunday', ...)
          Object.entries(schedule_).forEach(function([key_, value_]) {
            // Only check if weekday has a time value and weekdays that are selected
            if (key_ != 'Name' && value_ && daysOfWeek[key_].checked) { 
                // if there is conflict -> store to variable
                var conflict = checkForConflict(value_.StartTime, value_.EndTime, startTime, endTime);
                if (conflict) {
                  console.log('Conflict Detected');
                  conflictData = [key_, `Start: ${value_.StartTime}/${startTime}`, `End: ${value_.EndTime}/${endTime}`];
                }
            }
          });
        });
    }
    // Alert User of Conflict
    if (conflictData) {
      console.log(conflictData);
      warningMsg.textContent = `There is a scheduling conflict ${conflictData}`;
      overwriteButton.style.display = 'block';
      // Handle Conflict Resolution -> Overwrite Schedule, etc
    } 
    
    // Save the Schedule
    else {
      var dict = {
        Name: scheduleName.value,
        Sunday: sunday.checked && startTime && endTime ? {StartTime: startTime, EndTime: endTime} : null,  
        Monday: monday.checked && startTime && endTime ? {StartTime: startTime, EndTime: endTime} : null,
        Tuesday: tuesday.checked && startTime && endTime ? {StartTime: startTime, EndTime: endTime} : null,
        Wednesday: wednesday.checked && startTime && endTime ? {StartTime: startTime, EndTime: endTime} : null,
        Thursday: thursday.checked && startTime && endTime ? {StartTime: startTime, EndTime: endTime} : null,
        Friday: friday.checked && startTime && endTime ? {StartTime: startTime, EndTime: endTime} : null,
        Saturday: saturday.checked && startTime && endTime ? {StartTime: startTime, EndTime: endTime} : null,
      }

      savedSchedules[trackedSchedule] = dict;
      console.log(savedSchedules);

      // Add to the graph
      var randomColor = Math.floor(Math.random()*16777215).toString(16); // Make color indicative of temperature
      Object.entries(dict).forEach(function([key, value]) {
        if (key != 'Name' && value) {

          data.push({
            x: [`${getDate()} ${value.StartTime}`, `${getDate()} ${value.EndTime}`], 
            y: [key, key], 
            hovertext: dict.Name,
            type: 'scatter',
            mode: 'markers',
            marker: {
              size: 30,
              color: [randomColor, randomColor],
            }
          });

          data.push({
            x: [`${getDate()} ${value.StartTime}`, `${getDate()} ${value.EndTime}`], 
            y: [key, key], 
            hovertext: scheduleName.value,
            type: 'scatter',
            mode: "lines",
            line: {
              width: 30,
              color: randomColor,
            },
          });

        };
      });

      Plotly.newPlot('graph', data, layout);


      // Create the Dashboard Entry
      var newLine = document.createElement('div');
      newLine.classList.add('list-group-item');
      var newButton = document.createElement('div');
      newButton.classList.add('add-button');
      newButton.id = trackedSchedule;
      newButton.addEventListener('click', editSchedule);    
      var newTemp = document.createElement('a');
      var newName = document.createElement('a');
      newName.textContent = scheduleName.value;
      newName.classList.add('name-font');
      var newWeekSet = document.createElement('div');
      newWeekSet.classList.add('right-align');
      Object.entries(dict).forEach(function([key, value]) {
        if (key != 'Name') {
           var newDay = document.createElement('label')
           // newDay.classList.add('day-font');
           newDay.style.display = 'inline-block';
           newDay.style.margin = '5px';
           newDay.style.fontStyle = 'italic';
           var newDayIcon;
           newDay.textContent = key.charAt(0);
           if (value) {
             newDayIcon = document.createElement('i');
             newDayIcon.classList.add('far', 'fa-check-circle', 'fa-xs');
             // Why doesn't class work for this?
             newDayIcon.style.display = 'block';
             newDayIcon.style.color = 'Blue';
           } 
           else {
             newDayIcon = document.createElement('i');
             newDayIcon.classList.add('far', 'fa-times-circle', 'fa-xs');
             // Why doesn't class work for this?
             newDayIcon.style.display = 'block';
             newDayIcon.style.color = 'Orange';
           }
           newDay.append(newDayIcon);
           newWeekSet.appendChild(newDay);
        };
      });
      var newMoveIcon = document.createElement('i');
      newMoveIcon.classList.add('fas', 'fa-bars');
      newMoveIcon.style.display = 'inline-block';
      newMoveIcon.style.paddingTop = '10px';
      newMoveIcon.style.paddingLeft = '20px'

      newLine.appendChild(newButton);
      newLine.appendChild(newName);
      newLine.appendChild(newWeekSet);
      newWeekSet.appendChild(newMoveIcon);
      dashboard.appendChild(newLine);

      modal.style.display = "none";
    }
  }
}

              
            
!
999px

Console