diff --git a/lib/gui/app.js b/lib/gui/app.js index 74da7f61..b4cd8ff4 100644 --- a/lib/gui/app.js +++ b/lib/gui/app.js @@ -35,6 +35,7 @@ const app = angular.module('Etcher', [ // Models require('./models/selection-state'), require('./models/settings'), + require('./models/supported-formats'), // Components require('./components/progress-button/progress-button'), @@ -83,6 +84,7 @@ app.controller('AppController', function( DriveScannerService, SelectionStateModel, SettingsModel, + SupportedFormatsModel, ImageWriterService, AnalyticsService, DriveSelectorService, @@ -92,6 +94,7 @@ app.controller('AppController', function( OSDialogService ) { let self = this; + this.formats = SupportedFormatsModel; this.selection = SelectionStateModel; this.writer = ImageWriterService; this.scanner = DriveScannerService; diff --git a/lib/gui/models/supported-formats.js b/lib/gui/models/supported-formats.js new file mode 100644 index 00000000..90a457d0 --- /dev/null +++ b/lib/gui/models/supported-formats.js @@ -0,0 +1,98 @@ +/* + * 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.Models.SupportedFormats + */ + +const angular = require('angular'); +const _ = require('lodash'); +const imageStream = require('etcher-image-stream'); +const MODULE_NAME = 'Etcher.Models.SupportedFormats'; +const SupportedFormats = angular.module(MODULE_NAME, []); + +SupportedFormats.service('SupportedFormatsModel', function() { + + /** + * @summary Check if a file type is a compressed format + * @function + * @private + * + * @param {Object} fileType - file type + * @returns {Boolean} whether the file type is a compressed format + * + * @example + * if (isCompressedFileType({ + * extension: 'zip', + * type: 'compressed' + * })) { + * console.log('This is a compressed file type'); + * } + */ + const isCompressedFileType = function(fileType) { + return fileType.type === 'compressed'; + }; + + /** + * @summary Get compressed extensions + * @function + * @public + * + * @returns {String[]} compressed extensions + * + * SupportedFormatsModel.getCompressedExtensions().forEach(function(extension) { + * console.log('We support the ' + extension + ' compressed file format'); + * }); + */ + this.getCompressedExtensions = function() { + return _.map(_.filter(imageStream.supportedFileTypes, isCompressedFileType), 'extension'); + }; + + /** + * @summary Get non compressed extensions + * @function + * @public + * + * @returns {String[]} no compressed extensions + * + * SupportedFormatsModel.getNonCompressedExtensions().forEach(function(extension) { + * console.log('We support the ' + extension + ' file format'); + * }); + */ + this.getNonCompressedExtensions = function() { + return _.map(_.reject(imageStream.supportedFileTypes, isCompressedFileType), 'extension'); + }; + + /** + * @summary Get all supported extensions + * @function + * @public + * + * @returns {String[]} extensions + * + * SupportedFormatsModel.getAllExtensions().forEach(function(extension) { + * console.log('We support the ' + extension + ' format'); + * }); + */ + this.getAllExtensions = function() { + return _.map(imageStream.supportedFileTypes, 'extension'); + }; + +}); + +module.exports = MODULE_NAME; diff --git a/lib/gui/os/dialog/dialog.js b/lib/gui/os/dialog/dialog.js index ce2c8572..53496f93 100644 --- a/lib/gui/os/dialog/dialog.js +++ b/lib/gui/os/dialog/dialog.js @@ -25,7 +25,10 @@ const angular = require('angular'); const MODULE_NAME = 'Etcher.OS.Dialog'; -const OSDialog = angular.module(MODULE_NAME, []); +const OSDialog = angular.module(MODULE_NAME, [ + require('../../models/supported-formats') +]); + OSDialog.service('OSDialogService', require('./services/dialog')); module.exports = MODULE_NAME; diff --git a/lib/gui/os/dialog/services/dialog.js b/lib/gui/os/dialog/services/dialog.js index 8da032c2..96319f83 100644 --- a/lib/gui/os/dialog/services/dialog.js +++ b/lib/gui/os/dialog/services/dialog.js @@ -19,9 +19,8 @@ const _ = require('lodash'); const fs = require('fs'); const electron = require('electron'); -const imageStream = require('etcher-image-stream'); -module.exports = function($q) { +module.exports = function($q, SupportedFormatsModel) { /** * @summary Open an image selection dialog @@ -48,7 +47,7 @@ module.exports = function($q) { filters: [ { name: 'OS Images', - extensions: imageStream.supportedFileTypes + extensions: SupportedFormatsModel.getAllExtensions() } ] }, function(files) { diff --git a/lib/gui/partials/main.html b/lib/gui/partials/main.html index 4886d614..628d43ae 100644 --- a/lib/gui/partials/main.html +++ b/lib/gui/partials/main.html @@ -8,7 +8,12 @@