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 id="app" class="p-4 text-gray-900 text-lg">
  <h1 class="text-2xl font-bold">NASA Facilities</h1>
  <div class="mt-4">
    <div class="py-2 font-bold">
      Filter by:  
    </div>
    
    <div class="flex">
      <div class="">
        <label for="#stateFilter">
          State:
        </label>
        <select id="stateFilter" v-model="stateFilter" :class="selectClasses">
          <option :value="null">-</option>
          <option :value="state" v-for="state in availableStates">
            {{ state }}
          </option>
        </select>
      </div>
      
      <div class="ml-8">
        <label for="#cityFilter">
          City:
        </label>
        <select id="cityFilter" v-model="cityFilter" :class="selectClasses">
          <option :value="null">-</option>
          <option :value="city" v-for="city in availableCities">
            {{ city }}
          </option>
        </select>
      </div>
      <div class="ml-8 flex items-center">
        <label for="#date">
          Date from:
        </label>
        <vuejs-datepicker 
          id="date" 
          :class="selectClasses" 
          v-model="dateFrom" 
          clear-button="true"></vuejs-datepicker>
      </div>
      
      <div class="ml-8 flex items-center">
        <label for="#date">
          Date to:
        </label>
        
       <vuejs-datepicker 
         id="date" 
         :class="selectClasses" 
         v-model="dateTo" 
         clear-button="true"></vuejs-datepicker>
      </div>
    </div>
  </div> 
  
<div class="mt-8 text-base">
  {{ count }} entries
</div>
  
<table class="mt-4 w-full">
  <thead class="border-b border-b-gray-500">
    <tr>
      <th 
          @click="onSortClick(header.value)" 
          class="text-left cursor-pointer hover:text-blue-500" 
          v-for="header in headers"
      >
        {{header.label}}
        <div  
          v-if="header.value == orderBy"
          class="transform inline-block"
          :class="{ 'rotate-180': orderDirection == 'asc'}"
        >^</div>
      </th>
      <th class="text-left">
        Long / Lat
      </th
    </tr>
  </thead>
  <tbody>
    <tr v-for="entry in filteredData" :key="entry" class="hover:bg-gray-100">
      <td class="py-2">{{ entry.center }}</td>
      <td>{{ entry.city }}</td>
      <td>{{ entry.state }}</td>
      <td>{{ entry.country }}</td>
      <td>{{ entry.occupied | formatDate }}</td>
      <td>{{ entry.location.longitude}} / {{ entry.location.latitude}}
    </tr>
  </tbody>
</table>
</div>
              
            
!

CSS

              
                
              
            
!

JS

              
                const API = "https://data.nasa.gov/resource/gvk9-iz74.json";

new Vue({
  el: '#app',
  components: {
  	vuejsDatepicker
  },
  data() {
    return {
      selectClasses: "border border-coolGray-300 px-4 py-2 ml-4",
      datePickerOptions: {
        clearButton: true 
      },
      headers: [
        {value: 'center', label: 'Name'},
        {value: 'city', label: 'City'},
        {value: 'state', label: 'State'},
        {value: 'country', label: 'Country'},
        {value: 'occupied', label: 'Occupied'},
      ],
      data: null,
      orderBy: null,
      orderDirection: null,
      stateFilter: null,
      cityFilter: null,
      dateFrom: null,
      dateTo: null
    }
  },
  computed: {
    sortFunc() {
      const extractor = R.prop(this.orderBy)
      const comparator = R.comparator(this.orderDirection == 'asc' ? R.gte: R.lte);
      // apply extractor to the arguments of comparator
      const dataSorter = R.sort(R.useWith(comparator, [extractor, extractor]));
      
      return dataSorter;
    },
    
    alternativeSortFunc() {
      const dataSorter = R.sortBy(R.prop(this.orderBy));
      return R.compose(this.orderDirection == 'desc' ? R.reverse : R.identity, dataSorter);
    },

    filteredData() {
      const filterByStateFunc = this.createFilter(
        this.stateFilter, 'state', R.equals(this.stateFilter))
      
      const filterByCityFunc = this.createFilter(
        this.cityFilter, 'city', R.equals(this.cityFilter))
      
      const mkDate = (string) => { return new Date(string) }
      const filterByDateFromFunc = this.createFilter(
        this.dateFrom,
        'occupied',
        // This will check, whether the dateFrom is less or equal than the 
        // 'occupied' field of the data. In order for it
        // to work, we convert the 'occupied' field to a Date with
        // `mkDate`
        R.useWith(R.lte, [R.identity, mkDate])(this.dateFrom)
      )
      
      const filterByDateToFunc = this.createFilter(
        this.dateTo,
        'occupied',
        // this will check, whether the dateTo is greater or equal
        // than the 'occupied' field of the data. In order for it
        // to work, we convert the 'occupied' field to a Date with
        // `mkDate`
        R.useWith(R.gte, [R.identity, mkDate])(this.dateTo)
      )
      
      return R.compose(
        this.sortFunc,
        filterByDateFromFunc,
        filterByDateToFunc,
        filterByStateFunc,
        filterByCityFunc
      )(this.data || []);
    },
    availableStates() {
      return this.extractValues('state')
    },
    availableCities() {
      return this.extractValues('city')
    },
    count () {
      return this.filteredData.length    
    }
  },
  async mounted() {
    const response = await fetch(API);
    const entries = await response.json();
    this.data = entries;
  },
  methods: {
    extractValues(propName) {
      const extract =  R.compose(
        R.sort((a, b) => a > b),
        R.uniq,
        R.reject(R.isNil),
        R.map(R.prop(propName)))
      
      return extract(this.data || [])
    }, 
    onSortClick(value) {
      const previousOrderBy = this.orderBy;
      this.orderBy = value;
      
      // flip ordering if we clicked on the header which we already order by
      if (previousOrderBy == value) {
        this.orderDirection = this.orderDirection == 'desc' ? 'asc' : 'desc' 
      }
    },
    createFilter(filterValue, propertyName, comparisonFunc) {
      if (filterValue) {
        return R.filter(R.where({[propertyName]: comparisonFunc}))
      } else {
        return R.identity
      }
    },
  },
  filters: {
    formatDate(value) {
      return new Date(value).toLocaleDateString() 
    }
  }
})
              
            
!
999px

Console