UNPKG

makedrive

Version:
4 lines (3 loc) 5.42 kB
/*! makedrive 0.0.68 2014-11-14 */ angular.module("makedriveApp",["ui.bootstrap","makedriveApp.services"]),angular.module("makedriveApp").controller("editor",["$window",function($window){ace.config.set("basePath","/vendors/ace-builds/src-min"),$window.editor=ace.edit(document.getElementById("editor")),editor.setTheme("ace/theme/monokai"),editor.getSession().setMode("ace/mode/javascript")}]).controller("make",["$window","$scope","$rootScope","getList",function($window,$scope,$rootScope,Make){var prev,sh=$window.MakeDrive.fs().Shell(),Path=$window.MakeDrive.Path,fs=$window.MakeDrive.fs({manual:!0}),sync=fs.sync;$scope.mkfile=function(){$window.filerDialogs.showSaveAsDialog("Create new file","/","name",function(error,path){sh.mkdirp(Path.dirname(path),function(e){e&&console.error(e),fs.writeFile(path,$window.editor.getValue(),function(e){e&&console.error(e),$rootScope.$emit("mkfile",path),sync.request()})})})},$scope.save=function(){$rootScope.canSave&&fs.writeFile($rootScope.selectedPath,$window.editor.getValue(),function(e){e&&console.error(e),$rootScope.$emit("mkfile",$rootScope.selectedPath),sync.request(),$rootScope.canSave=!1})},$scope.rename=function(){if($rootScope.canSave){var dirname=Path.dirname($rootScope.selectedPath),basename=Path.basename($rootScope.selectedPath),path=prompt("Rename",basename),newPath=Path.join(dirname,path);null!=path&&fs.rename($rootScope.selectedPath,newPath,function(){$rootScope.$emit("mkfile",newPath),sync.request()})}},$scope.delete=function(){$rootScope.selectedPath&&Make.remove()},$rootScope.open=function(){$window.filerDialogs.showOpenDialog(!1,!1,"Open file","/","",function(e,d){fs.readFile(d[0],"utf8",function(e,data){e||($window.editor.setValue(data),prev=jQuery.jstree.reference("#jstree").get_selected(),jQuery("#jstree").jstree("deselect_node",prev),jQuery("#jstree").jstree("select_node",d[0]))})})}}]).controller("clickToggle",["$scope",function($scope){$scope.toggled=!1,$scope.toggle=function(){$scope.toggled=!$scope.toggled,$("#wrapper").toggleClass("toggled")}}]).controller("init",["getList","$window","$scope","param","$rootScope",function(Make,$window,$scope,param,$rootScope){var fs=$window.MakeDrive.fs({manual:!0}),sync=($window.MakeDrive.fs().Shell(),fs.sync);sync.on("connected",function(){Make.getListing(),console.log("server has connected")}),sync.on("syncing",function(){console.log("syncing in progress")}),sync.on("reconnecting",function(){console.log("reconnecting")}),sync.on("reconnect_failed",function(){console.log("reconnect_failed")}),sync.connect(param("makedrive")),$rootScope.$on("mkfile",function(e,path){setTimeout(function(){var prev;jQuery.jstree.reference("#jstree")&&(prev=jQuery.jstree.reference("#jstree").get_selected()),jQuery("#jstree").jstree("deselect_node",prev),jQuery("#jstree").jstree("select_node",path)},500)}),sync.on("completed",function(){Make.getListing(),$("#success").fadeIn(1e3),$("#success").fadeOut(5e3)}),sync.on("error",function(e){e.code&&e.message?e="Error code: "+e.code+" - "+e.message:e.stack?e=e.stack:e.data?e=e.data:e.error&&(e=e.error),console.error(e),$scope.error=e.stack,$("#error").fadeIn(1e3),$("#error").fadeOut(5e3)})}]),angular.module("makedriveApp.services",[]).factory("getList",["$rootScope","$http","$window",function($rootScope,$http,$window){function getContent(data){var listing=[];return data.map(function(content,index){0!=index&&(currentPath="/"),currentPath=Path.join(currentPath||"/",content.path);var node;node="DIRECTORY"!==content.type?{text:content.path,icon:"/demo/assets/icons/document.png",id:currentPath}:{text:content.path,id:currentPath},content.contents&&(node.children=getContent(content.contents)),listing.push(node)}),listing}function openFile(){fs.stat($rootScope.selectedPath,function(e,stat){e||(!stat.isDirectory()&&$rootScope.selectedPath?($rootScope.canSave=!0,$rootScope.$apply(),fs.readFile($rootScope.selectedPath,"utf8",function(e,data){e||$window.editor.setValue(data)})):($rootScope.canSave=!1,$rootScope.$apply()))})}function createTree(data){$("#jstree").jstree({core:{multiple:!1,data:[{text:"/",state:{opened:!0,selected:!1},children:data}]}}).bind("select_node.jstree",function(e,data){$rootScope.selectedPath=Path.normalize(data.instance.get_path(data.node).join("/")),openFile()}),jQuery.jstree.reference("#jstree").refresh()}var Make={};$rootScope.canSave=!1;var currentPath,fs=$window.MakeDrive.fs({manual:!0,autoReconnect:!0,reconnectionDelay:500,reconnectionDelayMax:1500,reconnectAttempts:20}),sh=$window.MakeDrive.fs().Shell(),sync=fs.sync,Path=$window.MakeDrive.Path;return Make.remove=function(){fs.stat($rootScope.selectedPath,function(e,stat){stat.isDirectory()?sh.rm($rootScope.selectedPath,{recursive:!0},function(){$rootScope.selectedPath=null,$rootScope.canSave=!1,$rootScope.$apply(),sync.request("/")}):fs.unlink($rootScope.selectedPath,function(){$rootScope.selectedPath=null,$rootScope.canSave=!1,$rootScope.$apply(),sync.request()})})},Make.getListing=function(){jQuery.jstree.reference("#jstree")&&jQuery.jstree.reference("#jstree").destroy(),sh.ls("/",{recursive:!0},function(err,data){err&&console.error(err),newListing=getContent(data),createTree(newListing)})},Make}]).factory("param",["$window",function($window){return getParam=function(name){var results=new RegExp("[?&]"+name+"=([^&#]*)").exec($window.location.href);return null==results?null:results[1]||0}}]); //# sourceMappingURL=app.min.map