blob: 95c2342f9450ebc6fc400d31e99c2d3e921a590f [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
Matteo Scandolo70bc45f2016-05-06 14:10:11 -070019'use strict';
20
21angular.module('xos.serviceGrid', [
22 'ngResource',
23 'ngCookies',
24 'ui.router',
25 'xos.helpers'
26])
27.config(($stateProvider) => {
28 $stateProvider
29 .state('serviceGrid', {
30 url: '/',
31 template: '<service-grid></service-grid>'
32 })
33 .state('serviceGraph', {
34 url: '/graph',
35 template: '<service-graph></service-graph>'
36 });
37})
38.config(function($httpProvider){
39 $httpProvider.interceptors.push('NoHyperlinks');
40})
41.directive('serviceGrid', function(){
42 return {
43 restrict: 'E',
44 scope: {},
45 bindToController: true,
46 controllerAs: 'vm',
47 templateUrl: 'templates/service-grid.tpl.html',
Matteo Scandoloba678a92016-06-20 17:16:15 -070048 controller: function(Services, ToscaEncoder, _){
Matteo Scandolo70bc45f2016-05-06 14:10:11 -070049
50 this.tableConfig = {
51 columns: [
52 {
53 label: 'Status',
54 prop: 'status',
Matteo Scandolo83369f32016-05-13 10:39:38 -070055 type: 'icon',
56 formatter: item => {
57 let status = parseInt(item.backend_status.match(/^[0-9]/)[0]);
58 switch(status){
59 case 0:
60 return 'time';
61 case 1:
62 return 'ok';
63 case 2:
64 return 'remove';
65 }
66 }
Matteo Scandolo70bc45f2016-05-06 14:10:11 -070067 },
68 {
69 label: 'Name',
70 prop: 'name',
71 link: item => `${item.view_url.replace(/\$[a-z]+\$/, item.id)}`
72 },
73 {
74 label: 'Kind',
75 prop: 'kind'
76 },
77 {
78 label: 'Enabled',
79 prop: 'enabled',
80 type: 'boolean'
81 }
82 ],
83 filter: 'field',
Matteo Scandolo83369f32016-05-13 10:39:38 -070084 order: {
85 field: 'name'
Matteo Scandoloba678a92016-06-20 17:16:15 -070086 },
87 actions: [
88 {
89 label: 'export',
90 icon: 'export',
91 cb: service => {
92 this.tosca = '';
93 ToscaEncoder.serviceToTosca(service)
94 .then(tosca => {
95 this.showFeedback = true;
96 this.tosca = tosca;
97 });
98 }
99 }
100 ]
Matteo Scandolo70bc45f2016-05-06 14:10:11 -0700101 };
102
103 // retrieving user list
104 Services.query().$promise
105 .then((services) => {
106 this.services = _.map(services, s => {
107 // parse backend_status string in a boolean for display
Matteo Scandolo206d7482016-05-13 09:26:54 -0700108 // NOTE they are not boolean:
109 // - start with 0 = provisioning
110 // - start with 1 = good
111 // - start with 2 = error
Matteo Scandolo70bc45f2016-05-06 14:10:11 -0700112 s.status = parseInt(s.backend_status.match(/^[0-9]/)[0]) === 0 ? false : true;
113 return s;
114 })
115 })
116 .catch((e) => {
117 throw new Error(e);
118 });
119 }
120 };
121});