Skip to content

Commit

Permalink
Remove hooks from migration, remove "getJsonDataFromDB" from dashboar…
Browse files Browse the repository at this point in the history
…d service,add generate function to chart service
  • Loading branch information
stasbamiza committed Nov 3, 2016
1 parent 2aa8734 commit 7cfa92b
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 52 deletions.
28 changes: 14 additions & 14 deletions modules/admin/src/app/dashboards/chart/lineChart.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class LineChart {
ngOnInit() {
this.chartData = this._lineChartService.getData(this.chartType, []);

let showAll = this.showAllBtnList.find((element) => {
let showAll = this.showAllBtnList['find']((element) => {
if (this.chartType === element) {
return true;
} else {
Expand All @@ -44,23 +44,23 @@ export class LineChart {
};

initChart(chart: any) {
this.dashboardService.executeDbFunction(this.dashboardTypeRid).subscribe((res) => {
this.chart = chart;
this.chart = chart;

let zoomChart = () => {
// chart.zoomToDates(new Date(2013, 3), new Date(2014, 0));
};
let zoomChart = () => {
// chart.zoomToDates(new Date(2013, 3), new Date(2014, 0));
};

chart.addListener('rendered', zoomChart);
zoomChart();
chart.addListener('rendered', zoomChart);
zoomChart();

if (chart.zoomChart) {
chart.zoomChart();
}
if (chart.zoomChart) {
chart.zoomChart();
}

this.chart.dataProvider = res;
this.chart.validateData();
});
/*
// Update data after load data from DB
this.chart.dataProvider = res;
this.chart.validateData();*/
}

public showAll() {
Expand Down
72 changes: 67 additions & 5 deletions modules/admin/src/app/dashboards/chart/lineChart.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ export class LineChartService {
}

getSerial(data: Object) {
var res = [];

for (var i = 1; i <= 12; i++) {
for (var y = 1; y <= 2; y++) {
var date = new Date(2016, i, y*5);
var day = date.getDate(); var monthIndex = date.getMonth();
var year = date.getFullYear();
res.push({
date: (monthIndex + " " + year),
value: Math.ceil(Math.random()*1000),
value0: Math.ceil(Math.random()*1000) });
}
}

let layoutColors = this._baConfig.get().colors;
let graphColor = this._baConfig.get().colors.custom.dashboardLineChart;

Expand All @@ -39,7 +53,7 @@ export class LineChartService {
responsive: {
'enabled': true
},
dataProvider: data,
dataProvider: res,
categoryField: 'date',
categoryAxis: {
parseDates: true,
Expand Down Expand Up @@ -111,10 +125,27 @@ export class LineChartService {
}

getPie(data: Object) {
function getStr() {
var text = "";
var possible = "abcdefghijklmnopqrstuvwxyz";

for( var i=0; i < 5; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length)); return text;
}

var res = [];
var len = Math.ceil(Math.random()*15);

for(var i = 0; i < len; i++) {
res.push({
country: getStr(),
litres: Math.ceil(Math.random()*100) });
}

return {
"type": "pie",
"theme": "light",
"dataProvider": data,
"dataProvider": res,
"valueField": "litres",
"titleField": "country",
"balloon":{
Expand All @@ -127,12 +158,23 @@ export class LineChartService {
}

getLine(data: Object) {
var res = [];

for(var i = 1900; i < 2016; i++) {
var single = Math.random()*10;
single = single > 5 ? 1 : -1;
res.push({
year: String(i),
value: Math.ceil(Math.random()*100)*single
});
}

return {
"type": "serial",
"theme": "light",
"marginTop":0,
"marginRight": 80,
"dataProvider": data,
"dataProvider": res,
"valueAxes": [{
"axisAlpha": 0,
"position": "left"
Expand Down Expand Up @@ -188,10 +230,30 @@ export class LineChartService {
}

getBar(data: Object) {
function getStr() {
var text = "";
var possible = "abcdefghijklmnopqrstuvwxyz";

for( var i=0; i < 5; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));

return text;
}

var res = [];
var len = Math.ceil(Math.random()*50);

for(var i = 0; i < len; i++) {
res.push({
country: getStr(),
visits: Math.ceil(Math.random()*10000)
});
}

return {
"type": "serial",
"theme": "light",
"dataProvider": data,
"dataProvider": res,
"gridAboveGraphs": true,
"startDuration": 1,
"graphs": [ {
Expand Down Expand Up @@ -243,7 +305,7 @@ export class LineChartService {
"balloon":{
"fixedPosition":true,
},
"dataProvider": data,
"dataProvider": res,
"valueAxes": [ {
"position": "bottom",
"axisAlpha": 0
Expand Down
23 changes: 0 additions & 23 deletions modules/admin/src/app/dashboards/dashboard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,29 +212,6 @@ export class DashboardService {
});
}

public executeDbFunction(rid): Observable<Object> {
let functionName = rid.replace(/#/g, '');
functionName = functionName.replace(/:/g, '_');
functionName = 'DashboardBoxTypeFunction_' + functionName;
let url: string = this.configService.config.orientDBUrl + '/function/smsc/' + functionName;

return Observable.create((observer: Observer<Object>) => {
this.authHttp.request(url)
.subscribe((res) => {
let result = JSON.parse(res['_body']);

if (result.result.length == 0) {
result = [];
} else {
result = result.result[0].value;
}

observer.next(result);
observer.complete();
});
});
}

// Temporary
/**
* Get Dashboard for DashboardBox for navigate to form without "Dashboard" field
Expand Down
10 changes: 0 additions & 10 deletions modules/core/src/main/resources/db/migration/1472473094.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ if ($Dashboard.size() == 0) {
let bubbleChartType = INSERT INTO DashboardBoxType SET name = 'Masha bubble chartаt', type = 'chart', kind = 'Bubble chart', code = 'var res = []; for(var i = 0; i < Math.ceil(Math.random()*30); i++) { res.push({ y: Math.ceil(Math.random()*50), x: Math.ceil(Math.random()*50), value: Math.ceil(Math.random()*50), y2: Math.ceil(Math.random()*50), x2: Math.ceil(Math.random()*50), value2: Math.ceil(Math.random()*50) }); } return res;', codeLanguage = 'JavaScript'

console.log "Creating process for DashboardBoxType class is done."

console.log "Create functions"

CREATE FUNCTION DashboardBoxTypeFunction "var boxTypeRid = doc.field('@rid'); boxTypeRid = String(boxTypeRid); var functionName = boxTypeRid.replace(/#/g, ''); functionName = functionName.replace(/:/g, '_'); functionName = 'DashboardBoxTypeFunction_' + functionName; db.executeCommand('DELETE FROM OFunction WHERE name = \"'+ functionName +'\"'); code = doc.field('code'); if (code != '') { code = code.replace(/'/g, \"\\'\"); code = code.replace(/\"/g, '\\\\\"'); db.executeCommand('CREATE FUNCTION '+ functionName +' \"'+ code +'\" IDEMPOTENT true LANGUAGE JavaScript'); print('Update'); }" LANGUAGE Javascript
CREATE FUNCTION DashboardBoxTypeDeleteFunction "var boxTypeRid = doc.field('@rid'); boxTypeRid = String(boxTypeRid); var functionName = boxTypeRid.replace(/#/g, ''); functionName = functionName.replace(/:/g, '_'); functionName = 'DashboardBoxTypeFunction_' + functionName; db.executeCommand('DELETE FROM OFunction WHERE name = \"'+ functionName +'\"');" LANGUAGE Javascript

ALTER CLASS DashboardBoxType CUSTOM onAfterUpdate = DashboardBoxTypeFunction;
ALTER CLASS DashboardBoxType CUSTOM onAfterDelete=DashboardBoxTypeDeleteFunction

console.log "End create functions"
}

let DashboardBox = SELECT FROM (SELECT expand(classes) FROM metadata:schema) WHERE name = 'DashboardBox';
Expand Down

0 comments on commit 7cfa92b

Please sign in to comment.