grafana/plugins/grafana-clock-panel/module.js

31 lines
844 KiB
JavaScript
Raw Permalink Normal View History

2025-01-10 20:54:04 -08:00
/*! For license information please see module.js.LICENSE.txt */
define(["@grafana/data","react","@grafana/ui","@emotion/css","moment","@grafana/runtime"],((b,z,M,p,O,A)=>(()=>{var c={154:(b,z,M)=>{(b.exports=M(262)).tz.load(M(565))},262:function(b,z,M){var p,O,A;!function(c,o){"use strict";b.exports?b.exports=o(M(283)):(O=[M(283)],void 0===(A="function"==typeof(p=o)?p.apply(z,O):p)||(b.exports=A))}(0,(function(b){"use strict";void 0===b.version&&b.default&&(b=b.default);var z,M={},p={},O={},A={},c={};b&&"string"==typeof b.version||g("Moment Timezone requires Moment.js. See https://momentjs.com/timezone/docs/#/use-it/browser/");var o=b.version.split("."),q=+o[0],W=+o[1];function d(b){return b>96?b-87:b>64?b-29:b-48}function n(b){var z=0,M=b.split("."),p=M[0],O=M[1]||"",A=1,c=0,o=1;for(45===b.charCodeAt(0)&&(z=1,o=-1);z<p.length;z++)c=60*c+d(p.charCodeAt(z));for(z=0;z<O.length;z++)A/=60,c+=d(O.charCodeAt(z))*A;return c*o}function R(b){for(var z=0;z<b.length;z++)b[z]=n(b[z])}function a(b,z){var M,p=[];for(M=0;M<z.length;M++)p[M]=b[z[M]];return p}function X(b){var z=b.split("|"),M=z[2].split(" "),p=z[3].split(""),O=z[4].split(" ");return R(M),R(p),R(O),function(b,z){for(var M=0;M<z;M++)b[M]=Math.round((b[M-1]||0)+6e4*b[M]);b[z-1]=1/0}(O,p.length),{name:z[0],abbrs:a(z[1].split(" "),p),offsets:a(M,p),untils:O,population:0|z[5]}}function B(b){b&&this._set(X(b))}function L(b,z){this.name=b,this.zones=z}function e(b){var z=b.toTimeString(),M=z.match(/\([a-z ]+\)/i);"GMT"===(M=M&&M[0]?(M=M[0].match(/[A-Z]/g))?M.join(""):void 0:(M=z.match(/[A-Z]{3,5}/g))?M[0]:void 0)&&(M=void 0),this.at=+b,this.abbr=M,this.offset=b.getTimezoneOffset()}function i(b){this.zone=b,this.offsetScore=0,this.abbrScore=0}function f(b,z){for(var M,p;p=6e4*((z.at-b.at)/12e4|0);)(M=new e(new Date(b.at+p))).offset===b.offset?b=M:z=M;return b}function l(b,z){return b.offsetScore!==z.offsetScore?b.offsetScore-z.offsetScore:b.abbrScore!==z.abbrScore?b.abbrScore-z.abbrScore:b.zone.population!==z.zone.population?z.zone.population-b.zone.population:z.zone.name.localeCompare(b.zone.name)}function r(b,z){var M,p;for(R(z),M=0;M<z.length;M++)p=z[M],c[p]=c[p]||{},c[p][b]=!0}function u(b){var z,M,p,O=b.length,o={},q=[];for(z=0;z<O;z++)for(M in p=c[b[z].offset]||{})p.hasOwnProperty(M)&&(o[M]=!0);for(z in o)o.hasOwnProperty(z)&&q.push(A[z]);return q}function t(b){return(b||"").toLowerCase().replace(/\//g,"_")}function N(b){var z,p,O,c;for("string"==typeof b&&(b=[b]),z=0;z<b.length;z++)c=t(p=(O=b[z].split("|"))[0]),M[c]=b[z],A[c]=p,r(c,O[2].split(" "))}function s(b,z){b=t(b);var O,c=M[b];return c instanceof B?c:"string"==typeof c?(c=new B(c),M[b]=c,c):p[b]&&z!==s&&(O=s(p[b],s))?((c=M[b]=new B)._set(O),c.name=A[b],c):null}function T(b){var z,M,O,c;for("string"==typeof b&&(b=[b]),z=0;z<b.length;z++)O=t((M=b[z].split("|"))[0]),c=t(M[1]),p[O]=c,A[O]=M[0],p[c]=O,A[c]=M[1]}function m(b){var z="X"===b._f||"x"===b._f;return!(!b._a||void 0!==b._tzm||z)}function g(b){"undefined"!=typeof console&&"function"==typeof console.error&&console.error(b)}function E(z){var M=Array.prototype.slice.call(arguments,0,-1),p=arguments[arguments.length-1],O=s(p),A=b.utc.apply(null,M);return O&&!b.isMoment(z)&&m(A)&&A.add(O.parse(A),"minutes"),A.tz(p),A}(q<2||2===q&&W<6)&&g("Moment Timezone requires Moment.js >= 2.6.0. You are using Moment.js "+b.version+". See momentjs.com"),B.prototype={_set:function(b){this.name=b.name,this.abbrs=b.abbrs,this.untils=b.untils,this.offsets=b.offsets,this.population=b.population},_index:function(b){var z,M=+b,p=this.untils;for(z=0;z<p.length;z++)if(M<p[z])return z},countries:function(){var b=this.name;return Object.keys(O).filter((function(z){return-1!==O[z].zones.indexOf(b)}))},parse:function(b){var z,M,p,O,A=+b,c=this.offsets,o=this.untils,q=o.length-1;for(O=0;O<q;O++)if(z=c[O],M=c[O+1],p=c[O?O-1:O],z<M&&E.moveAmbiguousForward?z=M:z>p&&E.moveInvalidForward&&(z=p),A<o[O]-6e4*z)return c[O];return c[q]},abbr:function(b){return this.abbrs[this._index(b)]},offset:function(b){return g("zone.offset has been deprecated in favor of zone.utcOffset"),this.offsets[this._index(b)]},utcOffset:function(b){return this.offsets[this._index(b)]}},i
font-size: ${z.fontSize};
font-weight: ${z.fontWeight};
line-height: 1.4;
`;let A=this.props.options.timezone||"";switch(M){case p.offsetAbbv:A=b.format("Z z");break;case p.offset:A=b.format("Z");break;case p.abbv:A=b.format("z");break;default:try{A=this.getTZ(A)._z.name}catch(b){console.log("Error getting timezone",b)}}return o().createElement("h4",{className:O},A,M===p.nameOffset&&o().createElement(o().Fragment,null,o().createElement("br",null),"(",b.format("Z z"),")"))}renderDate(){const{now:b}=this.state,{dateSettings:z}=this.props.options,M=n.css`
font-size: ${z.fontSize};
font-weight: ${z.fontWeight};
`,p=b.locale(z.locale||"").format(z.dateFormat);return o().createElement("span",null,o().createElement("h3",{className:M},p))}renderTime(){const{now:z}=this.state,{options:M}=this.props,{timeSettings:p,mode:O}=M,A=n.css`
font-size: ${p.fontSize};
font-weight: ${p.fontWeight};
`;let c=z.format(this.getTimeFormat());return O===b.countdown?c=this.getCountdownText():O===b.countup&&(c=this.getCountupText()),o().createElement("h2",{className:A},c)}render(){const{options:b,width:z,height:M,theme:p}=this.props,{dateSettings:O,timezoneSettings:A,bgColor:c}=b,q=n.css`
display: flex;
align-items: center;
justify-content: center;
flex-flow: column wrap;
text-align: center;
background-color: ${c?p.v1.visualization.getColorByName(c):p.colors.background.primary};
`;return o().createElement("div",{className:q,style:{width:z,height:M}},O.showDate&&this.renderDate(),this.renderTime(),A.showTimezone&&this.renderZone())}constructor(...b){super(...b),this.timerID=0,this.state={now:this.getTZ(),timezone:""},this.initTimers=()=>{const{refresh:b}=this.props.options;if(this.timerID&&(clearInterval(this.timerID),this.timerID=0),b===z.dashboard)return this.tick();this.timerID=setInterval((()=>this.tick()),1e3)},this.onPanelRefresh=()=>{const{refresh:b}=this.props.options;b===z.dashboard&&this.tick()}}}const L=(0,d.withTheme2)(B);function e(b){const z=i(X.config.theme);let M=null,p=null;return b.value&&(p=o().createElement(d.Icon,{className:z.trashIcon,name:"trash-alt",onClick:()=>b.onChange(void 0)})),M=o().createElement("div",{className:z.inputPrefix},o().createElement("div",{className:z.colorPicker},o().createElement(d.ColorPicker,{color:b.value||X.config.theme.colors.panelBg,onChange:b.onChange,enableNamedColors:!0}))),o().createElement("div",null,o().createElement(d.Input,{type:"text",value:b.value||"Pick Color",onBlur:b=>{console.log("CLICK")},prefix:M,suffix:p}))}const i=(0,d.stylesFactory)((b=>({colorPicker:n.css`
padding: 0 ${b.spacing.sm};
`,inputPrefix:n.css`
display: flex;
align-items: center;
`,trashIcon:n.css`
color: ${b.colors.textWeak};
cursor: pointer;
&:hover {
color: ${b.colors.text};
}
`})));function f(b,z,M,p,O,A,c){try{var o=b[A](c),q=o.value}catch(b){return void M(b)}o.done?z(q):Promise.resolve(q).then(p,O)}function l(b){return function(){var z=this,M=arguments;return new Promise((function(p,O){var A=b.apply(z,M);function c(b){f(A,p,O,c,o,"next",b)}function o(b){f(A,p,O,c,o,"throw",b)}c(void 0)}))}}const r=new A.PanelPlugin(L).setNoPadding().setMigrationHandler((b=>{var M,p;const O=b.options||{};return((null===(M=O.refreshSettings)||void 0===M?void 0:M.syncWithDashboard)||(null===(p=b.refreshSettings)||void 0===p?void 0:p.syncWithDashboard))&&(O.refresh=z.dashboard),O})).setPanelOptions((c=>{c.addRadio({path:"mode",name:"Mode",settings:{options:[{value:b.time,label:"Time"},{value:b.countdown,label:"Countdown"},{value:b.countup,label:"Countup"}]},defaultValue:b.time}).addRadio({path:"refresh",name:"Refresh",settings:{options:[{value:z.sec,label:"Every second"},{value:z.dashboard,label:"With the dashboard"}]},defaultValue:z.sec}).addCustomEditor({id:"bgColor",path:"bgColor",name:"Background Color",editor:e,defaultValue:""}),function(z){const M=["Countdown"];z.addTextInput({category:M,path:"countdownSettings.endCountdownTime",name:"End Time",settings:{placeholder:"ISO 8601 or RFC 2822 Date time"},defaultValue:(0,A.dateTime)(Date.now()).add(6,"h").format(),showIf:z=>z.mode===b.countdown}).addTextInput({category:M,path:"countdownSettings.endText",name:"End Text",defaultValue:"00:00:00",showIf:z=>z.mode===b.countdown}).addTextInput({category:M,path:"countdownSettings.customFormat",name:"Custom format",settings:{placeholder:"optional"},defaultValue:void 0,showIf:z=>z.mode===b.countdown})}(c),function(z){const M=["Countup"];z.addTextInput({category:M,path:"countupSettings.beginCountupTime",name:"Begin Time",settings:{placeholder:"ISO 8601 or RFC 2822 Date time"},defaultValue:(0,A.dateTime)(Date.now()).add(6,"h").format(),showIf:z=>z.mode===b.countup}).addTextInput({category:M,path:"countupSettings.beginText",name:"Begin Text",defaultValue:"00:00:00",showIf:z=>z.mode===b.countup}).addTextInput({category:M,path:"countupSettings.customFormat",name:"Custom format",settings:{placeholder:"optional"},defaultValue:void 0,showIf:z=>z.mode===b.countup})}(c),function(b){const z=["Time Format"];b.addRadio({category:z,path:"clockType",name:"Clock Type",settings:{options:[{value:M.H24,label:"24 Hour"},{value:M.H12,label:"12 Hour"},{value:M.Custom,label:"Custom"}]},defaultValue:M.H24}).addTextInput({category:z,path:"timeSettings.customFormat",name:"Time Format",description:"the date formatting pattern",settings:{placeholder:"date format"},defaultValue:void 0,showIf:b=>b.clockType===M.Custom}).addTextInput({category:z,path:"timeSettings.fontSize",name:"Font size",settings:{placeholder:"Font size (e.g. 12px)"},defaultValue:"12px"}).addRadio({category:z,path:"timeSettings.fontWeight",name:"Font weight",settings:{options:[{value:O.normal,label:"Normal"},{value:O.bold,label:"Bold"}]},defaultValue:O.normal})}(c),function(b){const z=["Timezone"],M=a().tz.names().map((b=>({label:b,value:b})));M.unshift({label:"Default",value:""}),b.addSelect({category:z,path:"timezone",name:"Timezone",settings:{options:M,getOptions:l((function*(){const b=(0,X.getTemplateSrv)().getVariables().map((b=>{const z="${"+b.name+"}";return{label:z,value:z,icon:"arrow-right"}}));return b.length?[...b,...M]:M}))},defaultValue:""}).addBooleanSwitch({category:z,path:"timezoneSettings.showTimezone",name:"Show Timezone",defaultValue:!1}).addSelect({category:z,path:"timezoneSettings.zoneFormat",name:"Display Format",settings:{options:[{value:p.name,label:"Normal"},{value:p.nameOffset,label:"Name + Offset"},{value:p.offsetAbbv,label:"Offset + Abbreviation"},{value:p.offset,label:"Offset"},{value:p.abbv,label:"Abbreviation"}]},defaultValue:p.offsetAbbv,showIf:b=>{var z;return null===(z=b.timezoneSettings)||void 0===z?void 0:z.showTimezone}}).addTextInput({category:z,path:"timezoneSettings.fontSize",name:"Font size",settings:{placeholder:"font size"},defaultValue:"12px",showIf:b=>{var z;return null===(z=b.timezoneSettings)||void 0===z?void 0:z.showTimezone}}).
//# sourceMappingURL=module.js.map