blob: 5a6e173d162df3b85e64648256d9b1734fce835f [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
Jeremy Mowery6efeb7a2016-02-25 09:32:00 -070019'use strict';
20
Jeremy Mowery81e84cc2016-04-19 17:01:48 -070021angular.module('xos.openVPNDashboard', [
Jeremy Mowery6efeb7a2016-02-25 09:32:00 -070022 'ngResource',
23 'ngCookies',
Jeremy Mowery6efeb7a2016-02-25 09:32:00 -070024 'ui.router',
25 'xos.helpers'
26])
27.config(($stateProvider) => {
28 $stateProvider
Jeremy Mowery81e84cc2016-04-19 17:01:48 -070029 .state('openVPNList', {
Jeremy Mowery6efeb7a2016-02-25 09:32:00 -070030 url: '/',
Jeremy Mowery41d6e882016-04-19 19:31:11 -070031 template: '<vpn-list></vpn-list>'
Jeremy Mowery6efeb7a2016-02-25 09:32:00 -070032 });
33})
Jeremy Moweryc257c412016-03-01 19:15:40 -070034.config(($compileProvider) => {
35 $compileProvider.aHrefSanitizationWhitelist(
36 /^\s*(https?|ftp|mailto|tel|file|blob):/);
37})
Jeremy Mowery6efeb7a2016-02-25 09:32:00 -070038.service('Vpn', function($http, $q){
39
Jeremy Mowery41d6e882016-04-19 19:31:11 -070040 this.getOpenVpnTenants = () => {
Jeremy Mowery6efeb7a2016-02-25 09:32:00 -070041 let deferred = $q.defer();
42
Jeremy Mowery441c3d62016-04-23 14:31:10 -070043 $http.get('/api/tenant/openvpn/list/')
Jeremy Mowery6efeb7a2016-02-25 09:32:00 -070044 .then((res) => {
45 deferred.resolve(res.data)
46 })
47 .catch((e) => {
48 deferred.reject(e);
49 });
50
51 return deferred.promise;
Jeremy Moweryc770ba02016-02-25 18:14:03 -070052 }
Jeremy Mowery6efeb7a2016-02-25 09:32:00 -070053})
54.config(function($httpProvider){
55 $httpProvider.interceptors.push('NoHyperlinks');
56})
Jeremy Mowery41d6e882016-04-19 19:31:11 -070057.directive('vpnList', function(){
Jeremy Mowery6efeb7a2016-02-25 09:32:00 -070058 return {
59 restrict: 'E',
60 scope: {},
61 bindToController: true,
62 controllerAs: 'vm',
Jeremy Mowery81e84cc2016-04-19 17:01:48 -070063 templateUrl: 'templates/openvpn-list.tpl.html',
Jeremy Mowery6efeb7a2016-02-25 09:32:00 -070064 controller: function(Vpn){
Jeremy Mowery41d6e882016-04-19 19:31:11 -070065 Vpn.getOpenVpnTenants()
Jeremy Mowerye84e3ee2016-02-28 22:21:54 -070066 .then((vpns) => {
Jeremy Mowery98dd6c82016-02-25 11:25:53 -070067 this.vpns = vpns;
Jeremy Mowery37e4efe2016-03-02 00:01:25 -070068 for (var i = 0; i < this.vpns.length; i++) {
Jeremy Moweryee139912016-04-17 19:20:01 -070069 var blob = new Blob([this.vpns[i].script_text], {type: 'text/plain'});
Jeremy Mowery37e4efe2016-03-02 00:01:25 -070070 this.vpns[i].script_text = (window.URL || window.webkitURL).createObjectURL( blob );
71 }
Jeremy Mowery6efeb7a2016-02-25 09:32:00 -070072 })
73 .catch((e) => {
74 throw new Error(e);
75 });
Jeremy Moweryc770ba02016-02-25 18:14:03 -070076 }
77 };
Jeremy Mowery6efeb7a2016-02-25 09:32:00 -070078});