Skip to content

Commit e7b79bc

Browse files
committed
Sort Entities.
1 parent a936f86 commit e7b79bc

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

app/app.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ app.use(express.urlencoded({ extended: false }));
5151
app.use(cookieParser());
5252
app.use(flash());
5353

54-
console.log(sessionOff)
55-
5654
if (process.env.NODE_ENV === 'production' && !sessionOff) {
5755
// Use Mongo-DB to store session data.
5856
app.use(

app/routes/index.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,52 +65,62 @@ router.get('/', async function (req, res) {
6565
const headers = ngsiLD.setHeaders(req.session.access_token, LinkHeader);
6666
try {
6767
monitor('NGSI', 'listEntities ?type=Building');
68-
const buildings = await ngsiLD.listEntities(
68+
const getBuildings = await ngsiLD.listEntities(
6969
{
7070
type: 'Building',
7171
format: 'keyValues',
72-
attrs: 'name',
72+
pick: 'id,name',
7373
limit: ENTITY_LIMIT
7474
},
7575
headers
7676
);
77+
const buildings = getBuildings.sort((a, b) => {
78+
return a.name.localeCompare(b.name);
79+
});
7780
monitor('NGSI', 'listEntities ?type=Animal');
7881
const animals = await ngsiLD.listEntities(
7982
{
8083
type: 'Animal',
8184
format: 'keyValues',
82-
attrs: 'name,species',
85+
pick: 'id,name,species,phenologicalCondition',
8386
limit: ENTITY_LIMIT
8487
},
8588
headers
8689
);
8790
monitor('NGSI', 'listEntities ?type=AgriParcel');
88-
const parcels = await ngsiLD.listEntities(
91+
const getParcels = await ngsiLD.listEntities(
8992
{
9093
type: 'AgriParcel',
9194
format: 'keyValues',
92-
attrs: 'name',
95+
pick: 'id,name',
9396
limit: ENTITY_LIMIT
9497
},
9598
headers
9699
);
100+
const parcels = getParcels.sort((a, b) => {
101+
return a.name.localeCompare(b.name);
102+
});
97103

98104
monitor('NGSI', 'listEntities ?type=Device');
99105
const devices = await ngsiLD.listEntities(
100106
{
101107
type: 'Device',
102108
format: 'keyValues',
103-
attrs: 'name',
109+
pick: 'id,name',
104110
limit: ENTITY_LIMIT
105111
},
106112
headers
107113
);
108114

109115
const cows = _.filter(animals, (o) => {
110116
return o.species === 'dairy cattle';
117+
}).sort((a, b) => {
118+
return a.name.localeCompare(b.name);
111119
});
112120
const pigs = _.filter(animals, (o) => {
113121
return o.species === 'pig';
122+
}).sort((a, b) => {
123+
return a.name.localeCompare(b.name);
114124
});
115125

116126
return res.render('index', {

app/views/animal.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ block content
1515
div.card-body
1616
div.container
1717
div.row
18-
- if (animal.species == 'dairy cattle')
18+
- if (animal.species.value == 'dairy cattle')
1919
div.col-lg-3
2020
img.img-thumbnail(src=`/img/cow-${imgId}.jpg` width="256px" height="256px")
2121
div.col-lg-9

app/views/index.pug

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,21 @@ block content
105105
ul.list-unstyled
106106
each animal in cows
107107
li
108-
img(class="pe-2" src='/img/cow.svg' width="32" height="32")
109-
a(class="link-underline link-underline-opacity-0" href=`app/animal/${animal.id}`) #{animal.name}
108+
- if (animal.phenologicalCondition.vocab.includes('Adult'))
109+
img(class="pe-2" src='/img/cow.svg' width="32" height="32")
110+
a(class="link-underline link-underline-opacity-0" href=`app/animal/${animal.id}`)
111+
112+
| #{animal.name}
113+
- if (animal.phenologicalCondition.vocab === 'maleAdult')
114+
|  the Bull
115+
- else
116+
img(class="ps-1 pe-1" src='/img/cow.svg' width="24" height="24" style="margin:4px")
117+
a(class="link-underline link-underline-opacity-0" href=`app/animal/${animal.id}`)
118+
| #{animal.name}
119+
120+
121+
122+
110123
div.col
111124
div.card
112125
div.card-body

0 commit comments

Comments
 (0)