From 0f57d7c8d596a81f465ae61366a434a75317e751 Mon Sep 17 00:00:00 2001 From: UnchartedBull Date: Thu, 17 Oct 2019 23:41:03 +0200 Subject: [PATCH] Fixed multi material issue --- src/app/files.service.ts | 23 ++++++++++++++++--- .../main-screen/main-screen.component.html | 9 +------- src/app/octoprint-api/filesAPI.ts | 2 +- src/app/octoprint-api/jobAPI.ts | 8 +++++-- src/app/octoprint-api/printerStatusAPI.ts | 8 +++++-- 5 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/app/files.service.ts b/src/app/files.service.ts index f617c74fb..ce5de8ce7 100644 --- a/src/app/files.service.ts +++ b/src/app/files.service.ts @@ -1,3 +1,4 @@ +import _ from 'lodash'; import { Injectable } from '@angular/core'; import { ConfigService } from './config/config.service'; import { HttpClient, HttpErrorResponse } from '@angular/common/http'; @@ -6,6 +7,7 @@ import { Subscription } from 'rxjs'; import { OctoprintFolderAPI, OctoprintFilesAPI, OctoprintFolderContentAPI } from './octoprint-api/filesAPI'; import { AppService } from './app.service'; + @Injectable({ providedIn: 'root' }) @@ -44,15 +46,26 @@ export class FilesService { // TODO: Think of a way to retrieve number of children files: fileOrFolder.children ? fileOrFolder.children.length : '-', } as Folder); - } else { + } 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 ...`); + return; + } + let filamentLength = 0; + _.forEach(fileOrFolder.gcodeAnalysis.filament, (tool) => { + filamentLength += tool.length; + }); + folder.push({ type: 'file', path: '/' + fileOrFolder.path, name: fileOrFolder.name, size: this.service.convertByteToMegabyte(fileOrFolder.size), printTime: this.service.convertSecondsToHours(fileOrFolder.gcodeAnalysis.estimatedPrintTime), - filamentWeight: this.service.convertFilamentLengthToAmount(fileOrFolder.gcodeAnalysis.filament.tool0.length), + filamentWeight: this.service.convertFilamentLengthToAmount(filamentLength), } as File); + } else if (fileOrFolder.typePath.includes('gcode') && fileOrFolder.origin === 'sdcard') { + // TODO } }); data = null; @@ -86,13 +99,17 @@ export class FilesService { this.httpGETRequest = this.http.get(this.configService.getURL('files/local' + filePath), this.configService.getHTTPHeaders()).subscribe( (data: OctoprintFilesAPI) => { + let filamentLength = 0; + _.forEach(data.gcodeAnalysis.filament, (tool) => { + filamentLength += tool.length; + }); const file = { type: 'file', path: '/' + data.path, name: data.name, size: this.service.convertByteToMegabyte(data.size), printTime: this.service.convertSecondsToHours(data.gcodeAnalysis.estimatedPrintTime), - filamentWeight: this.service.convertFilamentLengthToAmount(data.gcodeAnalysis.filament.tool0.length), + filamentWeight: this.service.convertFilamentLengthToAmount(filamentLength), date: this.service.convertDateToString(new Date(data.date * 1000)) } as File; resolve(file); diff --git a/src/app/main-screen/main-screen.component.html b/src/app/main-screen/main-screen.component.html index 3d6c8fa0b..466c38dc8 100644 --- a/src/app/main-screen/main-screen.component.html +++ b/src/app/main-screen/main-screen.component.html @@ -1,4 +1,4 @@ - -
- - - - -
diff --git a/src/app/octoprint-api/filesAPI.ts b/src/app/octoprint-api/filesAPI.ts index 54710b2f1..e899264f1 100644 --- a/src/app/octoprint-api/filesAPI.ts +++ b/src/app/octoprint-api/filesAPI.ts @@ -35,7 +35,7 @@ export interface OctoprintFolderContentAPI { interface OctoprintGCodeAnalysis { analysisFirstFilamentPrintTime: number; analysisLastFilamentPrintTime: number; - analysisPending: number; + analysisPending: boolean; analysisPrintTime: number; compensatedPrintTime: number; dimensions: { diff --git a/src/app/octoprint-api/jobAPI.ts b/src/app/octoprint-api/jobAPI.ts index e4c6684bd..9f47cb4f6 100644 --- a/src/app/octoprint-api/jobAPI.ts +++ b/src/app/octoprint-api/jobAPI.ts @@ -22,8 +22,12 @@ interface OctoprintFile { } export interface OctoprintFilament { - tool0: OctoprintFilamentValues; - tool1: OctoprintFilamentValues; + tool0?: OctoprintFilamentValues; + tool1?: OctoprintFilamentValues; + tool2?: OctoprintFilamentValues; + tool3?: OctoprintFilamentValues; + tool4?: OctoprintFilamentValues; + tool5?: OctoprintFilamentValues; [key: string]: any; } diff --git a/src/app/octoprint-api/printerStatusAPI.ts b/src/app/octoprint-api/printerStatusAPI.ts index 9b3eb788e..fac7e06a6 100644 --- a/src/app/octoprint-api/printerStatusAPI.ts +++ b/src/app/octoprint-api/printerStatusAPI.ts @@ -5,8 +5,12 @@ export interface OctoprintPrinterStatusAPI { } interface OctoprintTemperature { - tool0: OctoprintTemperatureData; - tool1: OctoprintTemperatureData; + tool0?: OctoprintTemperatureData; + tool1?: OctoprintTemperatureData; + tool2?: OctoprintTemperatureData; + tool3?: OctoprintTemperatureData; + tool4?: OctoprintTemperatureData; + tool5?: OctoprintTemperatureData; bed: OctoprintTemperatureData; [key: string]: any; }