UI initial implementation.
[validation.git] / ui / src / main / webapp / resources / js / AECCommittedSubmissionsController.js
1 /*
2  * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
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 var AECBlueprintValidationUIApp = angular
18         .module('BlueprintValidationUIManagement');
19
20 AECBlueprintValidationUIApp.controller('AECCommittedSubmissionsController',
21         function($scope, restAPISvc, $interval, refreshPeriod) {
22
23             $scope.submissionIdList = [];
24
25             restAPISvc.getRestAPI("/api/submission/", function(data) {
26                 $scope.submissions = data;
27             });
28
29             $scope.refreshCommittedSubmissions = function() {
30                 restAPISvc.getRestAPI("/api/submission/", function(data) {
31                     $scope.submissions = data;
32                 });
33             }
34
35             $scope.modifySubmissionIdList = function(id) {
36                 if ($scope.submissionIdList.indexOf(id) === -1) {
37                     $scope.submissionIdList.push(id);
38                 } else {
39                     $scope.submissionIdList.splice($scope.submissionIdList
40                             .indexOf(id), 1);
41                 }
42             }
43
44             $scope.deleteSubmissions = function() {
45                 var confirmation = confirm("Are you sure?");
46                 if (confirmation == true) {
47                     angular.forEach($scope.submissionIdList, function(id) {
48                         var submission = {
49                             "submissionId" : id
50                         };
51                         restAPISvc
52                                 .deleteRestAPI("/api/submission/", submission);
53                     });
54                 }
55             }
56
57             $interval(function() {
58                 $scope.refreshCommittedSubmissions();
59             }, refreshPeriod);
60
61         });