Upgrade drivelist to v3.0.0 (#354)

This new version reports the size as a number of bytes instead of a
human readable string, so we have to take care of converting back to a
readable GB format ourselves.

Signed-off-by: Juan Cruz Viotti <jviottidc@gmail.com>
This commit is contained in:
Juan Cruz Viotti 2016-04-25 12:46:59 -04:00
parent afeba11424
commit d5b3e0a83f
8 changed files with 102 additions and 6 deletions

View File

@ -56,7 +56,8 @@ const app = angular.module('Etcher', [
require('./utils/if-state/if-state'),
require('./utils/notifier/notifier'),
require('./utils/path/path'),
require('./utils/manifest-bind/manifest-bind')
require('./utils/manifest-bind/manifest-bind'),
require('./utils/byte-size/byte-size')
]);
app.run(function(AnalyticsService) {

View File

@ -25,7 +25,8 @@ const MODULE_NAME = 'Etcher.Components.DriveSelector';
const DriveSelector = angular.module(MODULE_NAME, [
require('angular-ui-bootstrap'),
require('../../modules/drive-scanner'),
require('../../models/selection-state')
require('../../models/selection-state'),
require('../../utils/byte-size/byte-size')
]);
DriveSelector.controller('DriveSelectorController', require('./controllers/drive-selector'));

View File

@ -8,7 +8,7 @@
<li class="list-group-item" ng-repeat="drive in modal.scanner.drives"
ng-click="modal.state.toggleSelectDrive(drive)">
<div>
<h4 class="list-group-item-heading">{{ drive.description }} - {{ drive.size }}</h4>
<h4 class="list-group-item-heading">{{ drive.description }} - {{ drive.size | gigabyte | number:1 }} GB</h4>
<p class="list-group-item-text">{{ drive.name }}</p>
</div>
<span class="tick tick--success" ng-disabled="!modal.state.isSelectedDrive(drive)"></span>

View File

@ -49,8 +49,7 @@
</div>
<div ng-show="app.selection.hasDrive()">
<div ng-bind="app.selection.getDrive().name + ' - ' + app.selection.getDrive().size"></div>
<div>{{ app.selection.getDrive().name }} - {{ app.selection.getDrive().size | gigabyte | number:1 }} GB</div>
<button class="btn btn-link step-footer"
ng-click="app.reselectDrive()"
ng-hide="app.writer.isFlashing()">Change</button>

View File

@ -0,0 +1,31 @@
/*
* 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';
/**
* @module Etcher.Utils.ByteSize
*
* The purpose of this module is to provide utilities
* to work with sizes in bytes.
*/
const angular = require('angular');
const MODULE_NAME = 'Etcher.Utils.ByteSize';
const ByteSize = angular.module(MODULE_NAME, []);
ByteSize.filter('gigabyte', require('./filters/gigabyte'));
module.exports = MODULE_NAME;

View File

@ -0,0 +1,36 @@
/*
* 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';
module.exports = function() {
/**
* @summary Convert bytes to gigabytes
* @function
* @public
*
* @param {Number} bytes - bytes
* @returns {Number} gigabytes
*
* @example
* {{ 7801405440 | gigabytes }}
*/
return function(bytes) {
return bytes / 1000000000;
};
};

View File

@ -55,7 +55,7 @@
"bluebird": "^3.0.5",
"bootstrap-sass": "^3.3.5",
"chalk": "^1.1.3",
"drivelist": "^2.0.13",
"drivelist": "^3.0.0",
"flexboxgrid": "^6.3.0",
"is-elevated": "^1.0.0",
"lodash": "^4.5.1",

View File

@ -0,0 +1,28 @@
'use strict';
const m = require('mochainon');
const angular = require('angular');
const os = require('os');
require('angular-mocks');
describe('Browser: ByteSize', function() {
beforeEach(angular.mock.module(
require('../../../lib/gui/utils/byte-size/byte-size')
));
describe('GigabyteFilter', function() {
let gigabyteFilter;
beforeEach(angular.mock.inject(function(_gigabyteFilter_) {
gigabyteFilter = _gigabyteFilter_;
}));
it('should convert bytes to gigabytes', function() {
m.chai.expect(gigabyteFilter(7801405440)).to.equal(7.80140544);
m.chai.expect(gigabyteFilter(100000000)).to.equal(0.1);
});
});
});