Skip to content

Commit

Permalink
Merge branch 'connectionProp'
Browse files Browse the repository at this point in the history
  • Loading branch information
jortilles committed May 6, 2024
2 parents f319720 + 55e01b6 commit 150f51d
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 39 deletions.
40 changes: 22 additions & 18 deletions eda/eda_api/lib/module/dashboard/dashboard.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,11 @@ export class DashboardController {
static async execQuery(req: Request, res: Response, next: NextFunction) {

try {
const connection = await ManagerConnectionService.getConnection(req.body.model_id);
let connectionProps: any;
if (req.body.dashboard.connectionProperties) connectionProps = req.body.dashboard.connectionProperties;

const connection = await ManagerConnectionService.getConnection(req.body.model_id, connectionProps);

const dataModel = await connection.getDataSource(req.body.model_id, req.qs.properties)
/**--------------------------------------------------------------------------------------------------------- */
/**Security check */
Expand Down Expand Up @@ -1004,9 +1008,10 @@ export class DashboardController {
*/
static async execSqlQuery(req: Request, res: Response, next: NextFunction) {
try {
const connection = await ManagerConnectionService.getConnection(
req.body.model_id
)
let connectionProps: any;
if (req.body.dashboard.connectionProperties) connectionProps = req.body.dashboard.connectionProperties;

const connection = await ManagerConnectionService.getConnection(req.body.model_id, connectionProps);
const dataModel = await connection.getDataSource(req.body.model_id)

/**Security check */
Expand Down Expand Up @@ -1255,9 +1260,10 @@ export class DashboardController {
*/
static async getQuery(req: Request, res: Response, next: NextFunction) {
try {
const connection = await ManagerConnectionService.getConnection(
req.body.model_id
)
let connectionProps: any;
if (req.body.dashboard.connectionProperties) connectionProps = req.body.dashboard.connectionProperties;

const connection = await ManagerConnectionService.getConnection(req.body.model_id, connectionProps);
const dataModel = await connection.getDataSource(req.body.model_id)
const dataModelObject = JSON.parse(JSON.stringify(dataModel))
const query = await connection.getQueryBuilded(
Expand All @@ -1274,9 +1280,10 @@ export class DashboardController {

static async execView(req: Request, res: Response, next: NextFunction) {
try {
const connection = await ManagerConnectionService.getConnection(
req.body.model_id
)
let connectionProps: any;
if (req.body.dashboard.connectionProperties) connectionProps = req.body.dashboard.connectionProperties;

const connection = await ManagerConnectionService.getConnection(req.body.model_id, connectionProps);
const query = req.body.query
connection.client = await connection.getclient()
const getResults = await connection.execQuery(query)
Expand Down Expand Up @@ -1356,14 +1363,11 @@ export class DashboardController {
}
}

static async cleanDashboardCache(
req: Request,
res: Response,
next: NextFunction
) {
const connection = await ManagerConnectionService.getConnection(
req.body.model_id
)
static async cleanDashboardCache(req: Request, res: Response, next: NextFunction) {
let connectionProps: any;
if (req.body.dashboard.connectionProperties) connectionProps = req.body.dashboard.connectionProperties;

const connection = await ManagerConnectionService.getConnection(req.body.model_id, connectionProps);
const dataModel = await connection.getDataSource(req.body.model_id)

if (dataModel.ds.metadata.cache_config.enabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ export const

export class ManagerConnectionService {

static async getConnection(id: string): Promise<AbstractConnection> {
static async getConnection(id: string, properties?: any): Promise<AbstractConnection> {
const datasource = await this.getDataSource(id);
const config = datasource.ds.connection;
config.password = EnCrypterService.decode(config.password || ' ');

if (properties) {
for (const prop in properties) {
config[prop] = properties[prop];
}
}

switch (config.type) {
case MS_CONNECTION:
// return new MsConnection(config, secondary);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ export class ColumnDialogComponent extends EdaDialogAbstract {
dataSource: this.controller.params.inject.dataSource._id,
dashboard: this.controller.params.inject.dashboard_id,
panel: this.controller.params.panel._id,
connectionProperties: this.controller.params.connectionProperties,
forSelector: true,
filters: []
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { QueryUtils } from './panel-utils/query-utils';
import { EbpUtils } from './panel-utils/ebp-utils';
import { ChartsConfigUtils } from './panel-utils/charts-config-utils';
import { PanelInteractionUtils } from './panel-utils/panel-interaction-utils'
import { ActivatedRoute } from '@angular/router';

export interface IPanelAction {
code: string;
Expand Down Expand Up @@ -167,8 +168,11 @@ export class EdaBlankPanelComponent implements OnInit {

/**panel chart component configuration */
public panelChartConfig: PanelChart = new PanelChart();

public connectionProperties: any;

constructor(
private route: ActivatedRoute,
public queryBuilder: QueryBuilderService,
public fileUtiles: FileUtiles,
private formBuilder: UntypedFormBuilder,
Expand All @@ -182,6 +186,15 @@ export class EdaBlankPanelComponent implements OnInit {
this.initializeBlankPanelUtils();
this.initializeInputs();

this.route.queryParams.subscribe(params => {
try {
if (params['cnproperties']) {
this.connectionProperties = JSON.parse(decodeURIComponent(params['cnproperties']));
}
} catch (err) {
console.error('queryParams: '+ err)
}
});
}

ngOnInit(): void {
Expand Down Expand Up @@ -628,7 +641,8 @@ export class EdaBlankPanelComponent implements OnInit {
inject: this.inject,
panel: this.panel,
table: this.findTable(column.table_id),
filters: this.selectedFilters
filters: this.selectedFilters,
connectionProperties: this.connectionProperties
};

if (!isFilter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export class FilterDialogComponent extends EdaDialogAbstract {
dataSource: this.controller.params.inject.dataSource._id,
dashboard: this.controller.params.inject.dashboard_id,
panel: this.controller.params.panel._id,
connectionProperties: this.controller.params.connectionProperties,
filters: [],
forSelector: true
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export const QueryUtils = {
*
*/
switchAndRun: async (ebp: EdaBlankPanelComponent, query: Query) => {
if (ebp.connectionProperties) {
query.dashboard.connectionProperties = ebp.connectionProperties;
}

if (!ebp.modeSQL) {
const response = await ebp.dashboardService.executeQuery(query).toPromise();
return response;
Expand Down Expand Up @@ -223,7 +227,8 @@ export const QueryUtils = {
filters: ebp.mergeFilters(ebp.selectedFilters, ebp.globalFilters),
config: config.getConfig(),
queryLimit: ebp.queryLimit,
joinType: ebp.joinType
joinType: ebp.joinType,
connectionProperties: ebp.connectionProperties
};
return ebp.queryBuilder.normalQuery(ebp.currentQuery, params);
},
Expand All @@ -240,7 +245,8 @@ export const QueryUtils = {
panel: ebp.panel.id,
dashboard: ebp.inject.dashboard_id,
filters: ebp.mergeFilters(ebp.selectedFilters, ebp.globalFilters),
config: config.getConfig()
config: config.getConfig(),
connectionProperties: ebp.connectionProperties
};
return ebp.queryBuilder.normalQuery(ebp.currentQuery, params, true, ebp.currentSQLQuery);

Expand Down
32 changes: 21 additions & 11 deletions eda/eda_app/src/app/module/pages/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy {
public datasourceName: string;
public group: string = '';
public onlyIcanEdit: boolean = false;

public connectionProperties: any;
public queryParams: any = {};

public filterButtonVisibility = {
public : false,
readOnly : false
Expand Down Expand Up @@ -529,19 +532,24 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy {

private getUrlParams(): void {
this.route.queryParams.subscribe(params => {
this.queryParams = params;
try{
if(params['hideWheel'] == 'true'){
this.display_v.hideWheel =true;
}
if(params['panelMode'] == 'true'){
this.display_v.panelMode =true;
this.display_v.hideWheel =true;
}
}catch(e){
}
try {
this.queryParams = params;

if(params['hideWheel'] == 'true'){
this.display_v.hideWheel =true;
}
if(params['panelMode'] == 'true'){
this.display_v.panelMode =true;
this.display_v.hideWheel =true;
}

if (params['cnproperties']) {
this.connectionProperties = JSON.parse(decodeURIComponent(params['cnproperties']));
}

} catch(e){
console.error('getUrlParams: '+ e);
}
});
}

Expand Down Expand Up @@ -748,6 +756,7 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy {
panels: this.panels,
dataSource: this.dataSource,
filtersList: this.filtersList,
connectionProperties: this.connectionProperties,
filter,
isnew
},
Expand Down Expand Up @@ -977,6 +986,7 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy {
const queryParams = {
table: targetTable,
dataSource: this.dataSource._id,
connectionProperties: this.connectionProperties,
dashboard: '',
panel: '',
filters: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ export class DashboardFilterDialogComponent extends EdaDialogAbstract {
table: this.targetTable.value,
dataSource: this.params.dataSource._id,
dashboard: this.params.id,
connectionProperties: this.params.connectionProperties,
forSelector: true,
panel: '',
filters: []
Expand Down
9 changes: 6 additions & 3 deletions eda/eda_app/src/app/services/utils/query-builder.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export interface QueryParams {
config?: any;
queryLimit? : number;
joinType?:string;
forSelector?: boolean
forSelector?: boolean;
connectionProperties?: any;
}

@Injectable()
Expand Down Expand Up @@ -54,6 +55,7 @@ export class QueryBuilderService extends ApiService {
dashboard: {
dashboard_id: params.dashboard,
panel_id: params.panel,
connectionProperties: params.connectionProperties
},
query: {
fields: queryColumns,
Expand All @@ -62,7 +64,7 @@ export class QueryBuilderService extends ApiService {
modeSQL : false,
SQLexpression : null,
queryLimit : null,
joinType: 'left' //puede que necesite el joinType
joinType: 'left', //puede que necesite el joinType
},
output: {
labels,
Expand Down Expand Up @@ -111,7 +113,8 @@ export class QueryBuilderService extends ApiService {
},
dashboard: {
dashboard_id: params.dashboard,
panel_id: params.panel
panel_id: params.panel,
connectionProperties: params.connectionProperties
},
query: {
fields: queryColumns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export interface Query {
};
dashboard: {
dashboard_id: string,
panel_id: string
panel_id: string,
connectionProperties: any
};
query: {
fields: Column[]
Expand All @@ -19,8 +20,7 @@ export interface Query {
SQLexpression : string,
queryLimit : number,
joinType: string,
forSelector?: boolean ;

forSelector?: boolean
};
output: {
labels: any[],
Expand Down

0 comments on commit 150f51d

Please sign in to comment.