Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | ONOS GUI -- Sample View Module |
| 19 | |
| 20 | @author Simon Hunt |
| 21 | @author Bri Prebilic Cole |
| 22 | */ |
| 23 | |
| 24 | (function () { |
| 25 | 'use strict'; |
| 26 | |
| 27 | var urlSuffix = '/onos/v1/devices'; |
| 28 | |
| 29 | // TODO : refactor into remote service |
| 30 | function buildUrl($loc) { |
| 31 | return $loc.protocol() + '://' + $loc.host() + ':' + $loc.port(); |
| 32 | } |
| 33 | |
| 34 | angular.module('ovDevice', []) |
| 35 | .controller('OvDeviceCtrl', ['$log', '$http', '$location', |
| 36 | function ($log, $http, $loc) { |
| 37 | var self = this; |
| 38 | self.deviceData = []; |
| 39 | var url = buildUrl($loc) + urlSuffix; |
| 40 | $log.log(url); |
| 41 | |
| 42 | $http.get(url).then( |
| 43 | //success |
| 44 | function (response) { |
| 45 | self.deviceData = response.data.devices; |
| 46 | }, |
| 47 | //failure |
| 48 | function (response) { |
| 49 | $log.warn('Failed to get device data ', response.status); |
| 50 | } |
| 51 | ); |
| 52 | |
| 53 | $log.log('OvDeviceCtrl has been created'); |
| 54 | }]); |
| 55 | }()); |