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