Skip to content

Commit fd57139

Browse files
committed
changes in analytics, admin login error message added
1 parent b7df2a9 commit fd57139

File tree

13 files changed

+70
-32
lines changed

13 files changed

+70
-32
lines changed

nitrite-datagate/src/main/java/org/dizitart/no2/datagate/controllers/HomeController.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package org.dizitart.no2.datagate.controllers;
1818

19-
import org.dizitart.no2.sync.data.UserAccount;
2019
import org.dizitart.no2.datagate.services.UserAccountService;
20+
import org.dizitart.no2.sync.data.UserAccount;
2121
import org.springframework.beans.factory.annotation.Autowired;
2222
import org.springframework.stereotype.Controller;
2323
import org.springframework.ui.Model;
@@ -58,4 +58,10 @@ public String signUp(@ModelAttribute UserAccount userAccount) {
5858
return "signUp";
5959
}
6060
}
61+
62+
@GetMapping(value = "/loginError")
63+
public String loginError(Model model) {
64+
model.addAttribute("loginError", true);
65+
return "login";
66+
}
6167
}

nitrite-datagate/src/main/java/org/dizitart/no2/datagate/models/Statistics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
public class Statistics {
2828
private int userCount;
2929
private int clientCount;
30-
private int collectionCount;
30+
private long collectionCount;
3131
private long documentCount;
3232
private Long[][] syncGraphData;
3333
private List<Device> deviceList;

nitrite-datagate/src/main/java/org/dizitart/no2/datagate/security/DataGateSecurityConfigurer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ protected void configure(HttpSecurity http) throws Exception {
7171
.and()
7272
.formLogin()
7373
.loginPage("/login")
74+
.failureUrl("/loginError")
7475
.defaultSuccessUrl("/admin/")
7576
.permitAll()
7677
.and()

nitrite-datagate/src/main/java/org/dizitart/no2/datagate/services/AnalyticsService.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
import org.dizitart.no2.datagate.models.Device;
2323
import org.dizitart.no2.datagate.models.Statistics;
2424
import org.dizitart.no2.datagate.models.SyncLog;
25-
import org.dizitart.no2.sync.data.UserAccount;
25+
import org.dizitart.no2.meta.Attributes;
2626
import org.jongo.Aggregate;
2727
import org.jongo.Jongo;
28+
import org.jongo.MongoCursor;
2829
import org.jongo.marshall.jackson.oid.MongoId;
2930
import org.springframework.beans.factory.annotation.Autowired;
3031
import org.springframework.scheduling.annotation.Scheduled;
@@ -82,22 +83,19 @@ public int getClientCount() {
8283
return userAccountService.findUsersByAuthorities(AUTH_CLIENT).size();
8384
}
8485

85-
public int getCollectionCount() {
86-
return userAccountService.findUsersByAuthorities(AUTH_USER)
87-
.stream()
88-
.mapToInt(userAccount -> userAccount.getCollections().size())
89-
.sum();
86+
public long getCollectionCount() {
87+
return jongo.getCollection(ATTRIBUTE_REPO).count();
9088
}
9189

9290
public long getDocumentCount() {
9391
long sum = 0;
94-
Set<String> collNames = new HashSet<>();
95-
for (UserAccount userAccount :
96-
userAccountService.findUsersByAuthorities(AUTH_USER)) {
97-
collNames.addAll(userAccount.getCollections());
92+
Set<String> collectionNames = new HashSet<>();
93+
MongoCursor<Attributes> cursor = jongo.getCollection(ATTRIBUTE_REPO).find().as(Attributes.class);
94+
for (Attributes attributes : cursor) {
95+
collectionNames.add(attributes.getCollection());
9896
}
9997

100-
for (String name : collNames) {
98+
for (String name : collectionNames) {
10199
sum = sum + jongo.getCollection(name).count();
102100
}
103101
return sum;
66.1 KB
Binary file not shown.
Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
/*
2-
* Copyright 2017 Nitrite author or authors.
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
2+
Flot plugin for automatically redrawing plots when the placeholder
3+
size changes, e.g. on window resizes.
4+
5+
It works by listening for changes on the placeholder div (through the
6+
jQuery resize event plugin) - if the size changes, it will redraw the
7+
plot.
8+
9+
There are no options. If you need to disable the plugin for some
10+
plots, you can just fix the size of their placeholders.
11+
*/
12+
13+
14+
/* Inline dependency:
15+
* jQuery resize event - v1.1 - 3/14/2010
16+
* http://benalman.com/projects/jquery-resize-plugin/
917
*
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.
18+
* Copyright (c) 2010 "Cowboy" Ben Alman
19+
* Dual licensed under the MIT and GPL licenses.
20+
* http://benalman.com/about/license/
1521
*/
22+
(function($,h,c){var a=$([]),e=$.resize=$.extend($.resize,{}),i,k="setTimeout",j="resize",d=j+"-special-event",b="delay",f="throttleWindow";e[b]=250;e[f]=true;$.event.special[j]={setup:function(){if(!e[f]&&this[k]){return false}var l=$(this);a=a.add(l);$.data(this,d,{w:l.width(),h:l.height()});if(a.length===1){g()}},teardown:function(){if(!e[f]&&this[k]){return false}var l=$(this);a=a.not(l);l.removeData(d);if(!a.length){clearTimeout(i)}},add:function(l){if(!e[f]&&this[k]){return false}var n;function m(s,o,p){var q=$(this),r=$.data(this,d);r.w=o!==c?o:q.width();r.h=p!==c?p:q.height();n.apply(this,arguments)}if($.isFunction(l)){n=l;return m}else{n=l.handler;l.handler=m}}};function g(){i=h[k](function(){a.each(function(){var n=$(this),m=n.width(),l=n.height(),o=$.data(this,d);if(m!==o.w||l!==o.h){n.trigger(j,[o.w=m,o.h=l])}});g()},e[b])}})(jQuery,this);
1623

17-
function($,e,t){"$:nomunge";var i=[],n=$.resize=$.extend($.resize,{}),a,r=false,s="setTimeout",u="resize",m=u+"-special-event",o="pendingDelay",l="activeDelay",f="throttleWindow";n[o]=200;n[l]=20;n[f]=true;$.event.special[u]={setup:function(){if(!n[f]&&this[s]){return false}var e=$(this);i.push(this);e.data(m,{w:e.width(),h:e.height()});if(i.length===1){a=t;h()}},teardown:function(){if(!n[f]&&this[s]){return false}var e=$(this);for(var t=i.length-1;t>=0;t--){if(i[t]==this){i.splice(t,1);break}}e.removeData(m);if(!i.length){if(r){cancelAnimationFrame(a)}else{clearTimeout(a)}a=null}},add:function(e){if(!n[f]&&this[s]){return false}var i;function a(e,n,a){var r=$(this),s=r.data(m)||{};s.w=n!==t?n:r.width();s.h=a!==t?a:r.height();i.apply(this,arguments)}if($.isFunction(e)){i=e;return a}else{i=e.handler;e.handler=a}}};function h(t){if(r===true){r=t||1}for(var s=i.length-1;s>=0;s--){var l=$(i[s]);if(l[0]==e||l.is(":visible")){var f=l.width(),c=l.height(),d=l.data(m);if(d&&(f!==d.w||c!==d.h)){l.trigger(u,[d.w=f,d.h=c]);r=t||true}}else{d=l.data(m);d.w=0;d.h=0}}if(a!==null){if(r&&(t==null||t-r<1e3)){a=e.requestAnimationFrame(h)}else{a=setTimeout(h,n[o]);r=false}}}if(!e.requestAnimationFrame){e.requestAnimationFrame=function(){return e.webkitRequestAnimationFrame||e.mozRequestAnimationFrame||e.oRequestAnimationFrame||e.msRequestAnimationFrame||function(t,i){return e.setTimeout(function(){t((new Date).getTime())},n[l])}}()}if(!e.cancelAnimationFrame){e.cancelAnimationFrame=function(){return e.webkitCancelRequestAnimationFrame||e.mozCancelRequestAnimationFrame||e.oCancelRequestAnimationFrame||e.msCancelRequestAnimationFrame||clearTimeout}()}})(jQuery,this);
1824

1925
(function ($) {
2026
var options = { }; // no options
@@ -32,23 +38,23 @@ function($,e,t){"$:nomunge";var i=[],n=$.resize=$.extend($.resize,{}),a,r=false,
3238
plot.setupGrid();
3339
plot.draw();
3440
}
35-
41+
3642
function bindEvents(plot, eventHolder) {
3743
plot.getPlaceholder().resize(onResize);
3844
}
3945

4046
function shutdown(plot, eventHolder) {
4147
plot.getPlaceholder().unbind("resize", onResize);
4248
}
43-
49+
4450
plot.hooks.bindEvents.push(bindEvents);
4551
plot.hooks.shutdown.push(shutdown);
4652
}
47-
53+
4854
$.plot.plugins.push({
4955
init: init,
5056
options: options,
5157
name: 'resize',
5258
version: '1.0'
5359
});
54-
})(jQuery);
60+
})(jQuery);

nitrite-datagate/src/main/resources/templates/adminHome.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ <h4>Versions</h4>
194194
init_flot_chart();
195195
init_chart_doughnut();
196196
init_sidebar();
197+
198+
// make flot responsive
199+
var placeholder = $('#demo-placeholder');
200+
placeholder.resize();
197201
});
198202
</script>
199203
</body>

nitrite-datagate/src/main/resources/templates/layout.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
</th:block>
2727

2828
<th:block th:fragment="styleFragment">
29+
<link rel="shortcut icon"
30+
th:href="@{/assets/img/favicon.ico}"
31+
href="../assets/img/favicon.ico"/>
2932
<!-- Bootstrap -->
3033
<link rel="stylesheet"
3134
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>

nitrite-datagate/src/main/resources/templates/login.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525

2626
<title>Nitrite DataGate | Admin Login</title>
2727

28+
<link rel="shortcut icon"
29+
th:href="@{/assets/img/favicon.ico}"
30+
href="../assets/img/favicon.ico"/>
2831
<!-- Bootstrap -->
2932
<link rel="stylesheet"
3033
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
@@ -48,6 +51,7 @@
4851
<form role="form" action="#" th:action="@{/login}"
4952
method="post">
5053
<h1 class="ubuntu-font">Admin Login</h1>
54+
<p th:if="${loginError}" class="error red">Wrong user or password</p>
5155
<div class="form-group">
5256
<input type="text" name="username"
5357
id="username"

nitrite-datagate/src/main/resources/templates/signUp.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525

2626
<title>Nitrite DataGate | Admin Sign Up</title>
2727

28+
<link rel="shortcut icon"
29+
th:href="@{/assets/img/favicon.ico}"
30+
href="../assets/img/favicon.ico"/>
2831
<!-- Bootstrap -->
2932
<link rel="stylesheet"
3033
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>

0 commit comments

Comments
 (0)