Reworked iso-device module and integration on vm view
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
angular = require 'angular'
|
||||
|
||||
#=====================================================================
|
||||
|
||||
module.exports = angular.module 'xoWebApp.isoDevice', []
|
||||
|
||||
.directive 'isoDevice', -> {
|
||||
restrict: 'E'
|
||||
template: require './view'
|
||||
scope: {
|
||||
isos: '='
|
||||
vm: '='
|
||||
}
|
||||
controller: 'IsoDevice as isoDevice'
|
||||
bindToController: true
|
||||
}
|
||||
|
||||
.controller 'IsoDevice', (xo) ->
|
||||
this.eject = (VM) ->
|
||||
xo.vm.ejectCd VM.id
|
||||
|
||||
this.insert = (VM, disc_id) ->
|
||||
xo.vm.insertCd VM.id, disc_id, true
|
||||
|
||||
return
|
||||
|
||||
# A module exports its name.
|
||||
.name
|
||||
61
app/modules/iso-device/index.js
Normal file
61
app/modules/iso-device/index.js
Normal file
@@ -0,0 +1,61 @@
|
||||
import angular from 'angular'
|
||||
|
||||
import view from './view'
|
||||
|
||||
// =====================================================================
|
||||
|
||||
export default angular.module('xoWebApp.isoDevice', [])
|
||||
|
||||
.directive('isoDevice', () => ({
|
||||
restrict: 'E',
|
||||
template: view,
|
||||
scope: {
|
||||
srs: '=',
|
||||
vm: '='
|
||||
},
|
||||
controller: 'IsoDevice as isoDevice',
|
||||
bindToController: true
|
||||
}))
|
||||
|
||||
.controller('IsoDevice', function ($scope, xo, xoApi) {
|
||||
const {get} = xoApi
|
||||
const descriptor = obj => obj.name_label + (obj.name_description.length ? (' - ' + obj.name_description) : '')
|
||||
|
||||
this.eject = VM => xo.vm.ejectCd(VM.id)
|
||||
this.insert = (VM, disc_id) => xo.vm.insertCd(VM.id, disc_id, true)
|
||||
|
||||
const prepareDiskData = (srs, vm) => {
|
||||
const ISOOpts = []
|
||||
for (let key in srs) {
|
||||
const SR = srs[key]
|
||||
if (SR.SR_type === 'iso') {
|
||||
for (let key in SR.VDIs) {
|
||||
const rIso = SR.VDIs[key]
|
||||
const oIso = get(rIso)
|
||||
ISOOpts.push({
|
||||
sr: SR.name_label,
|
||||
label: descriptor(oIso),
|
||||
iso: oIso
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
let mounted = ''
|
||||
for (let key in vm.$VBDs) {
|
||||
const VBD = vm.$VBDs[key]
|
||||
const oVbd = get(VBD)
|
||||
const oVdi = oVbd && get(oVbd.VDI)
|
||||
oVbd && oVbd.is_cd_drive && oVdi && (mounted = oVdi.id)
|
||||
}
|
||||
return {
|
||||
opts: ISOOpts,
|
||||
mounted
|
||||
}
|
||||
}
|
||||
|
||||
$scope.$watchCollection(() => this.srs, srs => this.isos = prepareDiskData(srs, this.vm.$VBDs))
|
||||
$scope.$watch(() => this.vm && this.vm.$VBDs, vbds => this.isos = prepareDiskData(this.srs, vbds))
|
||||
})
|
||||
|
||||
// A module exports its name.
|
||||
.name
|
||||
@@ -492,7 +492,7 @@
|
||||
| Save
|
||||
.grid
|
||||
.col-md-4
|
||||
iso-device(ng-if = 'VM && isoDeviceData', vm = 'VM', isos = 'isoDeviceData')
|
||||
iso-device(ng-if = 'VM && SRs', vm = 'VM', srs = 'SRs')
|
||||
.col-md-8.text-right
|
||||
div
|
||||
button.btn(type="button", ng-class = '{"btn-success": adding, "btn-primary": !adding}', ng-disabled="disksForm.$waiting", ng-click="adding = !adding;creatingVdi = false;bootReordering = false")
|
||||
|
||||
Reference in New Issue
Block a user