diff --git a/src/app/files.service.ts b/src/app/files.service.ts index b0105b041..8228011fe 100644 --- a/src/app/files.service.ts +++ b/src/app/files.service.ts @@ -30,7 +30,7 @@ export class FilesService { this.httpGETRequest.unsubscribe(); } this.httpGETRequest = this.http - .get(this.configService.getURL('files/local' + folderPath), this.configService.getHTTPHeaders()) + .get(this.configService.getURL('files' + folderPath), this.configService.getHTTPHeaders()) .subscribe( (data: OctoprintFolderAPI & OctoprintFolderContentAPI): void => { if ('children' in data) { @@ -38,42 +38,76 @@ export class FilesService { delete data.children; } const folder: (File | Folder)[] = []; + let localCount = 0; + let sdcardCount = 0; data.files.forEach((fileOrFolder): void => { if (fileOrFolder.type === 'folder') { + if (folderPath === '') { + if (fileOrFolder.origin == 'local') { + localCount += fileOrFolder.children.length; + } else { + sdcardCount += fileOrFolder.children.length; + } + } + folder.push(({ type: 'folder', - path: '/' + fileOrFolder.path, + path: '/' + fileOrFolder.origin + '/' + fileOrFolder.path, name: fileOrFolder.name, // TODO: Think of a way to retrieve number of children files: fileOrFolder.children ? fileOrFolder.children.length : '-', } as unknown) as Folder); - } else if (fileOrFolder.typePath.includes('gcode') && fileOrFolder.origin === 'local') { - if (!fileOrFolder.gcodeAnalysis) { - this.notificationService.setError( - 'Corrupted file found!', - `File ${fileOrFolder.name} does not include GCodeAnalysis. Ignoring it for now ...`, + } else if (fileOrFolder.typePath.includes('gcode')) { + let filamentLength = 0; + if (fileOrFolder.gcodeAnalysis) { + _.forEach(fileOrFolder.gcodeAnalysis.filament, (tool): void => { + filamentLength += tool.length; + }); + var estimatedPrintTime = this.service.convertSecondsToHours( + fileOrFolder.gcodeAnalysis.estimatedPrintTime, ); - return; } - let filamentLength = 0; - _.forEach(fileOrFolder.gcodeAnalysis.filament, (tool): void => { - filamentLength += tool.length; - }); + + if (folderPath === '') { + if (fileOrFolder.origin == 'local') { + localCount += 1; + } else { + sdcardCount += 1; + } + } folder.push(({ type: 'file', - path: '/' + fileOrFolder.path, + path: '/' + fileOrFolder.origin + '/' + fileOrFolder.path, name: fileOrFolder.name, date: fileOrFolder.date, size: this.service.convertByteToMegabyte(fileOrFolder.size), - printTime: this.service.convertSecondsToHours( - fileOrFolder.gcodeAnalysis.estimatedPrintTime, - ), - filamentWeight: this.service.convertFilamentLengthToAmount(filamentLength), + ... (fileOrFolder.gcodeAnalysis) ? { + printTime: estimatedPrintTime, + filamentWeight: this.service.convertFilamentLengthToAmount(filamentLength), + } : {}, } as unknown) as File); } }); data = null; + + if (folderPath === '') { + if (localCount > 0 && sdcardCount > 0) { + folder.length = 0; + folder.push(({ + type: 'folder', + path: '/local', + name: 'local', + files: localCount, + } as unknown) as Folder); + folder.push(({ + type: 'folder', + path: '/sdcard', + name: 'sdcard', + files: sdcardCount, + } as unknown) as Folder); + } + } resolve(folder); }, @@ -100,21 +134,25 @@ export class FilesService { this.httpGETRequest.unsubscribe(); } this.httpGETRequest = this.http - .get(this.configService.getURL('files/local' + filePath), this.configService.getHTTPHeaders()) + .get(this.configService.getURL('files' + filePath), this.configService.getHTTPHeaders()) .subscribe( (data: OctoprintFilesAPI): void => { let filamentLength = 0; - _.forEach(data.gcodeAnalysis.filament, (tool): void => { - filamentLength += tool.length; - }); + if (data.gcodeAnalysis) { + _.forEach(data.gcodeAnalysis.filament, (tool): void => { + filamentLength += tool.length; + }); + } const file = ({ type: 'file', - path: '/' + data.path, + path: '/' + data.origin + '/' + data.path, name: data.name, size: this.service.convertByteToMegabyte(data.size), - printTime: this.service.convertSecondsToHours(data.gcodeAnalysis.estimatedPrintTime), - filamentWeight: this.service.convertFilamentLengthToAmount(filamentLength), - date: this.service.convertDateToString(new Date(data.date * 1000)), + ... (data.gcodeAnalysis) ? { + date: this.service.convertDateToString(new Date(data.date * 1000)), + printTime: this.service.convertSecondsToHours(data.gcodeAnalysis.estimatedPrintTime), + filamentWeight: this.service.convertFilamentLengthToAmount(filamentLength), + } : {}, thumbnail: data.path.endsWith('.ufp.gcode') ? this.configService .getURL('plugin/UltimakerFormatPackage/thumbnail/') @@ -142,7 +180,7 @@ export class FilesService { this.httpGETRequest.unsubscribe(); } this.httpGETRequest = this.http - .get(this.configService.getURL('files/local/' + filePath), this.configService.getHTTPHeaders()) + .get(this.configService.getURL('files' + filePath), this.configService.getHTTPHeaders()) .subscribe( (data: OctoprintFilesAPI): void => { let thumbnail = data.path.endsWith('.ufp.gcode') @@ -170,7 +208,7 @@ export class FilesService { }; this.httpPOSTRequest = this.http .post( - this.configService.getURL('files/local' + filePath), + this.configService.getURL('files' + filePath), loadFileBody, this.configService.getHTTPHeaders(), ) @@ -192,7 +230,7 @@ export class FilesService { }; this.httpPOSTRequest = this.http .post( - this.configService.getURL('files/local' + filePath), + this.configService.getURL('files' + filePath), printFileBody, this.configService.getHTTPHeaders(), ) @@ -209,7 +247,7 @@ export class FilesService { this.httpDELETERequest.unsubscribe(); } this.httpDELETERequest = this.http - .delete(this.configService.getURL('files/local' + filePath), this.configService.getHTTPHeaders()) + .delete(this.configService.getURL('files' + filePath), this.configService.getHTTPHeaders()) .subscribe( (): void => null, (error: HttpErrorResponse): void => { diff --git a/src/app/files/files.component.html b/src/app/files/files.component.html index 37667fb26..9566dbecf 100644 --- a/src/app/files/files.component.html +++ b/src/app/files/files.component.html @@ -12,7 +12,7 @@ -
+
@@ -51,9 +51,9 @@
{{ content.size }}mb - {{ content.filamentWeight }}{{ content.filamentWeight }}g - {{ content.printTime }}h + {{ content.printTime }}h
{{ content.name }} @@ -69,13 +69,13 @@ {{ fileDetail.name }} {{ fileDetail.path }} - {{ fileDetail.date }} + {{ fileDetail.date }} - - + +
{{ fileDetail.size }}mb{{ fileDetail.printTime }}h{{ fileDetail.filamentWeight }}g{{ fileDetail.printTime }}h{{ fileDetail.filamentWeight }}g
diff --git a/src/app/files/files.component.scss b/src/app/files/files.component.scss index e5088b3e6..d96050dd5 100755 --- a/src/app/files/files.component.scss +++ b/src/app/files/files.component.scss @@ -202,11 +202,11 @@ font-size: 4vw; font-weight: 500; - &:first-of-type { + &:first-of-type:not(:only-of-type) { text-align: left; } - &:last-of-type { + &:last-of-type:not(:only-of-type) { text-align: right; } } diff --git a/src/app/files/files.component.ts b/src/app/files/files.component.ts index 72d91e565..de6d17d36 100644 --- a/src/app/files/files.component.ts +++ b/src/app/files/files.component.ts @@ -19,6 +19,7 @@ export class FilesComponent { public sortingAttribute: 'name' | 'date' | 'size'; public sortingOrder: 'asc' | 'dsc'; public showSorting: boolean = false; + public homeFolder: string = '/'; public constructor( private filesService: FilesService, @@ -60,7 +61,12 @@ export class FilesComponent { .getFolder(folderPath) .then((data): void => { this.folderContent = data; - this.currentFolder = folderPath; + if (folderPath === '/' && !(data[0].name === 'local' && data[1].name == 'sdcard')) { + this.currentFolder = data[0].path.startsWith('/local') ? '/local' : '/sdcard'; + this.homeFolder = this.currentFolder; + } else { + this.currentFolder = folderPath; + } this.sortFolder(this.sortingAttribute, this.sortingOrder); this.spinner.hide(); }) diff --git a/src/app/job-status/job-status.component.html b/src/app/job-status/job-status.component.html index 81e878e0d..b391b185c 100644 --- a/src/app/job-status/job-status.component.html +++ b/src/app/job-status/job-status.component.html @@ -7,10 +7,9 @@ {{ job.filename }}
- {{ job.filamentAmount }}g Filament -
- {{ job.timeLeft.value }}{{ job.timeLeft.unit }} left, + {{ job.filamentAmount }}g Filament
+ {{ job.timeLeft.value }}{{ job.timeLeft.unit }} left, elapsed: {{ job.timePrinted.value }}{{ job.timePrinted.unit }}
@@ -33,19 +32,24 @@
- - {{ job.estimatedPrintTime.value }}{{ job.estimatedPrintTime.unit }} - - - will finish ~{{ job.estimatedEndTime }} - -
- - - {{ job.filamentAmount }}g + + + + {{ job.estimatedPrintTime.value }}{{ job.estimatedPrintTime.unit }} + + + - will finish ~{{ job.estimatedEndTime }} + +
- - filament will be used + + + + {{ job.filamentAmount }}g + + + filament will be used +
diff --git a/src/app/job.service.ts b/src/app/job.service.ts index 58ecac740..38e9d2349 100644 --- a/src/app/job.service.ts +++ b/src/app/job.service.ts @@ -50,33 +50,30 @@ export class JobService { job = { status: data.state, filename: data.job.file.display.replace('.gcode', '').replace('.ufp', ''), - thumbnail: - data.job.file.origin == 'sdcard' - ? undefined - : await this.fileService.getThumbnail(data.job.file.path), + thumbnail: await this.fileService.getThumbnail('/' + data.job.file.origin + '/' + data.job.file.path), progress: Math.round((data.progress.filepos / data.job.file.size) * 100), - filamentAmount: - data.job.filament === null - ? null - : this.service.convertFilamentLengthToAmount( - this.getTotalAmountOfFilament(data.job.filament), - ), - timeLeft: { - value: - data.progress.printTimeLeft === null - ? null - : this.service.convertSecondsToHours(data.progress.printTimeLeft), - unit: 'h', - }, + ... (data.job.filament !== null) ? { + filamentAmount: this.service.convertFilamentLengthToAmount( + this.getTotalAmountOfFilament(data.job.filament), + ), + } : {}, + ... (data.progress.printTimeLeft !== null) ? { + timeLeft: { + value: this.service.convertSecondsToHours(data.progress.printTimeLeft), + unit: 'h', + }, + } : {}, timePrinted: { value: this.service.convertSecondsToHours(data.progress.printTime), unit: 'h', }, - estimatedPrintTime: { - value: this.service.convertSecondsToHours(data.job.estimatedPrintTime), - unit: 'h', - }, - estimatedEndTime: this.calculateEndTime(data.job.estimatedPrintTime), + ... (data.job.estimatedPrintTime !== null) ? { + estimatedPrintTime: { + value: this.service.convertSecondsToHours(data.job.estimatedPrintTime), + unit: 'h', + }, + estimatedEndTime: this.calculateEndTime(data.job.estimatedPrintTime), + } : {}, }; } catch (error) { this.notificationService.setError("Can't retrieve Job Status", error); @@ -255,9 +252,9 @@ export interface Job { filename: string; thumbnail: string | undefined; progress: number; - filamentAmount: number; - timeLeft: Duration; + filamentAmount?: number; + timeLeft?: Duration; timePrinted: Duration; - estimatedPrintTime: Duration; - estimatedEndTime: string; + estimatedPrintTime?: Duration; + estimatedEndTime?: string; } diff --git a/src/app/octoprint-api/filesAPI.ts b/src/app/octoprint-api/filesAPI.ts index 264e82fe5..bd6cfff86 100644 --- a/src/app/octoprint-api/filesAPI.ts +++ b/src/app/octoprint-api/filesAPI.ts @@ -3,9 +3,10 @@ import { OctoprintFilament } from './jobAPI'; export interface OctoprintFilesAPI { date: number; display: string; - gcodeAnalysis: OctoprintGCodeAnalysis; + gcodeAnalysis?: OctoprintGCodeAnalysis; hash: string; name: string; + origin: string; path: string; prints: OctoprintPrints; refs: OctoprintRefs;