Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sections #398

Open
wants to merge 46 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
baa79ce
Began work on adding sections (placeholder commit)
Oct 14, 2016
4291680
Set basic styles for sections
Oct 14, 2016
c33383b
Partially working type selection
Oct 20, 2016
ad69458
Fixed a bug in swapping the section-exists flag
Oct 20, 2016
b3e29dc
Set up json building and validation for sections
Oct 20, 2016
9a34dfa
When switching section types, add an empty rule to the group after we…
Oct 20, 2016
248f2d9
Implemented allow_sections and section flags
Oct 24, 2016
989967e
Set allow_sections in the example
Oct 24, 2016
6d249e8
Unless we have a default section id, create the section with no group…
Oct 24, 2016
6e1d3ad
Began work on adding sections (placeholder commit)
Oct 14, 2016
4440b58
Set basic styles for sections
Oct 14, 2016
8094d49
Partially working type selection
Oct 20, 2016
323bfc4
Fixed a bug in swapping the section-exists flag
Oct 20, 2016
f945379
Set up json building and validation for sections
Oct 20, 2016
e7e09df
When switching section types, add an empty rule to the group after we…
Oct 20, 2016
a771cf4
Implemented allow_sections and section flags
Oct 24, 2016
d9959dd
Set allow_sections in the example
Oct 24, 2016
543b87b
Unless we have a default section id, create the section with no group…
Oct 24, 2016
164acbe
Merge branch 'sections' of github.com:rsterbin/jQuery-QueryBuilder in…
Oct 24, 2016
3943f67
Fixed a merge error
Oct 24, 2016
3dfdf29
Fixed linting and style errors
Oct 24, 2016
1a3fa87
You can now set section data from JSON
Oct 26, 2016
ff606d4
Fixed linting/style warnings
Oct 26, 2016
1c16555
More bug fixes for sections
Oct 29, 2016
6df52ff
Invert plugin passes tests and works for sections
Nov 1, 2016
0ac0326
Broke section checking into its own method and added section detail t…
Nov 6, 2016
b7fc580
Fixed a logical error in setRules
Nov 7, 2016
8e6b42e
First pass at sections test suite (only currently passing tests for now)
Nov 7, 2016
d0a8ec6
Rounded out section tests and made allow_sections default to true
Nov 15, 2016
360fece
Removed allow_sections from the example
Nov 15, 2016
eb4f8ea
Sortable plugin now restricts moving rules/groups in and out of sections
Nov 18, 2016
08ba292
Fixed missing error message and tooltip on section
Nov 19, 2016
e4d7bf4
Changing filters now works both in and out of sections
Nov 21, 2016
5afefaf
Unique filters within sections
Nov 23, 2016
ed48873
Added support for sections to the SQL plugin and an error about non-s…
Nov 24, 2016
96b5847
Tests for get-sql sections support
Nov 29, 2016
fa0a2ab
Test for get-mongo sections error
Nov 29, 2016
187bdac
Setting sections from SQL works now; also:
Nov 30, 2016
a2a041e
Fixed linting and style warnings
Nov 30, 2016
8d550fe
Put sections in right include location
Nov 30, 2016
cf5395c
Merge branch 'dev' into sections
Nov 30, 2016
a46736a
Increased test coverage and fixed a bug in the sections part of the u…
Dec 8, 2016
71d8cec
Added a test for inverting on sections and fixed a bug in auto-settin…
Dec 8, 2016
5db5f73
Added testing of default unique filters
Dec 8, 2016
9fe66f5
Added a test for remove filter on a section
Dec 8, 2016
e3966f3
Forgot about section flags
Dec 8, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Partially working type selection
Reha Sterbin committed Oct 24, 2016
commit 8094d4995ae601a35c1545f46e4ebc9287c4a76f
121 changes: 121 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
@@ -124,6 +124,126 @@ <h3>Output</h3>
//default_filter: 'name',
sort_filters: true,

