-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged branch exports-module into master
- Loading branch information
Showing
24 changed files
with
1,048 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<div [formGroup]="form"> | ||
<p-dataTable [value]="columns" [responsive]="true"> | ||
<p-column field="name" header="Column name"></p-column> | ||
<p-column field="is_nullable" header="Contains nulls?"></p-column> | ||
<p-column field="system_type_name" header="Data type"></p-column> | ||
<p-column header="Include in export"> | ||
<ng-template let-foo="rowData" pTemplate="body"> | ||
<p-inputSwitch onLabel="Yes" offLabel="No" [(ngModel)]="foo.include" [formControlName]="foo.name"></p-inputSwitch> | ||
</ng-template> | ||
</p-column> | ||
</p-dataTable> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import {ReactiveFormsModule, FormsModule, FormGroup} from '@angular/forms'; | ||
import {DialogModule, InputSwitchModule, CalendarModule, DataTableModule, TabViewModule, DropdownModule} from 'primeng/primeng'; | ||
|
||
import { ExportsOptionsComponent } from './exports-options.component'; | ||
|
||
describe('ExportsOptionsComponent', () => { | ||
let component: ExportsOptionsComponent; | ||
let fixture: ComponentFixture<ExportsOptionsComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ ExportsOptionsComponent ], | ||
imports: [ | ||
DataTableModule, | ||
DropdownModule, | ||
TabViewModule, | ||
CalendarModule, | ||
DialogModule, | ||
InputSwitchModule, | ||
FormsModule, | ||
ReactiveFormsModule | ||
] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ExportsOptionsComponent); | ||
component = fixture.componentInstance; | ||
component.form = new FormGroup({}); | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Component, Input, OnInit, OnChanges } from '@angular/core'; | ||
import { ExportColumn } from './models/export-column'; | ||
import {FormGroup} from '@angular/forms'; | ||
@Component({ | ||
selector: 'exports-options', | ||
templateUrl: './exports-options.component.html', | ||
styleUrls: ['./exports-options.component.css'] | ||
}) | ||
export class ExportsOptionsComponent implements OnInit { | ||
@Input() columns: ExportColumn[] = []; | ||
@Input() form: FormGroup; | ||
constructor() { } | ||
|
||
ngOnInit() { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { RouterModule, Routes } from '@angular/router'; | ||
import {ExportsComponent} from './exports.component'; | ||
|
||
const exportsRoutes: Routes = [ | ||
{ | ||
path: '', | ||
component: ExportsComponent | ||
} | ||
]; | ||
@NgModule({ | ||
imports: [ | ||
RouterModule.forChild(exportsRoutes) | ||
], | ||
exports: [ | ||
RouterModule | ||
], | ||
providers: [ | ||
] | ||
}) | ||
export class ExportsRoutingModule { } |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<h1>Exports</h1> | ||
<div class="ui-g" > | ||
<div class="ui-g-12 ui-md-6"> | ||
<p-dropdown | ||
id="exportsDD" | ||
placeholder="Select a table" | ||
[options]="exportsDropDown" | ||
(onChange)="getColumns()" | ||
[(ngModel)]="selectedExportName" | ||
[filter]="true" | ||
[style]="{'width':'10em'}"></p-dropdown> | ||
</div> | ||
<div class="ui-g-12 ui-md-6"> | ||
<p-dropdown | ||
placeholder="date field for filter" | ||
[options]="dateFilterDropDown" | ||
[(ngModel)]="selectedDateFilter" | ||
[style]="{'width':'10em'}"></p-dropdown> | ||
</div> | ||
<div class="ui-g-12 ui-md-4 ui-lg-3"> | ||
<p-calendar | ||
placeholder="Start date" | ||
[showIcon]="true" | ||
[(ngModel)]="selectedStartDate" | ||
dataType="string"></p-calendar> | ||
</div> | ||
<div class="ui-g-12 ui-md-4 ui-lg-3"> | ||
<p-calendar | ||
placeholder="End date" | ||
[showIcon]="true" | ||
[(ngModel)]="selectedEndDate" | ||
dataType="string"></p-calendar> | ||
</div> | ||
<div class="ui-g-12 ui-md-4 ui-lg-3"> | ||
<button pButton type="submit" label="Export" (click)="onSubmit()"></button> | ||
</div> | ||
</div> | ||
<div> | ||
<exports-options [columns]="selectedColumns" [form]="form"></exports-options> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing'; | ||
import {DialogModule, CalendarModule, DataTableModule, TabViewModule, DropdownModule} from 'primeng/primeng'; | ||
import {FormsModule} from '@angular/forms'; | ||
import { ExportsComponent } from './exports.component'; | ||
import {InMemoryWebApiModule} from 'angular-in-memory-web-api'; | ||
import {InMemoryDataService} from '../in-memory-data.service'; | ||
import {HttpModule} from '@angular/http'; | ||
import {ExportsService} from './exports.service'; | ||
import {NoopAnimationsModule} from '@angular/platform-browser/animations'; | ||
import { ExportsOptionsComponent } from './exports-options.component'; | ||
describe('ExportsComponent', () => { | ||
let component: ExportsComponent; | ||
let fixture: ComponentFixture<ExportsComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ ExportsComponent, ExportsOptionsComponent ], | ||
providers: [ExportsService ], | ||
imports: [ | ||
NoopAnimationsModule, | ||
DataTableModule, | ||
DropdownModule, | ||
TabViewModule, | ||
CalendarModule, | ||
DialogModule, | ||
FormsModule, | ||
HttpModule, | ||
InMemoryWebApiModule.forRoot(InMemoryDataService) | ||
] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ExportsComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create the component', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should populate the export list', | ||
async(inject([ExportsService], (service: ExportsService) => { | ||
service.getExportsList() | ||
.toPromise() | ||
.then(rows => { | ||
expect(rows.length).toBe(2, 'expected 2 in exports list'); | ||
}); | ||
})) | ||
); | ||
|
||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import {ExportsService} from './exports.service'; | ||
import {MySelectItem} from '../reports/reports.component'; | ||
import { Export } from './models/export'; | ||
import {ExportColumn} from './models/export-column'; | ||
import {Response} from '@angular/http'; | ||
import { saveAs } from 'file-saver'; | ||
import {FormControl, FormGroup, FormBuilder} from '@angular/forms'; | ||
import * as contentDisposition from 'content-disposition'; | ||
@Component({ | ||
selector: 'app-exports', | ||
templateUrl: './exports.component.html', | ||
styleUrls: ['./exports.component.css'], | ||
providers: [ExportsService] | ||
}) | ||
export class ExportsComponent implements OnInit { | ||
exports: Export[]; | ||
dateFilterDropDown: MySelectItem[]; | ||
exportsDropDown: MySelectItem[]; | ||
errorMessage: string; | ||
selectedColumns: ExportColumn[]; | ||
selectedExportName: string; | ||
selectedDateFilter: string; | ||
selectedStartDate: string; | ||
selectedEndDate: string; | ||
form: FormGroup; | ||
|
||
constructor(private exportsService: ExportsService, private _fb: FormBuilder) | ||
{ | ||
this.form = new FormGroup({}); | ||
} | ||
|
||
ngOnInit() { | ||
this.exportsService.getExportsList() | ||
.subscribe( | ||
listData => { | ||
this.exports = listData; | ||
this.exportsDropDown = listData.map(r => | ||
new MySelectItem(r.name, r.name)); | ||
}, | ||
error => this.errorMessage = <any>error, | ||
() => console.log('exports.component: ngOnInit onCompleted')); | ||
} | ||
|
||
getColumns() { | ||
this.exportsService.getColumns(this.selectedExportName) | ||
.subscribe( | ||
data => { | ||
this.selectedColumns = data; | ||
this.dateFilterDropDown = data.filter(f => f.system_type_name === 'datetime') | ||
.map(r => | ||
new MySelectItem(r.name, r.name)); | ||
const group: any = {}; | ||
data.forEach(col => { | ||
group[col.name] = new FormControl(true); | ||
}); | ||
this.form = new FormGroup(group); | ||
}, | ||
error => this.errorMessage = <any>error, | ||
() => console.log('exportsService.getColumns completed') | ||
); | ||
} | ||
|
||
onSubmit() | ||
{ | ||
let data = Object.assign( { | ||
beginDate: this.selectedStartDate, | ||
endDate: this.selectedEndDate, | ||
filterField: this.selectedDateFilter | ||
}, this.form.value); | ||
console.log(this.form.value); | ||
this.exportsService.getExport(this.selectedExportName, data) | ||
.subscribe((res: Response) => { | ||
this.downloadFile(res['_body'], | ||
this.getFilename(res.headers.get('content-disposition')), | ||
res['_body'].type); | ||
} | ||
), | ||
error => this.errorMessage = <any>error, | ||
() => console.log('exportsService.getColumns completed'); | ||
} | ||
|
||
downloadFile(data: any, fileName: string, ttype: string) { | ||
const blob = new Blob([data], {type: ttype}); | ||
saveAs(blob, fileName); | ||
} | ||
|
||
getFilename(content: string): string { | ||
return contentDisposition.parse(content).parameters['filename']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { ExportsComponent } from './exports.component'; | ||
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; | ||
import { JsonpModule } from '@angular/http'; | ||
import {ExportsRoutingModule} from './exports-routing.module'; | ||
import { | ||
ButtonModule, DropdownModule, DataTableModule, SharedModule, ChartModule, | ||
DialogModule, TabViewModule, CalendarModule, InputTextareaModule, InputSwitchModule | ||
} from 'primeng/primeng'; | ||
import { ExportsOptionsComponent } from './exports-options.component'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
FormsModule, | ||
ReactiveFormsModule, | ||
JsonpModule, | ||
TabViewModule, | ||
ChartModule, | ||
DataTableModule, | ||
SharedModule, | ||
CalendarModule, | ||
ButtonModule, | ||
DropdownModule, | ||
DialogModule, | ||
InputSwitchModule, | ||
InputTextareaModule, | ||
ExportsRoutingModule | ||
], | ||
declarations: [ExportsComponent, ExportsOptionsComponent] | ||
}) | ||
export class ExportsModule { | ||
constructor() { | ||
console.log('ExportsModule-ctor'); | ||
} | ||
} |
Oops, something went wrong.