[WIP] Create VM as non-admin user with self service
This commit is contained in:
@@ -21,7 +21,19 @@ export default angular.module('xoWebApp.list', [
|
||||
template: view
|
||||
})
|
||||
})
|
||||
.controller('ListCtrl', function (xoApi, $scope, $rootScope) {
|
||||
.controller('ListCtrl', function (xo, xoApi, $state, $scope, $rootScope) {
|
||||
const user = xoApi.user
|
||||
|
||||
$scope.createButton = user.permission !== 'admin'
|
||||
|
||||
if (user.permission !== 'admin') {
|
||||
xo.resourceSet.getAll()
|
||||
.then(sets => {
|
||||
console.log('sets = ', sets)
|
||||
// TODO
|
||||
})
|
||||
}
|
||||
|
||||
this.hosts = xoApi.getView('host')
|
||||
this.pools = xoApi.getView('pool')
|
||||
this.SRs = xoApi.getView('SR')
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
i.fa.fa-square-o(ng-if='!options[state.toLowerCase()]')
|
||||
i.fa.fa-check-square-o(ng-if='options[state.toLowerCase()]')
|
||||
| {{state}}
|
||||
.btn-group(ng-if='createButton' style="margin-left:3em")
|
||||
a.btn.navbar-btn.filter(xo-sref='VMs_new()')
|
||||
| Create VM
|
||||
//- TODO: print a message when no entries.
|
||||
|
||||
//- FIXME: Ugly trick to force the results to be under the sub bar.
|
||||
|
||||
@@ -20,6 +20,22 @@ module.exports = angular.module 'xoWebApp.newVm', [
|
||||
bytesToSizeFilter, sizeToBytesFilter
|
||||
notify
|
||||
) ->
|
||||
user = xoApi.user
|
||||
console.log('user', user)
|
||||
$scope.isAdmin = user.permission == 'admin'
|
||||
|
||||
if !$scope.isAdmin
|
||||
$scope.resourceSets = []
|
||||
$scope.resourceSet = ''
|
||||
xo.resourceSet.getAll()
|
||||
.then (sets) ->
|
||||
$scope.resourceSets = sets
|
||||
console.log('sets', sets)
|
||||
$scope.resourceSet = $scope.resourceSets[0]
|
||||
|
||||
$scope.updateResourceSet = (resourceSet) ->
|
||||
console.log('TODO : update to ', resourceSet)
|
||||
|
||||
$scope.multipleVmsActive = false
|
||||
$scope.vmsNames = ['VM1', 'VM2']
|
||||
$scope.numberOfVms = 2
|
||||
|
||||
@@ -2,11 +2,31 @@
|
||||
.panel.panel-default
|
||||
p.page-title
|
||||
i.xo-icon-vm
|
||||
| Create VM on
|
||||
a(ng-if="'pool' === container.type", ui-sref="pools_view({id: container.id})")
|
||||
| {{container.name_label}}
|
||||
a(ng-if="'host' === container.type", ui-sref="hosts_view({id: container.id})")
|
||||
| {{container.name_label}}
|
||||
| Create VM
|
||||
span(ng-if='isAdmin') on
|
||||
a(ng-if="'pool' === container.type", ui-sref="pools_view({id: container.id})")
|
||||
| {{container.name_label}}
|
||||
a(ng-if="'host' === container.type", ui-sref="hosts_view({id: container.id})")
|
||||
| {{container.name_label}}
|
||||
.grid
|
||||
.panel.panel-default(ng-if='!isAdmin')
|
||||
.panel-heading.panel-title
|
||||
i.fa.fa-object-group
|
||||
| Resource set
|
||||
.panel-body
|
||||
.form-group(ng-if='resourceSets.length > 1')
|
||||
label.col-sm-2.col-md-offset-3.control-label Select resource set
|
||||
.col-sm-4
|
||||
select.form-control(
|
||||
ng-model="resourceSet"
|
||||
ng-options="resourceSet.name for resourceSet in resourceSets | orderBy:natural('name') track by resourceSet.id"
|
||||
ng-change="updateResourceSet(resourceSet)"
|
||||
required=""
|
||||
)
|
||||
.form-group(ng-if='resourceSets.length === 1')
|
||||
label.col-sm-2.col-md-offset-3.control-label Resource set
|
||||
.col-sm-4
|
||||
| {{ resourceSet.name }}
|
||||
//- Add server panel
|
||||
form.form-horizontal(ng-submit="createVMs()")
|
||||
.grid
|
||||
|
||||
@@ -155,7 +155,9 @@ export default angular.module('self.admin', [
|
||||
|
||||
this.create = function (name, subjects, pools, templates, srs, networks, cpuMax, memoryMax, memoryUnit, diskMax, diskUnit) {
|
||||
return xo.resourceSet.create(name)
|
||||
.then(set => save(name, subjects, pools, templates, srs, networks, cpuMax, memoryMax, memoryUnit, diskMax, diskUnit, set.id))
|
||||
.then(set => {
|
||||
save(name, subjects, pools, templates, srs, networks, cpuMax, memoryMax, memoryUnit, diskMax, diskUnit, set.id)
|
||||
})
|
||||
.then(reset)
|
||||
.then(loadSets)
|
||||
}
|
||||
@@ -210,12 +212,14 @@ export default angular.module('self.admin', [
|
||||
}
|
||||
}
|
||||
|
||||
this.delete = id => xo.resourceSet.delete(id).then(() => {
|
||||
if (id === this.editing) {
|
||||
reset()
|
||||
}
|
||||
loadSets()
|
||||
})
|
||||
this.delete = id => {
|
||||
xo.resourceSet.delete(id).then(() => {
|
||||
if (id === this.editing) {
|
||||
reset()
|
||||
}
|
||||
loadSets()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
// A module exports its name.
|
||||
|
||||
4
app/node_modules/xo/index.js
generated
vendored
4
app/node_modules/xo/index.js
generated
vendored
@@ -467,10 +467,10 @@ export default angular.module('xo', [
|
||||
return args
|
||||
}
|
||||
}),
|
||||
delete: action('Delete a resoucre set', 'resourceSet.delete', {
|
||||
delete: action('Delete a resource set', 'resourceSet.delete', {
|
||||
argsMapper: (id) => ({id})
|
||||
}),
|
||||
get: action('Get a resoucre set ', 'resourceSet.get', {
|
||||
get: action('Get a resource set ', 'resourceSet.get', {
|
||||
argsMapper: (id) => ({id})
|
||||
}),
|
||||
getAll: action('Get all resource sets', 'resourceSet.getAll'),
|
||||
|
||||
Reference in New Issue
Block a user