Skip to content

Commit

Permalink
NRPT-750: add enforcement text page. Updating config service (#855)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Truong authored May 11, 2021
1 parent f16dd0b commit cddac73
Show file tree
Hide file tree
Showing 26 changed files with 947 additions and 187 deletions.
4 changes: 1 addition & 3 deletions angular/projects/admin-nrpti/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ImportListResolver } from './import/import-list-resolver';
import { NewsResolver } from './news/news-resolver';
import { NewsListComponent } from './news/news-list.component';
import { CommunicationsComponent } from './communications/communications.component';
import { CommunicationsResolver } from './communications/communications.resolver';
import { LngMapInfoResolver } from './communications/lng-map-info/lng-map-info-resolver';

const routes: Routes = [
Expand Down Expand Up @@ -56,7 +55,6 @@ const routes: Routes = [
},
component: CommunicationsComponent,
resolve: {
communicationsPackage: CommunicationsResolver,
lngMapData: LngMapInfoResolver
}
}
Expand All @@ -75,4 +73,4 @@ const routes: Routes = [
exports: [RouterModule],
providers: []
})
export class AppRoutingModule {}
export class AppRoutingModule { }
2 changes: 0 additions & 2 deletions angular/projects/admin-nrpti/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import { NewsService } from './services/news.service';
import { ImportListResolver } from './import/import-list-resolver';
import { NewsResolver } from './news/news-resolver';
import { NewsListResolver } from './news/news-list.resolver';
import { CommunicationsResolver } from './communications/communications.resolver';

// guards
import { CanActivateGuard } from './guards/can-activate-guard.service';
Expand Down Expand Up @@ -135,7 +134,6 @@ export function overlayScrollFactory(overlay: Overlay): () => CloseScrollStrateg
ImportListResolver,
NewsResolver,
NewsListResolver,
CommunicationsResolver,
CanActivateGuard,
CanDeactivateGuard,
RecordUtils,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { FormGroup, FormControl } from '@angular/forms';
import { CommunicationsPackage } from '../../../../common/src/app/models/master/common-models/communications-package';
import { MapInfo } from './../../../../common/src/app/models/master/common-models/map-info';
import { FactoryService } from '../services/factory.service';
import { DatePickerComponent, LoadingScreenService, Utils } from 'nrpti-angular-components';
import { DatePickerComponent, LoadingScreenService, Utils, ConfigService } from 'nrpti-angular-components';
import { Constants } from '../utils/constants/misc';
import { ToastService } from '../services/toast.service';

@Component({
selector: 'communications-add',
Expand All @@ -35,26 +36,61 @@ export class CommunicationsComponent implements OnInit, OnDestroy {
browser_spellcheck: true,
height: 240,
plugins: ['lists, advlist, link'],
toolbar: [ 'undo redo | formatselect | ' +
' bold italic backcolor | alignleft aligncenter ' +
' alignright alignjustify | bullist numlist outdent indent |' +
' removeformat | help' ]
toolbar: ['undo redo | formatselect | ' +
' bold italic backcolor | alignleft aligncenter ' +
' alignright alignjustify | bullist numlist outdent indent |' +
' removeformat | help']
};

public datepickerMinDate = Constants.DatepickerMinDate;
private editing = false;
private commPackageId = '';

constructor(
public route: ActivatedRoute,
public router: Router,
private factoryService: FactoryService,
private utils: Utils,
private loadingScreenService: LoadingScreenService,
) {}
private configService: ConfigService,
private toastService: ToastService
) { }

ngOnInit() {
this.route.data.pipe(takeUntil(this.ngUnsubscribe)).subscribe((res: any) => {
this.commPackage = res.communicationsPackage.COMMUNICATIONS;
this.myForm = null;
this.selectedApplication = this.route.snapshot.params.application.toUpperCase();
switch (this.selectedApplication) {
case 'BCMI':
if (this.configService.config.COMMUNICATIONS_BCMI && this.configService.config.COMMUNICATIONS_BCMI.data) {
this.commPackage = this.configService.config.COMMUNICATIONS_BCMI.data;
this.commPackageId = this.configService.config.COMMUNICATIONS_BCMI._id;
this.editing = true;
} else {
this.commPackage = new CommunicationsPackage();
}
break;
case 'LNG':
if (this.configService.config.COMMUNICATIONS_LNG && this.configService.config.COMMUNICATIONS_LNG.data) {
this.commPackage = this.configService.config.COMMUNICATIONS_LNG.data;
this.commPackageId = this.configService.config.COMMUNICATIONS_LNG._id;
this.editing = true;
} else {
this.commPackage = new CommunicationsPackage();
}
break;
case 'NRCED':
if (this.configService.config.COMMUNICATIONS_NRCED && this.configService.config.COMMUNICATIONS_NRCED.data) {
this.commPackage = this.configService.config.COMMUNICATIONS_NRCED.data;
this.commPackageId = this.configService.config.COMMUNICATIONS_NRCED._id;
this.editing = true;
} else {
this.commPackage = new CommunicationsPackage();
}
break;
default:
break;
}
this.buildForm();
});
}
Expand All @@ -73,14 +109,14 @@ export class CommunicationsComponent implements OnInit, OnDestroy {
value: (this.commPackage &&
this.commPackage.startDate &&
this.utils.convertJSDateToNGBDate(new Date(this.commPackage.startDate))) ||
'',
'',
disabled: !this.checkRoles()
}),
endDate: new FormControl({
value: (this.commPackage &&
this.commPackage.endDate &&
this.utils.convertJSDateToNGBDate(new Date(this.commPackage.endDate))) ||
'',
'',
disabled: !this.checkRoles()
})
});
Expand All @@ -104,11 +140,39 @@ export class CommunicationsComponent implements OnInit, OnDestroy {
popup['description'] = this.myForm.get('description').value;
popup['startDate'] = this.utils.convertFormGroupNGBDateToJSDate(this.myForm.get('startDate').value);
popup['endDate'] = this.utils.convertFormGroupNGBDateToJSDate(this.myForm.get('endDate').value);
popup['application'] = this.selectedApplication;

this.factoryService.createCommunicationPackage(popup).subscribe(async (res: any) => {
popup['configApplication'] = this.selectedApplication;
popup['configType'] = 'communicationPackage';

try {
let res = null;
if (this.editing) {
res = await this.factoryService.editConfigData(popup, this.commPackageId, this.selectedApplication);
} else {
res = await this.factoryService.createConfigData(popup, this.selectedApplication);
}
switch (this.selectedApplication) {
case 'BCMI':
popup['enforcementActionText'] = res;
this.configService.config.COMMUNICATIONS_BCMI = res;
break;
case 'LNG':
this.configService.config.COMMUNICATIONS_LNG = res;
break;
case 'NRCED':
this.configService.config.COMMUNICATIONS_NRCED = res;
break;
default:
break;
}
this.loadingScreenService.setLoadingState(false, 'main');
});
this.toastService.addMessage('Enforcement text update', 'Success updated', Constants.ToastTypes.SUCCESS);
} catch (error) {
this.toastService.addMessage(
'An error has occured while saving and publishing',
'Save unsuccessful',
Constants.ToastTypes.ERROR
);
}
}

