cleanup of obsolete non-CI arm PODs
[releng.git] / utils / test / testapi / 3rd_party / static / testapi-ui / components / pods / podsController.js
1 /*
2  * Licensed under the Apache License, Version 2.0 (the "License");
3  * you may not use this file except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS,
10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  * See the License for the specific language governing permissions and
12  * limitations under the License.
13  */
14
15 (function () {
16     'use strict';
17
18     angular
19         .module('testapiApp')
20         .controller('PodsController', PodsController);
21
22     PodsController.$inject = [
23         '$scope', '$http', '$filter', '$state', 'testapiApiUrl','raiseAlert'
24     ];
25
26     /**
27      * TestAPI Pods Controller
28      * This controller is for the '/pods' page where a user can browse
29      * through pods declared in TestAPI.
30      */
31     function PodsController($scope, $http, $filter, $state, testapiApiUrl,
32         raiseAlert) {
33         var ctrl = this;
34
35         ctrl.url = testapiApiUrl + '/pods';
36
37         ctrl.create = create;
38         ctrl.update = update;
39         ctrl.open = open;
40         ctrl.clearFilters = clearFilters;
41
42         ctrl.roles = ['community-ci', 'production-ci'];
43         ctrl.modes = ['metal', 'virtual'];
44         ctrl.createRequirements = [
45             {label: 'name', type: 'text', required: true},
46             {label: 'mode', type: 'select', selects: ctrl.modes},
47             {label: 'role', type: 'select', selects: ctrl.roles},
48             {label: 'details', type: 'textarea', required: false}
49         ];
50
51         ctrl.name = '';
52         ctrl.role = 'community-ci';
53         ctrl.mode = 'metal';
54         ctrl.details = '';
55
56         ctrl.pageHeader = 'Pods';
57         ctrl.pageParagraph = 'This page is used to create or query pods.';
58
59         /**
60          * This is called when the date filter calendar is opened. It
61          * does some event handling, and sets a scope variable so the UI
62          * knows which calendar was opened.
63          * @param {Object} $event - The Event object
64          * @param {String} openVar - Tells which calendar was opened
65          */
66         function open($event, openVar) {
67             $event.preventDefault();
68             $event.stopPropagation();
69             ctrl[openVar] = true;
70         }
71
72         /**
73          * This function will clear all filters and update the results
74          * listing.
75          */
76         function clearFilters() {
77             ctrl.update();
78         }
79
80         /**
81          * This will contact the TestAPI to create a new pod.
82          */
83         function create() {
84             ctrl.showError = false;
85             var pods_url = ctrl.url;
86             var body = {
87                 name: ctrl.name,
88                 mode: ctrl.mode,
89                 role: ctrl.role,
90                 details: ctrl.details
91             };
92
93             ctrl.podsRequest =
94                 $http.post(pods_url, body).error(function (error) {
95                     ctrl.showError = true;
96                     ctrl.error =
97                         'Error creating the new pod from server: ' +
98                         angular.toJson(error);
99                 });
100         }
101
102         /**
103          * This will contact the TestAPI to get a listing of declared pods.
104          */
105         function update() {
106             ctrl.showError = false;
107             ctrl.podsRequest =
108                 $http.get(ctrl.url).success(function (data) {
109                     ctrl.data = data;
110                 }).error(function (error) {
111                     ctrl.data = null;
112                     ctrl.showError = true;
113                     ctrl.error =
114                         'Error retrieving pods from server: ' +
115                         angular.toJson(error);
116                 });
117         }
118     }
119 })();