Jeremy Mowery | 159f97b | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | angular.module('xos.vpnDashboard', [ |
| 4 | 'ngResource', |
| 5 | 'ngCookies', |
| 6 | 'ngLodash', |
| 7 | 'ui.router', |
| 8 | 'xos.helpers' |
| 9 | ]) |
| 10 | .config(($stateProvider) => { |
| 11 | $stateProvider |
Jeremy Mowery | 9fa1255 | 2016-03-01 08:30:30 -0700 | [diff] [blame^] | 12 | .state('vpnList', { |
Jeremy Mowery | 159f97b | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 13 | url: '/', |
Jeremy Mowery | 42b2c01 | 2016-02-25 11:25:53 -0700 | [diff] [blame] | 14 | template: '<vpn-list></vpn-list>' |
Jeremy Mowery | 33e861a | 2016-02-25 18:14:03 -0700 | [diff] [blame] | 15 | }) |
Jeremy Mowery | 9fa1255 | 2016-03-01 08:30:30 -0700 | [diff] [blame^] | 16 | .state('clientScript', { |
| 17 | url: '/client/:tenantId', |
Jeremy Mowery | 33e861a | 2016-02-25 18:14:03 -0700 | [diff] [blame] | 18 | template: '<client-script></client-script>' |
Jeremy Mowery | 159f97b | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 19 | }); |
| 20 | }) |
| 21 | .service('Vpn', function($http, $q){ |
| 22 | |
| 23 | this.getVpnTenants = () => { |
| 24 | let deferred = $q.defer(); |
| 25 | |
| 26 | $http.get('/xoslib/vpntenants/') |
| 27 | .then((res) => { |
| 28 | deferred.resolve(res.data) |
| 29 | }) |
| 30 | .catch((e) => { |
| 31 | deferred.reject(e); |
| 32 | }); |
| 33 | |
| 34 | return deferred.promise; |
Jeremy Mowery | 33e861a | 2016-02-25 18:14:03 -0700 | [diff] [blame] | 35 | } |
Jeremy Mowery | 9fa1255 | 2016-03-01 08:30:30 -0700 | [diff] [blame^] | 36 | this.getVpnTenants = (tenantId) => { |
Jeremy Mowery | 33e861a | 2016-02-25 18:14:03 -0700 | [diff] [blame] | 37 | let deferred = $q.defer(); |
| 38 | |
Jeremy Mowery | 9fa1255 | 2016-03-01 08:30:30 -0700 | [diff] [blame^] | 39 | $http.get('/xoslib/clientscript/', {params: {tenantId: tenantId}}) |
Jeremy Mowery | 33e861a | 2016-02-25 18:14:03 -0700 | [diff] [blame] | 40 | .then((res) => { |
| 41 | deferred.resolve(res.data) |
| 42 | }) |
| 43 | .catch((e) => { |
| 44 | deferred.reject(e); |
| 45 | }); |
| 46 | |
| 47 | return deferred.promise; |
Jeremy Mowery | 159f97b | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 48 | }; |
| 49 | }) |
| 50 | .config(function($httpProvider){ |
| 51 | $httpProvider.interceptors.push('NoHyperlinks'); |
| 52 | }) |
Jeremy Mowery | 42b2c01 | 2016-02-25 11:25:53 -0700 | [diff] [blame] | 53 | .directive('vpnList', function(){ |
Jeremy Mowery | 159f97b | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 54 | return { |
| 55 | restrict: 'E', |
| 56 | scope: {}, |
| 57 | bindToController: true, |
| 58 | controllerAs: 'vm', |
Jeremy Mowery | 42b2c01 | 2016-02-25 11:25:53 -0700 | [diff] [blame] | 59 | templateUrl: 'templates/vpn-list.tpl.html', |
Jeremy Mowery | 159f97b | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 60 | controller: function(Vpn){ |
| 61 | // retrieving user list |
| 62 | Vpn.getVpnTenants() |
Jeremy Mowery | 05cdae8 | 2016-02-28 22:21:54 -0700 | [diff] [blame] | 63 | .then((vpns) => { |
Jeremy Mowery | 42b2c01 | 2016-02-25 11:25:53 -0700 | [diff] [blame] | 64 | this.vpns = vpns; |
Jeremy Mowery | 159f97b | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 65 | }) |
| 66 | .catch((e) => { |
| 67 | throw new Error(e); |
| 68 | }); |
| 69 | } |
| 70 | }; |
Jeremy Mowery | 33e861a | 2016-02-25 18:14:03 -0700 | [diff] [blame] | 71 | }) |
| 72 | .directive('clientScript', function(){ |
| 73 | return { |
| 74 | restrict: 'E', |
| 75 | scope: { |
Jeremy Mowery | 9fa1255 | 2016-03-01 08:30:30 -0700 | [diff] [blame^] | 76 | tenantId: '=tenantId', |
Jeremy Mowery | 33e861a | 2016-02-25 18:14:03 -0700 | [diff] [blame] | 77 | }, |
| 78 | bindToController: true, |
| 79 | controllerAs: 'vm', |
| 80 | templateUrl: 'templates/client-script.tpl.html', |
| 81 | controller: function(Vpn){ |
| 82 | // retrieving user list |
Jeremy Mowery | 9fa1255 | 2016-03-01 08:30:30 -0700 | [diff] [blame^] | 83 | Vpn.getClientScript(tenantId) |
Jeremy Mowery | 05cdae8 | 2016-02-28 22:21:54 -0700 | [diff] [blame] | 84 | .then((script_location) => { |
Jeremy Mowery | 33e861a | 2016-02-25 18:14:03 -0700 | [diff] [blame] | 85 | this.script_location = script_location; |
| 86 | }) |
| 87 | .catch((e) => { |
| 88 | throw new Error(e); |
| 89 | }); |
| 90 | } |
| 91 | }; |
Jeremy Mowery | 159f97b | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 92 | }); |