Last active
August 5, 2017 04:34
Revisions
-
angelomiranda revised this gist
Aug 5, 2017 . 1 changed file with 69 additions and 29 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,29 +1,69 @@ this.remoteLoggingOptions = ['warn', 'info', 'error', 'debug']; const form = { value: { waitTime: 300, maxMsgs: 100, warn: true, info: true, debug: false, error: false } } const remoteLoggingModel = { key: 'loggerRemoteLevels', value: '' } const formValue = form.value; // model values coming from ngForm model let modelKeys = Object.keys(formValue); let transformedObject = modelKeys.reduce((result, current) => { let value = formValue[current]; // current model value // remoteLoggingOptions are comma separated options // 'warn,error' | 'warn,info,debug,error' if (_.includes(this.remoteLoggingOptions, current) && value) { result.push({ key: 'loggerRemoteLevels', value: current }); } if (current === 'waitTime') { result.push({ key: 'loggerRemoteWaitTime', value: value }); } if (current === 'maxMsgs') { result.push({ key: 'loggerRemoteMaxMsgs', value: value }); } return result; }, []); let otherRemoteLoggingOptions = _.reject(transformedObject, (current) => { return current.key === 'loggerRemoteLevels' }) let getLoggerRemoteLevels = _(transformedObject) .filter(function(currentObj) { return currentObj.key === 'loggerRemoteLevels' }) .map('value') .value(); let remoteLoggingOptions = { value: getLoggerRemoteLevels.join(',') } let finalRemoteLoggingModel = _.assign(remoteLoggingModel, remoteLoggingOptions) let finalRemoteLoggingOptions = otherRemoteLoggingOptions.concat(finalRemoteLoggingModel) -
angelomiranda created this gist
Aug 4, 2017 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ const formValue = form.value; // model values coming from ngForm model const arrayOfObjects = Object.keys(formValue) .reduce((result, current) => { const value = formValue[current]; if (_.includes(this.remoteLoggingOptions, current) && value) { result.push({ key: 'loggerRemoteLevels', value: current }); } if (current === 'waitTime') { result.push({ key: 'loggerRemoteWaitTime', value: value }); } if (current === 'maxMsgs') { result.push({ key: 'loggerRemoteMaxMsgs', value: value }); } return result; }, []);