async cancel() {
Expand All @@ -122,11 +186,8 @@ export class CommunicationsComponent implements OnInit, OnDestroy {
popup['startDate'] = null;
popup['endDate'] = null;
popup['application'] = this.selectedApplication;

this.factoryService.createCommunicationPackage(popup).subscribe(async (res: any) => {
this.loadingScreenService.setLoadingState(false, 'main');
this.resetDates.emit();
});
this.resetDates.emit();
this.loadingScreenService.setLoadingState(false, 'main');
}


Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
<main class="container-fluid-padding">
<h1>All Enforcement Actions</h1>
<br />
<search-filter-template
#explorePanel
(searchEvent)='executeSearch($event)'
[title]="'Keyword Search'"
[tooltip]="'Enter an enforcement action to search for'"
[advancedFilters]="false">
</search-filter-template>
<div *ngIf="!tableData.totalListItems">
No Enforcement Actions found.
</div>

<div *ngIf="!tableData.totalListItems">
No Enforcement Actions found.
</div>

<lib-table-template
*ngIf="tableData.totalListItems > 0"
[data]="tableData"
(messageOut)="onMessageOut($event)"
></lib-table-template>
</main>
<lib-table-template *ngIf="tableData.totalListItems > 0"
[data]="tableData"
(messageOut)="onMessageOut($event)"></lib-table-template>
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ export class EnforcementActionsTableComponent implements OnInit, OnDestroy {

ngOnInit() {
this.loadingScreenService.setLoadingState(true, 'body');

this.tableData.options.showPageSizePicker = false;
this.tableData.options.showPageCountDisplay = false;
this.route.params.pipe(takeUntil(this.ngUnsubscribe)).subscribe((params: Params) => {
this.queryParams = { ...params };
// Get params from route, shove into the tableTemplateUtils so that we get a new dataset to work with.
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,30 @@ <h4 class="m-0">Enforcement Actions</h4>
</div>
</div>
</section>
<!-- <section>
<section>
<h5>
Page Text
</h5>
<span *ngIf="!pageTextEditing">
{{pageText}}
</span>
<p *ngIf="!pageTextExists"><span>There is currently no enforcement action text.</span></p>
<div *ngIf="!pageTextEditing" [innerHTML]="pageText"></div>
<span *ngIf="pageTextEditing">
<editor [init]="tinyMceSettings"
name="pageTextDraft"
id="pageTextDraft"
[ngModel]="pageTextDraft"></editor>
[(ngModel)]="pageTextDraft"></editor>
</span>
</section>

<section class="d-flex justify-content-end"
*ngIf="!pageTextEditing">
<button class="btn btn-primary"
(click)="setEditingMode()">
Edit
<span *ngIf="!pageTextExists">
Add
</span>
<span *ngIf="pageTextExists">
Edit
</span>
</button>
</section>
<section class="d-flex justify-content-end"
Expand All @@ -33,10 +38,32 @@ <h5>
(click)="cancelEditing()">
Cancel
</button>
<button class="btn btn-primary">
<button class="btn btn-primary"
(click)="saveText()">
Save & Publish
</button>
</section> -->
</section>

<section class="add-record mt-3">
<div class="row mt-3 mb-3">
<div class="col-12 text-right">
<div ngbDropdown
placement="bottom-right">
<button class="btn btn-primary"
ngbDropdownToggle>
Add Record
</button>
<div ngbDropdownMenu>
<button ngbDropdownItem
(click)="add('administrative-penalties')">Administrative Penalty</button>
<button ngbDropdownItem
(click)="add('court-convictions')">Court Conviction</button>
</div>
</div>
</div>
</div>
</section>

<section>
<app-enforcement-actions-table></app-enforcement-actions-table>
</section>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.add-record {
border-top: 1px solid lightgray;
}
Loading

0 comments on commit cddac73

Please sign in to comment.