sections: [
{
id: 'subquery-a',
label: 'Subquery A',
filters: [
{
id: 'sqa-name',
label: {
en: 'Subquery A Name',
fr: 'Nom'
},
type: 'string',
optgroup: 'core',
default_value: 'Subquery Name',
size: 30,
unique: true
},
{
id: 'sqa-category',
label: 'Subquery A Category',
type: 'integer',
input: 'checkbox',
optgroup: 'core',
values: {
1: 'Books',
2: 'Movies',
3: 'Music',
4: 'Tools',
5: 'Goodies',
6: 'Clothes'
},
colors: {
1: 'foo',
2: 'warning',
5: 'success'
},
operators: ['in', 'not_in', 'equal', 'not_equal', 'is_null', 'is_not_null']
}
]
},
{
id: 'subquery-b',
label: 'Subquery B',
filters: [
{
id: 'sqb-name',
label: {
en: 'Subquery B Name',
fr: 'Nom'
},
type: 'string',
optgroup: 'core',
default_value: 'Subquery Name',
size: 30,
unique: true
},
{
id: 'sqb-category',
label: 'Subquery B Category',
type: 'integer',
input: 'checkbox',
optgroup: 'core',
values: {
1: 'Books',
2: 'Movies',
3: 'Music',
4: 'Tools',
5: 'Goodies',
6: 'Clothes'
},
colors: {
1: 'foo',
2: 'warning',
5: 'success'
},
operators: ['in', 'not_in', 'equal', 'not_equal', 'is_null', 'is_not_null']
}
]
},
{
id: 'subquery-c',
label: 'Subquery C',
filters: [
{
id: 'sqc-name',
label: {
en: 'Subquery C Name',
fr: 'Nom'
},
type: 'string',
optgroup: 'core',
default_value: 'Subquery Name',
size: 30,
unique: true
},
{
id: 'sqc-category',
label: 'Subquery C Category',
type: 'integer',
input: 'checkbox',
optgroup: 'core',
values: {
1: 'Books',
2: 'Movies',
3: 'Music',
4: 'Tools',
5: 'Goodies',
6: 'Clothes'
},
colors: {
1: 'foo',
2: 'warning',
5: 'success'
},
operators: ['in', 'not_in', 'equal', 'not_equal', 'is_null', 'is_not_null']
}
]
}
],

optgroups: {
core: {
en: 'Core',
@@ -406,6 +526,7 @@ <h3>Output</h3>
}
}]
};
console.log(options);

// init
$('#builder').queryBuilder(options);
73 changes: 67 additions & 6 deletions src/core.js
Original file line number Diff line number Diff line change
@@ -262,10 +262,20 @@ QueryBuilder.prototype.bindEvents = function() {
}
});

// section type change
this.$el.on('change.queryBuilder', Selectors.rule_stype, function() {
var sid = $(this).val();
var $section = $(this).closest(Selectors.section_container);
var model = Model($section)
model.id = sid;
self.refreshSection(model);
});

// rule filter change
this.$el.on('change.queryBuilder', Selectors.rule_filter, function() {
var $rule = $(this).closest(Selectors.rule_container);
Model($rule).filter = self.getFilterById($(this).val());
var m = Model($rule);
m.filter = self.getFilterById($(this).val(), m.section_id);
});

