Skip to content

Commit 01f3643

Browse files
authored
Issue 137 (#153)
* add column for grantcodes in ui and vsc export * issue fixed --------- Co-authored-by: = <=>
1 parent bace713 commit 01f3643

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

nomad-front-end/src/components/AccountsComponents/AccountsTable.jsx

+13
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ const AccountsTable = props => {
1616
}
1717
]
1818

19+
//add the grantCode column if data are for user calculation
20+
if (props.header === 'User Name') {
21+
columns.push({
22+
title: 'Grant Code',
23+
width: 35,
24+
dataIndex: 'grantCode',
25+
key: 'grantCode',
26+
fixed: 'left',
27+
align: 'center'
28+
})
29+
}
30+
1931
//Getting dynamic table headers from the first data object
2032
props.data[0].costsPerInstrument.forEach((cost, index) => {
2133
columns.push({
@@ -61,6 +73,7 @@ const AccountsTable = props => {
6173
const data = props.data.map((entry, key) => {
6274
const newEntry = {
6375
name: entry.name,
76+
grantCode: entry.grantCode || undefined,
6477
totalCost: entry.totalCost,
6578
key
6679
}

nomad-front-end/src/components/NavBar/PageHeader/Controls/AccountingControls.jsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ const AccountingControls = props => {
1717
columns = standardColumns.grants
1818
} else {
1919
columns = [head]
20+
if (type === 'Users') {
21+
columns = [...columns, 'Grant Code']
22+
}
2023
let presentColumns = data[0].costsPerInstrument
2124
presentColumns.forEach(({ instrument }) => {
2225
const newColumnsToAdd = [
2326
instrument + ' Exp Time Manual',
2427
instrument + ' Exp Time Auto',
25-
instrument + ' Exp Time Cost [£]'
28+
instrument + ' Cost [£]'
2629
]
2730
columns = [...columns, ...newColumnsToAdd]
2831
})
@@ -54,6 +57,11 @@ const AccountingControls = props => {
5457
} else {
5558
data.forEach(row => {
5659
let FlatRow = [row.name]
60+
61+
if (type === 'Users') {
62+
FlatRow = [...FlatRow, row.grantCode]
63+
}
64+
5765
row.costsPerInstrument.forEach(instrumentData => {
5866
const { cost, expTimeAuto, expTimeClaims } = instrumentData
5967
FlatRow = [...FlatRow, expTimeClaims, expTimeAuto, cost]

nomad-rest-api/controllers/admin/accounts.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Instrument from '../../models/instrument.js'
99
import Grant from '../../models/grant.js'
1010
import {
1111
checkDuplicate,
12+
getGrantInfo,
1213
getSearchParams,
1314
getSearchParamsClaims
1415
} from '../../utils/accountsUtils.js'
@@ -82,14 +83,25 @@ export async function getCosts(req, res) {
8283

8384
await Promise.all(
8485
usrArray.map(async usrId => {
85-
const user = await User.findById(usrId)
86+
const [user, grantInfo] = await Promise.all([User.findById(usrId), getGrantInfo(usrId)])
87+
88+
let grant
89+
if (grantInfo) {
90+
grant = await Grant.findById(grantInfo.grantId)
91+
}
92+
8693
const usrInactive = !user.isActive || user.group.toString() !== groupId
8794
const newEntry = {
88-
name: `${user.username} - ${user.fullName} ${usrInactive ? '(Inactive)' : ''}`,
95+
name: `${user.username} - ${user.fullName}`,
96+
grantCode: grant && grant.grantCode,
8997
costsPerInstrument: [],
9098
totalCost: 0
9199
}
92100

101+
if (groupId !== 'all') {
102+
newEntry.name += `${usrInactive ? '(Inactive)' : ''}`
103+
}
104+
93105
instrumentList.forEach(i => {
94106
const filteredExpArray = expArray.filter(
95107
exp => exp.instrument.name === i.name && exp.user.id.toString() === usrId

0 commit comments

Comments
 (0)