Skip to content

Commit

Permalink
Stopped characters with poor names from having failed URL's
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaumRystra committed Jul 13, 2017
1 parent a411fb2 commit ac23afa
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
5 changes: 4 additions & 1 deletion rpg-docs/Model/Character/Characters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion rpg-docs/Routes/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
},
});
Expand Down
3 changes: 3 additions & 0 deletions rpg-docs/client/globalHelpers/characterPath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Template.registerHelper("characterPath", function(char) {
return `\/character\/${char._id}\/${char.urlName || "-"}`;
});
2 changes: 1 addition & 1 deletion rpg-docs/client/views/characterList/characterList.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{{#if characters.count}}
<div class="character-list layout horizontal wrap">
{{# each characters}}
<a class="character-card flex layout vertical end-justified" href="{{pathFor route="characterSheet" data=this}}">
<a class="character-card flex layout vertical end-justified" href="{{characterPath this}}">
<iron-image class="fit {{colorClass}}"
sizing="cover" preload fade src={{picture}}>
</iron-image>
Expand Down
2 changes: 1 addition & 1 deletion rpg-docs/client/views/characterList/characterSideList.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{#if characters.count}}
<div class="side-list">
{{#each characters}}
<a href={{pathFor route="characterSheet" data=this}} tabindex="-1" class="side-list-character characterRepresentative">
<a href={{characterPath this}} tabindex="-1" class="side-list-character characterRepresentative">
<paper-item class="short">
<div class="character-name">
{{name}}
Expand Down

0 comments on commit ac23afa

Please sign in to comment.