blob: 9361afc2ce3faa5d746b5e63062f722037c65c00 [file] [log] [blame]
Simon Hunte6720442015-01-15 12:21:06 -08001/*
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 -- Remote Communications Module -- REST Service
Simon Hunte6720442015-01-15 12:21:06 -080019 */
20(function () {
21 'use strict';
22
23 var $log;
24
Simon Huntaa26adf2015-01-20 10:32:49 -080025 var urlSuffix = '/onos/ui/rs/';
Bri Prebilic Cole4fab8af2015-01-15 16:40:47 -080026
27
28
29 // TODO: remove temporary test code
30 var fakeData = {
31 '1': {
32 "devices": [{
33 "id": "of:0000000000000001",
34 "available": true,
Simon Hunt97225382015-01-19 13:33:09 -080035 "_iconid_available": "deviceOnline",
Bri Prebilic Cole4fab8af2015-01-15 16:40:47 -080036 "role": "MASTER",
37 "mfr": "Nicira, Inc.",
38 "hw": "Open vSwitch",
39 "sw": "2.0.1",
40 "serial": "None",
41 "annotations": {
42 "protocol": "OF_10"
43 }
44 },
Simon Hunt97225382015-01-19 13:33:09 -080045 {
46 "id": "of:0000000000000004",
47 "available": false,
48 "_iconid_available": "deviceOffline",
49 "role": "MASTER",
50 "mfr": "Nicira, Inc.",
51 "hw": "Open vSwitch",
52 "sw": "2.0.1",
53 "serial": "None",
54 "annotations": {
55 "protocol": "OF_10"
56 }
57 },
58 {
59 "id": "of:0000000000000092",
60 "available": false,
61 "_iconid_available": "deviceOffline",
62 "role": "MASTER",
63 "mfr": "Nicira, Inc.",
64 "hw": "Open vSwitch",
65 "sw": "2.0.1",
66 "serial": "None",
67 "annotations": {
68 "protocol": "OF_10"
69 }
70 }]
Bri Prebilic Cole4fab8af2015-01-15 16:40:47 -080071 },
72 '2': {
73 "devices": [{
74 "id": "of:0000000000000002",
75 "available": true,
Simon Hunt97225382015-01-19 13:33:09 -080076 "_iconid_available": "deviceOnline",
Bri Prebilic Cole4fab8af2015-01-15 16:40:47 -080077 "role": "MASTER",
78 "mfr": "Nicira, Inc.",
79 "hw": "Open vSwitch",
80 "sw": "2.0.0",
81 "serial": "None",
82 "annotations": {
83 "protocol": "OF_10"
84 }
85 },
Simon Hunt97225382015-01-19 13:33:09 -080086 {
87 "id": "of:0000000000000006",
88 "available": true,
89 "_iconid_available": "deviceOnline",
90 "role": "MASTER",
91 "mfr": "Nicira, Inc.",
92 "hw": "Open vSwitch",
93 "sw": "2.1.1",
94 "serial": "None",
95 "annotations": {
96 "protocol": "OF_10"
97 }
98 }]
Bri Prebilic Cole4fab8af2015-01-15 16:40:47 -080099 },
100 'empty': {
101 devices: []
102 }
103 };
104
105 function getFakeData(url) {
106 var id = url.slice(5);
107
108 return fakeData[id] || fakeData.empty;
109 }
110
Simon Hunte6720442015-01-15 12:21:06 -0800111 angular.module('onosRemote')
Bri Prebilic Cole4fab8af2015-01-15 16:40:47 -0800112 .factory('RestService', ['$log', '$http', 'UrlFnService',
113 function (_$log_, $http, ufs) {
Simon Hunte6720442015-01-15 12:21:06 -0800114 $log = _$log_;
115
116 function get(url, callback) {
Bri Prebilic Cole4fab8af2015-01-15 16:40:47 -0800117 // TODO: remove temporary test code
118 if (url.match(/^test\//)) {
119 callback(getFakeData(url));
120 return;
121 }
122 var fullUrl = ufs.urlPrefix() + urlSuffix + url;
123
124 $http.get(fullUrl).then(function (response) {
Simon Hunte6720442015-01-15 12:21:06 -0800125 // success
126 callback(response.data);
127 }, function (response) {
128 // error
Bri Prebilic Cole4fab8af2015-01-15 16:40:47 -0800129 $log.warn('Failed to retrieve JSON data: ' + fullUrl,
Simon Hunte6720442015-01-15 12:21:06 -0800130 response.status, response.data);
131 });
132 }
133
134 return {
135 get: get
136 };
137 }]);
138
139}());