blob: ae041117201f869d14d5a890b9820149f1992e59 [file] [log] [blame]
Steven Burrows57e24e92016-08-04 18:38:24 +01001/*
2 * Copyright 2016-present 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 -- Topology Devices Module.
19 Module that holds the devices for a region
20 */
21
22(function () {
23 'use strict';
24
25 var Collection, Model;
26
27 function createDeviceCollection(data, region) {
28
29 var DeviceCollection = Collection.extend({
30 model: Model,
31 get: function () {},
32 comparator: function(a, b) {
33
34 var order = region.layerOrder;
35 return order.indexOf(a.get('layer')) - order.indexOf(b.get('layer'));
36 }
37 });
38
39 var devices = [];
40 data.forEach(function (deviceLayer) {
41 deviceLayer.forEach(function (device) {
42 devices.push(device);
43 });
44 });
45
46 var deviceCollection = new DeviceCollection(devices);
47 deviceCollection.sort();
48
49 return deviceCollection;
50 }
51
52 angular.module('ovTopo2')
53 .factory('Topo2DeviceService',
54 ['Topo2Collection', 'Topo2Model',
55
56 function (_Collection_, _Model_) {
57
58 Collection = _Collection_;
59 Model = _Model_.extend({});
60
61 return {
62 createDeviceCollection: createDeviceCollection
63 };
64 }
65 ]);
66
67})();