Skip to content

Commit

Permalink
add admin tool to import pdf files as plain text
Browse files Browse the repository at this point in the history
  • Loading branch information
konrad2002 committed Jun 9, 2024
1 parent b839855 commit a97869f
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 119 deletions.
69 changes: 44 additions & 25 deletions src/app/content/admin/admin.module.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,55 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { PageAdminEventComponent } from './pages';
import { AdminMainViewComponent, AdminHeatToolComponent, AdminImportToolComponent, AdminEventListComponent } from './components';
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {PageAdminEventComponent} from './pages';
import {
AdminMainViewComponent,
AdminHeatToolComponent,
AdminImportToolComponent,
AdminEventListComponent,
AdminImportTextDialog
} from './components';
import {ElementsModule} from "../../shared/elements/elements.module";
import {EventsModule} from "../events";
import {CoreModule} from "../../core/core.module";
import {StartsModule} from "../starts";
import {ReactiveFormsModule} from "@angular/forms";
import {FormsModule, ReactiveFormsModule} from "@angular/forms";
import {MatIconModule} from "@angular/material/icon";
import {LiveModule} from "../live";
import {MatRadioModule} from "@angular/material/radio";

import {MatDialogActions, MatDialogClose, MatDialogContent, MatDialogTitle} from "@angular/material/dialog";
import {MatFormFieldModule} from "@angular/material/form-field";
import {MatButtonModule} from "@angular/material/button";
import {MatInputModule} from "@angular/material/input";


