Skip to content

Commit

Permalink
Merge pull request #600 from bcgov/2.0.1
Browse files Browse the repository at this point in the history
Version 2.0.1
  • Loading branch information
ychung-mot authored Mar 18, 2021
2 parents bd54689 + 4921dbc commit 27ba0c2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 57 deletions.
9 changes: 9 additions & 0 deletions Server/SchoolBusAPI/Services/SchoolBusOwnerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,15 @@ public virtual IActionResult SchoolbusownersIdHistoryGetAsync(int id, int? offse
{
var viewModel = Mapper.Map<HistoryViewModel>(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);
}

Expand Down
9 changes: 9 additions & 0 deletions Server/SchoolBusAPI/Services/SchoolBusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,15 @@ public virtual IActionResult SchoolbusesIdHistoryGetAsync(int id, int? offset, i
{
var viewModel = Mapper.Map<HistoryViewModel>(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);
}

Expand Down
3 changes: 3 additions & 0 deletions Server/SchoolBusAPI/ViewModels/HistoryViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

/// <summary>
/// Audit information - Timestamp for record modification
/// </summary>
Expand Down
82 changes: 25 additions & 57 deletions client/src/js/views/dialogs/HistoryListDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,7 +32,6 @@ class HistoryListDialog extends React.Component {
show: PropTypes.bool,

history: PropTypes.object,
users: PropTypes.object,
ui: PropTypes.object,
};

Expand All @@ -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) => {
Expand All @@ -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({
Expand All @@ -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,
});
});
};
Expand All @@ -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 (
<ModalDialog
Expand All @@ -123,20 +100,15 @@ class HistoryListDialog extends React.Component {
onClose={this.props.onClose}
title={
<strong>
History for {this.props.historyEntity.type}{" "}
{this.props.historyEntity.description}
History for {this.props.historyEntity.type} {this.props.historyEntity.description}
</strong>
}
footer={
<span>
<Button title="Close" onClick={this.props.onClose}>
Close
</Button>
<Button
title="Show More"
onClick={this.showMore}
disabled={!this.state.canShowMore}
>
<Button title="Show More" onClick={this.showMore} disabled={!this.state.canShowMore}>
Show More
</Button>
</span>
Expand All @@ -148,7 +120,7 @@ class HistoryListDialog extends React.Component {
{(() => {
if (this.state.loading) {
return (
<div style={{ textAlign: "center" }}>
<div style={{ textAlign: 'center' }}>
<Spinner />
</div>
);
Expand All @@ -158,18 +130,15 @@ class HistoryListDialog extends React.Component {
return <Alert bsStyle="success">No history</Alert>;
}

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 (
Expand Down Expand Up @@ -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,
};
}
Expand Down

0 comments on commit 27ba0c2

Please sign in to comment.