// rule operator change
@@ -331,7 +341,7 @@ QueryBuilder.prototype.bindEvents = function() {
},
'set': function(e, node) {
node.parent.$el.find('>' + Selectors.section_body).empty().append(node.$el);
self.updateSectionExistsFlag(node.section);
self.updateSectionExistsFlag(node.parent);
},
'move': function(e, node, group, index) {
node.$el.detach();
@@ -437,14 +447,12 @@ QueryBuilder.prototype.addGroup = function(parent, addRule, data, flags) {
}

var group_id = this.nextGroupId();
var $group = $(this.getGroupTemplate(group_id, level, parent instanceof Section || parent.section ? true : false));
console.log(parent);
var $group = $(this.getGroupTemplate(group_id, level, parent instanceof Section || parent.section_id ? true : false));
if (parent instanceof Section) {
var model = parent.setGroup($group);
} else {
var model = parent.addGroup($group);
}
console.log(model);

model.data = data;
model.flags = $.extend({}, this.settings.default_group_flags, flags);
@@ -552,6 +560,14 @@ QueryBuilder.prototype.addSection = function(parent, addRule, data, flags) {

model.exists = this.settings.default_exists;

this.createSectionTypes(model);

if (this.settings.default_section) {
model.id = this.settings.default_section;
} else {
model.id = this.sections[0].id;
}

this.addGroup(model, true, data, flags);

return model;
@@ -592,6 +608,40 @@ QueryBuilder.prototype.updateSectionExistsFlag = function(section) {
this.trigger('afterUpdateSectionExistsFlag', section);
};

/**
* Create the type <select> for a section
* @param section {Section}
*/
QueryBuilder.prototype.createSectionTypes = function(section) {
var stypes = this.change('getSectionTypes', this.sections, section);
var $stypesSelect = $(this.getSectionTypeSelect(section, stypes));

section.$el.find(Selectors.stype_container).html($stypesSelect);

this.trigger('afterCreateSectionStypes', section);
};

/**
* Refreshes a section after a type change
* @param section {Section}
*/
QueryBuilder.prototype.refreshSection = function(model) {

// Clear out the section if there's any rule that don't belong
var ok = true;
model.$el.find(Selectors.rule_container).each(function() {
var rule = Model($(this));
if (rule.section_id != model.id) {
ok = false;
}
});
if (!ok) {
model.empty();
}

this.trigger('afterRefreshSection', model);
};

//--section

/**
@@ -658,7 +708,18 @@ QueryBuilder.prototype.deleteRule = function(rule) {
* @param rule {Rule}
*/
QueryBuilder.prototype.createRuleFilters = function(rule) {
var filters = this.change('getRuleFilters', this.filters, rule);
if (rule.section_id) {
console.log('on create rule filters');
console.log(rule.section_id);
var section = this.getSectionById(rule.section_id);
if (section) {
var filters = this.change('getRuleFilters', section.filters, rule);
} else {
var filters = this.change('getRuleFilters', [], rule);
}
} else {
var filters = this.change('getRuleFilters', this.filters, rule);
}
var $filterSelect = $(this.getRuleFilterSelect(rule, filters));

rule.$el.find(Selectors.filter_container).html($filterSelect);
37 changes: 33 additions & 4 deletions src/data.js
Original file line number Diff line number Diff line change
@@ -220,6 +220,26 @@ QueryBuilder.prototype.nextSectionId = function() {
return this.status.id + '_section_' + (this.status.section_id++);
};

/**
* Returns a particular section by its id
* @throws UndefinedSectionError
* @param sectionId {string}
* @return {object|null}
*/
QueryBuilder.prototype.getSectionById = function(id) {
if (id == '-1') {
return null;
}

for (var i = 0, l = this.sections.length; i < l; i++) {
if (this.sections[i].id == id) {
return this.sections[i];
}
}

Utils.error('UndefinedSection', 'Undefined section "{0}"', id);
};

/**
* Returns the operators for a filter
* @param filter {string|object} (filter id name or filter object)
@@ -261,16 +281,25 @@ QueryBuilder.prototype.getOperators = function(filter) {
* Returns a particular filter by its id
* @throws UndefinedFilterError
* @param filterId {string}
* @param sectionId {string|null}
* @return {object|null}
*/
QueryBuilder.prototype.getFilterById = function(id) {
QueryBuilder.prototype.getFilterById = function(id, sectionId) {
if (id == '-1') {
return null;
}

for (var i = 0, l = this.filters.length; i < l; i++) {
if (this.filters[i].id == id) {
return this.filters[i];
if (sectionId) {
console.log('on getFilterById');
console.log(sectionId);
var s = this.getSectionById(sectionId);
var filters = s ? s.filters : [];
} else {
var filters = this.filters;
}
for (var i = 0, l = filters.length; i < l; i++) {
if (filters[i].id == id) {
return filters[i];
}
}

3 changes: 3 additions & 0 deletions src/defaults.js
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@ var Selectors = QueryBuilder.selectors = {
section_container: '.rules-section-container',
group_container: '.rules-group-container',
rule_container: '.rule-container',
stype_container: '.rule-stype-container',
filter_container: '.rule-filter-container',
operator_container: '.rule-operator-container',
value_container: '.rule-value-container',
@@ -59,6 +60,7 @@ var Selectors = QueryBuilder.selectors = {

section_exists_flag: '.rules-section-header [name$=_exists]',
group_condition: '.rules-group-header [name$=_cond]',
rule_stype: '.rule-stype-container [name$=_section_type]',
rule_filter: '.rule-filter-container [name$=_filter]',
rule_operator: '.rule-operator-container [name$=_operator]',
rule_value: '.rule-value-container [name*=_value_]',
@@ -153,6 +155,7 @@ QueryBuilder.DEFAULTS = {

templates: {
section: null,
stypeSelect: null,
group: null,
rule: null,
filterSelect: null,
Loading