Skip to content

Commit

Permalink
Merge "Closes-bug: #1491803 - UI: Support taking DHCP option value in…
Browse files Browse the repository at this point in the history
… bytes"
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed May 13, 2016
2 parents 324954a + 4a51ecc commit 65e6c76
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ define([

defaultConfig: {
'dhcp_option_name': '',
'dhcp_option_value':''
'dhcp_option_value': '',
'dhcp_option_value_bytes': ''
},

validateAttr: function (attributePath, validation, data) {
Expand All @@ -32,10 +33,6 @@ define([
'dhcp_option_name': {
required: true,
msg: 'Enter DHCP Code.'
},
'dhcp_option_value': {
required: true,
msg: 'Enter DHCP Value.'
}
}
}
Expand Down
131 changes: 58 additions & 73 deletions webroot/config/networking/port/ui/js/models/portModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,30 +231,26 @@ define([
modelConfig['allowedAddressPairCollection'] = appCollectionModel;

//Modal config default DHCP option formatting
var DHCP = [];
var dhcpList =
modelConfig["virtual_machine_interface_dhcp_option_list"]["dhcp_option"];
if(dhcpList != null && dhcpList.length > 0) {
var dhcpModelArray = [],
dhcpList = getValueByJsonPath(modelConfig,
"virtual_machine_interface_dhcp_option_list;dhcp_option", []);
if(dhcpList.length) {
var dhcpLen = dhcpList.length;
for(var i = 0; i < dhcpLen; i++) {
var dhcp_obj = dhcpList[i];
var dhcpVal = dhcpList[i].dhcp_option_value.split(" ");
if(dhcpVal.length > 1) {
var dhcpValLen = dhcpVal.length;
for(var j = 0; j < dhcpValLen; j++) {
var dhcp = {};
dhcp.dhcp_option_name = dhcpList[i].dhcp_option_name;
dhcp.dhcp_option_value = dhcpVal[j];
var dhcpOptionModel = new DHCPOptionModel(dhcp);
DHCP.push(dhcpOptionModel);
}
} else {
var dhcpOptionModel = new DHCPOptionModel(dhcp_obj);
DHCP.push(dhcpOptionModel);
}
var dhcp_obj = dhcpList[i],
dhcpVal = getValueByJsonPath(dhcpList[i],
"dhcp_option_value", null, false),
dhcpValBytes = getValueByJsonPath(dhcpList[i],
"dhcp_option_value_bytes", null, false),
dhcp = {}, dhcpOptionModel;
dhcp.dhcp_option_name = dhcpList[i].dhcp_option_name;
dhcp.dhcp_option_value = dhcpVal;
dhcp.dhcp_option_value_bytes = dhcpValBytes;
dhcpOptionModel = new DHCPOptionModel(dhcp);
dhcpModelArray.push(dhcpOptionModel);
}
}
var dhcpCollectionModel = new Backbone.Collection(DHCP);
var dhcpCollectionModel = new Backbone.Collection(dhcpModelArray);
modelConfig["virtual_machine_interface_dhcp_option_list"]["dhcp_option"]
= dhcpCollectionModel;
modelConfig['dhcpOptionCollection'] = dhcpCollectionModel;
Expand Down Expand Up @@ -630,6 +626,33 @@ define([
return "Select Routing Instance";
}
}
},
'dhcpOptionCollection': function(value, attr, finalObj) {
var dhcpOptCol = finalObj["dhcpOptionCollection"] ?
finalObj["dhcpOptionCollection"].toJSON() : [],
i, dhcpOptColCnt, dhcpOptionVal, dhcpOptionValBytes;
if(dhcpOptCol.length) {
dhcpOptColCnt = dhcpOptCol.length;
for(i = 0; i < dhcpOptColCnt; i++) {
if(dhcpOptCol[i]) {
dhcpOptionVal = dhcpOptCol[i].dhcp_option_value() ?
dhcpOptCol[i].dhcp_option_value().trim() : null;
dhcpOptionValBytes = dhcpOptCol[i].dhcp_option_value_bytes() ?
dhcpOptCol[i].dhcp_option_value_bytes().trim() : null;
if(!(dhcpOptionVal || dhcpOptionValBytes)) {
return "Invalid option value";
}
}
}
dhcpOptCol = _.map(dhcpOptCol, function(dhcpOpt) {
return dhcpOpt.dhcp_option_name();
});
for(i = 0; i < dhcpOptCol.length; i++){
if(dhcpOptCol[i] === dhcpOptCol[i + 1]){
return "DHCP Options are repeated";
}
}
}
}
}
},
Expand Down Expand Up @@ -695,6 +718,7 @@ define([
dhcpOptionModel = new DHCPOptionModel();
dhcpList.add([dhcpOptionModel]);
},

//DHCP Delete
deleteDHCP: function(data, dhcp) {
var dhcpCollection = data.model().collection,
Expand Down Expand Up @@ -773,18 +797,6 @@ define([
'ip_protocol': false, 'source_port': false,
'destination_port': false};
},
groupBy: function(array, f) {
var groups = {};
array.forEach( function(o) {
var group = JSON.stringify( f(o) );
groups[group] = groups[group] || [];
groups[group].push(o);
});
return Object.keys(groups).map( function( group )
{
return groups[group];
})
},
configurePorts: function (mode, callbackObj) {
var ajaxConfig = {}, returnFlag = true;
var temp_val;
Expand Down Expand Up @@ -941,54 +953,27 @@ define([
newPortData.virtual_machine_interface_bindings.key_value_pair = portBindingLocal;
}
//DHCP
var allDHCPValues = newPortData["dhcpOptionCollection"].toJSON();
var allDHCPValues = newPortData["dhcpOptionCollection"] ?
newPortData["dhcpOptionCollection"].toJSON() : [];
newPortData.virtual_machine_interface_dhcp_option_list = {};
if (allDHCPValues && allDHCPValues.length > 0) {
var unGroupedDHCPOptionsList = [];
var returnDHCPOptionsList = [];
var dhcpLen = allDHCPValues.length;
for(i = 0; i < dhcpLen; i++){
var dhcpCode = allDHCPValues[i].dhcp_option_name();
var dhcpValue = allDHCPValues[i].dhcp_option_value();
unGroupedDHCPOptionsList[i] = {};
unGroupedDHCPOptionsList[i]["dhcp_option_name"] =
var dhcpCode = allDHCPValues[i].dhcp_option_name(),
dhcpValue = allDHCPValues[i].dhcp_option_value(),
dhcpValueBytes =
allDHCPValues[i].dhcp_option_value_bytes();
returnDHCPOptionsList[i] = {};
returnDHCPOptionsList[i]["dhcp_option_name"] =
dhcpCode.trim();
unGroupedDHCPOptionsList[i]["dhcp_option_value"] =
returnDHCPOptionsList[i]["dhcp_option_value"] =
dhcpValue.trim();
returnDHCPOptionsList[i]["dhcp_option_value_bytes"] =
dhcpValueBytes.trim();
}
if(unGroupedDHCPOptionsList.length > 0) {
var groupedDHCPOptionsList =
self.groupBy(unGroupedDHCPOptionsList, function(item)
{ return [item.dhcp_option_name]; });
if (groupedDHCPOptionsList &&
groupedDHCPOptionsList != "" &&
groupedDHCPOptionsList.length > 0) {
returnDHCPOptionsList = [];
for (var i = 0; i < groupedDHCPOptionsList.length;
i++) {
var dhcpOptionsOfSameValue =
jsonPath(groupedDHCPOptionsList[i],
"$.*.dhcp_option_value");
if(dhcpOptionsOfSameValue === false)
dhcpOptionsOfSameValue = "";
else {
dhcpOptionsOfSameValue =
dhcpOptionsOfSameValue.join(" ");
}
if(typeof dhcpOptionsOfSameValue === "string" &&
dhcpOptionsOfSameValue.trim() !== "") {
returnDHCPOptionsList.push({
"dhcp_option_name":
groupedDHCPOptionsList[i][0]['dhcp_option_name'],
"dhcp_option_value":
dhcpOptionsOfSameValue
});
}
}
if(returnDHCPOptionsList.length > 0)
newPortData.virtual_machine_interface_dhcp_option_list.dhcp_option
= returnDHCPOptionsList;
}
}
newPortData.virtual_machine_interface_dhcp_option_list.dhcp_option
= returnDHCPOptionsList;
} else {
delete(newPortData.virtual_machine_interface_dhcp_option_list.dhcp_option);
}
Expand Down
19 changes: 13 additions & 6 deletions webroot/config/networking/port/ui/js/portViewConfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -721,9 +721,7 @@
templateId: cowc.TMPL_EDITABLE_GRID_INPUT_VIEW,
dataBindValue: 'dhcp_option_name()',
placeholder: 'Option code',
class: "span6",
width:275,
label: 'Code'
width: 200,
}
}, {
elementId: 'dhcp_option_value',
Expand All @@ -734,9 +732,18 @@
placeholder: 'Option value',
templateId: cowc.TMPL_EDITABLE_GRID_INPUT_VIEW,
dataBindValue: 'dhcp_option_value()',
class: "span6",
width:275,
label: 'Value'
width: 300,
}
}, {
elementId: 'dhcp_option_value_bytes',
name: "Value in Bytes",
view: "FormInputView",
viewConfig: {
path: 'dhcp_option_value_bytes',
placeholder: 'Option value in bytes',
templateId: cowc.TMPL_EDITABLE_GRID_INPUT_VIEW,
dataBindValue: 'dhcp_option_value_bytes()',
width: 300,
}
}],
rowActions: [{
Expand Down

0 comments on commit 65e6c76

Please sign in to comment.