1var et=Object.defineProperty;var st=(s,t,a)=>t in s?et(s,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):s[t]=a;var b=(s,t,a)=>st(s,typeof t!="symbol"?t+"":t,a);import{x as at,r as C,_ as it,a as d,e,o,d as Q,c as k,h as M,t as v,i as rt,j as ot,b as S,g as I,v as j,F as E,l as z,k as O,w as nt,s as dt}from"./index-DbpIxVVg.js";import{a as w,F as lt,b as ct}from"./FeedService-jWR4iRv8.js";import{A as ut}from"./ActivityIndicator-CHNVpzvm.js";import{_ as K}from"./RelativeTime.vue_vue_type_script_setup_true_lang-BRXoPN3V.js";import{r as gt}from"./ChevronRightIcon-CKGSa4-R.js";import"./PaginatedResultSet-gBeGRM8h.js";var G=(s=>(s[s.subscribe=0]="subscribe",s[s.unsubscribe=1]="unsubscribe",s[s.authenticate=4]="authenticate",s[s.initialState=16]="initialState",s[s.updateState=32]="updateState",s[s.error=128]="error",s))(G||{});let F;function pt(){return F||(F=new ht(at().webSocketBaseUrl+"/v1/events")),F}class ht{constructor(t){b(this,"topicMap",new Map);b(this,"delegateMap",new Map);b(this,"delegateId",0);b(this,"lastRequestId",0);b(this,"webSocket");b(this,"webSocketUrl");b(this,"_isConnected",C(!1));b(this,"consecutiveErrorCount",0);b(this,"recoveryTimerId");this.webSocketUrl=t}subscribe(t,a){var l;this.delegateMap.set(this.delegateId,a);for(const p of t)this.topicMap.has(p.id)?this.topicMap.get(p.id).push(this.delegateId):this.topicMap.set(p.id,[this.delegateId]);return((l=this.webSocket)==null?void 0:l.readyState)===WebSocket.OPEN?this.sendSubscribeTopics(t):this.webSocket||this.connect(),this.delegateId++}unsubscribe(t,a){var l;for(const p of t){const _=((l=this.topicMap.get(p))==null?void 0:l.filter(U=>U!==a))||[];_.length&&a!==void 0?this.topicMap.set(p,_):this.topicMap.delete(p)}a!==void 0&&this.delegateMap.delete(a),this.topicMap.size===0&&this.disconnect()}get isConnected(){return this._isConnected}connect(){this.webSocket||(console.log("EventService: connecting to ws"),clearTimeout(this.recoveryTimerId),this.webSocket=new WebSocket(this.webSocketUrl),this.webSocket.onopen=t=>this.initConnection(t),this.webSocket.onmessage=t=>this.handleMessage(t),this.webSocket.onerror=t=>this.handleError(t),this.webSocket.onclose=()=>this.handleClose())}initConnection(t){console.log(`EventService: connected to ws: ${t.type}`),this._isConnected.value=!0,this.consecutiveErrorCount=0,this.sendSubscribeTopics(Array.from(this.topicMap.keys()).map(a=>({id:a})))}disconnect(){console.log("EventService: disconnected"),this._isConnected.value=!1,this.webSocket.close()}handleMessage(t){const a=JSON.parse(t.data),l=this.getDelegatesForMessage(
1a);switch(a.action){case 16:case 32:l.forEach(p=>p(void 0,a));break;case 128:{const p=new Error(a.message);console.log(`EventService: received error: ${a.message}`),l.forEach(_=>_(p,a));break}default:console.log(`EventService: unknown message action received: ${t.data}`)}}handleError(t){console.log(`EventService: ws error: ${JSON.stringify(t)}`),this.consecutiveErrorCount++}handleClose(){if(this.webSocket=void 0,this._isConnected.value=!1,this.topicMap.size>0){const t=Math.pow(2,this.consecutiveErrorCount);console.log(`EventService: ws closed unexpectedly, scheduling recovery in ${t/2}s`),this.recoveryTimerId=window.setTimeout(()=>this.connect(),500*t)}}getDelegatesForMessage(t){return t.action===16||t.action===32?t.topicId?(this.topicMap.get(t.topicId)||[]).map(l=>this.delegateMap.get(l)).filter(l=>l!==void 0):void 0:[]}sendSubscribeTopics(t){const a={action:0,requestId:this.generateRequestId(),topics:t};this.webSocket.send(JSON.stringify(a))}generateRequestId(){return(++this.lastRequestId).toString()}}const mt={},xt={fill:"currentColor",viewBox:"0 0 8 8"};function yt(s,t){return o(),d("svg",xt,t[0]||(t[0]=[e("circle",{cx:"4",cy:"4",r:"3"},null,-1)]))}const ft=it(mt,[["render",yt]]),vt={key:0,class:"badge-lg bg-gray-100-d text-gray-400-d"},bt={key:1,class:"badge-lg text-white bg-red-500"},_t={key:2,class:"badge-lg text-white bg-orange-500"},kt={key:3,class:"badge-lg text-white-d bg-green-500"},wt={key:4,class:"badge-lg text-white-d bg-green-500"},St={key:5,class:"badge-lg text-white-d bg-gray-500"},Ct={key:6,class:"badge-lg bg-gray-100-d"},P=Q({__name:"FeedStatusBadge",props:{state:{type:Number,required:!1,default:w.Uninitialised},isOutdated:{type:Boolean,required:!1,default:!1}},setup(s){const t=s,a=k(()=>w[t.state]);return(l,p)=>s.state===M(w).Uninitialised?(o(),d("div",vt,"Unknown")):s.state===M(w).Error?(o(),d("div",bt,"Error")):s.isOutdated?(o(),d("div",_t,"Outdated")):s.state===M(w).Success?(o(),d("div",kt,"OK")):s.state===M(w).Subscribed?(o(),d("div",wt,"Subscribed")):s.state===M(w).Downloading?(o(),d("div",St,"Updating")):(o(),d("div",Ct,v(a.value),1))}}),Mt={class:"px-6 py-4"},It={class:"sm:flex sm:items-center"},Et={class:"sm:flex-auto py-2"},Ut={class:"flex space-x-4"},$t={key:0,class:"inline-flex items-center px-2.5 py-0.5 rounded-md text-sm font-medium bg-green-100-d text-green-800-d"},Ot={class:"mt-4 sm:mt-0 sm:ml-16 sm:flex-none"},Ft={key:0,class:"p-8"},Gt={key:1,class:"inline-block min-w-full align-middle"},Bt={class:"overflow-hidden shadow-sm ring-1 ring-black ring-opacity-5"},Nt={class:"min-w-full divide-y divide-gray-300 dark:divide-gray-700 border-t border-t-gray-200 dark:border-t-gray-700"},Vt={class:"divide-y divide-gray-200 dark:divide-gray-700 bg-white dark:bg-gray-900"},Dt=["onClick"],qt={scope:"colgroup",class:"bg-gray-50 dark:bg-gray-800 px-4 py-3.5 text-left text-base font-semibold text-gray-900 dark:text-gray-100 sm:px-6"},Tt={class:"flex items-center space-x-2"},Lt={class:"text-gray-600-d"},Jt={key:0,scope:"colgroup",colspan:"5",class:"bg-gray-50 dark:bg-gray-800 px-3 py-2 text-right text-sm font-semibold text-gray-500"},Rt={scope:"colgroup",class:"bg-gray-50 dark:bg-gray-800 px-3 py-2 text-right text-sm font-semibold text-gray-900 dark:text-gray-100"},jt={class:"bg-gray-50 dark:bg-gray-800 px-3 py-2 text-right text-sm font-normal text-gray-900-d"},zt={class:"bg-gray-50 dark:bg-gray-800 px-3 py-2 text-right text-sm font-normal text-gray-900-d"},Kt={class:"bg-gray-50 dark:bg-gray-800 px-3 py-2 text-right text-sm font-normal text-gray-900-d"},Pt={class:"bg-gray-50 dark:bg-gray-800 px-3 py-2 text-right text-sm font-normal text-gray-900-d"},Qt={class:"text-sm font-medium text-gray-900 dark:text-gray-100 align-top py-3.5"},At={class:"whitespace-nowrap px-3 py-3 text-sm text-gray-500 align-top text-right"},Ht={class:"px-3 py-3.5 text-sm text-gray-500-d align-top text-right"},Xt={class:"px-3 py-3.5 text-sm text-gray-500-d align-top text-right"},Yt={class:"px-3 py-3.5 text-sm text-gray-500-d align-top text-right"},Zt={class:"whitespace-nowrap px-3 py-3.5 text-sm text-gray-500-d align-top text-right"},oe=Q({__name:"FeedListView",setup(s){const t=C(),a=C(),l=C(!1),p=C(),_=C(new Set),U=k(()=>$.isConnected.value),A=new lt,$=pt();let B;rt(async()=>{await Y(),H()}),ot(()=>X());function H(){B=$.subscribe([{id:"feed.status"}],(m,c)=>{if(c.action===G.updateState||c.action===G.initialState){const h=Object.keys(c.payload).map(u=>ct.fromJSON(c.payload[u]));
1Z(h)}})}function X(){$.unsubscribe(["feed.status"],B)}async function Y(){try{l.value=!0,p.value=null,t.value=await A.findByQuery({limit:500}),a.value=W(t.value.items)}catch(m){p.value=m}finally{l.value=!1}}function Z(m){var h;if(!((h=t.value)!=null&&h.items))return;const c=new Map(m.map(u=>[u.id,u]));for(const u of t.value.items){const r=c.get(u.feed.id);r&&(u.status=r)}}function W(m){return Array.from(new Map(m.map(h=>[h.region.id,h.region])).values()).map(h=>{const u=m.filter(g=>g.feed.regionId===h.id),r=Array.from(new Map(u.filter(g=>g.group).map(g=>[g.group.id,g.group])).values()).sort((g,x)=>g.order-x.order).map(g=>{const x=u.filter(i=>i.feed.feedGroupId===g.id);return{region:h,feedGroup:g,results:x,aggregate:{state:k(()=>x.map(i=>{var n;return(n=i.status)==null?void 0:n.state}).filter(i=>i).reduce((i,n)=>i&&i>n?i:n,w.Uninitialised)),isOutdated:k(()=>x.some(i=>i.isOutdated)),lastTripCount:k(()=>x.reduce((i,n)=>{var y;return i+(((y=n.status)==null?void 0:y.lastTripCount)||0)},0)),lastVehicleCount:k(()=>x.reduce((i,n)=>{var y;return i+(((y=n.status)==null?void 0:y.lastVehicleCount)||0)},0)),lastAlertCount:k(()=>x.reduce((i,n)=>{var y;return i+(((y=n.status)==null?void 0:y.lastAlertCount)||0)},0)),lastUpdated:k(()=>x.map(i=>{var n;return(n=i.status)==null?void 0:n.lastUpdatedTimestamp}).filter(i=>i).reduce((i,n)=>i&&i>n?i:n,null))}}});return r.push({region:h,feedGroup:null,results:u.filter(g=>!g.feed.feedGroupId)}),r}).reduce((h,u)=>h.concat(u),[])}function tt(m){_.value.has(m.feedGroup.id)?_.value.delete(m.feedGroup.id):_.value.add(m.feedGroup.id)}return(m,c)=>{var u;const h=dt("router-link");return o(),d("div",null,[e("div",Mt,[e("div",It,[e("div",Et,[e("div",Ut,[c[1]||(c[1]=e("h1",{class:"text-xl font-semibold text-gray-900 dark:text-gray-100"},"Feeds",-1)),U.value?(o(),d("div",$t,[I(ft,{class:"-ml-0.5 mr-1.5 h-2 w-2 text-green-400"}),c[0]||(c[0]=j(" Live ",-1))])):S("",!0)]),c[2]||(c[2]=e("p",{class:"mt-2 text-sm text-gray-700 dark:text-gray-300 hidden"},null,-1))]),e("div",Ot,[S("",!0)])])]),l.value&&!t.value?(o(),d("div",Ft,[I(ut)])):(u=t.value)!=null&&u.items.length?(o(),d("div",Gt,[e("div",Bt,[e("table",Nt,[c[4]||(c[4]=e("thead",{class:""},[e("tr",null,[e("th",{scope:"col",class:"py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 dark:text-gray-100 sm:pl-6"}," Title "),e("th",{scope:"col",class:"px-3 py-3.5 text-right text-sm font-semibold text-gray-900 dark:text-gray-100"}," Status "),e("th",{scope:"col",class:"px-3 py-3.5 text-right text-sm font-semibold text-gray-900 dark:text-gray-100"}," Trips "),e("th",{scope:"col",class:"px-3 py-3.5 text-right text-sm font-semibold text-gray-900 dark:text-gray-100"}," Vehicles "),e("th",{scope:"col",class:"px-3 py-3.5 text-right text-sm font-semibold text-gray-900 dark:text-gray-100"}," Alerts "),e("th",{scope:"col",class:"px-3 py-3.5 text-right text-sm font-semibold text-gray-900 dark:text-gray-100"}," Updated ")])],-1)),e("tbody",Vt,[(o(!0),d(E,null,z(a.value,r=>{var g,x,i,n,y,N,V,D;return o(),d(E,{key:`${r.region.id}_${((g=r.feedGroup)==null?void 0:g.id)||0}`},[e("tr",{class:"border-t border-gray-200 dark:border-gray-700 cursor-pointer",onClick:f=>tt(r)},[e("th",qt,[e("div",Tt,[e("span",null,v(r.region.name),1),I(M(gt),{class:"w-3 h-3 text-gray-500"}),e("span",Lt,v(((x=r.feedGroup)==null?void 0:x.title)||"Other"),1)])]),r.aggregate?(o(),d(E,{key:1},[e("th",Rt,[r.aggregate?(o(),O(P,{key:0,state:r.aggregate.state.value,"is-outdated":r.aggregate.isOutdated.value},null,8,["state","is-outdated"])):S("",!0)]),e("th",jt,v((i=r.aggregate)==null?void 0:i.lastTripCount),1),e("th",zt,v((n=r.aggregate)==null?void 0:n.lastVehicleCount),1),e("th",Kt,v((y=r.aggregate)==null?void 0:y.lastAlertCount),1),e("th",Pt,[(V=(N=r.aggregate)==null?void 0:N.lastUpdated)!=null&&V.value?(o(),O(K,{key:0,"date-time":r.aggregate.lastUpdated.value,"show-seconds":!0,"auto-updating":!0},null,8,["date-time"])):S("",!0)])],64)):(o(),d("th",Jt,v(r.results.length)+" feeds ",1))],8,Dt),(o(!0),d(E,null,z(_.value.has((D=r.feedGroup)==null?void 0:D.id)?r.results:[],f=>{var q,T,L,J,R;return o(),d("tr",{key:f.feed.id},[e("td",Qt,[I(h,{to:f.feed.viewUrl,class:"block pl-4 pr-3 sm:pl-6"},{default:nt(()=>[j(v(f.feed.name),1)]),_:2},1032,["to"])]),e("td",At,[I(P,{state:(q=f.status)==null?void 0:q.state,"is-outdated":f.isOutdated},null,8,["state","is-outdated"])]),e("td",Ht,v((T=f.status)==null?void 0:T.lastTripCount),1),e("td",Xt,v((L=f.status)==null?void 0:L.lastVehicleC
1ount),1),e("td",Yt,v((J=f.status)==null?void 0:J.lastAlertCount),1),e("td",Zt,[(R=f.status)!=null&&R.lastUpdatedTimestamp?(o(),O(K,{key:0,"date-time":f.status.lastUpdatedTimestamp,"show-seconds":!0,"auto-updating":!0},null,8,["date-time"])):S("",!0)])])}),128))],64)}),128))])])])])):S("",!0)])}}});export{oe as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.