Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Gen 1 and Gen 2 ball flairs with dex images #669

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/controllers/FlairController.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports = {
promises.push(Event.create({type: "flairTextChange", user: req.user.name,content: "Changed " + user.name + "'s flair to " + css_flair}));

// Send a PM to let them know application was accepted.
var pmContent = 'Your application for ' + Flairs.formattedName(app.flair) + ' flair on /r/' + app.sub + ' has been approved.' + warning;
var pmContent = 'Your application for ' + Flairs.formattedName(app.flair, app.sub) + ' flair on /r/' + app.sub + ' has been approved.' + warning;
promises.push(Reddit.sendPrivateMessage(refreshToken, 'FlairHQ Notification', pmContent, user.name));
promises.push(Application.destroy({id: req.allParams().id}));
await* promises;
Expand Down
79 changes: 49 additions & 30 deletions api/services/Flairs.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,38 +63,57 @@ exports.hasEventFlair = function(user) {
return !!flairClasses.match(eventFlairRegExp);
};

exports.formattedName = function(name) {
if (!name) {
exports.formattedName = function(name, subreddit) {
const flairNames = {
"pokemontrades": {
"default" : "Gen 1 Dex",
"gen2" : "Gen 3 Dex",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll probably want to do a flair migration and change the css class name from gen2 to gen3 for mod usability.

"pokeball" : "Poké Ball",
"premierball" : "Premier Ball",
"greatball" : "Great Ball",
"ultraball" : "Ultra Ball",
"luxuryball" : "Luxury Ball",
"masterball" : "Master Ball",
"dreamball" : "Dream Ball",
"cherishball" : "Cherish Ball",
"ovalcharm" : "Oval Charm",
"shinycharm" : "Shiny Charm",
"involvement": "Involvement",
"pokeball1" : "Poké Ball",
"premierball1" : "Premier Ball",
"greatball1" : "Great Ball",
"ultraball1" : "Ultra Ball",
"luxuryball1" : "Luxury Ball",
"masterball1" : "Master Ball",
"dreamball1" : "Dream Ball",
"cherishball1" : "Cherish Ball",
"ovalcharm1" : "Oval Charm",
"shinycharm1" : "Shiny Charm",
"gsball1" : "GS Ball",
"upgrade" : "Up-Grade",
"eventribbon" : "Helper Ribbon"
},
"svexchange": {
"lucky" : "Lucky Egg",
"egg" : "Egg",
"eevee" : "Eevee Egg",
"togepi" : "Togepi Egg",
"torchic" : "Torchic Egg",
"pichu" : "Pichu Egg",
"manaphy" : "Manaphy Egg",
"eggcup" : "Egg Cup",
"cuteribbon" : "Cute Ribbon",
"coolribbon" : "Cool Ribbon",
"beautyribbon" : "Beauty Ribbon",
"smartribbon" : "Smart Ribbon",
"toughribbon" : "Tough Ribbon",
"upgrade" : "Up-Grade"
}
};
if (!name || !subreddit) {
return "";
}
var formatted = "",
numberToSliceTill,
suffix;
if (name.indexOf("ball") > -1) {
suffix = "Ball";
numberToSliceTill = -4;
} else if (name === "gen2") {
suffix = "II Ball";
numberToSliceTill = -1;
} else if (name.indexOf("charm") > -1) {
suffix = "Charm";
numberToSliceTill = -5;
} else if (name.indexOf("ribbon") > -1) {
suffix = "Ribbon";
numberToSliceTill = -6;
} else if (name === "eggcup") {
suffix = "Cup";
numberToSliceTill = -3;
} else if (name !== "egg" && name !== "involvement") {
suffix = "Egg";
}
formatted += name.charAt(0).toUpperCase();
formatted += name.slice(1, numberToSliceTill);
if (suffix) {
suffix = " " + suffix;
formatted += suffix;
}
return formatted;
return flairNames[subreddit][name] || "";
};
exports.validFC = function (fc) {
if (fc.match(/^SW-\d{4}-\d{4}-\d{4}$/)) {
Expand Down
Binary file modified assets/images/ballflairs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/balls.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions assets/views/home/applist.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
<span ng-if="app.claimedBy"><small>(/u/{{app.claimedBy}} is viewing)</small></span>
<span class="pull-right">
<span title={{formattedRequirements(app.flair)}} text-align="center">
{{formattedName(app.flair)}}
{{formattedName(app.flair, app.sub)}}
<small>({{app.sub}})</small>
</span>
<button class="btn btn-primary has-spinner" ng-really-user="{{app.user}}"
ng-really-flair="{{formattedName(app.flair)}}"
ng-really-flair="{{formattedName(app.flair, app.sub)}}"
ng-really-click="approveApp(app.id)"
ng-class="[adminok.appFlair[app.id] ? 'glyphicon glyphicon-ok' : '',
adminspin.appFlair[app.id] ? 'active' : '']">
Expand Down
8 changes: 4 additions & 4 deletions assets/views/home/flairApply.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class="list-group-item" ng-class="[canUserApply(flair) ? '' : 'disabled',
(selectedFlair === flair.name) ? 'active' : '']"
href="#" ng-click="setSelectedFlair(flair.name, canUserApply(flair))" title={{formattedRequirements(flair.name)}}>
<span ng-class="'flair-' + flair.name">{{formattedName(flair.name)}}</span><small ng-show="applied(flair)"> (Pending)</small><small ng-show="userHasFlair(flair)" class="greencheck" title="You already have this flair."> ✓</small>
<span ng-class="'flair-' + flair.name">{{formattedName(flair.name, "pokemontrades")}}</span><small ng-show="applied(flair)"> (Pending)</small><small ng-show="userHasFlair(flair)" class="greencheck" title="You already have this flair."> ✓</small>
</a>
</div>
<div class="list-group col-md-6">
Expand All @@ -27,7 +27,7 @@
class="list-group-item" ng-class="[canUserApply(flair) ? '' : 'disabled',
(selectedFlair === flair.name) ? 'active' : '']"
href="#" ng-click="setSelectedFlair(flair.name, canUserApply(flair))" title={{formattedRequirements(flair.name)}}>
<span ng-class="'flair-' + flair.name">{{formattedName(flair.name)}}</span><small ng-show="applied(flair)"> (Pending)</small><small ng-show="userHasFlair(flair)" class="greencheck" title="You already have this flair."> ✓</small>
<span ng-class="'flair-' + flair.name">{{formattedName(flair.name, "pokemontrades")}}</span><small ng-show="applied(flair)"> (Pending)</small><small ng-show="userHasFlair(flair)" class="greencheck" title="You already have this flair."> ✓</small>
</a>
</div>
</div>
Expand All @@ -39,7 +39,7 @@
class="list-group-item" ng-class="[canUserApply(flair) ? '' : 'disabled',
(selectedFlair === flair.name) ? 'active' : '']"
href="#" ng-click="setSelectedFlair(flair.name, canUserApply(flair))" title={{formattedRequirements(flair.name)}}>
<span ng-class="'flair-' + flair.name">{{formattedName(flair.name)}}</span><small ng-show="applied(flair)"> (Pending)</small><small ng-show="userHasFlair(flair)" class="greencheck" title="You already have this flair."> ✓</small>
<span ng-class="'flair-' + flair.name">{{formattedName(flair.name, "svexchange")}}</span><small ng-show="applied(flair)"> (Pending)</small><small ng-show="userHasFlair(flair)" class="greencheck" title="You already have this flair."> ✓</small>
</a>
</div>
<div class="list-group col-md-6">
Expand All @@ -48,7 +48,7 @@
class="list-group-item" ng-class="[canUserApply(flair) ? '' : 'disabled',
(selectedFlair === flair.name) ? 'active' : '']"
href="#" ng-click="setSelectedFlair(flair.name, canUserApply(flair))" title={{formattedRequirements(flair.name)}}>
<span ng-class="'flair2-' + flair.name">{{formattedName(flair.name)}}</span><small ng-show="applied(flair)"> (Pending)</small><small ng-show="userHasFlair(flair)" class="greencheck" title="You already have this flair."> ✓</small>
<span ng-class="'flair2-' + flair.name">{{formattedName(flair.name, "svexchange")}}</span><small ng-show="applied(flair)"> (Pending)</small><small ng-show="userHasFlair(flair)" class="greencheck" title="You already have this flair."> ✓</small>
</a>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion test/unit/data/standardFlairInfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"toughribbon":{"name":"toughribbon","sub":"svexchange","giveaways":800,"eggs":0,"trades":0,"involvement":0}
},
"expectedFormat":{
"pokeball":"Poke Ball",
"pokeball":"Poké Ball",
"premierball":"Premier Ball",
"greatball":"Great Ball",
"ultraball":"Ultra Ball",
Expand Down
4 changes: 3 additions & 1 deletion test/unit/services/Flairs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ describe("Flair template formatting", function () {
it("Formats flair names correctly", function () {
var names = _.keys(stdFlairInfo.flairs);
for (var i = 0; i < names.length; i++) {
assert.strictEqual(Flairs.formattedName(names[i]), stdFlairInfo.expectedFormat[names[i]], 'Formats ' + names[i] + ' flair incorrectly');
let flair = names[i]
let sub = stdFlairInfo["flairs"][flair]["sub"]
assert.strictEqual(Flairs.formattedName(flair, sub), stdFlairInfo.expectedFormat[flair], 'Formats ' + flair + ' flair incorrectly');
}
});
});
Expand Down