Просмотр исходного кода

feat(panel): active tab is now placed in querystring aswell

bergquist 9 лет назад
Родитель
Сommit
617d18e587

+ 11 - 3
public/app/features/panel/panel_ctrl.ts

@@ -91,16 +91,24 @@ export class PanelCtrl {
     this.editModeInitiated = true;
     this.events.emit('init-edit-mode', null);
 
-    var route = this.$injector.get('$route');
-    if (route.current.params.editorTab) {
+    var routeParams = this.$injector.get('$routeParams');
+    if (routeParams.editorTab) {
       this.editorTabs.forEach((tab, i) => {
-        if (tab.title === route.current.params.editorTab) {
+        if (tab.title === routeParams.editorTab) {
           this.editorTabIndex = i;
         }
       });
     }
   }
 
+  changeTab(newIndex) {
+    this.editorTabIndex = newIndex;
+    var route = this.$injector.get('$route');
+
+    route.current.params.editorTab = this.editorTabs[newIndex].title;
+    route.updateParams();
+  }
+
   addEditorTab(title, directiveFn, index?) {
     var editorTab = {title, directiveFn};
 

+ 1 - 1
public/app/features/panel/panel_directive.ts

@@ -36,7 +36,7 @@ var panelTemplate = `
 
         <ul class="gf-tabs">
           <li class="gf-tabs-item" ng-repeat="tab in ::ctrl.editorTabs">
-            <a class="gf-tabs-link" ng-click="ctrl.editorTabIndex = $index" ng-class="{active: ctrl.editorTabIndex === $index}">
+            <a class="gf-tabs-link" ng-click="ctrl.changeTab($index)" ng-class="{active: ctrl.editorTabIndex === $index}">
               {{::tab.title}}
             </a>
           </li>