@@ -0,0 +1,71 @@
|
|||||||
|
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
|
||||||
|
<button mat-raised-button color="primary">
|
||||||
|
<fa-icon icon="plus"></fa-icon>
|
||||||
|
Create Surveys
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<div fxLayout="row">
|
||||||
|
<mat-form-field fxFlex>
|
||||||
|
<mat-label>Filter</mat-label>
|
||||||
|
<input matInput (keyup)="applyFilter($event.target.value)">
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mat-elevation-z8">
|
||||||
|
|
||||||
|
<table mat-table [dataSource]="dataSource" matSort>
|
||||||
|
|
||||||
|
<ng-container matColumnDef="key">
|
||||||
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> Key </th>
|
||||||
|
<td mat-cell *matCellDef="let survey"> {{ survey.key }} </td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container matColumnDef="name">
|
||||||
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
|
||||||
|
<td mat-cell *matCellDef="let survey"> {{ survey.name }} </td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container matColumnDef="description">
|
||||||
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> Description </th>
|
||||||
|
<td mat-cell *matCellDef="let survey"> {{ survey.description }} </td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container matColumnDef="countryCode">
|
||||||
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> Country Code </th>
|
||||||
|
<td mat-cell *matCellDef="let survey"> {{ survey.countryCode }} </td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container matColumnDef="status">
|
||||||
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> Status </th>
|
||||||
|
<td mat-cell *matCellDef="let survey">
|
||||||
|
<div [className]="!isActive(survey.validFrom, survey.validTo) === true ? 'disabled' : 'enabled'">
|
||||||
|
<fa-icon matTooltip="{{ !isActive(survey.validFrom, survey.validTo) === true ? 'Disabled' : 'Enabled' }}" matTooltipPosition="right" icon="circle" size="lg"></fa-icon>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container matColumnDef="action">
|
||||||
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> Action </th>
|
||||||
|
<td mat-cell *matCellDef="let survey">
|
||||||
|
<button mat-button *ngIf="!isActive(survey.validFrom, survey.validTo)" color="accent">
|
||||||
|
<fa-icon icon="lock-open"></fa-icon> Activate
|
||||||
|
</button>
|
||||||
|
<button mat-button *ngIf="isActive(survey.validFrom, survey.validTo)" color="warn">
|
||||||
|
<fa-icon icon="lock"></fa-icon> Deactivate
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||||
|
<tr mat-row *matRowDef="let survey; columns: displayedColumns;" class="select-row"></tr>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<mat-paginator [pageSizeOptions]="[10, 25, 50, 100]" showFirstLastButtons></mat-paginator>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
table {
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
.select-row:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: CONFIGURE THESE CLASSES GLOBALLY
|
||||||
|
.enabled {
|
||||||
|
color: #32cd32;
|
||||||
|
}
|
||||||
|
|
||||||
|
.disabled {
|
||||||
|
color: #f44366;
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { ManageSurveysComponent } from './manage-surveys.component';
|
||||||
|
|
||||||
|
describe('SurveysComponent', () => {
|
||||||
|
let component: ManageSurveysComponent;
|
||||||
|
let fixture: ComponentFixture<ManageSurveysComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ ManageSurveysComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(ManageSurveysComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
/** Angular Imports */
|
||||||
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||||
|
import { MatTableDataSource, MatPaginator, MatSort } from '@angular/material';
|
||||||
|
import { ActivatedRoute } from '@angular/router';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manage Surveys component.
|
||||||
|
*/
|
||||||
|
@Component({
|
||||||
|
selector: 'mifosx-manage-surveys',
|
||||||
|
templateUrl: './manage-surveys.component.html',
|
||||||
|
styleUrls: ['./manage-surveys.component.scss'],
|
||||||
|
})
|
||||||
|
export class ManageSurveysComponent implements OnInit {
|
||||||
|
|
||||||
|
/* Surveys data */
|
||||||
|
surveysData: any;
|
||||||
|
/* Columns to be displayed in manage surveys data table */
|
||||||
|
displayedColumns: string[] = ['key', 'name', 'description', 'countryCode', 'status', 'action'];
|
||||||
|
/* Data source for manage surveys data table */
|
||||||
|
dataSource: MatTableDataSource<any>;
|
||||||
|
|
||||||
|
/** Paginator for manage surveys table. */
|
||||||
|
@ViewChild(MatPaginator) paginator: MatPaginator;
|
||||||
|
/** Sorter for manage surveys table. */
|
||||||
|
@ViewChild(MatSort) sort: MatSort;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the surveys data from `resolve`.
|
||||||
|
* @param {ActivatedRoute} route Activated Route.
|
||||||
|
*/
|
||||||
|
constructor(private route: ActivatedRoute) {
|
||||||
|
this.route.data.subscribe(( data: { surveys: any }) => {
|
||||||
|
this.surveysData = data.surveys;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether an survey is active based on its duration
|
||||||
|
* @param {number} validFrom Date valid from
|
||||||
|
* @param {number} validTo Date valid to
|
||||||
|
*/
|
||||||
|
isActive(validFrom: number, validTo: number) {
|
||||||
|
const curdate = new Date().getTime();
|
||||||
|
return (curdate > validFrom && curdate < validTo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the manage surveys table. And initiates button and action sort
|
||||||
|
*/
|
||||||
|
ngOnInit() {
|
||||||
|
this.setSurveys();
|
||||||
|
this.dataSource.sortingDataAccessor = (item, property) => {
|
||||||
|
switch (property) {
|
||||||
|
case 'status': return this.isActive(item.validFrom, item.validTo);
|
||||||
|
case 'action': return this.isActive(item.validFrom, item.validTo);
|
||||||
|
default: return item[property];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the data source, paginator and sorter for surveys table.
|
||||||
|
*/
|
||||||
|
setSurveys() {
|
||||||
|
this.dataSource = new MatTableDataSource(this.surveysData);
|
||||||
|
this.dataSource.paginator = this.paginator;
|
||||||
|
this.dataSource.sort = this.sort;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters data in surveys table based on passed value.
|
||||||
|
* @param {string} filterValue Value to filter data.
|
||||||
|
*/
|
||||||
|
applyFilter(filterValue: string) {
|
||||||
|
this.dataSource.filter = filterValue.trim().toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/** Angular Imports */
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Resolve } from '@angular/router';
|
||||||
|
|
||||||
|
/** rxjs Imports */
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
|
||||||
|
/** Custom Services */
|
||||||
|
import { SystemService } from '../system.service';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Surveys data resolver.
|
||||||
|
*/
|
||||||
|
@Injectable()
|
||||||
|
export class ManageSurveysResolver implements Resolve<Object> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {SystemService} systemService System service.
|
||||||
|
*/
|
||||||
|
constructor(private systemService: SystemService) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Surveys data.
|
||||||
|
* @returns {Observable<any>}
|
||||||
|
*/
|
||||||
|
resolve(): Observable<any> {
|
||||||
|
return this.systemService.getSurveys();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -13,12 +13,14 @@ import { ExternalServicesComponent } from './external-services/external-services
|
|||||||
import { ManageDataTablesComponent } from './manage-data-tables/manage-data-tables.component';
|
import { ManageDataTablesComponent } from './manage-data-tables/manage-data-tables.component';
|
||||||
import { ManageHooksComponent } from './manage-hooks/manage-hooks.component';
|
import { ManageHooksComponent } from './manage-hooks/manage-hooks.component';
|
||||||
import { RolesAndPermissionsComponent } from './roles-and-permissions/roles-and-permissions.component';
|
import { RolesAndPermissionsComponent } from './roles-and-permissions/roles-and-permissions.component';
|
||||||
|
import { ManageSurveysComponent } from './manage-surveys/manage-surveys.component';
|
||||||
|
|
||||||
/** Custom Resolvers */
|
/** Custom Resolvers */
|
||||||
import { CodesResolver } from './codes/codes.resolver';
|
import { CodesResolver } from './codes/codes.resolver';
|
||||||
import { ManageDataTablesResolver } from './manage-data-tables/manage-data-tables.resolver';
|
import { ManageDataTablesResolver } from './manage-data-tables/manage-data-tables.resolver';
|
||||||
import { ManageHooksResolver } from './manage-hooks/manage-hooks.resolver';
|
import { ManageHooksResolver } from './manage-hooks/manage-hooks.resolver';
|
||||||
import { RolesAndPermissionsResolver } from './roles-and-permissions/roles-and-permissions.resolver';
|
import { RolesAndPermissionsResolver } from './roles-and-permissions/roles-and-permissions.resolver';
|
||||||
|
import { ManageSurveysResolver } from './manage-surveys/manage-surveys.resolver';
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
Route.withShell([
|
Route.withShell([
|
||||||
@@ -78,6 +80,14 @@ const routes: Routes = [
|
|||||||
},
|
},
|
||||||
data: { title: extract('Roles and Permissions'), breadcrumb: 'Roles and Permissions' },
|
data: { title: extract('Roles and Permissions'), breadcrumb: 'Roles and Permissions' },
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'surveys',
|
||||||
|
component: ManageSurveysComponent,
|
||||||
|
resolve: {
|
||||||
|
surveys: ManageSurveysResolver
|
||||||
|
},
|
||||||
|
data: { title: extract('Manage Surveys'), breadcrumb: 'Manage Surveys' },
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
@@ -90,7 +100,8 @@ const routes: Routes = [
|
|||||||
CodesResolver,
|
CodesResolver,
|
||||||
ManageDataTablesResolver,
|
ManageDataTablesResolver,
|
||||||
ManageHooksResolver,
|
ManageHooksResolver,
|
||||||
RolesAndPermissionsResolver
|
RolesAndPermissionsResolver,
|
||||||
|
ManageSurveysResolver
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class SystemRoutingModule { }
|
export class SystemRoutingModule { }
|
||||||
|
|||||||
@@ -56,7 +56,7 @@
|
|||||||
<p matLine>Define or modify entity to entity mappings</p>
|
<p matLine>Define or modify entity to entity mappings</p>
|
||||||
</mat-list-item>
|
</mat-list-item>
|
||||||
|
|
||||||
<mat-list-item>
|
<mat-list-item [routerLink]="['surveys']">
|
||||||
<mat-icon matListIcon>
|
<mat-icon matListIcon>
|
||||||
<fa-icon icon="file-alt" size="sm"></fa-icon>
|
<fa-icon icon="file-alt" size="sm"></fa-icon>
|
||||||
</mat-icon>
|
</mat-icon>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { ExternalServicesComponent } from './external-services/external-services
|
|||||||
import { ManageDataTablesComponent } from './manage-data-tables/manage-data-tables.component';
|
import { ManageDataTablesComponent } from './manage-data-tables/manage-data-tables.component';
|
||||||
import { ManageHooksComponent } from './manage-hooks/manage-hooks.component';
|
import { ManageHooksComponent } from './manage-hooks/manage-hooks.component';
|
||||||
import { RolesAndPermissionsComponent } from './roles-and-permissions/roles-and-permissions.component';
|
import { RolesAndPermissionsComponent } from './roles-and-permissions/roles-and-permissions.component';
|
||||||
|
import { ManageSurveysComponent } from './manage-surveys/manage-surveys.component';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -26,7 +27,8 @@ import { RolesAndPermissionsComponent } from './roles-and-permissions/roles-and-
|
|||||||
ExternalServicesComponent,
|
ExternalServicesComponent,
|
||||||
ManageDataTablesComponent,
|
ManageDataTablesComponent,
|
||||||
ManageHooksComponent,
|
ManageHooksComponent,
|
||||||
RolesAndPermissionsComponent
|
RolesAndPermissionsComponent,
|
||||||
|
ManageSurveysComponent
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class SystemModule { }
|
export class SystemModule { }
|
||||||
|
|||||||
@@ -46,6 +46,13 @@ export class SystemService {
|
|||||||
return this.http.get('/codes');
|
return this.http.get('/codes');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {Observable<any>} Fetches Surveys.
|
||||||
|
*/
|
||||||
|
getSurveys(): Observable<any> {
|
||||||
|
return this.http.get('/surveys');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {any} code Code to be created.
|
* @param {any} code Code to be created.
|
||||||
* @returns {Observable<any>}
|
* @returns {Observable<any>}
|
||||||
|
|||||||
Reference in New Issue
Block a user