@NgModule({
declarations: [
PageAdminEventComponent,
AdminMainViewComponent,
AdminHeatToolComponent,
AdminImportToolComponent,
AdminEventListComponent
],
imports: [
CommonModule,
ElementsModule,
EventsModule,
CoreModule,
StartsModule,
ReactiveFormsModule,
MatIconModule,
LiveModule,
MatRadioModule
]
declarations: [
PageAdminEventComponent,
AdminMainViewComponent,
AdminHeatToolComponent,
AdminImportToolComponent,
AdminEventListComponent,
AdminImportTextDialog
],
imports: [
CommonModule,
ElementsModule,
EventsModule,
CoreModule,
StartsModule,
ReactiveFormsModule,
MatIconModule,
LiveModule,
MatRadioModule,
MatDialogTitle,
MatDialogContent,
FormsModule,
MatFormFieldModule,
MatDialogActions,
MatButtonModule,
MatInputModule,
MatDialogClose
]
})
export class AdminModule { }
export class AdminModule {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<h2 mat-dialog-title>Import PDF from Text</h2>
<mat-dialog-content>
<mat-form-field class="text-area-field">
<mat-label>Text from PDF</mat-label>
<textarea matInput [(ngModel)]="data.text">
</textarea>
</mat-form-field>
</mat-dialog-content>
<mat-dialog-actions>
<button mat-button (click)="onNoClick()">Cancel</button>
<button mat-button [mat-dialog-close]="data" cdkFocusInitial>Import</button>
</mat-dialog-actions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.text-area-field {
width: 100%;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {Component, Inject} from "@angular/core";
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
import {ImportFileRequest} from "../../../../core/service/api/import/import-file.service";

@Component({
selector: 'sr-admin-import-text-dialog',
templateUrl: './admin-import-text-dialog.component.html',
styleUrls: ['./admin-import-text-dialog.component.scss']
})
export class AdminImportTextDialog {

Check failure on line 10 in src/app/content/admin/components/admin-import-tool/admin-import-text-dialog.component.ts

View workflow job for this annotation

GitHub Actions / test (Lint)

Component class names should end with one of these suffixes: "Component" (https://angular.io/styleguide#style-02-03)

Check failure on line 10 in src/app/content/admin/components/admin-import-tool/admin-import-text-dialog.component.ts

View workflow job for this annotation

GitHub Actions / test (Lint)

Component class names should end with one of these suffixes: "Component" (https://angular.io/styleguide#style-02-03)
constructor(
public dialogRef: MatDialogRef<AdminImportTextDialog>,
@Inject(MAT_DIALOG_DATA) public data: ImportFileRequest,
) {
}

onNoClick(): void {
this.dialogRef.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<mat-radio-group aria-label="Listentyp" formControlName="listType">
<mat-radio-button value="definition" *ngIf="currentFileType === 'dsv'">Definitionsliste</mat-radio-button>
<mat-radio-button value="start_list" *ngIf="currentFileType === 'pdf'">Startliste</mat-radio-button>
<mat-radio-button value="start_list" *ngIf="currentFileType !== 'dsv' && currentFileType !== ''">Startliste</mat-radio-button>
<mat-radio-button value="result_list" *ngIf="currentFileType !== ''">Ergebnis</mat-radio-button>
</mat-radio-group>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,89 +1,95 @@
@import "../../../../../colors";

.refresh-btn {
float: right;
margin-top: -50px;
float: right;
margin-top: -50px;
}

sr-panel {
height: 150px;
vertical-align: top;
margin-bottom: 56px;
//height: 150px;
vertical-align: top;
margin-bottom: 16px;
}

sr-panel:first-of-type {
margin-right: 12px;
margin-right: 12px;
}

mat-radio-group {
display: inline-block;
vertical-align: top;
margin: 0 8px;
padding-right: 21px;
display: inline-block;
vertical-align: top;
margin: 0 8px;
padding-right: 21px;
}

mat-radio-button {
display: block;
display: block;
}

.file-import {
display: block;
display: block;
}

.file-import,
.file-import-url {
width: 400px;
margin: 4px 0;
width: 400px;
margin: 4px 0;
}

.file-list {
display: inline-block;
height: 138px;
overflow-y: auto;
overflow-x: hidden;
width: 350px;
display: inline-block;
height: 138px;
overflow-y: auto;
overflow-x: hidden;
width: 350px;
}

.file-list,
.file-list-buttons {
display: inline-block;
vertical-align: top;
display: inline-block;
vertical-align: top;
}

.file-list-buttons {
margin-left: 12px;
sr-btn {
display: block;
margin: 4px 0;
}
margin-left: 12px;

sr-btn {
display: block;
margin: 4px 0;
}
}

.file-name {
display: block;
text-overflow: ellipsis;
width: 328px;
padding: 2px;
margin: 0;
background-color: transparent;
cursor: pointer;
overflow: hidden;
white-space: nowrap;

&.file-selected {
background-color: $color-bg-contrast;
}

&.file-not-public {
color: $color-text-gray;
}
display: block;
text-overflow: ellipsis;
width: 328px;
padding: 2px;
margin: 0;
background-color: transparent;
cursor: pointer;
overflow: hidden;
white-space: nowrap;

&.file-selected {
background-color: $color-bg-contrast;
}

&.file-not-public {
color: $color-text-gray;
}
}

.import-button-box {
display: inline-block;
display: inline-block;

.file-import-events {
width: 100px;
display: block;
margin: 4px 0;
}
.pdf-to-text-btn {
margin-top: 4px;
display: block;
}

.file-import-events {
width: 100px;
display: block;
margin: 4px 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import {EventService, FileService} from "../../../../core/service/api";
import {MeetingImpl} from "../../../../core/model/meeting/meeting.model";
import {MeetingEvent} from "../../../../core/model/meeting/meeting-event.model";
import {FormBuilder, FormGroup} from "@angular/forms";
import {ImportFileService} from "../../../../core/service/api/import/import-file.service";
import {ImportFileRequest, ImportFileService} from "../../../../core/service/api/import/import-file.service";
import {MatDialog} from "@angular/material/dialog";
import {AdminImportTextDialog} from "./admin-import-text-dialog.component";

interface FileList {
name: string,
Expand All @@ -24,6 +26,7 @@ export class AdminImportToolComponent implements OnInit {
fileTypeList = [
{name: 'DSV', value: "dsv"},
{name: 'PDF', value: "pdf"},
{name: 'TXT', value: "pdf_txt"},
];

currentFileType: string = ""
Expand All @@ -41,7 +44,8 @@ export class AdminImportToolComponent implements OnInit {
private eventService: EventService,
private fileService: FileService,
private importService: ImportFileService,
private fb: FormBuilder
private fb: FormBuilder,
private dialog: MatDialog
) {
this.importForm = this.fb.group({
url: [],
Expand Down Expand Up @@ -112,23 +116,60 @@ export class AdminImportToolComponent implements OnInit {
}
}

this.importService.importFile(
this.importForm.value.url,
this.importForm.value.fileType,
this.importForm.value.listType,
excludes,
includes,
this.meetingId
).subscribe({
next: (_ => {
console.log("successfully send import for '" + this.importForm.value.url + "'")
this.runningImport = false;
}),
error: err => {
console.error(err);
this.runningImport = false;
}
})
let data: ImportFileRequest = {
url: this.importForm.value.url,
text: "",
file_extension: this.importForm.value.fileType.toUpperCase(),
file_type: this.importForm.value.listType.toUpperCase(),
exclude_events: excludes,
include_events: includes,
meeting: this.meetingId
}

if (this.importForm.value.fileType === 'pdf_txt') {
this.importService.readToPdfBeforeImport(data).subscribe({
next: (newData => {
console.log("successfully send pdf to text for '" + this.importForm.value.url + "'")
console.log(newData.text)

const dialogRef = this.dialog.open(AdminImportTextDialog, {
data: newData,
width: '80%'
});

dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');

this.importService.importFile(result).subscribe({
next: (_ => {
console.log("successfully send import for text")
this.runningImport = false;
}),
error: err => {
console.error(err);
this.runningImport = false;
}
})
});
}),
error: err => {
console.error(err);
this.runningImport = false;
}
})
} else {
this.importService.importFile(data).subscribe({
next: (_ => {
console.log("successfully send import for '" + this.importForm.value.url + "'")
this.runningImport = false;
}),
error: err => {
console.error(err);
this.runningImport = false;
}
})
}

}

setCurrentFileForImport() {
Expand Down Expand Up @@ -164,5 +205,5 @@ export class AdminImportToolComponent implements OnInit {
});
}
}

}

1 change: 1 addition & 0 deletions src/app/content/admin/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './admin-event-list/admin-event-list.component';
export * from './admin-import-tool/admin-import-tool.component';
export * from './admin-heat-tool/admin-heat-tool.component';
export * from './admin-main-view/admin-main-view.component';
export {AdminImportTextDialog} from "./admin-import-tool/admin-import-text-dialog.component";
Loading

0 comments on commit a97869f

Please sign in to comment.