Skip to content

Commit

Permalink
fix(downloads): fixed download by line bug and improved generation of…
Browse files Browse the repository at this point in the history
… downloads

Closes #56
  • Loading branch information
julianpoemp committed Feb 11, 2021
1 parent 1126e1f commit 39c9a1d
Show file tree
Hide file tree
Showing 7 changed files with 337 additions and 324 deletions.
2 changes: 0 additions & 2 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
Expand Down Expand Up @@ -84,7 +83,6 @@
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ declare var ohPortalVersion: string;
declare var ohPortalLastUpdated: string;

export class AppInfo {
public static readonly debugging = false;
public static readonly debugging = true;
static readonly _version = ohPortalVersion;
static readonly lastUpdated = ohPortalLastUpdated;

Expand Down
4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {CollapseModule} from 'ngx-bootstrap/collapse';
import {PopoverModule} from 'ngx-bootstrap/popover';
import {BsDropdownModule} from 'ngx-bootstrap/dropdown';
import {AppRoutingModule} from './app-routing.module';
import {DownloadService} from './shared/download.service';

@NgModule({
declarations: [
Expand Down Expand Up @@ -109,7 +110,8 @@ import {AppRoutingModule} from './app-routing.module';
AlertService,
SettingsService,
CompatibilityService,
OHModalService
OHModalService,
DownloadService
],
bootstrap: [AppComponent]
})
Expand Down
181 changes: 67 additions & 114 deletions src/app/components/results-table/results-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import {AppInfo, ConverterData} from '../../app.info';
import {HttpClient} from '@angular/common/http';
import {DomSanitizer} from '@angular/platform-browser';
import {FileInfo, isUnset} from '@octra/utilities';
import {Converter, IFile, OAnnotJSON, OAudiofile} from '@octra/annotation';
import {Converter, OAudiofile} from '@octra/annotation';
import {AudioInfo} from '@octra/media';
import {DownloadService} from '../../shared/download.service';

@Component({
selector: 'app-results-table',
Expand Down Expand Up @@ -34,7 +35,8 @@ export class ResultsTableComponent implements OnChanges {
public conversionExtension = '';
@Output() previewClick: EventEmitter<FileInfo> = new EventEmitter<FileInfo>();

constructor(private http: HttpClient, private sanitizer: DomSanitizer, private cd: ChangeDetectorRef) {
constructor(private http: HttpClient, private sanitizer: DomSanitizer,
private cd: ChangeDetectorRef, private downloadService: DownloadService) {
}

public get converters() {
Expand Down Expand Up @@ -68,117 +70,86 @@ export class ResultsTableComponent implements OnChanges {
this.cd.detectChanges();

if (this.operation.resultType !== '.wav') {
const promises: Promise<string>[] = [];
const promises: Promise<FileInfo[]>[] = [];

for (const result of this.operation.results) {
promises.push(FileInfo.getFileContent(result.file));
promises.push(this.downloadService.getConversionFiles(this.operation, this.operation.lastResult, this.converters));
}

// read all file contents of results
Promise.all(promises).then((promiseResults: string[]) => {
Promise.all(promises).then((promiseResults: (FileInfo[])[]) => {
for (let j = 0; j < promiseResults.length; j++) {
const result = this.operation.results[j];
let from: Converter = null;

// TODO change this!
for (const converter of AppInfo.converters) {
if (converter.obj.extension.indexOf(result.extension) > -1) {
this.originalLabel = converter.obj.extension;
from = converter.obj;
break;
}
}
const conversions = promiseResults[j];

let originalFileName: any = this.operation.task.files[0].attributes.originalFileName;
originalFileName = FileInfo.extractFileName(originalFileName);

const resultObj = {
url: this.sanitizer.bypassSecurityTrustUrl(URL.createObjectURL(result.file)),
name: originalFileName.name,
type: result.type,
available: result.available,
fullname: originalFileName.name + result.extension,
extension: result.extension,
file: result.file
};

const audio: OAudiofile = new OAudiofile();
audio.sampleRate = (this.operation.task.files[0] as AudioInfo).sampleRate;
audio.duration = (this.operation.task.files[0] as AudioInfo).duration.samples;
audio.name = (this.operation.task.files[0] as AudioInfo).fullname;
audio.size = (this.operation.task.files[0] as AudioInfo).size;

const file: IFile = {
name: result.name,
content: '',
type: result.type,
encoding: 'UTF-8'
};

const text = promiseResults[j];
file.content = text;

const convElem = {
input: resultObj,
conversions: [],
number: j
};
this.convertedArray.push(convElem);
this.convertedArray.sort(this.sortAlgorithm);

for (const converter of AppInfo.converters) {
if (converter.obj.extension.indexOf(result.extension) < 0) {
const res: {
converter: any,
state: string,
result: any
} = {
converter,
state: 'PENDING',
result: null
};
const from: ConverterData = AppInfo.converters.find(a => a.obj.extension.indexOf(result.extension) > -1);

let annotJSON;

if (from.name !== 'AnnotJSON') {
const importResult = from.import(file, audio);
if (!isUnset(importResult)) {
if (!isUnset(importResult.error !== '')) {
annotJSON = from.import(file, audio).annotjson;
} else {
console.error(`importResult Error from ${from.name}: ${importResult.error}`);
}
} else {
console.error(`importResult for import ${from.name} is undefined!`);
}
} else {
annotJSON = JSON.parse(text);
}
if (!isUnset(from)) {
const importConverter = from.obj;
this.originalLabel = importConverter.extension;

const levelnum = this.getLevelNumforConverter(converter, annotJSON);

let preResult = null;
let originalFileName: any = this.operation.task.files[0].attributes.originalFileName;
originalFileName = FileInfo.extractFileName(originalFileName);

try {
preResult = converter.obj.export(annotJSON, audio, levelnum);
} catch (e) {
console.log(e);
}
const resultObj = {
url: this.sanitizer.bypassSecurityTrustUrl(URL.createObjectURL(result.file)),
name: originalFileName.name,
type: result.type,
available: result.available,
fullname: originalFileName.name + result.extension,
extension: result.extension,
file: result.file
};

const audio: OAudiofile = new OAudiofile();
audio.sampleRate = (this.operation.task.files[0] as AudioInfo).sampleRate;
audio.duration = (this.operation.task.files[0] as AudioInfo).duration.samples;
audio.name = (this.operation.task.files[0] as AudioInfo).fullname;
audio.size = (this.operation.task.files[0] as AudioInfo).size;

const exp = (!(preResult === null || preResult === undefined))
? preResult.file : null;
const convElem = {
input: resultObj,
conversions: [],
number: j
};
this.convertedArray.push(convElem);
this.convertedArray.sort(this.sortAlgorithm);

const convertersWithoutFrom = this.converters.filter(a => a.obj.name !== importConverter.name);

for (let k = 0; k < conversions.length; k++) {
const conversion = conversions[k];
const converter = convertersWithoutFrom[k];

const res: {
converter: {
obj: Converter,
color: string
}
state: string;
result: FileInfo;
} = {
converter: {
obj: converter.obj,
color: converter.color
},
state: 'PENDING',
result: null
};

if (!(exp === null || exp === undefined)) {
const expFile = new File([exp.content], originalFileName.name + converter.obj.extension, {
type: exp.type
});
res.result = FileInfo.fromFileObject(expFile);
const url = URL.createObjectURL(expFile);
res.result.url = this.sanitizer.bypassSecurityTrustUrl(url);
if (!isUnset(conversion)) {
res.result = conversion;
const url = URL.createObjectURL(conversion.file);
res.result.url = this.sanitizer.bypassSecurityTrustUrl(url) as any;
res.state = 'FINISHED';
convElem.conversions.push(res);
} else {
res.state = 'FAILED';
}
}
} else {
console.error(`could not find import converter`);
}
}

Expand All @@ -187,12 +158,12 @@ export class ResultsTableComponent implements OnChanges {
}).catch((error) => {
console.error(error);

this.convertedArray = [];
this.convertedArray.push({
input: null,
conversions: [],
number: 0
});
this.convertedArray.sort(this.sortAlgorithm);

this.cd.markForCheck();
this.cd.detectChanges();
Expand Down Expand Up @@ -243,22 +214,4 @@ export class ResultsTableComponent implements OnChanges {
}
}

private getLevelNumforConverter(converterData: ConverterData, annotJSON: OAnnotJSON) {
if (!isUnset(converterData.tierNameMatches)) {
for (const tierNameMatch of converterData.tierNameMatches) {
const regex = new RegExp(tierNameMatch, 'g');

for (let i = 0; i < annotJSON.levels.length; i++) {
const level = annotJSON.levels[i];
if (regex.exec(level.name) !== null) {
return i;
}
}
}
return -1;
} else {
return 0;
}
}

}
10 changes: 7 additions & 3 deletions src/app/modals/download-modal/download-modal.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ <h4 class="modal-title pull-left">Download results by {{type}}</h4>
</button>
</div>
<div class="modal-body">
<p style="text-align: justify;">This creates a zip-archive of all the selected results and optionally
conversions to other formats.
If you do not select any additional conversions only the original results are added to the zip-archive.</p>
<p style="text-align: justify;">
This creates a zip-archive of all the selected results and optionally conversions to other formats.
If you do not select any additional conversions only the original results are added to the zip-archive.
</p>
<p>
Please notice, that only the latest results are inserted to the package.
</p>
<p>Add conversions (optional):</p>
<div>
<ng-container *ngFor="let conversion of converters; let i = index">
Expand Down
Loading

0 comments on commit 39c9a1d

Please sign in to comment.