3a0e1bc2a4
Added filePath config
231 lines
6.4 KiB
TypeScript
231 lines
6.4 KiB
TypeScript
import Vue from "vue";
|
|
import Component from "vue-class-component";
|
|
import Modal from "src/modules/base-components/modal.vue";
|
|
import { ModalHelper } from "src/modules/base-components/ModalHelper";
|
|
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 "./cards/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<any>;
|
|
PreviewBase64: any;
|
|
}
|
|
|
|
@Component({
|
|
components: {
|
|
modal: Modal,
|
|
cardFolderPath,
|
|
cardElementQueue
|
|
}
|
|
})
|
|
export default class ModalLoadProgram extends Vue {
|
|
driveList: Array<PathInfo> = [];
|
|
currentPath: string = "";
|
|
currentDrive: string = null;
|
|
lastClickPath: string = "";
|
|
|
|
breadcrumbs: Array<any> = [];
|
|
|
|
firstColumnData: Array<PathInfo> = [];
|
|
secondColumnData: Array<PathInfo> = [];
|
|
|
|
isLocalNavigation: boolean = true;
|
|
selectedFile: FileInfo = 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;
|
|
}
|
|
|
|
if (todepth == 2) {
|
|
this.fillArray(this.secondColumnData, files);
|
|
this.currentFilterSecond = "";
|
|
}
|
|
this.calcBreadCrumb(absolutePath);
|
|
}
|
|
|
|
fillArray(destinationArray: Array<any>, sourceArray: Array<any>) {
|
|
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<Array<any>> {
|
|
this.isLocalNavigation = local;
|
|
var result = null;
|
|
console.log(path);
|
|
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<any>): Array<PathInfo> {
|
|
console.log(data)
|
|
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
|
|
} 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))
|
|
);
|
|
|
|
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 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();
|
|
}
|
|
}
|
|
}
|