grafana/public/app/angular/diff-view.ts
Jack Westbrook 3a7623753b
Build: Replace babel-loader with esbuild-loader (#57837)
* build(webpack): replace babel-loader with esbuild-loader

* build(webpack): add esbuild minifier to production builds

* Wip

* Removed ngInject and replaced with manual inject params

* chore: bump esbuild to 0.15.13

* Fixed angular issues

* build(frontend): update esbuild to 0.16.16

* chore(webpack): support browserslist for esbuild

* build(esbuild): unify versions of esbuild to 0.16.17 and esbuild-loader to 2.21.0

Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
2023-01-23 12:15:05 +01:00

77 lines
1.6 KiB
TypeScript

import angular from 'angular';
import { GrafanaRootScope } from 'app/angular/GrafanaCtrl';
import coreModule from './core_module';
export class DeltaCtrl {
observer: any;
constructor() {
const waitForCompile = () => {};
this.observer = new MutationObserver(waitForCompile);
const observerConfig = {
attributes: true,
attributeFilter: ['class'],
characterData: false,
childList: true,
subtree: false,
};
this.observer.observe(angular.element('.delta-html')[0], observerConfig);
}
$onDestroy() {
this.observer.disconnect();
}
}
export function delta() {
return {
controller: DeltaCtrl,
replace: false,
restrict: 'A',
};
}
coreModule.directive('diffDelta', delta);
// Link to JSON line number
export class LinkJSONCtrl {
static $inject = ['$scope', '$rootScope', '$anchorScroll'];
constructor(private $scope: any, private $rootScope: GrafanaRootScope, private $anchorScroll: any) {}
goToLine(line: number) {
let unbind: () => void;
const scroll = () => {
this.$anchorScroll(`l${line}`);
unbind();
};
this.$scope.switchView().then(() => {
unbind = this.$rootScope.$on('json-diff-ready', scroll.bind(this));
});
}
}
export function linkJson() {
return {
controller: LinkJSONCtrl,
controllerAs: 'ctrl',
replace: true,
restrict: 'E',
scope: {
line: '@lineDisplay',
link: '@lineLink',
switchView: '&',
},
template: `<a class="diff-linenum btn btn-inverse btn-small" ng-click="ctrl.goToLine(link)">Line {{ line }}</a>`,
};
}
coreModule.directive('diffLinkJson', linkJson);