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