From 3817ee7ae2546674df30bf5710f917006798e676 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 8 Aug 2017 12:22:43 +0300 Subject: [PATCH] feature(cloudcmd) add emitter --- client/client.js | 21 +++++++++++++++++---- client/dom/index.js | 19 ++++++++++++------- client/modules/konsole.js | 9 +++++++-- package.json | 5 +++++ 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/client/client.js b/client/client.js index 3a479245..46604537 100644 --- a/client/client.js +++ b/client/client.js @@ -3,6 +3,8 @@ /* global Util, DOM */ const itype = require('itype/legacy'); +const emitify = require('emitify/legacy'); +const inherits = require('inherits'); const rendy = require('rendy'); const exec = require('execon'); const Images = require('./dom/images'); @@ -16,6 +18,10 @@ const { buildFromJSON, } = require('../common/cloudfunc'); +/* global Util, DOM */ + +inherits(CloudCmdProto, Emitify); + module.exports = new CloudCmdProto(Util, DOM); function CloudCmdProto(Util, DOM) { @@ -24,12 +30,14 @@ function CloudCmdProto(Util, DOM) { let Listeners; const log = (str) => { - if (Debug) - console.log(str); + if (!Debug) + return; - return str; + console.log(str); }; + Emitify.call(this); + const CloudCmd = this; const Info = DOM.CurrentInfo; const Storage = DOM.Storage; @@ -251,6 +259,7 @@ function CloudCmdProto(Util, DOM) { } DOM.setCurrentFile(current); + CloudCmd.execFromModule(module, 'show'); }; @@ -310,6 +319,8 @@ function CloudCmdProto(Util, DOM) { function baseInit(callback) { const files = DOM.getFiles(); + CloudCmd.on('current-file', DOM.updateCurrentInfo); + /* выделяем строку с первым файлом */ if (files) DOM.setCurrentFile(files[0], { @@ -507,10 +518,12 @@ function CloudCmdProto(Util, DOM) { if (!current) current = DOM.getFiles(panel)[0]; - + DOM.setCurrentFile(current, { history: history }); + + CloudCmd.emit('active-dir', Info.dirPath); } exec(callback); diff --git a/client/dom/index.js b/client/dom/index.js index 369431ca..399da5c9 100644 --- a/client/dom/index.js +++ b/client/dom/index.js @@ -159,7 +159,7 @@ function CmdProto() { * get current direcotory path */ this.getCurrentDirPath = (panel = DOM.getPanel()) => { - const path = DOM.getByDataName('js-path', panel); + const path = DOM.getByDataName('js-path', panel); const ret = path && path.textContent; return ret; @@ -473,17 +473,17 @@ function CmdProto() { * to prevent default behavior */ if (!o || o.history !== false) { - if (path !== '/') - path = FS + path; - - DOM.setHistory(path, null, path); + const historyPath = path === '/' ? path : FS + path; + DOM.setHistory(historyPath, null, historyPath); } } /* scrolling to current file */ DOM.scrollIntoViewIfNeeded(currentFile, CENTER); - Cmd.updateCurrentInfo(currentFile); + CloudCmd.emit('current-file', currentFile); + CloudCmd.emit('current-path', path); + CloudCmd.emit('current-name', DOM.getCurrentName(currentFile)); return DOM; }; @@ -996,7 +996,6 @@ function CmdProto() { return; DOM.setCurrentName(to, current); - Cmd.updateCurrentInfo(current); Storage.remove(dirPath); if (isExist) @@ -1029,7 +1028,11 @@ function CmdProto() { }; this.changePanel = () => { + const Info = CurrentInfo; let panel = DOM.getPanel(); + + CloudCmd.emit('passive-dir', Info.dirPath); + const panelPassive = DOM.getPanel({ active: false }); @@ -1067,6 +1070,8 @@ function CmdProto() { history: true }); + CloudCmd.emit('active-dir', Info.dirPath); + return DOM; }; diff --git a/client/modules/konsole.js b/client/modules/konsole.js index dbcf92a6..6cbead67 100644 --- a/client/modules/konsole.js +++ b/client/modules/konsole.js @@ -6,8 +6,12 @@ /* global Console */ const exec = require('execon'); +const currify = require('currify/legacy'); const Images = require('../dom/images'); -const {Dialog} = DOM; +const { + Dialog, + CurrentInfo:Info, +} = DOM; CloudCmd.Konsole = ConsoleProto; @@ -63,7 +67,7 @@ function ConsoleProto() { PASSIVE_DIR: DOM.getNotCurrentDirPath.bind(DOM), CURRENT_NAME: DOM.getCurrentName.bind(DOM), CURRENT_PATH: () => { - return DOM.CurrentInfo.path; + return Info.path; } }; } @@ -77,6 +81,7 @@ function ConsoleProto() { Console(Element, options, (spawn) => { spawn.on('connect', exec.with(authCheck, spawn)); + exec(callback); }); diff --git a/package.json b/package.json index 099a51de..86bfdad4 100644 --- a/package.json +++ b/package.json @@ -178,6 +178,11 @@ "html-looks-like": "^1.0.2", "html-webpack-plugin": "^3.0.4", "limier": "^2.0.0", + "html-webpack-exclude-assets-plugin": "^0.0.5", + "html-webpack-plugin": "^2.29.0", + "inherits": "^2.0.3", + "jscs": "^3.0.1", + "jshint": "^2.8.0", "minor": "^1.2.2", "mkdirp": "^0.5.1", "mock-require": "^3.0.1",