diff options
Diffstat (limited to 'app/assets/javascripts/api')
-rw-r--r-- | app/assets/javascripts/api/alert_management_alerts_api.js | 62 | ||||
-rw-r--r-- | app/assets/javascripts/api/projects_api.js | 2 |
2 files changed, 64 insertions, 0 deletions
diff --git a/app/assets/javascripts/api/alert_management_alerts_api.js b/app/assets/javascripts/api/alert_management_alerts_api.js new file mode 100644 index 00000000000..fa66ca5b3dd --- /dev/null +++ b/app/assets/javascripts/api/alert_management_alerts_api.js @@ -0,0 +1,62 @@ +import axios from '~/lib/utils/axios_utils'; +import { buildApiUrl } from '~/api/api_utils'; +import { ContentTypeMultipartFormData } from '~/lib/utils/headers'; + +const ALERT_METRIC_IMAGES_PATH = + '/api/:version/projects/:id/alert_management_alerts/:alert_iid/metric_images'; +const ALERT_SINGLE_METRIC_IMAGE_PATH = + '/api/:version/projects/:id/alert_management_alerts/:alert_iid/metric_images/:image_id'; + +export function fetchAlertMetricImages({ alertIid, id }) { + const metricImagesUrl = buildApiUrl(ALERT_METRIC_IMAGES_PATH) + .replace(':id', encodeURIComponent(id)) + .replace(':alert_iid', encodeURIComponent(alertIid)); + + return axios.get(metricImagesUrl); +} + +export function uploadAlertMetricImage({ alertIid, id, file, url = null, urlText = null }) { + const options = { headers: { ...ContentTypeMultipartFormData } }; + const metricImagesUrl = buildApiUrl(ALERT_METRIC_IMAGES_PATH) + .replace(':id', encodeURIComponent(id)) + .replace(':alert_iid', encodeURIComponent(alertIid)); + + // Construct multipart form data + const formData = new FormData(); + formData.append('file', file); + if (url) { + formData.append('url', url); + } + if (urlText) { + formData.append('url_text', urlText); + } + + return axios.post(metricImagesUrl, formData, options); +} + +export function updateAlertMetricImage({ alertIid, id, imageId, url = null, urlText = null }) { + const metricImagesUrl = buildApiUrl(ALERT_SINGLE_METRIC_IMAGE_PATH) + .replace(':id', encodeURIComponent(id)) + .replace(':alert_iid', encodeURIComponent(alertIid)) + .replace(':image_id', encodeURIComponent(imageId)); + + // Construct multipart form data + const formData = new FormData(); + if (url != null) { + formData.append('url', url); + } + if (urlText != null) { + formData.append('url_text', urlText); + } + + return axios.put(metricImagesUrl, formData); +} + +export function deleteAlertMetricImage({ alertIid, id, imageId }) { + const individualMetricImageUrl = buildApiUrl(ALERT_SINGLE_METRIC_IMAGE_PATH) + .replace(':id', encodeURIComponent(id)) + .replace(':alert_iid', encodeURIComponent(alertIid)) + .replace(':image_id', encodeURIComponent(imageId)); + + return axios.delete(individualMetricImageUrl); +} diff --git a/app/assets/javascripts/api/projects_api.js b/app/assets/javascripts/api/projects_api.js index b018db9a02d..7666f558eb5 100644 --- a/app/assets/javascripts/api/projects_api.js +++ b/app/assets/javascripts/api/projects_api.js @@ -2,6 +2,8 @@ import { DEFAULT_PER_PAGE } from '~/api'; import axios from '../lib/utils/axios_utils'; import { buildApiUrl } from './api_utils'; +export * from './alert_management_alerts_api'; + const PROJECTS_PATH = '/api/:version/projects.json'; const PROJECT_IMPORT_MEMBERS_PATH = '/api/:version/projects/:id/import_project_members/:project_id'; |