1
1
'use strict' ;
2
2
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
3
- /// <reference path="../node_modules/@types/mongoose/index.d.ts" />
4
3
// This part of forms-angular borrows _very_ heavily from https://github.com/Alexandre-Strzelewicz/angular-bridge
5
4
// (now https://github.com/Unitech/angular-bridge
6
5
var _ = require ( 'lodash' ) ;
@@ -41,10 +40,8 @@ var DataForm = function (mongoose, app, options) {
41
40
this . searchFunc = async . forEach ;
42
41
this . registerRoutes ( ) ;
43
42
this . app . get . apply ( this . app , processArgs ( this . options , [ 'search' , this . searchAll ( ) ] ) ) ;
44
- if ( this . options . JQMongoFileUploader ) {
45
- var JqUploadModule = this . options . JQMongoFileUploader . module || require ( 'fng-jq-upload' ) . Controller ;
46
- this . fileUploader = new JqUploadModule ( this , processArgs , this . options . JQMongoFileUploader ) ;
47
- void ( this . fileUploader ) ; // suppress warning
43
+ for ( var plugin in this . options . plugins ) {
44
+ this [ plugin ] = new this . options . plugins [ plugin ] . module ( this , processArgs , this . options . plugins [ plugin ] . options ) ;
48
45
}
49
46
} ;
50
47
module . exports = exports = DataForm ;
@@ -66,16 +63,16 @@ DataForm.prototype.getListFields = function (resource, doc, cb) {
66
63
if ( typeof doc [ aField . field ] !== 'undefined' ) {
67
64
if ( aField . params ) {
68
65
if ( aField . params . ref ) {
69
- var lookupResource = that . getResource ( resource . model . schema [ 'paths' ] [ aField . field ] . options . ref ) ;
70
- if ( lookupResource ) {
71
- var hiddenFields = that . generateHiddenFields ( lookupResource , false ) ;
66
+ var lookupResource_1 = that . getResource ( resource . model . schema [ 'paths' ] [ aField . field ] . options . ref ) ;
67
+ if ( lookupResource_1 ) {
68
+ var hiddenFields = that . generateHiddenFields ( lookupResource_1 , false ) ;
72
69
hiddenFields . __v = 0 ;
73
- lookupResource . model . findOne ( { _id : doc [ aField . field ] } ) . select ( hiddenFields ) . exec ( function ( err , doc2 ) {
70
+ lookupResource_1 . model . findOne ( { _id : doc [ aField . field ] } ) . select ( hiddenFields ) . exec ( function ( err , doc2 ) {
74
71
if ( err ) {
75
72
cbm ( err ) ;
76
73
}
77
74
else {
78
- that . getListFields ( lookupResource , doc2 , cbm ) ;
75
+ that . getListFields ( lookupResource_1 , doc2 , cbm ) ;
79
76
}
80
77
} ) ;
81
78
}
@@ -244,7 +241,8 @@ DataForm.prototype.internalSearch = function (req, resourcesToSearch, includeRes
244
241
}
245
242
}
246
243
}
247
- var that = this , results = [ ] , moreCount = 0 , searchCriteria , multiMatchPossible = searchFor . includes ( ' ' ) , modifiedSearchStr = multiMatchPossible ? searchFor . split ( ' ' ) . join ( '|' ) : searchFor ;
244
+ var that = this ;
245
+ var results = [ ] , moreCount = 0 , searchCriteria , multiMatchPossible = searchFor . includes ( ' ' ) , modifiedSearchStr = multiMatchPossible ? searchFor . split ( ' ' ) . join ( '|' ) : searchFor ;
248
246
// Removed the logic that preserved spaces when collection was specified because Louise asked me to.
249
247
searchCriteria = { $regex : '^(' + modifiedSearchStr + ')' , $options : 'i' } ;
250
248
this . searchFunc ( searches , function ( item , cb ) {
@@ -492,7 +490,8 @@ DataForm.prototype.report = function () {
492
490
if ( ! ( req . resource = this . getResource ( req . params . resourceName ) ) ) {
493
491
return next ( ) ;
494
492
}
495
- var reportSchema , self = this , urlParts = url . parse ( req . url , true ) ;
493
+ var self = this ;
494
+ var reportSchema , urlParts = url . parse ( req . url , true ) ;
496
495
if ( req . params . reportName ) {
497
496
reportSchema = req . resource . model . schema . statics [ 'report' ] ( req . params . reportName , req ) ;
498
497
}
@@ -519,9 +518,11 @@ DataForm.prototype.report = function () {
519
518
}
520
519
}
521
520
}
522
- reportSchema = { pipeline : [
521
+ reportSchema = {
522
+ pipeline : [
523
523
{ $project : fields }
524
- ] , drilldown : req . params . resourceName + '/|_id|/edit' } ;
524
+ ] , drilldown : req . params . resourceName + '/|_id|/edit'
525
+ } ;
525
526
}
526
527
// Replace parameters in pipeline
527
528
var schemaCopy = { } ;
@@ -624,10 +625,10 @@ DataForm.prototype.reportInternal = function (req, resource, schema, options, ca
624
625
resource . model . aggregate ( runPipeline , cb ) ;
625
626
}
626
627
} ;
627
- var translations = [ ] ; // array of form {ref:'lookupname',translations:[{value:xx, display:' '}] }
628
+ var translations_1 = [ ] ; // array of form {ref:'lookupname',translations:[{value:xx, display:' '}] }
628
629
// if we need to do any column translations add the function to the tasks list
629
630
if ( schema . columnTranslations ) {
630
- toDo . applyTranslations = [ 'runAggregation' , function ( cb , results ) {
631
+ toDo . applyTranslations = [ 'runAggregation' , function ( results , cb ) {
631
632
function doATranslate ( column , theTranslation ) {
632
633
results [ 'runAggregation' ] . forEach ( function ( resultRow ) {
633
634
var valToTranslate = resultRow [ column . field ] ;
@@ -643,7 +644,7 @@ DataForm.prototype.reportInternal = function (req, resource, schema, options, ca
643
644
doATranslate ( columnTranslation , columnTranslation ) ;
644
645
}
645
646
if ( columnTranslation . ref ) {
646
- var theTranslation = _ . find ( translations , function ( translation ) {
647
+ var theTranslation = _ . find ( translations_1 , function ( translation ) {
647
648
return ( translation . ref === columnTranslation . ref ) ;
648
649
} ) ;
649
650
if ( theTranslation ) {
@@ -673,19 +674,21 @@ DataForm.prototype.reportInternal = function (req, resource, schema, options, ca
673
674
var lookup = ref ;
674
675
return function ( cb ) {
675
676
var translateObject = { ref : lookup . resourceName , translations : [ ] } ;
676
- translations . push ( translateObject ) ;
677
+ translations_1 . push ( translateObject ) ;
677
678
lookup . model . find ( { } , { } , { lean : true } , function ( err , findResults ) {
678
679
if ( err ) {
679
680
cb ( err ) ;
680
681
}
681
682
else {
682
683
// TODO - this ref func can probably be done away with now that list fields can have ref
683
- var j = 0 ;
684
- async . whilst ( function ( ) { return j < findResults . length ; } , function ( cbres ) {
685
- var theResult = findResults [ j ] ;
686
- translateObject . translations [ j ] = translateObject . translations [ j ] || { } ;
687
- var theTranslation = translateObject . translations [ j ] ;
688
- j ++ ;
684
+ var j_1 = 0 ;
685
+ async . whilst ( function ( ) {
686
+ return j_1 < findResults . length ;
687
+ } , function ( cbres ) {
688
+ var theResult = findResults [ j_1 ] ;
689
+ translateObject . translations [ j_1 ] = translateObject . translations [ j_1 ] || { } ;
690
+ var theTranslation = translateObject . translations [ j_1 ] ;
691
+ j_1 ++ ;
689
692
self . getListFields ( lookup , theResult , function ( err , description ) {
690
693
if ( err ) {
691
694
cbres ( err ) ;
@@ -718,7 +721,7 @@ DataForm.prototype.reportInternal = function (req, resource, schema, options, ca
718
721
}
719
722
}
720
723
if ( callFuncs ) {
721
- toDo [ 'callFunctions' ] = [ 'runAggregation' , function ( cb , results ) {
724
+ toDo [ 'callFunctions' ] = [ 'runAggregation' , function ( results , cb ) {
722
725
async . each ( results . runAggregation , function ( row , cb ) {
723
726
for ( var i = 0 ; i < schema . columnTranslations . length ; i ++ ) {
724
727
var thisColumnTranslation = schema . columnTranslations [ i ] ;
@@ -821,10 +824,10 @@ DataForm.prototype.collectionGet = function () {
821
824
if ( aggregationParam ) {
822
825
this . hackVariablesInPipeline ( aggregationParam ) ;
823
826
}
824
- var self = this ;
827
+ var self_1 = this ;
825
828
this . filteredFind ( req . resource , req , aggregationParam , findParam , orderParam , limitParam , skipParam , function ( err , docs ) {
826
829
if ( err ) {
827
- return self . renderError ( err , null , req , res , next ) ;
830
+ return self_1 . renderError ( err , null , req , res , next ) ;
828
831
}
829
832
else {
830
833
res . send ( docs ) ;
@@ -845,7 +848,8 @@ DataForm.prototype.doFindFunc = function (req, resource, cb) {
845
848
}
846
849
} ;
847
850
DataForm . prototype . filteredFind = function ( resource , req , aggregationParam , findParam , sortOrder , limit , skip , callback ) {
848
- var that = this , hiddenFields = this . generateHiddenFields ( resource , false ) ;
851
+ var that = this ;
852
+ var hiddenFields = this . generateHiddenFields ( resource , false ) ;
849
853
function doAggregation ( cb ) {
850
854
if ( aggregationParam ) {
851
855
resource . model . aggregate ( aggregationParam , function ( err , aggregationResults ) {
@@ -1037,11 +1041,11 @@ DataForm.prototype.entityPut = function () {
1037
1041
req . doc [ name ] = ( value === '' ) ? undefined : value ;
1038
1042
} ) ;
1039
1043
if ( req . resource . options . hide !== undefined ) {
1040
- var hiddenFields = that . generateHiddenFields ( req . resource , true ) ;
1041
- hiddenFields . _id = false ;
1042
- req . resource . model . findById ( req . doc . _id , hiddenFields , { lean : true } , function ( err , data ) {
1044
+ var hiddenFields_1 = that . generateHiddenFields ( req . resource , true ) ;
1045
+ hiddenFields_1 . _id = false ;
1046
+ req . resource . model . findById ( req . doc . _id , hiddenFields_1 , { lean : true } , function ( err , data ) {
1043
1047
that . replaceHiddenFields ( req . doc , data ) ;
1044
- that . saveAndRespond ( req , res , hiddenFields ) ;
1048
+ that . saveAndRespond ( req , res , hiddenFields_1 ) ;
1045
1049
} ) ;
1046
1050
}
1047
1051
else {
0 commit comments