Skip to content

Commit 857cfaa

Browse files
authored
Merge pull request #60 from bcgov/2.2
2.2 to master
2 parents 7baf272 + e5c4983 commit 857cfaa

File tree

13 files changed

+105
-33
lines changed

13 files changed

+105
-33
lines changed

TransAction.API/Controllers/EventController.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ public EventController(IHttpContextAccessor httpContextAccessor, ILogger<Activit
2121

2222

2323
[HttpGet()]
24-
public IActionResult GetEvents(string Name, int page = 1, int pageSize = 25)
24+
public IActionResult GetEvents(string name, int page = 1, int pageSize = 25)
2525
{
26-
var events = _unitOfWork.Event.GetAll(page, pageSize, Name);
26+
var events = _unitOfWork.Event.GetAll(page, pageSize, name);
2727
var getEvents = _mapper.Map<IEnumerable<EventDto>>(events);
28-
int count = _unitOfWork.Event.GetCount(Name);
28+
int count = _unitOfWork.Event.Count(name);
2929
return StatusCode(200, new TransActionPagedResponse(getEvents, page, pageSize, count));
3030

3131
}

TransAction.API/Controllers/UserController.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ public UserController(IHttpContextAccessor httpContextAccessor, ILogger<Activity
2121

2222

2323
[HttpGet()]
24-
public IActionResult GetUsers(string Name, int page = 1, int pageSize = 25)
24+
public IActionResult GetUsers(string name, int page = 1, int pageSize = 25)
2525
{
26-
var user = _unitOfWork.User.GetAll(Name, page, pageSize);
26+
var user = _unitOfWork.User.GetAll(name, page, pageSize);
2727
var getUsers = _mapper.Map<IEnumerable<UserDto>>(user);
28-
return StatusCode(200, new TransActionPagedResponse(getUsers, page, pageSize, _unitOfWork.User.Count(Name)));
28+
return StatusCode(200, new TransActionPagedResponse(getUsers, page, pageSize, _unitOfWork.User.Count(name)));
2929
}
3030

3131
[HttpGet("{id}", Name = "GetUser")]

TransAction.Data/Repositories/EventRepository.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ public EventRepository(TransActionContext context) : base(context)
1212

1313
}
1414

15-
public IEnumerable<TraEvent> GetAll(int page, int pageSize, string Name)
15+
public IEnumerable<TraEvent> GetAll(int page, int pageSize, string name)
1616
{
1717
if (--page < 0) page = 0;
1818
var events = FindAll().Where(x => x.IsActive == true);
19-
if (!string.IsNullOrEmpty(Name))
19+
if (!string.IsNullOrEmpty(name))
2020
{
21-
events = events.Where(x => x.Name.Contains(Name));
21+
events = events.Where(x => x.Name.Contains(name));
2222
}
2323
return events.OrderByDescending(x => x.StartDate).Skip(page * pageSize).Take(pageSize).ToList();
2424

@@ -28,12 +28,12 @@ public TraEvent GetById(int id)
2828
{
2929
return Find(e => e.EventId == id).FirstOrDefault();
3030
}
31-
public int GetCount(string Name)
31+
public int Count(string name)
3232
{
3333
var eventCount = FindAll().Where(x => x.IsActive == true);
34-
if (!string.IsNullOrEmpty(Name))
34+
if (!string.IsNullOrEmpty(name))
3535
{
36-
return eventCount.Where(x => x.Name.Contains(Name)).Count();
36+
return eventCount.Where(x => x.Name.Contains(name)).Count();
3737
}
3838
return eventCount.Count();
3939
}

TransAction.Data/Repositories/Interfaces/IEventRepository.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace TransAction.Data.Repositories.Interfaces
55
{
66
public interface IEventRepository
77
{
8-
IEnumerable<TraEvent> GetAll(int page, int pageSize, string Name);
9-
int GetCount(string Name);
8+
IEnumerable<TraEvent> GetAll(int page, int pageSize, string name);
9+
int Count(string name);
1010
TraEvent GetById(int id);
1111
void Create(TraEvent newEvent);
1212
void Update(TraEvent updateEvent);

TransAction.Data/Repositories/Interfaces/IUserRepository.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ namespace TransAction.Data.Repositories.Interfaces
55
{
66
public interface IUserRepository
77
{
8-
IEnumerable<TraUser> GetAll(string Name, int page, int pageSize);
8+
IEnumerable<TraUser> GetAll(string name, int page, int pageSize);
99
TraUser GetById(int id);
1010
TraUser GetByGuid(string guid);
1111
IEnumerable<TraUser> GetByTeamId(int teamId);
1212
void Create(TraUser newUser);
1313
void Update(TraUser updateUser);
1414
TraUser GetCurrentUser(string guid);
15-
int Count(string Name);
15+
int Count(string name);
1616
}
1717
}

TransAction.Data/Repositories/UserRepository.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ public UserRepository(TransActionContext context) : base(context)
1313

1414
}
1515

16-
public IEnumerable<TraUser> GetAll(string Name, int page, int pageSize)
16+
public IEnumerable<TraUser> GetAll(string name, int page, int pageSize)
1717
{
1818

1919
if (--page < 0) page = 0;
2020
var users = FindAll();
21-
if (!string.IsNullOrEmpty(Name))
21+
if (!string.IsNullOrEmpty(name))
2222
{
23-
users = users.Where(x => (x.Fname + " " + x.Lname).Contains(Name));
23+
users = users.Where(x => (x.Fname + " " + x.Lname).Contains(name));
2424
}
2525
return users.Include(x => x.TraImage).OrderBy(x => x.Fname).ThenBy(x => x.Lname).Skip(page * pageSize).Take(pageSize).ToList();
2626
}
@@ -44,12 +44,12 @@ public TraUser GetCurrentUser(string guid)
4444
return Find(c => c.Guid == guid).Include(x => x.Role).Include(x => x.TraImage).FirstOrDefault();
4545
}
4646

47-
public int Count(string Name)
47+
public int Count(string name)
4848
{
4949
var userCount = FindAll().Include(x => x.TraImage);
50-
if (!string.IsNullOrEmpty(Name))
50+
if (!string.IsNullOrEmpty(name))
5151
{
52-
return userCount.Where(x => (x.Fname + " " + x.Lname).Contains(Name)).Count();
52+
return userCount.Where(x => (x.Fname + " " + x.Lname).Contains(name)).Count();
5353
}
5454
return userCount.Count();
5555
}

TransAction.SQL/dbo/Tables/TRA_TOPIC.sql

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
[TOPIC_ID] INT IDENTITY (1, 1) NOT NULL,
33
[TITLE] VARCHAR(1024) NOT NULL,
44
[USER_ID] INT NOT NULL,
5+
[LAST_MESSAGE_TIMESTAMP] DATETIME NULL,
56
[DB_CREATE_TIMESTAMP] DATETIME NOT NULL,
67
[DB_CREATE_USERID] VARCHAR(30) NOT NULL,
78
[DB_LAST_UPDATE_TIMESTAMP] DATETIME NOT NULL,
@@ -95,6 +96,7 @@ BEGIN
9596
SET
9697
TRA_TOPIC.TITLE = inserted.TITLE,
9798
TRA_TOPIC.USER_ID = inserted.USER_ID,
99+
LAST_MESSAGE_TIMESTAMP = inserted.LAST_MESSAGE_TIMESTAMP,
98100
TRA_TOPIC.DB_CREATE_TIMESTAMP = inserted.DB_CREATE_TIMESTAMP,
99101
TRA_TOPIC.DB_CREATE_USERID = inserted.DB_CREATE_USERID,
100102
TRA_TOPIC.DB_LAST_UPDATE_TIMESTAMP = CURRENT_TIMESTAMP,

transaction-client/src/js/actions/eventActions.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import api from '../api/api';
2-
import { getApiReponseData, buildApiErrorObject } from '../utils';
2+
import { getApiReponseData, getApiPagedReponseData, buildApiErrorObject, buildApiQueryString } from '../utils';
33
import { CREATE_EVENT, FETCH_EVENTS, FETCH_EVENT, EDIT_EVENT, ARCHIVE_EVENT, SHOW_ERROR_DIALOG_MODAL } from './types';
44

5-
export const fetchEvents = () => async dispatch => {
5+
export const fetchEvents = (name, page, pageSize) => async dispatch => {
66
return new Promise(async (resolve, reject) => {
77
try {
8-
const response = await api.get('/events');
9-
const data = getApiReponseData(response);
8+
const response = await api.get(`/events/?${buildApiQueryString(name, page, pageSize)}`);
9+
const data = getApiPagedReponseData(response).data;
1010
dispatch({ type: FETCH_EVENTS, payload: data });
1111

12-
resolve();
12+
resolve(getApiPagedReponseData(response).pageCount);
1313
} catch (e) {
1414
dispatch({ type: SHOW_ERROR_DIALOG_MODAL, payload: buildApiErrorObject(e.response) });
1515
reject(e);

transaction-client/src/js/actions/messageActions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const createTopic = topic => async dispatch => {
6262
const data = getApiReponseData(response);
6363
dispatch({ type: CREATE_TOPIC, payload: data });
6464

65-
history.push(`${Constants.PATHS.MESSAGES}/${response.data.id}`);
65+
history.push(`${Constants.PATHS.MESSAGES}/${data.id}`);
6666
resolve();
6767
} catch (e) {
6868
dispatch({ type: SHOW_ERROR_DIALOG_MODAL, payload: buildApiErrorObject(e.response) });

transaction-client/src/js/actions/teamActions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export const createTeam = teamObj => async dispatch => {
7878

7979
dispatch({ type: CREATE_TEAM, payload: data });
8080

81-
history.push(`${Constants.PATHS.TEAM}/${response.data.id}`);
81+
history.push(`${Constants.PATHS.TEAM}/${data.id}`);
8282
resolve();
8383
} catch (e) {
8484
dispatch({ type: SHOW_ERROR_DIALOG_MODAL, payload: buildApiErrorObject(e.response) });

transaction-client/src/js/components/EventList.js

+33-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import PageSpinner from './ui/PageSpinner';
99
import { fetchEvents, archiveEvent } from '../actions';
1010
import BreadcrumbFragment from './fragments/BreadcrumbFragment';
1111
import DialogModal from './ui/DialogModal';
12+
import ScrollLoader from './fragments/ScollLoader';
1213

1314
import * as utils from '../utils';
1415
import * as Constants from '../Constants';
@@ -20,14 +21,29 @@ class EventList extends Component {
2021
eventFormInitialValues: null,
2122
showConfirmDialog: false,
2223
confirmDialogOptions: {},
24+
searchTerm: undefined,
25+
page: 0,
26+
pageSize: 3,
27+
pageCount: 1,
2328
};
2429

2530
componentDidMount() {
26-
this.props.fetchEvents().then(() => {
27-
this.setState({ loading: false });
28-
});
31+
this.loadData();
2932
}
3033

34+
loadData = () => {
35+
const nextPage = this.state.page + 1;
36+
if (this.state.page < this.state.pageCount) {
37+
this.props.fetchEvents(this.state.searchTerm, nextPage, this.state.pageSize).then(pageCount => {
38+
this.setState({ loading: false, page: nextPage, pageCount });
39+
});
40+
}
41+
};
42+
43+
loadMoreData = () => {
44+
if (this.state.page <= this.state.pageCount) this.loadData();
45+
};
46+
3147
showAddEventForm = () => {
3248
this.setState({ showEventForm: true, eventFormType: Constants.FORM_TYPE.ADD, eventFormInitialValues: null });
3349
};
@@ -102,7 +118,20 @@ class EventList extends Component {
102118
return (
103119
<React.Fragment>
104120
{this.renderAddEventButton()}
105-
{this.state.loading ? <PageSpinner /> : this.renderEventList()}
121+
{this.state.loading ? (
122+
<PageSpinner />
123+
) : (
124+
<ScrollLoader loader={this.loadData}>
125+
{this.renderEventList()}
126+
{this.state.page < this.state.pageCount && (
127+
<div className="text-center mb-5">
128+
<Button color="primary" onClick={this.loadData}>
129+
More
130+
</Button>
131+
</div>
132+
)}
133+
</ScrollLoader>
134+
)}
106135
</React.Fragment>
107136
);
108137
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react';
2+
import _ from 'lodash';
3+
4+
class ScrollLoader extends React.Component {
5+
componentDidMount() {
6+
window.addEventListener('scroll', this.scrollListener);
7+
window.addEventListener('wheel', this.scrollListener);
8+
}
9+
10+
componentWillUnmount() {
11+
window.removeEventListener('scroll', this.scrollListener);
12+
window.removeEventListener('wheel', this.scrollListener);
13+
}
14+
15+
scrollListener = _.debounce(() => {
16+
if (window.innerHeight + window.pageYOffset >= document.documentElement.offsetHeight) {
17+
// Scrolled to the bottom
18+
if (this.props.loader) this.props.loader();
19+
}
20+
}, 100);
21+
22+
render() {
23+
return this.props.children;
24+
}
25+
}
26+
27+
export default ScrollLoader;

transaction-client/src/js/utils.js

+14
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ export const getApiReponseData = response => {
4040
return response.data.data ? response.data.data : response.data;
4141
};
4242

43+
export const getApiPagedReponseData = response => {
44+
return { data: response.data.data, pageCount: response.data.pageCount };
45+
};
46+
4347
export const buildApiErrorObject = response => {
4448
try {
4549
const method = response.config.method.toUpperCase();
@@ -57,3 +61,13 @@ export const buildApiErrorObject = response => {
5761
};
5862
}
5963
};
64+
65+
export const buildApiQueryString = (searchTerm, page, pageSize) => {
66+
const queries = [];
67+
68+
if (searchTerm) queries.push(`name=${searchTerm}`);
69+
if (page) queries.push(`page=${page}`);
70+
if (pageSize) queries.push(`pageSize=${pageSize}`);
71+
72+
return queries.join('&');
73+
};

0 commit comments

Comments
 (0)