mirror of
https://github.com/balena-io/etcher.git
synced 2025-04-24 07:17:18 +00:00
refactor(GUI): get rid of basename
Angular filter (#1252)
Signed-off-by: Juan Cruz Viotti <jviotti@openmailbox.org>
This commit is contained in:
parent
4a3a123f42
commit
997133c979
@ -18,6 +18,7 @@
|
||||
|
||||
const _ = require('lodash');
|
||||
const Bluebird = require('bluebird');
|
||||
const path = require('path');
|
||||
const messages = require('../../../../shared/messages');
|
||||
const errors = require('../../../../shared/errors');
|
||||
|
||||
@ -146,4 +147,22 @@ module.exports = function(
|
||||
this.openImageSelector();
|
||||
};
|
||||
|
||||
/**
|
||||
* @summary Get the basename of the selected image
|
||||
* @function
|
||||
* @public
|
||||
*
|
||||
* @returns {String} basename of the selected image
|
||||
*
|
||||
* @example
|
||||
* const imageBasename = ImageSelectionController.getImageBasename();
|
||||
*/
|
||||
this.getImageBasename = () => {
|
||||
if (!SelectionStateModel.hasImage()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return path.basename(SelectionStateModel.getImagePath());
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -55,7 +55,6 @@ const MainPage = angular.module(MODULE_NAME, [
|
||||
require('../../models/supported-formats'),
|
||||
require('../../models/drives'),
|
||||
|
||||
require('../../utils/path/path'),
|
||||
require('../../utils/byte-size/byte-size')
|
||||
]);
|
||||
|
||||
|
@ -23,8 +23,8 @@
|
||||
<span
|
||||
ng-click="main.showSelectedImageDetails()"
|
||||
class="step-image step-name"
|
||||
ng-bind="main.selection.getImageName() || main.selection.getImagePath() | basename | middleEllipses:20"
|
||||
uib-tooltip="{{ main.selection.getImagePath() | basename }}"></span>
|
||||
ng-bind="main.selection.getImageName() || image.getImageBasename() | middleEllipses:20"
|
||||
uib-tooltip="{{ image.getImageBasename() }}"></span>
|
||||
<span class="step-image step-size">{{ main.selection.getImageSize() | gigabyte | number:1 }} GB</span>
|
||||
</div>
|
||||
|
||||
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 resin.io
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
|
||||
module.exports = () => {
|
||||
|
||||
/**
|
||||
* @summary Get the basename of a path
|
||||
* @function
|
||||
* @public
|
||||
*
|
||||
* @param {String} input - input path
|
||||
* @returns {String} path basename
|
||||
*
|
||||
* @example
|
||||
* {{ '/foo/bar/baz' | basename }}
|
||||
*/
|
||||
return (input) => {
|
||||
if (!input) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return path.basename(input);
|
||||
};
|
||||
|
||||
};
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 resin.io
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* The purpose of this module is to provide utilities
|
||||
* to work with file paths.
|
||||
*
|
||||
* @module Etcher.Utils.Path
|
||||
*/
|
||||
|
||||
const angular = require('angular');
|
||||
const MODULE_NAME = 'Etcher.Utils.Path';
|
||||
const Path = angular.module(MODULE_NAME, []);
|
||||
|
||||
/* eslint-disable lodash/prefer-lodash-method */
|
||||
|
||||
Path.filter('basename', require('./filters/basename'));
|
||||
|
||||
/* eslint-enable lodash/prefer-lodash-method */
|
||||
|
||||
module.exports = MODULE_NAME;
|
@ -2,6 +2,7 @@
|
||||
|
||||
const m = require('mochainon');
|
||||
const _ = require('lodash');
|
||||
const path = require('path');
|
||||
const angular = require('angular');
|
||||
require('angular-mocks');
|
||||
|
||||
@ -131,10 +132,12 @@ describe('Browser: MainPage', function() {
|
||||
|
||||
let $controller;
|
||||
let SupportedFormatsModel;
|
||||
let SelectionStateModel;
|
||||
|
||||
beforeEach(angular.mock.inject(function(_$controller_, _SupportedFormatsModel_) {
|
||||
beforeEach(angular.mock.inject(function(_$controller_, _SupportedFormatsModel_, _SelectionStateModel_) {
|
||||
$controller = _$controller_;
|
||||
SupportedFormatsModel = _SupportedFormatsModel_;
|
||||
SelectionStateModel = _SelectionStateModel_;
|
||||
}));
|
||||
|
||||
it('should contain all available extensions in mainSupportedExtensions and extraSupportedExtensions', function() {
|
||||
@ -147,6 +150,33 @@ describe('Browser: MainPage', function() {
|
||||
m.chai.expect(_.sortBy(extensions)).to.deep.equal(_.sortBy(SupportedFormatsModel.getAllExtensions()));
|
||||
});
|
||||
|
||||
describe('.getImageBasename()', function() {
|
||||
|
||||
it('should return the basename of the selected image', function() {
|
||||
const controller = $controller('ImageSelectionController', {
|
||||
$scope: {}
|
||||
});
|
||||
|
||||
SelectionStateModel.setImage({
|
||||
path: path.join(__dirname, 'foo', 'bar.img'),
|
||||
size: 999999999
|
||||
});
|
||||
|
||||
m.chai.expect(controller.getImageBasename()).to.equal('bar.img');
|
||||
SelectionStateModel.removeImage();
|
||||
});
|
||||
|
||||
it('should return an empty string if no selected image', function() {
|
||||
const controller = $controller('ImageSelectionController', {
|
||||
$scope: {}
|
||||
});
|
||||
|
||||
SelectionStateModel.removeImage();
|
||||
m.chai.expect(controller.getImageBasename()).to.equal('');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('FlashController', function() {
|
||||
|
@ -1,40 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const m = require('mochainon');
|
||||
const angular = require('angular');
|
||||
const os = require('os');
|
||||
require('angular-mocks');
|
||||
|
||||
describe('Browser: Path', function() {
|
||||
|
||||
beforeEach(angular.mock.module(
|
||||
require('../../../lib/gui/utils/path/path')
|
||||
));
|
||||
|
||||
describe('BasenameFilter', function() {
|
||||
|
||||
let basenameFilter;
|
||||
|
||||
beforeEach(angular.mock.inject(function(_basenameFilter_) {
|
||||
basenameFilter = _basenameFilter_;
|
||||
}));
|
||||
|
||||
it('should return an empty string if no input', function() {
|
||||
m.chai.expect(basenameFilter()).to.equal('');
|
||||
});
|
||||
|
||||
it('should return the basename', function() {
|
||||
const isWindows = os.platform() === 'win32';
|
||||
let basename;
|
||||
|
||||
if (isWindows) {
|
||||
basename = basenameFilter('C:\\Users\\jviotti\\foo.img');
|
||||
} else {
|
||||
basename = basenameFilter('/Users/jviotti/foo.img');
|
||||
}
|
||||
|
||||
m.chai.expect(basename).to.equal('foo.img');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user