Skip to content

Commit

Permalink
Update API JS side
Browse files Browse the repository at this point in the history
  • Loading branch information
janhybs committed Oct 20, 2018
1 parent d386e57 commit d6f6a65
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 121 deletions.
10 changes: 9 additions & 1 deletion www/js/ci-hpc/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,18 @@ var ConfigureViewFilters = (function () {
text: 'show mean',
name: 'show-mean',
style: 'predefined',
checked: true,
checked: false,
desc: 'If checked, will display basic <strong>mean</strong> ' +
'line chart.'
},
{
text: 'show median',
name: 'show-median',
style: 'predefined',
checked: true,
desc: 'If checked, will display basic <strong>median</strong> ' +
'line chart.'
},
{
text: 'show std',
name: 'show-stdbar',
Expand Down
10 changes: 9 additions & 1 deletion www/js/ci-hpc/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ class ConfigureViewFilters {
text: 'show mean',
name: 'show-mean',
style: 'predefined',
checked: true,
checked: false,
desc: 'If checked, will display basic <strong>mean</strong> ' +
'line chart.'
},
{
text: 'show median',
name: 'show-median',
style: 'predefined',
checked: true,
desc: 'If checked, will display basic <strong>median</strong> ' +
'line chart.'
},
{
text: 'show std',
name: 'show-stdbar',
Expand Down
26 changes: 26 additions & 0 deletions www/js/ci-hpc/globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var Globals = (function () {
function Globals() {
}
Globals.initEnv = function () {
this.env = nunjucks.configure({});
this.env.addFilter('toFixed', function (num, digits) {
return parseFloat(num).toFixed(digits || 2);
});
this.env.addFilter('cut', function (str, digits) {
return str.substring(0, digits || 8);
});
this.env.addFilter('max', function (values) {
return Math.max.apply(Math, values);
});
this.env.addFilter('aslist', function (value) {
var s = '';
value.split('/').forEach(function (element) {
if (element) {
s += '<li>' + element + '</li>';
}
});
return '<ul>' + s + '</ul>';
});
};
return Globals;
}());
40 changes: 40 additions & 0 deletions www/js/ci-hpc/globals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
interface CIHPCSimple {
projectName: string;
flaskApiUrl: string;
}

interface Window {
cihpc: CIHPCSimple;
moment: any;
}

interface ExtraData {
_id: string[];
}


class Globals {
static env: nunjucks.Environment;

static initEnv() {
this.env = nunjucks.configure({});
this.env.addFilter('toFixed', (num, digits) => {
return parseFloat(num).toFixed(digits || 2)
});
this.env.addFilter('cut', (str, digits) => {
return str.substring(0, digits || 8)
});
this.env.addFilter('max', (values) => {
return Math.max.apply(Math, values);
});
this.env.addFilter('aslist', (value: string) => {
var s = ''
value.split('/').forEach((element: string) => {
if (element) {
s += '<li>' + element + '</li>';
}
})
return '<ul>' + s + '</ul>';
});
}
}
67 changes: 17 additions & 50 deletions www/js/ci-hpc/main.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
var Globals = (function () {
function Globals() {
}
Globals.initEnv = function () {
this.env = nunjucks.configure({});
this.env.addFilter('toFixed', function (num, digits) {
return parseFloat(num).toFixed(digits || 2);
});
this.env.addFilter('cut', function (str, digits) {
return str.substring(0, digits || 8);
});
this.env.addFilter('max', function (values) {
return Math.max.apply(Math, values);
});
this.env.addFilter('aslist', function (value) {
var s = '';
value.split('/').forEach(function (element) {
if (element) {
s += '<li>' + element + '</li>';
}
});
return '<ul>' + s + '</ul>';
});
};
return Globals;
}());
$(document).ready(function () {
Globals.initEnv();
Templates.loadTemplates();
Expand All @@ -50,32 +24,25 @@ $(document).ready(function () {
cntrlIsPressed = false;
});
CIHPC.url_base = window.cihpc.flaskApiUrl + '/' + window.cihpc.projectName;
var grabFilter = function (elem) {
var $data = $(elem);
var filters = {};
var data = $data.attr();
for (var key in data) {
if (key.indexOf('data-filter') == 0) {
if (key.substring(12)) {
filters[key.substring(5)] = data[key];
}
else {
if (data['data-level']) {
filters[data['data-level']] = data[key];
}
}
}
}
return filters;
};
var tryToExtractFilters = function (element) {
if ($(element).hasClass('list-group-item')) {
return grabFilter(element);
}
return {};
};
$.ajax({
url: CIHPC.url_base + '/config',
error: function (result) {
$('#configure-view').addClass('disabled');
$('#charts-sm').html(Templates.serverError.render({
title: 'Server error',
shortDesc: 'Cannot connect to the server [500]',
description: '<p>Could not connect to the server, make sure it is running ' +
'and is accesible. The server should be running on this address: ' +
'<code>' + CIHPC.url_base + '</code></p>' +
'<p>This can be changed in <code>index.html</code> file, in ' +
'section:</p><code><pre>' +
'window.cihpc = {\n' +
' projectName: "foobar",\n' +
' flaskApiUrl: "http://foo.bar.com:5000",\n' +
'}\n' +
'</pre></code>'
}));
},
success: function (config) {
CIHPC.init(config);
CIHPC.addFilters(config);
Expand Down
90 changes: 21 additions & 69 deletions www/js/ci-hpc/main.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,13 @@
/// <reference path ="../typings/jquery/jquery.d.ts"/>
/// <reference path ="../typings/nunjucks/nunjucks.d.ts"/>
/// <reference path ="../typings/highcharts/index.d.ts"/>
/// <reference path ="globals.ts"/>
/// <reference path ="filters.ts"/>
/// <reference path ="utils.ts"/>
/// <reference path ="templates.ts"/>
/// <reference path ="cihpc.ts"/>



interface CIHPCSimple {
projectName: string;
flaskApiUrl: string;
}

interface Window {
cihpc: CIHPCSimple;
moment: any;
}

interface ExtraData {
_id: string[];
}

class Globals {
static env: nunjucks.Environment;

static initEnv() {
this.env = nunjucks.configure({});
this.env.addFilter('toFixed', (num, digits) => {
return parseFloat(num).toFixed(digits || 2)
});
this.env.addFilter('cut', (str, digits) => {
return str.substring(0, digits || 8)
});
this.env.addFilter('max', (values) => {
return Math.max.apply(Math, values);
});
this.env.addFilter('aslist', (value: string) => {
var s = ''
value.split('/').forEach((element: string) => {
if (element) {
s += '<li>' + element + '</li>';
}
})
return '<ul>' + s + '</ul>';
});
}
}


$(document).ready(() => {
Globals.initEnv();
Templates.loadTemplates();
Expand Down Expand Up @@ -81,35 +40,28 @@ $(document).ready(() => {

CIHPC.url_base = window.cihpc.flaskApiUrl + '/' + window.cihpc.projectName;

var grabFilter = function(elem: HTMLElement) {
var $data = $(elem);
var filters = {};
var data = (<any>$data).attr();
for (let key in data) {
if (key.indexOf('data-filter') == 0) {
if (key.substring(12)) {
filters[key.substring(5)] = data[key];
} else {
if (data['data-level']) {
filters[data['data-level']] = data[key];
}
}
}
}
return filters;
}


var tryToExtractFilters = function(element: HTMLElement) {
if ($(element).hasClass('list-group-item')) {
return grabFilter(element);
}
return {};
};

$.ajax({
url: CIHPC.url_base + '/config',

error: function (result) {
$('#configure-view').addClass('disabled');
$('#charts-sm').html(
Templates.serverError.render({
title: 'Server error',
shortDesc: 'Cannot connect to the server [500]',
description: '<p>Could not connect to the server, make sure it is running ' +
'and is accesible. The server should be running on this address: ' +
'<code>' + CIHPC.url_base + '</code></p>' +
'<p>This can be changed in <code>index.html</code> file, in ' +
'section:</p><code><pre>' +
'window.cihpc = {\n' +
' projectName: "foobar",\n' +
' flaskApiUrl: "http://foo.bar.com:5000",\n' +
'}\n' +
'</pre></code>'
})
);
// alert(result);
},
success: function(config) {
CIHPC.init(config);
CIHPC.addFilters(config);
Expand Down
30 changes: 30 additions & 0 deletions www/js/ci-hpc/newcfg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
$(document).ready(function () {
Globals.initEnv();
Templates.loadTemplates();
Utils.extendJQuery();
CIHPC.url_base = window.cihpc.flaskApiUrl + '/' + window.cihpc.projectName;
$.ajax({
url: CIHPC.url_base + '/config',
error: function (result) {
$('#configure-view').addClass('disabled');
$('#charts-sm').html(Templates.serverError.render({
title: 'Server error',
shortDesc: 'Cannot connect to the server [500]',
description: '<p>Could not connect to the server, make sure it is running ' +
'and is accesible. The server should be running on this address: ' +
'<code>' + CIHPC.url_base + '</code></p>' +
'<p>This can be changed in <code>index.html</code> file, in ' +
'section:</p><code><pre>' +
'window.cihpc = {\n' +
' projectName: "foobar",\n' +
' flaskApiUrl: "http://foo.bar.com:5000",\n' +
'}\n' +
'</pre></code>'
}));
},
success: function (config) {
console.log(config);
CIHPC.init(config);
}
});
});
48 changes: 48 additions & 0 deletions www/js/ci-hpc/newcfg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/// <reference path ="../typings/jquery/jquery.d.ts"/>
/// <reference path ="../typings/nunjucks/nunjucks.d.ts"/>
/// <reference path ="../typings/highcharts/index.d.ts"/>
/// <reference path ="globals.ts"/>
/// <reference path ="filters.ts"/>
/// <reference path ="utils.ts"/>
/// <reference path ="templates.ts"/>
/// <reference path ="cihpc.ts"/>


$(document).ready(() => {
Globals.initEnv();
Templates.loadTemplates();
Utils.extendJQuery();


CIHPC.url_base = window.cihpc.flaskApiUrl + '/' + window.cihpc.projectName;

$.ajax({
url: CIHPC.url_base + '/config',
error: function (result) {
$('#configure-view').addClass('disabled');
$('#charts-sm').html(
Templates.serverError.render({
title: 'Server error',
shortDesc: 'Cannot connect to the server [500]',
description: '<p>Could not connect to the server, make sure it is running ' +
'and is accesible. The server should be running on this address: ' +
'<code>' + CIHPC.url_base + '</code></p>' +
'<p>This can be changed in <code>index.html</code> file, in ' +
'section:</p><code><pre>' +
'window.cihpc = {\n' +
' projectName: "foobar",\n' +
' flaskApiUrl: "http://foo.bar.com:5000",\n' +
'}\n' +
'</pre></code>'
})
);
// alert(result);
},
success: function(config) {
console.log(config);
CIHPC.init(config);
// CIHPC.addFilters(config);
// CIHPC.addTestList(config);
}
});
});
1 change: 1 addition & 0 deletions www/js/ci-hpc/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var Templates = (function () {
this.barTooltip = Globals.env.getTemplate("templates/mdb/bar-tooltip.njk", compileNow);
this.dateSliders = Globals.env.getTemplate("templates/mdb/date-sliders.njk", compileNow);
this.emptyResults = Globals.env.getTemplate("templates/mdb/empty-results.njk", compileNow);
this.serverError = Globals.env.getTemplate("templates/mdb/server-error.njk", compileNow);
};
return Templates;
}());

0 comments on commit d6f6a65

Please sign in to comment.