-
Notifications
You must be signed in to change notification settings - Fork 20
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
DCI number conversion and validation #29
Conversation
I'll try to load this up and test after work today. |
i have it running at http://csun.edu/~csw61793/decklist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are mostly stylistic changes, will verify algorithm and logic shortly, but the demo seems to be working fine.
An aside, I feel we may want to add a note if the DCI number is rewritten. Not a warning, necessarily, but just a notice so the user is aware that 10-digit DCI numbers are desired, and what their 10-digit DCI number would be.
js/decklist/dci.js
Outdated
@@ -0,0 +1,71 @@ | |||
var primes = [43,47,53,71,73,31,37,41,59,61,67,29]; | |||
function isValid(number){ | |||
number += ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
number = number.toString();
js/decklist/dci.js
Outdated
function isValid(number){ | ||
number += ""; | ||
if(number.length >= 8){ | ||
if(number.length == 8 || number.length == 10){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (
, not if(
) {
, not ){
js/decklist/dci.js
Outdated
var primes = [43,47,53,71,73,31,37,41,59,61,67,29]; | ||
function isValid(number){ | ||
number += ""; | ||
if(number.length >= 8){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (
, not if(
) {
, not ){
js/decklist/dci.js
Outdated
@@ -0,0 +1,71 @@ | |||
var primes = [43,47,53,71,73,31,37,41,59,61,67,29]; | |||
function isValid(number){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe these functions should be more descriptively named? Or perhaps nested so that they don't bleed into global namespace?
e: Looking at this comment again, there may not be as much room to do this as I thought; just was a thought of mine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
) {
, not ){
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functions nested, spacing changed
js/decklist/dci.js
Outdated
else return -1; // for a under 8-digit number, return -1 (evals to true) | ||
} | ||
function getTenDigit(number){ | ||
number += ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
number = number.toString();
js/decklist/dci.js
Outdated
for (var i = 0; i < number.length; i++){ | ||
sum += parseInt(number[i]) * primes[i]; | ||
} | ||
var check = (Math.floor(sum / 10) % 9) + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing semicolon
js/decklist/dci.js
Outdated
var check = (Math.floor(sum / 10) % 9) + 1 | ||
return check; | ||
} | ||
function getTenIfValid(number){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
) {
, not ){
js/decklist/dci.js
Outdated
return check; | ||
} | ||
function getTenIfValid(number){ | ||
if(getTenDigit(number)){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (
, not if(
) {
, not ){
js/decklist/main.js
Outdated
@@ -327,6 +327,10 @@ function generateDecklistPDF(outputtype) { | |||
} | |||
|
|||
dcinumber = $('#dcinumber').val(); | |||
if(dcinumber){ // only if there is a dci number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (
, not if(
) {
, not ){
js/decklist/main.js
Outdated
@@ -327,6 +327,10 @@ function generateDecklistPDF(outputtype) { | |||
} | |||
|
|||
dcinumber = $('#dcinumber').val(); | |||
if(dcinumber){ // only if there is a dci number | |||
dcinumber = getTenIfValid(dcinumber); | |||
dcinumber += ""; //convert to string (function returns an int) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dcinumber = getTenIfValid(dcinumber).toString();
BTW, you can also name your branch |
Yeah, i was trying to test some things while my dev machine was acting up, so all I had was my phone. It was fairly simple to ssh to my school stuff and do a clone, rather than teach myself github pages. |
@Nightfirecat I think I got them all. I also updated the host. |
@april Is there something further that I need to do for this? this is my first real pull request, so I'm slightly unfamiliar with how to do it. |
Sorry, I've been traveling the last couple weeks. Could I ask you to squash it all into a single commit, please? |
js/decklist/main.js
Outdated
} else if (validationObject['error'] === 'invalid') { | ||
notifications.push(prop, ['DCI number is invalid', validType]); | ||
} else if (validationObject['warning'] === 'nocheck') { | ||
notifications.push(prop, ['We cannot verify that your DCI# is valid as it is in an old format. Please double-check it.', validType]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please be consistent about using DCI Number vs. DCI #.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, my bad.
Looks good as far as I'm concerned. Style changes are mostly consistent with existing code, and the algorithms seem sound. |
If you're on Twitter, I'd be happy to credit you. :) |
I'm on Twitter @imanEngineer2 |
Is that still true? That would be damn sweet!! @april Do you run decklist.org directly from gh pages? |
I don't believe so, since GH pages (still?) doesn't allow for custom certs on custom domains. That said, you can definitely host it from GH pages in development: https://nightfirecat.github.io/decklist/ |
I can probably push it to gh-pages, if folks would like. I can't run it directly from GitHub because as @Nightfirecat said, they don't yet support certificates on custom domains. |
Which certificates are we talking about? What are they used for?
GH pages in development? Hmm, what do you mean? |
Server HTTPS cert. And by "in development", I mean you can host directly from GitHub on *.github.io from a repository's development code. |
Oh right, it could be production code too then. ;) HTTPS is actually possible with gh pages and a custom domain if you combine it with a free cloudflare account. Just do a quick google search, there are a lot of articles. If you want to safe some hosting costs... |
@april FYI, there's a fair bit of discussion on isaacs/github#156 regarding a slow roll-out of custom domain certs on GitHub's part for GH pages. It's not immediately available, but at some point, it sounds like this will be fully supported and available for new sites. Once that's available, it might be worth just running decklist.org off GH pages? |
Completes Issue #4