Grafana, write a simple plugin, without using grunt or whatever - javascript

Good day all. I'm new to Grafana and we adopted it very recently at work.
I'm willing to create a plugin, I need to load a simple external js library and fire it in a Grafana panel, nothing extreme.
First problem: I don't want to use any building library (grunt or whatever), I just want to write the plugin javascript, I don't want to redistribute it. Where do I write the code?
Am I right to write the code I want to execute in the data/plugins/myplugin/dist/ folder? (I'm trying to follow the steps at Grafana Docs, but they are unclear as they talk about building and install scripts which I don't like to use).
Second Problem: Seems like that if I use the dist/ folder, the plugin get executed. Now, I'd like to import a external.js library into it, the external library will take care of display the data as I like.
into my myplugin_ctrl.js I write this:
System.register(['app/plugins/sdk', 'lodash', './css/clock-panel.css!','./libs/datamaps'], function (_export, _context) {
var PanelCtrl, _, _createClass, panelDefaults, ClockCtrl;
As you may notice, I've used the clock plugin that is used into the how-to at Grafana.
I'd like to import './libs/datamaps', what I managed to do is having this error upon adding the panel to a dashboard:
Plugin component error Error: Fetch error: 404 Not Found
Instantiating http://127.0.0.1:3000/data/plugins/test-panel/libs/datamaps
Loading http://127.0.0.1:3000/public/plugins/test-panel/clock_ctrl.js
What I'm doing wrong? Where do the datamap.js should be? Or how do I can import it into Grafana plugin?

I don't know if you really need to solve this with a plugin, as I couldn't find any mention about data retrieval from any data sources in your question. Also, I'm not yet very familiar with Grafana plugin development, but I was able to solve one JavaScript related problem without a need to write a plugin.
What I did: I put a Text element in html mode on a dashboard and inserted a <script>...</script> section as well as some HTML code. This worked until I updated Grafana to a newer version, where they started to block this due to security reasons. After configuring /etc/grafana/grafana.ini setting disable_sanitize_html = true in section [panels], I made it work again. You could do this, too, but keep in mind that this is a security risk, because the dashboards now allow to inject any kind of malicious JavaScript code.
See also this Grafana reference page for scripted dashboards.

Related

how to create documentation from markdown inside docs folder on github? javascript

I have seen a lot of docs websites that have the same layout or same features.
so I am wondering if there is a library used by all these docs.
how do they do this?
./docs -> files.md -> ./docs/files.html
like you see there are a lot of files with .md (sometimes also .mdx)
and they have the same functionalities (see below)
so I am wondering if they use the same js library to generate it?
I tried to search in all the repo, what they are using to generate, but nothing says the name of a library?
is there an npm package or CDN link to that js library?
that can get the .md files inside .docs, and based on the folder structure, create a list on the left with all topics, 2 buttons with next and previous, a button with edit this page on GitHub, etc...
if isn't possible I will do it by scratch, but writing HTML for every doc is time-consuming.
I prefer some markdown fast, build consistent docs, and automatically added to the first-page list on the left.
also the routing thing for getting previous and next elements I need to do it manually and this can be time-consuming.
is there something that does that for me, some web API that gets files .md if I need to do it from scratch?
but still prefering npm package if there is.
Example:
previous and next docs.
react native
deno
lusift
and they have a button with the text EDIT THIS ON GITHUB
Mozilla docs MDN
when scrolling, it will change the color of the currently viewed section
sketch API
but I never find the name of the library.
other functionalities are...
multi-page
and much more...
(I tried to search on Github, but never find it)
it's there a good docs generator for a programming library that I create?
I also google it: https://www.google.com/search?q=javascript+library+documentation
but nothing. the libraries there are for API GET/POST swagger etc...
but I am wanting a library for functions like if you write this function this happen, maybe also code snippet functionality to see what result give you that function.
something similar to StackOverflow. text to HTML (but not need any server-side things comlicated... just keep it simple the files are inside .docs in GitHub, so just simple stuff.
maybe I am writing wrong the google keyterm
I found the solution to this, by using the #evolutionxbox comment.
how to find?
if you want to find what library is used in a GitHub repo,
go to the package.json, there you can find the list of libraries that is used on the project
the name?
in this case, the library used is DOCUSAURUS
link: https://docusaurus.io/
is very simple to config and solves the job!
and is used by
Facebook,
and other big companies like:
supabase
redux
etc...

Custom JavaScript to existing Joomla core module

I have developed a custom Joomla template, and I need to add a piece of custom javascript to a Joomla core module (mod_articles_news), without a plugin, if possible (this should be so simple that I don't think I want to use a third party plugin for that). And async, if possible.
I have been searching thoroughly, but haven't found the perfect solution. Either they want me to install a plugin or the solution refers to a custom written module (suggesting to add JS before installation of module) while I am dealing with a core module (Articles Newsflash) that is already installed per definition. (The reason I need to use JS is to make a conditional design change, presently not possible with CSS).
I have been following the steps outlined here, but to no avail. Namely, I added the following code into the module's template folder (mod_articles_news/tmpl/my-template-name.php)
<?php
JHtml::script(Juri::base() . 'templates/my-template-name/js/myScript.js');
?>
(Of course, I have added the myScript.js file into the above location).
When checking it live, nothing happens, the browser is not loading my JavaScript at all (the script itself is tested and it works).
Please help me what I am missing here. Thank you in advance!
If you want to do customization you should use a Joomla! template for this. A template determines the basic HTML including the necessary CSS/JS for your site. In addition it can contain overrides for modules and components so you can do even more customization without touching any of the original code.
What you want to do sounds like a simple customization. Just add any CSS/JS which is necessary to achieve your task to the template.
You could try
<?php
JHTML::script('templates/my-template-name/js/myScript.js');
?>
alternatively, is there any reason you can't add it via your custom template, as suggested by Sven Bluege

How to organize Vue-JS : Non Javascript way?

How to organize Vue-JS project [files and directory]: Non Javascript way?
Coming from a non-javascript background, I found Vue.js very intuitive and easy to use. My earlier experience in Javascript is with JQuery and vanilla javascript on the browser.
I created an application using Vue , Vue-components and vue router. Everything works fine.
My problem is, I have ended up writing a lot of code in a single index.html file of my project. This file contains over 10 templates that I have created and attached to different component in my app. I want to know that is there a non-javascript way to organize these templates in seperate files.
I see that there are options using webpack and browserify to modularize the project. But coming from non javascript background, I don't find them intuitive. I don't want to go node - npm way because that has its own learning curve and moreover it downloads a dozen of files and dependencies in my project which I don't understand. I am old school and more comfortable downloading the files and including them in the webpages.
So probably, you understand where I am going to. I need a solution where I could put my templates as separate files and read those files in the different components.
What I have tried :
Declaring the templates inside my components. But writing all that html inside the component is not that clean. It also, makes my JS file too huge. I am better in putting all data in the index.html instead.
Storing template as smaller chunk "homepage.html","about.html" and in my components, using $.get / $.load to read different components in ready function of the component. This works but I still have to fire an additional ajax call for each component which is not efficient.
Please refrain from suggesting the obvious node-npm [webpack and browserify] way. I know thats what is supported by Vue but this needs a learning curve and complete setup. Answer to this question would actually help other developers who hesitate going the node-npm way.
Please shout back if you need more clarifications to the question.
The options you've mentioned are your only real ones... the HTML of the template needs to be available when it's needed, so you either have to have it within your html file off the bat, or load it using AJAX or an in-browser loader like RequireJS (and this extension that allows it to load HTML https://github.com/requirejs/text).
In-file templates make sense for very small projects. As your project grows, you'll need to start using the tools that are built for this. NPM rocks and every JS package that you'll ever need can be included in your project in seconds.
I highly encourage you to try the Vue CLI
It does use node, npm, webpack and downloads dozens of files. Which you've you've explicitly asked for not to use, so let me clarify:
The Vue CLI takes care of the complexity and configures webpack for you.
You don't even have to know it's using webpack.
It's very developer friendly (it even has a built-in gui) and lowers the barrier to entry compared configuring a webpack config.
I hope you'll also find it "intuitive and easy to use".

Adding pure javascript code to Shopify Theme by using Shopify API

I developed a Shopify application that i install on Shopify Store and i want my application to add a javascript snippet in all the store pages. For this I want my application to modify the current theme, by using Shopify API, and add the javascript snippet to that theme.
I know of several ways to do it but they have several disadvantage:
Add a Shopify Asset/Snippet - The store owner has to manually modify the store's theme to link to the asset/snippet.
Add a script tag - I want my javascript to be embedded and not to be downloaded from a different source. A different source means longer page loads and i do not want my site to extend the page load.
Add an application proxy - This can also extend the loading time.
Can you suggest on what is the correct way to do it?
Add a script tag and be done with it. No other pattern offers up the same customer experience. When they install your App, your script is available. When they uninstall your App, their theme reverts nicely. Worrying about the load times of your asset is not worth it if you have done your job, and minimized your code and provided a fast CDN address for it.
In 2022, you get Theme App Extensions for OS 2.0. Do that!! Best way to add JS to a theme/store.
Are you using the embedded apps SDK? I'm pretty sure they have some option that makes this easier, like you can create a "sidebar" on every page and position it wherever you want (hidden if necessary).
Answering you question: the good way is using ScriptTag. Consider this article on this: https://docs.shopify.com/api/unlinked/using-javascript-responsibly
Still if you need to add code snippet as an asset, I want to point out that it's not necessary the customer must manually update the theme. As far as I know, you can add your snippet as an asset and then update another -- theme liquid template.
https://docs.shopify.com/api/asset#update
For the reasons described in an article I've provided above, you should not do that.

Javascript library work with Meteor.js only when placed in the same directory as template

I am new to Meteor.js and is trying to use a Javascript library HighCharts without pulling from Atmosphere. I am calling this Javascript library from a template helper in client/views/main.js to be displayed in client/views/main.html.
When I place all the library's files into client/compatibility/highcharts, I get a long bunch of errors in the browser Javascript console.
When I place all the files into packages/highcharts, I get a single clientside console error Uncaught TypeError: Object [object Object] has no method 'highcharts'
However it works only when I move only highcharts.js to client/views, it works perfectly.
Is this the correct way to use a downloaded Javascript library? It seems strange that one of the library's .js files must be in the same directory as the template file.
The only thing that goes to packages are well... packages. Only JS that is specially built using the packaging API can be placed there.
client/compatibility are for scripts build the traditional way. They are not wrapped in a scope (IIFE I suppose) making them global, like ordinary scripts. However, they are loded before other client-side scripts. If this was a jQuery plugin, but you use Meteor's jQuery, there is a chance that you might be loading the plugin before the library. This will cause an error.
The usual way to do this is to use a Meteor-packaged version of your plugin, in this case, a packaged Highcharts. Otherwise, you just take a library and package as a meteor package. It isn't that hard actually.
If you ever wondered where to place what, there's an unofficial FAQ that covers this.

Categories