From 3a333651339cff6b09983d281967b16289e6ed19 Mon Sep 17 00:00:00 2001 From: Chaim Lev-Ari Date: Wed, 22 Jul 2020 21:30:42 +0300 Subject: [PATCH] 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 --- .../{node-selector.js => index.js} | 6 +++- .../node-selector/nodeSelectorController.js | 35 +++++++++---------- 2 files changed, 21 insertions(+), 20 deletions(-) rename app/agent/components/node-selector/{node-selector.js => index.js} (50%) diff --git a/app/agent/components/node-selector/node-selector.js b/app/agent/components/node-selector/index.js similarity index 50% rename from app/agent/components/node-selector/node-selector.js rename to app/agent/components/node-selector/index.js index 2f7e14e82..140319c8a 100644 --- a/app/agent/components/node-selector/node-selector.js +++ b/app/agent/components/node-selector/index.js @@ -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: '=', }, diff --git a/app/agent/components/node-selector/nodeSelectorController.js b/app/agent/components/node-selector/nodeSelectorController.js index ce44f8568..728f569b7 100644 --- a/app/agent/components/node-selector/nodeSelectorController.js +++ b/app/agent/components/node-selector/nodeSelectorController.js @@ -1,20 +1,17 @@ -angular.module('portainer.agent').controller('NodeSelectorController', [ - 'AgentService', - 'Notifications', - function (AgentService, Notifications) { - var ctrl = this; +export class NodeSelectorController { + constructor(AgentService, Notifications) { + Object.assign(this, { AgentService, Notifications }); + } - this.$onInit = function () { - AgentService.agents() - .then(function success(data) { - ctrl.agents = data; - if (!ctrl.model) { - ctrl.model = data[0].NodeName; - } - }) - .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'); + } + } +}