Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/api/alert_management_alerts_api.js')
-rw-r--r--app/assets/javascripts/api/alert_management_alerts_api.js62
1 files changed, 62 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);
+}