Skip to content
Snippets Groups Projects
Commit 1b2e1424 authored by Lukas Mauß's avatar Lukas Mauß
Browse files

Cleanup export, just download as csv

parent dda73f87
No related merge requests found
......@@ -31,7 +31,7 @@
</div>
</div>
<div fxLayoutAlign="center center">
<button mat-raised-button class="export" (click)="openExportDialog()" aria-labelledby="export-comments">
<button mat-raised-button class="export" (click)="exportCSV()" aria-labelledby="export-comments">
<mat-icon>save</mat-icon>
{{ 'room-page.export-comments' | translate }}</button>
</div>
......
......@@ -9,12 +9,10 @@ import { CommentService } from '../../../../services/http/comment.service';
import { BonusTokenService } from '../../../../services/http/bonus-token.service';
import { CommentSettingsService } from '../../../../services/http/comment-settings.service';
import { DeleteCommentsComponent } from '../delete-comments/delete-comments.component';
import { ExportFormatComponent } from '../export-format/export-format.component';
import { Room } from '../../../../models/room';
import { CommentBonusTokenMixin } from '../../../../models/comment-bonus-token-mixin';
import { CommentSettings } from '../../../../models/comment-settings';
import { CommentSettingsDialog } from '../../../../models/comment-settings-dialog';
import { del } from 'selenium-webdriver/http';
@Component({
selector: 'app-comment-settings',
......@@ -102,7 +100,7 @@ export class CommentSettingsComponent implements OnInit {
this.commentService.deleteCommentsByRoomId(this.roomId).subscribe();
}
export(delimiter: string, date: string): void {
export(delimiter: string, format: string): void {
this.commentService.getAckComments(this.roomId)
.subscribe(comments => {
this.bonusTokenService.getTokensByRoomId(this.roomId).subscribe( list => {
......@@ -145,12 +143,13 @@ export class CommentSettingsComponent implements OnInit {
valueFields += '' + delimiter + '\r\n';
}
});
const format = delimiter === ';' ? 'xls' : 'csv';
const date = new Date();
const dateString = date.toLocaleDateString();
let file: string;
file = keyFields + valueFields;
const myBlob = new Blob([file], { type: `text/${format}` });
const link = document.createElement('a');
const fileName = this.editRoom.name + '_' + this.editRoom.shortId + '_' + date + '.' + format;
const fileName = this.editRoom.name + '_' + this.editRoom.shortId + '_' + dateString + '.' + format;
link.setAttribute('download', fileName);
link.href = window.URL.createObjectURL(myBlob);
link.click();
......@@ -159,23 +158,8 @@ export class CommentSettingsComponent implements OnInit {
});
}
onExport(exportType: string): void {
const date = new Date();
const dateString = date.toLocaleDateString();
if (exportType === 'comma') {
this.export(',', dateString);
} else if (exportType === 'semicolon') {
this.export(';', dateString);
}
}
openExportDialog(): void {
const dialogRef = this.dialog.open(ExportFormatComponent, {
width: '400px'
});
dialogRef.afterClosed().subscribe(result => {
this.onExport(result);
});
exportCSV(): void {
this.export(',', 'csv');
}
closeDialog(): void {
......
<div fxLayout="column" fxLayoutAlign="center center" fxLayoutGap="35px">
<h2>{{'comment-page.delimiter' | translate}}</h2>
<mat-radio-group [(ngModel)]="exportType">
<div fxLayout="column">
<mat-radio-button value="semicolon" checked><p>{{'comment-page.comma' | translate}}</p></mat-radio-button>
<mat-radio-button value="comma"><p>{{'comment-page.semicolon' | translate}}</p></mat-radio-button>
</div>
</mat-radio-group>
</div>
<app-dialog-action-buttons
buttonsLabelSection="comment-page"
confirmButtonLabel="export"
[cancelButtonClickAction]="buildCloseDialogActionCallback()"
[confirmButtonClickAction]="buildExportActionCallback()"
></app-dialog-action-buttons>
button {
min-width: 100px;
}
.abort {
background-color: var(--secondary);
color: var(--on-secondary);
}
.export {
background-color: var(--primary);
color: var(--on-primary);
}
/** import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ExportFormatComponent } from './export-format.component';
describe('ExportFormatComponent', () => {
let component: ExportFormatComponent;
let fixture: ComponentFixture<ExportFormatComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ExportFormatComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ExportFormatComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
}); */
import { Component, OnInit } from '@angular/core';
import { MatDialogRef } from '@angular/material';
@Component({
selector: 'app-export-format',
templateUrl: './export-format.component.html',
styleUrls: ['./export-format.component.scss']
})
export class ExportFormatComponent implements OnInit {
exportType = 'semicolon';
constructor(public dialogRef: MatDialogRef<Component>) { }
ngOnInit() {
}
/**
* Closes the dialog on call.
*/
closeDialog(): void {
this.dialogRef.close();
}
/**
* Returns a lambda which closes the dialog on call.
*/
buildCloseDialogActionCallback(): () => void {
return () => this.closeDialog();
}
/**
* Returns a lambda which executes the dialog dedicated action on call.
*/
buildExportActionCallback(): () => void {
return () => this.dialogRef.close(this.exportType);
}
}
......@@ -10,7 +10,6 @@ import { SharedModule } from '../shared/shared.module';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { HttpClient } from '@angular/common/http';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { ExportFormatComponent } from './_dialogs/export-format/export-format.component';
import { ModeratorsComponent } from './_dialogs/moderators/moderators.component';
import { BonusTokenComponent } from './_dialogs/bonus-token/bonus-token.component';
import { CommentSettingsComponent } from './_dialogs/comment-settings/comment-settings.component';
......@@ -43,7 +42,6 @@ import { DeleteAnswerComponent } from './_dialogs/delete-answer/delete-answer.co
RoomCreatorPageComponent,
RoomDeleteComponent,
RoomEditComponent,
ExportFormatComponent,
ModeratorsComponent,
BonusTokenComponent,
CommentSettingsComponent,
......@@ -58,7 +56,6 @@ import { DeleteAnswerComponent } from './_dialogs/delete-answer/delete-answer.co
entryComponents: [
RoomDeleteComponent,
RoomEditComponent,
ExportFormatComponent,
ModeratorsComponent,
BonusTokenComponent,
CommentSettingsComponent,
......
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