Skip to content

Commit

Permalink
Merge pull request #92 from e-ucm/nodeupdate
Browse files Browse the repository at this point in the history
New frontend and dependencies updated
  • Loading branch information
Dan Cristian, Rotaru committed Oct 5, 2017
2 parents 01c3a87 + 2520f97 commit 009b3bc
Show file tree
Hide file tree
Showing 62 changed files with 3,054 additions and 2,455 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- "0.12"
- "8.5"

services:
- mongodb
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:4.2.1
FROM node:8.5.0

ENV USER_NAME="user" \
WORK_DIR="/app"
Expand Down
4 changes: 2 additions & 2 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ app.use(function (req, res, next) {
next();
});

app.use('/', require('./viewRoutes'));
app.use('/health', require('./health'));
app.use('/', require('./viewRoutes'));


// Catch 404 and forward to error handler
Expand All @@ -63,7 +63,7 @@ app.use(function (req, res, next) {
// no stacktraces leaked to user
app.use(function (err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
res.render('view/error', {
message: err.message,
error: err
});
Expand Down
34 changes: 31 additions & 3 deletions app/public/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,27 @@ html, body {

.left-menu {
padding-left: 0px;
padding-right: 0px;
height: 100%;
float: none;
display: table-cell;
position: relative;
}

.left-menu ul.nav {
top: 0;
bottom: 0;
position: absolute;
background-color: #f8f8f8;
border-right: 1px solid #e7e7e7;
height: 75vh;
height: 100%;
width: 100%;
}

.left-menu ul.nav span.left-menu-item {
color: #707070;
display: block;
padding: 15px 10px;
padding: 15px 13px 15px 20px;
}

.left-menu ul.nav span.left-menu-item:hover {
Expand All @@ -35,6 +44,18 @@ html, body {
user-select: none;
}

.tabled {
display: table;
padding: 0px;
min-height: 80vh;
width: 100%;
}

.row-tabled {
display: table-row;
width: 100%;
}

.left-menu ul.nav li.active {
font-weight: bold;
}
Expand All @@ -43,6 +64,11 @@ html, body {
color: #606060;
}

.table-cell {
display: table-cell;
float: none;
}

.no-border { border: 0; }

.top5 { margin-top:5px; }
Expand All @@ -59,9 +85,11 @@ html, body {
.right20 { margin-right:20px; }
.right30 { margin-right:30px; }

.left10 { margin-left: 10px; }

.in-line {
display: inline-block;
vertical-align: text-top;
vertical-align: middle;
}

.warning-alert-table {
Expand Down
237 changes: 237 additions & 0 deletions app/public/js/controllers/activity-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
/*
* 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('activitiesApp', ['ngStorage', 'services'])
.controller('ActivityListCtrl', ['$rootScope', '$scope', '$attrs', '$interpolate', '$http', 'Activities', 'Games', 'Versions', 'Classes', 'CONSTANTS',
function ($rootScope, $scope, $attrs, $interpolate, $http, Activities, Games, Versions, Classes, CONSTANTS) {

$scope.activityOpenedError = '';
$scope.activityCreatedError = '';
$scope.activity = {};

var loadByClass = function (classId) {
$scope.classId = classId;
$scope.games = Games.public();
$scope.activities = Activities.forClass({classId: $scope.classId});
};

var loadByGameAndVersion = function (gameId, versionId) {
$scope.gameId = gameId;
$scope.versionId = versionId;
$scope.classes = Classes.my();
$scope.activities = Activities.forGame({gameId: $scope.gameId, versionId: $scope.versionId});
};

var loadAll = function () {
$scope.activities = Activities.my();
$scope.classes = Classes.my();
$scope.games = Games.public();
};

if (!$attrs.classid && !$attrs.gameid && !$attrs.versionid) {
loadAll();
}

$attrs.$observe('classid', function() {
if ($attrs.classid) {
loadByClass($attrs.classid);
}
});

$attrs.$observe('gameid', function() {
if ($attrs.gameid && $attrs.versionid) {
loadByGameAndVersion($attrs.gameid, $attrs.versionid);
}
});

$attrs.$observe('versionid', function() {
if ($attrs.gameid && $attrs.versionid) {
loadByGameAndVersion($attrs.gameid, $attrs.versionid);
}
});

$scope.$on('refreshClasses', function () {
Classes.my().$promise
.then(function(classes) { $scope.classes = classes; })
.then(function() {
Activities.my().$promise.then(function(activities) {
$scope.activities = activities;
});
});
});

$scope.$on('refreshGames', function () {
Games.public().$promise.then(function(games) { $scope.games = games; });
Activities.my().$promise.then(function(activities) { $scope.activities = activities; });
});

$scope.$on('refreshActivities', function () {
Activities.my().$promise.then(function(activities) { $scope.activities = activities; });
});


$scope.createActivity = function () {
var activityName = $scope.activity.name ? $scope.activity.name : 'New activity';
var classId = $scope.classId ? $scope.classId : $scope.activity.classId;
var gameId = $scope.gameId ? $scope.gameId : $scope.activity.gameId;
var versionId = $scope.versionId;
console.log(gameId);

$scope.activityCreatedError = '';
if (!gameId) {
// It's necessary to pick a game
$scope.activityCreatedError = 'Please, select a game.';
return;
}

if (!classId) {
// It's necessary to pick a class
$scope.activityCreatedError = 'Please, select a class.';
return;
}

if (!versionId) {
Versions.forGame({gameId: gameId}).$promise.then(function(versions) {
if (versions && versions.length > 0 && versions[0]._id) {
doCreateActivity(activityName, gameId, versions[0]._id, classId);
} else {
console.log('No version for the selected gameId');
}
});
} else {
doCreateActivity(activityName, gameId, versionId, classId);
}

};

var doCreateActivity = function(activityName, gameId, versionId, classId) {
var activity = new Activities();
activity.name = activityName;
activity.gameId = gameId;
activity.versionId = versionId;
activity.classId = classId;
activity.$save().then(function() {
$http.get(CONSTANTS.PROXY + '/kibana/visualization/list/tch/' + gameId)
.success(function (data) {
var panels = [];
var uiStates = {};

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

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

// Add dashboard
var numPan = 1;
if (data.length > 0) {
data.forEach(function (visualizationId) {
$http.post(CONSTANTS.PROXY + '/kibana/visualization/activity/' + gameId +
'/' + visualizationId + '/' + activity._id, {}).success(function (result) {
panels.push('{\"id\":\"' + visualizationId + '_' + activity._id +
'\",\"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_' + activity._id,
hits: 0,
description: '',
panelsJSON: '[' + panels.toString() + ']',
optionsJSON: '{"darkTheme":false}',
uiStateJSON: JSON.stringify(uiStates),
version: 1,
timeRestore: true,
timeTo: 'now',
timeFrom: 'now-1h',
refreshInterval: {
display: '5 seconds',
pause: false,
section: 1,
value: 5000
},
kibanaSavedObjectMeta: {
searchSourceJSON: '{"filter":[{"query":{"query_string":{"query":"*","analyze_wildcard":true}}}]}'
}
};
$http.post(CONSTANTS.PROXY + '/kibana/dashboard/activity/' + activity._id, dashboard)
.success(function (data) {
$scope.goToActivity(activity);
$rootScope.$broadcast('refreshActivities');
}).error(function (data, status) {
console.error('Error on post /kibana/dashboard/activity/' + activity._id + ' ' +
JSON.stringify(data) + ', status: ' + status);
});
}
}).error(function (data, status) {
console.error('Error on post /kibana/visualization/activity/' + visualizationId + '/' + activity._id + ' ' +
JSON.stringify(data) + ', status: ' + status);
});
});
} else {
$scope.goToActivity(activity);
$rootScope.$broadcast('refreshActivities');
}
}).error(function (data, status) {
console.error('Error on post /kibana/visualization/list/' + gameId + ' ' +
JSON.stringify(data) + ', status: ' + status);
});
});
};

$scope.deleteActivity = function (activityObj) {
if (activityObj) {
activityObj.$remove().then(function() {
$rootScope.$broadcast('refreshActivities');
});
}
};

$scope.getClassById = function(_id) {
var r = null;
if ($scope.classes) {
$scope.classes.forEach(function (c) {
if (c._id === _id) {
r = c;
}
});
}
return r;
};

$scope.getGameById = function(_id) {
var r = null;
if ($scope.games) {
$scope.games.forEach(function (g) {
if (g._id === _id) {
r = g;
}
});
}
return r;
};
}
]);
Loading

0 comments on commit 009b3bc

Please sign in to comment.