Skip to content

Commit 1844d57

Browse files
committed
Added filter when displaying an option based on the value of another option which also applies to the mlcp command displayed.
1 parent b452acf commit 1844d57

File tree

2 files changed

+42
-16
lines changed

2 files changed

+42
-16
lines changed

quick-start/src/main/resources/static/app/services/modalService.js

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,23 @@
33
'use strict';
44

55
angular.module('dhib.quickstart.service.modal', ['ui.bootstrap'])
6+
.filter('GetByFieldAndValue', GetByFieldAndValue)
67
.service('ModalService', ModalService)
78
.controller('loadDataModalController', LoadDataModalController)
89
.controller('entityModalController', EntityModalController)
910
.controller('flowModalController', FlowModalController);
11+
12+
function GetByFieldAndValue() {
13+
return function(field, value, collection) {
14+
var i=0, len=collection.length;
15+
for (; i<len; i++) {
16+
if (String(collection[i]['Field']) === String(field) && String(collection[i]['Value']) === String(value)) {
17+
return collection[i];
18+
}
19+
}
20+
return null;
21+
}
22+
}
1023

1124
function ModalService($uibModal) {
1225
var self = this;
@@ -76,7 +89,7 @@
7689
}
7790
}
7891

79-
function LoadDataModalController($scope, $uibModalInstance, DataHub, entityName, flowName) {
92+
function LoadDataModalController($scope, $uibModalInstance, $filter, DataHub, entityName, flowName) {
8093
$scope.loadDataForm = {
8194
inputPath: '.',
8295
inputFileType: 'documents',
@@ -223,16 +236,27 @@
223236
};
224237

225238
$scope.showBasedOnCategoryAndInputFileType = function(category, inputFileType) {
226-
if(category === 'Delimited text options' && $scope.loadDataForm.inputFileType !== 'delimited_text') {
227-
return false;
228-
} else if(category === 'Aggregate XML options' && $scope.loadDataForm.inputFileType !== 'aggregates') {
229-
return false;
239+
return showBasedOnCategoryAndInputFileType(category, inputFileType);
240+
};
241+
242+
$scope.showIfHasNoFilterFieldOrWithSpecifiedValue = function(field,value,collection) {
243+
if(angular.isUndefined(field) || $filter('GetByFieldAndValue')(field,value,collection)) {
244+
return true;
230245
}
231-
return true;
246+
return false;
232247
};
233248

234249
}
235250

251+
function showBasedOnCategoryAndInputFileType(category, inputFileType) {
252+
if(category === 'Delimited text options' && inputFileType !== 'delimited_text') {
253+
return false;
254+
} else if(category === 'Aggregate XML options' && inputFileType !== 'aggregates') {
255+
return false;
256+
}
257+
return true;
258+
};
259+
236260
function constructInitialMlcpCommand(DataHub) {
237261
var mlcpCommand = 'mlcp';
238262

@@ -258,16 +282,18 @@
258282

259283
var otherOptions = [];
260284
$.each(groups, function(i, group) {
261-
$.each(group.settings, function(i, setting) {
262-
if(setting['Value']) {
263-
var key = setting['Field'];
264-
var value = '"' + setting['Value'] + '"';
265-
mlcpCommand += ' ' + key + ' ' + value;
266-
var option = {};
267-
option[key] = value;
268-
otherOptions.push(option);
285+
if(showBasedOnCategoryAndInputFileType(group.category, loadDataForm.inputFileType)) {
286+
$.each(group.settings, function(i, setting) {
287+
if(setting['Value']) {
288+
var key = setting['Field'];
289+
var value = '"' + setting['Value'] + '"';
290+
mlcpCommand += ' ' + key + ' ' + value;
291+
var option = {};
292+
option[key] = value;
293+
otherOptions.push(option);
269294
}
270-
});
295+
});
296+
}
271297
});
272298

273299
loadDataForm.otherOptions = otherOptions.length > 0 ? JSON.stringify(otherOptions) : '';

quick-start/src/main/resources/static/top/modal/loadDataModal.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ <h4 class="modal-title" id="myModalLabel">Load Data</h4>
3636
<div class="form-group">
3737
<uib-accordion close-others="true">
3838
<uib-accordion-group heading="{{group.category}}" ng-repeat="group in groups" ng-show="showBasedOnCategoryAndInputFileType(group.category,loadDataForm.inputFileType)">
39-
<div class="form-group" ng-repeat="setting in group.settings">
39+
<div class="form-group" ng-repeat="setting in group.settings" ng-show="showIfHasNoFilterFieldOrWithSpecifiedValue(setting['FilterField'],setting['FilterValue'],group.settings)">
4040
<input type="checkbox" name="{{setting['Field']}}" ng-if="setting['Type'] === 'boolean'" ng-model="setting['Value']" value="true" ng-change="updateMlcpCommand()" ng-focus="hideInputPathTreeBrowser()">
4141
<label class="control-label" for="{{setting['Field']}}" title="{{setting['Description']}}">{{setting['Label']}}</label><br ng-if="setting['Type'] !== 'boolean'"/>
4242
<input type="text" class="form-control" name="{{setting['Field']}}" ng-if="isText(setting['Type'])" ng-model="setting['Value']" placeholder="{{setting['Placeholder Value'] ? setting['Placeholder Value'] : ''}}" ng-change="updateMlcpCommand()" ng-focus="hideInputPathTreeBrowser()"/>

0 commit comments

Comments
 (0)