The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/dashboard/validation_srv.ts

46 lines
1.1 KiB

import coreModule from 'app/core/core_module';
export class ValidationSrv {
rootName = 'root';
/** @ngInject */
constructor(private $q, private backendSrv) {}
validateNewDashboardOrFolderName(name) {
name = (name || '').trim();
if (name.length === 0) {
return this.$q.reject({
type: 'REQUIRED',
message: 'Name is required',
});
}
if (name.toLowerCase() === this.rootName) {
return this.$q.reject({
type: 'EXISTING',
message: 'A folder or dashboard with the same name already exists',
});
}
let deferred = this.$q.defer();
this.backendSrv.search({ query: name }).then(res => {
for (let hit of res) {
if (name.toLowerCase() === hit.title.toLowerCase()) {
deferred.reject({
type: 'EXISTING',
message: 'A folder or dashboard with the same name already exists',
});
break;
}
}
deferred.resolve();
});
return deferred.promise;
}
}
coreModule.service('validationSrv', ValidationSrv);