Skip to content

Commit

Permalink
Merge remote-tracking branch 'SinergiaDA/reporting'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.gitignore
#	eda/eda_api/lib/module/dashboard/dashboard.controller.ts
#	eda/eda_app/src/app/module/components/eda-panels/eda-blank-panel/panel-utils/query-utils.ts
#	eda/eda_app/src/app/module/components/eda-table/eda-table.component.html
#	eda/eda_app/src/locale/messages.ca.xlf
#	eda/eda_app/src/locale/messages.en.xlf

1. Afegit filtres numerics.
2. Afegit control sobre no data.
3. Revisión de la ordenació per defecte
4. Anadido display
  • Loading branch information
jortilles committed Dec 3, 2023
2 parents 0ff2a10 + 47ba662 commit 34e6bd2
Show file tree
Hide file tree
Showing 16 changed files with 151 additions and 96 deletions.
45 changes: 22 additions & 23 deletions eda/eda_api/lib/module/datasource/datasource.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import ConnectionModel from './model/connection.model';
import { EnCrypterService } from '../../services/encrypter/encrypter.service';
import BigQueryConfig from './model/BigQueryConfig.model';
import CachedQuery, { ICachedQuery } from '../../services/cache-service/cached-query.model';
import { QueryOptions } from 'mongoose';
import { Mongoose, QueryOptions } from 'mongoose';
import { upperCase } from 'lodash';
import Group from '../../module/admin/groups/model/group.model';
import { json } from 'body-parser';
const cache_config = require('../../../config/cache.config');

