+ showAssets() {
+ this.setState({
+ panelTabShown: 'assets'
+ });
+ }
+ showDescriptor() {
+ this.setState({
+ panelTabShown: 'descriptor'
+ });
+ }
+
+ //File Manager methods
+ getFilelistSuccess(data) {
+ let self = this;
+ let filesState = null;
+ if (self.fileMonitoringSocketID) {
+ filesState = addInputState( _.cloneDeep(this.filesState),data);
+ // filesState = _.merge(self.filesState, addInputState({},data));
+ let normalizedData = normalizeTree(data);
+ this.setState({
+ files: {
+ data: _.mergeWith(normalizedData.data, self.files.data, function(obj, src) {
+ return _.uniqBy(obj? obj.concat(src) : src, 'name');
+ }),
+ id: self.files.id || normalizedData.id
+ },
+ filesState: filesState
+ });
+ }
+ function normalizeTree(data) {
+ let f = {
+ id:[],
+ data:{}
+ };
+ data.contents.map(getContents);
+ function getContents(d) {
+ if(d.hasOwnProperty('contents')) {
+ let contents = [];
+ d.contents.map(function(c,i) {
+ if (!c.hasOwnProperty('contents')) {
+ contents.push(c);
+ } else {
+ getContents(c);
+ }
+ })
+ f.id.push(d.name);
+ f.data[d.name] = contents;
+ }
+ }
+ return f;
+ }
+ function addInputState(obj, d) {
+ d.newFile = '';
+ if(d.hasOwnProperty('contents')) {
+ d.contents.map(addInputState.bind(null, obj))
+ }
+ if(!obj[d.name]) {
+ obj[d.name] = '';
+ }
+ return obj;
+ }
+ }
+ sendDownloadFileRequst(data) {
+ let id = data.id || this.item.id;
+ let type = data.type || this.item.uiState.type;
+ let path = data.path;
+ let url = data.url;
+ this.getInstance().addFile(id, type, path, url);
+ }
+ updateFileLocationInput = (data) => {
+ let name = data.name;
+ let value = data.value;
+ var filesState = _.cloneDeep(this.filesState);
+ filesState[name] = value;
+ this.setState({
+ filesState: filesState
+ });
+ }
+ addFileSuccess = (data) => {
+ let path = data.path;
+ let fileName = data.fileName;
+ let files = _.cloneDeep(this.files);
+ let loadingIndex = files.data[path].push({
+ status: 'DOWNLOADING',
+ name: path + '/' + fileName
+ }) - 1;
+ this.setState({files: files});
+
+ }
+ startWatchingJob = () => {
+ let ws = window.multiplexer.channel(this.jobSocketId);
+ this.setState({
+ jobSocket:null
+ })
+ }
+ openDownloadMonitoringSocketSuccess = (id) => {
+ let self = this;
+ let ws = window.multiplexer.channel(id);
+ let downloadJobs = _.cloneDeep(self.downloadJobs);
+ let newFiles = {};
+ ws.onmessage = (socket) => {
+ if (self.files && self.files.length > 0) {
+ let jobs = [];
+ try {
+ jobs = JSON.parse(socket.data);
+ } catch(e) {}
+ newFiles = _.cloneDeep(self.files);
+ jobs.map(function(j) {
+ //check if not in completed state
+ let fullPath = j['package-path'];
+ let path = fullPath.split('/');
+ let fileName = path.pop();
+ path = path.join('/');
+ let index = _.findIndex(self.files.data[path], function(o){
+ return fullPath == o.name
+ });
+ if((index > -1) && newFiles.data[path][index]) {
+ newFiles.data[path][index].status = j.status
+ } else {
+ if(j.status.toUpperCase() == 'LOADING...' || j.status.toUpperCase() == 'IN_PROGRESS') {
+ newFiles.data[path].push({
+ status: j.status,
+ name: fullPath
+ })
+ } else {
+ // if ()
+ }
+ }
+ })
+ self.setState({
+ files: newFiles
+ })
+ // console.log(JSON.parse(socket.data));
+ }
+ }
+ this.setState({
+ jobSocketId: id,
+ jobSocket: ws
+ })
+
+ }
+ getFilelistSocketSuccess = (id) => {
+ let self = this;
+ let ws = window.multiplexer.channel(id);
+ ws.onmessage = (socket) => {
+ if (self.fileMonitoringSocketID) {
+ let data = [];
+ try {
+ data = JSON.parse(socket.data);
+ } catch(e) {}
+ self.getFilelistSuccess(data)
+ }
+ }
+
+ this.setState({
+ fileMonitoringSocketID: id,
+ fileMonitoringSocket: ws
+ })
+
+ }
+ closeFileManagerSockets() {
+ this.fileMonitoringSocketID = null;
+ this.setState({
+ jobSocketId : null,
+ fileMonitoringSocketID : null
+ // jobSocket : null,
+ // fileMonitoringSocket : null,
+ });
+ this.jobSocket && this.jobSocket.close();
+ this.fileMonitoringSocket && this.fileMonitoringSocket.close();
+ console.log('closing');
+ }
+ openFileManagerSockets(i) {
+ let self = this;
+ let item = i || self.item;
+ this.files = {data:[]};
+ // this.closeFileManagerSockets();
+ this.getInstance().openFileMonitoringSocket(item.id, item.uiState.type).then(function() {
+ // // self.getInstance().openDownloadMonitoringSocket(item.id);
+ });
+ this.getInstance().openDownloadMonitoringSocket(item.id);
+ }
+ endWatchingJob(id) {
+
+ }
+ deletePackageFile(name) {
+ let id = this.item.id;
+ let type = this.item.uiState.type;
+ this.getInstance().deleteFile(id, type, name);
+ }
+ deleteFileSuccess = (data) => {
+ let path = data.path.split('/')
+ let files = _.cloneDeep(this.files);
+ path.pop();
+ path = path.join('/');
+ let pathFiles = files.data[path]
+ _.remove(pathFiles, function(c) {
+ return c.name == data.path;
+ });