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';
2017-08-17 22:00:37 +05:30
import Cookies from 'js-cookie';
2021-04-29 21:17:54 +05:30
import createFlash from '~/flash';
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: () =>
createFlash({
message: s__(
'Activity|An error occured while retrieving activity. Reload the page to try again.',
),
parent: this.containerEl,
}),
container: this.containerSelector,
});
}
2017-08-17 22:00:37 +05:30
updateTooltips() {
2018-03-17 18:26:18 +05:30
localTimeAgo($('.js-timeago', '.content_list'));
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');
Cookies.set('event_filter', filter);
$sender.closest('li').toggleClass('active');
}
}