debian-mirror-gitlab/app/assets/javascripts/commit_merge_requests.js

79 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2021-09-30 23:02:18 +05:30
import createFlash from './flash';
2018-03-17 18:26:18 +05:30
import axios from './lib/utils/axios_utils';
import { n__, s__ } from './locale';
export function getHeaderText(childElementCount, mergeRequestCount) {
if (childElementCount === 0) {
return `${mergeRequestCount} ${n__('merge request', 'merge requests', mergeRequestCount)}`;
}
return ',';
}
export function createHeader(childElementCount, mergeRequestCount) {
const headerText = getHeaderText(childElementCount, mergeRequestCount);
return $('<span />', {
2020-07-28 23:09:34 +05:30
class: 'gl-mr-2',
2018-03-17 18:26:18 +05:30
text: headerText,
});
}
export function createLink(mergeRequest) {
return $('<a />', {
2020-07-28 23:09:34 +05:30
class: 'gl-mr-2',
2018-03-17 18:26:18 +05:30
href: mergeRequest.path,
text: `!${mergeRequest.iid}`,
});
}
export function createTitle(mergeRequest) {
return $('<span />', {
text: mergeRequest.title,
});
}
export function createItem(mergeRequest) {
const $item = $('<span />');
const $link = createLink(mergeRequest);
const $title = createTitle(mergeRequest);
$item.append($link);
$item.append($title);
return $item;
}
export function createContent(mergeRequests) {
const $content = $('<span />');
if (mergeRequests.length === 0) {
$content.text(s__('Commits|No related merge requests found'));
} else {
2021-03-08 18:12:59 +05:30
mergeRequests.forEach((mergeRequest) => {
2018-03-17 18:26:18 +05:30
const $header = createHeader($content.children().length, mergeRequests.length);
const $item = createItem(mergeRequest);
$content.append($header);
$content.append($item);
});
}
return $content;
}
export function fetchCommitMergeRequests() {
const $container = $('.merge-requests');
2018-12-13 13:39:08 +05:30
axios
.get($container.data('projectCommitPath'))
2021-03-08 18:12:59 +05:30
.then((response) => {
2018-03-17 18:26:18 +05:30
const $content = createContent(response.data);
$container.html($content);
})
2021-09-30 23:02:18 +05:30
.catch(() =>
createFlash({
message: s__('Commits|An error occurred while fetching merge requests data.'),
}),
);
2018-03-17 18:26:18 +05:30
}