-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d8d163
commit e26df5b
Showing
6 changed files
with
49 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,26 @@ | ||
import axios from "@/services/axios"; | ||
|
||
export const SCHEMA_NOT_SUPPORTED = 1; | ||
export const SCHEMA_LOAD_ERROR = 2; | ||
export const IMG_ROOT = "/static/images/db-logos"; | ||
|
||
export let DataSource = null; // eslint-disable-line import/no-mutable-exports | ||
|
||
function DataSourceService($q, $resource, $http) { | ||
function fetchSchema(dataSourceId, refresh = false) { | ||
const DataSource = { | ||
query: () => axios.get("api/data_sources"), | ||
get: ({ id }) => axios.get(`api/data_sources/${id}`), | ||
types: () => axios.get("api/data_sources/types"), | ||
create: data => axios.post(`api/data_sources`, data), | ||
save: data => axios.post(`api/data_sources/${data.id}`, data), | ||
test: data => axios.post(`api/data_sources/${data.id}/test`), | ||
delete: ({ id }) => axios.delete(`api/data_sources/${id}`), | ||
fetchSchema: (data, refresh = false) => { | ||
const params = {}; | ||
|
||
if (refresh) { | ||
params.refresh = true; | ||
} | ||
|
||
return $http.get(`api/data_sources/${dataSourceId}/schema`, { params }); | ||
} | ||
|
||
const actions = { | ||
get: { method: "GET", cache: false, isArray: false }, | ||
query: { method: "GET", cache: false, isArray: true }, | ||
save: { method: "POST" }, | ||
types: { | ||
method: "GET", | ||
cache: false, | ||
isArray: true, | ||
url: "api/data_sources/types", | ||
}, | ||
test: { | ||
method: "POST", | ||
cache: false, | ||
isArray: false, | ||
url: "api/data_sources/:id/test", | ||
}, | ||
}; | ||
|
||
const DataSourceResource = $resource("api/data_sources/:id", { id: "@id" }, actions); | ||
|
||
DataSourceResource.prototype.getSchema = function getSchema(refresh = false) { | ||
if (this._schema === undefined || refresh) { | ||
return fetchSchema(this.id, refresh).then(response => { | ||
const data = response.data; | ||
|
||
this._schema = data; | ||
|
||
return data; | ||
}); | ||
} | ||
|
||
return $q.resolve(this._schema); | ||
}; | ||
|
||
return DataSourceResource; | ||
} | ||
|
||
export default function init(ngModule) { | ||
ngModule.factory("DataSource", DataSourceService); | ||
|
||
ngModule.run($injector => { | ||
DataSource = $injector.get("DataSource"); | ||
}); | ||
} | ||
return axios.get(`api/data_sources/${data.id}/schema`, { params }); | ||
}, | ||
}; | ||
|
||
init.init = true; | ||
export default DataSource; |