Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WV-1959: Available layers page #9

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
progress
  • Loading branch information
jasontk19 committed Dec 13, 2021
commit 7b494e4a9127cb201071a47548bc156ba7eb6a82
6 changes: 1 addition & 5 deletions docs/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,10 @@ th {
color: #666;
}

.source-container {
margin: 5px;
padding: 10px;
}

.layer-table.docutils {
border-collapse: collapse;
width: 100%;
margin: 5px;
}
.layer-table.docutils tr td {
padding: 6px;
Expand Down
111 changes: 54 additions & 57 deletions docs/javascript/imagery-products.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,17 @@ Vue.component('layer-row', {
}
})

Vue.component('source-container', {
Vue.component('layer-table', {
props: ['layers'],
template: `
<div class="source-container">
<table class="layer-table docutils">
<thead>
<tr> <th v-for="title in columnTitles"> {{title}} </th> </tr>
</thead>
<tbody>
<layer-row v-for="layer in layers" :layer="layer"></layer-row>
</tbody>
</table>
</div>`,
<table class="layer-table docutils">
<thead>
<tr> <th v-for="title in columnTitles"> {{title}} </th> </tr>
</thead>
<tbody>
<layer-row v-for="layer in layers" :layer="layer"></layer-row>
</tbody>
</table>`,
data: function () {
return {
columnTitles: [ 'Platform', 'Instrument', 'Name / Identifier', 'Period', 'Format', 'Temporal Range', 'Product']
Expand All @@ -59,7 +57,7 @@ Vue.component('measurement-container', {
<div class="measurement-container">
<h3 v-on:click="toggleExpanded()"> {{expandSymbol}} {{ measurement.title }} </h3>
<div v-if="isExpanded">
<source-container :layers="measurement.layers"> </source-container>
<layer-table :layers="measurement.layers"> </layer-table>
</div>
</div>`,
data: function () {
Expand All @@ -76,45 +74,15 @@ Vue.component('measurement-container', {
}
})


function getMeasurementsForCategory(category, allCategories, allLayers, allMeasurements) {
const keys = allCategories[category].measurements;
const mForCategory = {}
keys.forEach(key => {
const measurement = allMeasurements[key]
measurement.layers = [];
mForCategory[key] = measurement;
});

Object.keys(allLayers).forEach(key => {
const layer = allLayers[key];
let { layergroup } = layer;
if (!layergroup) {
layergroup = 'Other';
}
if (layergroup === 'Reference') {
layergroup = 'Reference Map'
}
if (!mForCategory[layergroup]) {
console.error(layergroup);
return;
function formatLayers (layers) {
const getDate = (layer, key) => {
if (!layer[key]) {
return key === 'endDate' && layer['startDate'] ? 'Present' : '';
}
mForCategory[layergroup].layers.push(layer);
});

return Object.keys(mForCategory).map(key => mForCategory[key]);
}

function getDate (layer, key) {
if (!layer[key]) {
return key === 'endDate' && layer['startDate'] ? 'Present' : '';
const { period, inactive } = layer;
const date = period === 'subdaily' ? layer[key] : layer[key].split('T')[0];
return (key === 'endDate' && !inactive) ? 'Present' : date;
}
const { period, inactive } = layer;
const date = period === 'subdaily' ? layer[key] : layer[key].split('T')[0];
return (key === 'endDate' && !inactive) ? 'Present' : date;
}

function formatLayers (layers) {
Object.keys(layers).map(id => {
const layer = layers[id];
const projections = Object.keys(layer.projections);
Expand Down Expand Up @@ -151,9 +119,44 @@ const app = new Vue({
methods: {
selectCategory: function(event) {
const category = event.target.options[event.target.options.selectedIndex].text
this.measurements = getMeasurementsForCategory(category, this.categories, this.allLayers, this.allMeasurements);
this.measurements = this.getMeasurementsForCategory(category);
this.selectedCategory = category;
},
init: function (data) {
const { measurements, layers, categories } = data;
this.loading = false;
this.allMeasurements = measurements;
this.allLayers = formatLayers(layers);
this.categories = categories['science disciplines'];
this.measurements = this.getMeasurementsForCategory(this.selectedCategory);
},
getMeasurementsForCategory: function getMeasurementsForCategory(category) {
const keys = this.categories[category].measurements;
const mForCategory = {}
keys.forEach(key => {
const measurement = this.allMeasurements[key]
measurement.layers = [];
mForCategory[key] = measurement;
});

Object.keys(this.allLayers).forEach(key => {
const layer = this.allLayers[key];
let { layergroup } = layer;
if (!layergroup) {
layergroup = 'Other';
}
if (layergroup === 'Reference') {
layergroup = 'Reference Map'
}
if (!mForCategory[layergroup]) {
console.error(layergroup);
return;
}
mForCategory[layergroup].layers.push(layer);
});

return Object.keys(mForCategory).map(key => mForCategory[key]);
},
}
});

Expand All @@ -162,13 +165,7 @@ const requestSettings = {
type: "GET",
crossDomain: true,
dataType: "json",
success: function (data) {
app.loading = false;
app.allMeasurements = data.measurements;
app.allLayers = formatLayers(data.layers);
app.categories = data.categories['science disciplines'];
app.measurements = getMeasurementsForCategory(app.selectedCategory, app.categories, app.allLayers, app.allMeasurements)
}
success: app.init
}

$(document).ready(() => {
Expand Down