export class DataSourceController {
Expand Down Expand Up @@ -41,7 +42,6 @@ export class DataSourceController {
if (err) {
return next(new HttpException(404, 'Datasouce not found'));
}

// ocultem el password
dataSource.ds.connection.password = EnCrypterService.decode(dataSource.ds.connection.password);
dataSource.ds.connection.password = '__-(··)-__';
Expand All @@ -54,7 +54,7 @@ export class DataSourceController {
}
}

/** AQUSTA FUNCIÓ RETORNA TOTS ELS DATASOURCES */
/** aQUSTA FUNCIÓ RETORNA TOTS ELS DATASOURCES */
static async GetDataSourcesNames(req: Request, res: Response, next: NextFunction) {
let options:QueryOptions = {};
DataSource.find({}, '_id ds.metadata.model_name ds.security', options, (err, ds) => {
Expand Down Expand Up @@ -169,7 +169,7 @@ export class DataSourceController {
return next(new HttpException(500, 'Error loading DataSources'));
}
const names = JSON.parse(JSON.stringify(ds));

for (let i = 0, n = names.length; i < n; i += 1) {
const e = names[i];
// Si tenim propietari....
Expand Down Expand Up @@ -319,10 +319,10 @@ export class DataSourceController {
} else {

try {
const cn = req.qs.type !== 'bigquery' ?
new ConnectionModel(req.qs.user, req.qs.host, req.qs.database, req.qs.password, req.qs.port,
req.qs.type, req.qs.schema, req.body.poolLimit, req.qs.sid, req.qs.warehouse
) : new BigQueryConfig(req.qs.type, req.qs.database, req.qs.project_id);
const cn = req.qs.type !== 'bigquery' ? new ConnectionModel(req.qs.user, req.qs.host, req.qs.database,
req.qs.password, req.qs.port, req.qs.type,
req.body.poolLimit, req.qs.schema, req.qs.sid, req.qs.warehouse)
: new BigQueryConfig(req.qs.type, req.qs.database, req.qs.project_id);

const manager = await ManagerConnectionService.testConnection(cn);
await manager.tryConnection();
Expand All @@ -343,10 +343,8 @@ export class DataSourceController {
const actualDS = await DataSourceController.getMongoDataSource(req.params.id);
const passwd = req.qs.password === '__-(··)-__' ? EnCrypterService.decode(actualDS.ds.connection.password) : req.qs.password;

const cn = new ConnectionModel(
req.qs.user, req.qs.host, req.qs.database, passwd, req.qs.port,
req.qs.type, req.qs.schema, req.body.poolLimit, req.qs.sidm, req.qs.warehouse
);
const cn = new ConnectionModel(req.qs.user, req.qs.host, req.qs.database, passwd,
req.qs.port, req.qs.type, req.qs.schema, req.body.poolLimit, req.qs.sidm, req.qs.warehouse);
const manager = await ManagerConnectionService.testConnection(cn);
await manager.tryConnection();
return res.status(200).json({ ok: true });
Expand Down Expand Up @@ -422,15 +420,13 @@ export class DataSourceController {

static async GenerateDataModelSql(req: Request, res: Response, next: NextFunction) {
try {
const cn = new ConnectionModel(
req.body.user, req.body.host, req.body.database, req.body.password, req.body.port,
req.body.type, req.body.schema, req.body.poolLimit, req.body.sid, req.qs.warehouse
);
const cn = new ConnectionModel(req.body.user, req.body.host, req.body.database,
req.body.password, req.body.port, req.body.type, req.body.schema, req.body.poolLimit, req.body.sid, req.qs.warehouse);
const manager = await ManagerConnectionService.testConnection(cn);
const tables = await manager.generateDataModel(req.body.optimize, req.body.filter, req.body.name);
const CC = req.body.allowCache === 1 ? cache_config.DEFAULT_CACHE_CONFIG : cache_config.DEFAULT_NO_CACHE_CONFIG;


const datasource: IDataSource = new DataSource({
ds: {
connection: {
Expand Down Expand Up @@ -459,18 +455,23 @@ export class DataSourceController {
tables: tables
}
}
});

});

datasource.save((err, data_source) => {

if (err) {


console.log(err);
return next(new HttpException(500, `Error saving the datasource`));
}

return res.status(201).json({ ok: true, data_source_id: data_source._id });
});
});

} catch (err) {

next(err);
}
}
Expand All @@ -495,10 +496,8 @@ export class DataSourceController {
const actualDS = await DataSourceController.getMongoDataSource(req.params.id);
const passwd = req.body.password === '__-(··)-__' ? EnCrypterService.decode(actualDS.ds.connection.password) : req.body.password

const cn = new ConnectionModel(
req.body.user, req.body.host, req.body.database, passwd, req.body.port,
req.body.type, req.body.schema, req.body.poolLimit, req.body.sid, req.qs.warehouse
);
const cn = new ConnectionModel(req.body.user, req.body.host, req.body.database, passwd,
req.body.port, req.body.type, req.body.schema, req.body.poolLimit, req.body.sid, req.qs.warehouse);
const manager = await ManagerConnectionService.testConnection(cn);
const storedDataModel = JSON.parse(JSON.stringify(actualDS));
let tables = [];
Expand Down
2 changes: 1 addition & 1 deletion eda/eda_api/lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ app.use(function(err: IError, req, res, next) {
});

app.listen(PORT, () => {
console.log('\n\x1b[34m=====\x1b[0m Server start on port \x1b[32m[8666] \x1b[0m \x1b[34m=====\x1b[0m\n');
console.log('\n\x1b[34m=====\x1b[0m Server start on port \x1b[32m['+PORT+'] \x1b[0m \x1b[34m=====\x1b[0m\n');
});

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ export class MySqlBuilderService extends QueryBuilderService {
return tables;
}

public normalQuery(columns: string[], origin: string, dest: any[], joinTree: any[], grouping: any[], tables: Array<any>, limit: number, joinType: string, valueListJoins: Array<any>): any {
public normalQuery(columns: string[], origin: string, dest: any[], joinTree: any[], grouping: any[], tables: Array<any>, limit: number, joinType: string, valueListJoins: Array<any>, schema:any, database:any, forSelector: any): any {

let o = tables.filter(table => table.name === origin).map(table => { return table.query ? table.query : table.name })[0];
let myQuery = `SELECT ${columns.join(', ')} \nFROM ${o}`;

if (forSelector === true) {
myQuery = `SELECT DISTINCT ${columns.join(', ')} \nFROM ${o}`;
}

//to WHERE CLAUSE
const filters = this.queryTODO.filters.filter(f => {
const column = this.findColumn(f.filter_table, f.filter_column);
Expand Down Expand Up @@ -72,6 +76,8 @@ export class MySqlBuilderService extends QueryBuilderService {
const order_columns_string = orderColumns.join(',');
if (order_columns_string.length > 0) {
myQuery = `${myQuery}\norder by ${order_columns_string}`;
} else if (forSelector === true) {
myQuery = `${myQuery}\norder by 1`;
}

if (limit) myQuery += `\nlimit ${limit}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export abstract class QueryBuilderService {
this.usercode = user.email;
this.groups = user.role;
this.tables = dataModel.ds.model.tables;

}

abstract getFilters(filters, type: string);
Expand All @@ -41,7 +40,7 @@ export abstract class QueryBuilderService {
abstract processFilter(filter: any, columnType: string);
abstract normalQuery(columns: string[], origin: string, dest: any[], joinTree: any[],
grouping: any[], tables: Array<any>, limit: number,
joinType: string,valueListJoins:any[], Schema?: string, database?: string);
joinType: string,valueListJoins:any[], Schema?: string, database?: string, forSelector?: any );
abstract sqlQuery(query: string, filters: any[], filterMarks: string[]): string;
abstract buildPermissionJoin(origin: string, join: string[], permissions: any[], schema?: string);
abstract parseSchema(tables: string[], schema?: string, database?: string);
Expand Down Expand Up @@ -185,7 +184,7 @@ export abstract class QueryBuilderService {
let tables = this.dataModel.ds.model.tables
.map(table => { return { name: table.table_name, query: table.query } });
this.query = this.normalQuery(columns, origin, dest, joinTree, grouping, tables,
this.queryTODO.queryLimit, this.queryTODO.joinType, valueListJoins, this.dataModel.ds.connection.schema, this.dataModel.ds.connection.database);
this.queryTODO.queryLimit, this.queryTODO.joinType, valueListJoins, this.dataModel.ds.connection.schema, this.dataModel.ds.connection.database, this.queryTODO.forSelector);
return this.query;
}
}
Expand Down Expand Up @@ -276,6 +275,7 @@ export abstract class QueryBuilderService {
return `SELECT DISTINCT ${this.queryTODO.fields[0].valueListSource.target_description_column} \nFROM ${table}`;
}

/** esto se usa para las consultas que hacemos a bbdd para generar el modelo */
public simpleQuery(columns: string[], origin: string) {


Expand All @@ -300,8 +300,7 @@ export abstract class QueryBuilderService {
return res;
}
public getPermissions(modelPermissions, modelTables, originTable) {



originTable = this.cleanOriginTable(originTable);
let filters = [];
const permissions = this.getUserPermissions(modelPermissions);
Expand Down
3 changes: 2 additions & 1 deletion eda/eda_api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"start": "nodemon",
"start:forever": "npm run build && forever start -c node ./dist/server.js",
"start:pm2": "npm run build && pm2 start ./dist/server.js",
"start:pm2": "npm run build && pm2 start ./dist/server.js ",
"edapi": "forever start -c node ./dist/server.js",
"build": "tsc && npm run movejpgs",
"dev": "ts-node ./lib/server.ts",
Expand Down Expand Up @@ -42,6 +42,7 @@
"node-schedule": "^2.0.0",
"nodemailer": "^6.7.2",
"nodemon": "^2.0.20",
"object-hash": "^3.0.0",
"oracledb": "^5.0.0",
"password_hash": "^1.1.0",
"pg": "^8.2.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ <h6 id="p-header" class="panel-title" style="cursor: default">
<p-tabPanel i18n-header="@@vistaSeleccionador" header="{{!modeSQL ? editQuery : editSQLQuery}}">

<div *ngIf="!modeSQL" class="grid">

<div class="col-6 md:col-2 pl-2 pr-2">
<h4 i18n="@@entidadesH4" i18n-title="@@entidadesTitle" title="Clique sobre un entidad para ver sus atributos." >
<div class="col-6 md:col-2 pl-2 pr-2" >
<div class="d-flex justify-content-between" style="min-height: 45px;">
<h4 i18n="@@entidadesH4" i18n-title="@@entidadesTitle" title="Clique sobre un entidad para ver sus atributos.">
Entidades
</h4>
<hr class="mb-0">
</div>

<eda-input [inject]="inputs.findTable"></eda-input>
<div class="column-list">
<div class="our-table-box" *ngFor="let table of tablesToShow" (click)="loadColumns(table)"
Expand All @@ -60,14 +61,17 @@ <h4 i18n="@@entidadesH4" i18n-title="@@entidadesTitle" title="Clique sobre un e
</div>

<div class="col-6 md:col-2 pl-2">
<div class="d-flex justify-content-between">
<h4 i18n="@@atributosH4" i18n-title="@@atributsTitle" title="Atributos de una entidad. Arrastre los atrubutos a la selección o los filtros para consultarlos. Haciendo click sobre el atributo se accede a sus propiedaes" >
<div class="d-flex justify-content-between" style="min-height: 45px;">
<h4 *ngIf="!userSelectedTable" i18n="@@atributosH4" i18n-title="@@atributsTitle" title="Atributos de una entidad. Arrastre los atrubutos a la selección o los filtros para consultarlos. Haciendo click sobre el atributo se accede a sus propiedaes">
Atributos
</h4>
<h5 *ngIf="userSelectedTable" i18n-title="@@atributsTitle+" title="Clique sobre un entidad para ver sus atributos." >
<span i18n="@@atributosH4+">Columnas de:</span> <span class="d-block font-weight-bold" i18n="@@atributosH4interpolation" i18n-title="@@atributsTitle+">{{getNiceTableName(userSelectedTable)}}</span>
</h5>
</div>
<hr class="mb-0" style="margin-top: 0.5rem!important;">
<div>
<eda-input [inject]="inputs.findColumn"></eda-input>

</div>
<div class="column-list" cdkDropList #columnsList="cdkDropList" [cdkDropListData]="columns"
[cdkDropListConnectedTo]="[selectList, filterList]" (cdkDropListDropped)="drop($event)"
[cdkDropListEnterPredicate]="isAllowed" >
Expand Down Expand Up @@ -118,17 +122,18 @@ <h4 i18n="@@seleccionH4" i18n-title="@@seleccionTitle" title="Para lanzar una co
#selectList="cdkDropList" [cdkDropListData]="currentQuery"
[cdkDropListConnectedTo]="[columnsList, filterList]" (cdkDropListDropped)="drop($event)" >
<p *ngIf="currentQuery.length < 1" class="fieldsInfo">{{draggFields}}</p>
<div *ngFor="let item of currentQuery"
class="select-box col-3 col-md-2 p-1"
(click)="openColumnDialog(item)"
<div *ngFor="let item of currentQuery"
class="select-box col-3 col-md-2 p-1"
(click)="openColumnDialog(item)"
(mouseover)="showDescription(item)"
(mouseout)="description = ''"
cdkDrag
(mouseout)="description = ''"
cdkDrag
[cdkDragData]="column">

<span class="close-thin pointer" style="z-index: 9999;" (click)="removeColumn( item, 'select' )"></span>
<span *ngIf='item.column_type == "text" ' class="mdi mdi-alphabetical" style="margin-right:4px;"></span>
<span *ngIf='item.column_type == "date" ' class="mdi mdi-calendar-text" style="margin-right:4px;"></span>
<span *ngIf='item.column_type == "numeric" ' class="mdi mdi-numeric" style="margin-right:4px;"></span>
<span *ngIf='item.column_type == "date" ' class="mdi mdi-calendar-text" style="margin-right:4px;"></span>
<span *ngIf='item.column_type == "numeric" ' class="mdi mdi-numeric" style="margin-right:4px;"></span>
<span class="text-center eda-col-class-{{item.column_type}}" title="{{item.description.default}}" >
{{item.display_name.default}}
</span>
Expand All @@ -138,27 +143,28 @@ <h4 i18n="@@seleccionH4" i18n-title="@@seleccionTitle" title="Para lanzar una co
</div>

<h4 class="mt-4" i18n="@@filtrosH4">
Filtrar los resultados por:
Filtrar los resultados por:
</h4>
<hr class="mb-0">
<div class="filter-list" cdkDropList cdkDropListOrientation="horizontal"
#filterList="cdkDropList" [cdkDropListData]="filtredColumns"
[cdkDropListConnectedTo]="[columnsList, selectList]" (cdkDropListDropped)="drop($event)" >
[cdkDropListConnectedTo]="[columnsList, selectList]" (cdkDropListDropped)="drop($event)"
>
<p *ngIf="filtredColumns.length < 1" class="fieldsInfo">{{draggFilters}}</p>
<div class="select-box col-3 col-md-2 p-1" *ngFor="let item of filtredColumns"
(click)="openColumnDialog(item, true)" (mouseover)="showDescription(item)"
(mouseout)="description = ''" cdkDrag [cdkDragData]="column" >
<span class="close-thin pointer" (click)="removeColumn( item, 'filter' )"></span>
<span *ngIf='item.column_type == "text" ' class="mdi mdi-alphabetical" style="margin-right:4px;"></span>
<span *ngIf='item.column_type == "date" ' class="mdi mdi-calendar-text" style="margin-right:4px;"></span>
<span *ngIf='item.column_type == "numeric" ' class="mdi mdi-numeric" style="margin-right:4px;"></span>
<span *ngIf='item.column_type == "date" ' class="mdi mdi-calendar-text" style="margin-right:4px;"></span>
<span *ngIf='item.column_type == "numeric" ' class="mdi mdi-numeric" style="margin-right:4px;"></span>
<span class=" text-center eda-col-class-{{item.column_type}}" title="{{item.description.default}}" >
{{item.display_name.default}}
</span>
</div>

</div>

<div class="grid">
<div class="col-4 md:col-12 infoFiltres">
<span i18n="@@topQueryH4">
Expand All @@ -180,7 +186,7 @@ <h4 class="mt-4" i18n="@@filtrosH4">
</p-selectButton>





</div>
Expand Down Expand Up @@ -525,4 +531,4 @@ <h6 i18n="@@indicaciones">Indicaciones</h6>

<sunburst-dialog *ngIf="sunburstController" [controller]="sunburstController"> </sunburst-dialog>

<eda-context-menu [inject]="contextMenu"></eda-context-menu>
<eda-context-menu [inject]="contextMenu"></eda-context-menu>
Loading

0 comments on commit 34e6bd2

Please sign in to comment.