Skip to content

Commit

Permalink
Move species search to app.
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-fox committed Apr 4, 2024
1 parent 54cb1e7 commit b8f780e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 31 deletions.
39 changes: 15 additions & 24 deletions app/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,60 +52,51 @@ router.get('/', async function (req, res) {

const headers = ngsiLD.setHeaders(req.session.access_token, LinkHeader);

const buildings =
await ngsiLD.listEntities(
const buildings = await ngsiLD.listEntities(
{
type: 'Building',
options: 'keyValues',
options: 'concise',
attrs: 'name',
limit: 200
},
headers
);
const pigs =
await ngsiLD.listEntities(
const animals = await ngsiLD.listEntities(
{
type: 'Animal',
options: 'keyValues',
q: 'species=="pig"',
options: 'concise',
attrs: 'name,species',
limit: 200
},
headers
);
const cows =
await ngsiLD.listEntities(
{
type: 'Animal',
q: 'species=="dairy cattle"',
options: 'keyValues',
attrs: 'name,species',
limit: 200
},
headers
);
const parcels =
await ngsiLD.listEntities(
const parcels = await ngsiLD.listEntities(
{
type: 'AgriParcel',
options: 'keyValues',
options: 'concise',
attrs: 'name',
limit: 200
},
headers
);

const devices =
await ngsiLD.listEntities(
const devices = await ngsiLD.listEntities(
{
type: 'Devices',
options: 'keyValues',
options: 'concise',
attrs: 'name',
limit: 200
},
headers
);

const cows = _.filter(animals, (o) => {
return o.species === 'dairy cattle';
});
const pigs = _.filter(animals, (o) => {
return o.species === 'pig';
});

res.render('index', {
success: req.flash('success'),
errors: req.flash('error'),
Expand Down
2 changes: 1 addition & 1 deletion app/views/animal.pug
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ block content
dt.col-lg-3 Heart Rate
dd.col-lg-9
| #{animal.heartRate.value} bpm
- if (animal.location.value.coordinates)
- if (animal.location && animal.location.value.coordinates)
dt.col-lg-3 Current Location:
dd.col-lg-9 #{animal.location.value.coordinates[1]}°N, #{animal.location.value.coordinates[0]}°E

Expand Down
11 changes: 5 additions & 6 deletions app/views/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ block content
each building in buildings
li.list-inline-item
- if (securityEnabled)
a(class="link-danger link-underline link-underline-opacity-0" href=`app/${building.type.toLowerCase()}/${building.id}`)
a(class="link-danger link-underline link-underline-opacity-0" href=`app/building/${building.id}`)
img(class="p-2" src='/img/barn.png' width="32" height="32")
| #{building.name}
- else
a(class="link-underline link-underline-opacity-0" href=`app/${building.type.toLowerCase()}/${building.id}`)
a(class="link-underline link-underline-opacity-0" href=`app/building/${building.id}`)
img(class="p-2" src='/img/barn.png' width="32" height="32")
| #{building.name}
div.row
Expand All @@ -88,7 +88,7 @@ block content
each animal in cows
li
img(class="pe-2" src='/img/cow.svg' width="32" height="32")
a(class="link-underline link-underline-opacity-0" href=`app/${animal.type.toLowerCase()}/${animal.id}`) #{animal.name}
a(class="link-underline link-underline-opacity-0" href=`app/animal/${animal.id}`) #{animal.name}
div.col
div.card
div.card-body
Expand All @@ -99,7 +99,7 @@ block content
each animal in pigs
li
img(class="pe-2" src='/img/pig.svg' width="32" height="32")
a(class="link-underline link-underline-opacity-0" href=`app/${animal.type.toLowerCase()}/${animal.id}`) #{animal.name}
a(class="link-underline link-underline-opacity-0" href=`app/animal/${animal.id}`) #{animal.name}
div.row
div.col
h3 Agri Parcel Details
Expand All @@ -114,8 +114,7 @@ block content
each parcel in parcels
li.list-inline-item
img(class="p-2" src='/img/corn.png' width="32" height="32")
a(class="link-underline link-underline-opacity-0" href=`app/${parcel.type.toLowerCase()}/${parcel.id}`) #{parcel.name}

a(class="link-underline link-underline-opacity-0" href=`app/agriparcel/${parcel.id}`) #{parcel.name}
div
h3
- if (session.username)
Expand Down

0 comments on commit b8f780e

Please sign in to comment.