aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Magorsch <max@magorsch.de>2020-01-03 01:55:50 +0100
committerMax Magorsch <max@magorsch.de>2020-01-03 01:55:50 +0100
commit7de161a64e8199a1235d9c91981a68f99438cbf0 (patch)
treee82c97f8bb179f8c07c5178467457ded43ae2acb /app/webpack/src/javascript/index/query_generator.js
parentFix the environment variables in .travis.docker.yml (diff)
downloadpackages-5-7de161a64e8199a1235d9c91981a68f99438cbf0.tar.gz
packages-5-7de161a64e8199a1235d9c91981a68f99438cbf0.tar.bz2
packages-5-7de161a64e8199a1235d9c91981a68f99438cbf0.zip
Migrate the project from sprockets to webpacker
The asset pipeline was introduced in Rails 3.1. However, since Rails 5.1 webpacker has been available, so that it's possible to use webpack. The project has been fully migrated to use webpacker for bundeling javascripts as well as stylesheets now. This way, sprockets has been completely replaced and removed from the project. Associated gems as jquery-rails have been removed as well. Accordingly all advanced webpack functionalities are available now. The bin/first-run file as well as the Dockerfiles have been adjusted to use webpacker instead of the asset pipeline. Please note: In order to use webpacker, yarn has to be installed on the target system. Please make sure that 'yarnpkg' is in your path. Signed-off-by: Max Magorsch <max@magorsch.de>
Diffstat (limited to 'app/webpack/src/javascript/index/query_generator.js')
-rw-r--r--app/webpack/src/javascript/index/query_generator.js93
1 files changed, 93 insertions, 0 deletions
diff --git a/app/webpack/src/javascript/index/query_generator.js b/app/webpack/src/javascript/index/query_generator.js
new file mode 100644
index 0000000..17cb798
--- /dev/null
+++ b/app/webpack/src/javascript/index/query_generator.js
@@ -0,0 +1,93 @@
+function updateDropdown(self) {
+ getThirdParent(self).querySelector('button > span:first-child').innerHTML = self.innerHTML;
+}
+
+function buildAdvancedQuery(){
+ var query = ""
+ document.querySelectorAll('#search-container > .row').forEach(function(element) {
+ var term = element.querySelector('.form-control').value;
+
+ if(!term.replace(/\s/g, '').length){
+ return;
+ }else{
+ term = parseSearchTerm(term);
+ }
+
+ var operator = parseOperator(element.querySelector('.pgo-query-operator > span:first-child').innerHTML);
+ var field = element.querySelector('.pgo-query-field > span:first-child').innerHTML;
+
+ query += operator + field + ":" + term + " ";
+ });
+ document.getElementById('q').value = query;
+}
+
+function parseOperator(operator){
+ switch(operator) {
+ case "should match":
+ return "";
+ case "must match":
+ return "+";
+ case "must not match":
+ return "-";
+ default:
+ return "";
+ }
+}
+
+function parseSearchTerm(term){
+ if (/\s/.test(term) && !/^\".*\"$/.test(term)) {
+ return "\"" + term + "\""
+ }else{
+ return term
+ }
+}
+
+function addInput(self){
+ var new_input = document.querySelector('#search-container > .row').cloneNode(true);
+ resetInput(new_input);
+ document.querySelector('#search-container').append(new_input);
+ checkDeleteButtons();
+ checkAddButtons();
+}
+
+function resetInput(input) {
+ input.querySelector('.form-control').value = '';
+ input.querySelector('.pgo-query-operator > span:first-child').innerHTML = 'should match';
+ input.querySelector('.pgo-query-field > span:first-child').innerHTML = 'name';
+}
+
+function deleteInput(self){
+ getThirdParent(self).removeChild(getSecondParent(self));
+ checkDeleteButtons();
+ checkAddButtons();
+}
+
+function checkDeleteButtons(){
+ if(document.querySelectorAll('#search-container > .row').length == 1){
+ document.querySelectorAll('.pgo-query-delete-btn').forEach(function(element) {
+ element.style.display = 'none';
+ });
+ }else{
+ document.querySelectorAll('.pgo-query-delete-btn').forEach(function(element) {
+ element.style.display = 'block';
+ });
+ }
+}
+
+function checkAddButtons(){
+ document.querySelectorAll('.pgo-query-add-btn').forEach(function(element) {
+ element.style.display = 'none';
+ });
+
+ document.querySelectorAll('.pgo-query-add-btn')[document.querySelectorAll('.pgo-query-add-btn').length - 1].style.display = 'block';
+}
+
+function getThirdParent(self) {
+ return self.parentElement.parentElement.parentElement;
+}
+
+function getSecondParent(self) {
+ return self.parentElement.parentElement;
+}
+
+checkDeleteButtons(); \ No newline at end of file