11const moment = require ( 'moment' ) ;
2+ const _ = require ( 'underscore' ) ;
23
34const Time = require ( './../models/time' ) ;
45
56const dates = [ 'from' , 'to' ] ;
7+ const objectsWithDefaults = [ 'timeFormat' , 'columns' ] ;
68const defaults = {
79 type : 'project' ,
810 subgroups : false ,
@@ -47,7 +49,7 @@ class config {
4749 * construct
4850 */
4951 constructor ( ) {
50- this . data = defaults ;
52+ this . data = _ . extend ( { } , defaults ) ;
5153 }
5254
5355 /**
@@ -70,21 +72,27 @@ class config {
7072 /**
7173 * get a value by the given key
7274 * @param key
75+ * @param subKey
7376 * @returns {* }
7477 */
75- get ( key ) {
76- if ( ! dates . includes ( key ) ) return this . data [ key ] ;
78+ get ( key , subKey = false ) {
79+ if ( dates . includes ( key ) )
80+ return moment ( this . data [ key ] ) ;
7781
78- return moment ( this . data [ key ] ) ;
82+ if ( objectsWithDefaults . includes ( key ) && _ . isObject ( this . data [ key ] ) )
83+ return subKey && this . data [ key ] [ subKey ] ? this . data [ key ] [ subKey ] : defaults [ key ] ;
84+
85+ return this . data [ key ] ;
7986 }
8087
8188 /**
8289 * get a human readable version of the given time
8390 * @param input
91+ * @param timeFormat
8492 * @returns {string }
8593 */
86- toHumanReadable ( input ) {
87- return Time . toHumanReadable ( input , this . get ( 'hoursPerDay' ) , this . get ( 'timeFormat' ) ) ;
94+ toHumanReadable ( input , timeFormat = false ) {
95+ return Time . toHumanReadable ( input , this . get ( 'hoursPerDay' ) , this . get ( 'timeFormat' , timeFormat ) ) ;
8896 }
8997}
9098
0 commit comments