Files
grafana/dist/app/panels/table/module.js
T
2013-09-13 13:52:13 -07:00

5 lines
4.5 KiB
JavaScript
Executable File

define("panels/table/module",["angular","app","underscore","kbn","moment"],function(e,t,n,r,i){var s=e.module("kibana.panels.table",[]);t.useModule(s),s.controller("table",["$rootScope","$scope","fields","querySrv","dashboard","filterSrv",function(t,i,s,o,u,a){i.panelMeta={editorTabs:[{title:"Paging",src:"app/panels/table/pagination.html"},{title:"Queries",src:"app/partials/querySelect.html"}],status:"Stable",description:"A paginated table of records matching your query or queries. Click on a row to expand it and review all of the fields associated with that document. <p>"};var f={status:"Stable",queries:{mode:"all",ids:[]},size:100,pages:5,offset:0,sort:["_score","desc"],group:"default",style:{"font-size":"9pt"},overflow:"min-height",fields:[],highlight:[],sortable:!0,header:!0,paging:!0,field_list:!0,trimFactor:300,normTimes:!0,spyable:!0};n.defaults(i.panel,f),i.init=function(){i.Math=Math,i.$on("refresh",function(){i.get_data()}),i.fields=s,i.get_data()},i.percent=r.to_percent,i.toggle_micropanel=
function(e){var t=n.pluck(i.data,"_source");i.micropanel={field:e,values:r.top_field_values(t,e,10),related:r.get_related_fields(t,e),count:n.countBy(t,function(t){return n.contains(n.keys(t),e)})["true"]}},i.micropanelColor=function(e){var t=["bar-success","bar-warning","bar-danger","bar-info","bar-primary"];return e>t.length?"":t[e]},i.set_sort=function(e){i.panel.sort[0]===e?i.panel.sort[1]=i.panel.sort[1]==="asc"?"desc":"asc":i.panel.sort[0]=e,i.get_data()},i.toggle_field=function(e){n.indexOf(i.panel.fields,e)>-1?i.panel.fields=n.without(i.panel.fields,e):i.panel.fields.push(e)},i.toggle_highlight=function(e){n.indexOf(i.panel.highlight,e)>-1?i.panel.highlight=n.without(i.panel.highlight,e):i.panel.highlight.push(e)},i.toggle_details=function(e){e.kibana=e.kibana||{},e.kibana.details=e.kibana.details?!1:i.without_kibana(e)},i.page=function(e){i.panel.offset=e*i.panel.size,i.get_data()},i.build_search=function(t,r,s){var o;n.isArray(r)?o="("+n.map(r,function(t){return e.toJson(t)}).
join(" AND ")+")":n.isUndefined(r)?(o="*",s=!s):o=e.toJson(r),a.set({type:"field",field:t,query:o,mandate:s?"mustNot":"must"}),i.panel.offset=0,u.refresh()},i.fieldExists=function(e,t){a.set({type:"exists",field:e,mandate:t}),u.refresh()},i.get_data=function(e,t){i.panel.error=!1;if(u.indices.length===0)return;i.panelMeta.loading=!0,i.panel.queries.ids=o.idsByMode(i.panel.queries);var s=n.isUndefined(e)?0:e;i.segment=s;var f=i.ejs.Request().indices(u.indices[s]),l=i.ejs.BoolQuery();n.each(i.panel.queries.ids,function(e){l=l.should(o.getEjsObj(e))}),f=f.query(i.ejs.FilteredQuery(l,a.getBoolFilter(a.ids))).highlight(i.ejs.Highlight(i.panel.highlight).fragmentSize(2147483647).preTags("@start-highlight@").postTags("@end-highlight@")).size(i.panel.size*i.panel.pages).sort(i.panel.sort[0],i.panel.sort[1]),i.populate_modal(f);var c=f.doSearch();c.then(function(e){i.panelMeta.loading=!1,s===0&&(i.hits=0,i.data=[],t=i.query_id=(new Date).getTime());if(!n.isUndefined(e.error)){i.panel.error=i.parse_error
(e.error);return}if(i.query_id!==t)return;i.data=i.data.concat(n.map(e.hits.hits,function(e){return{_source:r.flatten_json(e._source),highlight:r.flatten_json(e.highlight||{}),_type:e._type,_index:e._index,_id:e._id,_sort:e.sort}})),i.hits+=e.hits.total,i.data=n.sortBy(i.data,function(e){return e._sort[0]}),i.panel.sort[1]==="desc"&&i.data.reverse(),i.data=i.data.slice(0,i.panel.size*i.panel.pages),(i.data.length<i.panel.size*i.panel.pages||!n.contains(a.timeField(),i.panel.sort[0])||i.panel.sort[1]!=="desc")&&s+1<u.indices.length&&i.get_data(s+1,i.query_id)})},i.populate_modal=function(t){i.inspector=e.toJson(JSON.parse(t.toString()),!0)},i.without_kibana=function(e){return{_source:e._source,highlight:e.highlight}},i.set_refresh=function(e){i.refresh=e},i.close_edit=function(){i.refresh&&i.get_data(),i.refresh=!1}}]),s.filter("tableHighlight",function(){return function(e){return!n.isUndefined(e)&&!n.isNull(e)&&e.toString().length>0?e.toString().replace(/&/g,"&amp;").replace(/</g,"&lt;"
).replace(/>/g,"&gt;").replace(/\r?\n/g,"<br/>").replace(/@start-highlight@/g,'<code class="highlight">').replace(/@end-highlight@/g,"</code>"):""}}),s.filter("tableTruncate",function(){return function(e,t,r){return!n.isUndefined(e)&&!n.isNull(e)&&e.toString().length>0?e.length>t/r?e.substr(0,t/r)+"...":e:""}}),s.filter("tableFieldFormat",["fields",function(e){return function(t,r,s,o){var u;if(!n.isUndefined(e.mapping[s._index])&&!n.isUndefined(e.mapping[s._index][s._type])){u=e.mapping[s._index][s._type][r].type;if(u==="date"&&o.panel.normTimes)return i(t).format("YYYY-MM-DD HH:mm:ss")}return t}}])});