Skip to content
This repository was archived by the owner on May 14, 2023. It is now read-only.

Commit 757abd7

Browse files
committed
release v1
0 parents  commit 757abd7

33 files changed

+1604
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

index.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en" ng-app="agrihub">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Cloud Gateway</title>
6+
<script src="scripts/vendor/angular.min.js"></script>
7+
<script src="scripts/vendor/angular-route.min.js"></script>
8+
<script src="scripts/vendor/angular-resource.min.js"></script>
9+
<script src="scripts/vendor/angular-cookies.min.js"></script>
10+
<script src="scripts/vendor/ui-bootstrap.min.js"></script>
11+
<script src="scripts/directives/directives.js"></script>
12+
<script src="scripts/services/services.js"></script>
13+
<script src="scripts/services/authenticate.js"></script>
14+
<script src="scripts/mainApp.js"></script>
15+
<script src="scripts/controllers/main.controllers.js"></script>
16+
<script src="scripts/controllers/node.controllers.js"></script>
17+
<script src="scripts/controllers/sensor.controllers.js"></script>
18+
<script src="scripts/controllers/subscription.controllers.js"></script>
19+
<link href="styles/bootstrap.min.css" rel="stylesheet">
20+
</head>
21+
<body>
22+
<div ng-view></div>
23+
</body>
24+
</html>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
'use strict';
2+
3+
app.controller('MainCtrl',
4+
function($scope, $location, checkCreds) {
5+
if (!checkCreds.isAuth()) {
6+
$location.path('/login');
7+
return;
8+
}
9+
10+
if (checkCreds.isAdmin()) {
11+
$location.path('/403');
12+
} else if (checkCreds.isResearcher()) {
13+
$location.path('/nodes/index');
14+
}
15+
}
16+
);
17+
18+
app.controller('LoginCtrl',
19+
function($scope, $location, Login, setCreds, checkCreds) {
20+
if (checkCreds.isAuth()) {
21+
$location.path('/nodes/index');
22+
}
23+
24+
// default
25+
$scope.user = {
26+
'username': 'basukicahya',
27+
'password': 'admin123'
28+
};
29+
30+
$scope.submit = function () {
31+
$scope.sub = true;
32+
33+
var postData = {
34+
"username": $scope.user.username,
35+
"password": $scope.user.password
36+
};
37+
38+
Login.login({}, postData,
39+
function success(response) {
40+
if (undefined !== response.token) {
41+
// console.log("Success:" + JSON.stringify(response));
42+
setCreds(response);
43+
$location.path('/');
44+
} else {
45+
$scope.error = 'Login Failed';
46+
}
47+
},
48+
function error(errorResponse) {
49+
// console.log("Error:" + JSON.stringify(errorResponse));
50+
$scope.error = errorResponse.data.__all__;
51+
}
52+
);
53+
}
54+
}
55+
);
56+
57+
app.controller('LogoutCtrl',
58+
function($scope, $location, deleteCreds) {
59+
deleteCreds();
60+
$location.path('/login');
61+
}
62+
);
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
'use strict';
2+
3+
app.controller('NodeListCtrl',
4+
function($scope, $location, Nodes, checkCreds) {
5+
if (!checkCreds.isAuth()) {
6+
$location.path('/login');
7+
return;
8+
}
9+
10+
// breadcrumb
11+
$scope.links = [
12+
{ label: "Home", url: "/#/" , is_active: true}
13+
];
14+
15+
Nodes.query().success(function (data) {
16+
$scope.nodes = data
17+
})
18+
}
19+
);
20+
21+
app.controller('NodeViewCtrl',
22+
function($scope, $routeParams, $location, Nodes) {
23+
Nodes.get($routeParams.nodeId).success(function (data) {
24+
$scope.node = data;
25+
// breadcrumb
26+
$scope.links = [
27+
{ label: "Home", url: "/#/" },
28+
{ label: "Nodes", url: "/#/"},
29+
{ label: data.label, is_active: true}
30+
];
31+
});
32+
33+
$scope.edit = function() {
34+
$location.path('/nodes/edit/' + $scope.node.id);
35+
};
36+
}
37+
);
38+
39+
app.controller('NodeEditCtrl',
40+
function($scope, $routeParams, $location, Nodes) {
41+
Nodes.get($routeParams.nodeId).success(function (data) {
42+
$scope.node = data;
43+
// breadcrumb
44+
$scope.links = [
45+
{ label: "Home", url: "/#/" },
46+
{ label: "Nodes", url: "/#/"},
47+
{ label: data.label, url: "/#/nodes/view/" + data.id},
48+
{ label: "Edit", is_active: true}
49+
];
50+
});
51+
$scope.save = function() {
52+
Nodes.save($scope.node).then(function() {
53+
$location.path('/nodes/index');
54+
});
55+
};
56+
}
57+
);
58+
59+
app.controller('NodeNewCtrl',
60+
function($scope, $location, Nodes, getCreds) {
61+
$scope.is_new = true;
62+
$scope.node = {
63+
'user': getCreds.user.username,
64+
'label': "LAB_1",
65+
'secretkey': 'rahasia',
66+
'subsperday': 20
67+
};
68+
// breadcrumb
69+
$scope.links = [
70+
{ label: "Home", url: "/#/" },
71+
{ label: "Nodes", url: "/#/"},
72+
{ label: "New", is_active: true}
73+
];
74+
$scope.save = function() {
75+
Nodes.save($scope.node).then(
76+
function(response) {
77+
$location.path('/nodes/index');
78+
},
79+
function(error) {
80+
var errors = [];
81+
angular.forEach(error.data, function(value, key) {
82+
this.push({
83+
field: key,
84+
message: value[0]
85+
});
86+
}, errors);
87+
$scope.errors = errors;
88+
}
89+
);
90+
};
91+
}
92+
);
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
'use strict';
2+
3+
app.controller('SensorListCtrl',
4+
function($scope, $routeParams, $location, Nodes, Sensors, checkCreds, $log) {
5+
if (!checkCreds.isAuth()) {
6+
$location.path('/login');
7+
return;
8+
}
9+
10+
Nodes.get($routeParams.nodeId).success(function (data) {
11+
// breadcrumb
12+
$scope.links = [
13+
{ label: "Home", url: "/#/" },
14+
{ label: "Nodes", url: "/#/nodes/index"},
15+
{ label: data.label, url: "/#/nodes/view/" + data.id},
16+
{ label: "Sensors", is_active: true}
17+
];
18+
});
19+
Sensors.query($routeParams.nodeId).success(function (data) {
20+
$scope.sensors = data;
21+
$scope.nodeid = $routeParams.nodeId;
22+
})
23+
}
24+
);
25+
26+
app.controller('SensorViewCtrl',
27+
function($scope, $routeParams, $location, Nodes, Sensors) {
28+
Nodes.get($routeParams.nodeId).success(function (data) {
29+
$scope.nodeid = data.id;
30+
// breadcrumb
31+
$scope.links = [
32+
{ label: "Home", url: "/#/" },
33+
{ label: "Nodes", url: "/#/nodes/index"},
34+
{ label: data.label, url: "/#/nodes/view/" + data.id}
35+
];
36+
Sensors.get($routeParams.nodeId, $routeParams.sensorId).success(function (data) {
37+
// breadcrumb
38+
$scope.links.push(
39+
{ label: "Sensors", url: "/#/nodes/" + $routeParams.nodeId + "/sensors/index"},
40+
{ label: data.label, is_active: true}
41+
);
42+
$scope.sensor = data;
43+
});
44+
});
45+
46+
$scope.edit = function() {
47+
$location.path('/nodes/' + $scope.nodeid + '/sensors/edit/' + $scope.sensor.id);
48+
};
49+
}
50+
);
51+
52+
app.controller('SensorNewCtrl',
53+
function($scope, $routeParams, $location, Nodes, Sensors) {
54+
$scope.is_new = true;
55+
Nodes.get($routeParams.nodeId).success(function (data) {
56+
$scope.node = data;
57+
// breadcrumb
58+
$scope.links = [
59+
{ label: "Home", url: "/#/" },
60+
{ label: "Nodes", url: "/#/nodes/index"},
61+
{ label: data.label, url: "/#/nodes/view/" + data.id},
62+
{ label: "Sensors", url: "/#/nodes/" + data.id + "/sensors/index"},
63+
{ label: "New", is_active: true}
64+
];
65+
});
66+
$scope.sensor = {
67+
label: 'TEMP'
68+
};
69+
$scope.save = function() {
70+
Sensors.save($scope.node, $scope.sensor).then(
71+
function(response) {
72+
$location.path("/nodes/" + $scope.node.id + "/sensors/index");
73+
},
74+
function(error) {
75+
console.log(error)
76+
$scope.errors = [
77+
{field: "label", message: error.data.label[0]}
78+
];
79+
}
80+
);
81+
};
82+
}
83+
);
84+
85+
app.controller('SensorEditCtrl',
86+
function($scope, $routeParams, $location, Nodes, Sensors) {
87+
Nodes.get($routeParams.nodeId).success(function (data) {
88+
$scope.node = data;
89+
// breadcrumb
90+
$scope.links = [
91+
{ label: "Home", url: "/#/" },
92+
{ label: "Nodes", url: "/#/nodes/index"},
93+
{ label: data.label, url: "/#/nodes/view/" + data.id}
94+
];
95+
Sensors.get($routeParams.nodeId, $routeParams.sensorId).success(function (data) {
96+
// breadcrumb
97+
$scope.links.push(
98+
{ label: "Sensors", url: "/#/nodes/" + $routeParams.nodeId + "/sensors/index"},
99+
{ label: data.label, is_active: true}
100+
);
101+
$scope.sensor = data;
102+
});
103+
});
104+
$scope.save = function() {
105+
Sensors.save($scope.node, $scope.sensor).then(function() {
106+
$location.path("/nodes/" + $scope.node.id + "/sensors/index");
107+
});
108+
};
109+
}
110+
);

0 commit comments

Comments
 (0)