UNPKG

gumga-query-filter-ng

Version:

Gumga Query Filter

27 lines (18 loc) 47.7 kB
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ "use strict";function HQLFactory($filter){function useType(type){return SUPPORTED_TYPES[type]||null}function hqlObjectCreator(){var hqls=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],hqlObjects=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return hqlObjects.contains={hql:" contains ",label:" contém ",before:" like '%",after:"%'"},hqlObjects.not_contains={hql:" not_contains ",label:" não contém ",before:" not like '%",after:"%'"},hqlObjects.starts_with={hql:" starts_with ",label:" começa com ",before:" like '",after:"%'"},hqlObjects.ends_with={hql:" ends_with ",label:" termina com ",before:" like '%",after:"'"},hqlObjects.eq={hql:" eq ",label:" igual ",before:" = '",after:"'"},hqlObjects.ne={hql:" ne ",label:" diferente de ",before:" != '",after:"'"},hqlObjects.ge={hql:" ge ",label:" maior igual ",before:" >= '",after:"'"},hqlObjects.gt={hql:" gt ",label:" maior que ",before:" > ",after:""},hqlObjects.le={hql:" le ",label:" menor igual ",before:" <= ",after:""},hqlObjects.lt={hql:" lt ",label:" menor que ",before:" < '",after:"'"},hqlObjects.in={hql:" in ",label:" em",before:" in (",after:")"},hqlObjects.is={hql:" is ",label:" está ",before:" is ",after:""},hqlObjects.date_eq={hql:" eq ",label:" igual ",before:" >= ",after:""},hqlObjects.date_ne={hql:" ne ",label:" diferente de ",before:" <= ",after:""},hqls.map(function(value){return hqlObjects[value]})}function createHql(){var mapObj=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},aqo=[],aq=Object.keys(mapObj).filter(function(value){return mapObj[value].active&&mapObj[value].query.value}).map(function(val){var attribute="obj.".concat(mapObj[val].query.attribute?mapObj[val].query.attribute.field:"*"),before=mapObj[val].query.condition?mapObj[val].query.condition.before:"*",value=mapObj[val].query.value.replace?mapObj[val].query.value.replace(/'/g,"''"):mapObj[val].query.value,after=mapObj[val].query.condition?mapObj[val].query.condition.after:"*";if(mapObj[val].query.attribute)switch(mapObj[val].query.attribute.type){case"date":var date=value.split("");value=""+date[4]+date[5]+date[6]+date[7]+"-"+date[2]+date[3]+"-"+date[0]+date[1];var valueBefore="'"+value+" 00:00:00'",valueAfter="'"+value+" 23:59:59'";switch(mapObj[val].query.condition.hql){case" eq ":value=valueBefore+" AND "+attribute+" <= "+valueAfter;break;case" ne ":value=valueBefore+" OR "+attribute+" >= "+valueAfter;break;case" le ":case" gt ":value=valueAfter}value=value;break;case"enum":value="'"+mapObj[val].query.value.join("','")+"'";break;case"number":case"float":case"money":before=before.replace(/'/g,""),after=after.replace(/'/g,"")}return aqo.push({attribute:mapObj[val].query.attribute,condition:mapObj[val].query.condition,value:mapObj[val].query.value.replace?mapObj[val].query.value.replace(/'/g,"''"):mapObj[val].query.value}),attribute.concat(before).concat(value).concat(after).replace(/obj.\*/g,"").replace(/\*/g,"")}).filter(function(item,idx,ary){var operators=["OR","AND"];if(-1===operators.indexOf(item))return!0;var previousValue=ary[idx-1],nextValue=ary[idx+1];if(void 0!==previousValue&&-1===operators.indexOf(previousValue)&&void 0!==nextValue&&-1===operators.indexOf(nextValue))return!0;return!1}).join(" ");if("ND"===aq.slice(-2)||"OR"===aq.slice(-2))return aqo.pop(),{hql:aq.slice(0,-3),source:JSON.stringify(aqo)};if(aq)return{hql:aq,source:JSON.stringify(aqo)};return{}}function validator(){var type=arguments.length>0&&void 0!==arguments[0]?arguments[0]:" ";return SUPPORTED_TYPES[type]?SUPPORTED_TYPES[type].validator:angular.noop}var CPF_REGEX=/[0-9]{3}\.[0-9]{3}\.[0-9]{3}\-[0-9]{2}/,CNPJ_REGEX=/[0-9]{2}\.?[0-9]{3}\.?[0-9]{3}\/?[0-9]{4}\-?[0-9]{2}/,DATE_REGEX=/[0-9]{2}\/[0-9]{2}\/[0-9]{4}/,URL_REGEX=/^[a-z][a-z\d.+-]*:\/*(?:[^:@]+(?::[^@]+)?@)?(?:[^\s:\/?#]+|\[[a-f\d:]+\])(?::\d+)?(?:\/[^?#]*)?(?:\?[^#]*)?(?:#.*)?$/i,IP_REGEX=/(?:[0-9]{1,3}\.){3}[0-9]{1,3}/,NUMBER_REGEX=/^[0-9]+$/,FLOAT_REGEX=/^[0-9]+(\.[0-9]{1,2})?$/,SUPPORTED_TYPES={};SUPPORTED_TYPES.string={validator:function validator(string){return"string"==typeof string||string instanceof String},defaultCondition:hqlObjectCreator(["contains"]),conditions:hqlObjectCreator(["eq","ne","contains","not_contains","starts_with","ends_with"]),template:'<div class="input-group">\n <input type="text" ng-keyup="goSearch($event)" ng-model="$value.query.value" class="form-control" required autofocus style=" width: 150px;height: 40px;" />\n <div class="input-group-addon">\n <i ng-show="validator($value.query.value) && $value.query.value.length > 0" class="glyphicon glyphicon-ok" style="color:green"></i></span>\n <i ng-show="!validator($value.query.value) || !$value.query.value" class="glyphicon glyphicon-remove" style="color:red"></i>\n </div>\n <div class="input-group-addon">\n <button ng-click="callSearch($event, \'btn\')" class="btn btn-default">Buscar</button>\n </div>\n </div>'},SUPPORTED_TYPES.number={validator:function validator(str){return NUMBER_REGEX.test(str)},defaultCondition:hqlObjectCreator(["eq"]),conditions:hqlObjectCreator(["eq","ne","gt","ge","lt","le"]),template:'<div class="input-group">\n <input type="text" ng-keyup="goSearch($event)" ng-model="$value.query.value" class="form-control" gumga-number required style=" width: 150px;height: 40px;" />\n <div class="input-group-addon">\n <i ng-show="validator($value.query.value)" class="glyphicon glyphicon-ok" style="color:green"></i></span>\n <i ng-show="!validator($value.query.value)" class="glyphicon glyphicon-remove" style="color:red"></i>\n </div>\n <div class="input-group-addon">\n <button ng-click="callSearch($event, \'btn\')" class="btn btn-default">Buscar</button>\n </div>\n </div>'},SUPPORTED_TYPES.float={validator:function validator(number){return FLOAT_REGEX.test(number)},defaultCondition:hqlObjectCreator(["eq"]),conditions:hqlObjectCreator(["eq","ne","gt","ge","lt","le"]),template:'<div class="input-group">\n <input type="text" ng-keyup="goSearch($event)" ng-model="$value.query.value" class="form-control" gumga-number required style=" width: 150px;height: 40px;"/> \n <div class="input-group-addon">\n <i ng-show="validator($value.query.value)" class="glyphicon glyphicon-ok" style="color:green"></i></span>\n <i ng-show="!validator($value.query.value)" class="glyphicon glyphicon-remove" style="color:red"></i>\n </div>\n <div class="input-group-addon">\n <button ng-click="callSearch($event, \'btn\')" class="btn btn-default">Buscar</button>\n </div>\n </div>'},SUPPORTED_TYPES.money={validator:function validator(number){return FLOAT_REGEX.test(number)},defaultCondition:hqlObjectCreator(["eq"]),conditions:hqlObjectCreator(["eq","ne","gt","ge","lt","le"]),template:'<div class="input-group">\n <input ng-keyup="goSearch($event)" type="text" ng-model="$value.query.value" gumga-mask="R$ " class="form-control" gumga-number required style=" width: 150px;height: 40px;" />\n <div class="input-group-addon">\n <i ng-show="validator($value.query.value)" class="glyphicon glyphicon-ok" style="color:green"></i></span>\n <i ng-show="!validator($value.query.value)" class="glyphicon glyphicon-remove" style="color:red"></i>\n </div>\n <div class="input-group-addon">\n <button ng-click="callSearch($event, \'btn\')" class="btn btn-default">Buscar</button>\n </div>\n </div>'},SUPPORTED_TYPES.cpf={validator:function validator(cpf){return CPF_REGEX.test(utils.toCpf(cpf))},defaultCondition:hqlObjectCreator(["eq"]),conditions:hqlObjectCreator(["eq","ne","contains","not_contains","starts_with","ends_with"]),template:'<div class="input-group">\n <input type="text" ng-keyup="goSearch($event)" ng-model="$value.query.value" gumga-mask="999.999.999.99" class="form-control" required style=" width: 150px;height: 40px;" />\n <div class="input-group-addon">\n <i ng-show="validator($value.query.value) && $value.query.value.length > 0" class="glyphicon glyphicon-ok" style="color:green"></i></span>\n <i ng-show="!validator($value.query.value) || !$value.query.value" class="glyphicon glyphicon-remove" style="color:red"></i>\n </div>\n <div class="input-group-addon">\n <button ng-click="callSearch($event, \'btn\')" class="btn btn-default">Buscar</button>\n </div>\n </div>'},SUPPORTED_TYPES.cnpj={validator:function validator(cnpj){return CNPJ_REGEX.test(cnpj)},defaultCondition:hqlObjectCreator(["eq"]),conditions:hqlObjectCreator(["eq","ne","contains","not_contains","starts_with","ends_with"]),template:'<div class="input-group">\n <input type="text" ng-keyup="goSearch($event)" ng-model="$value.query.value" gumga-mask="99.999.999/9999-99" class="form-control" required style=" width: 150px;height: 40px;" />\n <div class="input-group-addon">\n <i ng-show="validator($value.query.value) && $value.query.value.length > 0" class="glyphicon glyphicon-ok" style="color:green"></i></span>\n <i ng-show="!validator($value.query.value) || !$value.query.value" class="glyphicon glyphicon-remove" style="color:red"></i>\n </div>\n <div class="input-group-addon">\n <button ng-click="callSearch($event, \'btn\')" class="btn btn-default">Buscar</button>\n </div>\n </div>'},SUPPORTED_TYPES.boolean={validator:function validator(boolean){return"true"==boolean||"false"==boolean},defaultCondition:hqlObjectCreator(["is"]),conditions:hqlObjectCreator(["is"]),template:' <div class="radio"><label><input type="radio" ng-model="$value.query.value" value="true"> {{$value.query.attribute.extraProperties.trueLabel}}</label></div><div class="radio"><label><input type="radio" ng-model="$value.query.value" value="false"> {{$value.query.attribute.extraProperties.falseLabel}} </label></div>'},SUPPORTED_TYPES.date={validator:function validator(date){return DATE_REGEX.test($filter("date")(date,"dd/MM/yyyy"))},defaultCondition:hqlObjectCreator(["date_eq"]),conditions:hqlObjectCreator(["date_eq","date_ne","gt","ge","lt","le"]),template:'<div class="input-group">\n <input type="text" ng-keyup="goSearch($event)" ng-model="$value.query.value" gumga-mask="99/99/9999" class="form-control" required style=" width: 150px;height: 40px;"/>\n <div class="input-group-addon">\n <i ng-show="validator($value.query.value) && $value.query.value.length > 0" class="glyphicon glyphicon-ok" style="color:green"></i></span>\n <i ng-show="!validator($value.query.value) || !$value.query.value" class="glyphicon glyphicon-remove" style="color:red"></i>\n </div>\n <div class="input-group-addon">\n <button ng-click="callSearch($event, \'btn\')" class="btn btn-default">Buscar</button>\n </div>\n </div>'},SUPPORTED_TYPES.select={validator:function validator(value){return!!value},defaultCondition:hqlObjectCreator(["eq"]),conditions:hqlObjectCreator(["eq","ne"]),template:'<select ng-model="$value.query.value" ng-options="d.field as d.label for d in $value.query.attribute.extraProperties.data track by d.field" class="form-control" required /></select>'},SUPPORTED_TYPES.enum={validator:function validator(enumList){return Array.isArray(enumList)},defaultCondition:hqlObjectCreator(["in"]),conditions:hqlObjectCreator(["in"]),template:'<div class="col-md-4" ng-class="{\'row\': $index % 3 == 0}" ng-repeat="d in $value.query.attribute.extraProperties.data"><label><input type="checkbox" ng-checked="$value.query.value.indexOf(d.field) > -1" ng-click="toggleEnum($event, $key, d.field)"></label> {{d.label}}</div>'},SUPPORTED_TYPES.email={validator:function validator(emailAddress){return"string"==typeof emailAddress||emailAddress instanceof String},defaultCondition:hqlObjectCreator(["eq"]),conditions:hqlObjectCreator(["eq","ne","contains","not_contains","starts_with","ends_with"]),template:'<div class="input-group">\n <input type="text" ng-keyup="goSearch($event)" ng-model="$value.query.value" class="form-control" required style=" width: 150px;height: 40px;" />\n <div class="input-group-addon">\n <i ng-show="validator($value.query.value) && $value.query.value.length > 0" class="glyphicon glyphicon-ok" style="color:green"></i></span>\n <i ng-show="!validator($value.query.value) || !$value.query.value" class="glyphicon glyphicon-remove" style="color:red"></i>\n </div>\n <div class="input-group-addon">\n <button ng-click="callSearch($event, \'btn\')" class="btn btn-default">Buscar</button>\n </div>\n </div>'},SUPPORTED_TYPES.url={validator:function validator(url){return URL_REGEX.test(url)},defaultCondition:hqlObjectCreator(["eq"]),conditions:hqlObjectCreator(["eq","ne","contains","not_contains","starts_with","ends_with"]),template:'<div class="input-group">\n <input type="url" ng-keyup="goSearch($event)" ng-model="$value.query.value" class="form-control" required style=" width: 150px;height: 40px;" />\n <div class="input-group-addon">\n <i ng-show="validator($value.query.value) && $value.query.value.length > 0" class="glyphicon glyphicon-ok" style="color:green"></i></span>\n <i ng-show="!validator($value.query.value) || !$value.query.value" class="glyphicon glyphicon-remove" style="color:red"></i>\n </div>\n <div class="input-group-addon">\n <button ng-click="callSearch($event, \'btn\')" class="btn btn-default">Buscar</button>\n </div>\n </div>'},SUPPORTED_TYPES.ip={validator:function validator(ip){return IP_REGEX.test(ip)},defaultCondition:hqlObjectCreator(["eq"]),conditions:hqlObjectCreator(["eq","ne","contains","not_contains","starts_with","ends_with"]),template:'<div class="input-group">\n <input type="text" ng-keyup="goSearch($event)" ng-model="$value.query.value" class="form-control" required style=" width: 150px;height: 40px;" />\n <div class="input-group-addon">\n <i ng-show="validator($value.query.value) && $value.query.value.length > 0" class="glyphicon glyphicon-ok" style="color:green"></i></span>\n <i ng-show="!validator($value.query.value) || !$value.query.value" class="glyphicon glyphicon-remove" style="color:red"></i>\n </div>\n <div class="input-group-addon">\n <button ng-click="callSearch($event, \'btn\')" class="btn btn-default">Buscar</button>\n </div>\n </div>'};var utils={toCpf:function toCpf(input){return(input+"").replace(/\D/g,"").replace(/(\d{3})(\d)/,"$1.$2").replace(/(\d{3})(\d)/,"$1.$2").replace(/(\d{3})(\d{1,2})$/,"$1-$2")}};return{useType:useType,hqlObjectCreator:hqlObjectCreator,createHql:createHql,validator:validator}}HQLFactory.$inject=["$filter"],angular.module("gumga.queryfilter.factory.hql",[]).factory("HQLFactory",HQLFactory); },{}],2:[function(require,module,exports){ "use strict";require("./hql-factory.js"),require("./query-model-factory.js"),angular.module("gumga.queryfilter.factory",["gumga.queryfilter.factory.hql","gumga.queryfilter.factory.querymodel"]); },{"./hql-factory.js":1,"./query-model-factory.js":3}],3:[function(require,module,exports){ "use strict";function QueryModelFactory(){function QueryModel(){var query=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},active=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],initialState=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"NOTHING",zIndex=arguments.length>3&&void 0!==arguments[3]?arguments[3]:999;this.STATES=Object.freeze({NOTHING:1,ONLY_ATTRIBUTE:2,ATTRIBUTE_AND_CONDITION:4,EVERYTHING_NEEDED:8,UPDATING_ATTRIBUTE:16,UPDATING_CONDITION:32,UPDATING_VALUE:64}),this.query=query,this.active=active,this.activeStates=this.STATES[initialState],this.zIndex=zIndex}return QueryModel.prototype.addState=function(newState){return this.activeStates|=this.STATES[newState],this},QueryModel.prototype.removeState=function(stateToRemove){return this.activeStates&=~this.STATES[stateToRemove],this},QueryModel.prototype.isNOTHING=function(){return 0!=(this.activeStates&this.STATES.NOTHING)},QueryModel.prototype.isONLY_ATTRIBUTE=function(){return 0!=(this.activeStates&this.STATES.ONLY_ATTRIBUTE)},QueryModel.prototype.isATTRIBUTE_AND_CONDITION=function(){return 0!=(this.activeStates&this.STATES.ATTRIBUTE_AND_CONDITION)},QueryModel.prototype.isEVERYTHING_NEEDED=function(){return 0!=(this.activeStates&this.STATES.EVERYTHING_NEEDED)},QueryModel.prototype.isUPDATING_ATTRIBUTE=function(){return 0!=(this.activeStates&this.STATES.UPDATING_ATTRIBUTE)},QueryModel.prototype.isUPDATING_CONDITION=function(){return 0!=(this.activeStates&this.STATES.UPDATING_CONDITION)},QueryModel.prototype.isUPDATING_VALUE=function(){return 0!=(this.activeStates&this.STATES.UPDATING_VALUE)},QueryModel.prototype.isBeingUpdated=function(){return this.isUPDATING_VALUE()},{create:function create(){for(var _len=arguments.length,param=Array(_len),_key=0;_key<_len;_key++)param[_key]=arguments[_key];return new(Function.prototype.bind.apply(QueryModel,[null].concat(param)))}}}QueryModelFactory.$inject=[],angular.module("gumga.queryfilter.factory.querymodel",[]).factory("QueryModelFactory",QueryModelFactory); },{}],4:[function(require,module,exports){ "use strict";function Filter(HQLFactory,$compile,$timeout,$interpolate,QueryModelFactory){return{restrict:"E",template:'\n <style>\n .gumga-filter .dropdown-menu > li > a {\n cursor: pointer;\n }\n .gumga-filter .panel-body .input-group-btn {\n border: 1px solid #ccc;\n border-left-width: 2px;\n border-right-width: 2px;\n border-radius: 4px;\n }\n .gumga-filter .panel-body .input-group-btn .btn {\n border-color: transparent;\n border-radius: 4px;\n border: 1px;\n }\n .gumga-filter .panel-body .btn,\n .gumga-filter .panel-body .input-group-btn .btn {\n padding: 3px 6px;\n }\n .gumga-filter-panel {\n position: absolute;\n top: 100%;\n left: 0;\n z-index: 1000;\n display: none;\n float: left;\n min-width: 160px;\n padding: 12px;\n margin: 2px 0 0;\n font-size: 14px;\n text-align: left;\n background-color: #fff;\n border: 1px solid #ccc;\n border: 1px solid rgba(0,0,0,.15);\n border-radius: 4px;\n box-shadow: 0 6px 12px rgba(0,0,0,.175);\n background-clip: padding-box;\n }\n .gumga-filter-panel .dropdown-menu li {\n z-index: 3000;\n position: absolute;\n top: 100%;\n left: 0;\n z-index: 1000;\n display: none;\n float: left;\n min-width: 160px;\n padding: 12px;\n margin: 2px 0 0;\n font-size: 14px;\n text-align: left;\n background-color: #fff;\n border: 1px solid #ccc;\n border: 1px solid rgba(0,0,0,.15);\n border-radius: 4px;\n box-shadow: 0 6px 12px rgba(0,0,0,.175);\n background:-clip padding-box;\n }\n gumga-filter .panel.heading {\n padding: 5px 10px;\n }\n gumga-filter .form-inline.panel-body .input-group {\n margin-right: 5px;\n }\n gumga-filter .form-inline.panel-body .input-group-btn > button,\n gumga-filter .form-inline.panel-body .input-group-btn > btn-group > button[uib-dropdown-toggle] {\n z-index: 0;\n }\n gumga-filter .form-inline.panel-body .input-group-btn > btn-group > ul[uib-dropdown-menu],\n gumga-filter .form-inline.panel-body .input-group-btn > btn-group > ul[uib-dropdown-menu] > li {\n z-index: 3000;\n }\n gumga-filter .btn-group.dropdown .glyphicon {\n top: 3px;\n }\n gumga-query .row.replace-filter {\n margin-top: .5%;\n }\n </style>\n <div class="gumga-filter panel panel-default" >\n <header class="panel-heading" style="padding: 5px 10px;">\n <div class="row">\n <div class="col-md-8 col-xs-7">\n <h5>Pesquisa avançada <strong ng-if="filterSelectItem"> - {{filterSelectItem.description}}</strong></h5>\n </div>\n <div class="col-md-4 col-xs-5" ng-show="saveQuery">\n <div class="input-group" >\n <input type="text" ng-model="nameSearch" class="form-control" id="_save" ng-show="saveFilterOpen" ng-keyup="saveSearch(nameSearch, $event)" ng-blur="closeInput()">\n <div class="input-group-btn">\n <button class="btn btn-success" ng-show="saveFilterOpen" ng-click="saveSearch(nameSearcht)" ng-disabled="!nameSearch">\n <i class="glyphicon glyphicon-floppy-saved"></i>\n </button>\n <button class="btn btn-default pull-right" type="button" ng-hide="saveFilterOpen" ng-click="showInput()" ng-disabled="!isAnyQueryNotOk()">\n <i class="glyphicon glyphicon-floppy-disk"></i>\n </button>\n <button class="btn btn-default" ng-click="deleteFilter(filterSelectItem.id)" ng-if="filterSelectItem" style="float: right;margin-right: 15px;">\n <i class="glyphicon glyphicon-floppy-remove"></i>\n </button>\n </div>\n </div>\n </div>\n </div>\n </header>\n <div class="form-inline panel-body">\n <div class="row">\n <div class="col-md-6">\n <h5><strong>Filtrar por:</strong></h5>\n </div>\n <div class="col-md-6">\n <button id="single-button" type="button" class="btn btn-default pull-right" ng-click="clearQuery()" ng-disabled="!isAnyQueryNotOk()" >\n <i class="glyphicon glyphicon-repeat"></i> Limpar filtros\n </button>\n </div>\n </div>\n <div class="input-group" ng-repeat="($key, $value) in controlMap" style="margin-right: 1%;margin-top: 7.5px;z-index: {{$value.zIndex}}" ng-show="$value.active" id="first" >\n <div class="input-group-btn">\n <div class="btn-group" uib-dropdown ng-show="!$value.query.label" is-open="$value.isUPDATING_ATTRIBUTE()" auto-close="disabled">\n <button type="button" style="z-index: 0" class="btn btn-default" uib-dropdown-toggle ng-click="toggleUpdatingAttribute(this)" ng-disabled="$value.isUPDATING_VALUE() || $value.isUPDATING_CONDITION() || (!isAnyQueryNotOk() && $value.isEVERYTHING_NEEDED()) ">\n <span> {{ $value.query.attribute.label || \'Atributo\' }} <i class="glyphicon glyphicon-chevron-down"></i></span>\n </button>\n <ul uib-dropdown-menu style="z-index: 3000" role="menu">\n <li style="z-index: 3000;" role="menuitem" ng-repeat="attribute in _attributes track by $index">\n <a ng-click="addAttribute(attribute, this.$parent, $key)">{{attribute.label}}</a>\n </li>\n </ul>\n </div>\n <div class="btn-group" uib-dropdown is-open="$value.isUPDATING_CONDITION()" ng-show="!$value.query.label" auto-close="disabled">\n <button type="button" class="btn btn-default" uib-dropdown-toggle ng-click="toggleUpdatingCondition(this)" ng-disabled="$value.isUPDATING_VALUE() || $value.isUPDATING_ATTRIBUTE() || (!isAnyQueryNotOk() && $value.isEVERYTHING_NEEDED()) || $value.isNOTHING()">\n <span>{{ $value.query.condition.label || \'Condição\' }} <i class="glyphicon glyphicon-chevron-down"></i></span>\n </button>\n <ul uib-dropdown-menu role="menu" >\n <li role="menuitem" ng-repeat="condition in conditions track by $index">\n <a ng-click="addCondition(condition, this.$parent, $key)">{{condition.label}}</a>\n </li>\n </ul>\n </div>\n <div class="btn-group" id="_btnValue{{$key}}" ng-show="!$value.query.label">\n <button type="button" class="btn btn-default" ng-click="toggleUpdatingValue(this, $key)" ng-disabled="validatonValue($value)" id="_valueLabel{{$key}}">\n <span id="_conditionLabel{{$key}}">{{ $value.query.value ? $value.query.value.push && $value.query.value.length > 0 ? $value.query.value.join(\', \') : $value.query.value : \'valor\' | gumgaGenericFilter:$value.query.attribute.type}} </span>\n </button>\n <div class="gumga-filter-panel" id="_panelValue{{$key}}"></div>\n </div>\n <div class="btn-group" ng-show="$value.query.label">\n <button type="button" class="btn btn-default" ng-click="updateOperator(this)" ng-disabled="!isAnyQueryNotOk()">\n <span> {{$value.query.label}} </span>\n </button>\n </div>\n <button type="button" style="z-index: 0;border-left: 1px solid #ccc; " class="btn btn-default" ng-click="removeQuery(this, $event, $index)" ng-show="!$value.query.label" ng-disabled="!$value.isEVERYTHING_NEEDED() || $value.isUPDATING_VALUE() ||(!isAnyQueryNotOk() && $value.isEVERYTHING_NEEDED()) ">\n <span class="glyphicon glyphicon-remove"></span>\n </button>\n </div>\n </div>\n <button id="single-button" type="button" class="btn btn-default" ng-click="addQuery()" ng-disabled="!isAnyQueryNotOk()" style="margin-top: 7.5px;" >\n <span class="glyphicon glyphicon-plus"></span>\n </button>\n </div>\n </div>\n </div>\n </div>',transclude:!0,scope:{search:"&",saveQuery:"&"},link:function link($scope,$element,$attrs,$ctrl,$transclude){function addAttribute(selectedAttribute,scope,key){scope.$value.query.attribute=selectedAttribute,scope.conditions=HQLFactory.useType(selectedAttribute.type).conditions,scope.validator=HQLFactory.useType(selectedAttribute.type).validator,scope.$value.removeState("UPDATING_ATTRIBUTE").removeState("NOTHING").addState("ONLY_ATTRIBUTE"),$timeout(function(){scope.$value.addState("UPDATING_CONDITION"),scope.$value.isEVERYTHING_NEEDED()&&(scope.$value.removeState("EVERYTHING_NEEDED"),scope.$value.query.value="")})}function goSearch(event){13==event.keyCode&&callSearch(event)}function deleteFilter(filterId){console.log(filterId)}function toggleUpdatingAttribute(scope){scope.$value.isUPDATING_ATTRIBUTE()?scope.$value.removeState("UPDATING_ATTRIBUTE"):scope.$value.addState("UPDATING_ATTRIBUTE")}function addCondition(selectedCondition,scope,key){scope.$value.query.condition=selectedCondition,scope.$value.removeState("UPDATING_CONDITION").removeState("ONLY_ATTRIBUTE"),$timeout(function(){scope.$value.isEVERYTHING_NEEDED()?$scope.search({param:HQLFactory.createHql($scope.controlMap)}):(scope.$value.removeState("ATTRIBUTE_AND_CONDITION").addState("UPDATING_VALUE"),compileContent(key,scope))})}function compileContent(key,scope){var elm=getElm("_panelValue"+key);elm.addClass("show"),"enum"==scope.$value.query.attribute.type?elm.attr("style","width: 500px"):"enum"!==scope.$value.query.attribute.type&&elm.attr("style")&&elm.removeAttr("style"),$compile(elm.html(HQLFactory.useType(scope.$value.query.attribute.type).template).contents())(scope)}function toggleUpdatingCondition(scope){scope.$value.isUPDATING_CONDITION()?scope.$value.removeState("UPDATING_CONDITION"):scope.$value.addState("UPDATING_CONDITION")}function toggleUpdatingValue(scope,key){scope.$value.isUPDATING_VALUE()?(scope.$value.removeState("UPDATING_VALUE"),getElm("_panelValue"+key).addClass("show")):(scope.$value.addState("UPDATING_VALUE"),getElm("_panelValue"+key).addClass("show"))}function isAnyQueryNotOk(){return 0===Object.keys($scope.controlMap).filter(function(intern){return!$scope.controlMap[intern].isEVERYTHING_NEEDED()||$scope.controlMap[intern].isUPDATING_ATTRIBUTE()||$scope.controlMap[intern].isUPDATING_CONDITION()||$scope.controlMap[intern].isUPDATING_VALUE()}).filter(function(value){return parseInt(value)%2==0}).length}function lastOfControlMap(){return Object.keys($scope.controlMap)[Object.keys($scope.controlMap).length-1]}function getIndexScope(){for(var index=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,desiredScope=angular.element(document.getElementById("first")).scope();desiredScope.$index!=index&&null!=desiredScope.$$nextSibling;)desiredScope=desiredScope.$$nextSibling;return desiredScope}function validatonValue($value){return $value.isNOTHING()||$value.isUPDATING_ATTRIBUTE()||$value.isUPDATING_VALUE()||$value.isUPDATING_CONDITION()||!($value.isEVERYTHING_NEEDED()||!$value.isATTRIBUTE_AND_CONDITION())||!isAnyQueryNotOk()&&$value.isEVERYTHING_NEEDED()}function toggleEnum(event,key,field){event.stopPropagation();var elm=getElm("_panelValue"+key).scope();Array.isArray(elm.$value.query.value)||(elm.$value.query.value=[]);var index=elm.$value.query.value.indexOf(field);index>-1?elm.$value.query.value.splice(index,1):elm.$value.query.value.push(field)}function getExtraProperties(value){var properties=void 0;switch(value.getAttribute("type")){case"boolean":properties={trueLabel:value.getAttribute("true-label"),falseLabel:value.getAttribute("false-label")};break;case"select":properties={data:outerScope[value.getAttribute("data")]};break;case"enum":properties={data:outerScope[value.getAttribute("data")]}}return properties}function addQuery(){delete $scope.filterSelectItem,$scope.controlMap[parseInt(lastOfControlMap())+1]=QueryModelFactory.create({value:"AND",label:"E"},void 0,"EVERYTHING_NEEDED",zIndexInitial--),$scope.controlMap[parseInt(lastOfControlMap())+1]=QueryModelFactory.create({attribute:{},condition:{},value:""},void 0,"NOTHING",zIndexInitial--),$timeout(function(){return getIndexScope(parseInt(lastOfControlMap())).$value.addState("UPDATING_ATTRIBUTE")})}function clearQuery(){$scope.controlMap=[],initialize()}function closeInput(){$timeout(function(){$scope.saveFilterOpen=!1},200)}function showInput(){$scope.saveFilterOpen=!0,$timeout(function(){return document.getElementById("_save").focus()})}function saveSearch(name,event){event&&13!=event.keyCode||($scope.$parent.proxySave(HQLFactory.createHql($scope.controlMap),$scope.nameSearch),$scope.saveFilterOpen=!$scope.saveFilterOpen,$scope.nameSearch="")}function removeQuery(scope,e,index){if(delete $scope.filterSelectItem,!scope.$$prevSibling.$key&&!scope.$$nextSibling)return scope.$value.query={attribute:{},condition:{},value:""},scope.$value.activeStates=0,$timeout(function(){return scope.$value.addState("UPDATING_ATTRIBUTE")}),void callSearch(e,"remove",index);if(!scope.$$prevSibling.$key&&scope.$$nextSibling)return scope.$value.active=!1,scope.$$nextSibling.$value.active=!1,$timeout(function(){return scope.$$nextSibling.$destroy(),scope.$destroy()}),void callSearch(e,"remove",index);scope.$$prevSibling.$key&&(scope.$value.active=!1,scope.$$prevSibling.$value.active=!1,$timeout(function(){return scope.$$prevSibling.$destroy(),scope.$destroy()}),callSearch(e,"remove",index))}function updateOperator(scope){if("AND"===scope.$value.query.value)return scope.$value.query.value="OR",scope.$value.query.label="OU",void $scope.search({param:HQLFactory.createHql($scope.controlMap)});scope.$value.query.value="AND",scope.$value.query.label="E",$scope.search({param:HQLFactory.createHql($scope.controlMap)})}function callSearch(e,typeSearch){var positionCondition=arguments.length>2&&void 0!==arguments[2]?arguments[2]:-1,outerClick=!0,updatingValue=Object.keys($scope.controlMap).filter(function(intern){return $scope.controlMap[intern].isUPDATING_VALUE()})[0],validator=void 0;if(e.target.id=="_conditionLabel"+updatingValue||e.target.id=="_valueLabel"+updatingValue)return;if((e.target.id=="_panelValue"+updatingValue||function isPanelAParent(element,id){for(var desired=angular.element(element);0!=desired.parent().length;desired=desired.parent())if(desired[0].id=="_panelValue"+id){desired=!0;break}return!0===desired&&desired}(e.target,updatingValue))&&(outerClick=!1),$scope.controlMap[updatingValue]&&(validator=HQLFactory.validator($scope.controlMap[updatingValue].query.attribute.type)),outerClick&&validator&&validator($scope.controlMap[updatingValue].query.value)||"keyup"==e.type||"btn"==typeSearch){var scopeBeingUpdated=getElm("_panelValue"+updatingValue).scope();$timeout(function(){return scopeBeingUpdated.$value.removeState("UPDATING_VALUE").removeState("ATTRIBUTE_AND_CONDITION").addState("EVERYTHING_NEEDED")}),getElm("_panelValue"+updatingValue).removeClass("show"),$scope.search({param:HQLFactory.createHql($scope.controlMap)})}if("remove"==typeSearch){var param=0==positionCondition?{}:HQLFactory.createHql($scope.controlMap);$scope.search({param:param})}}var outerScope=$scope.$parent.$parent,zIndexInitial=999;if($scope._attributes=[],$scope.controlMap={},$scope.addCondition=addCondition,$scope.addQuery=addQuery,$scope.clearQuery=clearQuery,$scope.closeInput=closeInput,$scope.removeQuery=removeQuery,$scope.showInput=showInput,$scope.saveSearch=saveSearch,$scope.updateOperator=updateOperator,$scope.toggleEnum=toggleEnum,$scope.saveQuery=!!$attrs.saveQuery&&$scope.saveQuery,$attrs.search||console.error('É necessário atribuir uma função para o atributo SEARCH. [search="foo()"]'),$scope.$on("filter-items",function(err,data){var value=JSON.parse(data.value);$scope.controlMap={},JSON.parse(value.source).forEach(function(val,index){$scope.controlMap[index]=index%2==0?QueryModelFactory.create(val,!0,"EVERYTHING_NEEDED",zIndexInitial--):QueryModelFactory.create({value:val.value,label:"AND"===val.value?"E":"OU"},void 0,"EVERYTHING_NEEDED",zIndexInitial--)}),$scope.filterSelectItem=data,$timeout(function(){return $scope.search({param:HQLFactory.createHql($scope.controlMap)})})}),$scope.$on("openOrCloseFilter",function(event,openOrClose){if(!openOrClose)return delete $scope.filterSelectItem,Object.keys($scope.controlMap).forEach(function(key){var scope=getIndexScope(key);scope.$value.active=!1,delete $scope.controlMap[key],$timeout(function(_){return scope.$destroy()})}),void $scope.search({param:{}});$scope.controlMap[0]||initialize()}),$transclude(function(transcludeElement){var parentContext=$scope.$parent.$parent;[].slice.call(transcludeElement).forEach(function(value,$index){if("ADVANCED-SEARCH-FIELD"!==value.nodeName)return;if(!value.getAttribute("field"))return console.error("É necessário atribuir um valor ao atributo FIELD da tag ADVANCED-SEARCH-FIELD.");var field=value.getAttribute("field"),type=value.getAttribute("type"),label=value.getAttribute("label")?$interpolate(value.getAttribute("label"))(parentContext):field.charAt(0).toUpperCase().concat(field.slice(1)),extraProperties={};if(!type)return console.error("É necessário atribuir um valor ao atributo TYPE da tag ADVANCED-SEARCH-FIELD.");if(type=type.toLowerCase().trim()||"",label=label||field.charAt(0).toUpperCase()+field.slice(1),extraProperties=getExtraProperties(value),!HQLFactory.useType(type))return console.error('O tipo "{1}" passado como parâmetro para o ADVANCED-SEARCH-FIELD não é suportado.'.replace("{1}",type));$scope._attributes.push({field:field,type:type,label:label,extraProperties:extraProperties})})}),!$scope._attributes[0])return;var getElm=function getElm(string){return angular.element(document.getElementById(string))},initialize=function initialize(_){$scope.controlMap[0]=QueryModelFactory.create({attribute:{},condition:{},value:""},!0,"NOTHING",zIndexInitial--),$timeout(function(_){getIndexScope().$value.removeState("NOTHING").addState("UPDATING_ATTRIBUTE")})};initialize();var defaultAttribute=angular.copy($scope._attributes[0]);angular.copy(HQLFactory.useType(defaultAttribute.type).defaultCondition)[0];$scope.addAttribute=addAttribute,$scope.toggleUpdatingAttribute=toggleUpdatingAttribute,$scope.addCondition=addCondition,$scope.toggleUpdatingCondition=toggleUpdatingCondition,$scope.toggleUpdatingValue=toggleUpdatingValue,$scope.goSearch=goSearch,$scope.callSearch=callSearch,$scope.deleteFilter=deleteFilter,$scope.isAnyQueryNotOk=isAnyQueryNotOk,$scope.lastOfControlMap=lastOfControlMap,$scope.getIndexScope=getIndexScope,$scope.validatonValue=validatonValue,document.addEventListener("click",function(e){callSearch(e)}),document.addEventListener("keyup",function(e){27===e.keyCode&&Object.keys($scope.controlMap).forEach(function(key){var scope=getIndexScope(key);8!==scope.$value.activeStates&&(scope.$$prevSibling.$key?(scope.$$prevSibling.$value.active=!1,delete $scope.controlMap[scope.$$prevSibling.$key],$timeout(function(){return scope.$$prevSibling.$destroy()})):scope.$$nextSibling.$key?(scope.$$nextSibling.$value.active=!1,delete $scope.controlMap[scope.$$nextSibling.$key],$timeout(function(){return scope.$$nextSibling.$destroy()})):scope.$$prevSibling.$key&&scope.$$nextSibling.$key&&(scope.$$nextSibling.$value.active=!1,delete $scope.controlMap[scope.$$nextSibling.$key],$timeout(function(){return scope.$$nextSibling.$destroy()})),scope.$value.active=!1,delete $scope.controlMap[key],$timeout(function(_){return scope.$destroy()}))})})}}}Filter.$inject=["HQLFactory","$compile","$timeout","$interpolate","QueryModelFactory"],angular.module("gumga.queryfilter.filter.core",[]).directive("gumgaFilterCore",Filter); },{}],5:[function(require,module,exports){ "use strict";function Filter(HQLFactory,$compile,$timeout){return{restrict:"E",template:'\n <div>\n <button class="btn btn-default" ng-click="isOpen = !isOpen ">\n <span class="glyphicon glyphicon-filter"></span>\n </button>\n </div>\n <div id="replace"></div>\n ',transclude:!0,scope:{search:"&",saveQuery:"&",containerId:"@?"},link:function link($scope,$element,$attrs,$ctrl,$transclude){console.log("TESTE"),$scope.possibleAdvancedFields=[],$scope.search=$scope.search||angular.noop,$scope.saveQuery=$scope.saveQuery||angular.noop,$scope.containerId=$scope.containerId||"replace",$scope.proxySave=function(query){$scope.saveQuery({query:query,name:name})},$scope.proxySearch=function(param){$scope.search({param:param})},$transclude(function(transcludeElement){[].slice.call(transcludeElement).forEach(function(value){value&&"ADVANCED-SEARCH-FIELD"===value.nodeName&&$scope.possibleAdvancedFields.push(value.outerHTML)});var template='<gumga-filter-core ng-show="isOpen" search="proxySearch(param)" '+($attrs.saveQuery?'save-query="saveQuery(query, name)"':"")+">\n "+$scope.possibleAdvancedFields.reduce(function(prev,next){return prev+=next},"")+"\n </gumga-filter-core>";angular.element(document.getElementById($scope.containerId)).replaceWith($compile(template)($scope))})}}}Filter.$inject=["HQLFactory","$compile","$timeout"],angular.module("gumga.queryfilter.filter.directive",[]).directive("gumgaFilter",Filter); },{}],6:[function(require,module,exports){ "use strict";require("./filter.js"),require("./filter-core.js"),angular.module("gumga.queryfilter.filter",["gumga.queryfilter.filter.directive","gumga.queryfilter.filter.core"]); },{"./filter-core.js":4,"./filter.js":5}],7:[function(require,module,exports){ "use strict";require("./factory/index.js"),require("./query/query.js"),require("./filter/index.js"),angular.module("gumga.queryfilter",["gumga.queryfilter.query","gumga.queryfilter.filter","gumga.queryfilter.factory"]); },{"./factory/index.js":2,"./filter/index.js":6,"./query/query.js":8}],8:[function(require,module,exports){ "use strict";function Search($q,$timeout,$compile,$interpolate){function controller($scope,$element,$attrs,$transclude){function compileFilter(){var template='<gumga-filter-core ng-show="openFilter" is-open="true" search="ctrl.proxySearch(param)" '+($attrs.saveQuery?'save-query="saveQuery(query, name)"':"")+'is-query="true">'+ctrl.possibleAdvancedFields.reduce(function(prev,next){return prev+=next},"")+"</gumga-filter-core>";angular.element(document.getElementById(ctrl.containerAdvanced)).replaceWith($compile(template)($scope))}function doSearch(param){var event=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{keyCode:13},inputType=arguments[2];if(13!==event.keyCode||"TYPEAHEAD"==inputType)return;var field=Object.keys(ctrl.mapFields).filter(function(value){return!!ctrl.mapFields[value].checkbox}).reduce(function(prev,next){return prev+=next.concat(",")},"").slice(0,-1);if(0===field.length)return;ctrl.search({field:field,param:param})}function proxyFn($value){return $q.when(ctrl.savedFilters({page:location.hash}))}function filterSelect($item,$model,$label,$event){$timeout(function(){return ctrl.searchField="",$scope.$broadcast("filter-items",$item)})}var ctrl=this,hasAttr=function hasAttr(string){return!!$attrs[string]};ctrl.mapFields={},ctrl.possibleAdvancedFields=[],hasAttr("search")||console.error('É necessário passar uma função para o atributo "search". [search="foo(field, param)"]'),$transclude(function(transcludeElement){var alreadySelected=!1,parentContext=$scope.$parent;if([].slice.call(transcludeElement).forEach(function(value){if(value&&"ADVANCED-SEARCH-FIELD"===value.nodeName&&ctrl.possibleAdvancedFields.push(value.outerHTML),!value||"SEARCH-FIELD"!==value.nodeName)return;var element=angular.element(value),field=element.attr("field")?element.attr("field"):"",checkbox=!!$scope.$eval(element.attr("select")),label=element.attr("label")?$interpolate(element.attr("label"))(parentContext):field.charAt(0).toUpperCase().concat(field.slice(1));field||console.error('É necessário um parâmetro field na tag search-field.[<search-field field="foo"></search-field>]'),checkbox&&(alreadySelected=!0),ctrl.mapFields[field]={checkbox:checkbox,label:label,field:field}}),!alreadySelected){for(var first in ctrl.mapFields)break;first&&(ctrl.mapFields[first].checkbox=!0)}}),ctrl.compileFilter=compileFilter,ctrl.doSearch=doSearch,ctrl.proxyFn=proxyFn,ctrl.filterSelect=filterSelect,ctrl.advancedSearch=hasAttr("advancedSearch")?ctrl.advancedSearch:null,ctrl.containerAdvanced=hasAttr("containerAdvanced")?ctrl.containerAdvanced:"replaceFilter",ctrl.savedFilters=hasAttr("savedFilters")?ctrl.savedFilters:angular.noop,ctrl.searchText=hasAttr("searchText")?$attrs.searchText:" ",ctrl.proxySearch=function(param){return ctrl.advancedSearch({param:param})},ctrl.hasQuerySaved=!!$attrs.savedFilters,$scope.proxySave=function(query,name){return ctrl.saveQuery({query:query,name:name})},ctrl.advancedSearch&&ctrl.compileFilter(),$scope.$watch("openFilter",function(open){void 0!==open&&$scope.$broadcast("openOrCloseFilter",open)}),ctrl.checkFields=function(event,field){var someChecked=Object.keys(ctrl.mapFields).filter(function(value){return!!ctrl.mapFields[value].checkbox});1==someChecked.length&&someChecked[0]==field&&event.preventDefault(),event.stopPropagation()}}return controller.$inject=["$scope","$element","$attrs","$transclude"],{restrict:"E",scope:{search:"&",advancedSearch:"&?",containerAdvanced:"@?",savedFilters:"&?",saveQuery:"&?"},bindToController:!0,transclude:!0,controllerAs:"ctrl",controller:controller,template:'\n <div class="input-group">\n <input type="text" placeholder="Busque seus filtros salvos" class="form-control" ng-model="ctrl.searchField" ng-keyup="ctrl.doSearch(ctrl.searchField, $event, \'TYPEAHEAD\')" uib-typeahead="item.description for item in ctrl.proxyFn($viewValue)" typeahead-on-select="ctrl.filterSelect($item, $model, $label, $event)" ng-show="ctrl.hasQuerySaved && openFilter"/>\n <input type="text" class="form-control" ng-model="ctrl.searchField" ng-keyup="ctrl.doSearch(ctrl.searchField, $event)" ng-show="!ctrl.hasQuerySaved || !openFilter" />\n <span class="input-group-btn" uib-dropdown uib-keyboard-nav auto-close="outsideClick">\n <button class="btn btn-default" type="button" uib-dropdown-toggle>\n <span class="glyphicon glyphicon-chevron-down"><span>\n </button>\n <ul uib-dropdown-menu role="menu" aria-labelledby="single-button" class="dropdown-menu-search">\n <li role="menuitem" ng-repeat="(key, $value) in ctrl.mapFields">\n <a class="no-padding-search-fields">\n <label ng-click="ctrl.checkFields($event, $value.field)">\n <input type="checkbox" ng-model="$value.checkbox" />\n {{::$value.label}}\n </label>\n </a>\n </li>\n </ul>\n <button class="btn btn-default" ng-click="openFilter = !openFilter">\n <span class="glyphicon glyphicon-filter"></span>\n </button>\n <button class="btn btn-primary" type="button" ng-click="ctrl.doSearch(ctrl.searchField)">\n <span> {{::ctrl.searchText}} </span>\n <span class="glyphicon glyphicon-search rotate-search-glyph"></span>\n </button>\n </span>\n </div>\n <div class="row replace-filter">\n <div class="col-md-12">\n <div id="replaceFilter"></div>\n </div>\n </div>'}}Search.$inject=["$q","$timeout","$compile","$interpolate"],angular.module("gumga.queryfilter.query",[]).directive("gumgaQuery",Search); },{}]},{},[7]) //# sourceMappingURL=gumga-query-filter.js.map