Skip to content

Commit

Permalink
changes in analytics, admin login error message added
Browse files Browse the repository at this point in the history
  • Loading branch information
anidotnet committed Apr 25, 2017
1 parent b7df2a9 commit fd57139
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package org.dizitart.no2.datagate.controllers;

import org.dizitart.no2.sync.data.UserAccount;
import org.dizitart.no2.datagate.services.UserAccountService;
import org.dizitart.no2.sync.data.UserAccount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
Expand Down Expand Up @@ -58,4 +58,10 @@ public String signUp(@ModelAttribute UserAccount userAccount) {
return "signUp";
}
}

@GetMapping(value = "/loginError")
public String loginError(Model model) {
model.addAttribute("loginError", true);
return "login";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class Statistics {
private int userCount;
private int clientCount;
private int collectionCount;
private long collectionCount;
private long documentCount;
private Long[][] syncGraphData;
private List<Device> deviceList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ protected void configure(HttpSecurity http) throws Exception {
.and()
.formLogin()
.loginPage("/login")
.failureUrl("/loginError")
.defaultSuccessUrl("/admin/")
.permitAll()
.and()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
import org.dizitart.no2.datagate.models.Device;
import org.dizitart.no2.datagate.models.Statistics;
import org.dizitart.no2.datagate.models.SyncLog;
import org.dizitart.no2.sync.data.UserAccount;
import org.dizitart.no2.meta.Attributes;
import org.jongo.Aggregate;
import org.jongo.Jongo;
import org.jongo.MongoCursor;
import org.jongo.marshall.jackson.oid.MongoId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
Expand Down Expand Up @@ -82,22 +83,19 @@ public int getClientCount() {
return userAccountService.findUsersByAuthorities(AUTH_CLIENT).size();
}

public int getCollectionCount() {
return userAccountService.findUsersByAuthorities(AUTH_USER)
.stream()
.mapToInt(userAccount -> userAccount.getCollections().size())
.sum();
public long getCollectionCount() {
return jongo.getCollection(ATTRIBUTE_REPO).count();
}

public long getDocumentCount() {
long sum = 0;
Set<String> collNames = new HashSet<>();
for (UserAccount userAccount :
userAccountService.findUsersByAuthorities(AUTH_USER)) {
collNames.addAll(userAccount.getCollections());
Set<String> collectionNames = new HashSet<>();
MongoCursor<Attributes> cursor = jongo.getCollection(ATTRIBUTE_REPO).find().as(Attributes.class);
for (Attributes attributes : cursor) {
collectionNames.add(attributes.getCollection());
}

for (String name : collNames) {
for (String name : collectionNames) {
sum = sum + jongo.getCollection(name).count();
}
return sum;
Expand Down
Binary file not shown.
40 changes: 23 additions & 17 deletions nitrite-datagate/src/main/resources/assets/js/jquery.flot.resize.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
/*
* Copyright 2017 Nitrite author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
Flot plugin for automatically redrawing plots when the placeholder
size changes, e.g. on window resizes.
It works by listening for changes on the placeholder div (through the
jQuery resize event plugin) - if the size changes, it will redraw the
plot.
There are no options. If you need to disable the plugin for some
plots, you can just fix the size of their placeholders.
*/


/* Inline dependency:
* jQuery resize event - v1.1 - 3/14/2010
* http://benalman.com/projects/jquery-resize-plugin/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(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);

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);

(function ($) {
var options = { }; // no options
Expand All @@ -32,23 +38,23 @@ function($,e,t){"$:nomunge";var i=[],n=$.resize=$.extend($.resize,{}),a,r=false,
plot.setupGrid();
plot.draw();
}

function bindEvents(plot, eventHolder) {
plot.getPlaceholder().resize(onResize);
}

function shutdown(plot, eventHolder) {
plot.getPlaceholder().unbind("resize", onResize);
}

plot.hooks.bindEvents.push(bindEvents);
plot.hooks.shutdown.push(shutdown);
}

$.plot.plugins.push({
init: init,
options: options,
name: 'resize',
version: '1.0'
});
})(jQuery);
})(jQuery);
4 changes: 4 additions & 0 deletions nitrite-datagate/src/main/resources/templates/adminHome.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ <h4>Versions</h4>
init_flot_chart();
init_chart_doughnut();
init_sidebar();

// make flot responsive
var placeholder = $('#demo-placeholder');
placeholder.resize();
});
</script>
</body>
Expand Down
3 changes: 3 additions & 0 deletions nitrite-datagate/src/main/resources/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
</th:block>

<th:block th:fragment="styleFragment">
<link rel="shortcut icon"
th:href="@{/assets/img/favicon.ico}"
href="../assets/img/favicon.ico"/>
<!-- Bootstrap -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
Expand Down
4 changes: 4 additions & 0 deletions nitrite-datagate/src/main/resources/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

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

<link rel="shortcut icon"
th:href="@{/assets/img/favicon.ico}"
href="../assets/img/favicon.ico"/>
<!-- Bootstrap -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
Expand All @@ -48,6 +51,7 @@
<form role="form" action="#" th:action="@{/login}"
method="post">
<h1 class="ubuntu-font">Admin Login</h1>
<p th:if="${loginError}" class="error red">Wrong user or password</p>
<div class="form-group">
<input type="text" name="username"
id="username"
Expand Down
3 changes: 3 additions & 0 deletions nitrite-datagate/src/main/resources/templates/signUp.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

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

<link rel="shortcut icon"
th:href="@{/assets/img/favicon.ico}"
href="../assets/img/favicon.ico"/>
<!-- Bootstrap -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void testTime() {
userAgent.setDevice(devices[random.nextInt(6)]);
userAgent.setAppName("App" + random.nextInt(2));
userAgent.setAppVersion(Integer.toString(random.nextInt(5)));
userAgent.setClientId("Client" + random.nextInt(3));
syncLog.setUserAgent(userAgent);
jongo.getCollection(SYNC_LOG).insert(syncLog);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ public DataGateClient connectTimeout(long milliseconds) {
}

/**
* Sets the {@link UserAgent} details.
* Sets the {@link UserAgent} details. The user agent details
* helps to generate several analytics in DataGate server.
*
* @param userAgent the {@link UserAgent}
* @return the {@link DataGateClient}
Expand Down
13 changes: 12 additions & 1 deletion nitrite/src/main/java/org/dizitart/no2/sync/data/UserAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ public class UserAgent {
* */
private String device;

/**
* The client id
*
* @param clientId the client id
* @return the client id.
* */
private String clientId;

/**
* Parse a user agent string.
*
Expand All @@ -80,6 +88,8 @@ public static UserAgent parse(String userAgentString) {
case 2:
userAgent.setDevice(split[2].trim());
break;
case 3:
userAgent.setClientId(split[3].trim());
default:
break;
}
Expand All @@ -92,6 +102,7 @@ public static UserAgent parse(String userAgentString) {
@Override
public String toString() {
return appName + separator + appVersion
+ separator + device;
+ separator + device
+ separator + clientId;
}
}

0 comments on commit fd57139

Please sign in to comment.