@@ -1235,7 +1235,9 @@ export class RoleCtrl extends entityCtrl<Role> {
12351235 if ( this . model . _id ) {
12361236 await NoderedUtil . UpdateOne ( this . collection , null , this . model , 1 , false , null ) ;
12371237 } else {
1238- await NoderedUtil . InsertOne ( this . collection , this . model , 1 , false , null ) ;
1238+ this . model = await NoderedUtil . InsertOne ( this . collection , this . model , 1 , false , null ) ;
1239+ // this.model = await NoderedUtil.InsertOne(this.collection, this.model, 1, false, null);
1240+ // this.model = await NoderedUtil.UpdateOne(this.collection, null, this.model, 1, false, null);
12391241 }
12401242 this . $location . path ( "/Roles" ) ;
12411243 if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
@@ -4034,10 +4036,18 @@ export class DuplicatesCtrl extends entitiesCtrl<Base> {
40344036 super ( $scope , $location , $routeParams , $interval , WebSocketClientService , api , userdata ) ;
40354037 console . debug ( "DuplicatesCtrl" ) ;
40364038 this . autorefresh = true ;
4037- this . basequery = { _id : 'notthere' } ;
4039+ this . basequery = { } ;
40384040 this . collection = $routeParams . collection ;
4039- this . baseprojection = { _type : 1 , type : 1 , name : 1 , _created : 1 , _createdby : 1 , _modified : 1 } ;
4041+ // this.baseprojection = { _type: 1, type: 1, name: 1, _created: 1, _createdby: 1, _modified: 1 };
4042+ this . pagesize = 1 ;
40404043 this . postloadData = this . processdata ;
4044+ var checkList = document . getElementById ( 'list1' ) ;
4045+ ( checkList . getElementsByClassName ( 'anchor' ) [ 0 ] as any ) . onclick = function ( evt ) {
4046+ if ( checkList . classList . contains ( 'visible' ) )
4047+ checkList . classList . remove ( 'visible' ) ;
4048+ else
4049+ checkList . classList . add ( 'visible' ) ;
4050+ }
40414051 if ( this . userdata . data . DuplicatesCtrl ) {
40424052 this . basequery = this . userdata . data . DuplicatesCtrl . basequery ;
40434053 this . uniqeness = this . userdata . data . DuplicatesCtrl . uniqeness ;
@@ -4071,14 +4081,23 @@ export class DuplicatesCtrl extends entitiesCtrl<Base> {
40714081 this . loadData ( ) ;
40724082 } ) ;
40734083 }
4084+ public keys : string [ ] = [ ] ;
40744085 async processdata ( ) {
4086+ if ( this . models . length > 0 ) {
4087+ this . keys = Object . keys ( this . models [ 0 ] ) ;
4088+ for ( var i : number = this . keys . length - 1 ; i >= 0 ; i -- ) {
4089+ if ( this . keys [ i ] . startsWith ( '_' ) && this . keys [ i ] != "_type" ) this . keys . splice ( i , 1 ) ;
4090+ }
4091+ this . keys . sort ( ) ;
4092+ this . keys . reverse ( ) ;
4093+ } else { this . keys = [ ] ; }
40754094 if ( ! NoderedUtil . IsNullEmpty ( this . uniqeness ) ) {
40764095 var pipe : any [ ] = [ ] ;
40774096 var arr = this . uniqeness . split ( "," ) ;
40784097 var group : any = { _id : { } , count : { "$sum" : 1 } } ;
40794098 //if ("111".toLowerCase() == "22") {
40804099 group . items = {
4081- $push : '$$ROOT._id'
4100+ $push : { "_id" : '$$ROOT._id' , "name" : '$$ROOT.name' }
40824101 }
40834102 //}
40844103 arr . forEach ( field => {
@@ -4108,15 +4127,33 @@ export class DuplicatesCtrl extends entitiesCtrl<Base> {
41084127 this . userdata . data . DuplicatesCtrl . basequeryas = this . basequeryas ;
41094128 if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
41104129 }
4130+ ToggleUniqeness ( model ) {
4131+ var arr = [ ] ;
4132+ if ( this . uniqeness != null && this . uniqeness != "" ) arr = this . uniqeness . split ( ',' ) ;
4133+ var index = arr . indexOf ( model ) ;
4134+ if ( index > - 1 ) {
4135+ arr . splice ( index , 1 ) ;
4136+ this . uniqeness = arr . join ( ',' ) ;
4137+ } else {
4138+ arr . push ( model ) ;
4139+ this . uniqeness = arr . join ( ',' ) ;
4140+ }
4141+ if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
4142+ this . loadData ( ) ;
4143+ }
41114144 async ShowData ( model ) {
41124145 var modal : any = $ ( "#exampleModal" ) ;
41134146 modal . modal ( ) ;
41144147 this . model = model ;
41154148 }
4116- OpenEntity ( id ) {
4149+ async CloseModal ( ) {
41174150 var modal : any = $ ( "#exampleModal" ) ;
41184151 modal . modal ( 'hide' ) ;
4119- this . $location . path ( "/Entity/" + this . collection + "/" + id ) ;
4152+ }
4153+ OpenEntity ( model ) {
4154+ var modal : any = $ ( "#exampleModal" ) ;
4155+ modal . modal ( 'hide' ) ;
4156+ this . $location . path ( "/Entity/" + this . collection + "/" + model . _id ) ;
41204157 if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
41214158 return ;
41224159
@@ -4125,8 +4162,8 @@ export class DuplicatesCtrl extends entitiesCtrl<Base> {
41254162 this . loading = true ;
41264163 for ( var x = 0 ; x < this . models . length ; x ++ ) {
41274164 var item = ( this . models [ x ] as any ) ;
4128- console . log ( "deleting " + item . items [ 0 ] ) ;
4129- await NoderedUtil . DeleteOne ( this . collection , item . items [ 0 ] , null ) ;
4165+ console . log ( "deleting " , item . items [ 0 ] ) ;
4166+ await NoderedUtil . DeleteOne ( this . collection , item . items [ 0 ] . _id , null ) ;
41304167 }
41314168 this . loading = false ;
41324169 this . loadData ( ) ;
@@ -4136,8 +4173,8 @@ export class DuplicatesCtrl extends entitiesCtrl<Base> {
41364173 for ( var x = 0 ; x < this . models . length ; x ++ ) {
41374174 var item = ( this . models [ x ] as any ) ;
41384175 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 ) ;
4176+ console . log ( "deleting " , item . items [ y ] ) ;
4177+ await NoderedUtil . DeleteOne ( this . collection , item . items [ y ] . _id , null ) ;
41414178 }
41424179 }
41434180 this . loading = false ;
@@ -4148,8 +4185,8 @@ export class DuplicatesCtrl extends entitiesCtrl<Base> {
41484185 for ( var x = 0 ; x < this . models . length ; x ++ ) {
41494186 var item = ( this . models [ x ] as any ) ;
41504187 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 ) ;
4188+ console . log ( "deleting " , item . items [ y ] ) ;
4189+ await NoderedUtil . DeleteOne ( this . collection , item . items [ y ] . _id , null ) ;
41534190 }
41544191 }
41554192 this . loading = false ;
@@ -4160,8 +4197,19 @@ export class DuplicatesCtrl extends entitiesCtrl<Base> {
41604197 if ( NoderedUtil . IsNullUndefinded ( model . items ) ) return ;
41614198 if ( model . items . length < 2 ) return ;
41624199 this . loading = true ;
4163- console . log ( "deleting " + model . items [ 0 ] ) ;
4164- await NoderedUtil . DeleteOne ( this . collection , model . items [ 0 ] , null ) ;
4200+ console . log ( "deleting " , model . items [ 0 ] ) ;
4201+ await NoderedUtil . DeleteOne ( this . collection , model . items [ 0 ] . _id , null ) ;
4202+ this . loading = false ;
4203+ this . loadData ( ) ;
4204+ }
4205+ async DeleteAllButOne ( model ) {
4206+ if ( NoderedUtil . IsNullUndefinded ( model ) ) return ;
4207+ if ( NoderedUtil . IsNullUndefinded ( model . items ) ) return ;
4208+ this . loading = true ;
4209+ for ( var i = 1 ; i < model . items . length ; i ++ ) {
4210+ console . log ( "deleting " , model . items [ i ] ) ;
4211+ await NoderedUtil . DeleteOne ( this . collection , model . items [ i ] . _id , null ) ;
4212+ }
41654213 this . loading = false ;
41664214 this . loadData ( ) ;
41674215 }
@@ -4170,10 +4218,20 @@ export class DuplicatesCtrl extends entitiesCtrl<Base> {
41704218 if ( NoderedUtil . IsNullUndefinded ( model . items ) ) return ;
41714219 this . loading = true ;
41724220 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 ) ;
4221+ console . log ( "deleting " , model . items [ i ] ) ;
4222+ await NoderedUtil . DeleteOne ( this . collection , model . items [ i ] . _id , null ) ;
41754223 }
41764224 this . loading = false ;
41774225 this . loadData ( ) ;
41784226 }
4227+ async ModalDeleteOne ( model ) {
4228+ this . loading = true ;
4229+ await NoderedUtil . DeleteOne ( this . collection , model . _id , null ) ;
4230+ var arr : any [ ] = ( this . model as any ) . items ;
4231+ arr = arr . filter ( x => x . _id != model . _id ) ;
4232+ ( this . model as any ) . items = arr ;
4233+ this . loading = false ;
4234+ if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
4235+ this . loadData ( ) ;
4236+ }
41794237}
0 commit comments