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

63 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-11-08 19:23:39 +05:30
/* eslint-disable class-methods-use-this */
2017-08-17 22:00:37 +05:30
2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2022-04-04 11:22:00 +05:30
import { setCookie } from '~/lib/utils/common_utils';
2023-05-27 22:25:52 +05:30
import { createAlert } from '~/alert';
2021-04-29 21:17:54 +05:30
import { s__ } from '~/locale';
2018-03-17 18:26:18 +05:30
import { localTimeAgo } from './lib/utils/datetime_utility';
2021-03-11 19:13:27 +05:30
import Pager from './pager';
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
export default class Activities {
2021-04-29 21:17:54 +05:30
constructor(containerSelector = '') {
this.containerSelector = containerSelector;
this.containerEl = this.containerSelector
? document.querySelector(this.containerSelector)
: undefined;
this.$contentList = $('.content_list');
2017-09-10 17:25:29 +05:30
2021-04-29 21:17:54 +05:30
this.loadActivities();
2018-12-13 13:39:08 +05:30
2021-03-08 18:12:59 +05:30
$('.event-filter-link').on('click', (e) => {
2017-08-17 22:00:37 +05:30
e.preventDefault();
this.toggleFilter(e.currentTarget);
this.reloadActivities();
});
}
2021-04-29 21:17:54 +05:30
loadActivities() {
Pager.init({
limit: 20,
preload: true,
prepareData: (data) => data,
successCallback: () => this.updateTooltips(),
errorCallback: () =>
2022-07-23 23:45:48 +05:30
createAlert({
2021-04-29 21:17:54 +05:30
message: s__(
2022-05-07 20:08:51 +05:30
'Activity|An error occurred while retrieving activity. Reload the page to try again.',
2021-04-29 21:17:54 +05:30
),
parent: this.containerEl,
}),
container: this.containerSelector,
});
}
2017-08-17 22:00:37 +05:30
updateTooltips() {
2021-09-30 23:02:18 +05:30
localTimeAgo(document.querySelectorAll('.content_list .js-timeago'));
2017-08-17 22:00:37 +05:30
}
reloadActivities() {
2021-04-29 21:17:54 +05:30
this.$contentList.html('');
this.loadActivities();
2017-08-17 22:00:37 +05:30
}
toggleFilter(sender) {
const $sender = $(sender);
const filter = $sender.attr('id').split('_')[0];
$('.event-filter .active').removeClass('active');
2022-04-04 11:22:00 +05:30
setCookie('event_filter', filter);
2017-08-17 22:00:37 +05:30
$sender.closest('li').toggleClass('active');
}
}