-
Notifications
You must be signed in to change notification settings - Fork 925
Expand file tree
/
Copy pathedit-sms-campaign-step.component.ts
More file actions
148 lines (135 loc) · 4.3 KB
/
edit-sms-campaign-step.component.ts
File metadata and controls
148 lines (135 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* Copyright since 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/** Angular Imports */
import { Component, OnInit, Output, Input, EventEmitter, inject } from '@angular/core';
import {
UntypedFormGroup,
Validators,
UntypedFormBuilder,
UntypedFormControl,
ReactiveFormsModule
} from '@angular/forms';
/** Custom Services */
import { ReportsService } from 'app/reporting-plugin/services/reports.service';
/** Custom Models */
import { ReportParameter } from 'app/reporting-plugin/models/report-parameter.model';
import { SettingsService } from 'app/settings/settings.service';
import { MatCheckbox } from '@angular/material/checkbox';
import { EditBusinessRuleParametersComponent } from './edit-business-rule-parameters/edit-business-rule-parameters.component';
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
/**
* Edit SMS Campaign step.
*/
@Component({
selector: 'mifosx-edit-sms-campaign-step',
templateUrl: './edit-sms-campaign-step.component.html',
styleUrls: ['./edit-sms-campaign-step.component.scss'],
imports: [
...STANDALONE_SHARED_IMPORTS,
MatCheckbox,
EditBusinessRuleParametersComponent
]
})
export class EditSmsCampaignStepComponent implements OnInit {
private formBuilder = inject(UntypedFormBuilder);
private reportService = inject(ReportsService);
private settingsService = inject(SettingsService);
/** SMS Campaign Template */
@Input() smsCampaignTemplate: any;
/** SMS Campaign */
@Input() smsCampaign: any;
/** SMS Campaign Form */
smsCampaignDetailsForm: UntypedFormGroup;
/** Data to be passed to sub component */
paramData: any;
/** Trigger types options */
triggerTypes: any[];
/** SMS providers options */
smsProviders: any[];
/** Business Rules options */
businessRules: any[];
/** Repetition Intervals */
repetitionIntervals: any[];
/** Minimum Date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum Date allowed. */
maxDate = new Date();
/** Template Parameters Event Emitter */
@Output() templateParameters = new EventEmitter();
/**
* @param {FormBuilder} formBuilder Form Builder
* @param {ReportsService} reportService Reports Service
* @param {SettingsService} settingsService Settings Service.
*/
constructor() {
this.createSMSCampaignDetailsForm();
}
/**
* Initializes the SMS campaign form.
*/
createSMSCampaignDetailsForm() {
this.smsCampaignDetailsForm = this.formBuilder.group({
campaignName: [
'',
Validators.required
],
providerId: [null],
triggerType: [
'',
Validators.required
],
runReportId: [
'',
Validators.required
],
isNotification: [false]
});
}
ngOnInit() {
this.maxDate = this.settingsService.businessDate;
this.triggerTypes = this.smsCampaignTemplate.triggerTypeOptions;
this.smsProviders = this.smsCampaignTemplate.smsProviderOptions;
this.businessRules = this.smsCampaignTemplate.businessRulesOptions;
this.setControlValues();
this.getParameters();
}
/**
* Passes template parameters emitted from child to parent.
* @param {any} $event Template Parameters
*/
passParameters($event: any) {
this.templateParameters.emit($event);
}
/**
* Gets Template parameters and disables the SMS form.
*/
getParameters() {
this.reportService.getReportParams(this.smsCampaign.reportName).subscribe((response: ReportParameter[]) => {
this.paramData = response;
});
this.smsCampaignDetailsForm.disable();
}
/**
* Patches all control values as in API response.
*/
setControlValues() {
this.smsCampaignDetailsForm.patchValue({
campaignName: this.smsCampaign.campaignName,
providerId: this.smsCampaign.providerId,
triggerType: this.smsCampaign.triggerType.id,
runReportId: this.smsCampaign.runReportId,
isNotification: this.smsCampaign.isNotification
});
if (this.smsCampaign.triggerType.value === 'Schedule') {
this.smsCampaignDetailsForm.addControl(
'recurrenceStartDate',
new UntypedFormControl(new Date(this.smsCampaign.recurrenceStartDate))
);
}
}
}