Skip to content

Commit

Permalink
validate form input, add proj behind scenes;closes #109
Browse files Browse the repository at this point in the history
  • Loading branch information
radekstepan committed Jan 30, 2016
1 parent af0201e commit de4129a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
18 changes: 11 additions & 7 deletions public/js/bundle.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions public/js/bundle.min.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/js/components/AddProjectForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ export default React.createClass({

// Add the project.
_onAdd() {
let [ owner, name ] = this.state.val.split('/');
let val = this.state.val;
// Validate input.
if (!/^[^\s\/]+\/[^\s\/]+$/.test(val)) return;

let [ owner, name ] = val.split('/');
actions.emit('projects.add', { owner, name });
// Redirect to the dashboard.
App.navigate({ 'to': 'projects' });
Expand Down
18 changes: 9 additions & 9 deletions src/js/stores/projectsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class ProjectsStore extends Store {

// No owner and no user means nothing to go by.
if (!owner && !user) return;

// Make the request.
request.repos(user, owner, this.cb((err, res) => {
if (err) return; // ignore errors
Expand Down Expand Up @@ -198,7 +198,7 @@ class ProjectsStore extends Store {
// Simple points difference.
return aM.stats.progress.points - bM.stats.progress.points;
});

// From most delayed in days.
case 'priority':
return deIdx(([ , aM ], [ , bM ]) => {
Expand All @@ -208,10 +208,10 @@ class ProjectsStore extends Store {
let [ $a, $b ] = _.map([ aM, bM ], ({ stats }) => {
return (stats.progress.points - stats.progress.time) * stats.days;
});

return $b - $a;
});

// Based on project then milestone name including semver.
case 'name':
return deIdx(([ aP, aM ], [ bP, bM ]) => {
Expand All @@ -232,7 +232,7 @@ class ProjectsStore extends Store {
return bM.title.localeCompare(aM.title);
}
});

// The "whatever" sort order...
default:
return () => { return 0; }
Expand Down Expand Up @@ -334,7 +334,7 @@ class ProjectsStore extends Store {
if (say) this.notify(milestone);

// We are supposed to exist already.
if ((i = this.findIndex(project)) < 0) { throw 500; }
if ((i = this.findIndex(project)) < 0) { throw 500; }

// Does the milestone exist already?
let milestones;
Expand Down Expand Up @@ -365,8 +365,8 @@ class ProjectsStore extends Store {
if ((idx = this.findIndex(project)) > -1) {
this.push(`list.${idx}.errors`, err);
} else {
// We are supposed to exist already.
throw 500;
// Create the stub project behind the scenes.
this.push('list', _.extend({}, project, { 'errors': [ err ] }));
}

// Notify?
Expand All @@ -385,7 +385,7 @@ class ProjectsStore extends Store {
let idx;
// Get the existing index.
let index = this.get('index');

// Index one milestone in an already sorted index.
if (ref) {
idx = sortedIndex(index, data, this.comparator());
Expand Down

0 comments on commit de4129a

Please sign in to comment.