Skip to content

Commit c79524d

Browse files
committed
lots of changes
1 parent cc1b2ef commit c79524d

24 files changed

+2508
-740
lines changed

service/src/models/event.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export type FormFieldChoiceDocument = FormFieldChoice & mongoose.Document & {
5353
}
5454

5555
export type TODO = any
56-
export type Callback<Result = unknown> = (err: Error | null, result?: Result) => void
56+
export type Callback<Result = unknown> = (err: Error | null, result?: Result, totalCount?: number) => void
5757

5858
export declare function count(options: TODO, callback: Callback<number>): void
5959
export declare function getEvents(options: TODO, callback: Callback<MageEventDocument[]>): void

service/src/models/event.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ exports.count = function (options, callback) {
321321
});
322322
};
323323

324-
exports.getEvents = function (options, callback) {
324+
exports.getEvents = async function (options, callback) {
325325
if (typeof options === 'function') {
326326
callback = options;
327327
options = {};
@@ -331,6 +331,14 @@ exports.getEvents = function (options, callback) {
331331
const filter = options.filter || {};
332332
if (filter.complete === true) query.complete = true;
333333
if (filter.complete === false) query.complete = { $ne: true };
334+
if (filter.teamId) query.teamIds = filter.teamId;
335+
if (filter.searchTerm) {
336+
const searchRegex = new RegExp(filter.searchTerm, 'i');
337+
query['$or'] = [
338+
{ name: searchRegex },
339+
{ description: searchRegex }
340+
];
341+
}
334342

335343
let projection = {};
336344
if (options.projection) {
@@ -341,6 +349,8 @@ exports.getEvents = function (options, callback) {
341349
projection.teamIds = true;
342350
}
343351

352+
const totalCount = await Event.count(query).exec();
353+
344354
Event.find(query, projection, function (err, events) {
345355
if (err) return callback(err);
346356

@@ -375,13 +385,16 @@ exports.getEvents = function (options, callback) {
375385

376386
if (options.populate) {
377387
Event.populate(events, [{ path: 'teamIds' }, { path: 'layerIds' }], function (err, events) {
378-
callback(err, events);
388+
callback(err, events, totalCount);
379389
});
380390
} else {
381-
callback(null, events);
391+
callback(null, events, totalCount);
382392
}
383393
});
384-
});
394+
})
395+
.sort({ name: 1, _id: 1 })
396+
.limit(options.limit || 1000)
397+
.skip(options.start * options.limit || 0);
385398
};
386399

387400
exports.getById = function (id, options, callback) {

service/src/routes/events.ts

Lines changed: 92 additions & 74 deletions
Large diffs are not rendered by default.

web-app/admin/src/app/admin/admin-event/events.service.ts

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@ import { Injectable } from '@angular/core';
22
import { HttpClient, HttpParams } from '@angular/common/http';
33
import { Observable } from 'rxjs';
44
import { User } from '@ngageoint/mage.web-core-lib/user';
5+
import { Event } from 'src/app/filter/filter.types';
56

67
export interface SearchOptions {
7-
populate?: boolean;
8-
limit?: number;
9-
sort?: { [key: string]: 1 | -1 };
10-
omit_event_teams?: boolean;
118
term?: string;
12-
start?: string;
9+
teamId?: string;
1310
id?: string;
11+
page?: number;
12+
page_size?: number;
13+
}
14+
15+
interface EventsResponse {
16+
pageSize?: number;
17+
page?: number;
18+
items: Event[];
19+
totalCount?: number;
1420
}
1521

1622
@Injectable({
@@ -20,53 +26,28 @@ export class EventsService {
2026

2127
constructor(private http: HttpClient) { }
2228

23-
getEvents(options: SearchOptions): Observable<any> {
29+
getEvents(options: SearchOptions): Observable<EventsResponse> {
2430
let params = new HttpParams();
2531

26-
if (options.populate !== undefined) {
27-
params = params.set('populate', String(options.populate));
28-
}
29-
if (options.limit !== undefined) {
30-
params = params.set('limit', String(options.limit));
31-
}
32-
if (options.sort !== undefined) {
33-
params = params.set('sort', JSON.stringify(options.sort));
34-
}
35-
if (options.omit_event_teams !== undefined) {
36-
params = params.set('omit_event_teams', String(options.omit_event_teams));
37-
}
3832
if (options.term !== undefined) {
3933
params = params.set('term', options.term);
4034
}
41-
if (options.start !== undefined) {
42-
params = params.set('start', options.start);
43-
}
44-
45-
return this.http.get('/api/events', { params });
46-
}
47-
48-
getNonMembers(options: SearchOptions): Observable<User[]> {
49-
let params = new HttpParams();
50-
51-
if (options.populate !== undefined) {
52-
params = params.set('populate', String(options.populate));
53-
}
54-
if (options.limit !== undefined) {
55-
params = params.set('limit', String(options.limit));
56-
}
57-
if (options.sort !== undefined) {
58-
params = params.set('sort', JSON.stringify(options.sort));
59-
}
60-
if (options.omit_event_teams !== undefined) {
61-
params = params.set('omit_event_teams', String(options.omit_event_teams));
35+
if (options.page !== undefined) {
36+
params = params.set('start', String(options.page));
6237
}
63-
if (options.term !== undefined) {
64-
params = params.set('term', options.term);
38+
if (options.page_size !== undefined) {
39+
params = params.set('limit', String(options.page_size));
6540
}
66-
if (options.start !== undefined) {
67-
params = params.set('start', options.start);
41+
if (options.teamId !== undefined) {
42+
params = params.set('teamId', options.teamId);
6843
}
6944

70-
return this.http.get<User[]>(`/api/events/${options.id}/nonMembers`, { params });
45+
params = params.set('includePagination', 'true');
46+
47+
return this.http.get<EventsResponse>('/api/events', { params });
48+
}
49+
50+
removeEvent(eventId: string): Observable<void> {
51+
return this.http.delete<void>(`/api/events/${eventId}`);
7152
}
7253
}

web-app/admin/src/app/admin/admin-teams/admin-teams.module.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { MatDialogModule } from '@angular/material/dialog';
88
import { MatFormFieldModule } from '@angular/material/form-field';
99
import { MatInputModule } from '@angular/material/input';
1010
import { MatButtonModule } from '@angular/material/button';
11+
import { MatCheckboxModule } from '@angular/material/checkbox';
12+
import { MatIconModule } from '@angular/material/icon';
13+
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
1114

1215
import { TeamDashboardComponent } from './dashboard/team-dashboard.component';
1316
import { CreateTeamDialogComponent } from './create-team/create-team.component';
@@ -16,13 +19,15 @@ import { EventsService } from '../admin-event/events.service';
1619
import { TeamDetailsComponent } from './team-details/team-details.component';
1720
import { CoreModule } from '../../core/core.module';
1821
import { DeleteTeamComponent } from './delete-team/delete-team.component';
22+
import { SearchModalComponent } from './search-modal/search-modal.component';
1923

2024
@NgModule({
2125
declarations: [
2226
TeamDashboardComponent,
2327
CreateTeamDialogComponent,
2428
TeamDetailsComponent,
25-
DeleteTeamComponent
29+
DeleteTeamComponent,
30+
SearchModalComponent
2631
],
2732
imports: [
2833
CommonModule,
@@ -35,15 +40,19 @@ import { DeleteTeamComponent } from './delete-team/delete-team.component';
3540
MatDialogModule,
3641
MatFormFieldModule,
3742
MatInputModule,
38-
MatButtonModule
43+
MatButtonModule,
44+
MatCheckboxModule,
45+
MatIconModule,
46+
MatProgressSpinnerModule
3947
],
4048
providers: [
4149
TeamsService,
4250
EventsService
4351
],
4452
entryComponents: [
4553
CreateTeamDialogComponent,
46-
DeleteTeamComponent
54+
DeleteTeamComponent,
55+
SearchModalComponent
4756
]
4857
})
4958
export class AdminTeamsModule { }
Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
1-
<div class="admin-team-create">
2-
<h1 mat-dialog-title>New Team</h1>
3-
<div mat-dialog-content>
4-
<div *ngIf="errorMessage" class="error-message" style="color: red; margin-bottom: 16px;">
5-
{{ errorMessage }}
1+
<div class="modern-dialog">
2+
<div class="dialog-header">
3+
<h2 class="dialog-title">Create a New Team</h2>
4+
</div>
5+
6+
<div class="dialog-content">
7+
<div *ngIf="errorMessage" class="error-alert">
8+
<i class="fa fa-exclamation-triangle"></i>
9+
<span>{{ errorMessage }}</span>
610
</div>
7-
<form [formGroup]="teamForm">
8-
<mat-form-field class="full-width">
9-
<mat-label>Name</mat-label>
10-
<input matInput formControlName="name" required>
11-
<mat-error *ngIf="teamForm.get('name').hasError('required')">
11+
12+
<form [formGroup]="teamForm" class="team-form">
13+
<div class="form-field">
14+
<label class="field-label">Team Name</label>
15+
<input type="text" class="form-input" formControlName="name" placeholder="Enter team name">
16+
<div *ngIf="teamForm.get('name').hasError('required')" class="field-error">
17+
<i class="fa fa-exclamation-circle"></i>
1218
Name is required
13-
</mat-error>
14-
</mat-form-field>
15-
<mat-form-field class="full-width">
16-
<mat-label>Description</mat-label>
17-
<textarea matInput formControlName="description"></textarea>
18-
</mat-form-field>
19+
</div>
20+
</div>
21+
22+
<div class="form-field">
23+
<label class="field-label">Description</label>
24+
<textarea class="form-input" formControlName="description" rows="3"
25+
placeholder="Enter team description (optional)"></textarea>
26+
</div>
1927
</form>
2028
</div>
21-
<div mat-dialog-actions>
22-
<button mat-button (click)="cancel()">Cancel</button>
23-
<button mat-button color="primary" (click)="save()" [disabled]="teamForm.invalid">Save</button>
29+
30+
<div class="dialog-actions">
31+
<button class="action-button" (click)="cancel()">Cancel</button>
32+
<button class="action-button btn-primary" (click)="save()" [disabled]="teamForm.invalid">
33+
<i class="fa fa-save"></i>
34+
Create Team
35+
</button>
2436
</div>
2537
</div>

0 commit comments

Comments
 (0)