Initialize the UI code
[holmes/rule-management.git] / rulemgt / src / main / frontend / src / public / framework / browser / js / DataService.js
1 /*
2
3     Copyright 2016-2017, Huawei Technologies Co., Ltd.
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
19 app.factory("DataService", function($http, $log){
20     return {
21         getAllData: function (value) {
22             //var value = $scope.param;
23             return $http({
24                 url: 'http://localhost:8080/POC_NodeToServletPorting_Server/?widgetType=' + value,
25                 headers: {'Content-Type': 'application/json'},
26                 method: 'GET'
27             }).then(function (response) {
28                 $log.info(response.data);
29                 return response.data;
30             })
31         },
32
33         getAllProvinceData : function() {
34             return $http({
35                 url: 'http://localhost:3000/api/getAllProvinceData',
36                 method: 'GET',
37                 headers: {'Content-Type': 'application/json'}
38             }).then(function(response){
39                 //$log.info(response);
40                 return response.data;
41             });
42         },
43         addProvinceData : function(provinceDetail) {
44             return $http({
45                 url: 'http://localhost:3000/api/addProvinceData',
46                 method: 'POST',
47                 data: provinceDetail,
48                 headers: {'Content-Type': 'application/json '}
49             }).then(function(response){
50                 console.log("Response : ");
51                 $log.info(response.data);
52                 return response.data;
53             });
54         },
55         deleteProvinceData : function(idList) {
56             return $http({
57                 url: 'http://localhost:3000/api/deleteProvinceData',
58                 method: 'POST',
59                 data: {'idList':idList},
60                 headers: {'Content-Type': 'application/json'}
61             }).then(function(response){
62                 console.log("Successfully Deleted..");
63                 $log.info(response);
64                 return response.data;
65             });
66         },
67         editProvinceData : function(provinceDetail) {
68             return $http({
69                 url: 'http://localhost:3000/api/editProvinceData',
70                 method: 'POST',
71                 data: provinceDetail,
72                 headers: {'Content-Type': 'application/json'}
73             }).then(function(response){
74                 console.log("Successfully Edited...");
75                 $log.info(response);
76                 return response.data;
77             });
78         }
79     }
80 });
81
82 app.factory('LoginService', function($http, $log) {
83     var admin = 'admin';
84     var pass = 'pass';
85     var isAuthenticated = false;
86
87     return {
88         login : function(user) {
89             console.log(user);
90             return $http({
91                 url: 'http://localhost:8081/api/signin',//http://192.168.4.161:3000/api/login
92                 method: 'POST',
93                 data: {'name':user.username, 'pswd':user.password},
94                 headers: {'Content-Type': 'application/json'}
95             }).then(function(response){
96                 $log.info(response);
97                 if(response.status == 200) {
98                     console.log("Success");
99                     //Success
100                     isAuthenticated = true;
101                 }
102                 else {
103                     console.log("Fail");
104                     isAuthenticated = false;
105                 }
106                 console.log("isAuthenticated: " + isAuthenticated);
107                 return isAuthenticated;
108             }, function(reason){
109                 $log.info(reason);
110                 console.log("Fail");
111                 isAuthenticated = false;
112                 return reason;
113             });
114             /*isAuthenticated = user.username === admin && user.password === pass;
115             return isAuthenticated;*/
116         },
117         isAuthenticated : function() {
118             return isAuthenticated;
119         },
120         registerUser: function(user){
121             console.log("New Registration: " + JSON.stringify(user));
122             return $http({
123                 url: 'http://localhost:8081/api/signup',//http://192.168.4.161:3000/api/login
124                 method: 'POST',
125                 data: {'name':user.username, 'pswd':user.password, 'email':user.email},
126                 headers: {'Content-Type': 'application/json'}
127             }).then(function(response){
128                 $log.info(response);
129             },function(reason){
130                 $log.info(reason);
131             });
132
133
134         }
135     };
136
137 });