@ -1,3 +1,4 @@
import { HttpErrorResponse } from '@angular/common/http' ;
import { HttpErrorResponse } from '@angular/common/http' ;
import { AfterViewInit , Component , OnInit , QueryList , ViewChildren } from '@angular/core' ;
import { AfterViewInit , Component , OnInit , QueryList , ViewChildren } from '@angular/core' ;
import { InfoTable } from '../model/info-table' ;
import { InfoTable } from '../model/info-table' ;
@ -6,6 +7,8 @@ import { InfoTableService } from '../service/info-table.service';
import { JoinsTableComponent } from '../joins-table/joins-table.component' ;
import { JoinsTableComponent } from '../joins-table/joins-table.component' ;
import { Join } from '../model/join' ;
import { Join } from '../model/join' ;
import { Alias } from '../model/alias' ;
import { Alias } from '../model/alias' ;
import { WhereCardComponent } from '../where-card/where-card.component' ;
import { Condition } from '../model/condition' ;
@Component ( {
@Component ( {
selector : 'app-create-joins-page' ,
selector : 'app-create-joins-page' ,
@ -13,14 +16,16 @@ import { Alias } from '../model/alias';
styleUrls : [ './create-joins-page.component.scss' ]
styleUrls : [ './create-joins-page.component.scss' ]
} )
} )
export class CreateJoinsPageComponent implements OnInit , AfterViewInit {
export class CreateJoinsPageComponent implements OnInit , AfterViewInit {
@ViewChildren ( JoinsTableComponent )
@ViewChildren ( JoinsTableComponent ) joinsTableComponent ! : QueryList < JoinsTableComponent > ;
joinsTableComponent ! : QueryList < JoinsTableComponent > ;
@ViewChildren ( WhereCardComponent ) whereCardComponent ! : QueryList < WhereCardComponent > ;
public allSchema : String [ ] | undefined ;
public allSchema : String [ ] | undefined ;
filterBaseSchema : any ;
filterBaseSchema : any ;
filterBaseTables : any ;
filterBaseTables : any ;
public tablesByBaseSchema : InfoTable [ ] | undefined ;
public tablesByBaseSchema : InfoTable [ ] | undefined ;
baseTableData : any ;
baseTableData : any ;
requestInfoJoin : Array < JoinsTableComponent > = [ ] ;
requestInfoJoin : Array < JoinsTableComponent > = [ ] ;
whereCardList : Array < WhereCardComponent > = [ ] ;
baseTableName : String = "" ;
baseTableName : String = "" ;
baseTableNameLowerCase : String = "" ;
baseTableNameLowerCase : String = "" ;
oneJoinRemaining : boolean = true ;
oneJoinRemaining : boolean = true ;
@ -32,9 +37,10 @@ export class CreateJoinsPageComponent implements OnInit, AfterViewInit{
passSchema : String = "" ;
passSchema : String = "" ;
passTable : String = "" ;
passTable : String = "" ;
baseAlias : Alias | undefined ;
baseAlias : Alias | undefined ;
memoAlias : Alias | undefined ;
conditionData : Condition [ ] = [ ]
constructor (
constructor (
private infoColumnService : InfoColumnService ,
private infoColumnService : InfoColumnService ,
private infoTableService : InfoTableService
private infoTableService : InfoTableService
) { }
) { }
@ -71,37 +77,78 @@ export class CreateJoinsPageComponent implements OnInit, AfterViewInit{
}
}
public getNameBaseTable ( ) {
public getNameBaseTable ( ) {
let previousBaseAlias ;
if ( this . baseSchema ) {
if ( this . baseSchema ) {
this . baseTableName = this . baseTableData . nameTable ;
this . baseTableName = this . baseTableData . nameTable ;
this . baseTableNameLowerCase = this . baseTableName ? . toLowerCase ( ) ;
this . baseTableNameLowerCase = this . baseTableName ? . toLowerCase ( ) ;
this . baseAlias = {
this . baseAlias = {
nameSchema : this.baseSchema ,
nameSchema : this.baseSchema ,
nameTable : this.baseTableName ,
nameTable : this.baseTableName ,
nameAlias : this.baseTableNameLowerCase ,
nameAlias : this.baseTableNameLowerCase ,
}
}
if ( this . aliasData . length != 0 ) {
previousBaseAlias = this . aliasData [ 0 ] . nameAlias ;
for ( let iz = this . allData . length ; iz >= 0 ; iz -- ) {
if ( this . allData [ iz ] && this . allData [ iz ] . baseAlias == previousBaseAlias ) {
this . allData . splice ( iz , 1 ) ;
this . requestInfoJoin . splice ( iz , 1 ) ;
this . aliasData . splice ( iz , 1 ) ;
}
}
if ( this . requestInfoJoin . length === 0 ) {
this . requestInfoJoin . push ( new JoinsTableComponent ( this . infoColumnService , this . infoTableService ) ) ;
}
}
this . aliasData . shift ( ) ;
this . aliasData . shift ( ) ;
this . aliasData . unshift ( this . baseAlias ) ;
this . aliasData . unshift ( this . baseAlias ) ;
}
}
}
}
public addTable ( i : number ) {
public addTable ( ) {
this . requestInfoJoin . push ( new JoinsTableComponent ( this . infoColumnService , this . infoTableService ) ) ;
this . requestInfoJoin . push ( new JoinsTableComponent ( this . infoColumnService , this . infoTableService ) ) ;
this . checkLength ( ) ;
this . checkLength ( ) ;
}
}
public addCondition ( ) {
this . whereCardList . push ( new WhereCardComponent ( this . infoColumnService , this . infoTableService ) ) ;
}
public checkAndRemoveIfAliasWasUse ( previousAlias : String ) {
for ( let iz = this . allData . length ; iz >= 0 ; iz -- ) {
if ( this . allData [ iz ] && this . allData [ iz ] . baseAlias == previousAlias ) {
console . log ( this . allData [ iz ] )
this . allData . splice ( iz , 1 ) ;
this . requestInfoJoin . splice ( iz , 1 ) ;
this . aliasData . splice ( iz , 1 ) ;
}
}
if ( this . conditionData . length != 0 ) {
for ( let iy = this . conditionData . length ; iy >= 0 ; iy -- ) {
if ( this . conditionData [ iy ] && this . conditionData [ iy ] . alias == previousAlias ) {
this . conditionData . splice ( iy , 1 ) ;
this . whereCardList . splice ( iy , 1 ) ;
}
}
}
}
public removeTable ( i : number ) {
public removeTable ( i : number ) {
this . requestInfoJoin . splice ( i , 1 ) ;
this . requestInfoJoin . splice ( i , 1 ) ;
this . checkLength ( ) ;
const deleteAlias = this . allData [ i ] . aliasSpecificTable ;
const deleteAlias = this . allData [ i ] . aliasSpecificTable ;
let aliasSplitName = deleteAlias . slice ( 0 , - 1 ) ;
let aliasSplitName = deleteAlias . slice ( 0 , - 1 ) ;
this . allData . splice ( i , 1 ) ;
this . allData . splice ( i , 1 ) ;
this . aliasData . shift ( ) ;
this . checkAndRemoveIfAliasWasUse ( deleteAlias ) ;
let indexOfHighest = - 1 ;
let indexOfHighest = - 1 ;
let highestValue = 0 ;
let highestValue = 0 ;
let tempAlias ;
let tempAlias ;
let inInclude = false ;
let inInclude = false ;
if ( this . allData . length === 0 ) {
this . requestInfoJoin . push ( new JoinsTableComponent ( this . infoColumnService , this . infoTableService ) ) ;
} else {
this . allData . forEach ( ( join , ind ) = > {
this . allData . forEach ( ( join , ind ) = > {
const alias = join . aliasSpecificTable ;
const alias = join . aliasSpecificTable ;
if ( alias . includes ( aliasSplitName . toString ( ) ) ) {
if ( alias . includes ( aliasSplitName . toString ( ) ) ) {
@ -112,21 +159,22 @@ export class CreateJoinsPageComponent implements OnInit, AfterViewInit{
highestValue = numTempAlias ;
highestValue = numTempAlias ;
}
}
inInclude = true ;
inInclude = true ;
}
}
} )
} )
if ( inInclude ) {
}
if ( inInclude && highestValue != 0 ) {
this . allData [ indexOfHighest ] . aliasSpecificTable = deleteAlias || "" ;
this . allData [ indexOfHighest ] . aliasSpecificTable = deleteAlias || "" ;
this . aliasData . shift ( ) ;
this . aliasData . splice ( i , 1 ) ;
this . aliasData . splice ( i , 1 ) ;
this . aliasData [ indexOfHighest ] . nameAlias = deleteAlias ;
this . aliasData [ indexOfHighest ] . nameAlias = deleteAlias ;
} else {
} else {
this . aliasData . shift ( ) ;
this . aliasData . splice ( i , 1 ) ;
this . aliasData . splice ( i , 1 ) ;
}
}
if ( this . baseAlias ) {
if ( this . baseAlias ) {
this . aliasData . unshift ( this . baseAlias ) ;
this . aliasData . unshift ( this . baseAlias ) ;
}
}
console . log ( this . aliasData )
this . checkLength ( ) ;
this . aliasData = [ . . . this . aliasData ]
}
}
public checkLength ( ) {
public checkLength ( ) {
@ -137,6 +185,7 @@ export class CreateJoinsPageComponent implements OnInit, AfterViewInit{
}
}
}
}
public retrieveData ( event : String [ ] , index : number ) {
public retrieveData ( event : String [ ] , index : number ) {
const tempData : Join = {
const tempData : Join = {
joinSpec : event [ 0 ] ,
joinSpec : event [ 0 ] ,
@ -147,52 +196,167 @@ export class CreateJoinsPageComponent implements OnInit, AfterViewInit{
specificColumn : event [ 5 ] ,
specificColumn : event [ 5 ] ,
aliasSpecificTable : event [ 6 ] ,
aliasSpecificTable : event [ 6 ] ,
}
}
if ( this . allData . length != 0 && this . allData [ index ] ) {
const antAlias = this . allData [ index ] . aliasSpecificTable ;
console . log ( antAlias )
if ( this . allData [ index ] . aliasSpecificTable . includes ( event [ 6 ] . toString ( ) ) ) {
} else {
this . checkAndRemoveIfAliasWasUse ( antAlias ) ;
}
}
let switchData = "" ;
let tempNum = "" ;
let tempNum = "" ;
let aliasName = "" ;
let first = 0 ;
let first = 0 ;
let tem = 0 ;
let tempAllData : Join [ ] = [ ] ;
let tempAllData : Join [ ] = [ ] ;
let indexAliasData : Join [ ] = [ ] ;
let noIndexAliasData : Join [ ] = [ ] ;
let alias = "" ;
let inInclude = false ;
let indexOfHighest = - 1 ;
let highestValue = - 1 ;
let tempAlias ;
tempAllData = [ . . . this . allData ] ;
if ( this . allData . length === 0 ) {
if ( this . allData . length === 0 ) {
tempData . aliasSpecificTable = tempData . aliasSpecificTable + "0" ;
switchData = "emptyData ";
} else {
} else {
this . allData . forEach ( ( join , i ) = > {
if ( this . allData [ index ] ) {
const alias = join . aliasSpecificTable ;
if ( this . allData . length != 1 ) {
tempAllData . splice ( index , 1 ) ;
}
tempAllData . forEach ( ( join , i ) = > {
alias = join . aliasSpecificTable . toString ( ) ;
if ( alias . includes ( tempData . aliasSpecificTable . toString ( ) ) ) {
if ( alias . includes ( tempData . aliasSpecificTable . toString ( ) ) ) {
if ( this . allData [ index ] ) {
indexAliasData . push ( tempA llData [ i ] ) ;
tempNum = "0" ;
switchData = "indexAlias ";
first = 1 ;
first = 1 ;
} else {
} else {
tempAllData . push ( this . allData [ i ] ) ;
if ( first === 0 ) {
switchData = "indexNoAlias" ;
}
}
} else if ( this . allData [ index ] ) {
tempNum = "0" ;
first = 1 ;
} else {
tempNum = "0" ;
}
}
} )
} )
tempAllData . forEach ( ( tempJoin ) = > {
} else {
const tempAlias = tempJoin . aliasSpecificTable ;
this . allData . forEach ( ( join , i ) = > {
for ( let lastNum = 0 ; lastNum < 10 ; lastNum ++ ) {
alias = join . aliasSpecificTable . toString ( ) ;
if ( tempAlias == ( tempData . aliasSpecificTable . toString ( ) ) + lastNum . toString ( ) ) {
if ( alias . includes ( tempData . aliasSpecificTable . toString ( ) ) ) {
aliasName = tempAlias . slice ( 0 , - 1 ) ;
noIndexAliasData . push ( tempAllData [ i ] ) ;
const tem = + lastNum + + 1 ;
switchData = "noIndexAlias" ;
first = 2 ;
first = 1
tempNum = tem . toString ( ) ;
} else {
if ( first === 0 ) {
switchData = "noIndexNoAlias" ;
}
}
}
}
} )
} )
}
}
}
if ( first === 0 ) {
switch ( switchData ) {
tempData . aliasSpecificTable = tempData . aliasSpecificTable + tempNum ;
case "emptyData" :
console . log ( switchData )
tempData . aliasSpecificTable = tempData . aliasSpecificTable + "0" ;
this . allData . push ( tempData ) ;
this . allData . push ( tempData ) ;
} else if ( first === 1 ) {
break ;
case "indexAlias" :
console . log ( switchData )
let memo = 0 ;
const rememberAlias = this . allData [ index ] . aliasSpecificTable ;
const aliasSplitName = rememberAlias . slice ( 0 , - 1 ) ;
if ( this . allData [ index ] . aliasSpecificTable == tempData . aliasSpecificTable + "0" ) {
tempNum = "0"
console . log ( "bien 0" )
}
else {
console . log ( "pas 0" )
indexAliasData . forEach ( ( jo ) = > {
const indexAliasName = jo . aliasSpecificTable ;
for ( let num = 8 ; num > - 1 ; num -- ) {
if ( indexAliasName == ( tempData . aliasSpecificTable + num . toString ( ) ) ) {
tem = + num + + 1 ;
if ( memo < tem ) {
memo = tem ;
tempNum = memo . toString ( ) ;
}
}
}
} )
this . allData . forEach ( ( join , ind ) = > {
const aliasRem = join . aliasSpecificTable ;
if ( aliasRem . includes ( aliasSplitName . toString ( ) ) ) {
tempAlias = aliasRem . slice ( - 1 ) ;
let numTempAlias = + tempAlias ;
if ( numTempAlias > highestValue ) {
indexOfHighest = ind ;
highestValue = numTempAlias ;
}
inInclude = true ;
}
} )
}
if ( inInclude && highestValue != 0 ) {
console . log ( indexOfHighest , highestValue , rememberAlias )
this . allData [ indexOfHighest ] . aliasSpecificTable = rememberAlias || "" ;
}
this . allData [ index ] = tempData ;
this . allData [ index ] = tempData ;
this . allData [ index ] . aliasSpecificTable = tempData . aliasSpecificTable + tempNum ;
this . allData [ index ] . aliasSpecificTable = tempData . aliasSpecificTable + tempNum ;
} else if ( first === 2 ) {
break ;
tempData . aliasSpecificTable = aliasName + tempNum ;
case "indexNoAlias" :
console . log ( switchData )
const rememberIndexAlias = this . allData [ index ] . aliasSpecificTable ;
const indexAliasSplitName = rememberIndexAlias . slice ( 0 , - 1 ) ;
this . allData . forEach ( ( join , ind ) = > {
const aliasRem = join . aliasSpecificTable ;
if ( aliasRem . includes ( indexAliasSplitName . toString ( ) ) ) {
tempAlias = aliasRem . slice ( - 1 ) ;
let numTempAlias = + tempAlias ;
if ( numTempAlias > highestValue ) {
indexOfHighest = ind ;
highestValue = numTempAlias ;
}
inInclude = true ;
}
} )
if ( inInclude && highestValue != 0 ) {
this . allData [ indexOfHighest ] . aliasSpecificTable = rememberIndexAlias || "" ;
}
this . allData [ index ] = tempData ;
this . allData [ index ] . aliasSpecificTable = tempData . aliasSpecificTable + "0" ;
break ;
case "noIndexAlias" :
console . log ( switchData )
let memRem = 0 ;
console . log ( noIndexAliasData )
noIndexAliasData . forEach ( ( jo ) = > {
const indexAliasName = jo . aliasSpecificTable ;
for ( let num = 8 ; num > - 1 ; num -- ) {
if ( indexAliasName == ( tempData . aliasSpecificTable + num . toString ( ) ) ) {
tem = + num + + 1 ;
if ( memRem < tem ) {
memRem = tem ;
tempNum = memRem . toString ( ) ;
}
}
}
} )
tempData . aliasSpecificTable = tempData . aliasSpecificTable + tempNum ;
this . allData . push ( tempData ) ;
break ;
case "noIndexNoAlias" :
tempData . aliasSpecificTable = tempData . aliasSpecificTable + "0" ;
this . allData . push ( tempData ) ;
this . allData . push ( tempData ) ;
break ;
}
}
this . allData = [ . . . this . allData ]
console . log ( this . allData ) ;
if ( this . baseAlias ) {
if ( this . baseAlias ) {
this . aliasData . splice ( 0 ) ;
this . aliasData . splice ( 0 ) ;
@ -203,32 +367,34 @@ export class CreateJoinsPageComponent implements OnInit, AfterViewInit{
nameTable : all.specificTable ,
nameTable : all.specificTable ,
nameAlias : all.aliasSpecificTable
nameAlias : all.aliasSpecificTable
}
}
console . log ( ephAlias . nameAlias )
this . aliasData . push ( ephAlias ) ;
this . aliasData . push ( ephAlias ) ;
console . log ( this . aliasData )
} ) ;
} ) ;
}
}
console . log ( this . allData ) ;
this . aliasData = [ . . . this . aliasData ] ;
}
}
public removeWhereCard ( i : number ) {
this . whereCardList . splice ( i , 1 ) ;
if ( this . conditionData [ i ] ) {
this . conditionData . splice ( i , 1 ) ;
}
if ( this . conditionData [ 0 ] ) {
this . conditionData [ 0 ] . operator = "WHERE" ;
}
}
// public getSelectedAlias(event: String){
public getConditionData ( event : String [ ] , index : number ) {
// this.selectedAlias = event;
const tempCondition : Condition = {
operator : event [ 0 ] ,
// if(this.baseTableNameLowerCase == this.selectedAlias){
alias : event [ 1 ] ,
// if(this.baseSchema && this.baseTableName)
column : event [ 2 ] ,
// this.passSchema = this.baseSchema;
condition : event [ 3 ] ,
// this.passTable = this.baseTableName;
value : event [ 4 ]
// } else {
}
// this.allData.forEach((join, i) => {
if ( this . conditionData [ index ] ) {
// const alias = join.aliasSpecificTable;
this . conditionData [ index ] = tempCondition ;
// if(alias == this.selectedAlias){
} else {
// this.passSchema = join.specificSchema;
this . conditionData . push ( tempCondition ) ;
// this.passTable = join.specificTable;
}
// }
}
// })
// }
// }
}
}