IEEE.org     |     IEEE Xplore Digital Library     |     IEEE Standards     |     IEEE Spectrum     |     More Sites

Unverified Commit 3e8654bb authored by Anthony Palumbo's avatar Anthony Palumbo Committed by GitHub
Browse files

Removing hardcoded values from last team's LWC (#102)

parent e87eda97
......@@ -2,6 +2,7 @@
* Maps Project related requests to the correct database function and returns a response.
*/
const db = require('../db');
const projectsDb = require('../db/projects.db');
/**
......@@ -61,8 +62,26 @@ const update = async (req, res, next) => {
}
};
/**
* Gets all the projects from the database.
* @param {*} req - the request
* @param {*} res - the response
* @param {*} next - the next middleware function
*/
const getAllProjects = async (req, res, next) => {
const predicates = req.query;
try {
const projects = await db.projects.findAllProjects(predicates);
res.json(projects);
} catch (e) {
next(e);
}
};
module.exports = {
find,
create,
update
update,
getAllProjects
};
const db = require('../db');
/**
* Gets all the sponsors from the database.
* @param {*} req - the request
* @param {*} res - the response
* @param {*} next - the next middleware function
*/
const getSponsors = async (req, res, next) => {
const predicates = req.query;
try {
const sponsors = await db.sponsors.findSponsors(predicates);
res.json(sponsors);
} catch (e) {
next(e);
}
};
module.exports = {
getSponsors
};
......@@ -153,8 +153,25 @@ const update = async (projectId, project) => {
}
};
/**
* Query to find all projects.
*/
const findAllProjects = async () => {
let query = `
SELECT
id,
name
FROM
project
ORDER BY id
`;
return global.dbPool.query(query);
};
module.exports = {
find,
create,
update
update,
findAllProjects
};
// const utils = require('../utils');
/**
* Query to find all sponsors.
*/
const findSponsors = async () => {
let query = `
SELECT
id,
name
FROM
sponsor
ORDER BY id
`;
return global.dbPool.query(query);
};
module.exports = {
findSponsors
};
......@@ -13,7 +13,8 @@ const {
dataTypes,
geometrySearch,
projects,
temporal
temporal,
sponsors
} = require('../controllers');
// Geometry Searches
......@@ -123,4 +124,7 @@ router.put(
projects.update
);
// router.get('/sponsors', sponsors.getSponsors);
// router.get('/all_projects', projects.getAllProjects);
module.exports = router;
......@@ -3,11 +3,13 @@ import bboxAssets from './bboxAssetsController';
import dataTypes from './dataTypesController';
import assetDefinitions from './assetDefinitionsController';
import projects from './projectsController';
import sponsors from './sponsorsController';
export {
assets,
assetDefinitions,
bboxAssets,
dataTypes,
projects
projects,
sponsors
};
......@@ -61,9 +61,18 @@ const update = (id, project) => {
const updateURL = new URL(PROJECTS_URL + `/${id}`);
return utils.put(updateURL.href, {'project': project});
};
/**
* Finds all projects.
*/
const fetchAllProjects = () => {
const url = utils.URL + 'all_projects';
return utils.get(url);
};
export default {
find,
create,
update
update,
fetchAllProjects
};
import utils from 'c/utils';
/**
* Finds all sponsors.
*/
const fetchSponsors = () => {
const url = utils.URL + 'sponsors';
return utils.get(url);
};
export default {
fetchSponsors
};
<template>
<lightning-card>
<lightning-card title="Asset Filters">
<div class="slds-p-around_x-large">
<h1 class="slds-text-heading_large">{state.title}</h1>
<lightning-combobox
options={sponsors}
options={all_sponsors}
value={sponsor}
onchange={handleSponsorChange}
placeholder={sponsor}
label="Sponsor"
></lightning-combobox>
<lightning-badge label="Sponsor"></lightning-badge>
<br/>
<lightning-combobox
options={projects}
options={all_projects}
value={project}
onchange={handleProjectChange}
placeholder={project}
label="Project"
></lightning-combobox>
<lightning-badge label="Project"></lightning-badge>
<br/>
<lightning-combobox
options={assets}
value={asset}
onchange={handleAssetChange}
placeholder={asset}
label="Asset Type"
></lightning-combobox>
<lightning-badge label="Asset"></lightning-badge>
</div>
</lightning-card>
</template>
......@@ -2,126 +2,101 @@ import { LightningElement, wire, track } from 'lwc';
//import { assets } from 'c/controllers';
import { CurrentPageReference } from 'lightning/navigation';
import { fireEvent } from 'c/pubsub';
import { assetDefinitions, sponsors, projects } from 'c/controllers';
export default class App extends LightningElement {
@wire(CurrentPageReference) pageRef;
@track
state = {
title: 'Select Asset Type'
};
export default class SelectAsset extends LightningElement {
@wire(CurrentPageReference) pageRef;
@track
sponsor;
@track asset = 'Select an asset type...';
@track assets;
@track sponsor = 'Select a sponsor...';
@track all_sponsors;
@track project = 'Select a project...';
@track all_projects;
get sponsors() {
var ret = [];
@track
state = {
title: 'Asset Filters'
};
ret.push({
label: 'Default: Any',
value: '0'
});
/**
* Sets the combobox options.
*/
connectedCallback() {
var i, j, l;
ret.push({
label: 'Seneca Park Zoo',
value: '1'
});
if (ret.sizeOf === 0) {
return [
{
label: 'Default: Any',
value: '0'
}
];
}
return ret;
}
@track
project;
get projects() {
var ret = []; //Set Up Return
assetDefinitions.fetchAssetTypes()
.then(data => {
var temp_assets = [];
for (i = 0; i < data.rows.length; i++) {
temp_assets.push({
'label': data.rows[i]['name'] + ': ' + data.rows[i]['id'],
'value': data.rows[i]['name'] + ': ' + data.rows[i]['id']
});
}
this.assets = temp_assets;
})
.catch(e => {
console.log('Exception: ', e);
});
//Push all projects to return
ret.push({
label: 'Default: Any',
value: '0'
});
ret.push({
label: 'Madagascar Lemur Conservation',
value: '1'
});
ret.push({
label: 'Madagascar Reforesting',
value: '2'
});
ret.push({
label: 'African Elephant Conservation',
value: '3'
});
if (ret.sizeOf === 0) {
return [
{
label: 'Default: Any',
value: '0'
}
];
}
return ret;
}
@track
asset;
get assets() {
var ret = [];
// sponsors.fetchSponsors()
// .then(data => {
// var temp_sponsors = [];
// for (j = 0; j < data.rows.length; j++) {
// temp_sponsors.push({
// 'label': data.rows[i]['name'] + ': ' + data.rows[i]['id'],
// 'value': data.rows[i]['name'] + ': ' + data.rows[i]['id']
// });
// }
// this.all_sponsors = temp_sponsors;
// })
// .catch(e => {
// console.log('Exception: ', e);
// });
ret.push({
label: 'Default: Any',
value: '0'
});
ret.push({
label: 'Ring Tailed Lemur',
value: '1'
});
ret.push({
label: 'Brown Mouse Lemur',
value: '2'
});
ret.push({
label: 'Silky Sifaka',
value: '3'
});
ret.push({
label: 'Tree',
value: '4'
});
ret.push({
label: 'Elephant',
value: '5'
});
ret.push({
label: 'Baobab',
value: '6'
});
if (ret.sizeOf === 0) {
return [
{
label: 'Default: Any',
value: ''
}
];
}
return ret;
}
handleSponsorChange(event) {
this.sponsor = event.detail.value;
fireEvent(this.pageRef, 'selectedSponsor', this.sponsor);
}
handleProjectChange(event) {
this.project = event.detail.value;
fireEvent(this.pageRef, 'selectedProject', this.project);
}
handleAssetChange(event) {
this.asset = event.detail.value;
fireEvent(this.pageRef, 'selectedAsset', this.asset);
}
this.all_sponsors = [
{
'label': 'Seneca Park Zoo Society: 1',
'value': 'Seneca Park Zoo Society: 1'
}
];
this.all_projects = [
{
'label': 'Madagascar Reforestation: 1',
'value': 'Madagascar Reforestation: 1'
}
];
// projects.fetchAllProjects()
// .then(data => {
// var temp_projects = [];
// for (l = 0; l < data.rows.length; l++) {
// temp_projects.push({
// 'label': data.rows[i]['name'] + ': ' + data.rows[i]['id'],
// 'value': data.rows[i]['name'] + ': ' + data.rows[i]['id']
// });
// }
// this.all_projects = temp_projects;
// })
// .catch(e => {
// console.log('Exception: ', e);
// });
}
handleSponsorChange(event) {
this.sponsor = event.detail.value;
fireEvent(this.pageRef, 'selectedSponsor', event.detail.value.split(':')[1].trimLeft());
}
handleProjectChange(event) {
this.project = event.detail.value;
fireEvent(this.pageRef, 'selectedProject', event.detail.value.split(':')[1].trimLeft());
}
handleAssetChange(event) {
this.asset = event.detail.value;
fireEvent(this.pageRef, 'selectedAsset', event.detail.value.split(':')[1].trimLeft());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment