diff --git a/Server/SchoolBusAPI/Services/SchoolBusOwnerService.cs b/Server/SchoolBusAPI/Services/SchoolBusOwnerService.cs index b7457a1ae..687267b37 100644 --- a/Server/SchoolBusAPI/Services/SchoolBusOwnerService.cs +++ b/Server/SchoolBusAPI/Services/SchoolBusOwnerService.cs @@ -329,6 +329,15 @@ public virtual IActionResult SchoolbusownersIdHistoryGetAsync(int id, int? offse { var viewModel = Mapper.Map(data[i]); viewModel.AffectedEntityId = id; + + var user = _context.Users + .FirstOrDefault(x => x.SmUserId == viewModel.LastUpdateUserid); + + if (user != null) + { + viewModel.UserName = $"{user.Surname}, {user.GivenName}"; + } + result.Add(viewModel); } diff --git a/Server/SchoolBusAPI/Services/SchoolBusService.cs b/Server/SchoolBusAPI/Services/SchoolBusService.cs index f2f91f446..7d28adf36 100644 --- a/Server/SchoolBusAPI/Services/SchoolBusService.cs +++ b/Server/SchoolBusAPI/Services/SchoolBusService.cs @@ -466,6 +466,15 @@ public virtual IActionResult SchoolbusesIdHistoryGetAsync(int id, int? offset, i { var viewModel = Mapper.Map(data[i]); viewModel.AffectedEntityId = id; + + var user = _context.Users + .FirstOrDefault(x => x.SmUserId == viewModel.LastUpdateUserid); + + if (user != null) + { + viewModel.UserName = $"{user.Surname}, {user.GivenName}"; + } + result.Add(viewModel); } diff --git a/Server/SchoolBusAPI/ViewModels/HistoryViewModel.cs b/Server/SchoolBusAPI/ViewModels/HistoryViewModel.cs index 98ef8cba4..2a42454d8 100644 --- a/Server/SchoolBusAPI/ViewModels/HistoryViewModel.cs +++ b/Server/SchoolBusAPI/ViewModels/HistoryViewModel.cs @@ -70,6 +70,9 @@ public HistoryViewModel(int Id, string HistoryText = null, string LastUpdateUser [MetaDataExtension (Description = "Audit information - SM User Id for the User who most recently updated the record.")] public string LastUpdateUserid { get; set; } + [DataMember(Name = "userName")] + public string UserName { get; set; } + /// /// Audit information - Timestamp for record modification /// diff --git a/client/src/js/views/dialogs/HistoryListDialog.jsx b/client/src/js/views/dialogs/HistoryListDialog.jsx index af9a15f70..629a1594b 100644 --- a/client/src/js/views/dialogs/HistoryListDialog.jsx +++ b/client/src/js/views/dialogs/HistoryListDialog.jsx @@ -2,26 +2,25 @@ // This would allow an admin to view history by user, etc. Also, it would eliminate the // convoluted way we get to linked content. -import React from "react"; -import PropTypes from "prop-types"; +import React from 'react'; +import PropTypes from 'prop-types'; -import { connect } from "react-redux"; +import { connect } from 'react-redux'; -import { Alert, Button } from "react-bootstrap"; +import { Alert, Button } from 'react-bootstrap'; -import _ from "lodash"; +import _ from 'lodash'; -import * as Action from "../../actionTypes"; -import * as Api from "../../api"; -import * as Constant from "../../constants"; -import * as History from "../../history"; -import store from "../../store"; +import * as Action from '../../actionTypes'; +import * as Constant from '../../constants'; +import * as History from '../../history'; +import store from '../../store'; -import ModalDialog from "../../components/ModalDialog.jsx"; -import SortTable from "../../components/SortTable.jsx"; -import Spinner from "../../components/Spinner.jsx"; +import ModalDialog from '../../components/ModalDialog.jsx'; +import SortTable from '../../components/SortTable.jsx'; +import Spinner from '../../components/Spinner.jsx'; -import { formatDateTime } from "../../utils/date"; +import { formatDateTime } from '../../utils/date'; // API limit: how many to fetch first time const API_LIMIT = 10; @@ -33,7 +32,6 @@ class HistoryListDialog extends React.Component { show: PropTypes.bool, history: PropTypes.object, - users: PropTypes.object, ui: PropTypes.object, }; @@ -43,20 +41,14 @@ class HistoryListDialog extends React.Component { canShowMore: false, ui: { - sortField: this.props.ui.sortField || "timestampSort", + sortField: this.props.ui.sortField || 'timestampSort', sortDesc: this.props.ui.sortDesc !== false, }, }; componentDidMount() { this.setState({ loading: true }); - Api.getUsers() - .then(() => { - return this.fetch(true); - }) - .finally(() => { - this.setState({ loading: false }); - }); + this.fetch(true); } updateUIState = (state, callback) => { @@ -78,15 +70,8 @@ class HistoryListDialog extends React.Component { return History.get(this.props.historyEntity, 0, first ? API_LIMIT : null) .then(() => { var history = _.map(this.props.history, (history) => { - history.userName = this.getUserName(history.lastUpdateUserid); - history.formattedTimestamp = formatDateTime( - history.lastUpdateTimestamp, - Constant.DATE_TIME_LOG - ); - history.event = History.renderEvent( - history.historyText, - this.props.onClose - ); + history.formattedTimestamp = formatDateTime(history.lastUpdateTimestamp, Constant.DATE_TIME_LOG); + history.event = History.renderEvent(history.historyText, this.props.onClose); return history; }); this.setState({ @@ -96,8 +81,7 @@ class HistoryListDialog extends React.Component { .finally(() => { this.setState({ loading: false, - canShowMore: - first && Object.keys(this.props.history).length >= API_LIMIT, + canShowMore: first && Object.keys(this.props.history).length >= API_LIMIT, }); }); }; @@ -106,13 +90,6 @@ class HistoryListDialog extends React.Component { this.fetch(); }; - getUserName = (smUserId) => { - var user = _.find(this.props.users, (user) => { - return user.smUserId === smUserId; - }); - return user ? user.name : smUserId; - }; - render() { return ( - History for {this.props.historyEntity.type}{" "} - {this.props.historyEntity.description} + History for {this.props.historyEntity.type} {this.props.historyEntity.description} } footer={ @@ -132,11 +108,7 @@ class HistoryListDialog extends React.Component { - @@ -148,7 +120,7 @@ class HistoryListDialog extends React.Component { {(() => { if (this.state.loading) { return ( -
+
); @@ -158,18 +130,15 @@ class HistoryListDialog extends React.Component { return No history; } - var history = _.sortBy( - this.props.history, - this.state.ui.sortField - ); + var history = _.sortBy(this.props.history, this.state.ui.sortField); if (this.state.ui.sortDesc) { _.reverse(history); } var headers = [ - { field: "timestampSort", title: "Timestamp" }, - { field: "userName", title: "User" }, - { field: "event", noSort: true, title: "Event" }, + { field: 'timestampSort', title: 'Timestamp' }, + { field: 'userName', title: 'User' }, + { field: 'event', noSort: true, title: 'Event' }, ]; return ( @@ -203,7 +172,6 @@ class HistoryListDialog extends React.Component { function mapStateToProps(state) { return { history: state.models.history, - users: state.models.users, ui: state.ui.history, }; }