1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-06 03:50:04 +02:00

Style File Explorer along with coding standard.

This commit is contained in:
Gunther Brunner 2015-10-01 17:11:14 +09:00
parent 82c20c28d1
commit 2b7a9403aa
3 changed files with 57 additions and 58 deletions

View file

@ -1,47 +1,46 @@
module.exports = function ExplorerCtrl($scope) { module.exports = function ExplorerCtrl($scope) {
$scope.search = '' $scope.search = ''
$scope.files = []; $scope.files = []
$scope.paths = []; $scope.paths = []
var listdir = function(){ var listDir = function () {
var path = '/'+$scope.paths.join('/'); var path = '/' + $scope.paths.join('/')
$scope.control.fslist(path) $scope.control.fslist(path)
.then(function(result){ .then(function (result) {
$scope.files = result.body; $scope.files = result.body;
$scope.$digest(); $scope.$digest();
}) })
.catch(function(err){ .catch(function (err) {
alert(err.message); alert(err.message);
}) })
} }
$scope.dirEnter = function(name){ $scope.dirEnter = function (name) {
if (name){ if (name) {
$scope.paths.push(name); $scope.paths.push(name)
} }
listdir(); listDir()
$scope.search = ''; $scope.search = ''
} }
$scope.dirJump = function(){ $scope.dirJump = function () {
if ($scope.paths.length !== 0){ if ($scope.paths.length !== 0) {
$scope.paths.pop(); $scope.paths.pop()
} }
listdir(); listDir()
} }
$scope.getFile = function(file){ $scope.getFile = function (file) {
var path = '/'+$scope.paths.join('/')+'/'+file; var path = '/' + $scope.paths.join('/') + '/' + file
$scope.control.fsretrieve(path) $scope.control.fsretrieve(path)
.then(function(result){ .then(function (result) {
location.href = result.body.href+"?download" location.href = result.body.href + "?download"
}) })
.catch(function(err){ .catch(function (err) {
alert(err.message); alert(err.message)
}) })
} }
// Initialize
// init listDir($scope.dir)
listdir($scope.dir);
} }

View file

@ -1,17 +1,17 @@
describe('FsCtrl', function () { describe('FsCtrl', function () {
beforeEach(angular.mock.module(require('./').name)); beforeEach(angular.mock.module(require('./').name))
var scope, ctrl; var scope, ctrl
beforeEach(inject(function ($rootScope, $controller) { beforeEach(inject(function ($rootScope, $controller) {
scope = $rootScope.$new(); scope = $rootScope.$new()
ctrl = $controller('ExplorerCtrl', {$scope: scope}); ctrl = $controller('ExplorerCtrl', {$scope: scope})
})); }))
it('should ...', inject(function () { it('should ...', inject(function () {
expect(1).toEqual(1); expect(1).toEqual(1)
})); }))
}); })

View file

@ -6,32 +6,32 @@ module.exports = angular.module('stf.explorer', [])
require('./explorer.jade') require('./explorer.jade')
) )
}]) }])
.filter('mode2unix', function(){ .filter('mode2unix', function () {
return function(mode){ return function (mode) {
if(mode !== null){ if (mode !== null) {
var res = []; var res = [];
var s = ['x', 'w', 'r']; var s = ['x', 'w', 'r'];
for (var i = 0; i < 3; i++) { for (var i = 0; i < 3; i++) {
for (var j = 0; j < 3; j++) { for (var j = 0; j < 3; j++) {
if ((mode >> (i*3+j)) & 1 !== 0){ if ((mode >> (i * 3 + j)) & 1 !== 0) {
res.unshift(s[j]) res.unshift(s[j])
} else { } else {
res.unshift('-') res.unshift('-')
} }
} }
} }
res.unshift(mode & 040000 ? 'd' : '-'); res.unshift(mode & 040000 ? 'd' : '-');
return res.join(''); return res.join('');
} }
} }
}) })
.filter('isdir', function(){ .filter('isdir', function () {
return function(mode){ return function (mode) {
if(mode !== null){ if (mode !== null) {
mode = parseInt(mode, 10) mode = parseInt(mode, 10)
mode = mode - (mode & 0777); mode = mode - (mode & 0777)
return (mode == 040000) || (mode == 0120000); return (mode == 040000) || (mode == 0120000)
} }
} }
}) })
.controller('ExplorerCtrl', require('./explorer-controller')) .controller('ExplorerCtrl', require('./explorer-controller'))