Skip to content

Commit

Permalink
Add resolve for DashboardView
Browse files Browse the repository at this point in the history
  • Loading branch information
stasbamiza committed Oct 25, 2016
1 parent d5b310d commit 5589edf
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 11 deletions.
2 changes: 2 additions & 0 deletions modules/admin/src/app/dashboards/dashboard.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {GridPaginationModule} from "../crud/directives/gridPagination/gridPagina
import {DashboardCrudDelete} from "./crud/dashboardBoxDelete";
import {DashboardCrudUpdateResolve} from "./crud/dashboardCrudUpdate.resolve";
import {DashboardCrudCreateResolve} from "./crud/dashboardCrudCreate.resolve";
import {DashboardViewResolve} from "./dashboardView.resolve";

const DASHBOARD_DECLARATION = [
OrderBy,
Expand Down Expand Up @@ -73,6 +74,7 @@ const DASHBOARD_DECLARATION = [
LineChartService,
DashboardCrudUpdateResolve,
DashboardCrudCreateResolve,
DashboardViewResolve
]
})
export class DashboardModule {
Expand Down
17 changes: 15 additions & 2 deletions modules/admin/src/app/dashboards/dashboard.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {DashboardView} from "./dashboardView.component";
import {DashboardCrudDelete} from "./crud/dashboardBoxDelete";
import {CrudLinkset} from "../crud/crudLinkset/crudLinkset.component";
import {Dashboard} from "./dashboard.component";
import {DashboardViewResolve} from "./dashboardView.resolve";

export const DASHBOARD_ROUTER_PROVIDER = [
{
Expand All @@ -20,7 +21,13 @@ export const DASHBOARD_ROUTER_PROVIDER = [
dashboard: 'default'
},
children: [
{ path: '', component: DashboardView },
{
path: '',
component: DashboardView,
resolve: {
data: DashboardViewResolve
}
},
{
path: 'edit/:id',
component: DashboardCrudUpdate,
Expand Down Expand Up @@ -51,7 +58,13 @@ export const DASHBOARD_ROUTER_PROVIDER = [
crudTypeClass: 'DashboardBoxType'
},
children: [
{ path: '', component: DashboardView },
{
path: '',
component: DashboardView,
resolve: {
data: DashboardViewResolve
}
},
{
path: 'edit/:id',
component: DashboardCrudUpdate,
Expand Down
14 changes: 6 additions & 8 deletions modules/admin/src/app/dashboards/dashboardView.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component } from "@angular/core";
import { TranslateService } from "ng2-translate/ng2-translate";
import { Router } from "@angular/router";
import {Router, ActivatedRoute} from "@angular/router";
import { DragulaService } from "ng2-dragula/ng2-dragula";
import { DashboardService } from "./dashboardService";
import { BrowserDomAdapter } from "@angular/platform-browser/src/browser/browser_adapter";
Expand Down Expand Up @@ -34,7 +34,8 @@ export class DashboardView {
private dragulaService: DragulaService,
private dashboardService: DashboardService,
private router: Router,
public crudService: CrudService) {
public crudService: CrudService,
private route: ActivatedRoute) {
dragulaService.setOptions('status-bag', {
direction: 'horizontal',
moves: function (el, container, handle) {
Expand All @@ -51,13 +52,10 @@ export class DashboardView {
this.onDrop(value.slice(1));
});

this.dashboardService.getDashboardBoxes().subscribe((res) => {
this.boxesCss = new DashboardList<string>();
this.boxes = new DashboardListItem<DashboardBox>();
let orderBy: OrderBy = new OrderBy();
this.boxes.merge(orderBy.transform(res, { key: 'order', direction: 'ascending' }));
this.route.data.subscribe((res) => {
this.boxesCss = res['data'].boxesCss;
this.boxes = res['data'].boxes;
this.updateClasses();
console.log(this.boxes);
});
}

Expand Down
34 changes: 34 additions & 0 deletions modules/admin/src/app/dashboards/dashboardView.resolve.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {Injectable} from "@angular/core";
import {Resolve, ActivatedRouteSnapshot} from "@angular/router";
import {Observable, Observer} from "rxjs";
import {DashboardList} from "./models/dashboardList";
import {DashboardBox} from "./models/dashboardBox";
import {DashboardListItem} from "./models/dashboardListItem";
import {OrderBy} from "./sorts/orderby";
import {DashboardService} from "./dashboardService";

@Injectable()
export class DashboardViewResolve implements Resolve<any> {
constructor(private dashboardService: DashboardService) {

}

resolve(route: ActivatedRouteSnapshot): Observable<Object> {
return Observable.create((observer: Observer<Object>) => {
this.dashboardService.getDashboardBoxes().subscribe((res) => {
let boxesCss = new DashboardList<string>();
let boxes = new DashboardListItem<DashboardBox>();
let orderBy: OrderBy = new OrderBy();
boxes.merge(orderBy.transform(res, { key: 'order', direction: 'ascending' }));

let ressult = {
boxesCss: boxesCss,
boxes: boxes
}

observer.next(ressult);
observer.complete();
});
});
}
}
4 changes: 3 additions & 1 deletion modules/core/src/main/resources/db/migration/1472473094.sql
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ if ($Dashboard.size() == 0) {
let serialChartType = INSERT INTO DashboardBoxType SET name = 'Rusia chart profit', type = 'chart', kind = 'Serial chart', code = "return {data: \"let res = []; for (let i = 1; i <= 12; i++) { for (let y = 1; y <= 2; y++) { res.push({ date: new Date(2016, i, y*5), value: Math.ceil(Math.random()*1000), value0: Math.ceil(Math.random()*1000) }); } } res;\"}", codeLanguage = 'JavaScript'
let lineChartType = INSERT INTO DashboardBoxType SET name = 'Ivan chart profit', type = 'chart', kind = 'Line chart', code = "return {data: \"var res = []; for(let 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 }); } res;\"}", codeLanguage = 'JavaScript'
let barChartType = INSERT INTO DashboardBoxType SET name = 'Kolia chart profit', type = 'chart', kind = 'Bar chart', code = "return {data: \"var res = []; 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 len = Math.ceil(Math.random()*50); for(var i = 0; i < len; i++) { res.push({ country: getStr(), visits: Math.ceil(Math.random()*10000) }); } res;\"}", codeLanguage = 'JavaScript'
let barChartType = INSERT INTO DashboardBoxType SET name = 'Masha bubble chartаt', type = 'chart', kind = 'Bubble chart', code = "return {data: \"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) }); } res;\"}", codeLanguage = 'JavaScript'
let bubbleChartType = INSERT INTO DashboardBoxType SET name = 'Masha bubble chartаt', type = 'chart', kind = 'Bubble chart', code = "return {data: \"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) }); } res;\"}", codeLanguage = 'JavaScript'

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

Expand All @@ -73,6 +73,7 @@ if ($Dashboard.size() == 0) {
let serialChartType = select * from DashboardBoxType where name = 'Rusia chart profit'
let lineChartType = select * from DashboardBoxType where name = 'Ivan chart profit'
let barChartType = select * from DashboardBoxType where name = 'Kolia chart profit'
let bubbleChartType = select * from DashboardBoxType where name = 'Masha bubble chartаt'
let defaultDashboard = select * from Dashboard where name = 'default'

CREATE Class DashboardBox
Expand Down Expand Up @@ -104,6 +105,7 @@ if ($Dashboard.size() == 0) {
INSERT INTO DashboardBox SET width = 50, height = 50, order = 6, dashboard = $defaultDashboard['@rid'][0], type = $serialChartType['@rid'][0], name = 'Box 6', description = 'Box 6 desc'
INSERT INTO DashboardBox SET width = 50, height = 50, order = 7, dashboard = $defaultDashboard['@rid'][0], type = $lineChartType['@rid'][0], name = 'Box 7', description = 'Box 7 desc'
INSERT INTO DashboardBox SET width = 50, height = 50, order = 8, dashboard = $defaultDashboard['@rid'][0], type = $barChartType['@rid'][0], name = 'Box 8', description = 'Box 8 desc'
INSERT INTO DashboardBox SET width = 50, height = 50, order = 8, dashboard = $defaultDashboard['@rid'][0], type = $bubbleChartType['@rid'][0], name = 'Box 9', description = 'Box 9 desc'

console.log "Creating process for DashboardBox class is done."
}
Expand Down

0 comments on commit 5589edf

Please sign in to comment.