Skip to content

Commit

Permalink
Merge pull request #35 from sayoungestguy/develop-searchForActivity-dev
Browse files Browse the repository at this point in the history
Develop search for activity dev
  • Loading branch information
sayoungestguy authored Oct 16, 2024
2 parents 055086e + 70cdd3f commit 07a21a2
Show file tree
Hide file tree
Showing 12 changed files with 386 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public PasswordEncoder passwordEncoder() {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http, MvcRequestMatcher.Builder mvc) throws Exception {
http
.cors(withDefaults())
//.cors(withDefaults())
.csrf(csrf -> csrf.disable())
.addFilterAfter(new SpaWebFilter(), BasicAuthenticationFilter.class)
.headers(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ public ActivityQueryService(ActivityRepository activityRepository, ActivityMappe
@Transactional(readOnly = true)
public Page<ActivityDTO> findByCriteria(ActivityCriteria criteria, Pageable page) {
log.debug("find by criteria : {}, page: {}", criteria, page);
User currentUser = userService.getUserById().orElseThrow(() -> new UsernameNotFoundException("User not found"));
boolean isAdmin = SecurityUtils.isCurrentUserInRole(AuthoritiesConstants.ADMIN);
if (currentUser != null && !isAdmin) {
// Set the creatorProfileId in the criteria to match the current user
if (criteria == null) {
criteria = new ActivityCriteria();
}
LongFilter userFilter = new LongFilter();
userFilter.setEquals(currentUser.getId());
criteria.setCreatorProfileId(userFilter);
}
// User currentUser = userService.getUserById().orElseThrow(() -> new UsernameNotFoundException("User not found"));
// boolean isAdmin = SecurityUtils.isCurrentUserInRole(AuthoritiesConstants.ADMIN);
// if (currentUser != null && !isAdmin) {
// // Set the creatorProfileId in the criteria to match the current user
// if (criteria == null) {
// criteria = new ActivityCriteria();
// }
// LongFilter userFilter = new LongFilter();
// userFilter.setEquals(currentUser.getId());
// criteria.setCreatorProfileId(userFilter);
// }
final Specification<Activity> specification = createSpecification(criteria);
return activityRepository.findAll(specification, page).map(activityMapper::toDto);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/.h2.server.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#H2 Server Properties
#Wed Sep 11 08:50:53 SGT 2024
#Tue Oct 15 23:21:09 SGT 2024
0=JHipster H2 (Disk)|org.h2.Driver|jdbc\:h2\:file\:./target/h2db/db/scaleup|scaleup
webAllowOthers=true
webPort=8092
Expand Down
4 changes: 4 additions & 0 deletions src/main/webapp/app/config/icon-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import {
faUsers,
faUsersCog,
faWrench,
faEnvelope,
faPeopleArrows,
} from '@fortawesome/free-solid-svg-icons';

import { library } from '@fortawesome/fontawesome-svg-core';
Expand Down Expand Up @@ -71,5 +73,7 @@ export const loadIcons = () => {
faUsers,
faUsersCog,
faWrench,
faEnvelope,
faPeopleArrows,
);
};
22 changes: 13 additions & 9 deletions src/main/webapp/app/entities/activity/activity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export const Activity = () => {

const activityList = useAppSelector(state => state.activity.entities);
const loading = useAppSelector(state => state.activity.loading);
// Assuming the user's roles are stored in the authentication state
const currentUser = useAppSelector(state => state.authentication.account);

// Check if the current user has the "admin" role
const isAdmin = currentUser?.authorities?.includes('ROLE_ADMIN');

const [currentActivities, setCurrentActivities] = useState([]);
const [pastActivities, setPastActivities] = useState([]);
Expand All @@ -47,9 +52,14 @@ export const Activity = () => {

const getAllActivities = () => {
dispatch(
getAllActivity({
sort: `${currentPaginationState.sort},${currentPaginationState.order}`,
}),
getAllActivity(
isAdmin
? { sort: `${currentPaginationState.sort},${currentPaginationState.order}` }
: {
sort: `${currentPaginationState.sort},${currentPaginationState.order}`,
query: `creatorProfileId.equals=${currentUser.id.toString()}`,
},
),
);
};

Expand Down Expand Up @@ -193,12 +203,6 @@ export const Activity = () => {
}
}, [currentActivities, pastActivities]);

// Assuming the user's roles are stored in the authentication state
const currentUser = useAppSelector(state => state.authentication.account);

// Check if the current user has the "admin" role
const isAdmin = currentUser?.authorities?.includes('ROLE_ADMIN');

return (
<div>
<h2 id="activity-heading" data-cy="ActivityHeading">
Expand Down
19 changes: 11 additions & 8 deletions src/main/webapp/app/entities/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,30 @@ const EntitiesMenu = () => {
{/*<MenuItem icon="asterisk" to="/code-tables">*/}

Check warning on line 9 in src/main/webapp/app/entities/menu.tsx

View workflow job for this annotation

GitHub Actions / Frontend Test Stage

Expected space or tab after '/*' in comment
{/* Code Tables*/}
{/*</MenuItem>*/}
<MenuItem icon="asterisk" to="/user-profile">
<MenuItem icon="user" to="/user-profile">
User Profile
</MenuItem>
<MenuItem icon="asterisk" to="/skill">
<MenuItem icon="pencil-alt" to="/skill">
Skill
</MenuItem>
<MenuItem icon="asterisk" to="/message">
<MenuItem icon="envelope" to="/message">
Message
</MenuItem>
<MenuItem icon="asterisk" to="/activity">
<MenuItem icon="book" to="/activity">
Activity
</MenuItem>
<MenuItem icon="asterisk" to="/activity-invite">
<MenuItem icon="people-arrows" to="/activity-invite">
Activity Invite
</MenuItem>
<MenuItem icon="asterisk" to="/notification">
Notification
</MenuItem>
{/*<MenuItem icon="asterisk" to="/notification">*/}
{/* Notification*/}
{/*</MenuItem>*/}
<MenuItem icon="asterisk" to="/user-skill">
User Skill
</MenuItem>
<MenuItem icon="search" to="/search">
Search ScaleUp Network
</MenuItem>
{/* jhipster-needle-add-entity-to-menu - JHipster will add entities to the menu here */}
</>
);
Expand Down
2 changes: 2 additions & 0 deletions src/main/webapp/app/entities/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Activity from './activity';
import ActivityInvite from './activity-invite';
import Notification from './notification';
import UserSkill from './user-skill';
import SearchAppActivity from 'app/entities/search/searchAppActivity';
/* jhipster-needle-add-route-import - JHipster will add routes here */

export default () => {
Expand All @@ -26,6 +27,7 @@ export default () => {
<Route path="activity-invite/*" element={<ActivityInvite />} />
<Route path="notification/*" element={<Notification />} />
<Route path="user-skill/*" element={<UserSkill />} />
<Route path="search/*" element={<SearchAppActivity />} />
{/* jhipster-needle-add-route-path - JHipster will add routes here */}
</ErrorBoundaryRoutes>
</div>
Expand Down
39 changes: 39 additions & 0 deletions src/main/webapp/app/entities/search/commonNameCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Card, CardBody, CardText } from 'reactstrap';
import React from 'react';

export const CommonNameCard = ({ key, id, profilePic, nickname, jobRole }) => {
return (
<>
<Card
style={{
border: '2px solid navy',
borderRadius: '10px',
width: '45%',
padding: '10px',
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
marginRight: '2rem',
}}
>
{/* Display Picture Placeholder */}
<img
src={
profilePic === 'Male Profile Picture'
? 'https://images2.imgbox.com/58/df/QqnDcnpM_o.png'
: 'https://images2.imgbox.com/b3/e3/eB7ZJyVa_o.png'
}
alt="Profile Picture"
style={{ width: '50px', height: '50px', borderRadius: '50%', marginRight: '15px' }}
/>
{/* Nickname and Job Role */}
<CardBody style={{ padding: '0' }}>
<h5 style={{ margin: '0', color: 'navy' }}>{nickname}</h5>
<CardText style={{ margin: '0', color: '#666' }}>{jobRole}</CardText>
</CardBody>
</Card>
</>
);
};

export default CommonNameCard;
12 changes: 12 additions & 0 deletions src/main/webapp/app/entities/search/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import ErrorBoundaryRoutes from 'app/shared/error/error-boundary-routes';
import { Route } from 'react-router-dom';
import React from 'react';
import SearchAppActivity from 'app/entities/search/searchAppActivity';

const SearchAppActivityRoutes = () => (
<ErrorBoundaryRoutes>
<Route index element={<SearchAppActivity />} />
</ErrorBoundaryRoutes>
);

export default SearchAppActivityRoutes;
Loading

0 comments on commit 07a21a2

Please sign in to comment.