Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Simplifying the viewTypes

  • Loading branch information...
commit 6ee45ba4d4bbcc94b92be22aaa9e83233d85b707 1 parent 56ef12c
@zmoazeni authored
Showing with 86 additions and 92 deletions.
  1. +22 −16 coffee/site.coffee
  2. +64 −76 js/site.js
View
38 coffee/site.coffee
@@ -79,40 +79,46 @@ class Event extends Spine.Model
super(args)
@commits ||= []
- groupKey: ->
- "#{@repo.name}-#{@created_at_short_string()}"
+ groupKey: -> "#{@repo.name}-#{@created_at_short_string()}"
addCommits: (newCommits) ->
newCommits.forEach((e) => @commits.push(e)) if newCommits
viewType: ->
- switch @type
+ defaultTypes = {
+ ForkEvent: "fork"
+ FollowEvent:"follow"
+ DeleteEvent:"skip"
+ WatchEvent: "watch"
+ GollumEvent:"gollum"
+ }
+
+ return defaultTypes[@type] if defaultTypes[@type]
+
+ view = switch @type
when "PullRequestReviewCommentEvent"
- if @payload.comment._links then "pull_request_comment" else "skip"
+ "pull_request_comment" if @payload.comment._links
when "IssueCommentEvent"
- if @payload.issue then "issue_comment" else "skip"
+ "issue_comment" if @payload.issue
when "IssuesEvent"
- if @payload.action == "opened" then "issue" else "skip"
+ "issue" if @payload.action == "opened"
when "CommitCommentEvent"
- if @payload.comment then "commit_comment" else "skip"
- when "ForkEvent" then "fork"
- when "FollowEvent" then "follow"
+ "commit_comment" if @payload.comment
when "PullRequestEvent"
- if @payload.action == "opened" && @payload.pull_request._links then "pull_request" else "skip"
+ "pull_request" if @payload.action == "opened" && @payload.pull_request._links
when "GistEvent"
- if @payload.action == "create" && @payload.gist then "gist" else "skip"
+ "gist" if @payload.action == "create" && @payload.gist
when "CreateEvent"
switch @payload.ref_type
when "branch"
- if @payload.ref == "master" then "skip" else "branch"
+ "branch" if @payload.ref != "master"
else @payload.ref_type
when "PushEvent"
- if @payload.commits?.length > 0 then "push" else "skip"
- when "DeleteEvent" then "skip"
- when "WatchEvent" then "watch"
- when "GollumEvent" then "gollum"
+ "push" if @payload.commits?.length > 0
else "item"
+ view || "skip"
+
viewInfo: ->
view = @viewType()
context = switch view
View
140 js/site.js
@@ -167,83 +167,71 @@
};
Event.prototype.viewType = function() {
- var _ref;
- switch (this.type) {
- case "PullRequestReviewCommentEvent":
- if (this.payload.comment._links) {
- return "pull_request_comment";
- } else {
- return "skip";
- }
- break;
- case "IssueCommentEvent":
- if (this.payload.issue) {
- return "issue_comment";
- } else {
- return "skip";
- }
- break;
- case "IssuesEvent":
- if (this.payload.action === "opened") {
- return "issue";
- } else {
- return "skip";
- }
- break;
- case "CommitCommentEvent":
- if (this.payload.comment) {
- return "commit_comment";
- } else {
- return "skip";
- }
- break;
- case "ForkEvent":
- return "fork";
- case "FollowEvent":
- return "follow";
- case "PullRequestEvent":
- if (this.payload.action === "opened" && this.payload.pull_request._links) {
- return "pull_request";
- } else {
- return "skip";
- }
- break;
- case "GistEvent":
- if (this.payload.action === "create" && this.payload.gist) {
- return "gist";
- } else {
- return "skip";
- }
- break;
- case "CreateEvent":
- switch (this.payload.ref_type) {
- case "branch":
- if (this.payload.ref === "master") {
- return "skip";
- } else {
- return "branch";
- }
- break;
- default:
- return this.payload.ref_type;
- }
- break;
- case "PushEvent":
- if (((_ref = this.payload.commits) != null ? _ref.length : void 0) > 0) {
- return "push";
- } else {
- return "skip";
- }
- break;
- case "DeleteEvent":
- return "skip";
- case "WatchEvent":
- return "watch";
- case "GollumEvent":
- return "gollum";
- default:
- return "item";
+ var defaultTypes, view;
+ defaultTypes = {
+ ForkEvent: "fork",
+ FollowEvent: "follow",
+ DeleteEvent: "skip",
+ WatchEvent: "watch",
+ GollumEvent: "gollum"
+ };
+ if (defaultTypes[this.type]) {
+ return defaultTypes[this.type];
}
+ view = (function() {
+ var _ref;
+ switch (this.type) {
+ case "PullRequestReviewCommentEvent":
+ if (this.payload.comment._links) {
+ return "pull_request_comment";
+ }
+ break;
+ case "IssueCommentEvent":
+ if (this.payload.issue) {
+ return "issue_comment";
+ }
+ break;
+ case "IssuesEvent":
+ if (this.payload.action === "opened") {
+ return "issue";
+ }
+ break;
+ case "CommitCommentEvent":
+ if (this.payload.comment) {
+ return "commit_comment";
+ }
+ break;
+ case "PullRequestEvent":
+ if (this.payload.action === "opened" && this.payload.pull_request._links) {
+ return "pull_request";
+ }
+ break;
+ case "GistEvent":
+ if (this.payload.action === "create" && this.payload.gist) {
+ return "gist";
+ }
+ break;
+ case "CreateEvent":
+ switch (this.payload.ref_type) {
+ case "branch":
+ if (this.payload.ref !== "master") {
+ return "branch";
+ }
+ break;
+ default:
+ return this.payload.ref_type;
+ }
+ break;
+ case "PushEvent":
+ if (((_ref = this.payload.commits) != null ? _ref.length : void 0) > 0) {
+ return "push";
+ }
+ break;
+ default:
+ return "item";
+ }
+ }).call(this);
+ return view || "skip";
};
Event.prototype.viewInfo = function() {
Please sign in to comment.
Something went wrong with that request. Please try again.