feat: add view sms campaign page (#835)

Fixes: #563
Co-authored-by: Ashutosh Sharma  <b18010@students.iitmandi.ac.in>
This commit is contained in:
Karan Takalkar
2020-06-01 21:48:51 +05:30
committed by GitHub
co-authored by Ashutosh Sharma
parent b1b015833c
commit 14516d2ac2
10 changed files with 382 additions and 8 deletions
@@ -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);
}
}
@@ -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>&nbsp;&nbsp;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>&nbsp;&nbsp;Activate
</button>
</span>
<span *ngIf="smsCampaignData.campaignStatus.value !== 'closed'">
<button mat-raised-button color="warn" *mifosxHasPermission="'CLOSE_SMSCAMPAIGN'">
<fa-icon icon="times"></fa-icon>&nbsp;&nbsp;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>&nbsp;&nbsp;Reactivate
</button>
</span>
<span *ngIf="smsCampaignData.campaignStatus.value === 'closed'">
<button mat-raised-button color="warn" *mifosxHasPermission="'DELETE_SMSCAMPAIGN'">
<fa-icon icon="trash"></fa-icon>&nbsp;&nbsp;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>&nbsp;&nbsp;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();
});
}
}