gumga-controller-ng
Version:
Gumga Controller
1 lines • 14 kB
JavaScript
!function(t){function e(r){if(a[r])return a[r].exports;var o=a[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var a={};e.m=t,e.c=a,e.i=function(t){return t},e.d=function(t,a,r){e.o(t,a)||Object.defineProperty(t,a,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var a=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(a,"a",a),a},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=1)}([function(t,e,a){"use strict";function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var o=function(){function t(t,e){for(var a=0;a<e.length;a++){var r=e[a];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,a,r){return a&&t(e.prototype,a),r&&t(e,r),e}}();e.QueryObject=function(){function t(e,a){r(this,t),this.service=e,this.controller=a,this.queryObject={start:this.service.start,pageSize:this.service.pageSize}}return o(t,[{key:"page",value:function(t){return t||(t=1),this._page=t,this.queryObject.start=(t-1)*this.queryObject.pageSize,this.controller.handlingStorage(this._page,this.queryObject.pageSize),this.controller.setPageInContainer(this._page),this.controller.page=t,this}},{key:"pageSize",value:function(t){return t||(t=10),this.queryObject.pageSize=t,this._page&&this.page(this._page),this.controller.handlingStorage(this._page,this.queryObject.pageSize),this}},{key:"aq",value:function(t){return t||console.error("Ao chamar o método um aq é obrigatório informar seu hql."),this.queryObject.aq=t,this}},{key:"q",value:function(t,e){var a=this;return t||console.error("Ao chamar o método um q é obrigatório informar os atributos que serão utilizados na busca."),this.queryObject.searchFields=this.queryObject.searchFields||[],t.trim().split(",").forEach(function(t){return a.queryObject.searchFields.push(t.trim())}),this.queryObject.q=e,this}},{key:"sort",value:function(t,e){return t||(t=this.controller.storage.get("field"),e=this.controller.storage.get("way")),e||(e="asc"),null==t||null==e||"null"==t||"null"==e?this:(this.queryObject.sortField=(this.queryObject.sortField||"").concat(",").concat(t),","==this.queryObject.sortField.substring(0,1)&&(this.queryObject.sortField=this.queryObject.sortField.substring(1,this.queryObject.sortField.length)),this.queryObject.sortDir=(this.queryObject.sortDir||"").concat(",").concat(e),","==this.queryObject.sortDir.substring(0,1)&&(this.queryObject.sortDir=this.queryObject.sortDir.substring(1,this.queryObject.sortDir.length)),this)}},{key:"gQuery",value:function(t){return this.queryObject.gQuery=t,this}},{key:"send",value:function(){var t=this;return this.service.sendQueryObject||console.error("Precisamos que você atualize a versão do componente gumga-rest-ng, acesse: https://github.com/GUMGA/gumga-rest-ng/releases"),this.queryObject.searchCount=this.controller.page<=1,this.service.sendQueryObject(this.queryObject).then(function(e){return t.controller.data=e.data.values,t.controller.pageSize=e.data.pageSize,e.data.count>0&&t.controller.page<=1&&(t.controller.count=e.data.count),e})}}]),t}()},function(t,e,a){"use strict";var r=a(0);!function(){function t(t,e,a,o){var n=this;this.and=this,this.data=[],this.page=1,this.pageSize=10,this.count=0,this.records=[],this.pageModel=o,this.container=a,this.identifierOrConfiguration=e,this.storage={set:function(t,a){sessionStorage.setItem(e+"-"+t,a)},get:function(t){return sessionStorage.getItem(e+"-"+t)}},this.setPageInContainer=function(){if(!n.container[o]){var t=parseInt(n.storage.get("page")||n.page);n.container[o]=t}},this.handlingStorage=function(t,e,a,r,o){return t||(t=parseInt(n.storage.get("page")||n.page)),e||(e=parseInt(n.storage.get("pageSize")||n.pageSize)),a||(a=n.storage.get("field")),r||(r=n.storage.get("way")),o||(o=""),n.storage.set("page",t||n.page),n.storage.set("pageSize",e||n.pageSize),n.storage.set("field",a),n.storage.set("way",r),n.storage.set("param",o),{page:t,pageSize:e,field:a,way:r,param:o}},this.methods={getLatestOperation:function(){n.setPageInContainer();var t=n.storage.get("last-operation");switch(t||n.methods.get(n.storage.get("page"),n.storage.get("pageSize")),n.count||(n.count=Number(n.storage.get("count"))),t){case"get":n.methods.get(n.storage.get("page"),n.storage.get("pageSize"));break;case"sort":n.methods.sort(n.storage.get("field"),n.storage.get("way"),n.storage.get("pageSize"));break;case"search":n.methods.search(n.storage.get("field"),n.storage.get("param"),n.storage.get("pageSize"),n.storage.get("page"));break;case"asyncSearch":n.methods.asyncSearch(n.storage.get("field"),n.storage.get("param"));break;case"advancedSearch":n.methods.advancedSearch(JSON.parse(n.storage.get("param")),n.storage.get("pageSize"),n.storage.get("page"));break;case"searchWithGQuery":try{n.methods.searchWithGQuery(JSON.parse(n.storage.get("gQuery")),n.storage.get("page"),n.storage.get("pageSize"))}catch(t){n.methods.searchWithGQuery(void 0,n.storage.get("page"),n.storage.get("pageSize"))}break;case"asyncSearchWithGQuery":try{n.methods.asyncSearchWithGQuery(JSON.parse(n.storage.get("gQuery")),n.storage.get("page"),n.storage.get("pageSize"))}catch(t){n.methods.asyncSearchWithGQuery(void 0,n.storage.get("page"),n.storage.get("pageSize"))}break;default:n.methods.get(n.storage.get("page"),n.storage.get("pageSize"))}},getRecords:function(){return n.records},asyncSearch:function(e,a){n.handlingStorage(void 0,void 0,e,void 0,a);return n.storage.set("last-operation","asyncSearch"),t.getSearch(e,a).then(function(t){return n.storage.set("pageSize",t.data.pageSize),t.data.values})},asyncPost:function(e,a){return n.emit("asyncPostStart"),t.save(e)},get:function(e,a){a||(a=n.pageSize),e||(e=n.page);n.handlingStorage(e,a);return n.storage.set("last-operation","get"),n.count>0&&n.storage.set("count",n.count),n.emit("getStart"),t.get(e,a).then(function(t){n.emit("getSuccess",t.data),n.data=t.data.values,n.pageSize=t.data.pageSize,t.data.count>0&&n.storage.set("count",t.data.count),t.data.count>0&&e<=1&&(n.count=t.data.count),t.data.count||(t.data.count=Number(n.storage.get("count"))),n.storage.set("pageSize",t.data.pageSize),n.data.map(function(t){return n.records.push(t.id)})},function(t){n.emit("getError",t)}),n},getId:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return n.emit("getIdStart"),t.getById(e).then(function(t){n.emit("getIdSuccess",t.data),n.data=t.data,n.pageSize&&delete n.pageSize,n.count&&delete n.count},function(t){n.emit("getIdError",t)}),n},getNew:function(){return n.emit("getNewStart"),t.getNew().then(function(t){n.emit("getNewSuccess",t.data),n.data=t.data,n.pageSize&&delete n.pageSize,n.count&&delete n.count},function(t){n.emit("getNewError",t)}),n},put:function(e){return n.emit("putStart"),t.update(e).then(function(t){n.emit("putSuccess",t)},function(t){n.emit("putError",t)}),n},post:function(e){return n.emit("postStart"),t.save(e).then(function(t){n.emit("postSuccess",t)},function(t){n.emit("postError",t)}),n},delete:function(e){return n.emit("deleteStart"),t.deleteCollection(e).then(function(t){n.emit("deleteSuccess",t)},function(t){n.emit("deleteError",t)}),n},sort:function(e,a,r){r||(r=n.pageSize);var o=n.handlingStorage(void 0,r,e,a),i=o.page;return n.storage.set("last-operation","sort"),n.count>0&&n.storage.set("count",n.count),n.emit("sortStart"),t.sort(e,a,r,i).then(function(t){n.emit("sortSuccess",t.data),n.data=t.data.values,n.pageSize=t.data.pageSize,t.data.count>0&&n.storage.set("count",t.data.count),t.data.count>0&&i<=1&&(n.count=t.data.count),t.data.count||(t.data.count=Number(n.storage.get("count"))),n.storage.set("pageSize",t.data.pageSize)},function(t){n.emit("sortError",t)}),n},searchWithPagination:function(e,a,r,o){r||(r=n.pageSize),o||(o=n.page);n.handlingStorage(o,r,e,void 0,a);return n.count>0&&n.storage.set("count",n.count),n.emit("searchWithPaginationStart"),t.getSearch(e,a,r,o).then(function(t){return n.emit("searchWithPaginationSuccess",t.data),n.data=t.data.values,n.pageSize=t.data.pageSize,t.data.count>0&&n.storage.set("count",t.data.count),t.data.count>0&&o<=1&&(n.count=t.data.count),t.data.count||(t.data.count=Number(n.storage.get("count"))),n.storage.set("pageSize",t.data.pageSize),t},function(t){n.emit("searchWithPaginationError",t)})},search:function(e,a,r,o){r||(r=n.pageSize),o||(o=n.page);n.handlingStorage(o,r,e,void 0,a);return n.storage.set("last-operation","search"),n.count>0&&n.storage.set("count",n.count),n.emit("searchStart"),t.getSearch(e,a,r,o).then(function(t){return n.emit("searchSuccess",t.data),n.data=t.data.values,n.pageSize=t.data.pageSize,t.data.count>0&&n.storage.set("count",t.data.count),t.data.count>0&&o<=1&&(n.count=t.data.count),t.data.count||(t.data.count=Number(n.storage.get("count"))),n.storage.set("pageSize",t.data.pageSize),t},function(t){n.emit("searchError",t)}),n},advancedSearch:function(e,a,r){a||(a=n.pageSize),r||(r=n.page);n.handlingStorage(r,a,void 0,void 0,JSON.stringify(e));return n.storage.set("last-operation","advancedSearch"),n.count>0&&n.storage.set("count",n.count),n.emit("advancedSearchStart"),t.getAdvancedSearch(e,a,r).then(function(t){n.emit("advancedSearchSuccess",t.data),n.data=t.data.values,n.pageSize=t.data.pageSize,t.data.count>0&&n.storage.set("count",t.data.count),t.data.count>0&&r<=1&&(n.count=t.data.count),t.data.count||(t.data.count=Number(n.storage.get("count"))),n.storage.set("pageSize",t.data.pageSize)},function(t){n.emit("advancedSearchError",t)}),n},searchWithGQuery:function(e,a,r){return r||(r=n.pageSize),a||(a=n.page),n.storage.set("pageSize",r),n.storage.set("page",a),n.count>0&&n.storage.set("count",n.count),e&&n.storage.set("gQuery",JSON.stringify(e)),n.storage.set("last-operation","searchWithGQuery"),n.lastGQuery=e,n.emit("searchWithGQueryStart"),t.searchWithGQuery(e,a,r).then(function(t){n.emit("searchWithGQuerySuccess",t.data),n.data=t.data.values,n.pageSize=t.data.pageSize,t.data.count>0&&n.storage.set("count",t.data.count),t.data.count>0&&a<=1&&(n.count=t.data.count),t.data.count||(t.data.count=Number(n.storage.get("count")))},function(t){n.emit("searchWithGQueryError",t)})},asyncSearchWithGQuery:function(e,a,r){return r||(r=n.pageSize),a||(a=n.page),n.lastGQuery=e,n.count>0&&n.storage.set("count",n.count),n.storage.set("pageSize",r),n.storage.set("page",a),e&&n.storage.set("gQuery",JSON.stringify(e)),n.storage.set("last-operation","asyncSearchWithGQuery"),n.emit("asyncSearchWithGQuery"),t.searchWithGQuery(e,a,r).then(function(t){return n.emit("asyncSearchWithGQuery",t.data),n.pageSize=t.data.pageSize,t.data.count>0&&n.storage.set("count",t.data.count),t.data.count>0&&a<=1&&(n.count=t.data.count),t.data.count||(t.data.count=Number(n.storage.get("count"))),t.data.values},function(t){n.emit("asyncSearchWithGQuery",t)})},redoSearch:function(){return n.emit("redoSearchStart"),t.redoSearch().then(function(t){n.emit("redoSearchSuccess",t.data),n.data=t.data.values,n.pageSize=t.data.pageSize,t.data.count>0&&page<=1&&(n.count=t.data.count)},function(t){n.emit("redoSearchError",t)}),n},postQuery:function(e,a){return n.emit("postQueryStart"),t.saveQuery({query:e,name:a}).then(function(t){n.emit("postQuerySuccess")},function(t){n.emit("postQueryError",t)}),n},getQuery:function(e){return e||(e=n.page),n.emit("getQueryStart"),t.getQuery(e).then(function(t){return n.emit("getQuerySuccess",t.data),t.data.values},function(t){n.emit("getQueryError",t)})},postImage:function(e,a){return n.emit("postImageStart"),t.saveImage(e,a).then(function(t){return n.emit("postImageSuccess"),t},function(t){n.emit("postImageError",t)})},deleteImage:function(e,a){return n.emit("deleteImageStart"),t.deleteImage(e,a).then(function(t){n.emit("deleteImageSuccess")},function(t){n.emit("deleteImageError",t)}),n},reset:function(){return n.emit("resetStart"),t.resetDefaultState(),n},getAvailableTags:function(){return n.emit("getAvailableTagsStart"),t.getAvailableTags()},getSelectedTags:function(e){return n.emit("getSelectedTagsStart"),t.getSelectedTags(e)},postTags:function(e,a){n.emit("postTagStart",a),t.postTags(e,a).then(function(t){n.emit("postTagSuccess",a)},function(t){n.emit("postTagError",a)})},getDocumentationURL:function(){return n.emit("getDocumentationURLStart"),t.getDocumentationURL()},createQuery:function(){return new r.QueryObject(t,n)}}}function e(){function e(e,a,r){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"page",n=r.constructor;if(!e)throw"É necessário passar um objeto no primeiro parâmetro";if(!a)throw"É necessário passar um objeto no segundo parâmetro";if(n!==Object&&n!==String)throw"É necessário passar um objeto ou uma string no terceiro parâmetro";var i=this._createOptions(r);if(i.noScope)return new t(a,r,e,o);e[i.identifier]=new t(a,r,e,o)}function a(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(t.constructor===String)return{identifier:t,noScope:!1};var e=angular.extend({},t);if(e.noScope=!!e.noScope,!e.identifier)throw"Você precisa passar um identificador para o objeto de configuração do createRestMethods!";return e}return{createRestMethods:e,_createOptions:a}}t.prototype.callbacks={},t.prototype.and=this,t.prototype.emit=function(t,e){return this.callbacks[t]&&this.callbacks[t].forEach(function(t){t(e)}),this},t.prototype.on=function(t,e){return this.callbacks[t]||(this.callbacks[t]=[]),this.callbacks[t].push(e),this},t.prototype.execute=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(t.constructor!==String)throw"O primeiro parâmetro deve ser uma string!";if(this.methods[t]){for(var e,a=arguments.length,r=Array(a>1?a-1:0),o=1;o<a;o++)r[o-1]=arguments[o];return(e=this.methods)[t].apply(e,r),this}throw"O nome do método está errado! Por favor coloque um método que está no GumgaController"},e.$inject=[],angular.module("gumga.controller",[]).factory("gumgaController",e)}()}]);