mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-06 20:41:17 +01:00
WIP showing updated flag data, history, updating flag data
This commit is contained in:
@@ -22,6 +22,8 @@ define('admin/manage/flags', [
|
||||
handleDelete();
|
||||
handleInfiniteScroll();
|
||||
handleGraphs();
|
||||
|
||||
updateFlagDetails(ajaxify.data.posts);
|
||||
handleFormActions();
|
||||
};
|
||||
|
||||
@@ -152,6 +154,29 @@ define('admin/manage/flags', [
|
||||
});
|
||||
}
|
||||
|
||||
function updateFlagDetails(source) {
|
||||
// As the flag details are returned in the API, update the form controls to show the correct data
|
||||
|
||||
// Create reference hash for use in this method
|
||||
source = source.reduce(function(memo, cur) {
|
||||
memo[cur.pid] = cur.flagData;
|
||||
return memo;
|
||||
}, {});
|
||||
|
||||
components.get('posts/flag').each(function(idx, el) {
|
||||
var pid = el.getAttribute('data-pid');
|
||||
var el = $(el);
|
||||
|
||||
if (source[pid]) {
|
||||
for(var prop in source[pid]) {
|
||||
if (source[pid].hasOwnProperty(prop)) {
|
||||
el.find('[name="' + prop + '"]').val(source[pid][prop]);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function handleFormActions() {
|
||||
components.get('posts/flag').find('[component="posts/flag/update"]').on('click', function() {
|
||||
var pid = $(this).parents('[component="posts/flag"]').attr('data-pid');
|
||||
|
||||
@@ -35,6 +35,20 @@ flagsController.get = function(req, res, next) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
// Parse out flag data into its own object inside each post hash
|
||||
results.posts = results.posts.map(function(postObj) {
|
||||
for(var prop in postObj) {
|
||||
postObj.flagData = postObj.flagData || {};
|
||||
|
||||
if (postObj.hasOwnProperty(prop) && prop.startsWith('flag:')) {
|
||||
postObj.flagData[prop.slice(5)] = postObj[prop];
|
||||
delete postObj[prop];
|
||||
}
|
||||
}
|
||||
|
||||
return postObj;
|
||||
});
|
||||
|
||||
// Minimise data set for assignees so tjs does less work
|
||||
results.assignees = results.assignees.map(function(userObj) {
|
||||
var keep = ['uid', 'username'];
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var winston = require('winston');
|
||||
var db = require('../database');
|
||||
var user = require('../user');
|
||||
var analytics = require('../analytics');
|
||||
@@ -171,7 +172,7 @@ module.exports = function(Posts) {
|
||||
}, next);
|
||||
},
|
||||
posts: function(next) {
|
||||
Posts.getPostSummaryByPids(pids, uid, {stripTags: false, extraFields: ['flags']}, next);
|
||||
Posts.getPostSummaryByPids(pids, uid, {stripTags: false, extraFields: ['flags', 'flag:assignee', 'flag:state', 'flag:notes', 'flag:history']}, next);
|
||||
}
|
||||
}, next);
|
||||
},
|
||||
@@ -190,8 +191,22 @@ module.exports = function(Posts) {
|
||||
}
|
||||
|
||||
results.posts.forEach(function(post, index) {
|
||||
var history;
|
||||
|
||||
if (post) {
|
||||
post.flagReasons = reasons[index];
|
||||
|
||||
// Expand flag history
|
||||
try {
|
||||
history = JSON.parse(post['flag:history'] || '[]');
|
||||
history.map(function(event) {
|
||||
event.timestampISO = new Date(event.timestamp).toISOString();
|
||||
return event;
|
||||
});
|
||||
post['flag:history'] = history;
|
||||
} catch (e) {
|
||||
winston.warn('[posts/getFlags] Unable to deserialise post flag history, likely malformed data');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -256,6 +271,36 @@ module.exports = function(Posts) {
|
||||
}
|
||||
}
|
||||
|
||||
// Append changes to history string
|
||||
if (changes.length) {
|
||||
try {
|
||||
var history = JSON.parse(postData['flag:history'] || '[]');
|
||||
|
||||
changes.forEach(function(property) {
|
||||
switch(property) {
|
||||
case 'assignee': // intentional fall-through
|
||||
case 'state':
|
||||
history.unshift({
|
||||
type: property,
|
||||
value: flagObj[property],
|
||||
timestamp: Date.now()
|
||||
});
|
||||
break;
|
||||
|
||||
case 'notes':
|
||||
history.unshift({
|
||||
type: property,
|
||||
timestamp: Date.now()
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
changeset['flag:history'] = JSON.stringify(history);
|
||||
} catch (e) {
|
||||
winston.warn('[posts/updateFlagData] Unable to deserialise post flag history, likely malformed data');
|
||||
}
|
||||
}
|
||||
|
||||
// Save flag data into post hash
|
||||
Posts.setPostFields(pid, changeset, callback);
|
||||
});
|
||||
|
||||
@@ -144,9 +144,18 @@
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<h5>[[topic:flag_manage_history]]</h5>
|
||||
<!-- IF !../flagHistory.length -->
|
||||
<!-- IF !posts.flagData.history.length -->
|
||||
<div class="alert alert-info">[[topic:flag_manage_no_history]]</div>
|
||||
<!-- ENDIF !../flagHistory.length -->
|
||||
<!-- ELSE -->
|
||||
<ul class="list-group">
|
||||
<!-- BEGIN posts.flagData.history -->
|
||||
<li class="list-group-item">
|
||||
<div class="pull-right"><small><span class="timeago" title="{../timestampISO}"></span></small></div>
|
||||
Updated <span class="label label-info">{../type}</span> to {../value}
|
||||
</li>
|
||||
<!-- END posts.flagData.history -->
|
||||
</ul>
|
||||
<!-- ENDIF !posts.flagData.history.length -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user