Matteo Scandolo | 05bff8c | 2016-06-13 16:55:20 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 8fb63ec | 2017-08-03 22:46:35 -0700 | [diff] [blame] | 2 | * Copyright 2015 Open Networking Foundation |
Matteo Scandolo | 05bff8c | 2016-06-13 16:55:20 -0700 | [diff] [blame] | 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 | angular.module('mCord') |
| 18 | .directive('addProfileToItem', function () { |
| 19 | return { |
| 20 | restrict: 'E', |
| 21 | templateUrl: 'app/components/add-profile-to-item/add-profile-to-item.html', |
| 22 | scope: { |
| 23 | modal: '=', |
| 24 | cb: '=', |
| 25 | item: '=' |
| 26 | }, |
| 27 | bindToController: true, |
| 28 | controllerAs: 'vm', |
| 29 | controller: function(Profile){ |
| 30 | |
| 31 | Profile.query().$promise |
| 32 | .then((profiles) => { |
Matteo Scandolo | 3b3eee8 | 2016-06-23 16:38:04 -0700 | [diff] [blame] | 33 | profiles = _.filter(profiles, p => { |
| 34 | console.log(p.Name, p.Name.indexOf('Default'), p.Name.indexOf('Default') === -1); |
| 35 | return p.Name.indexOf('Default') === -1 |
| 36 | }); |
| 37 | console.log(profiles); |
Matteo Scandolo | 05bff8c | 2016-06-13 16:55:20 -0700 | [diff] [blame] | 38 | this.profiles = profiles; |
| 39 | return this.item.getProfiles(); |
| 40 | }) |
| 41 | .then((itemProfiles) => { |
Matteo Scandolo | 3b3eee8 | 2016-06-23 16:38:04 -0700 | [diff] [blame] | 42 | console.log(this.profiles, itemProfiles); |
Matteo Scandolo | 05bff8c | 2016-06-13 16:55:20 -0700 | [diff] [blame] | 43 | this.profiles = _.differenceBy(this.profiles, itemProfiles, 'Name'); |
| 44 | }); |
| 45 | |
| 46 | this.config = { |
| 47 | columns: [ |
| 48 | { |
| 49 | label: 'Name', |
| 50 | prop: 'Name' |
| 51 | }, |
| 52 | { |
| 53 | label: 'DlAllocRBRate', |
| 54 | prop: 'DlAllocRBRate' |
| 55 | }, |
| 56 | { |
| 57 | label: 'UlAllocRBRate', |
| 58 | prop: 'UlAllocRBRate' |
| 59 | }, |
| 60 | { |
| 61 | label: 'Start', |
| 62 | prop: 'Start' |
| 63 | }, |
| 64 | { |
| 65 | label: 'End', |
| 66 | prop: 'End' |
| 67 | } |
| 68 | ], |
| 69 | actions: [ |
| 70 | { |
| 71 | label: 'Add', |
| 72 | icon: 'plus', |
| 73 | cb: (profile) => { |
| 74 | _.remove(this.profiles, p => p.Name === profile.Name); |
| 75 | this.cb(profile); |
| 76 | }, |
| 77 | } |
| 78 | ], |
| 79 | filter: 'field', |
| 80 | order: true |
| 81 | } |
| 82 | } |
| 83 | }; |
| 84 | }); |