Skip to content

Commit

Permalink
Set ng-change for tag control options
Browse files Browse the repository at this point in the history
Create a function setupCategoryOptions to be called on ng-change

https://bugzilla.redhat.com/show_bug.cgi?id=1542590
  • Loading branch information
syncrou committed Feb 13, 2018
1 parent 37ef254 commit 8d68195
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/dialog-editor/components/abstractModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default class AbstractModal {
addEntry: '=?',
removeEntry: '=?',
currentCategoryEntries: '=?',
setupCategoryOptions: '=?',
resolveCategories: '=?',
modalTabIsSet: '<',
modalTabSet: '<',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default class ModalFieldTemplate {
addEntry: '=?',
removeEntry: '=?',
currentCategoryEntries: '=?',
setupCategoryOptions: '=?',
resolveCategories: '=?',
modalTabIsSet: '<',
modalTab: '=',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
</div>
<div pf-form-group pf-label="{{'Category'|translate}}">
<select class="form-control" pf-select
ng-change="vm.setupCategoryOptions()"
ng-model="vm.modalData.options.category_id"
ng-options="category.id.toString() as category.description for category in vm.categories.resources">
<option selected="selected" value="" translate>None</option>
Expand Down
1 change: 1 addition & 0 deletions src/dialog-editor/components/modal-field/field.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ <h4 class="modal-title" id="myModalLabel" translate>Edit Field Details</h4>
modal-tab-is-set="vm.modalTabIsSet"
modal-tab="vm.modalTab"
current-category-entries="vm.currentCategoryEntries"
setup-category-options="vm.setupCategoryOptions"
categories="vm.categories"
resolve-categories="vm.resolveCategories"
modal-data="vm.modalData">
Expand Down
26 changes: 26 additions & 0 deletions src/dialog-editor/components/modal/modalComponent.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
describe('modalComponentSpec', () => {
let bindings;
describe('controller', () => {
let modalComponent;

beforeEach(() => {
bindings = {
modalData: { options: { category_id: '10' } }
};
angular.mock.module('miqStaticAssets.dialogEditor');
angular.mock.module('ui.bootstrap');
angular.mock.inject($componentController => {
modalComponent = $componentController('dialogEditorModal', {API: {} }, bindings);
});
});

describe('#setupCategoryOptions', () => {
it('sets the id, name and description entries for the selected tag control', () => {
modalComponent.categories = { resources : [{'id': '10', 'description': 'CategoryName'}] };
modalComponent.setupCategoryOptions();
expect(modalComponent.modalData.options.category_name).toEqual('category_name');
expect(modalComponent.modalData.options.category_description).toEqual('CategoryName');
});
});
});
});
17 changes: 17 additions & 0 deletions src/dialog-editor/components/modal/modalComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,22 @@ class ModalController {
}
}

/**
* Finds entries for the selected TagControl and sets them.
* @memberof ModalController
* @function setupCategoryOptions
*/
public setupCategoryOptions() {
let vm = this;
let item = this.modalData.options.category_id;
_.forEach(this.categories.resources, function (name) {
if(name['id'] === item) {
vm.modalData.options.category_description = name['description'];
vm.modalData.options.category_name = _.snakeCase(name['description']);
}
});
}

/**
* Receives specification of which modal should be created and it's
* parameters, sets default tab, loads the data of the element edited in modal
Expand Down Expand Up @@ -289,6 +305,7 @@ class ModalController {
tree-selector-show="modalCtrl.parent.treeSelectorShow"
tree-selector-include-domain="modalCtrl.parent.treeSelectorIncludeDomain"
on-select="modalCtrl.parent.onSelect"
setup-category-options="modalCtrl.parent.setupCategoryOptions"
></${component}>`;
}
}
Expand Down

0 comments on commit 8d68195

Please sign in to comment.