app.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /*jslint browser: true, continue: true, plusplus: true */
  2. /*global $: false, angular: false */
  3. 'use strict';
  4. var syncthing = angular.module('syncthing', []);
  5. var urlbase = 'rest';
  6. syncthing.controller('SyncthingCtrl', function ($scope, $http) {
  7. var prevDate = 0;
  8. var getOK = true;
  9. var restarting = false;
  10. $scope.connections = {};
  11. $scope.config = {};
  12. $scope.myID = '';
  13. $scope.nodes = [];
  14. $scope.configInSync = true;
  15. $scope.errors = [];
  16. $scope.seenError = '';
  17. $scope.model = {};
  18. $scope.repos = {};
  19. // Strings before bools look better
  20. $scope.settings = [
  21. {id: 'ListenStr', descr: 'Sync Protocol Listen Addresses', type: 'text', restart: true},
  22. {id: 'MaxSendKbps', descr: 'Outgoing Rate Limit (KiB/s)', type: 'number', restart: true},
  23. {id: 'RescanIntervalS', descr: 'Rescan Interval (s)', type: 'number', restart: true},
  24. {id: 'ReconnectIntervalS', descr: 'Reconnect Interval (s)', type: 'number', restart: true},
  25. {id: 'ParallelRequests', descr: 'Max Outstanding Requests', type: 'number', restart: true},
  26. {id: 'MaxChangeKbps', descr: 'Max File Change Rate (KiB/s)', type: 'number', restart: true},
  27. {id: 'GlobalAnnEnabled', descr: 'Global Discovery', type: 'bool', restart: true},
  28. {id: 'LocalAnnEnabled', descr: 'Local Discovery', type: 'bool', restart: true},
  29. {id: 'LocalAnnPort', descr: 'Local Discovery Port', type: 'number', restart: true},
  30. {id: 'StartBrowser', descr: 'Start Browser', type: 'bool'},
  31. {id: 'UPnPEnabled', descr: 'Enable UPnP', type: 'bool'},
  32. ];
  33. $scope.guiSettings = [
  34. {id: 'Address', descr: 'GUI Listen Addresses', type: 'text', restart: true},
  35. {id: 'User', descr: 'GUI Authentication User', type: 'text', restart: true},
  36. {id: 'Password', descr: 'GUI Authentication Password', type: 'password', restart: true},
  37. {id: 'UseTLS', descr: 'Use HTTPS for GUI', type: 'bool', restart: true},
  38. ];
  39. function getSucceeded() {
  40. if (!getOK) {
  41. $scope.init();
  42. $('#networkError').modal('hide');
  43. getOK = true;
  44. }
  45. if (restarting) {
  46. $scope.init();
  47. $('#restarting').modal('hide');
  48. $('#shutdown').modal('hide');
  49. restarting = false;
  50. }
  51. }
  52. function getFailed() {
  53. if (restarting) {
  54. return;
  55. }
  56. if (getOK) {
  57. $('#networkError').modal({backdrop: 'static', keyboard: false});
  58. getOK = false;
  59. }
  60. }
  61. $scope.refresh = function () {
  62. $http.get(urlbase + '/system').success(function (data) {
  63. getSucceeded();
  64. $scope.system = data;
  65. }).error(function () {
  66. getFailed();
  67. });
  68. Object.keys($scope.repos).forEach(function (id) {
  69. $http.get(urlbase + '/model?repo=' + encodeURIComponent(id)).success(function (data) {
  70. $scope.model[id] = data;
  71. });
  72. });
  73. $http.get(urlbase + '/connections').success(function (data) {
  74. var now = Date.now(),
  75. td = (now - prevDate) / 1000,
  76. id;
  77. prevDate = now;
  78. for (id in data) {
  79. if (!data.hasOwnProperty(id)) {
  80. continue;
  81. }
  82. try {
  83. data[id].inbps = Math.max(0, 8 * (data[id].InBytesTotal - $scope.connections[id].InBytesTotal) / td);
  84. data[id].outbps = Math.max(0, 8 * (data[id].OutBytesTotal - $scope.connections[id].OutBytesTotal) / td);
  85. } catch (e) {
  86. data[id].inbps = 0;
  87. data[id].outbps = 0;
  88. }
  89. }
  90. $scope.connections = data;
  91. });
  92. $http.get(urlbase + '/errors').success(function (data) {
  93. $scope.errors = data;
  94. });
  95. };
  96. $scope.repoStatus = function (repo) {
  97. if (typeof $scope.model[repo] === 'undefined') {
  98. return 'Unknown';
  99. }
  100. if ($scope.model[repo].invalid !== '') {
  101. return 'Stopped';
  102. }
  103. var state = '' + $scope.model[repo].state;
  104. state = state[0].toUpperCase() + state.substr(1);
  105. if (state == "Syncing" || state == "Idle") {
  106. state += " (" + $scope.syncPercentage(repo) + "%)";
  107. }
  108. return state;
  109. }
  110. $scope.repoClass = function (repo) {
  111. if (typeof $scope.model[repo] === 'undefined') {
  112. return 'info';
  113. }
  114. if ($scope.model[repo].invalid !== '') {
  115. return 'danger';
  116. }
  117. var state = '' + $scope.model[repo].state;
  118. if (state == 'idle') {
  119. return 'success';
  120. }
  121. if (state == 'syncing') {
  122. return 'primary';
  123. }
  124. return 'info';
  125. }
  126. $scope.syncPercentage = function (repo) {
  127. if (typeof $scope.model[repo] === 'undefined') {
  128. return 100;
  129. }
  130. if ($scope.model[repo].globalBytes === 0) {
  131. return 100;
  132. }
  133. var pct = 100 * $scope.model[repo].inSyncBytes / $scope.model[repo].globalBytes;
  134. return Math.floor(pct);
  135. };
  136. $scope.nodeStatus = function (nodeCfg) {
  137. var conn = $scope.connections[nodeCfg.NodeID];
  138. if (conn) {
  139. if (conn.Completion === 100) {
  140. return 'Up to Date';
  141. } else {
  142. return 'Syncing (' + conn.Completion + '%)';
  143. }
  144. }
  145. return 'Disconnected';
  146. };
  147. $scope.nodeIcon = function (nodeCfg) {
  148. var conn = $scope.connections[nodeCfg.NodeID];
  149. if (conn) {
  150. if (conn.Completion === 100) {
  151. return 'ok';
  152. } else {
  153. return 'refresh';
  154. }
  155. }
  156. return 'minus';
  157. };
  158. $scope.nodeClass = function (nodeCfg) {
  159. var conn = $scope.connections[nodeCfg.NodeID];
  160. if (conn) {
  161. if (conn.Completion === 100) {
  162. return 'success';
  163. } else {
  164. return 'primary';
  165. }
  166. }
  167. return 'info';
  168. };
  169. $scope.nodeAddr = function (nodeCfg) {
  170. var conn = $scope.connections[nodeCfg.NodeID];
  171. if (conn) {
  172. return conn.Address;
  173. }
  174. return '?';
  175. };
  176. $scope.nodeCompletion = function (nodeCfg) {
  177. var conn = $scope.connections[nodeCfg.NodeID];
  178. if (conn) {
  179. return conn.Completion + '%';
  180. }
  181. return '';
  182. };
  183. $scope.nodeVer = function (nodeCfg) {
  184. if (nodeCfg.NodeID === $scope.myID) {
  185. return $scope.version;
  186. }
  187. var conn = $scope.connections[nodeCfg.NodeID];
  188. if (conn) {
  189. return conn.ClientVersion;
  190. }
  191. return '?';
  192. };
  193. $scope.findNode = function (nodeID) {
  194. var matches = $scope.nodes.filter(function (n) { return n.NodeID == nodeID; });
  195. if (matches.length != 1) {
  196. return undefined;
  197. }
  198. return matches[0];
  199. };
  200. $scope.nodeName = function (nodeCfg) {
  201. if (typeof nodeCfg === 'undefined') {
  202. return "";
  203. }
  204. if (nodeCfg.Name) {
  205. return nodeCfg.Name;
  206. }
  207. return nodeCfg.NodeID.substr(0, 6);
  208. };
  209. $scope.thisNodeName = function () {
  210. var node = $scope.thisNode();
  211. if (typeof node === 'undefined') {
  212. return "(unknown node)";
  213. }
  214. if (node.Name) {
  215. return node.Name;
  216. }
  217. return node.NodeID.substr(0, 6);
  218. };
  219. $scope.editSettings = function () {
  220. // Make a working copy
  221. $scope.config.workingOptions = angular.copy($scope.config.Options);
  222. $scope.config.workingGUI = angular.copy($scope.config.GUI);
  223. $('#settings').modal({backdrop: 'static', keyboard: true});
  224. }
  225. $scope.saveSettings = function () {
  226. // Make sure something changed
  227. var changed = ! angular.equals($scope.config.Options, $scope.config.workingOptions) ||
  228. ! angular.equals($scope.config.GUI, $scope.config.workingGUI);
  229. if(changed){
  230. $scope.config.Options = angular.copy($scope.config.workingOptions);
  231. $scope.config.GUI = angular.copy($scope.config.workingGUI);
  232. $scope.configInSync = false;
  233. $scope.config.Options.ListenAddress = $scope.config.Options.ListenStr.split(',').map(function (x) { return x.trim(); });
  234. $http.post(urlbase + '/config', JSON.stringify($scope.config), {headers: {'Content-Type': 'application/json'}});
  235. }
  236. $('#settings').modal("hide");
  237. };
  238. $scope.restart = function () {
  239. restarting = true;
  240. $('#restarting').modal({backdrop: 'static', keyboard: false});
  241. $http.post(urlbase + '/restart');
  242. $scope.configInSync = true;
  243. };
  244. $scope.shutdown = function () {
  245. restarting = true;
  246. $http.post(urlbase + '/shutdown').success(function () {
  247. $('#shutdown').modal({backdrop: 'static', keyboard: false});
  248. });
  249. $scope.configInSync = true;
  250. };
  251. $scope.editNode = function (nodeCfg) {
  252. $scope.currentNode = $.extend({}, nodeCfg);
  253. $scope.editingExisting = true;
  254. $scope.editingSelf = (nodeCfg.NodeID == $scope.myID);
  255. $scope.currentNode.AddressesStr = nodeCfg.Addresses.join(', ');
  256. $scope.nodeEditor.$setPristine();
  257. $('#editNode').modal({backdrop: 'static', keyboard: true});
  258. };
  259. $scope.idNode = function () {
  260. $('#idqr').modal('show');
  261. };
  262. $scope.addNode = function () {
  263. $scope.currentNode = {AddressesStr: 'dynamic'};
  264. $scope.editingExisting = false;
  265. $scope.editingSelf = false;
  266. $scope.nodeEditor.$setPristine();
  267. $('#editNode').modal({backdrop: 'static', keyboard: true});
  268. };
  269. $scope.deleteNode = function () {
  270. $('#editNode').modal('hide');
  271. if (!$scope.editingExisting) {
  272. return;
  273. }
  274. $scope.nodes = $scope.nodes.filter(function (n) {
  275. return n.NodeID !== $scope.currentNode.NodeID;
  276. });
  277. $scope.config.Nodes = $scope.nodes;
  278. for (var id in $scope.repos) {
  279. $scope.repos[id].Nodes = $scope.repos[id].Nodes.filter(function (n) {
  280. return n.NodeID !== $scope.currentNode.NodeID;
  281. });
  282. }
  283. $scope.configInSync = false;
  284. $http.post(urlbase + '/config', JSON.stringify($scope.config), {headers: {'Content-Type': 'application/json'}});
  285. };
  286. $scope.saveNode = function () {
  287. var nodeCfg, done, i;
  288. $scope.configInSync = false;
  289. $('#editNode').modal('hide');
  290. nodeCfg = $scope.currentNode;
  291. nodeCfg.NodeID = nodeCfg.NodeID.replace(/ /g, '').replace(/-/g, '').toUpperCase().trim();
  292. nodeCfg.Addresses = nodeCfg.AddressesStr.split(',').map(function (x) { return x.trim(); });
  293. done = false;
  294. for (i = 0; i < $scope.nodes.length; i++) {
  295. if ($scope.nodes[i].NodeID === nodeCfg.NodeID) {
  296. $scope.nodes[i] = nodeCfg;
  297. done = true;
  298. break;
  299. }
  300. }
  301. if (!done) {
  302. $scope.nodes.push(nodeCfg);
  303. }
  304. $scope.nodes.sort(nodeCompare);
  305. $scope.config.Nodes = $scope.nodes;
  306. $http.post(urlbase + '/config', JSON.stringify($scope.config), {headers: {'Content-Type': 'application/json'}});
  307. };
  308. $scope.otherNodes = function () {
  309. return $scope.nodes.filter(function (n){
  310. return n.NodeID !== $scope.myID;
  311. });
  312. };
  313. $scope.thisNode = function () {
  314. var i, n;
  315. for (i = 0; i < $scope.nodes.length; i++) {
  316. n = $scope.nodes[i];
  317. if (n.NodeID === $scope.myID) {
  318. return n;
  319. }
  320. }
  321. };
  322. $scope.allNodes = function () {
  323. var nodes = $scope.otherNodes();
  324. nodes.push($scope.thisNode());
  325. return nodes;
  326. };
  327. $scope.errorList = function () {
  328. return $scope.errors.filter(function (e) {
  329. return e.Time > $scope.seenError;
  330. });
  331. };
  332. $scope.clearErrors = function () {
  333. $scope.seenError = $scope.errors[$scope.errors.length - 1].Time;
  334. $http.post(urlbase + '/error/clear');
  335. };
  336. $scope.friendlyNodes = function (str) {
  337. for (var i = 0; i < $scope.nodes.length; i++) {
  338. var cfg = $scope.nodes[i];
  339. str = str.replace(cfg.NodeID, $scope.nodeName(cfg));
  340. }
  341. return str;
  342. };
  343. $scope.repoList = function () {
  344. return repoList($scope.repos);
  345. }
  346. $scope.editRepo = function (nodeCfg) {
  347. $scope.currentRepo = angular.copy(nodeCfg);
  348. $scope.currentRepo.selectedNodes = {};
  349. $scope.currentRepo.Nodes.forEach(function (n) {
  350. $scope.currentRepo.selectedNodes[n.NodeID] = true;
  351. });
  352. if ($scope.currentRepo.Versioning && $scope.currentRepo.Versioning.Type === "simple") {
  353. $scope.currentRepo.simpleFileVersioning = true;
  354. $scope.currentRepo.simpleKeep = +$scope.currentRepo.Versioning.Params.keep;
  355. }
  356. $scope.currentRepo.simpleKeep = $scope.currentRepo.simpleKeep || 5;
  357. $scope.editingExisting = true;
  358. $scope.repoEditor.$setPristine();
  359. $('#editRepo').modal({backdrop: 'static', keyboard: true});
  360. };
  361. $scope.addRepo = function () {
  362. $scope.currentRepo = {selectedNodes: {}};
  363. $scope.editingExisting = false;
  364. $scope.repoEditor.$setPristine();
  365. $('#editRepo').modal({backdrop: 'static', keyboard: true});
  366. };
  367. $scope.saveRepo = function () {
  368. var repoCfg, done, i;
  369. $scope.configInSync = false;
  370. $('#editRepo').modal('hide');
  371. repoCfg = $scope.currentRepo;
  372. repoCfg.Nodes = [];
  373. repoCfg.selectedNodes[$scope.myID] = true;
  374. for (var nodeID in repoCfg.selectedNodes) {
  375. if (repoCfg.selectedNodes[nodeID] === true) {
  376. repoCfg.Nodes.push({NodeID: nodeID});
  377. }
  378. }
  379. delete repoCfg.selectedNodes;
  380. if (repoCfg.simpleFileVersioning) {
  381. repoCfg.Versioning = {
  382. 'Type': 'simple',
  383. 'Params': {
  384. 'keep': '' + repoCfg.simpleKeep,
  385. }
  386. };
  387. delete repoCfg.simpleFileVersioning;
  388. delete repoCfg.simpleKeep;
  389. } else {
  390. delete repoCfg.Versioning;
  391. }
  392. $scope.repos[repoCfg.ID] = repoCfg;
  393. $scope.config.Repositories = repoList($scope.repos);
  394. $http.post(urlbase + '/config', JSON.stringify($scope.config), {headers: {'Content-Type': 'application/json'}});
  395. };
  396. $scope.sharesRepo = function(repoCfg) {
  397. var names = [];
  398. repoCfg.Nodes.forEach(function (node) {
  399. names.push($scope.nodeName($scope.findNode(node.NodeID)));
  400. });
  401. names.sort();
  402. return names.join(", ");
  403. };
  404. $scope.deleteRepo = function () {
  405. $('#editRepo').modal('hide');
  406. if (!$scope.editingExisting) {
  407. return;
  408. }
  409. delete $scope.repos[$scope.currentRepo.ID];
  410. $scope.config.Repositories = repoList($scope.repos);
  411. $scope.configInSync = false;
  412. $http.post(urlbase + '/config', JSON.stringify($scope.config), {headers: {'Content-Type': 'application/json'}});
  413. };
  414. $scope.init = function() {
  415. $http.get(urlbase + '/version').success(function (data) {
  416. $scope.version = data;
  417. });
  418. $http.get(urlbase + '/system').success(function (data) {
  419. $scope.system = data;
  420. $scope.myID = data.myID;
  421. });
  422. $http.get(urlbase + '/config').success(function (data) {
  423. $scope.config = data;
  424. $scope.config.Options.ListenStr = $scope.config.Options.ListenAddress.join(', ');
  425. $scope.nodes = $scope.config.Nodes;
  426. $scope.nodes.sort(nodeCompare);
  427. $scope.repos = repoMap($scope.config.Repositories);
  428. $scope.refresh();
  429. });
  430. $http.get(urlbase + '/config/sync').success(function (data) {
  431. $scope.configInSync = data.configInSync;
  432. });
  433. };
  434. $scope.init();
  435. setInterval($scope.refresh, 10000);
  436. });
  437. function nodeCompare(a, b) {
  438. if (typeof a.Name !== 'undefined' && typeof b.Name !== 'undefined') {
  439. if (a.Name < b.Name)
  440. return -1;
  441. return a.Name > b.Name;
  442. }
  443. if (a.NodeID < b.NodeID) {
  444. return -1;
  445. }
  446. return a.NodeID > b.NodeID;
  447. }
  448. function repoCompare(a, b) {
  449. if (a.Directory < b.Directory) {
  450. return -1;
  451. }
  452. return a.Directory > b.Directory;
  453. }
  454. function repoMap(l) {
  455. var m = {};
  456. l.forEach(function (r) {
  457. m[r.ID] = r;
  458. });
  459. return m;
  460. }
  461. function repoList(m) {
  462. var l = [];
  463. for (var id in m) {
  464. l.push(m[id])
  465. }
  466. l.sort(repoCompare);
  467. return l;
  468. }
  469. function decimals(val, num) {
  470. var digits, decs;
  471. if (val === 0) {
  472. return 0;
  473. }
  474. digits = Math.floor(Math.log(Math.abs(val)) / Math.log(10));
  475. decs = Math.max(0, num - digits);
  476. return decs;
  477. }
  478. syncthing.filter('natural', function () {
  479. return function (input, valid) {
  480. return input.toFixed(decimals(input, valid));
  481. };
  482. });
  483. syncthing.filter('binary', function () {
  484. return function (input) {
  485. if (input === undefined) {
  486. return '0 ';
  487. }
  488. if (input > 1024 * 1024 * 1024) {
  489. input /= 1024 * 1024 * 1024;
  490. return input.toFixed(decimals(input, 2)) + ' Gi';
  491. }
  492. if (input > 1024 * 1024) {
  493. input /= 1024 * 1024;
  494. return input.toFixed(decimals(input, 2)) + ' Mi';
  495. }
  496. if (input > 1024) {
  497. input /= 1024;
  498. return input.toFixed(decimals(input, 2)) + ' Ki';
  499. }
  500. return Math.round(input) + ' ';
  501. };
  502. });
  503. syncthing.filter('metric', function () {
  504. return function (input) {
  505. if (input === undefined) {
  506. return '0 ';
  507. }
  508. if (input > 1000 * 1000 * 1000) {
  509. input /= 1000 * 1000 * 1000;
  510. return input.toFixed(decimals(input, 2)) + ' G';
  511. }
  512. if (input > 1000 * 1000) {
  513. input /= 1000 * 1000;
  514. return input.toFixed(decimals(input, 2)) + ' M';
  515. }
  516. if (input > 1000) {
  517. input /= 1000;
  518. return input.toFixed(decimals(input, 2)) + ' k';
  519. }
  520. return Math.round(input) + ' ';
  521. };
  522. });
  523. syncthing.filter('short', function () {
  524. return function (input) {
  525. return input.substr(0, 6);
  526. };
  527. });
  528. syncthing.filter('alwaysNumber', function () {
  529. return function (input) {
  530. if (input === undefined) {
  531. return 0;
  532. }
  533. return input;
  534. };
  535. });
  536. syncthing.filter('chunkID', function () {
  537. return function (input) {
  538. if (input === undefined)
  539. return "";
  540. var parts = input.match(/.{1,6}/g);
  541. if (!parts)
  542. return "";
  543. return parts.join('-');
  544. }
  545. });
  546. syncthing.filter('shortPath', function () {
  547. return function (input) {
  548. if (input === undefined)
  549. return "";
  550. var parts = input.split(/[\/\\]/);
  551. if (!parts || parts.length <= 3) {
  552. return input;
  553. }
  554. return ".../" + parts.slice(parts.length-2).join("/");
  555. }
  556. });
  557. syncthing.filter('clean', function () {
  558. return function (input) {
  559. return encodeURIComponent(input).replace(/%/g, '');
  560. }
  561. });
  562. syncthing.directive('optionEditor', function () {
  563. return {
  564. restrict: 'C',
  565. replace: true,
  566. transclude: true,
  567. scope: {
  568. setting: '=setting',
  569. },
  570. template: '<input type="text" ng-model="config.Options[setting.id]"></input>',
  571. };
  572. });
  573. syncthing.directive('uniqueRepo', function() {
  574. return {
  575. require: 'ngModel',
  576. link: function(scope, elm, attrs, ctrl) {
  577. ctrl.$parsers.unshift(function(viewValue) {
  578. if (scope.editingExisting) {
  579. // we shouldn't validate
  580. ctrl.$setValidity('uniqueRepo', true);
  581. } else if (scope.repos[viewValue]) {
  582. // the repo exists already
  583. ctrl.$setValidity('uniqueRepo', false);
  584. } else {
  585. // the repo is unique
  586. ctrl.$setValidity('uniqueRepo', true);
  587. }
  588. return viewValue;
  589. });
  590. }
  591. };
  592. });
  593. syncthing.directive('validNodeid', function() {
  594. return {
  595. require: 'ngModel',
  596. link: function(scope, elm, attrs, ctrl) {
  597. ctrl.$parsers.unshift(function(viewValue) {
  598. if (scope.editingExisting) {
  599. // we shouldn't validate
  600. ctrl.$setValidity('validNodeid', true);
  601. } else {
  602. var cleaned = viewValue.replace(/ /g, '').replace(/-/g, '').toUpperCase().trim();
  603. if (cleaned.match(/^[A-Z2-7]{52}$/)) {
  604. ctrl.$setValidity('validNodeid', true);
  605. } else {
  606. ctrl.$setValidity('validNodeid', false);
  607. }
  608. }
  609. return viewValue;
  610. });
  611. }
  612. };
  613. });