blob: b3b7f8527ba925d36ca3ba1c8a4d92865b05518a [file] [log] [blame]
Jeremy Mowery159f97b2016-02-25 09:32:00 -07001'use strict';
2
3angular.module('xos.vpnDashboard', [
4 'ngResource',
5 'ngCookies',
6 'ngLodash',
7 'ui.router',
8 'xos.helpers'
9])
10.config(($stateProvider) => {
11 $stateProvider
Jeremy Mowery9fa12552016-03-01 08:30:30 -070012 .state('vpnList', {
Jeremy Mowery159f97b2016-02-25 09:32:00 -070013 url: '/',
Jeremy Mowery42b2c012016-02-25 11:25:53 -070014 template: '<vpn-list></vpn-list>'
Jeremy Mowery33e861a2016-02-25 18:14:03 -070015 })
Jeremy Mowery9fa12552016-03-01 08:30:30 -070016 .state('clientScript', {
17 url: '/client/:tenantId',
Jeremy Mowery33e861a2016-02-25 18:14:03 -070018 template: '<client-script></client-script>'
Jeremy Mowery159f97b2016-02-25 09:32:00 -070019 });
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 Mowery33e861a2016-02-25 18:14:03 -070035 }
Jeremy Mowery9fa12552016-03-01 08:30:30 -070036 this.getVpnTenants = (tenantId) => {
Jeremy Mowery33e861a2016-02-25 18:14:03 -070037 let deferred = $q.defer();
38
Jeremy Mowery9fa12552016-03-01 08:30:30 -070039 $http.get('/xoslib/clientscript/', {params: {tenantId: tenantId}})
Jeremy Mowery33e861a2016-02-25 18:14:03 -070040 .then((res) => {
41 deferred.resolve(res.data)
42 })
43 .catch((e) => {
44 deferred.reject(e);
45 });
46
47 return deferred.promise;
Jeremy Mowery159f97b2016-02-25 09:32:00 -070048 };
49})
50.config(function($httpProvider){
51 $httpProvider.interceptors.push('NoHyperlinks');
52})
Jeremy Mowery42b2c012016-02-25 11:25:53 -070053.directive('vpnList', function(){
Jeremy Mowery159f97b2016-02-25 09:32:00 -070054 return {
55 restrict: 'E',
56 scope: {},
57 bindToController: true,
58 controllerAs: 'vm',
Jeremy Mowery42b2c012016-02-25 11:25:53 -070059 templateUrl: 'templates/vpn-list.tpl.html',
Jeremy Mowery159f97b2016-02-25 09:32:00 -070060 controller: function(Vpn){
61 // retrieving user list
62 Vpn.getVpnTenants()
Jeremy Mowery05cdae82016-02-28 22:21:54 -070063 .then((vpns) => {
Jeremy Mowery42b2c012016-02-25 11:25:53 -070064 this.vpns = vpns;
Jeremy Mowery159f97b2016-02-25 09:32:00 -070065 })
66 .catch((e) => {
67 throw new Error(e);
68 });
69 }
70 };
Jeremy Mowery33e861a2016-02-25 18:14:03 -070071})
72.directive('clientScript', function(){
73 return {
74 restrict: 'E',
75 scope: {
Jeremy Mowery9fa12552016-03-01 08:30:30 -070076 tenantId: '=tenantId',
Jeremy Mowery33e861a2016-02-25 18:14:03 -070077 },
78 bindToController: true,
79 controllerAs: 'vm',
80 templateUrl: 'templates/client-script.tpl.html',
81 controller: function(Vpn){
82 // retrieving user list
Jeremy Mowery9fa12552016-03-01 08:30:30 -070083 Vpn.getClientScript(tenantId)
Jeremy Mowery05cdae82016-02-28 22:21:54 -070084 .then((script_location) => {
Jeremy Mowery33e861a2016-02-25 18:14:03 -070085 this.script_location = script_location;
86 })
87 .catch((e) => {
88 throw new Error(e);
89 });
90 }
91 };
Jeremy Mowery159f97b2016-02-25 09:32:00 -070092});