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 includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                <div class="flex h-full w-full bg-yellow-200 p-4" id="timekeeper">
  <div class="calendar bg-yellow-200 flex-grow flex flex-col">
    <div class="mb-3 flex items-center">
      <select v-model="selectedMonth" @change="fillCalendar()" class="mr-3">
        <option v-for="m in months" :value="m">{{monthNames[m]}}</option>
      </select>
      <select v-model="selectedYear" @change="fillCalendar()" class="mr-3">
        <option v-for="y in years" :value="y">{{y}}</option>
      </select>
      <div class="border border-blue-600 bg-blue-400 p-1 text-sm mr-3">Something</div>
      <div class="border border-red-700 bg-red-500 p-1 text-sm">Another Thing</div>
    </div>
    <div>    
      <div class="flex" v-if="final">
          <div v-for="c in [0,1,2,3,4,5,6]" class="flex flex-col">
            <div class="border border-orange-600 flex justify-center items-center bg-orange-400">{{ dayNames[c] }}</div>
             <div v-for="r in weekRows" class="border border-yellow-400 h-24 w-24  flex flex-col p-1 items-end" :class="getCellBgColor(getRowCellValue(r,c))">
               {{getRowCellValue(r, c) > 0 ? getRowCellValue(r, c) : '' }}
               
               <div v-if="getTimeKeepingHours(r, c) > 0" class="border border-blue-600 bg-blue-400 self-stretch text-center">{{getTimeKeepingHours(r, c)}}</div>
               <div v-if="getCaseHours(r, c) > 0" class="border border-red-700 bg-red-500 self-stretch text-center">{{getCaseHours(r, c)}}</div>
            </div>
        </div>
      </div>
    </div>
    
  </div>
</div>
              
            
!

CSS

              
                
              
            
!

JS

              
                var app = new Vue({
  el: '#timekeeper',
  data: {
    title: 'TimeKeeper',
    months: [],
    monthNames: [ "January", "February", "March", "April", "May", "June", 
                       "July", "August", "September", "October", "November", "December" ],
    dayNames: ["Sunday", "Monday", "Tuesday", "Wednesday","Thursday", "Friday", "Saturday"],
    selectedMonth: new Date().getMonth(),
    years:[],
    selectedYear: new Date().getFullYear(),
    weekDayList: {},
    results: null,
    final: [],
    remoteData: [
        {dd: 3, timekeeping: 7, cases: 3.5},
        {dd: 12, timekeeping: .5, cases: 2},
        {dd: 23, timekeeping: 4, cases: 0},
        {dd: 26, timekeeping: 0, cases: 1.5},
        {dd: 12, timekeeping: .5, cases: 2}
    ]
  },
  computed: {
    daysInMonth: function() {
      return dateFns.getDaysInMonth(new Date(this.selectedYear, this.selectedMonth));
    },
    startDate: function() {
      return new Date(this.selectedYear, this.selectedMonth, 1);
    },
    endDate: function() {
      return new Date(this.selectedYear, this.selectedMonth, this.daysInMonth);
    },
    isFirstDaySunday: function() {
      return dateFns.isSunday(this.startDate);
    },
    hasSixthWeek: function() {
      return this.final && this.final.some(rec => rec.row == 5 && rec.value > 0);
    },
    weekRows: function() {
      var arr = [0,1,2,3,4];
      if(this.hasSixthWeek) arr.push(5);
      return arr;
    }
  },
  mounted: function() {
    for(var i = 0; i < 12; i++) {
      this.months.push(i);
    }
    
    for(var i = 2005; i <= new Date().getFullYear(); i ++) {
      this.years.push(i);
    }
    
    this.fillCalendar();
  },
  methods: {
    getRowCellValue: function(row, col) {
      var vl = this.final.find(i => i.row == row && i.col == col);
      return vl ? vl.value : -1;
    },
    getTimeKeepingHours: function(row, col) {
      var dd = this.getRowCellValue(row, col);
       if(!dd || dd < 0) return 0;
      var record = this.remoteData.find(d => d.dd == dd);
      return record ? record.timekeeping : 0;
    },
    getCaseHours: function(row, col) {
      var dd = this.getRowCellValue(row, col);
      if(!dd || dd < 0) return 0;
      var record = this.remoteData.find(d => d.dd == dd);
      return record ? record.cases : 0;
    },
    getCellBgColor: function(dd) {
      return dd < 0 ? 'bg-yellow-100' : 'bg-yellow-200';
    },
    fillCalendar: function() {
      this.final = [];
       var result = new Array(6).fill(new Array(7).fill(null));
      this.weekDayList = {};
      var start = this.startDate;
      var end = this.endDate;
      var isSame = true;
      var row = 0;
      var col = 0;
      while(isSame) {
        //console.log(dateFns.format(start, 'MM/DD/YYYY') , dateFns.getDay(start))
        //start = dateFns.addDays(start, 1);
        
        var dayOfWeek = dateFns.getDay(start);
       
        for(var c = 0; c < 7; c ++) {
            if(c == dayOfWeek) { 
            result[row][c]= start.getDate();
              this.final.push({row: row, col: c, value: start.getDate()});
             //console.log(row, c, result[row][c]);
          }else {
            //this.final.push({row: row, col:c, value: -1})
          }
        }
        //row = row + 1;
        
        
        
       if(dayOfWeek == 6) { row = row + 1}
        
        
         start = dateFns.addDays(start, 1);
        
        isSame = !dateFns.isAfter(start, end);
      }
      
      //console.log(this.weekDayList); 
      console.log(this.final);
      //this.result = result;
    }
  }
})
              
            
!
999px

Console