X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;ds=inline;f=skyquake%2Fplugins%2Fcomposer%2Fsrc%2Fsrc%2Fcomponents%2Ffilemanager%2FFileManager.jsx;h=d5eea5196da8c478caaa87bc948d2bd12203476a;hb=HEAD;hp=ed9ea93a5c83041b1436f366d6071b221be82299;hpb=c5b71af99c40f4ead1384cf6f85e4d052000484a;p=osm%2FUI.git
diff --git a/skyquake/plugins/composer/src/src/components/filemanager/FileManager.jsx b/skyquake/plugins/composer/src/src/components/filemanager/FileManager.jsx
index ed9ea93a5..d5eea5196 100644
--- a/skyquake/plugins/composer/src/src/components/filemanager/FileManager.jsx
+++ b/skyquake/plugins/composer/src/src/components/filemanager/FileManager.jsx
@@ -20,6 +20,7 @@
//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';
@@ -28,7 +29,7 @@ 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 { Panel, PanelWrapper } from 'widgets/panel/panel';
import SkyquakeComponent from 'widgets/skyquake_container/skyquakeComponent.jsx';
import LoadingIndicator from 'widgets/loading-indicator/loadingIndicator.jsx';
@@ -37,17 +38,70 @@ import Utils from '../../libraries/utils'
import FileManagerUploadDropZone from '../../libraries/FileManagerUploadDropZone';
let API_SERVER = require('utils/rw.js').getSearchParams(window.location).api_server;
-const createDropZone = function (action, clickable, type, id, path, dropTarget) {
- const dropZone = new FileManagerUploadDropZone(ReactDOM.findDOMNode(dropTarget), [clickable], action, type, id, path);
+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 },
+ { id: 'DOC', folder: 'doc', title: "Doc", allowFolders: false },
+ { id: 'TEST', folder: 'test', title: "Test", 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: 'CLOUD_INIT', folder: 'cloud_init', title: "cloud_init", allowFolders: false },
+ { id: 'DOC', folder: 'doc', title: "Doc", allowFolders: false },
+ { id: 'TEST', folder: 'test', title: "Test", 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;
};
-//updateFileLocationInput
+
+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].reduce((assets, info) =>
+ {
+ let name = info.name.startsWith(fullName) ? info.name.slice(fullName.length + 1) : info.name;
+ let status = filesStatus[info.name];
+ if (fullName !== '.' || !(name.endsWith('.yaml') || name.startsWith('checksum'))) {
+ assets.push({ name, status });
+ }
+ return assets;
+ }
+ , []);
+ 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()
@@ -57,62 +111,47 @@ class FileManager extends React.Component {
}
generateFolder(data, nesting) {
let nestingLevel = nesting || 1;
-
}
- deleteFile(name) {
- return function(e) {
- FileManagerActions.deletePackageFile(name);
- }
-
- }
- updateFileLocationInput(name) {
- return function(e) {
- FileManagerActions.updateFileLocationInput({
- name: name,
- value: e.target.value
- });
+ render() {
+ let { files, filesState, type, item, actions } = this.props;
+ if (!item) {
+ return null;
}
- }
- sendDownloadFileRequst = (url, path) => {
- let self = this;
- return function(e) {
- if(!url || url == "") {
- return self.props.actions.showNotification.defer({type: 'error', msg: 'Value missing in download request'});;
+ let assets = normalizeAssets(type, files, filesState);
+ let children = [];
+ const User = this.props.User || {};
+ const ProjectID = User.projectId;
+ 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);
}
- let files = self.props.files.data;
- let folder = path.split('/');
- let splitUrl = url.split('/');
- let fileName = splitUrl[splitUrl.length - 1];
- folder.pop;
- let fullPath = _cloneDeep(folder);
- fullPath.push(fileName);
- fullPath = fullPath.join('/');
- folder = folder.join('/');
- let fileIndex = _findIndex(files[folder], function(f) {
- return f.name == fullPath;
- })
- if (fileIndex == -1) {
- FileManagerActions.sendDownloadFileRequst({
- url: url,
- path: path
- });
- } else {
- self.props.actions.showNotification('It seems you\'re attempting to upload a file with a duplicate file name');
- }
- }
- }
- render() {
- let self = this;
+ children.push(
+