refactor(agent): node selector (#4084)

* refactor(agent): rename files

* refactor(agent): replace controller with regular export

* refactor(agent): replace function with class

* refactor(agent): replace promise with async

* refactor(agent): rename main file
pull/4073/head
Chaim Lev-Ari 2020-07-22 21:30:42 +03:00 committed by GitHub
parent 67069547b8
commit 3a33365133
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 20 deletions

View File

@ -1,6 +1,10 @@
import angular from 'angular';
import { NodeSelectorController } from './nodeSelectorController';
angular.module('portainer.agent').component('nodeSelector', {
templateUrl: './nodeSelector.html',
controller: 'NodeSelectorController',
controller: NodeSelectorController,
bindings: {
model: '=',
},

View File

@ -1,20 +1,17 @@
angular.module('portainer.agent').controller('NodeSelectorController', [
'AgentService',
'Notifications',
function (AgentService, Notifications) {
var ctrl = this;
this.$onInit = function () {
AgentService.agents()
.then(function success(data) {
ctrl.agents = data;
if (!ctrl.model) {
ctrl.model = data[0].NodeName;
export class NodeSelectorController {
constructor(AgentService, Notifications) {
Object.assign(this, { AgentService, Notifications });
}
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to load agents');
});
};
},
]);
async $onInit() {
try {
const agents = await this.AgentService.agents();
this.agents = agents;
if (!this.model) {
this.model = agents[0].NodeName;
}
} catch (err) {
this.Notifications.error('Failure', err, 'Unable to load agents');
}
}
}