/*
*
* Copyright 2016 RIFT.IO Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
//https://raw.githubusercontent.com/RIFTIO/RIFT.ware/master/rift-shell
import _cloneDeep from 'lodash/cloneDeep'
import _findIndex from 'lodash/findIndex'
import _uniqueId from 'lodash/uniqueId'
import React from 'react';
import ReactDOM from 'react-dom';
import TreeView from 'react-treeview';
import TextInput from 'widgets/form_controls/textInput.jsx';
import Button from '../Button';
import './FileMananger.scss';
import FileManagerActions from './FileManagerActions.js';
import imgSave from '../../../../node_modules/open-iconic/svg/data-transfer-upload.svg'
import { Panel, PanelWrapper } from 'widgets/panel/panel';
import SkyquakeComponent from 'widgets/skyquake_container/skyquakeComponent.jsx';
import LoadingIndicator from 'widgets/loading-indicator/loadingIndicator.jsx';
import DropZone from 'dropzone'
import Utils from '../../libraries/utils'
import FileManagerUploadDropZone from '../../libraries/FileManagerUploadDropZone';
let API_SERVER = require('utils/rw.js').getSearchParams(window.location).api_server;
const ASSET_TYPE = {
'nsd': [
{ id: 'ICONS', folder: 'icons', title: "Icons", allowFolders: false },
{ id: 'SCRIPTS', folder: 'scripts', title: "scripts", allowFolders: true },
{ id: 'NS_CONFIG', folder: 'ns_config', title: "NS Config", allowFolders: false },
{ id: 'VNF_CONFIG', folder: 'vnf_config', title: "VNF Config", allowFolders: false }
],
'vnfd': [
{ id: 'ICONS', folder: 'icons', title: "Icons", allowFolders: false },
{ id: 'CHARMS', folder: 'charms', title: "charms", allowFolders: true },
{ id: 'SCRIPTS', folder: 'scripts', title: "scripts", allowFolders: true },
{ id: 'IMAGES', folder: 'images', title: "images", allowFolders: false },
{ id: 'CLOUD_INIT', folder: 'cloud_init', title: "cloud_init", allowFolders: false },
{ id: 'README', folder: '.', title: "readme", allowFolders: false }
]
}
const createDropZone = function (action, clickable, getUploadPropsCallback, dropTarget) {
const dropZone = new FileManagerUploadDropZone(ReactDOM.findDOMNode(dropTarget), [clickable], action, getUploadPropsCallback);
// dropZone.on('dragover', this.onDragOver);
// dropZone.on('dragend', this.onDragEnd);
// dropZone.on('addedfile', this.onFileAdded);
return dropZone;
};
function normalizeAssets(packageType, assetInfo, filesStatus) {
let assets = {};
let assetTypes = ASSET_TYPE[packageType];
assetTypes.forEach(assetGroup => {
const typeFolder = assetGroup.folder;
let folders = assetInfo.id.filter(name => name.startsWith(typeFolder));
if (folders.length) {
folders.reverse();
assets[assetGroup.id] = folders.map(fullName => {
let path = fullName.slice(typeFolder.length + 1);
let files = assetInfo.data[fullName].map(info => ({
name: info.name.startsWith(fullName) ? info.name.slice(fullName.length + 1) : info.name,
status: filesStatus[info.name]
}));
return { path, files };
});
}
});
return assets;
}
function sendDeleteFileRequest(assetType, path, name) {
path = path ? path + '/' + name : name;
FileManagerActions.deletePackageFile({ assetType, path });
}
class FileManager extends React.Component {
constructor(props) {
super(props)
let assests = props.files;
}
componentWillMount() {
// FileManagerActions.openFileManagerSockets()
}
componentWillUnmount() {
// FileManagerActions.closeFileManagerSockets();
}
generateFolder(data, nesting) {
let nestingLevel = nesting || 1;
}
render() {
let { files, filesState, type, item, actions } = this.props;
let assets = normalizeAssets(type, files, filesState);
let children = [];
let assetTypes = ASSET_TYPE[type];
assetTypes.forEach(assetGroup => {
const typeFolder = assetGroup.folder;
let folders = assets[assetGroup.id];
let rootAssets = { path: '', files: [] };
let subFolders = null;
if (folders && folders.length) {
rootAssets = folders[0];
subFolders = folders.slice(1);
}
children.push(