import Vue from "vue"; import Component from "vue-class-component"; import { ModalHelper,Modal } from "src/components/modals"; import { Factory, MessageService, awaiter } from "../../_base"; // import { MaintenanceService } from "../services/maintenanceService"; // import { store } from "src/store"; // import { maintenanceActions } from "../store/maintenance.store"; import moment from "moment"; import cardFolderPath from "./cards/card-folder-path.vue"; import cardElementQueue from "src/app_modules/production/components/card-element-queue.vue"; import * as iziToast from "izitoast"; import { fileService } from "../../services/fileService"; declare var cmsClient: any; interface PathInfo { Name: string; AbsolutePath: string; Path: string; IsDirectory: boolean; } interface FileInfo { Name: string; AbsolutePath: string; CreationDate: string; LastModDate: string; Content: Array; PreviewBase64: any; IsJob: boolean; } @Component({ components: { modal: Modal, cardFolderPath, cardElementQueue } }) export default class ModalLoadProgram extends Vue { driveList: Array = []; currentPath: string = ""; currentDrive: string = null; lastClickPath: string = ""; breadcrumbs: Array = []; firstColumnData: Array = []; secondColumnData: Array = []; isLocalNavigation: boolean = true; selectedFile: FileInfo = null; selectedFileMetadata = null; currentFilterFirst: string = ""; currentFilterSecond: string = ""; navigationDepth: number = 0; mounted() { if (typeof cmsClient != "undefined") { this.driveList = JSON.parse(cmsClient.getOSdriveList()); } } async navigateTo( path: string, absolutePath: string, local: boolean, todepth: number, fromdepth: number ) { this.currentPath = absolutePath; this.lastClickPath = absolutePath; this.checkChangeNavigationType(local); var files = await this.getFilesForPath(absolutePath, path, local); // controlla se impostare il currentDrive if (fromdepth == 0) this.currentDrive = absolutePath; // controlla come organizzare le colonne. if (this.navigationDepth == 2 && todepth == 2 && fromdepth == 2) { this.fillArray(this.firstColumnData, this.secondColumnData); } this.navigationDepth = todepth; if (todepth == 1) { this.fillArray(this.firstColumnData, files); this.secondColumnData.splice(0, this.secondColumnData.length); this.currentFilterFirst = ""; this.selectedFile = null; this.selectedFileMetadata = null; } if (todepth == 2) { this.fillArray(this.secondColumnData, files); this.currentFilterSecond = ""; } this.calcBreadCrumb(absolutePath); } fillArray(destinationArray: Array, sourceArray: Array) { destinationArray.splice(0, destinationArray.length); for (const key in sourceArray) { if (sourceArray.hasOwnProperty(key)) { const element = sourceArray[key]; destinationArray.push(element); } } } checkChangeNavigationType(local: boolean) { if (this.isLocalNavigation != local) { this.navigationDepth = 0; this.firstColumnData.splice(0, this.firstColumnData.length); this.secondColumnData.splice(0, this.secondColumnData.length); } } async getFilesForPath(absolutePath: string, path: string, local: boolean): Promise> { this.isLocalNavigation = local; var result = null; if (local) result = JSON.parse(cmsClient.getFileList(absolutePath)); else result = await awaiter(fileService.getFiles(path)); return this.toUpperCaseModel(result).sort(this.compareDirectoriesFirst); } private compareDirectoriesFirst(x, y) { return (x.IsDirectory === y.IsDirectory) ? 0 : x.IsDirectory ? -1 : 1; } toUpperCaseModel(data: Array): Array { return data.map(i => { return { Name: i.name || i.Name, AbsolutePath: i.absolutePath || i.AbsolutePath, Path: i.path || i.Path, IsDirectory: (i.isDirectory != null && i.isDirectory) || (i.IsDirectory != null && i.IsDirectory) }; }); } calcBreadCrumb(path: string) { this.breadcrumbs.splice(0, this.breadcrumbs.length); if (path.startsWith("\\\\")) { this.breadcrumbs.push({ name: "CN", path: "\\\\" }); } if (path) { var fragments = path.split("\\"); var __p = ""; fragments.forEach(element => { __p = __p + element + "\\"; this.breadcrumbs.push({ name: element, path: __p }); }); } } isInPath(path) { if (this.currentPath) return this.currentPath.startsWith(path); return false; } toUpperCaseFileModel(data: any): FileInfo { return { AbsolutePath: data.absolutePath || data.AbsolutePath, Path: data.path || data.Path, Content: data.content || data.Content, CreationDate: data.creationDate || data.CreationDate, LastModDate: data.lastModDate || data.LastModDate, Name: data.name || data.Name, PreviewBase64: data.previewBase64 || data.PreviewBase64, IsJob: data.isJob || data.IsJob } as FileInfo; } async fileInfo(str, fromdepth: number) { this.lastClickPath = str; if (fromdepth == 1) this.secondColumnData.splice(0, this.secondColumnData.length); if (this.isLocalNavigation && typeof cmsClient != "undefined"){ this.selectedFile = this.toUpperCaseFileModel( JSON.parse(cmsClient.getProgramInfo(str)) ); this.selectedFileMetadata = JSON.parse(cmsClient.readJobMetadata(str)).metadata; console.log(this.selectedFileMetadata); } if (!this.isLocalNavigation) this.selectedFile = this.toUpperCaseFileModel( await awaiter(fileService.getFileInfo(str))); } close() { Factory.Get(MessageService).deleteChannel("esc_pressed"); ModalHelper.HideModal(); } reload() { this.driveList = JSON.parse(cmsClient.getOSdriveList()); } getDate(date) { return moment(date).format("L"); } async load(item: FileInfo) { if (item.IsJob) this.loadJob(item.AbsolutePath); else this.loadProgram(item.AbsolutePath); } async loadProgram(path: string) { if (this.isLocalNavigation && typeof cmsClient != "undefined") { var resp = cmsClient.uploadAndActivateProgram(path); if (resp != "") (iziToast as any).error({ title: resp.split(";")[0], message: resp.split(";")[1], theme: "dark", timeout: 10000, class: "t-error", transitionOut: "fadeOut", }) else this.close(); } if (!this.isLocalNavigation) { await awaiter(fileService.activateProgram(path)); this.close(); } } async loadJob(path: string) { var jobMetadata = cmsClient.readJobMetadata(path); // var result = await ModalHelper.ShowModalAsync(, jobMetadata); } }