Skip to content

Commit

Permalink
add import on main view and small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierlambert committed Sep 26, 2014
1 parent cc0f9ac commit 1692418
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
31 changes: 30 additions & 1 deletion app/modules/home/index.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
require 'angular'

require 'angular-ui-router'
require 'ng-file-upload'

throttle = require 'lodash.throttle'

#=====================================================================

module.exports = angular.module 'xoWebApp.home', [
'angularFileUpload'
'ui.router'

(require '../delete-vms').name
Expand All @@ -13,7 +18,7 @@ module.exports = angular.module 'xoWebApp.home', [
url: '/'
controller: 'HomeCtrl'
template: require './view'
.controller 'HomeCtrl', ($scope, modal, xo, dateFilter, deleteVmsModal, notify) ->
.controller 'HomeCtrl', ($scope, modal, $upload, xo, dateFilter, deleteVmsModal, notify) ->
VMs = []
$scope.$watch(
-> xo.revision
Expand Down Expand Up @@ -178,3 +183,27 @@ module.exports = angular.module 'xoWebApp.home', [
# Unselects all VMs.
$scope.selectVMs false

$scope.importVm = ($files, id) ->
file = $files[0]

xo.vm.import id
.then ({ $sendTo: url }) ->
return $upload.http {
method: 'POST'
url
data: file
}
.progress throttle(
(event) ->
percentage = (100 * event.loaded / event.total)|0

notify.info
title: 'VM import'
message: "#{percentage}%"
6e3
)
.then (result) ->
throw result.status if result.status isnt 200
notify.info
title: 'VM import'
message: 'Success'
5 changes: 5 additions & 0 deletions app/modules/home/view.jade
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ div(ng-if="pools.length")
a(xo-sref="VMs_new({container: host.UUID})")
i.xo-icon-vm.fa-fw
| Add VM
//- TODO: solve the "a" problem for ng-file-select
li(ng-file-select="importVm($files, host.UUID)")
a
i.fa.fa-upload.fa-fw
| Import VM
li.divider
li
a(ng-repeat="controller in [host.controller] | resolve track by controller.UUID", xo-sref="consoles_view({id: controller.UUID})")
Expand Down
6 changes: 3 additions & 3 deletions app/modules/host/view.jade
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@
.grid-cell.btn-group(ng-if="!pool.name_label")
button.btn(tooltip="Add to pool", style="width: 90%", type="button", xo-click="pool_addHost(host.UUID)")
i.fa.fa-cloud-download.fa-2x.fa-fw
.grid-cell.btn-group(style="margin-bottom: 0.5em")
button.btn(tooltip="Host console", type="button", style="width: 90%", ng-repeat="controller in [host.controller] | resolve track by controller.UUID", xo-sref="consoles_view({id: controller.UUID})")
i.xo-icon-console.fa-2x.fa-fw
.grid-cell.btn-group(style="margin-bottom: 0.5em")
button.btn(
tooltip="Import VM"
Expand All @@ -107,6 +104,9 @@
ng-file-select = 'importVm($files)'
)
i.fa.fa-upload.fa-2x.fa-fw
.grid-cell.btn-group(style="margin-bottom: 0.5em")
button.btn(tooltip="Host console", type="button", style="width: 90%", ng-repeat="controller in [host.controller] | resolve track by controller.UUID", xo-sref="consoles_view({id: controller.UUID})")
i.xo-icon-console.fa-2x.fa-fw

//- TODO: Memory panel
.grid
Expand Down

0 comments on commit 1692418

Please sign in to comment.