@@ -4012,4 +4012,168 @@ export class CredentialCtrl extends entityCtrl<Base> {
40124012 } ) ;
40134013 }
40144014
4015+ }
4016+
4017+
4018+
4019+
4020+
4021+ export class DuplicatesCtrl extends entitiesCtrl < Base > {
4022+ public collections : any ;
4023+ public model : Base ;
4024+ public uniqeness : string ;
4025+ constructor (
4026+ public $scope : ng . IScope ,
4027+ public $location : ng . ILocationService ,
4028+ public $routeParams : ng . route . IRouteParamsService ,
4029+ public $interval : ng . IIntervalService ,
4030+ public WebSocketClientService : WebSocketClientService ,
4031+ public api : api ,
4032+ public userdata : userdata
4033+ ) {
4034+ super ( $scope , $location , $routeParams , $interval , WebSocketClientService , api , userdata ) ;
4035+ console . debug ( "DuplicatesCtrl" ) ;
4036+ this . autorefresh = true ;
4037+ this . basequery = { _id : 'notthere' } ;
4038+ this . collection = $routeParams . collection ;
4039+ this . baseprojection = { _type : 1 , type : 1 , name : 1 , _created : 1 , _createdby : 1 , _modified : 1 } ;
4040+ this . postloadData = this . processdata ;
4041+ if ( this . userdata . data . DuplicatesCtrl ) {
4042+ this . basequery = this . userdata . data . DuplicatesCtrl . basequery ;
4043+ this . uniqeness = this . userdata . data . DuplicatesCtrl . uniqeness ;
4044+ this . baseprojection = this . userdata . data . DuplicatesCtrl . baseprojection ;
4045+ this . orderby = this . userdata . data . DuplicatesCtrl . orderby ;
4046+ this . searchstring = this . userdata . data . DuplicatesCtrl . searchstring ;
4047+ this . basequeryas = this . userdata . data . DuplicatesCtrl . basequeryas ;
4048+ } else {
4049+ if ( NoderedUtil . IsNullEmpty ( this . collection ) ) {
4050+ console . log ( "1 redir to /Duplicates/entities" ) ;
4051+ this . $location . path ( "/Duplicates/entities" ) ;
4052+ if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
4053+ return ;
4054+ }
4055+ }
4056+ if ( NoderedUtil . IsNullEmpty ( this . collection ) ) {
4057+ console . log ( "2 redir to /Duplicates/entities" ) ;
4058+ this . $location . path ( "/Duplicates/entities" ) ;
4059+ if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
4060+ return ;
4061+ } else if ( this . $location . path ( ) != "/Duplicates/" + this . collection ) {
4062+ console . log ( "3 redir from / to" ) ;
4063+ console . log ( this . $location . path ( ) ) ;
4064+ console . log ( "/Duplicates/" + this . collection ) ;
4065+ this . $location . path ( "/Duplicates/" + this . collection ) ;
4066+ if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
4067+ return ;
4068+ }
4069+ if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
4070+ WebSocketClientService . onSignedin ( async ( user : TokenUser ) => {
4071+ this . loadData ( ) ;
4072+ } ) ;
4073+ }
4074+ async processdata ( ) {
4075+ if ( ! NoderedUtil . IsNullEmpty ( this . uniqeness ) ) {
4076+ var pipe : any [ ] = [ ] ;
4077+ var arr = this . uniqeness . split ( "," ) ;
4078+ var group : any = { _id : { } , count : { "$sum" : 1 } } ;
4079+ //if ("111".toLowerCase() == "22") {
4080+ group . items = {
4081+ $push : '$$ROOT._id'
4082+ }
4083+ //}
4084+ arr . forEach ( field => {
4085+ if ( field . trim ( ) !== "" ) {
4086+ group . _id [ field ] = "$" + field ;
4087+ }
4088+ } ) ;
4089+ pipe . push ( { "$group" : group } ) ;
4090+ pipe . push ( { "$match" : { "count" : { "$gte" : 2 } } } ) ;
4091+ pipe . push ( { "$limit" : 100 } ) ;
4092+ pipe . push ( { "$sort" : this . orderby } )
4093+ try {
4094+ this . models = await NoderedUtil . Aggregate ( this . collection , pipe , null ) ;
4095+ console . log ( this . models ) ;
4096+ } catch ( error ) {
4097+ console . log ( pipe ) ;
4098+ this . errormessage = JSON . stringify ( error ) ;
4099+ }
4100+ }
4101+
4102+ if ( ! this . userdata . data . DuplicatesCtrl ) this . userdata . data . DuplicatesCtrl = { } ;
4103+ this . userdata . data . DuplicatesCtrl . basequery = this . basequery ;
4104+ this . userdata . data . DuplicatesCtrl . uniqeness = this . uniqeness ;
4105+ this . userdata . data . DuplicatesCtrl . baseprojection = this . baseprojection ;
4106+ this . userdata . data . DuplicatesCtrl . orderby = this . orderby ;
4107+ this . userdata . data . DuplicatesCtrl . searchstring = this . searchstring ;
4108+ this . userdata . data . DuplicatesCtrl . basequeryas = this . basequeryas ;
4109+ if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
4110+ }
4111+ async ShowData ( model ) {
4112+ var modal : any = $ ( "#exampleModal" ) ;
4113+ modal . modal ( ) ;
4114+ this . model = model ;
4115+ }
4116+ OpenEntity ( id ) {
4117+ var modal : any = $ ( "#exampleModal" ) ;
4118+ modal . modal ( 'hide' ) ;
4119+ this . $location . path ( "/Entity/" + this . collection + "/" + id ) ;
4120+ if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
4121+ return ;
4122+
4123+ }
4124+ async MassDeleteOnlyOne ( ) {
4125+ this . loading = true ;
4126+ for ( var x = 0 ; x < this . models . length ; x ++ ) {
4127+ var item = ( this . models [ x ] as any ) ;
4128+ console . log ( "deleting " + item . items [ 0 ] ) ;
4129+ await NoderedUtil . DeleteOne ( this . collection , item . items [ 0 ] , null ) ;
4130+ }
4131+ this . loading = false ;
4132+ this . loadData ( ) ;
4133+ }
4134+ async MassDeleteAllButOne ( ) {
4135+ this . loading = true ;
4136+ for ( var x = 0 ; x < this . models . length ; x ++ ) {
4137+ var item = ( this . models [ x ] as any ) ;
4138+ for ( var y = 1 ; y < item . items . length ; y ++ ) {
4139+ console . log ( "deleting " + item . items [ y ] ) ;
4140+ await NoderedUtil . DeleteOne ( this . collection , item . items [ y ] , null ) ;
4141+ }
4142+ }
4143+ this . loading = false ;
4144+ this . loadData ( ) ;
4145+ }
4146+ async MassDeleteAll ( ) {
4147+ this . loading = true ;
4148+ for ( var x = 0 ; x < this . models . length ; x ++ ) {
4149+ var item = ( this . models [ x ] as any ) ;
4150+ for ( var y = 0 ; y < item . items . length ; y ++ ) {
4151+ console . log ( "deleting " + item . items [ y ] ) ;
4152+ await NoderedUtil . DeleteOne ( this . collection , item . items [ y ] , null ) ;
4153+ }
4154+ }
4155+ this . loading = false ;
4156+ this . loadData ( ) ;
4157+ }
4158+ async DeleteOnlyOne ( model ) {
4159+ if ( NoderedUtil . IsNullUndefinded ( model ) ) return ;
4160+ if ( NoderedUtil . IsNullUndefinded ( model . items ) ) return ;
4161+ if ( model . items . length < 2 ) return ;
4162+ this . loading = true ;
4163+ console . log ( "deleting " + model . items [ 0 ] ) ;
4164+ await NoderedUtil . DeleteOne ( this . collection , model . items [ 0 ] , null ) ;
4165+ this . loading = false ;
4166+ this . loadData ( ) ;
4167+ }
4168+ async DeleteAll ( model ) {
4169+ if ( NoderedUtil . IsNullUndefinded ( model ) ) return ;
4170+ if ( NoderedUtil . IsNullUndefinded ( model . items ) ) return ;
4171+ this . loading = true ;
4172+ for ( var i = 0 ; i < model . items . length ; i ++ ) {
4173+ console . log ( "deleting " + model . items [ i ] ) ;
4174+ await NoderedUtil . DeleteOne ( this . collection , model . items [ i ] , null ) ;
4175+ }
4176+ this . loading = false ;
4177+ this . loadData ( ) ;
4178+ }
40154179}
0 commit comments