Node.js based forum software built for the modern web
WIP showing updated flag data, history, updating flag data
Julian Lamd04a10225c2e
diff --git a/public/src/admin/manage/flags.js b/public/src/admin/manage/flags.jsindex 8885d7b8a5..3b235677ca 100644--- a/public/src/admin/manage/flags.js+++ b/public/src/admin/manage/flags.js@@ -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');diff --git a/src/controllers/admin/flags.js b/src/controllers/admin/flags.jsindex f21cc773ad..61413ce1f0 100644--- a/src/controllers/admin/flags.js+++ b/src/controllers/admin/flags.js@@ -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 workresults.assignees = results.assignees.map(function(userObj) {var keep = ['uid', 'username'];diff --git a/src/posts/flags.js b/src/posts/flags.jsindex ba0196bedf..6a9ad6ecfd 100644--- a/src/posts/flags.js+++ b/src/posts/flags.js@@ -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 hashPosts.setPostFields(pid, changeset, callback);});diff --git a/src/views/admin/manage/flags.tpl b/src/views/admin/manage/flags.tplindex 04e7d86d1f..40416d3a70 100644--- a/src/views/admin/manage/flags.tpl+++ b/src/views/admin/manage/flags.tpl@@ -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>