From ac23afac5d4cd42dc457bdcf297678c3d96d7eb0 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Thu, 13 Jul 2017 17:16:23 +0200 Subject: [PATCH] Stopped characters with poor names from having failed URL's --- rpg-docs/Model/Character/Characters.js | 5 ++++- rpg-docs/Routes/Routes.js | 2 +- rpg-docs/client/globalHelpers/characterPath.js | 3 +++ rpg-docs/client/views/characterList/characterList.html | 2 +- rpg-docs/client/views/characterList/characterSideList.html | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 rpg-docs/client/globalHelpers/characterPath.js diff --git a/rpg-docs/Model/Character/Characters.js b/rpg-docs/Model/Character/Characters.js index f8a2d33f..e75430b2 100644 --- a/rpg-docs/Model/Character/Characters.js +++ b/rpg-docs/Model/Character/Characters.js @@ -4,7 +4,7 @@ Characters = new Mongo.Collection("characters"); Schemas.Character = new SimpleSchema({ //strings name: {type: String, defaultValue: "", trim: false, optional: true}, - urlName: {type: String, defaultValue: "", trim: false, optional: true}, + urlName: {type: String, defaultValue: "-", trim: false, optional: true}, alignment: {type: String, defaultValue: "", trim: false, optional: true}, gender: {type: String, defaultValue: "", trim: false, optional: true}, race: {type: String, defaultValue: "", trim: false, optional: true}, @@ -547,6 +547,9 @@ if (Meteor.isServer){ Characters.update(doc._id, {$set: {urlName}}); } }); + Characters.before.insert(function(userId, doc) { + doc.urlName = getSlug(doc.name, {maintainCase: true}) || "-"; + }); } Characters.allow({ diff --git a/rpg-docs/Routes/Routes.js b/rpg-docs/Routes/Routes.js index 14ac42ff..90676c79 100644 --- a/rpg-docs/Routes/Routes.js +++ b/rpg-docs/Routes/Routes.js @@ -43,7 +43,7 @@ Router.map(function() { var _id = this.params._id var character = Characters.findOne(_id); var urlName = character && character.urlName; - var path = `\/character\/${_id}\/${urlName}`; + var path = `\/character\/${_id}\/${urlName || "-"}`; Router.go(path,{},{replaceState:true}); }, }); diff --git a/rpg-docs/client/globalHelpers/characterPath.js b/rpg-docs/client/globalHelpers/characterPath.js new file mode 100644 index 00000000..723ee07b --- /dev/null +++ b/rpg-docs/client/globalHelpers/characterPath.js @@ -0,0 +1,3 @@ +Template.registerHelper("characterPath", function(char) { + return `\/character\/${char._id}\/${char.urlName || "-"}`; +}); diff --git a/rpg-docs/client/views/characterList/characterList.html b/rpg-docs/client/views/characterList/characterList.html index 82e12b92..acde48cb 100644 --- a/rpg-docs/client/views/characterList/characterList.html +++ b/rpg-docs/client/views/characterList/characterList.html @@ -11,7 +11,7 @@ {{#if characters.count}}
{{# each characters}} - + diff --git a/rpg-docs/client/views/characterList/characterSideList.html b/rpg-docs/client/views/characterList/characterSideList.html index e65d7804..38a19859 100644 --- a/rpg-docs/client/views/characterList/characterSideList.html +++ b/rpg-docs/client/views/characterList/characterSideList.html @@ -2,7 +2,7 @@ {{#if characters.count}}