mirror of https://github.com/grafana/grafana
parent
eacc46da6d
commit
ad94f99d57
@ -1,9 +1,9 @@ |
||||
package dtos |
||||
|
||||
type AppPlugin struct { |
||||
Type string `json:"type"` |
||||
Enabled bool `json:"enabled"` |
||||
PinNavLinks bool `json:"pin_nav_links"` |
||||
Module string `json:"module"` |
||||
JsonData map[string]interface{} `json:"jsonData"` |
||||
Type string `json:"type"` |
||||
Enabled bool `json:"enabled"` |
||||
Pinned bool `json:"pinned"` |
||||
Module string `json:"module"` |
||||
JsonData map[string]interface{} `json:"jsonData"` |
||||
} |
||||
|
||||
@ -1,58 +0,0 @@ |
||||
define([ |
||||
'angular', |
||||
'lodash', |
||||
], |
||||
function (angular, _) { |
||||
'use strict'; |
||||
|
||||
var module = angular.module('grafana.services'); |
||||
|
||||
module.service('appSrv', function($rootScope, $timeout, $q, backendSrv) { |
||||
var self = this; |
||||
this.init = function() { |
||||
console.log("appSrv init"); |
||||
this.apps = {}; |
||||
}; |
||||
|
||||
this.get = function(type) { |
||||
return $q(function(resolve) { |
||||
if (type in self.apps) { |
||||
return resolve(self.apps[type]); |
||||
} |
||||
backendSrv.get('api/org/apps').then(function(results) { |
||||
_.forEach(results, function(p) { |
||||
self.apps[p.type] = p; |
||||
}); |
||||
return resolve(self.apps[type]); |
||||
}); |
||||
}); |
||||
}; |
||||
|
||||
this.getAll = function() { |
||||
return $q(function(resolve) { |
||||
if (!_.isEmpty(self.apps)) { |
||||
return resolve(self.apps); |
||||
} |
||||
backendSrv.get('api/org/apps').then(function(results) { |
||||
_.forEach(results, function(p) { |
||||
self.apps[p.type] = p; |
||||
}); |
||||
return resolve(self.apps); |
||||
}); |
||||
}); |
||||
}; |
||||
|
||||
this.update = function(app) { |
||||
return $q(function(resolve, reject) { |
||||
backendSrv.post('api/org/apps', app).then(function(resp) { |
||||
self.apps[app.type] = app; |
||||
resolve(resp); |
||||
}, function(resp) { |
||||
reject(resp); |
||||
}); |
||||
}); |
||||
}; |
||||
|
||||
this.init(); |
||||
}); |
||||
}); |
||||
@ -0,0 +1,47 @@ |
||||
///<reference path="../../headers/common.d.ts" />
|
||||
|
||||
import config = require('app/core/config'); |
||||
import angular from 'angular'; |
||||
|
||||
export class AppSrv { |
||||
apps: any = {}; |
||||
|
||||
/** @ngInject */ |
||||
constructor( |
||||
private $rootScope, |
||||
private $timeout, |
||||
private $q, |
||||
private backendSrv) { |
||||
} |
||||
|
||||
get(type) { |
||||
if (this.apps[type]) { |
||||
return this.$q.when(this.apps[type]); |
||||
} |
||||
return this.getAll().then(() => { |
||||
return this.apps[type]; |
||||
}); |
||||
} |
||||
|
||||
|
||||
getAll() { |
||||
if (!_.isEmpty(this.apps)) { |
||||
return this.$q.when(this.apps); |
||||
} |
||||
|
||||
return this.backendSrv.get('api/org/apps').then(results => { |
||||
this.apps = results.reduce((prev, current) => { |
||||
prev[current.type] = current; |
||||
}, {}); |
||||
return this.apps; |
||||
}); |
||||
} |
||||
|
||||
update(app) { |
||||
return this.backendSrv.post('api/org/apps', app).then(resp => { |
||||
this.apps[app.type] = app; |
||||
}); |
||||
} |
||||
} |
||||
|
||||
angular.module('grafana.services').service('appSrv', AppSrv); |
||||
Loading…
Reference in new issue