Commit 0143ff45 authored by rajkumar's avatar rajkumar
Browse files

Dac changes

parent ce1fbda7
<div class="body">
<div>
<div class="mat-h3 mat-tittle">Register Data access committee (DAC)</div>
</div>
<mat-divider></mat-divider>
<div class="container">
<mat-card>
<mat-card-subtitle>DAC Details</mat-card-subtitle>
<div style="width: 100%;">
<mat-form-field class="app-field-padding">
<textarea rows="3" matInput placeholder="Short descriptive title for the DAC" required
[(ngModel)]="title" name="title"></textarea>
</mat-form-field>
</div>
</mat-card>
<mat-card>
<mat-card-subtitle>Contact Information</mat-card-subtitle>
<a (click)="openDialog('Add', { submissionAccountId: id })">Add At Least One Contact
<mat-icon>add_circle</mat-icon>
</a>
<table mat-table *ngIf="dataSource" #table [dataSource]="dataSource" class="mat-elevation-z8">
<ng-container matColumnDef="emailAddress">
<th mat-header-cell *matHeaderCellDef>Email</th>
<td mat-cell *matCellDef="let element">{{ element.emailAddress }}</td>
</ng-container>
<form (ngSubmit)="submitDac(f)" #f="ngForm">
<div class="body">
<div>
<div class="mat-h3 mat-tittle">Register Data access committee (DAC)</div>
</div>
<mat-divider></mat-divider>
<div class="container">
<mat-card>
<mat-card-subtitle>DAC Details</mat-card-subtitle>
<div style="width: 100%;">
<mat-form-field class="app-field-padding">
<textarea rows="3" matInput placeholder="Short descriptive title for the DAC" required
[(ngModel)]="title" name="title"></textarea>
</mat-form-field>
</div>
</mat-card>
<mat-card>
<mat-card-subtitle>Contact Information</mat-card-subtitle>
<a (click)="openDialog('Add', { submissionAccountId: id })">Add At Least One Contact
<mat-icon>add_circle</mat-icon>
</a>
<table mat-table *ngIf="dataSource" #table [dataSource]="dataSource" class="mat-elevation-z8">
<ng-container matColumnDef="emailAddress">
<th mat-header-cell *matHeaderCellDef>Email</th>
<td mat-cell *matCellDef="let element">{{ element.emailAddress }}</td>
</ng-container>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef>Name</th>
<td mat-cell *matCellDef="let element">
{{ element.name }}
</td>
</ng-container>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef>Name</th>
<td mat-cell *matCellDef="let element">
{{ element.name }}
</td>
</ng-container>
<ng-container matColumnDef="telephone">
<th mat-header-cell *matHeaderCellDef>Telephone</th>
<td mat-cell *matCellDef="let element">
{{ element.telephone }}
</td>
</ng-container>
<ng-container matColumnDef="telephone">
<th mat-header-cell *matHeaderCellDef>Telephone</th>
<td mat-cell *matCellDef="let element">
{{ element.telephone }}
</td>
</ng-container>
<ng-container matColumnDef="organization">
<th mat-header-cell *matHeaderCellDef>Organization</th>
<td mat-cell *matCellDef="let element">
{{ element.organization }}
</td>
</ng-container>
<ng-container matColumnDef="organization">
<th mat-header-cell *matHeaderCellDef>Organization</th>
<td mat-cell *matCellDef="let element">
{{ element.organization }}
</td>
</ng-container>
<ng-container matColumnDef="edit">
<th mat-header-cell *matHeaderCellDef>Edit</th>
<td mat-cell *matCellDef="let element">
<mat-icon (click)="openDialog('Update', element)">edit</mat-icon>
</td>
</ng-container>
<ng-container matColumnDef="edit">
<th mat-header-cell *matHeaderCellDef>Edit</th>
<td mat-cell *matCellDef="let element">
<mat-icon (click)="openDialog('Update', element)">edit</mat-icon>
</td>
</ng-container>
<ng-container matColumnDef="remove">
<th mat-header-cell *matHeaderCellDef>Remove</th>
<td mat-cell *matCellDef="let element">
<mat-icon (click)="openDialog('Delete', element)">delete</mat-icon>
</td>
</ng-container>
<ng-container matColumnDef="remove">
<th mat-header-cell *matHeaderCellDef>Remove</th>
<td mat-cell *matCellDef="let element">
<mat-icon (click)="openDialog('Delete', element)">delete</mat-icon>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
</table>
</mat-card>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
</table>
<div style="text-align:Center">
<button mat-raised-button color="accent"
[disabled]="f.invalid || contactArray.length < 1">Save</button>
<button *ngIf="action==='Edit'" mat-raised-button style="margin-left: 5px;"
routerLink="/report/studies">Cancel</button>
<button *ngIf="action!='Edit'" mat-raised-button style="margin-left: 5px;"
routerLink="">Cancel</button>
</div>
</mat-card>
</div>
<div class="centred" *ngIf="showLoadingFlag" style="height:70px;">
<mat-spinner [diameter]="50" [strokeWidth]="5" style="margin:0 auto;">
</mat-spinner>
</div>
</div>
</div>
</form>
\ No newline at end of file
import { Component, OnInit } from '@angular/core';
import { MatDialog, MatTableDataSource } from '@angular/material';
import { ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs';
import { ContactDialogModalComponent } from '../contact-dialog-modal/contact-dialog-modal.component';
import { SubmissionResultDialogComponent } from '../submission-result-dialog/submission-result-dialog.component';
import { UtilService } from '../util/Util-services';
import { XmlService } from '../util/xml.service';
@Component({
selector: 'app-dac-management',
......@@ -13,8 +18,12 @@ export class DacManagementComponent implements OnInit {
/* Used for storing added emails, this will be used for validation */
emails = [];
contactArray = [];
deletedContacts = [];
action: string;
dataSource: MatTableDataSource<any>;
id: string;
showLoadingFlag: boolean;
xmlString: string;
title: string;
displayedColumns: string[] = [
"emailAddress",
"name",
......@@ -25,9 +34,19 @@ export class DacManagementComponent implements OnInit {
];
constructor(public dialog: MatDialog,) { }
constructor(
public dialog: MatDialog,
private util: UtilService,
private xmlUtil: XmlService,
private activatedRoute: ActivatedRoute,
) { }
ngOnInit() {
this.id = this.activatedRoute.snapshot.params.id;
if (this.id) {
this.action = "Edit";
this.initEdit(this.id);
}
}
openDialog(action, obj): void {
......@@ -100,7 +119,81 @@ export class DacManagementComponent implements OnInit {
return item.id;
})
.indexOf(contact.id);
this.deletedContacts.push(this.contactArray[index]);
this.contactArray.splice(index, 1);
}
submitDac(form) {
var observable: Observable<string>;
let redirectPath = ""
if (this.action != "Edit") {
observable = this.xmlUtil.generateDacXml(
form.value,
this.contactArray,
);
} else {
observable = this.xmlUtil.updateDacXml(
this.xmlString,
form.value,
this.contactArray,
);
redirectPath = null;
}
this.util.showSubmissionResponse(
this,
SubmissionResultDialogComponent,
observable,
redirectPath
);
}
initEdit(id) {
this.showLoading();
this.util.getDacXml(id).subscribe((xmlString: any) => {
this.xmlString = xmlString;
this.setPageValuesfromXml();
this.hideLoading();
});
}
setPageValuesfromXml() {
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(this.xmlString, "text/xml");
this.title = xmlDoc.getElementsByTagName("TITLE")[0].childNodes[0].nodeValue;
this.setContactDetails(xmlDoc);
}
setContactDetails(xmlDoc) {
var contacts = xmlDoc.getElementsByTagName("CONTACT");
var contactLen = contacts.length;
for (var i = 0; i < contactLen; i++) {
var email = contacts[i].getAttribute("email");
var name = contacts[i].getAttribute("name") || "";
var organisation = contacts[i].getAttribute("organisation") || "";
var telephone = contacts[i].getAttribute("telephone") || "";
this.contactArray.push({
id: this.util.getId(),
emailAddress: email,
name: name,
organization: organisation,
telephone: telephone
});
}
if (contacts.length > 0) {
this.dataSource = new MatTableDataSource<any>(this.contactArray);
}
}
showLoading() {
this.showLoadingFlag = true;
}
hideLoading() {
this.showLoadingFlag = false;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment