mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-22 00:35:15 +02:00
add filesystem(file explorer) support, done
This commit is contained in:
50
res/app/control-panes/filesystem/fs-controller.js
Normal file
50
res/app/control-panes/filesystem/fs-controller.js
Normal file
@@ -0,0 +1,50 @@
|
||||
module.exports = function FsCtrl($scope, $timeout) {
|
||||
$scope.search = ''
|
||||
$scope.files = [];
|
||||
$scope.paths = [];
|
||||
|
||||
var listdir = function(){
|
||||
var path = '/'+$scope.paths.join('/');
|
||||
$scope.control.fslist(path)
|
||||
.then(function(result){
|
||||
$scope.files = result.body;
|
||||
$scope.$digest();
|
||||
})
|
||||
.catch(function(err){
|
||||
alert(err.message);
|
||||
})
|
||||
}
|
||||
|
||||
$scope.dirEnter = function(name){
|
||||
if (name){
|
||||
$scope.paths.push(name);
|
||||
}
|
||||
listdir();
|
||||
$scope.search = '';
|
||||
}
|
||||
|
||||
$scope.dirJump = function(){
|
||||
if ($scope.paths.length !== 0){
|
||||
$scope.paths.pop();
|
||||
}
|
||||
listdir();
|
||||
}
|
||||
|
||||
$scope.getFile = function(file){
|
||||
var path = '/'+$scope.paths.join('/')+'/'+file;
|
||||
$scope.control.fsretrive(path)
|
||||
.then(function(result){
|
||||
location.href = result.body.href+"?download"
|
||||
})
|
||||
.catch(function(err){
|
||||
alert(err.message);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// init
|
||||
// $scope.list($scope.dir); // FIXME(ssx): can't call immediately, do not known why.
|
||||
$timeout(function(){
|
||||
listdir();
|
||||
}, 800);
|
||||
}
|
||||
17
res/app/control-panes/filesystem/fs-spec.js
Normal file
17
res/app/control-panes/filesystem/fs-spec.js
Normal file
@@ -0,0 +1,17 @@
|
||||
describe('FsCtrl', function () {
|
||||
|
||||
beforeEach(angular.mock.module(require('./').name));
|
||||
|
||||
var scope, ctrl;
|
||||
|
||||
beforeEach(inject(function ($rootScope, $controller) {
|
||||
scope = $rootScope.$new();
|
||||
ctrl = $controller('FsCtrl', {$scope: scope});
|
||||
}));
|
||||
|
||||
it('should ...', inject(function () {
|
||||
expect(1).toEqual(1);
|
||||
|
||||
}));
|
||||
|
||||
});
|
||||
30
res/app/control-panes/filesystem/fs.jade
Normal file
30
res/app/control-panes/filesystem/fs.jade
Normal file
@@ -0,0 +1,30 @@
|
||||
.stf-fs(ng-controller='FsCtrl')
|
||||
.row: .col-md-6
|
||||
|
||||
span /{{paths.join("/")}}
|
||||
button.btn.btn-xm.btn-primary-outline(ng-click='dirJump()')
|
||||
span(translate) Back
|
||||
|
||||
form.input-group.form-inline(ng-submit='dirEnter(search)')
|
||||
input(type=text, ng-model='search', placeholder="dir or file ...").form-control
|
||||
span.input-group-btn
|
||||
button.btn.btn-default.btn-primary-outline(type='submit')
|
||||
i.fa.fa-search
|
||||
span(translate) Enter
|
||||
|
||||
table.table
|
||||
tr(ng-repeat='f in files | filter:search | orderBy: "-mode|isdir"')
|
||||
td
|
||||
span
|
||||
i.fa.fa-folder-open(ng-show='f.mode|isdir')
|
||||
i.fa.fa-file-o(ng-hide='f.mode|isdir')
|
||||
td
|
||||
button.btn.btn-sm.btn-primary-outline(
|
||||
ng-click='dirEnter(f.name)', ng-show='f.mode|isdir')
|
||||
{{f.name}}
|
||||
button.btn.btn-sm.btn-primary-outline(
|
||||
ng-click='getFile(f.name)', ng-hide='f.mode|isdir')
|
||||
{{f.name}}
|
||||
td
|
||||
i {{f.mode|mode2unix}}
|
||||
td {{f.size}}
|
||||
0
res/app/control-panes/filesystem/fs.less
Normal file
0
res/app/control-panes/filesystem/fs.less
Normal file
37
res/app/control-panes/filesystem/index.js
Normal file
37
res/app/control-panes/filesystem/index.js
Normal file
@@ -0,0 +1,37 @@
|
||||
require('./fs.less')
|
||||
|
||||
module.exports = angular.module('stf.filesystem', [])
|
||||
.run(["$templateCache", function ($templateCache) {
|
||||
$templateCache.put('control-panes/filesystem/fs.jade',
|
||||
require('./fs.jade')
|
||||
)
|
||||
}])
|
||||
.filter('mode2unix', function(){
|
||||
return function(mode){
|
||||
if(mode !== null){
|
||||
var res = [];
|
||||
var s = ['x', 'w', 'r'];
|
||||
for (var i = 0; i < 3; i++) {
|
||||
for (var j = 0; j < 3; j++) {
|
||||
if ((mode >> (i*3+j)) & 1 !== 0){
|
||||
res.unshift(s[j])
|
||||
} else {
|
||||
res.unshift('-')
|
||||
}
|
||||
}
|
||||
}
|
||||
res.unshift(mode & 040000 ? 'd' : '-');
|
||||
return res.join('');
|
||||
}
|
||||
}
|
||||
})
|
||||
.filter('isdir', function(){
|
||||
return function(mode){
|
||||
if(mode !== null){
|
||||
mode = parseInt(mode, 10)
|
||||
mode = mode - (mode & 0777);
|
||||
return (mode == 040000) || (mode == 0120000);
|
||||
}
|
||||
}
|
||||
})
|
||||
.controller('FsCtrl', require('./fs-controller'))
|
||||
Reference in New Issue
Block a user