Commit 179d70d4 by Van

fix(all) : autocomplete first item fixed. Exclude and include empty . All fields bt contenttypes

parent fe66bb39
...@@ -77,6 +77,7 @@ class CustomQueriesExtension extends SimpleExtension ...@@ -77,6 +77,7 @@ class CustomQueriesExtension extends SimpleExtension
} }
$json = json_decode($input, true); $json = json_decode($input, true);
if(!$json || empty($json)) { if(!$json || empty($json)) {
return ''; return '';
} }
...@@ -85,7 +86,11 @@ class CustomQueriesExtension extends SimpleExtension ...@@ -85,7 +86,11 @@ class CustomQueriesExtension extends SimpleExtension
$storage = $this->getContainer()['storage']; $storage = $this->getContainer()['storage'];
foreach ($json as $contentType => $fields) { foreach ($json as $contentType => $fields) {
$query = $this->_buildQuery($contentType, $fields); $query = false;
if ($contentType != 'all'){
$query = $this->_buildQuery($json, $contentType, $fields);
}
if(!empty($query)) if(!empty($query))
{ {
...@@ -97,12 +102,12 @@ class CustomQueriesExtension extends SimpleExtension ...@@ -97,12 +102,12 @@ class CustomQueriesExtension extends SimpleExtension
$contents = $storage->getContent($contentType, ['id' => implode(' || ', $ids), 'paging' => true, 'limit' => 99999]); $contents = $storage->getContent($contentType, ['id' => implode(' || ', $ids), 'paging' => true, 'limit' => 99999]);
if(is_array($contents)) { if(is_array($contents)) {
$records = array_merge($records, $contents); $records = array_merge($records, $contents);
} else { } else {
$records = array_merge($records, [$contents]); $records = array_merge($records, [$contents]);
} }
} }
} }
return $this->getContainer()['twig']->render("custom_queries.twig", ['records' => $records]); return $this->getContainer()['twig']->render("custom_queries.twig", ['records' => $records]);
...@@ -191,26 +196,32 @@ class CustomQueriesExtension extends SimpleExtension ...@@ -191,26 +196,32 @@ class CustomQueriesExtension extends SimpleExtension
} }
/** /**
* @param array $json
* @param $contentType
* @param array $fields * @param array $fields
* @return string * @return string
*/ */
protected function _buildQuery($contentType, array $fields = []) { protected function _buildQuery(array $json, $contentType, array $fields = []) {
if(!$contentType) { if(!$contentType) {
return ''; return '';
} }
$storage = $this->getContainer()['storage']; $storage = $this->getContainer()['storage'];
$tableName = $storage->getContenttypeTablename($contentType); $tableName = $storage->getContenttypeTablename($contentType);
if(!$tableName) { if(!$tableName) {
return ''; return '';
} }
$query = 'SELECT id FROM '.$tableName; $query = 'SELECT id FROM '.$tableName;
if(!isset($json['all']) || !\in_array($contentType, $json['all'])) {
$where = $this->_buildWhere($fields); $where = $this->_buildWhere($fields);
if($where) { if($where) {
$query .= $where; $query .= $where;
} }
}
return $query; return $query;
} }
......
...@@ -15,13 +15,15 @@ ...@@ -15,13 +15,15 @@
margin-right: 1em; margin-right: 1em;
} }
/* Autocomplete css */
.chooseField { .chooseField {
height: 26px !important; height: 26px !important;
width: 20em !important;
text-align: center !important;
} }
.select span{ .select2-container {
width: 20em; text-align: left;
text-align: center;
} }
.addContentTypeContainer { .addContentTypeContainer {
......
...@@ -25,20 +25,21 @@ class CustomQueries { ...@@ -25,20 +25,21 @@ class CustomQueries {
this.name = element.attr('name'); this.name = element.attr('name');
this.usedContentType = []; this.usedContentType = [];
this.selectors = { this.selectors = {
addContentTypeContainer: '.addContentTypeContainer-'+this.name, addContentTypeContainer: '.addContentTypeContainer-' + this.name,
addContentTypeBtn: '#addContentType-'+this.name, addContentTypeBtn: '#addContentType-' + this.name,
validateContentTypeBtn: '#validateContentType-'+this.name, validateContentTypeBtn: '#validateContentType-' + this.name,
cancelContentTypeBtn: '#cancelContentType-'+this.name, cancelContentTypeBtn: '#cancelContentType-' + this.name,
selectContentType: '.addContentTypeContainer-'+this.name+' select', selectContentType: '.addContentTypeContainer-' + this.name + ' select',
listContentTypeContainer: '.listContentTypeContainer-'+this.name, listContentTypeContainer: '.listContentTypeContainer-' + this.name,
removeContentTypeBtn: '#removeContentType-'+this.name, removeContentTypeBtn: '#removeContentType-' + this.name,
addFieldBtn: '#addField-'+this.name, addFieldBtn: '#addField-' + this.name,
allFields: '#allFields-'+this.name, allFields: '#allFields-' + this.name,
validateFieldBtn: '#validateField-'+this.name, validateFieldBtn: '#validateField-' + this.name,
cancelFieldBtn: '#cancelField-'+this.name, cancelFieldBtn: '#cancelField-' + this.name,
removeFieldBtn: '#removeField-'+this.name, removeFieldBtn: '#removeField-' + this.name,
} }
} }
/** /**
* Init * Init
*/ */
...@@ -54,13 +55,14 @@ class CustomQueries { ...@@ -54,13 +55,14 @@ class CustomQueries {
/*########################################## /*##########################################
Load original content Load original content
##########################################*/ ##########################################*/
/** /**
* INIT JSON content for content type * INIT JSON content for content type
*/ */
loadOriginalContent() { loadOriginalContent() {
let content = this.json; let content = this.json;
for(let index in content) { for (let index in content) {
if (index != 'all'){ if (index != 'all') {
this.createContentTypeBlock(index); this.createContentTypeBlock(index);
this.loadOriginalField(index, content[index], content) this.loadOriginalField(index, content[index], content)
} }
...@@ -73,14 +75,14 @@ class CustomQueries { ...@@ -73,14 +75,14 @@ class CustomQueries {
* @param fields * @param fields
*/ */
loadOriginalField(contentType, fields, json) { loadOriginalField(contentType, fields, json) {
for(let index in fields) { for (let index in fields) {
let text = index; let text = index;
let joinField = 'and'; let joinField = 'and';
if(this.config[contentType] && this.config[contentType]['fields'] && this.config[contentType]['fields'][index] && this.config[contentType]['fields'][index].label) { if (this.config[contentType] && this.config[contentType]['fields'] && this.config[contentType]['fields'][index] && this.config[contentType]['fields'][index].label) {
text = this.config[contentType]['fields'][index].label; text = this.config[contentType]['fields'][index].label;
} }
if(json[contentType] && json[contentType][index] && json[contentType][index]['joinFields']) { if (json[contentType] && json[contentType][index] && json[contentType][index]['joinFields']) {
joinField = json[contentType][index]['joinFields'] joinField = json[contentType][index]['joinFields']
} }
...@@ -96,9 +98,9 @@ class CustomQueries { ...@@ -96,9 +98,9 @@ class CustomQueries {
* @param fieldContent * @param fieldContent
*/ */
loadOriginalFieldContent(contentType, field, fieldContent) { loadOriginalFieldContent(contentType, field, fieldContent) {
for(let type in fieldContent) { this.createInput(contentType, field, 'joinFields', fieldContent['joinFields']);
this.createInput(contentType, field, type, fieldContent[type]); this.createInput(contentType, field, 'include', fieldContent['include']);
} this.createInput(contentType, field, 'exclude', fieldContent['exclude']);
} }
/*########################################## /*##########################################
...@@ -129,7 +131,7 @@ class CustomQueries { ...@@ -129,7 +131,7 @@ class CustomQueries {
* @param contentType * @param contentType
*/ */
createContentTypeBlock(contentType) { createContentTypeBlock(contentType) {
if(!this.usedContentType[contentType] && contentType) { if (!this.usedContentType[contentType] && contentType) {
this.usedContentType[contentType] = []; this.usedContentType[contentType] = [];
let checked = ""; let checked = "";
if (jQuery.inArray(contentType, this.json['all']) !== -1) { if (jQuery.inArray(contentType, this.json['all']) !== -1) {
...@@ -137,7 +139,7 @@ class CustomQueries { ...@@ -137,7 +139,7 @@ class CustomQueries {
} }
$(this.selectors.listContentTypeContainer).append( $(this.selectors.listContentTypeContainer).append(
`<fieldset class="bolt-field-repeater"> `<fieldset class="bolt-field-repeater">
<div class="repeater-slot contentType ${contentType}"> <div class="repeater-slot contentType ${contentType}" data-content-type="${contentType}">
<div class="repeater-group panel panel-default"> <div class="repeater-group panel panel-default">
<div class="panel-heading text-right"> <div class="panel-heading text-right">
<div class="pull-left title"> <div class="pull-left title">
...@@ -197,7 +199,7 @@ class CustomQueries { ...@@ -197,7 +199,7 @@ class CustomQueries {
* @param value * @param value
*/ */
fillContentTypeSelector(value) { fillContentTypeSelector(value) {
$(this.selectors.selectContentType).append('<option value="'+value+'">'+value+'</option>'); $(this.selectors.selectContentType).append('<option value="' + value + '">' + value + '</option>');
} }
/** /**
...@@ -206,13 +208,13 @@ class CustomQueries { ...@@ -206,13 +208,13 @@ class CustomQueries {
* @param field * @param field
*/ */
createFieldLine(contentType, field, fieldText, joinField) { createFieldLine(contentType, field, fieldText, joinField) {
if(!joinField || (joinField != 'or' && joinField != 'and')) { if (!joinField || (joinField != 'or' && joinField != 'and')) {
joinField = 'and'; joinField = 'and';
} }
let andChecked = (joinField == 'and') ? 'checked': ''; let andChecked = (joinField == 'and') ? 'checked' : '';
let orChecked = (joinField == 'or') ? 'checked': ''; let orChecked = (joinField == 'or') ? 'checked' : '';
let container = $(this.selectors.listContentTypeContainer+' .contentType.'+contentType+' tbody'); let container = $(this.selectors.listContentTypeContainer + ' .contentType.' + contentType + ' tbody');
container.append(` container.append(`
<tr class="field-${field}"> <tr class="field-${field}">
<td>${fieldText}</td> <td>${fieldText}</td>
...@@ -238,25 +240,26 @@ class CustomQueries { ...@@ -238,25 +240,26 @@ class CustomQueries {
this.initEventClickBtnRemoveField(contentType, field); this.initEventClickBtnRemoveField(contentType, field);
this.initEventChaneToggleField(contentType, field); this.initEventChaneToggleField(contentType, field);
} }
/** /**
* Create Input in Field line * Create Input in Field line
* @param contentType * @param contentType
* @param field * @param field
*/ */
createInput(contentType, field, type, values) { createInput(contentType, field, type, values) {
let container = $(this.selectors.listContentTypeContainer+' .contentType.'+contentType+' tbody .field-'+field+' .'+type); let container = $(this.selectors.listContentTypeContainer + ' .contentType.' + contentType + ' tbody .field-' + field + ' .' + type);
let input = '<select class="tags form-control" id="field-'+contentType+'-'+field+'-'+type+'" multiple="true">'; let input = '<select class="tags form-control" id="field-' + contentType + '-' + field + '-' + type + '" multiple="true">';
if(values) { if (values) {
for(let index in values) { for (let index in values) {
input += '<option value="'+values[index]+'" selected>'+values[index]+'</option>'; input += '<option value="' + values[index] + '" selected>' + values[index] + '</option>';
} }
} }
input += '</select>'; input += '</select>';
container.append(input); container.append(input);
let selector = $('#field-'+contentType+'-'+field+'-'+type); let selector = $('#field-' + contentType + '-' + field + '-' + type);
this.initEventSelectTags(selector); this.initEventSelectTags(selector);
} }
...@@ -267,8 +270,8 @@ class CustomQueries { ...@@ -267,8 +270,8 @@ class CustomQueries {
* @param text * @param text
*/ */
fillFieldSelector(contentType, value, text) { fillFieldSelector(contentType, value, text) {
if(this.usedContentType[contentType].indexOf(value) === -1) { if (this.usedContentType[contentType].indexOf(value) === -1) {
$('#chooseField-'+this.name+'-'+contentType).append('<option value="'+value+'">'+text+'</option>'); $('#chooseField-' + this.name + '-' + contentType).append('<option value="' + value + '">' + text + '</option>');
} }
} }
...@@ -292,9 +295,9 @@ class CustomQueries { ...@@ -292,9 +295,9 @@ class CustomQueries {
$(this.selectors.addContentTypeBtn).on('click', (e) => { $(this.selectors.addContentTypeBtn).on('click', (e) => {
e.preventDefault(); e.preventDefault();
$(this.selectors.addContentTypeBtn).hide(); $(this.selectors.addContentTypeBtn).hide();
$(this.selectors.selectContentType+' option').remove(); $(this.selectors.selectContentType + ' option').remove();
for(let index in this.config) { for (let index in this.config) {
if(!this.usedContentType[index]) { if (!this.usedContentType[index]) {
this.fillContentTypeSelector(index); this.fillContentTypeSelector(index);
} }
} }
...@@ -307,6 +310,7 @@ class CustomQueries { ...@@ -307,6 +310,7 @@ class CustomQueries {
$(this.selectors.selectContentType).parent().hide(); $(this.selectors.selectContentType).parent().hide();
$(this.selectors.addContentTypeBtn).show(); $(this.selectors.addContentTypeBtn).show();
this.createContentTypeBlock($(this.selectors.selectContentType).val()); this.createContentTypeBlock($(this.selectors.selectContentType).val());
this.rebuildJson();
}); });
// Content type cancel btn // Content type cancel btn
...@@ -322,13 +326,13 @@ class CustomQueries { ...@@ -322,13 +326,13 @@ class CustomQueries {
* @param contentType * @param contentType
*/ */
initEventClickBtnRemoveContentType(contentType) { initEventClickBtnRemoveContentType(contentType) {
$(this.selectors.removeContentTypeBtn+'-'+contentType).on('click', (e) => { $(this.selectors.removeContentTypeBtn + '-' + contentType).on('click', (e) => {
e.preventDefault(); e.preventDefault();
this.usedContentType = this.usedContentType.slice(this.usedContentType.indexOf(contentType)); this.usedContentType = this.usedContentType.slice(this.usedContentType.indexOf(contentType));
let index = this.usedContentType.indexOf(contentType); let index = this.usedContentType.indexOf(contentType);
this.usedContentType.splice(index, 1); this.usedContentType.splice(index, 1);
$('.listContentTypeContainer-'+this.name+' .contentType.'+contentType).remove(); $('.listContentTypeContainer-' + this.name + ' .contentType.' + contentType).remove();
this.rebuildJson(); this.rebuildJson();
}); });
...@@ -337,8 +341,8 @@ class CustomQueries { ...@@ -337,8 +341,8 @@ class CustomQueries {
/** /**
* @param contentType * @param contentType
*/ */
initEventClickAllFields(contentType){ initEventClickAllFields(contentType) {
$(this.selectors.allFields+'-'+contentType).on('click', (e) => { $(this.selectors.allFields + '-' + contentType).on('click', (e) => {
this.rebuildJson(); this.rebuildJson();
}); });
} }
...@@ -349,32 +353,33 @@ class CustomQueries { ...@@ -349,32 +353,33 @@ class CustomQueries {
*/ */
initEventClickBtnAddField(contentType) { initEventClickBtnAddField(contentType) {
// Field add btn // Field add btn
$(this.selectors.addFieldBtn+'-'+contentType).on('click', (e) => { $(this.selectors.addFieldBtn + '-' + contentType).on('click', (e) => {
e.preventDefault(); e.preventDefault();
$(this.selectors.addFieldBtn+'-'+contentType).hide(); $(this.selectors.addFieldBtn + '-' + contentType).hide();
$(this.selectors.listContentTypeContainer+' .contentType.'+contentType+' .headField select option').remove(); $(this.selectors.listContentTypeContainer + ' .contentType.' + contentType + ' .headField select option').remove();
if(this.config[contentType] && this.config[contentType]['fields']) { if (this.config[contentType] && this.config[contentType]['fields']) {
/*console.log(this.config[contentType]['fields']);*/ for (let index in this.config[contentType]['fields']) {
for(let index in this.config[contentType]['fields']) {
let text = index; let text = index;
if(this.config[contentType]['fields'][index].label) { if (this.config[contentType]['fields'][index].label) {
text = this.config[contentType]['fields'][index].label; text = this.config[contentType]['fields'][index].label;
} }
this.fillFieldSelector(contentType, index, text); this.fillFieldSelector(contentType, index, text);
} }
} }
$(this.selectors.listContentTypeContainer+' .contentType.'+contentType+' .headField').show();
});
$('.chooseField').select2();
setTimeout(function () {
$('.chooseField').select2();
}, 1);
$(this.selectors.listContentTypeContainer + ' .contentType.' + contentType + ' .headField').show();
});
// Field validate btn // Field validate btn
$(this.selectors.validateFieldBtn+'-'+contentType).on('click', (e) => { $(this.selectors.validateFieldBtn + '-' + contentType).on('click', (e) => {
e.preventDefault(); e.preventDefault();
$(this.selectors.listContentTypeContainer+' .contentType.'+contentType+' .headField').hide(); $(this.selectors.listContentTypeContainer + ' .contentType.' + contentType + ' .headField').hide();
$(this.selectors.addFieldBtn+'-'+contentType).show(); $(this.selectors.addFieldBtn + '-' + contentType).show();
let field = $('#chooseField-'+this.name+'-'+contentType).val(); let field = $('#chooseField-' + this.name + '-' + contentType).val();
let fieldText = $('#chooseField-'+this.name+'-'+contentType+' option:selected').text(); let fieldText = $('#chooseField-' + this.name + '-' + contentType + ' option:selected').text();
this.createFieldLine(contentType, field, fieldText); this.createFieldLine(contentType, field, fieldText);
this.createInput(contentType, field, 'include'); this.createInput(contentType, field, 'include');
...@@ -384,10 +389,10 @@ class CustomQueries { ...@@ -384,10 +389,10 @@ class CustomQueries {
}); });
// Field cancel btn // Field cancel btn
$(this.selectors.cancelFieldBtn+'-'+contentType).on('click', (e) => { $(this.selectors.cancelFieldBtn + '-' + contentType).on('click', (e) => {
e.preventDefault(); e.preventDefault();
$(this.selectors.listContentTypeContainer+' .contentType.'+contentType+' .headField').hide(); $(this.selectors.listContentTypeContainer + ' .contentType.' + contentType + ' .headField').hide();
$(this.selectors.addFieldBtn+'-'+contentType).show(); $(this.selectors.addFieldBtn + '-' + contentType).show();
}); });
} }
...@@ -397,9 +402,9 @@ class CustomQueries { ...@@ -397,9 +402,9 @@ class CustomQueries {
* @param field * @param field
*/ */
initEventClickBtnRemoveField(contentType, field) { initEventClickBtnRemoveField(contentType, field) {
$(this.selectors.removeFieldBtn+'-'+contentType+'-'+field).on('click', (e) => { $(this.selectors.removeFieldBtn + '-' + contentType + '-' + field).on('click', (e) => {
e.preventDefault(); e.preventDefault();
$(this.selectors.listContentTypeContainer+' .contentType.'+contentType+' .field-'+field).remove(); $(this.selectors.listContentTypeContainer + ' .contentType.' + contentType + ' .field-' + field).remove();
// removed used field // removed used field
this.rebuildJson(); this.rebuildJson();
...@@ -411,7 +416,7 @@ class CustomQueries { ...@@ -411,7 +416,7 @@ class CustomQueries {
* @param selector * @param selector
*/ */
initEventSelectTags(selector) { initEventSelectTags(selector) {
selector.select2({width:"100%",tags:true,minimumInputLength:1,tokenSeparators:[',']}); selector.select2({width: "100%", tags: true, minimumInputLength: 1, tokenSeparators: [',']});
selector.on("select2:select", (e) => { selector.on("select2:select", (e) => {
this.rebuildJson(); this.rebuildJson();
...@@ -428,10 +433,10 @@ class CustomQueries { ...@@ -428,10 +433,10 @@ class CustomQueries {
* @param field * @param field
*/ */
initEventChaneToggleField(contentType, field) { initEventChaneToggleField(contentType, field) {
$('#or-'+contentType+'-'+field).on('click', (e) => { $('#or-' + contentType + '-' + field).on('click', (e) => {
this.rebuildJson(); this.rebuildJson();
}); });
$('#and-'+contentType+'-'+field).on('click', (e) => { $('#and-' + contentType + '-' + field).on('click', (e) => {
this.rebuildJson(); this.rebuildJson();
}); });
} }
...@@ -441,20 +446,28 @@ class CustomQueries { ...@@ -441,20 +446,28 @@ class CustomQueries {
*/ */
rebuildJson() { rebuildJson() {
let json = { let json = {
all: {} all: []
}; };
$('.contentType').each(function () {
let contentType = $(this).data('contentType');
if (!json[contentType]) {
json[contentType] = {};
}
});
$('.tags').each(function () { $('.tags').each(function () {
let id = $(this).attr('id').split('-'); let id = $(this).attr('id').split('-');
let value = $(this).select2('val'); let value = $(this).select2('val');
if(value) { if (value) {
let joinFields = 'and'; let joinFields = 'and';
if($('#or-'+id[1]+'-'+id[2]).is(":checked")) { if ($('#or-' + id[1] + '-' + id[2]).is(":checked")) {
joinFields = 'or'; joinFields = 'or';
} }
if(!json[id[1]]) { if (!json[id[1]]) {
json[id[1]] = {}; json[id[1]] = {};
} }
if(!json[id[1]][id[2]]) { if (!json[id[1]][id[2]]) {
json[id[1]][id[2]] = { json[id[1]][id[2]] = {
joinFields: joinFields joinFields: joinFields
}; };
...@@ -462,12 +475,13 @@ class CustomQueries { ...@@ -462,12 +475,13 @@ class CustomQueries {
json[id[1]][id[2]][id[3]] = value; json[id[1]][id[2]][id[3]] = value;
} }
}); });
$('.allCheckbox input').each(function () { $('.allCheckbox input').each(function (e) {
if($(this).is(':checked')) { if ($(this).is(':checked')) {
let contentType = $(this).attr('id').replace('allFields-list-', ''); let contentType = $(this).attr('id').replace('allFields-list-', '');
json.all.push(contentType); json.all.push(contentType);
} }
}); });
/*console.log(json);*/ /*console.log(json);*/
this.element.val(JSON.stringify(json)); this.element.val(JSON.stringify(json));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment