3 const $ = require('jquery');
4 const _ = require('lodash');
5 const Backbone = require('backbone');
6 const Marionette = require('backbone.marionette');
7 require('./views/behaviors/isomorphic');
8 const debug = require('debug-proxy')('app:chat-messsage-reports');
9 const generatePermalink = require('gitter-web-shared/chat/generate-permalink');
11 const context = require('gitter-web-client-context');
13 function getAccountAgeString(user) {
15 const createdDate = new Date(user.accountCreatedDate);
19 (Date.now() - createdDate.getTime()) / (1000 * 60 * 60 * 24)
20 )} days, ${createdDate.getFullYear()}-${createdDate.getMonth()}-${createdDate.getDay()}
27 const ReportView = Marionette.ItemView.extend({
32 <td class="admin-chat-report-table-cell admin-chat-report-table-reporter-cell model-id-${_.escape(
33 data.reporterUser && data.reporterUser.id
35 <div class="admin-chat-report-table-reporter-cell-username">
36 ${_.escape(data.reporterUser ? data.reporterUser.username : 'Unknown')}
38 <div class="admin-chat-report-table-reporter-cell-id">
39 ${_.escape(data.reporterUserId)}
41 <div title="Account age">
42 ${_.escape(getAccountAgeString(data.reporterUser))}
45 <td class="admin-chat-report-table-cell admin-chat-report-table-message-author-cell model-id-${_.escape(
46 data.messageUser && data.messageUser.id
48 <div class="admin-chat-report-table-message-author-cell-username">
49 ${_.escape(data.messageUser ? data.messageUser.username : 'Unknown')}
51 <div class="admin-chat-report-table-message-author-cell-id">
52 ${_.escape(data.messageUserId)}
54 <div title="Account age">
55 ${_.escape(getAccountAgeString(data.messageUser))}
59 <td class="admin-chat-report-table-cell admin-chat-report-item-message-text">
61 Weight: <strong>${_.escape(data.weight)}</strong> -- ${_.escape(
65 <div class="admin-chat-report-table-message-cell-id">
66 ${_.escape(data.messageId)}
69 ${_.escape(data.messageText)}
73 <td class="admin-chat-report-table-cell admin-chat-report-table-room-cell">
74 <div class="admin-chat-report-table-room-cell-uri">
75 ${_.escape(data.message && data.message.toTroupe && data.message.toTroupe.uri)}
76 <a class="admin-chat-report-table-room-cell-link" href="${_.escape(
78 data.message.toTroupe &&
79 generatePermalink(data.message.toTroupe.uri, data.message.id)
81 <svg viewbox="0 128 768 768" xmlns="http://www.w3.org/2000/svg">
82 <path d="M640 768H128V257.90599999999995L256 256V128H0v768h768V576H640V768zM384 128l128 128L320 448l128 128 192-192 128 128V128H384z"/>
86 <div class="admin-chat-report-table-room-cell-id">
87 ${_.escape(data.message && data.message.toTroupe && data.message.toTroupe.id)}
94 const ReportCollectionView = Marionette.CompositeView.extend({
95 childView: ReportView,
96 childViewContainer: '.js-report-list',
98 childViewOptions: function(item) {
102 template: function() {
107 <td class="admin-chat-report-table-header-cell admin-chat-report-table-reporter-cell">
110 <td class="admin-chat-report-table-header-cell admin-chat-report-table-message-author-cell">
113 <td class="admin-chat-report-table-header-cell">
116 <td class="admin-chat-report-table-header-cell">
121 <tbody class="js-report-list"></tbody>
127 const DashboardView = Marionette.LayoutView.extend({
130 reportTable: { el: '.js-report-table', init: 'initReportCollectionView' }
134 initReportCollectionView: function(optionsForRegion) {
135 return new ReportCollectionView(
137 collection: new Backbone.Collection(this.model.get('reports'))
142 template: function(data) {
143 const reports = data.reports;
144 const lastReport = reports && reports[reports.length - 1];
146 let paginationLink = '';
150 <a href="?beforeId=${lastReport.id}">
157 <div class="dashboard">
158 <div class="js-report-table"></div>
170 const snapshot = context.getSnapshot('adminChatMessageReportDashboard');
172 debug('snapshot', snapshot);
175 el: $('.js-chat-message-report-dashboard-root'),
176 model: new Backbone.Model(snapshot)