2 * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 var app = angular.module('RegisterTimeslot');
20 'RegisterTimeslotController',
21 function($scope, restAPISvc, $q) {
25 function initialize() {
26 $scope.loadingLabs = true;
27 $scope.loadingBlueprintInstances = true;
28 $scope.definedStart = "now";
31 $scope.selectedLab = '';
32 $scope.blueprintInstances = [];
33 $scope.declerativeInsts = [];
34 $scope.selectedDeclerativeInst = '';
41 $scope.labInfos = data;
42 angular.forEach(data, function(
44 $scope.labs.push(lab.lab);
48 "/api/v1/blueprintinstance/",
51 $scope.blueprintInstances = data2;
54 $scope.blueprintInstances,
58 + blueprintInstance.blueprintInstanceId
60 + blueprintInstance["blueprint"]["blueprintName"]
62 + blueprintInstance["version"];
63 $scope.declerativeInsts
67 confirm("No blueprint instances found");
71 confirm("No labs found");
73 $scope.loadingLabs = false;
74 $scope.loadingBlueprintInstances = false;
78 $scope.addInst = function(selectedDeclerativeInst) {
80 .indexOf(selectedDeclerativeInst.trim()) === -1) {
81 $scope.insts.push(selectedDeclerativeInst);
85 $scope.deleteInst = function(index) {
86 $scope.insts.splice(index, 1);
89 $scope.register = function() {
90 if (!$scope.selectedLab || !$scope.insts
91 || $scope.insts.length === 0) {
92 confirm("You must specify all the fields");
96 angular.forEach($scope.labInfos, function(labInfo) {
97 if (labInfo.lab.trim() === $scope.selectedLab) {
102 confirm("Error in lab data");
106 "startDateTime" : $scope.definedStart,
115 var confirmText = "The timeslot has been registered successfully. Timeslot id:"
117 confirm(confirmText);
118 updateBlusInsts(data);
120 confirm("Error when registering the timeslot");
125 function updateBlusInsts(timeslot) {
126 var blueprintInstances = [];
131 var id = inst.substring(inst
132 .indexOf("id:") + 4, inst
133 .indexOf("name") - 1);
136 $scope.blueprintInstances,
139 if (blueprintInstance.blueprintInstanceId
145 .push(blueprintInstance);
149 if (!blueprintInstances) {
150 confirm("Error in blueprint instances data");
157 function(blueprintInstance) {
158 if (blueprintInstance.timeslots) {
159 blueprintInstance.timeslots
162 blueprintInstance.timeslots = [ timeslot ];
167 "/api/v1/blueprintinstance/",
172 var text = "Blueprint instance: "
173 + blueprintInstance.blueprint.blueprintName
175 + blueprintInstance.version
176 + " updated successfully";
179 var text2 = "Failed to update blueprint instance: "
180 + blueprintInstance.blueprint.blueprintName
182 + blueprintInstance.version;
191 confirm("All blueprint instances have been updated");
192 $scope.selectedLab = '';
193 $scope.selectedDeclerativeInst = '';