Skip to content

Commit

Permalink
Added developer visualizations
Browse files Browse the repository at this point in the history
  • Loading branch information
gorco committed Sep 14, 2016
1 parent 8bce0e7 commit 3dc0919
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 20 deletions.
24 changes: 12 additions & 12 deletions app/public/js/controllers/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

// Declare app level module which depends on filters, and services
angular.module('myApp', [
'ngRoute', 'signupApp', 'loginApp', 'homeApp', 'classApp', 'gameApp', 'dataApp', 'sessionApp', 'analyticsApp', 'services', 'xeditable', 'env-vars',
'ngFileUpload'
'ngRoute', 'signupApp', 'loginApp', 'homeApp', 'classApp', 'gameApp', 'dataApp', 'sessionApp', 'analyticsApp',
'devVisualizatorApp', 'services', 'xeditable', 'env-vars', 'ngFileUpload'
]).run(function (editableOptions, $localStorage, $cookies) {
editableOptions.theme = 'bs3';
if($localStorage.user) {
if ($localStorage.user) {
$cookies.put('rageUserCookie', $localStorage.user.token, {
path: '/'
});
Expand Down Expand Up @@ -328,7 +328,7 @@ angular.module('myApp', [
var obj = {};
var nameList = '';

if(usr === 'dev'){
if (usr === 'dev') {
listVisualizations = $scope.selectedVisualizationDevList ? $scope.selectedVisualizationDevList : [];
checkboxList = $scope.checkboxVisualizationsDev ? $scope.checkboxVisualizationsDev : {};
nameList = 'visualizationsDev';
Expand Down Expand Up @@ -366,7 +366,7 @@ angular.module('myApp', [
JSON.stringify(data) + ', status: ' + status);
});
} else {
$http.delete(CONSTANTS.PROXY + '/kibana/visualization/list/' + $scope.selectedGame._id + '/'+ usr +'/' + visualizationId)
$http.delete(CONSTANTS.PROXY + '/kibana/visualization/list/' + $scope.selectedGame._id + '/' + usr + '/' + visualizationId)
.success(function(data) {
$scope.selectedVisualizationDevList = data.visualizationsDev;
$scope.selectedVisualizationTchList = data.visualizationsTch;
Expand Down Expand Up @@ -412,8 +412,8 @@ angular.module('myApp', [
$scope.visualizationFields.push(f);
}
});
$http.put(CONSTANTS.PROXY + '/kibana/visualization/list/' + $scope.selectedGame._id, {visualizationsDev: [visualizationData._id]})
.success(function(data) {
$http.put(CONSTANTS.PROXY + '/kibana/visualization/list/' + $scope.selectedGame._id,
{visualizationsDev: [visualizationData._id]}).success(function(data) {
if ($scope.selectedVisualizationDevList.indexOf(visualizationData._id) === -1) {
$scope.selectedVisualizationDevList.push(visualizationData._id);
}
Expand Down Expand Up @@ -677,7 +677,7 @@ angular.module('myApp', [
$http.post(CONSTANTS.PROXY + '/kibana/visualization/session/' + $scope.selectedGame._id + '/' + visualizationId + '/' + $scope.testIndex, {})
.success(function(data) {
panels.push('{\"id\":\"' + visualizationId + '_' + $scope.testIndex + '\",\"type\":\"visualization\",\"panelIndex\":' + numPan + ',' +
'\"size_x\":6,\"size_y\":4,\"col\":'+(1+(numPan-1%2))+',\"row\":' + (numPan+1/2) + '}');
'\"size_x\":6,\"size_y\":4,\"col\":' + (1 + (numPan - 1 % 2)) + ',\"row\":' + (numPan + 1 / 2) + '}');
uiStates['P-' + numPan] = {vis: {legendOpen: false}};
numPan++;

Expand All @@ -692,17 +692,17 @@ angular.module('myApp', [
uiStateJSON: JSON.stringify(uiStates),
version: 1,
timeRestore: true,
timeTo: "now",
timeFrom: "now-1h",
timeTo: 'now',
timeFrom: 'now-1h',
kibanaSavedObjectMeta: {
searchSourceJSON: '{"filter":[{"query":{"query_string":{"query":"*","analyze_wildcard":true}}}]}'
}
};
$http.post(CONSTANTS.PROXY + '/kibana/dashboard/session/' + $scope.testIndex, dashboard)
.success(function(data) {
var url = CONSTANTS.KIBANA + '/app/kibana#/dashboard/dashboard_' +
$scope.testIndex + "?embed=true_g=(refreshInterval:(display:'5%20seconds'," +
"pause:!f,section:1,value:5000),time:(from:now-1h,mode:quick,to:now))";
$scope.testIndex + '?embed=true_g=(refreshInterval:(display:\'5%20seconds\',' +
'pause:!f,section:1,value:5000),time:(from:now-1h,mode:quick,to:now))';
if (url.startsWith('localhost')) {
url = 'http://' + url;
}
Expand Down
10 changes: 5 additions & 5 deletions app/public/js/controllers/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ angular.module('classApp', ['ngStorage', 'services'])
$http.post(CONSTANTS.PROXY + '/games/' + QueryParams.getQueryParam('game') + '/versions/' +
QueryParams.getQueryParam('version') + '/sessions', {name: className}).success(function (session) {

$http.get(CONSTANTS.PROXY + '/kibana/visualization/list/tch' + $scope.gameId)
$http.get(CONSTANTS.PROXY + '/kibana/visualization/list/tch/' + $scope.gameId)
.success(function(data) {

var panels = [];
Expand All @@ -67,8 +67,8 @@ angular.module('classApp', ['ngStorage', 'services'])
{}).success(function(result) {
panels.push('{\"id\":\"' + visualizationId + '_' + session._id +
'\",\"type\":\"visualization\",\"panelIndex\":' + numPan + ',' +
'\"size_x\":6,\"size_y\":4,\"col\":'+(1+(numPan-1%2))+',\"row\":' +
(numPan+1/2) + '}');
'\"size_x\":6,\"size_y\":4,\"col\":' + (1 + (numPan - 1 % 2)) + ',\"row\":' +
(numPan + 1 / 2) + '}');
uiStates['P-' + numPan] = {vis: {legendOpen: false}};
numPan++;

Expand All @@ -82,8 +82,8 @@ angular.module('classApp', ['ngStorage', 'services'])
uiStateJSON: JSON.stringify(uiStates),
version: 1,
timeRestore: true,
timeTo: "now",
timeFrom: "now-1h",
timeTo: 'now',
timeFrom: 'now-1h',
kibanaSavedObjectMeta: {
searchSourceJSON: '{"filter":[{"query":{"query_string":{"query":"*","analyze_wildcard":true}}}]}'
}
Expand Down
105 changes: 105 additions & 0 deletions app/public/js/controllers/devVisualizator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Copyright 2016 e-UCM (http://www.e-ucm.es/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* This project has received funding from the European Union’s Horizon
* 2020 research and innovation programme under grant agreement No 644187.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0 (link is external)
*
* 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.
*/

'use strict';

angular.module('devVisualizatorApp', ['ngStorage', 'services'])
.controller('DevVisualizatorCtrl', ['$scope', '$location', '$http', '$window', '$localStorage', 'Games',
'Versions', 'Role', 'CONSTANTS', '$sce', 'QueryParams',
function ($scope, $location, $http, $window, $localStorage, Games, Versions, Role, CONSTANTS, $sce, QueryParams) {
$scope.$storage = $localStorage;

var versionId = QueryParams.getQueryParam('version');
$scope.gameId = QueryParams.getQueryParam('game');
$scope.showVisualization = function () {
versionId = QueryParams.getQueryParam('version');
$scope.gameId = QueryParams.getQueryParam('game');

$http.get(CONSTANTS.PROXY + '/kibana/visualization/list/dev/' + $scope.gameId)
.success(function(data) {

var panels = [];
var uiStates = {};

// Add index
$http.post(CONSTANTS.PROXY + '/kibana/index/' + $scope.gameId + '/' + versionId, {})
.success(function(data) {

}).error(function (data, status) {
console.error('Error on post /kibana/index/' + $scope.gameId + '/' + versionId + ' ' +
JSON.stringify(data) + ', status: ' + status);
});

// Add dashboard
var numPan = 1;
data.forEach(function (visualizationId) {
$http.post(CONSTANTS.PROXY + '/kibana/visualization/session/' + $scope.gameId + '/' + visualizationId + '/' + versionId,
{}).success(function(result) {
panels.push('{\"id\":\"' + visualizationId + '_' + versionId +
'\",\"type\":\"visualization\",\"panelIndex\":' + numPan + ',' +
'\"size_x\":6,\"size_y\":4,\"col\":' + (1 + (numPan - 1 % 2)) + ',\"row\":' +
(numPan + 1 / 2) + '}');
uiStates['P-' + numPan] = {vis: {legendOpen: false}};
numPan++;

if (numPan > data.length) {
var dashboard = {
title: 'dashboard_' + versionId,
hits: 0,
description: '',
panelsJSON: '[' + panels.toString() + ']',
optionsJSON: '{"darkTheme":false}',
uiStateJSON: JSON.stringify(uiStates),
version: 1,
timeRestore: true,
timeTo: 'now',
timeFrom: 'now-1h',
kibanaSavedObjectMeta: {
searchSourceJSON: '{"filter":[{"query":{"query_string":{"query":"*","analyze_wildcard":true}}}]}'
}
};
$http.post(CONSTANTS.PROXY + '/kibana/dashboard/session/' + versionId, dashboard)
.success(function(data) {
$scope.dashboardLink = getDashboardLink();
}).error(function (data, status) {
console.error('Error on post /kibana/dashboard/session/' + versionId + ' ' +
JSON.stringify(data) + ', status: ' + status);
});
}
}).error(function (data, status) {
console.error('Error on post /kibana/visualization/session/' + visualizationId + '/' + versionId + ' ' +
JSON.stringify(data) + ', status: ' + status);
});
});
}).error(function (data, status) {
console.error('Error on post /kibana/visualization/list/' + $scope.gameId + ' ' +
JSON.stringify(data) + ', status: ' + status);
});
};

var getDashboardLink = function() {
var url = CONSTANTS.KIBANA + '/app/kibana#/dashboard/dashboard_' +
QueryParams.getQueryParam('version') + '?embed=true_g=(refreshInterval:(display:\'5%20seconds\',' +
'pause:!f,section:1,value:5000),time:(from:now-1h,mode:quick,to:now))';
if (url.startsWith('localhost')) {
url = 'http://' + url;
}
return $sce.trustAsResourceUrl(url);
};
}
]);
2 changes: 1 addition & 1 deletion app/public/js/controllers/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ angular.module('loginApp', ['ngStorage', 'ngCookies'])
$http.post(CONSTANTS.APIPATH + '/login', $scope.user).success(function (data) {
$localStorage.$reset();
$scope.$storage.user = data.user;
$cookies.put('rageUserCookie', data.user.token, {path : '/'});
$cookies.put('rageUserCookie', data.user.token, {path: '/'});

$http.get(CONSTANTS.APIPATH + '/users/' + data.user._id + '/roles').success(function (data) {
$scope.$storage.user.roles = data;
Expand Down
4 changes: 2 additions & 2 deletions app/public/js/controllers/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ angular.module('sessionApp', ['myApp', 'ngStorage', 'services'])

$scope.dashboardLink = function() {
var url = CONSTANTS.KIBANA + '/app/kibana#/dashboard/dashboard_' +
QueryParams.getQueryParam('session') + "?embed=true_g=(refreshInterval:(display:'5%20seconds'," +
"pause:!f,section:1,value:5000),time:(from:now-1h,mode:quick,to:now))";
QueryParams.getQueryParam('session') + '?embed=true_g=(refreshInterval:(display:\'5%20seconds\',' +
'pause:!f,section:1,value:5000),time:(from:now-1h,mode:quick,to:now))';
if (url.startsWith('localhost')) {
url = 'http://' + url;
}
Expand Down
2 changes: 2 additions & 0 deletions app/views/data.jade
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,7 @@ block content
include data/config
#analysis.tab-pane
include data/analysis
#dev-visualization.tab-pane
include data/dev-visualization


21 changes: 21 additions & 0 deletions app/views/data/dev-visualization.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//-
Copyright 2016 e-UCM (http://www.e-ucm.es/)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
This project has received funding from the European Union’s Horizon
2020 research and innovation programme under grant agreement No 644187.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 (link is external)
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.
h1(ng-controller='DevVisualizatorCtrl') Developer Visualizations
.row
button.btn.btn-warning.top30(ng-click='showVisualization()') Show visualization
iframe#dashboardIframe.no-border.top10(src = "{{dashboardLink}}" height="800px" width="100%")
6 changes: 6 additions & 0 deletions app/views/data/menu.jade
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,10 @@ ul.nav
span.left-menu-item(href="#analysis", role="tab", data-toggle="tab", ng-click="view = 'analysis'")
span.glyphicon.glyphicon-cog.right20
| Analytics Setup
li(ng-if='isDeveloper()')
span.left-menu-item(href="#dev-visualization", role="tab", data-toggle="tab", ng-click="view = 'dev-visualization'")
span.glyphicon.glyphicon-dashboard.right20
div.in-line Developer
br
| Visualizations

1 change: 1 addition & 0 deletions app/views/layout.jade
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ html
script(src='libs/xapicollection.min.js')
script(src='libs/xapidashboard.min.js')
script(src='js/services.js')
script(src='js/controllers/devVisualizator.js')
script(src='js/controllers/data.js')
script(src='js/controllers/analytics.js')
script(src='js/controllers/session.js')
Expand Down

0 comments on commit 3dc0919

Please sign in to comment.