Skip to content

Commit

Permalink
Linting and tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-fox committed Apr 4, 2024
1 parent 44cd10b commit ef68dd4
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 26 deletions.
12 changes: 11 additions & 1 deletion app/controllers/ngsi-ld/animal.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,17 @@ async function displayAnimal(req, res) {
{ options: 'concise' },
ngsiLD.setHeaders(req.session.access_token, LinkHeader)
);
return res.render('animal', { title: animal.name, animal });

let imgId = animal.id.substring(animal.id.length - 3);

if (imgId < 100) {
imgId = `00${imgId % 10}`;
}

console.log(imgId);
//animal.img=)

return res.render('animal', { title: animal.name, animal, imgId });
} catch (error) {
const errorDetail = error.error;
debug(errorDetail);
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/ngsi-ld/farm.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
const debug = require('debug')('tutorial:ngsi-ld');
const monitor = require('../../lib/monitoring');
const ngsiLD = require('../../lib/ngsi-ld');
const _ = require('lodash');
const Context = process.env.IOTA_JSON_LD_CONTEXT || 'http://context/ngsi-context.jsonld';
const LinkHeader = '<' + Context + '>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json">';

Expand Down Expand Up @@ -68,7 +67,6 @@ async function displayFarm(req, res) {
}
}


module.exports = {
display: displayFarm,
display: displayFarm
};
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
28 changes: 13 additions & 15 deletions app/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const express = require('express');
const router = express.Router();
const monitor = require('../lib/monitoring');
const Constants = require('../lib/constants');
const Device = require('../controllers/ngsi-ld/device');
const Farm = require('../controllers/ngsi-ld/farm');
const Animal = require('../controllers/ngsi-ld/animal');
Expand All @@ -22,7 +21,7 @@ const TRANSPORT = process.env.DUMMY_DEVICES_TRANSPORT || 'HTTP';
const DEVICE_PAYLOAD = process.env.DUMMY_DEVICES_PAYLOAD || 'ultralight';
const GIT_COMMIT = process.env.GIT_COMMIT || 'unknown';
const SECURE_ENDPOINTS = process.env.SECURE_ENDPOINTS || false;
const AUTHZFORCE_ENABLED = process.env.AUTHZFORCE_ENABLED || false;
//const AUTHZFORCE_ENABLED = process.env.AUTHZFORCE_ENABLED || false;

const NOTIFY_ATTRIBUTES = ['controlledAsset', 'type', 'filling', 'humidity', 'temperature'];

Expand Down Expand Up @@ -53,28 +52,28 @@ router.get('/', async function (req, res) {

const headers = ngsiLD.setHeaders(req.session.access_token, LinkHeader);
let entities = await ngsiLD.listEntities(
{
type: 'Building,Animal,AgriParcel',
options: 'keyValues',
limit: 200
},
headers
);
{
type: 'Building,Animal,AgriParcel',
options: 'keyValues',
limit: 200
},
headers
);

entities = Array.isArray(entities) ? entities : [entities];
entities = _.groupBy(entities, (e) => {
return e.type;
});

if(entities.Animal){
if (entities.Animal) {
entities.Animal = _.groupBy(entities.Animal, (e) => {
return e.species;
});
} else {
entities.Animal = {
'dairy cattle': [],
'pig': []
}
pig: []
};
}

res.render('index', {
Expand All @@ -83,8 +82,8 @@ router.get('/', async function (req, res) {
info: req.flash('info'),
securityEnabled,
buildings: entities.Building || [],
pigs : entities.Animal.pig || [],
cows : entities.Animal['dairy cattle'] || [],
pigs: entities.Animal.pig || [],
cows: entities.Animal['dairy cattle'] || [],
parcels: entities.AgriParcel || [],
devices: entities.Device || [],
ngsi: 'ngsi-ld'
Expand Down Expand Up @@ -165,7 +164,6 @@ router.get('/app/building/:id', Security.authenticate, Farm.display);
router.get('/app/person/:id', Security.authenticate, Person.display);
router.get('/app/device-details/:id', Security.authenticate, Device.display);


// Whenever a subscription is received, display it on the monitor
// and notify any interested parties using Socket.io
router.post('/subscription/:type', (req, res) => {
Expand Down
14 changes: 7 additions & 7 deletions app/views/animal.pug
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@ block content
div.row
- if (animal.species == 'dairy cattle')
div.col-lg-3
img.img-thumbnail(src=`/img/cow-${animal.name.toLowerCase()}.jpg` width="256px" height="256px")
img.img-thumbnail(src=`/img/cow-${imgId}.jpg` width="256px" height="256px")
div.col-lg-9
dl.row
- if (animal.species)
dt.col-lg-3 Species:
dd.col-lg-9 #{animal.species}
- if (animal.sex)
dt.col-lg-3 Sex:
dd.col-lg-9 #{animal.sex.vocab}
- if (animal.legalId)
dd.col-lg-9 #{animal.sex.vocab||animal.sex}
- if (animal.legalId||animal.legalID)
dt.col-lg-3 Legal ID:
dd.col-lg-9
strong #{animal.legalId}
code #{animal.legalId||animal.legalID}
- if (animal.phenologicalCondition)
dt.col-lg-3 Phenological Condition:
dd.col-lg-9 #{animal.phenologicalCondition.vocab}
dd.col-lg-9 #{animal.phenologicalCondition.vocab||animal.phenologicalCondition}
- if (animal.healthCondition)
dt.col-lg-3 Health:
dd.col-lg-9 #{animal.healthCondition.vocab}
dd.col-lg-9 #{animal.healthCondition.vocab||animal.healthCondition}
- if (animal.reproductiveCondition)
dt.col-lg-3 Reproductive Condition:
dd.col-lg-9 #{animal.reproductiveCondition.vocab}
dd.col-lg-9 #{animal.reproductiveCondition.vocab||animal.reproductiveCondition}
- if (animal.calvedBy)
dt.col-lg-3 Calved by:
dd.col-lg-9
Expand Down

0 comments on commit ef68dd4

Please sign in to comment.