Skip to content

Commit

Permalink
feat: [admin/dashboard] ajoute les cards qui décompte les jobs et les…
Browse files Browse the repository at this point in the history
… utilisateurs (#309)
  • Loading branch information
matthieuaudemard committed May 6, 2023
1 parent 522f2b7 commit 525fb24
Show file tree
Hide file tree
Showing 27 changed files with 186 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public ResponseEntity<Page<UserDto>> getAll(
return ResponseEntity.ok(users);
}

@GetMapping(GET_ENABLED_USERS_COUNT)
public ResponseEntity<Long> getEnabledUsersCount() {
return ResponseEntity.ok(userService.getEnabledUsersCount());
}

@GetMapping(GET_PENDING_USER_URI)
@PreAuthorize("hasRole('ROLE_ADMIN')")
public ResponseEntity<Page<UserDto>> getAllPendingUsers(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ public interface UserRepository extends JpaRepository<UserModel, Long> {

Page<UserModel> findAllByEnabledIsFalse(Pageable pageable);

Long countByEnabledTrue();
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,8 @@ public UserDto updateUserRoles(final String username, final Set<RoleEnum> roles)

return userMapper.toDto(userRepository.save(user));
}

public Long getEnabledUsersCount() {
return userRepository.countByEnabledTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public class UserUris {
public static final String GET_PENDING_USER_URI = "/pending";
public static final String ENABLE_USER = "/{username}/enable";
public static final String UPDATE_USER_ROLES = "/{username}/roles";
public static final String GET_ENABLED_USERS_COUNT = "/count";
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,9 @@ public ResponseEntity<JobPostingDto> validateJob(@PathVariable final Long jobId)
final JobPostingDto jobUpdate = jobPostingService.validateJob(jobId);
return ResponseEntity.ok(jobUpdate);
}

@GetMapping(GET_ENABLED_COUNT)
public ResponseEntity<Long> getEnabledJobsCount() {
return ResponseEntity.ok(jobPostingService.getEnabledJobsCount());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public interface JobPostingRepository extends JpaRepository<JobPostingModel, Lon
Page<JobPostingModel> findAllByValidIsFalse(Pageable pageable);

Page<JobPostingModel> findAllByArchiveFalseAndValidTrueOrderByCreatedAtDesc(Pageable pageable);

Long countByValidTrue();
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,8 @@ private JobPostingModel findById(final Long jobId) {
return jobPostingRepository.findById(jobId)
.orElseThrow(() -> new NotFoundException(String.format(JOB_NOT_FOUND_MESSAGE, jobId)));
}

public Long getEnabledJobsCount() {
return jobPostingRepository.countByValidTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public class JobPostingUris {
public static final String VALIDATE_JOB_URI = "{jobId}/validate";
public static final String VALIDATED_JOBS = "/validated";
public static final String GET_LATEST_JOBS_URI = "/latest";
public static final String GET_ENABLED_COUNT = "/count";
}
10 changes: 7 additions & 3 deletions frontend-implicaction/src/app/admin/admin.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import {UserManagementWidgetComponent} from './widgets/user-management-wiget/use
import {UserFragmentComponent} from './fragments/user-fragment/user-fragment.component';
import {SkeletonModule} from "primeng/skeleton";
import {DashboardFragmentComponent} from "./fragments/dashboard-fragment/dashboard-fragment.component";
import {AdminOverviewWidgetComponent} from "./widgets/admin-overview-widget/admin-overview-widget.component";
import {UserCounterWidgetComponent} from './widgets/user-counter-widget/user-counter-widget.component';
import {CounterCardComponent} from './components/counter-card/counter-card.component';
import {PendingJobTableComponent} from "./components/users/pending-job-table/pending-job-table.component";
import { JobCounterWidgetComponent } from './widgets/job-counter-widget/job-counter-widget.component';


@NgModule({
Expand All @@ -32,8 +34,10 @@ import {PendingJobTableComponent} from "./components/users/pending-job-table/pen
UserManagementWidgetComponent,
UserFragmentComponent,
DashboardFragmentComponent,
AdminOverviewWidgetComponent,
PendingJobTableComponent
UserCounterWidgetComponent,
CounterCardComponent,
PendingJobTableComponent,
JobCounterWidgetComponent
],
imports: [
CommonModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class="card info-card revenue-card">

<div class="card-body">

<div class="d-flex align-items-center">
<div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
<i [ngClass]="icon" style="font-size: 2rem"></i>
</div>
<div class="ps-3">
<h4>{{value ?? 0}}</h4>
<span class="text-muted small pt-2 ps-1">{{title}}</span>
</div>
</div>
</div>

</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@import "src/assets/variables";

.card-icon {
font-size: 32px;
line-height: 0;
width: 64px;
height: 64px;
flex-shrink: 0;
flex-grow: 0;
background-color: $secondary;
}

.card {
margin: 0 0 30px !important;
padding: 10px 0 !important;

.card-body {
padding: 20px;

.card-title {
margin: 0 0 8px;
padding: 20px 0 15px;
}

h4 {
color: $primary;
font-size: 28px;
font-weight: 700;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {ChangeDetectionStrategy, Component, Input} from '@angular/core';

@Component({
selector: 'app-counter-card',
templateUrl: './counter-card.component.html',
styleUrls: ['./counter-card.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class CounterCardComponent {

@Input() title: string
@Input() icon: string;
@Input() value: number;

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<div class="overview">
<app-admin-overview></app-admin-overview>
</div>
<div class="row">
<div class="col-xxl-4 col-md-6">
<app-user-counter-widget></app-user-counter-widget>
</div>
<div class="col-xxl-4 col-md-6">
<app-job-counter-widget></app-job-counter-widget>
</div>

<app-user-management-widget
title="Inscriptions récentes"
sortBy="registeredAt"
sortOrder="DESC"
[rows]="5"
></app-user-management-widget>
<app-user-management-widget
title="Inscriptions récentes"
sortBy="registeredAt"
sortOrder="DESC"
[rows]="5"
></app-user-management-widget>

</div>

<div class="pending-table card mt-4">
<div class="card-header pb-0 bg-primary text-light">
Expand All @@ -21,4 +27,3 @@ <h5 class="panel-title">Nouveaux groupes</h5>
</div>
<app-pending-group-table></app-pending-group-table>
</div>

This file was deleted.

Empty file.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<app-counter-card
icon="pi pi-briefcase"
[value]="jobCounter$ | async"
[title]="'Offres d\'emplois'"
></app-counter-card>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Component, OnInit } from '@angular/core';
import {JobService} from "../../../job/services/job.service";
import {Observable} from "rxjs";

@Component({
selector: 'app-job-counter-widget',
templateUrl: './job-counter-widget.component.html',
})
export class JobCounterWidgetComponent implements OnInit {

jobCounter$: Observable<number>

constructor(private jobService: JobService) { }

ngOnInit(): void {
this.jobCounter$ = this.jobService.getEnabledJobsCount();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<app-counter-card
icon="pi pi-users"
[value]="userCount$ | async"
[title]="'Utilisateurs activés'"
></app-counter-card>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {Component, OnInit} from '@angular/core';
import {UserService} from "../../../community/services/profile/user.service";
import {Observable} from "rxjs";

@Component({
selector: 'app-user-counter-widget',
templateUrl: './user-counter-widget.component.html',
})
export class UserCounterWidgetComponent implements OnInit {

userCount$: Observable<number>;

constructor(private userService: UserService) {
}

ngOnInit(): void {
this.userCount$ = this.userService.getEnabledUsersCount();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export class RelationButtonComponent implements OnInit, OnChanges {
}

private buildButtons(): RelationButton[] {
console.log(this.profile.username, [this.getCancelButton(), this.getOkButton()]);
return [this.getCancelButton(), this.getOkButton()].filter(b => b !== null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export enum ProfileMenuCode {

export class ProfileMenuEnum extends EnumCodeLabelAbstract<ProfileMenuCode> {

static readonly ALL = new ProfileMenuEnum(ProfileMenuCode.ALL, 'Tous les utilisateurs', null, `/${Univers.COMMUNITY.url}/profiles`);
static readonly ALL_FRIENDS = new ProfileMenuEnum(ProfileMenuCode.ALL_FRIENDS, 'Mes amis', null, `/${Univers.COMMUNITY.url}/profiles`);
static readonly ONLY_FRIEND_REQUESTS = new ProfileMenuEnum(ProfileMenuCode.ONLY_FRIEND_REQUESTS, 'Invitations', null, `/${Univers.COMMUNITY.url}/profiles`);
static readonly ALL = new ProfileMenuEnum(ProfileMenuCode.ALL, 'Tous les utilisateurs', null, `/${Univers.COMMUNITY.url}/profiles`, null);
static readonly ALL_FRIENDS = new ProfileMenuEnum(ProfileMenuCode.ALL_FRIENDS, 'Mes amis', null, `/${Univers.COMMUNITY.url}/profiles`, ProfileMenuCode.ALL_FRIENDS);
static readonly ONLY_FRIEND_REQUESTS = new ProfileMenuEnum(ProfileMenuCode.ONLY_FRIEND_REQUESTS, 'Invitations', null, `/${Univers.COMMUNITY.url}/profiles`, ProfileMenuCode.ONLY_FRIEND_REQUESTS);

constructor(readonly code: ProfileMenuCode, readonly label: string, readonly icon: string, readonly url: string) {
constructor(readonly code: ProfileMenuCode, readonly label: string, readonly icon: string, readonly url: string, readonly filter: ProfileMenuCode) {
super(code, label);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ export class ProfileListPageComponent implements OnInit, OnDestroy {
loading = true;
selectedItemMenuCode: ProfileMenuCode;
menuItems: MenuItem[] = ProfileMenuEnum.values()
.map((item: ProfileMenuEnum) => ({
id: item.code,
label: item.label,
routerLink: item.url,
queryParams: {filter: item.code},
routerLinkActiveOptions: {queryParams: 'subset'}
} as MenuItem));
.map((item: ProfileMenuEnum) => {
const menuItem = {
id: item.code,
label: item.label,
routerLink: item.url,
routerLinkActiveOptions: {queryParams: 'subset'}
} as MenuItem;
return item.filter ? {...menuItem, queryParams: {filter: item.filter}} : menuItem;
});

private onDestroySubject = new Subject<void>();
private onlyFriendRequestMenuItem: MenuItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ export class UserService {

}

getAll(pageable: Pageable<any>): Observable<Pageable<User>> {
getAll(pageable: Pageable<User>): Observable<Pageable<User>> {
return this.http.get(this.apiEndpointsService.getAllUserEndpoint(pageable));
}

getAllPendingActivationUsers(pageable: Pageable<User>): Observable<any> {
return this.http.get(this.apiEndpointsService.getAllPendingActivationUsersEndpoint(pageable));
}

enableUser(username: string): Observable<User> {
return this.http.post<User>(this.apiEndpointsService.getActivateUserEndpoint(username), null);
}

updateUserRoles(username: string, roles: RoleEnumCode[]): Observable<User> {
return this.http.post(this.apiEndpointsService.updateUserRolesEndpoint(username), roles);
}

getEnabledUsersCount(): Observable<number> {
return this.http.get<number>(this.apiEndpointsService.getEnabledUsersCount());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ export class ApiEndpointsService {
return ApiEndpointsService.createUrlWithPageable(Uris.USERS.BASE_URI, pageable);
}

getAllPendingActivationUsersEndpoint(pageable: Pageable<any>): string {
return ApiEndpointsService.createUrlWithPageable(Uris.USERS.GET_ALL_PENDING_USERS, pageable);
getEnabledUsersCount() {
return ApiEndpointsService.createUrl(Uris.USERS.ENABLED_USERS_COUNT);
}


Expand Down Expand Up @@ -330,6 +330,10 @@ export class ApiEndpointsService {
true);
}

getEnabledJobsCountEndpoint(): string {
return ApiEndpointsService.createUrl(Uris.JOBS.COUNT);
}

createJobPostingEndpoint(): string {
return ApiEndpointsService.createUrl(Uris.JOBS.BASE_URI);
}
Expand Down
Loading

0 comments on commit 525fb24

Please sign in to comment.