Browse Source

bringing some enhancements forward from DTP Sites

master
Rob Colbert 2 years ago
parent
commit
8c1665da16
  1. 2
      app/controllers/admin/user.js
  2. 14
      app/models/lib/resource-stats.js
  3. 7
      app/services/display-engine.js
  4. 26
      app/services/user.js
  5. 4
      app/views/admin/user/form.pug
  6. 21
      client/js/site-app.js
  7. 2
      client/less/site/button.less
  8. 8
      lib/client/js/dtp-display-engine.js
  9. 21
      lib/site-platform.js

2
app/controllers/admin/user.js

@ -47,7 +47,7 @@ class UserController extends SiteController {
async postUpdateUser (req, res, next) {
const { user: userService } = this.dtp.services;
try {
await userService.update(res.locals.userAccount, req.body);
await userService.updateForAdmin(res.locals.userAccount, req.body);
res.redirect('/admin/user');
} catch (error) {
return next(error);

14
app/models/lib/resource-stats.js

@ -16,4 +16,16 @@ module.exports.ResourceStats = new Schema({
module.exports.ResourceStatsDefaults = {
uniqueVisitCount: 0,
totalVisitCount: 0,
};
};
module.exports.CommentStats = new Schema({
upvoteCount: { type: Number, default: 0, required: true },
downvoteCount: { type: Number, default: 0, required: true },
replyCount: { type: Number, default: 0, required: true },
});
module.exports.CommentStatsDefaults = {
upvoteCount: 0,
downvoteCount: 0,
replyCount: 0,
};

7
app/services/display-engine.js

@ -102,6 +102,13 @@ class DisplayList {
params: { remove, add },
});
}
navigateTo (href) {
this.commands.push({
action: 'navigateTo',
params: { href },
});
}
}
class DisplayEngineService extends SiteService {

26
app/services/user.js

@ -114,6 +114,32 @@ class UserService {
}
async update (user, userDefinition) {
if (!user.flags.canLogin) {
throw SiteError(403, 'Invalid user account operation');
}
// strip characters we don't want to allow in username
userDefinition.username = striptags(userDefinition.username.trim().replace(/[^A-Za-z0-9\-_]/gi, ''));
const username_lc = userDefinition.username.toLowerCase();
userDefinition.displayName = striptags(userDefinition.displayName.trim());
userDefinition.bio = striptags(userDefinition.bio.trim());
this.log.info('updating user', { userDefinition });
await User.updateOne(
{ _id: user._id },
{
$set: {
username: userDefinition.username,
username_lc,
displayName: userDefinition.displayName,
bio: userDefinition.bio,
},
},
);
}
async updateForAdmin (user, userDefinition) {
// strip characters we don't want to allow in username
userDefinition.username = striptags(userDefinition.username.trim().replace(/[^A-Za-z0-9\-_]/gi, ''));
const username_lc = userDefinition.username.toLowerCase();

4
app/views/admin/user/form.pug

@ -4,14 +4,14 @@ block content
div(uk-grid).uk-grid-small
div(class="uk-width-1-1 uk-width-2-3@l")
form(method="POST", action=`/admin/user/${userAccount._id}`).uk-form
input(type="hidden", name="username", value= userAccount.username)
input(type="hidden", name="displayName", value= userAccount.displayName)
.uk-card.uk-card-secondary.uk-card-small
.uk-card-header
.uk-text-large= userAccount.displayName || userAccount.email
div= userAccount.username
.uk-card-body
input(type="hidden", name="username", value= userAccount.username)
input(type="hidden", name="displayName", value= userAccount.displayName)
.uk-margin
label(for="bio").uk-form-label.sr-only Bio
textarea(id="bio", name="bio", rows="4", placeholder= "Enter profile bio").uk-textarea.uk-resize-vertical= userAccount.bio

21
client/js/site-app.js

@ -49,6 +49,19 @@ export default class DtpSiteApp extends DtpApp {
}
this.charts = {/* will hold rendered charts */};
this.scrollToHash();
}
async scrollToHash ( ) {
const { hash } = window.location;
if (hash === '') {
return;
}
const target = document.getElementById(hash.slice(1));
if (target && target.scrollIntoView) {
target.scrollIntoView({ behavior: 'smooth' });
}
}
async connect ( ) {
@ -231,6 +244,14 @@ export default class DtpSiteApp extends DtpApp {
return;
}
async closeCurrentDialog ( ) {
if (!this.currentDialog) {
return;
}
this.currentDialog.hide();
delete this.currentDialog;
}
async copyHtmlToText (event, textContentId) {
const content = this.editor.getContent({ format: 'text' });
const text = document.getElementById(textContentId);

2
client/less/site/button.less

@ -120,6 +120,8 @@ button.uk-button.dtp-button-primary {
}
}
a.uk-button.dtp-button-secondary,
button.uk-button.dtp-button-secondary {
background: none;

8
lib/client/js/dtp-display-engine.js

@ -209,6 +209,10 @@ export default class DtpDisplayEngine {
}
async showModal (displayList, command) {
UIkit.modal.dialog(command.html);
UIkit.modal.dialog(command.params.html);
}
}
async navigateTo (displayList, command) {
window.location = command.params.href;
}
}

21
lib/site-platform.js

@ -322,26 +322,9 @@ module.exports.startWebServer = async (dtp) => {
res.locals.dtp = {
request: req,
};
res.locals.socialIcons = [
{
url: 'https://facebook.com',
label: 'Facebook',
icon: 'fa-facebook'
},
{
url: 'https://twitter.com',
label: 'Twitter',
icon: 'fa-twitter'
},
{
url: 'https://instagram.com',
label: 'Instagram',
icon: 'fa-instagram'
},
];
const settingsKey = `settings:${dtp.config.site.domainKey}:site`;
res.locals.site = dtp.config.site;
res.locals.site = Object.assign({ }, dtp.config.site);
const settings = await cacheService.getObject(settingsKey);
if (settings) {
@ -383,4 +366,4 @@ module.exports.startWebServer = async (dtp) => {
module.exports.shutdown = async ( ) => {
module.log.info('platform shutting down');
};
};

Loading…
Cancel
Save