feat: add view sms campaign page (#835)
Fixes: #563 Co-authored-by: Ashutosh Sharma <b18010@students.iitmandi.ac.in>
This commit is contained in:
co-authored by
Ashutosh Sharma
parent
b1b015833c
commit
14516d2ac2
@@ -38,6 +38,7 @@ import { ViewHolidaysComponent } from './holidays/view-holidays/view-holidays.co
|
||||
import { ViewOfficeComponent } from './offices/view-office/view-office.component';
|
||||
import { GeneralTabComponent } from './offices/view-office/general-tab/general-tab.component';
|
||||
import { DatatableTabsComponent } from './offices/view-office/datatable-tabs/datatable-tabs.component';
|
||||
import { ViewCampaignComponent } from './sms-campaigns/view-campaign/view-campaign.component';
|
||||
|
||||
/** Custom Resolvers */
|
||||
import { LoanProvisioningCriteriaResolver } from './loan-provisioning-criteria/loan-provisioning-criteria.resolver';
|
||||
@@ -46,7 +47,7 @@ import { EmployeesResolver } from './employees/employees.resolver';
|
||||
import { EmployeeResolver } from './employees/employee.resolver';
|
||||
import { EditEmployeeResolver } from './employees/edit-employee.resolver';
|
||||
import { CurrenciesResolver } from './currencies/currencies.resolver';
|
||||
import { SmsCampaignsResolver } from './sms-campaigns/sms-campaigns.resolver';
|
||||
import { SmsCampaignsResolver } from './sms-campaigns/common-resolvers/sms-campaigns.resolver';
|
||||
import { AdhocQueriesResolver } from './adhoc-query/adhoc-queries.resolver';
|
||||
import { AdhocQueryResolver } from './adhoc-query/adhoc-query.resolver';
|
||||
import { TellersResolver } from './tellers/tellers.resolver';
|
||||
@@ -66,6 +67,7 @@ import { HolidayResolver } from './holidays/holiday.resolver';
|
||||
import { OfficeResolver } from './offices/common-resolvers/office.resolver';
|
||||
import { OfficeDatatableResolver } from './offices/common-resolvers/office-datatable.resolver';
|
||||
import { OfficeDatatablesResolver } from './offices/common-resolvers/office-datatables.resolver';
|
||||
import { SmsCampaignResolver } from './sms-campaigns/common-resolvers/sms-campaign.resolver';
|
||||
|
||||
/** Organization Routes */
|
||||
const routes: Routes = [
|
||||
@@ -222,11 +224,24 @@ const routes: Routes = [
|
||||
},
|
||||
{
|
||||
path: 'sms-campaigns',
|
||||
component: SmsCampaignsComponent,
|
||||
data: { title: extract('SMS Campaigns'), breadcrumb: 'SMS Campaigns' },
|
||||
resolve: {
|
||||
smsCampaigns: SmsCampaignsResolver
|
||||
}
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
component: SmsCampaignsComponent,
|
||||
resolve: {
|
||||
smsCampaigns: SmsCampaignsResolver
|
||||
}
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
component: ViewCampaignComponent,
|
||||
data: { title: extract('View SMS Campaign'), routeResolveBreadcrumb: ['smsCampaign', 'campaignName'] },
|
||||
resolve: {
|
||||
smsCampaign: SmsCampaignResolver
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: 'adhoc-query',
|
||||
@@ -421,6 +436,7 @@ const routes: Routes = [
|
||||
EditEmployeeResolver,
|
||||
CurrenciesResolver,
|
||||
SmsCampaignsResolver,
|
||||
SmsCampaignResolver,
|
||||
AdhocQueriesResolver,
|
||||
AdhocQueryResolver,
|
||||
TellersResolver,
|
||||
|
||||
@@ -41,6 +41,7 @@ import { GeneralTabComponent } from './offices/view-office/general-tab/general-t
|
||||
import { DatatableTabsComponent } from './offices/view-office/datatable-tabs/datatable-tabs.component';
|
||||
import { SingleRowComponent } from './offices/view-office/datatable-tabs/single-row/single-row.component';
|
||||
import { MultiRowComponent } from './offices/view-office/datatable-tabs/multi-row/multi-row.component';
|
||||
import { ViewCampaignComponent } from './sms-campaigns/view-campaign/view-campaign.component';
|
||||
|
||||
/**
|
||||
* Organization Module
|
||||
@@ -87,7 +88,8 @@ import { MultiRowComponent } from './offices/view-office/datatable-tabs/multi-ro
|
||||
GeneralTabComponent,
|
||||
DatatableTabsComponent,
|
||||
SingleRowComponent,
|
||||
MultiRowComponent
|
||||
MultiRowComponent,
|
||||
ViewCampaignComponent
|
||||
]
|
||||
})
|
||||
export class OrganizationModule { }
|
||||
|
||||
@@ -173,6 +173,28 @@ export class OrganizationService {
|
||||
return this.http.get('/smscampaigns');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} smsCampaignId SMS Campaign ID of SMS Campaign.
|
||||
* @returns {Observable<any>} SMS Campaign.
|
||||
*/
|
||||
getSmsCampaign(smsCampaignId: string): Observable<any> {
|
||||
return this.http.get(`/smscampaigns/${smsCampaignId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} SMS
|
||||
* @returns {Observable<any>} Messages Data
|
||||
*/
|
||||
getMessagebyStatus(SMS: any): Observable<any> {
|
||||
let httpParams = new HttpParams()
|
||||
.set('status', SMS.status.toString())
|
||||
.set('locale', SMS.locale)
|
||||
.set('dateFormat', SMS.dateFormat);
|
||||
httpParams = SMS.fromDate ? httpParams.set('fromDate', SMS.fromDate) : httpParams;
|
||||
httpParams = SMS.toDate ? httpParams.set('toDate', SMS.toDate) : httpParams;
|
||||
return this.http.get(`/sms/${SMS.id}/messageByStatus`, { params: httpParams });
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Observable<any>} Adhoc Queries data
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/** Angular Imports */
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Resolve, ActivatedRouteSnapshot } from '@angular/router';
|
||||
|
||||
/** rxjs Imports */
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
/** Custom Services */
|
||||
import { OrganizationService } from 'app/organization/organization.service';
|
||||
|
||||
/**
|
||||
* SMS Campaign data resolver.
|
||||
*/
|
||||
@Injectable()
|
||||
export class SmsCampaignResolver implements Resolve<Object> {
|
||||
|
||||
/**
|
||||
* @param {OrganizationService} organizationService Organization service.
|
||||
*/
|
||||
constructor(private organizationService: OrganizationService) {}
|
||||
|
||||
/**
|
||||
* Returns the SMS Campaign data.
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
resolve(route: ActivatedRouteSnapshot): Observable<any> {
|
||||
const smsCampaignId = route.paramMap.get('id');
|
||||
return this.organizationService.getSmsCampaign(smsCampaignId);
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -6,7 +6,7 @@ import { Resolve } from '@angular/router';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
/** Custom Services */
|
||||
import { OrganizationService } from '../organization.service';
|
||||
import { OrganizationService } from '../../organization.service';
|
||||
|
||||
/**
|
||||
* SMS Campaigns data resolver.
|
||||
@@ -55,7 +55,7 @@
|
||||
</ng-container>
|
||||
|
||||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;" class="select-row"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;" class="select-row" [routerLink]="[row.id]"></tr>
|
||||
|
||||
</table>
|
||||
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
<div class="container">
|
||||
|
||||
<div fxLayout="row" fxLayoutGap="1%" fxLayoutAlign="flex-end" class="action-buttons m-b-20">
|
||||
<span *ngIf="smsCampaignData.campaignStatus.value !== 'active'">
|
||||
<button mat-raised-button color="primary" *mifosxHasPermission="'UPDATE_SMSCAMPAIGN'">
|
||||
<fa-icon icon="edit"></fa-icon> Edit
|
||||
</button>
|
||||
</span>
|
||||
<span *ngIf="smsCampaignData.campaignStatus.value === 'Pending'">
|
||||
<button mat-raised-button color="accent" *mifosxHasPermission="'ACTIVATE_SMSCAMPAIGN'">
|
||||
<fa-icon icon="lock-open"></fa-icon> Activate
|
||||
</button>
|
||||
</span>
|
||||
<span *ngIf="smsCampaignData.campaignStatus.value !== 'closed'">
|
||||
<button mat-raised-button color="warn" *mifosxHasPermission="'CLOSE_SMSCAMPAIGN'">
|
||||
<fa-icon icon="times"></fa-icon> Close
|
||||
</button>
|
||||
</span>
|
||||
<span *ngIf="smsCampaignData.campaignStatus.value !== 'Pending' && smsCampaignData.campaignStatus.value !== 'active'">
|
||||
<button mat-raised-button color="accent" *mifosxHasPermission="'REACTIVATE_SMSCAMPAIGN'">
|
||||
<fa-icon icon="undo"></fa-icon> Reactivate
|
||||
</button>
|
||||
</span>
|
||||
<span *ngIf="smsCampaignData.campaignStatus.value === 'closed'">
|
||||
<button mat-raised-button color="warn" *mifosxHasPermission="'DELETE_SMSCAMPAIGN'">
|
||||
<fa-icon icon="trash"></fa-icon> Delete
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<mat-card class="sms-card">
|
||||
|
||||
<mat-card-content>
|
||||
|
||||
<mat-tab-group (selectedTabChange)="onTabChange($event)">
|
||||
|
||||
<mat-tab label="Campaign">
|
||||
|
||||
<div class="tab-content mat-typography">
|
||||
|
||||
<mat-list>
|
||||
<mat-list-item>
|
||||
Campaign Name : {{ smsCampaignData.campaignName }}
|
||||
</mat-list-item>
|
||||
<mat-list-item>
|
||||
Report Name : {{ smsCampaignData.reportName }}
|
||||
</mat-list-item>
|
||||
<mat-list-item>
|
||||
Status : {{ smsCampaignData.campaignStatus.value }}
|
||||
</mat-list-item>
|
||||
<mat-list-item>
|
||||
Trigger Type : {{ smsCampaignData.triggerType.value }}
|
||||
</mat-list-item>
|
||||
<mat-list-item>
|
||||
Submitted on : {{ smsCampaignData.smsCampaignTimeLine.submittedOnDate | date}}
|
||||
</mat-list-item>
|
||||
<div fxLayout="column" fxLayoutGap="10px" class="template-message">
|
||||
<h3>Template Message :</h3>
|
||||
<textarea matInput disabled>{{ smsCampaignData.campaignMessage}}</textarea>
|
||||
</div>
|
||||
</mat-list>
|
||||
|
||||
</div>
|
||||
|
||||
</mat-tab>
|
||||
|
||||
<mat-tab *ngFor = "let tab of smsTabs" [label]="tab.label">
|
||||
|
||||
<div class="tab-content mat-typography">
|
||||
|
||||
<form [formGroup]="smsForm" (ngSubmit)="search()">
|
||||
<div fxLayout="row" fxLayoutGap="3%" fxLayoutAlign="center">
|
||||
<mat-form-field>
|
||||
<mat-label>From Date</mat-label>
|
||||
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="fromDatePicker" formControlName="fromDate">
|
||||
<mat-datepicker-toggle matSuffix [for]="fromDatePicker"></mat-datepicker-toggle>
|
||||
<mat-datepicker #fromDatePicker></mat-datepicker>
|
||||
</mat-form-field>
|
||||
<mat-form-field>
|
||||
<mat-label>To Date</mat-label>
|
||||
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="toDatePicker" formControlName="toDate">
|
||||
<mat-datepicker-toggle matSuffix [for]="toDatePicker"></mat-datepicker-toggle>
|
||||
<mat-datepicker #toDatePicker></mat-datepicker>
|
||||
</mat-form-field>
|
||||
<div class="search-button" >
|
||||
<button mat-raised-button color="primary">
|
||||
<fa-icon icon="search"></fa-icon> Search</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="mat-elevation-z1 m-b-25">
|
||||
<table #messageTable mat-table [dataSource]="dataSource">
|
||||
<ng-container matColumnDef="Message">
|
||||
<th mat-header-cell *matHeaderCellDef> Message </th>
|
||||
<td mat-cell *matCellDef="let sms">{{sms.message}}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="Status">
|
||||
<th mat-header-cell *matHeaderCellDef> Status </th>
|
||||
<td mat-cell *matCellDef="let sms">{{sms.status.value}}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="Mobile No.">
|
||||
<th mat-header-cell *matHeaderCellDef> Mobile No. </th>
|
||||
<td mat-cell *matCellDef="let sms">{{sms.mobileNo}} </td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="Campaign Name">
|
||||
<th mat-header-cell *matHeaderCellDef> Campaign Name </th>
|
||||
<td mat-cell *matCellDef="let sms">{{sms.campaignName}}</td>
|
||||
</ng-container>
|
||||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</mat-tab>
|
||||
|
||||
</mat-tab-group>
|
||||
|
||||
</mat-card-content>
|
||||
|
||||
</mat-card>
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,21 @@
|
||||
.action-buttons {
|
||||
width: 88.75%;
|
||||
}
|
||||
.sms-card {
|
||||
margin: 0 auto;
|
||||
width: 77.5%;
|
||||
padding: 0;
|
||||
.tab-content {
|
||||
padding: 1%;
|
||||
margin: 1%;
|
||||
.template-message {
|
||||
padding-inline: 1.5%;
|
||||
margin-top: 1%;
|
||||
}
|
||||
.search-button {
|
||||
max-width: 3%;
|
||||
max-height: 2%;
|
||||
padding-block: 2.25%;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ViewCampaignComponent } from './view-campaign.component';
|
||||
|
||||
describe('ViewCampaignComponent', () => {
|
||||
let component: ViewCampaignComponent;
|
||||
let fixture: ComponentFixture<ViewCampaignComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ ViewCampaignComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ViewCampaignComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,132 @@
|
||||
/** Angular Imports */
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { FormGroup, FormBuilder } from '@angular/forms';
|
||||
import { MatTableDataSource, MatTable } from '@angular/material';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { DatePipe } from '@angular/common';
|
||||
|
||||
/** Custom Services */
|
||||
import { OrganizationService } from '../../organization.service';
|
||||
|
||||
/**
|
||||
* View SMS Campaign Component
|
||||
*/
|
||||
@Component({
|
||||
selector: 'mifosx-view-campaign',
|
||||
templateUrl: './view-campaign.component.html',
|
||||
styleUrls: ['./view-campaign.component.scss']
|
||||
})
|
||||
export class ViewCampaignComponent implements OnInit {
|
||||
|
||||
/** Minimum date allowed. */
|
||||
minDate = new Date(2000, 0, 1);
|
||||
/** Maximum date allowed. */
|
||||
maxDate = new Date();
|
||||
/** SMS form. */
|
||||
smsForm: FormGroup;
|
||||
/** SMS Campaign data. */
|
||||
smsCampaignData: any;
|
||||
/** Message Status */
|
||||
status: any;
|
||||
/** Data Table Columns */
|
||||
displayedColumns: string[] = ['Message', 'Status', 'Mobile No.', 'Campaign Name'];
|
||||
/** Data source for SMS campaigns table. */
|
||||
dataSource = new MatTableDataSource();
|
||||
|
||||
/** Message Table Reference */
|
||||
@ViewChild('messageTable') messageTableRef: MatTable<Element>;
|
||||
|
||||
/** SMS Camapaign Tabs */
|
||||
smsTabs: any[] = [
|
||||
{
|
||||
label: 'Pending SMS',
|
||||
status: 100
|
||||
},
|
||||
{
|
||||
label: 'Waiting for Delivery Report',
|
||||
status: 150
|
||||
},
|
||||
{
|
||||
label: 'Sent SMS',
|
||||
status: 200
|
||||
},
|
||||
{
|
||||
label: 'Delivered SMS',
|
||||
status: 300
|
||||
},
|
||||
{
|
||||
label: 'Failed SMS',
|
||||
status: 400
|
||||
}
|
||||
];
|
||||
|
||||
/**
|
||||
* Retrieves the SMS Campaign data from `resolve`
|
||||
* @param {ActivatedRoute} route Activated Route
|
||||
* @param {FormBuilder} formBuilder Form Builder
|
||||
* @param {DatePipe} datePipe Date Pipe
|
||||
* @param {OrganizationService} organizationService Organization Service
|
||||
*/
|
||||
constructor(private route: ActivatedRoute,
|
||||
private formBuilder: FormBuilder,
|
||||
private datePipe: DatePipe,
|
||||
private organizationService: OrganizationService) {
|
||||
this.route.data.subscribe((data: { smsCampaign: any }) => {
|
||||
this.smsCampaignData = data.smsCampaign;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
ngOnInit() {
|
||||
this.createSMSForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the SMS form.
|
||||
*/
|
||||
createSMSForm() {
|
||||
this.smsForm = this.formBuilder.group({
|
||||
'fromDate': [''],
|
||||
'toDate': [''],
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets status for messages on tab change.
|
||||
* Clears data in messages table if any.
|
||||
* Resets the search form.
|
||||
* @param {any} $event Tab change event.
|
||||
*/
|
||||
onTabChange($event: any) {
|
||||
const selectedTabName = $event.tab ? $event.tab.textLabel : 'Campaign';
|
||||
const tab = this.smsTabs.find((entry: any) => selectedTabName === entry.label);
|
||||
this.status = tab ? tab.status : undefined;
|
||||
this.dataSource.data = [];
|
||||
this.messageTableRef.renderRows();
|
||||
this.smsForm.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrives messages by status.
|
||||
*/
|
||||
search() {
|
||||
const prevFromDate: Date = this.smsForm.value.fromDate;
|
||||
const prevToDate: Date = this.smsForm.value.toDate;
|
||||
// TODO: Update once language and date settings are setup
|
||||
const dateFormat = 'yyyy-MM-dd';
|
||||
this.smsForm.patchValue({
|
||||
fromDate: this.datePipe.transform(prevFromDate, dateFormat),
|
||||
toDate: this.datePipe.transform(prevToDate, dateFormat)
|
||||
});
|
||||
const SMS = this.smsForm.value;
|
||||
SMS.id = this.smsCampaignData.id;
|
||||
SMS.locale = 'en';
|
||||
SMS.dateFormat = dateFormat;
|
||||
SMS.status = this.status;
|
||||
this.organizationService.getMessagebyStatus(SMS).subscribe((response: any) => {
|
||||
this.dataSource.data = response.pageItems;
|
||||
this.messageTableRef.renderRows();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user