Skip to content

Commit

Permalink
Merge pull request #776 from Ckoelewyn/PUBLIC-18
Browse files Browse the repository at this point in the history
Public 18
  • Loading branch information
Ckoelewyn authored Sep 17, 2024
2 parents 709864d + 25757fd commit ea99dd9
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,25 @@ <h2>Activity Post</h2>
<div *ngIf="typeIsPCP && !projectIsSelected" class="alert alert-warning" role="alert">
Please select a project.
</div>
<div *ngIf="typeIsProjectNotificationNews && !projectIsSelected" class="alert alert-warning" role="alert">
Please select a Project Notification.
</div>
<div *ngIf="typeIsPCP && projectIsSelected && periods.length === 0" class="alert alert-warning" role="alert">
No public comment periods exist for selected project.
</div>
<div class="flex-container">
<div class="flex-container">
<div class="label-pair med">
<label *ngIf="!typeIsPCP" for="project">Project </label>
<label *ngIf="!typeIsPCP && !typeIsProjectNotificationNews" for="project">Project </label>
<label *ngIf="typeIsPCP" for="project">Project* </label>
<select [required]="typeIsPCP" class="form-control" formControlName="project" (change)="updateProject()">
<option *ngFor="let project of projects" [ngValue]="project._id">{{project.name}}</option>
<label *ngIf="typeIsProjectNotificationNews" for="project">Project Notification* </label>
<select [required]="typeIsPCP || typeIsProjectNotificationNews"
class="form-control"
formControlName="project"
(change)="updateProject()">
<option *ngFor="let item of (typeIsPCP ? projects : (typeIsProjectNotificationNews ? projectNotifications : []))"
[ngValue]="item._id">
{{item.name}}
</option>
</select>
</div>
</div>
Expand Down
50 changes: 35 additions & 15 deletions src/app/activity/add-edit-activity/add-edit-activity.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Component, OnInit, OnDestroy, ChangeDetectorRef } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { Subject } from 'rxjs';
import { Subject, Subscription } from 'rxjs';
import { ProjectService } from 'app/services/project.service';
import { NotificationProjectService } from 'app/services/notification-project.service';
import { RecentActivityService } from 'app/services/recent-activity';
import { RecentActivity } from 'app/models/recentActivity';
import { Utils } from 'app/shared/utils/utils';
Expand All @@ -17,15 +18,19 @@ import { MatSnackBar } from '@angular/material';
export class AddEditActivityComponent implements OnInit, OnDestroy {
public myForm: FormGroup;
public isEditing = false;
// private subscriptions: Subscription[] = [];
private subscriptions = new Subscription();
private ngUnsubscribe: Subject<boolean> = new Subject<boolean>();
public loading = true;
public projects = [];
public projectNotifications = [];
public types = [];
public activityTypes = Constants.activityTypes.map(type => type.name);
public periods = [];
public activity: any;
public typeIsPCP = false;
public typeIsNotification = false;
public typeIsProjectNotificationNews = false;
public projectIsSelected = false;
public snackBarTimeout = 1500;
public isPublished = false;
Expand All @@ -48,15 +53,15 @@ export class AddEditActivityComponent implements OnInit, OnDestroy {
private snackBar: MatSnackBar,
private recentActivityService: RecentActivityService,
private projectService: ProjectService,
private notificationProjectService: NotificationProjectService,
private commentPeriodService: CommentPeriodService,
private _changeDetectorRef: ChangeDetectorRef
) { }

ngOnInit() {
this.route.data
.takeUntil(this.ngUnsubscribe)
.subscribe(res => {
if (Object.keys(res).length === 0 && res.constructor === Object) {
ngOnInit() {
this.subscriptions.add(
this.route.data.subscribe(res => {
if (Object.keys(res).length === 0 && res.constructor === Object) {
this.isPublished = false;
this.buildForm({
'headline': '',
Expand All @@ -81,10 +86,11 @@ export class AddEditActivityComponent implements OnInit, OnDestroy {
this.updateProject();
this.updateType();
}
})
);

this.projectService.getAll(1, 1000, '+name')
.takeUntil(this.ngUnsubscribe)
.subscribe((res2: any) => {
this.subscriptions.add(
this.projectService.getAll(1, 1000, '+name').subscribe((res2: any) => {
if (res2) {
this.projects = res2.data;
// TODO: Later
Expand All @@ -101,9 +107,17 @@ export class AddEditActivityComponent implements OnInit, OnDestroy {

this.loading = false;
this._changeDetectorRef.detectChanges();
});
});
}
})
);

this.subscriptions.add(
this.notificationProjectService.getAll(1, 1000, '+name').subscribe((res3: any) => {
if (res3) {
this.projectNotifications = res3.data;
}
})
);
}

onCancel() {
this.router.navigate(['/activity']);
Expand All @@ -120,7 +134,6 @@ export class AddEditActivityComponent implements OnInit, OnDestroy {
type: this.myForm.get('type').value,
pcp: this.myForm.get('pcp').value,
notificationName: this.myForm.get('type').value === 'Project Notification Public Comment Period' ? this.myForm.controls.notificationName.value : null,

contentUrl: this.myForm.controls.contentUrl.value,
documentUrl: this.myForm.controls.documentUrl.value,
active: this.isPublished,
Expand Down Expand Up @@ -169,6 +182,7 @@ export class AddEditActivityComponent implements OnInit, OnDestroy {
if (this.myForm.get('type').value === this.activityTypes[0]) {
this.typeIsPCP = true;
this.typeIsNotification = false;
this.typeIsProjectNotificationNews = false;
this.myForm.get('pcp').enable();
this.myForm.get('project').enable();
if (this.projectIsSelected) {
Expand All @@ -180,9 +194,16 @@ export class AddEditActivityComponent implements OnInit, OnDestroy {
this.myForm.controls['project'].reset({ value: '', disabled: true });
this.myForm.controls['pcp'].reset({ value: '', disabled: true });
this.typeIsPCP = false;
} else if (this.myForm.get('type').value === this.activityTypes[3]) { // projectNotificationNews
this.typeIsNotification = false;
this.typeIsPCP = false;
this.typeIsProjectNotificationNews = true;
this.myForm.get('project').enable();
this.myForm.controls['pcp'].reset({ value: '', disabled: true });
} else {
this.typeIsPCP = false;
this.typeIsNotification = false;
this.typeIsProjectNotificationNews = false;
this.myForm.get('project').enable();
this.myForm.controls['pcp'].reset({ value: '', disabled: true });
}
Expand Down Expand Up @@ -247,7 +268,6 @@ export class AddEditActivityComponent implements OnInit, OnDestroy {
}

ngOnDestroy() {
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
this.subscriptions.unsubscribe();
}
}
2 changes: 2 additions & 0 deletions src/app/models/recentActivity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export class RecentActivity {
_id: string;
project: any;
projectNotification: any;
type: string;
pcp: any;
dateAdded: string;
Expand All @@ -18,6 +19,7 @@ export class RecentActivity {
this.type = obj && obj.type || null;
this.pcp = obj && obj.pcp || null;
this.project = obj && obj.project || null;
this.projectNotification = obj && obj.projectNotification || null;
this.dateAdded = obj && obj.dateAdded || null;
this.content = obj && obj.content || null;
this.documentUrl = obj && obj.documentUrl || null;
Expand Down
18 changes: 18 additions & 0 deletions src/app/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,24 @@ export class ApiService {
//
// Project Notifications
//

getProjectNotifications(pageNum: number, pageSize: number, sortBy: string, populate: Boolean = true): Observable<Object> {
const fields = [
'name',
'epicProjectID',
'location',
'decisionDate'
];

let queryString = `projectNotification?`;
if (pageNum !== null) { queryString += `pageNum=${pageNum - 1}&`; }
if (pageSize !== null) { queryString += `pageSize=${pageSize}&`; }
if (sortBy !== '' && sortBy !== null) { queryString += `sortBy=${sortBy}&`; }
if (populate !== null) { queryString += `populate=${populate}&`; }
queryString += `fields=${this.buildValues(fields)}`;
return this.http.get<Object>(`${this.pathAPI}/${queryString}`, {});
}

saveNotificationProject(projectNotification: ProjectNotification, publish: boolean): Observable<ProjectNotification> {
let queryString = `projectNotification/${projectNotification._id}`;
if (publish !== null) {
Expand Down
20 changes: 19 additions & 1 deletion src/app/services/notification-project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,27 @@ import { ProjectNotification } from 'app/models/projectNotification';

@Injectable()
export class NotificationProjectService {

private projectNotificationList: ProjectNotification[] = [];
constructor(private api: ApiService) { }


// get all project notifications

getAll(pageNum: number = 1, pageSize: number = 20, sortBy: string = null): Observable<Object> {
return this.api.getProjectNotifications(pageNum, pageSize, sortBy)
.map((res: any) => {
if (res) {
this.projectNotificationList = [];
res.forEach(projectNotification => {
this.projectNotificationList.push(new ProjectNotification(projectNotification));
});
return { totalCount: res.length, data: this.projectNotificationList };
}
return {};
})
.catch(error => this.api.handleError(error));
}

save(notificationProject: ProjectNotification, publish: boolean = null): Observable<ProjectNotification> {
return this.api.saveNotificationProject(notificationProject, publish)
.catch(error => this.api.handleError(error));
Expand Down
3 changes: 2 additions & 1 deletion src/app/shared/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ export class Constants {
public static readonly activityTypes = [
{ code: 'pcp', name: 'Public Comment Period' },
{ code: 'notification', name: 'Project Notification Public Comment Period' },
{ code: 'news', name: 'News' }
{ code: 'news', name: 'News' },
{ code: 'projectNotificationNews', name: 'Project Notification News' }
];

public static readonly documentTypes = {
Expand Down

0 comments on commit ea99dd9

Please sign in to comment.