diff options
Diffstat (limited to 'app')
143 files changed, 4187 insertions, 808 deletions
diff --git a/app/assets/images/Plus.png b/app/assets/images/Plus.png Binary files differnew file mode 100644 index 0000000..fa6a7a5 --- /dev/null +++ b/app/assets/images/Plus.png diff --git a/app/assets/images/bg.png b/app/assets/images/bg.png Binary files differnew file mode 100644 index 0000000..91c77c8 --- /dev/null +++ b/app/assets/images/bg.png diff --git a/app/assets/images/chess.png b/app/assets/images/chess.png Binary files differnew file mode 100644 index 0000000..6bcffe6 --- /dev/null +++ b/app/assets/images/chess.png diff --git a/app/assets/images/hearthstone.png b/app/assets/images/hearthstone.png Binary files differnew file mode 100644 index 0000000..15d20b4 --- /dev/null +++ b/app/assets/images/hearthstone.png diff --git a/app/assets/images/league_of_legends.png b/app/assets/images/league_of_legends.png Binary files differnew file mode 100644 index 0000000..9a78047 --- /dev/null +++ b/app/assets/images/league_of_legends.png diff --git a/app/assets/images/rock_paper_scissors.png b/app/assets/images/rock_paper_scissors.png Binary files differnew file mode 100644 index 0000000..294916c --- /dev/null +++ b/app/assets/images/rock_paper_scissors.png diff --git a/app/assets/images/rock_paper_scissors.svg b/app/assets/images/rock_paper_scissors.svg new file mode 100644 index 0000000..67bb6bd --- /dev/null +++ b/app/assets/images/rock_paper_scissors.svg @@ -0,0 +1,108 @@ +<?xml version="1.0"?> +<svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:svg="http://www.w3.org/2000/svg" id="svg2" viewBox="0 0 691.81 691.81" version="1.1"> + <title id="title4919">Rock Scissors Paper</title> + <defs id="defs4"> + <marker id="Arrow2Mend" refY="0" refX="0" overflow="visible" orient="auto"> + <path id="path4038" stroke-linejoin="round" d="m8.7186 4.0337-10.926-4.0177 10.926-4.0177c-1.7455 2.3721-1.7354 5.6175-6e-7 8.0354z" fill-rule="evenodd" transform="scale(-.6)" stroke-width=".625"/> + </marker> + </defs> + <rect x="0" y="0" width="691.81" height="691.81" style="fill: #AAAAAA" /> + <g id="layer1" transform="translate(-42.612 -137.16)"> + <g id="g4875" transform="matrix(.77244 0 0 .77244 192.28 -14.824)"> + <g id="g2906" transform="matrix(-.84212 .17678 .17678 .84212 677.84 268.6)"> + <path id="path3" d="m259.08 17.719c-4.01-0.256-2.042 5.467-6.258 5.006-2.182-2.162-1.385-7.737 1.251-8.761 0.281 0.971 0.035 2.469 1.252 2.503 0.28-0.97 0.034-2.468 1.251-2.503 0.299 1.786 2.062 2.111 2.504 3.755z"/> + <path id="path5" d="m173.97 17.719c-1.584 1.436-9.868 2.515-11.265 0 4.306 0.479 7.803-6.286 11.265-2.503-1.511 0.264-0.771 1.389 0 2.503z"/> + <path id="path7" d="m240.3 20.221c-1.901 1.276-8.113-1.155-10.014-3.754 5.03-0.44 9.158 0.02 10.014 3.754z"/> + <path id="path9" d="m290.36 57.769c1.164-2.922 4.529-10.066 0-5.006-1.437-2.351-0.207-10.399 5.006-10.013 0.505 7.179 0.247 13.597-5.006 15.019z"/> + <path id="path11" d="m112.88 15.406h-18.773c-0.743-0.873 29.706-4.351 18.773 0z"/> + <path id="path13" d="m369.21 86.556c-0.326-1.948-2.745-0.868-3.754 0 3.313-2.11 1.396-9.449 3.754-12.516 1.525 1.894 2.458 10.78 0 12.516z"/> + <path id="path15" d="m295.37 89.058c1.109-4.731 0.937-10.745 3.756-13.767-0.142 5.699-0.024 11.657-3.756 13.767z"/> + <path id="path17" d="m191.49 85.303c-7.078-0.848-17.994 2.142-21.276-2.503 9.66 0.83 16.427-3.137 21.276 2.503z"/> + <path id="path19" d="m334.17 125.35c-1.795-1.543-2.371-4.304-2.503-7.51 2.142-1.195 2.521-4.152 5.006-5.005-1.2 3.807 2.68 12.692-2.503 12.515z"/> + <path id="path21" d="m289.11 124.1c0.39-3.784-1.39-9.734 2.503-10.013-1.03 3.141 2.434 10.775-2.503 10.013z"/> + <path id="path23" d="m188.99 126.61c-4.574 0.851-9.1 1.746-15.019 1.251 1.243-3.813 9.789-6.836 13.769-3.754-7.763 0.486 0.084 0.641 1.25 2.503z"/> + <path id="path25" d="m200.25 169.16c-0.073-5.496 0.504-10.345 2.503-13.768-1.261 4.163 2.766 13.615-2.503 13.768z"/> + <path id="path27" d="m158.95 46.505c5.797 0.809 10.295-4.935 15.019 0-5.767-1.534-11.103 3.833-15.019 0z"/> + <path id="path29" d="m46.229 20.57c8.204 0.277 14.635-1.219 21.277-2.503-2.471 4.077-20.887 4.58-21.277 2.503z"/> + <path id="path31" d="m281.6 126.61c1.312-2.515 0.599-13.491 2.503-11.265 0.411 4.236-0.976 13.112-2.503 11.265z"/> + <path id="path33" d="m285.36 129.11c0.745-6.283 0.367-10.093 1.252-13.768 2.044 2.957 2.173 12.365-1.252 13.768z"/> + <path id="path35" d="m367.96 126.6c-5.002 1.868-15.024 1.868-20.025 0-1.197-7.076 1.841-16.464 0-20.024-46.83 1.298-86.581 1.938-135.17 1.251 20.958-7.99 48.129-3.82 75.094-5.007 43.017-1.89 87.378 1.49 122.65-7.509 4.33-5.413 3.127-19.587-2.503-22.527 2.882 6.014 0.101 13.255-2.503 17.521-8.105 0.18-16.143 0.289-21.276-2.502 0.216-7.711-1.787-17.64 5.006-18.773-31.898 1.353-56.328-3.795-86.357-1.252 0.331 5.869 3.998 16.742-2.503 18.773 1.253-5.3 2.223-13.686 0-18.773-29.323-3.635-65.038-0.877-91.364-7.51 62.248-1.654 128.88 7.685 183.98 1.252-0.668-4.338 1.859-11.87-2.503-12.516 0.728 4.898-1.077 7.267-2.503 10.013-8.161-0.962-16.246 1.611-21.275 0 0.783-3.804-1.603-10.78 1.252-12.516-5.466 15.413 17.483 12.443 20.023 5.006-6.653-8.223-20.667-9.609-32.541-11.264-47.229-6.583-111.25 0.445-155.19-10.013 36.4 2.273 86.049 1.268 121.4 2.503 7.167 0.251 22.518 6.253 21.276-7.509-3.388 4.539-11.951 3.901-20.025 3.754-2.494-1.276 2.634-8.914-1.251-11.264-51.09-5.314-113.91-14.316-167.7-11.256-41.5 2.359-82.498-0.122-117.64 5.006-12.469 1.817-24.626 7.461-36.298 5.006 22.245-7.795 47.513-9.995 75.093-11.263 32.795-1.507 69.275-6.218 101.38-5.007 6.743 0.256 13.555 3.074 20.025 3.756 52.454 5.521 106.54 1.751 148.94 17.521 3.519 3.539 1.673 11.946 2.503 15.02 22.246 3.101 56.888-0.582 48.811 28.785 5.949-0.524 9.027 1.819 13.769 2.503 4.653 6.229 8.617 18.292 5.005 28.787-7.016 9.671-28.406 4.97-41.302 8.762 7.52 10.533 1.729 26.649-6.257 32.54-31.736 6.23-69.292 6.638-106.38 7.51 5.988 5.631 10.071 17.214 6.259 28.786-27.447 16.401-68.675 7.55-100.12 12.516-15.694 2.479-21.298 6.535-33.792 7.51-54.56 4.252-64.943-32.562-103.88-47.561-5.108-1.966-11.236-2.437-16.271-3.754-3.554-0.933-13.292 0.196-13.767-7.51 0.09-5.264 13.964 2.216 15.02 0-1.541-2.722-13.286-6.875-7.511-8.762 35.521 12.869 61.882 56.016 106.38 61.327 22.711 2.71 44.086-4.475 67.584-6.259 25.915-1.966 51.778 2.017 75.094-6.258-5.259-2.249-14.193-0.824-20.024-2.503-0.108-7.2-0.271-14.455 1.252-20.025 6.923-2.259 13.888 0.48 21.276 1.252 3.234 5.568 2.444 14.378 3.754 18.773 17.154-49.229-104.77-10.208-123.9-36.295 32.543 9.766 100.99 5.861 148.94 3.754 34.288-1.507 102.81 3.411 81.353-31.289 2.749 4.647 1.047 13.937-1.256 17.522zm-41.3-108.88c-1.144 2.194-0.43 6.245-2.503 7.51 4.209 1.758 10.931 2.934 15.021 1.251 1.364-8.457-6.901-7.285-12.518-8.761zm60.076 55.068v13.768c4.332 1.925 11.41 1.106 17.522 1.252 8.308-11.294-5.278-20.534-17.522-15.02zm-35.044 37.548c-2.397 3.025-0.789 10.057-1.251 15.019h13.768c9.719-7.536-0.683-22.006-12.517-15.019zm-111.39 45.057c-1.666 3.758-1.273 9.576-1.252 15.021 7.063-0.39 11.13 2.219 18.773 1.251 2.625-3.851 1.255-12.357-1.252-15.021-6.133 0.292-9.475-2.205-16.269-1.251z"/> + </g> + <g id="g2982" transform="matrix(-.33587 -.48446 .48446 -.33587 255.64 813.8)" fill-rule="evenodd"> + <path id="path3-4" d="m0 129.73c5.056 1.287 3.347 9.338 10.379 8.649 2.95-0.709-0.364-2.23 0-5.189 4.51 2.985 8.768 6.223 8.649 13.838-6.934-2.29-11.824-6.629-19.028-8.649v-8.649z"/> + <path id="path5-0" d="m19.028 131.46c3.663 16.518 24.55 15.811 34.596 25.947-11.769-1.308-20.868-9.217-29.407-8.649 0.714-8.21-5.903-9.088-5.189-17.298z"/> + <path id="path7-9" d="m247.36 153.95c9.951-0.126 16.131 18.447 20.758 29.405-8.991-7.729-11.192-22.252-20.758-29.405z"/> + <path id="path9-4" d="m385.74 205.84c4.146 3.703-5.014 8.726-10.379 8.649 1.757-4.586 7.999-4.686 10.379-8.649z"/> + <path id="path11-8" d="m321.74 243.9c4.889 3.89-2.845 9.726-3.46 13.838-4.889-3.89 2.842-9.726 3.46-13.838z"/> + <path id="path13-8" d="m0 153.95c10.402 3.682 40.146 8.392 53.624 13.838 40.282 16.275 58.092 66.777 124.55 51.894-6.811-5.875-15.101-10.27-22.488-15.567 13.222 1.081 20.92 12.012 34.596 17.297 7.584 2.931 18.474 2.089 27.677 6.92 11.564 6.071 21.198 19.362 32.866 27.677 24.197 17.243 40.023 31.271 64.002 6.919-3.854 7.102-9.293 12.617-19.027 13.838 18.444 3.007 35.974-11.953 36.325-25.946 0.427-16.97-25.394-39.572-36.325-57.084-19.65-31.474-23.18-54.689-36.326-79.57 5.988-3.042 6.72 13.99 13.838 15.568 7.606-5.078 5.466-19.906 15.568-22.487-1.614 8.764-4.848 15.91-6.918 24.217 5.624 3.309 9.881 3.427 13.838 1.73 6.081-24.971 9.578-51.964 32.865-55.354-13.657 11.844-36.839 46.024-15.568 65.732 14.236-11.135 18.784-31.958 34.597-41.515 3.048 6.002-1.768 7.836 8.648 5.189-5.946 5.585-16.236 6.826-20.757 13.838 2.43 2.873 9.672-4.067 17.297-1.73-15.773 4.983-27.891 13.624-31.135 31.137 1.87 12.262 21.477 13.787 25.946 32.865 1.311 5.597-2.26 12.064-1.729 17.299 2.02 19.947 29.403 38.392 39.785 15.568 2.611 5.559-0.23 6.872 5.189 6.919 8.24-0.327 15.966-9.178 17.298-20.758 5.03-43.67-5.31-129.17-20.76-152.23-5.61-8.383-16.99-15.295-29.4-17.293-58.25-9.38-117.67 20.656-172.98 20.757-68.45 0.125-126.98-38.346-185.09-48.435v-5.189c28.95 8.619 55.573 15.987 83.03 24.217 25.389 7.61 52.703 19.662 83.03 22.488 34.634 3.226 63.573-4.378 93.409-10.379 44.027-8.854 116.44-25.423 136.65 13.838 10.15 19.708 10.938 52.111 13.839 74.381 3.635 27.895 10.597 61.064 5.189 83.03-1.816 7.374-10.973 14.042-17.298 25.946-5.971 11.24-8.695 21.203-15.568 25.947-4.525 3.125-12.553 0.71-20.757 5.189-8.051 4.396-10.497 15.109-22.488 19.028-8.403 2.746-20.753 1.121-31.136 3.459-12.255 2.761-19.113 9.001-27.677 8.649-13.187-0.541-39.07-11.738-53.624-22.488-7.122-5.26-9.862-15.02-17.298-20.757-27.34-21.11-82.78-17.64-112.42-31.14-22.143-10.08-32.794-35.57-50.167-43.24-13.597-6.01-35.367-5.07-46.703-8.65v-15.57zm364.99 102.06c3.907-6.804 8.095-2.571 12.109-8.649 2.249 4.296-5.075 7.179 0 8.649 4.095-6.283 10.517-10.24 12.108-19.028-11.298-0.811-22.458-1.761-32.867-3.46-2.915 8.062-3.552 24.269 8.65 22.488z"/> + <path id="path15-2" d="m219.68 140.11c1.396-5.323 10.558 10.831 10.379 1.729 6.086 5.444 12.56 10.504 13.838 20.758-9.095-6.473-15.122-16.014-24.217-22.487z"/> + <path id="path17-4" d="m164.33 162.6c1.46-2.458 8.919 3.65 10.379 6.919 2.568-0.755-0.683-2.213 0-5.189 7.596 6.242 14.36 13.316 22.487 19.027-10.021-0.957-25.064-11.824-32.866-20.757z"/> + <path id="path19-5" d="m207.58 138.38c-6.535-3.267-16.759-2.845-19.027-10.379 7.358-3.752 17.359 2.874 19.027 10.379z"/> + </g> + <g id="g3028" transform="matrix(.94236 .33461 -.33461 .94236 -172.81 169.56)" fill-rule="evenodd"> + <path id="path3-1" d="m361.4 18.798c0.183 3.935-2.72 8.736 0.351 11.859 0.581-1.918 2.404-2.862 1.882-1.278 3.681-0.369-0.205-4.866 1.708-7.206-2.92-0.673-1.599-2.539-3.941-3.375z"/> + <path id="path5-7" d="m323.56 19.741c-1.958 1.333-1.575 8.389 0.848 10.972 2.115-4.334-1.078-7.171-0.848-10.972z"/> + <path id="path7-1" d="m373.98 89.99c-3.714 1.095-4.415 7.683-4.585 10.26 3.952-1.163 2.957-7.273 4.585-10.26z"/> + <path id="path9-1" d="m321.97 72.5c-2.411 1.459-2.76 8.722-4.691 12.531 4.131-1.946 5.219-9.416 4.691-12.531z"/> + <path id="path11-5" d="m270.18 127.44c-4.752 9.811-19.64 1.719-24.672-8 5.153-4.7 10.842-7.498 16.442-10.608 2.885 6.549 11.457 11.943 8.23 18.608zm-21.122-6.01c4.796 2.948 9.505 7.987 15.086 8.457 11.746-11.772-8.793-23.322-15.086-8.457z"/> + <path id="path13-2" d="m253.65 111.17c-2.67-1.188-6.125 1.818-5.647 3.832 2.115-0.45 3.98-1.786 5.647-3.832z"/> + <path id="path15-7" d="m2.984 27.804c19.307-0.023 39.398-2.352 60.289-3.524 19.921-1.12 40.249-0.095 60.179-1.253 17.961-1.042 38.129-5.02 57.842-9.561 20.324-4.681 39.488-12.878 57.559-13.218 13.051-0.246 29.157 4.603 43.064 4.315 9.181-0.19 19.653-2.939 30.252-4.035 21.304-2.203 44.943 3.055 65.787 5.389 12.365 1.385 29.646 4.323 29.889 13.256 0.524 19.289-27.008 14.056-36.328 16.955-13.509 1.351-27.446-2.572-41.397-1.047-7.37 0.806-14.535 4.626-21.66 5.351-9.644 0.983-20.19-3.831-27.589 5.527 42.685 20.521 87.223 26.455 127.48 49.3 5.767 34.513-41.071 12.854-62.277 7.074-26.268-7.161-48.3-16.484-64.968-13.095-0.35 10.063 16.708 15.225 17.493 24.967-10.56 23.538-31.963 8.575-42.513 32.15-10.699-0.138-23.185 6.185-32.632 6.199-7.419 0.01-15.125-4.914-25.168-7.113-23.599-5.165-59.929-1.638-81.196-7.028-22.981-5.826-35.052-17.105-52.047-7.019-1.775-0.994-3.549-1.988-5.325-2.983 8.888-5.595 19.42-5.348 29.083-8.189 0.795-1.107-2.106-4.701 1.102-4.046-0.22 1.557 0.171 2.94 1.171 4.154 0.967-2.802-1.314-8.549 1.813-9.479 0.1 3.21-0.55 6.631 1.843 9.196 21.318-4.805 47.895-5.07 65.761-13.287-18.073 0.189-38.065 2.406-58.541-14.155 28.437 15.536 61.903 14.136 83.4-1.064-5.337-3.071-11.74-3.682-13.7-8.847 1.478 0.828 2.957 1.657 4.436 2.487-1.045-6.191-9.188-14.342-6.843-18.997-0.98 21.186 32.324 21.716 50.648 36.556 3.521 2.852 4.986 8.622 8.552 11.79 12.459 11.079 38.325 27.914 43.629 11.63 1.475-4.527-5.874-17.871-9.398-22.763-6.85-9.518-17.31-22.53-25.97-28.56-15.51-10.8-35.67-11.84-39.22-27.814 5.059 3.557 6.6 8.104 13.593 11.116 3.937-3.393-0.896-8.159 2.702-8.98 0.786 2.865 0.175 8.934 4.612 8.417 3.356-4.005 6.206-9.805 10.124-11.819-2.581 5.461-8.058 11.736-6.682 16.081 14.856 5.141 28.032 15.589 34.783 25.328 31.917-10.33 73.244 4.919 112.58 17.624 10.837 3.501 33.131 11.804 36.853 0.833 2.115-6.233-8.018-11.988-14.763-15.274-34.38-16.744-79.11-26.327-115.55-41.446-1.908-0.621-8.7 3.843-6.816-0.324 10.694-11.2 25.805-10.954 39.771-12.692 5.622-0.7 11.034-2.603 17.008-3.294 26.229-3.041 50.338 4.846 68.879-2.207 6.501-2.474 12.802-8.383 8.456-15.085-33.85-7.884-68.86-11.57-103.92-8.105-18.22 1.801-33.92 0.942-50.98-0.589-32.88-2.953-66.64 12.387-96.51 18.207-16.4 3.195-32.97 1.52-50.21 2.181-33.113 1.266-69.593 3.773-101.4 6.13 0.995-1.775 1.99-3.55 2.984-5.324zm261.6 63.842c0.395 11.847 9.998 21.099 12.129 32.457 6.438 0.748 12.617 0.576 16.336-8.335-5.655-8.494-16.405-22.274-28.465-24.122zm-43.467 23.451c-2.333-0.235 0.908 10.869 4.329 4.76-2.22-1.369-3.948-2.875-4.329-4.76zm34.5 21.673c-11.813-7.808-30.909-17.961-31.703-3.777-8.923-9.287-27.699-17.935-34.863-4.381 7.407-3.651 15.946-0.771 21.513 7.394-0.996 1.774-1.99 3.55-2.985 5.324 4.788 2.848 9.016 3.707 13.418 5.189 8.938-5.838 28.133 3.156 34.62-9.749zm-64.013-4.395c4.305 3.021 6.208 6.721 12.316 9.237 0.995-1.775 1.99-3.551 2.984-5.325-2.4-4.755-11.471-9.038-15.3-3.912z"/> + <path id="path17-6" d="m320.29 21.408c-1.362-2.508-1.234 5.898-0.82 7.705 3.498-0.554 0.371-5.536 0.82-7.705z"/> + <path id="path19-1" d="m239.77 96.394c-2.115 0.449-3.981 1.787-5.646 3.832-0.551-3.857 6.066-4.896 7.354-11.038-5.153 2.885-9.686 10.019-12.503 13.983 3.877-1.264 7.735-2.605 10.795-6.777z"/> + <path id="path21-4" d="m61.931 91.17c1.902 1.954 2.553 4.263 1.951 6.924-16.353-0.565-31.533 3.027-47.544 3.672 15.331 5.78 32.779-3.897 50.486 1.477-0.191-3.683-1.925-6.93-2.231-10.58 1.717-3.636 5.314-0.588 7.032-4.223-20.932-0.899-40.87 1.712-60.396 5.797 14.697 1.758 33.589-4.559 50.702-3.067z"/> + </g> + <path id="path3234" marker-end="url(#Arrow2Mend)" d="m192.86 538.08-65.72-114.29" stroke="#000" stroke-width="4" fill="none"/> + <path id="path3234-2" marker-end="url(#Arrow2Mend)" d="m193.47 352.93 130.62 17.825" stroke="#000" stroke-width="4" fill="none"/> + <path id="path3234-8" marker-end="url(#Arrow2Mend)" d="m416.72 467.9-105.26 79.37" stroke="#000" stroke-width="4" fill="none"/> + </g> + </g> + <metadata> + <rdf:RDF> + <cc:Work> + <dc:format>image/svg+xml</dc:format> + <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/> + <cc:license rdf:resource="http://creativecommons.org/licenses/publicdomain/"/> + <dc:publisher> + <cc:Agent rdf:about="http://openclipart.org/"> + <dc:title>Openclipart</dc:title> + </cc:Agent> + </dc:publisher> + <dc:title>Rock Scissors Paper</dc:title> + <dc:date>2010-05-31T17:54:35</dc:date> + <dc:description>Rock Scissors Paper hand game depiction. Rock, scissors, and paper by Francesco 'Architetto' Rollandin from openclipart.org</dc:description> + <dc:source>http://openclipart.org/detail/63805/rock-scissors-paper-by-mazeo</dc:source> + <dc:creator> + <cc:Agent> + <dc:title>mazeo</dc:title> + </cc:Agent> + </dc:creator> + <dc:subject> + <rdf:Bag> + <rdf:li>clip art</rdf:li> + <rdf:li>clipart</rdf:li> + <rdf:li>fingers</rdf:li> + <rdf:li>fist</rdf:li> + <rdf:li>hand</rdf:li> + <rdf:li>hands</rdf:li> + <rdf:li>paper</rdf:li> + <rdf:li>paper rock scissors</rdf:li> + <rdf:li>paper scissors rock</rdf:li> + <rdf:li>remix</rdf:li> + <rdf:li>rock</rdf:li> + <rdf:li>rock paper scissors</rdf:li> + <rdf:li>rock scissors paper</rdf:li> + <rdf:li>scissor</rdf:li> + <rdf:li>scissors</rdf:li> + <rdf:li>scissors paper rock</rdf:li> + <rdf:li>scissors rock paper</rdf:li> + </rdf:Bag> + </dc:subject> + </cc:Work> + <cc:License rdf:about="http://creativecommons.org/licenses/publicdomain/"> + <cc:permits rdf:resource="http://creativecommons.org/ns#Reproduction"/> + <cc:permits rdf:resource="http://creativecommons.org/ns#Distribution"/> + <cc:permits rdf:resource="http://creativecommons.org/ns#DerivativeWorks"/> + </cc:License> + </rdf:RDF> + </metadata> +</svg> diff --git a/app/assets/javascripts/alerts/edit.js.coffee b/app/assets/javascripts/alerts/edit.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/alerts/edit.js.coffee diff --git a/app/assets/javascripts/alerts/index.js.coffee b/app/assets/javascripts/alerts/index.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/alerts/index.js.coffee diff --git a/app/assets/javascripts/alerts/new.js.coffee b/app/assets/javascripts/alerts/new.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/alerts/new.js.coffee diff --git a/app/assets/javascripts/alerts/show.js.coffee b/app/assets/javascripts/alerts/show.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/alerts/show.js.coffee diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index d6925fa..1130838 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -13,4 +13,8 @@ //= require jquery //= require jquery_ujs //= require turbolinks -//= require_tree . +//= require 'drag.js' +//= require 'dragsort.js' +//= require 'coordinates.js' +// +//= require_tree ./application diff --git a/app/assets/javascripts/application/.keep b/app/assets/javascripts/application/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/application/.keep diff --git a/app/assets/javascripts/application/layout.js.coffee b/app/assets/javascripts/application/layout.js.coffee new file mode 100644 index 0000000..19b0b8a --- /dev/null +++ b/app/assets/javascripts/application/layout.js.coffee @@ -0,0 +1,43 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + +json_url = "/alerts.json" + +page_visited = false +starting_size = 0 +update = (alerts) -> + if !page_visited + starting_size = alerts.length + page_visited = true + + if alerts.length > starting_size + $("#alerts-ajax").css("display", "inline"); + return + + setTimeout (-> + $.ajax(url: json_url).done update + return + ), 2000 + +# Now kick off the whole process +window.onload = -> + $.ajax(url: json_url).done update
\ No newline at end of file diff --git a/app/assets/javascripts/brackets/edit.js.coffee b/app/assets/javascripts/brackets/edit.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/brackets/edit.js.coffee diff --git a/app/assets/javascripts/brackets/index.js.coffee b/app/assets/javascripts/brackets/index.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/brackets/index.js.coffee diff --git a/app/assets/javascripts/brackets/new.js.coffee b/app/assets/javascripts/brackets/new.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/brackets/new.js.coffee diff --git a/app/assets/javascripts/brackets/show.js.coffee b/app/assets/javascripts/brackets/show.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/brackets/show.js.coffee diff --git a/app/assets/javascripts/games/edit.js.coffee b/app/assets/javascripts/games/edit.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/games/edit.js.coffee diff --git a/app/assets/javascripts/games/index.js.coffee b/app/assets/javascripts/games/index.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/games/index.js.coffee diff --git a/app/assets/javascripts/games/new.js.coffee b/app/assets/javascripts/games/new.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/games/new.js.coffee diff --git a/app/assets/javascripts/games/show.js.coffee b/app/assets/javascripts/games/show.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/games/show.js.coffee diff --git a/app/assets/javascripts/main/homepage.js.coffee b/app/assets/javascripts/main/homepage.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/main/homepage.js.coffee diff --git a/app/assets/javascripts/matches/show.js.coffee b/app/assets/javascripts/matches/show.js.coffee new file mode 100644 index 0000000..2609a69 --- /dev/null +++ b/app/assets/javascripts/matches/show.js.coffee @@ -0,0 +1,2 @@ +window.onload = -> + BetterDragSort.makeListSortable(document.getElementById("boxes")); diff --git a/app/assets/javascripts/pms/edit.js.coffee b/app/assets/javascripts/pms/edit.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/pms/edit.js.coffee diff --git a/app/assets/javascripts/pms/index.js.coffee b/app/assets/javascripts/pms/index.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/pms/index.js.coffee diff --git a/app/assets/javascripts/pms/new.js.coffee b/app/assets/javascripts/pms/new.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/pms/new.js.coffee diff --git a/app/assets/javascripts/pms/show.js.coffee b/app/assets/javascripts/pms/show.js.coffee new file mode 100644 index 0000000..8397fbe --- /dev/null +++ b/app/assets/javascripts/pms/show.js.coffee @@ -0,0 +1,47 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + +json_url = window.location.href.replace(/\.[^/]*$/,'')+".json" + +page_visited_pms = false +starting_size_pms = 0 +update = (pms) -> + if !page_visited_pms + starting_size_pms = pms.conversation.count_messages + page_visited_pms = true + + if pms.convesation.count_messages > starting_size_pms + window.location.reload true + return + + console.log("hey we got here!") + console.log(starting_size_pms) + console.log(pms.convesation.count_messages) + + setTimeout (-> + $.ajax(url: json_url).done update + return + ), 2000 + +# Now kick off the whole process +window.onload = -> + $.ajax(url: json_url).done update
\ No newline at end of file diff --git a/app/assets/javascripts/search/go.js.coffee b/app/assets/javascripts/search/go.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/search/go.js.coffee diff --git a/app/assets/javascripts/server/edit.js.coffee b/app/assets/javascripts/server/edit.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/server/edit.js.coffee diff --git a/app/assets/javascripts/server/show.js.coffee b/app/assets/javascripts/server/show.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/server/show.js.coffee diff --git a/app/assets/javascripts/sessions/new.js.coffee b/app/assets/javascripts/sessions/new.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/sessions/new.js.coffee diff --git a/app/assets/javascripts/teams/edit.js.coffee b/app/assets/javascripts/teams/edit.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/teams/edit.js.coffee diff --git a/app/assets/javascripts/teams/index.js.coffee b/app/assets/javascripts/teams/index.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/teams/index.js.coffee diff --git a/app/assets/javascripts/teams/new.js.coffee b/app/assets/javascripts/teams/new.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/teams/new.js.coffee diff --git a/app/assets/javascripts/teams/show.js.coffee b/app/assets/javascripts/teams/show.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/teams/show.js.coffee diff --git a/app/assets/javascripts/tournaments/edit.js.coffee b/app/assets/javascripts/tournaments/edit.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/tournaments/edit.js.coffee diff --git a/app/assets/javascripts/tournaments/index.js.coffee b/app/assets/javascripts/tournaments/index.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/tournaments/index.js.coffee diff --git a/app/assets/javascripts/tournaments/new.js.coffee b/app/assets/javascripts/tournaments/new.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/tournaments/new.js.coffee diff --git a/app/assets/javascripts/tournaments/show.js.coffee b/app/assets/javascripts/tournaments/show.js.coffee new file mode 100644 index 0000000..1fa9916 --- /dev/null +++ b/app/assets/javascripts/tournaments/show.js.coffee @@ -0,0 +1,54 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + +json_url = window.location.href.replace(/\.[^/]*$/,'')+".json" + +update = (tournament) -> + here = tournament["players"].length + needed = (tournament["min_teams_per_match"] * tournament["min_players_per_team"]) + pct_complete = here / needed + + $("#prog-bar").width (pct_complete * 100) + "%" + $("#players-needed").text here + " " + ((if here is 1 then "player has" else "players have")) + " signed up. " + needed + " players needed. " + + # Update the user list + players = "" + for player in tournament["players"] + players = players + "<li>"+player["user_name"]+"</li>" + $("#tournament-users").html players + + # Enable/disable the "start" button depending on the number of players + $("input[value=\"Start Tournament\"]").prop "disabled", (if (pct_complete >= 1) then false else true) + + # Switch views if the tournament has been started + if tournament["status"] is 1 + window.location.reload true + + # Do it all again + setTimeout (-> + $.ajax(url: json_url).done update + return + ), 2000 + +# Now kick off the whole process +window.onload = -> + $.ajax(url: json_url).done update diff --git a/app/assets/javascripts/users/edit.js.coffee b/app/assets/javascripts/users/edit.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/users/edit.js.coffee diff --git a/app/assets/javascripts/users/index.js.coffee b/app/assets/javascripts/users/index.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/users/index.js.coffee diff --git a/app/assets/javascripts/users/new.js.coffee b/app/assets/javascripts/users/new.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/users/new.js.coffee diff --git a/app/assets/javascripts/users/show.js.coffee b/app/assets/javascripts/users/show.js.coffee new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/assets/javascripts/users/show.js.coffee diff --git a/app/assets/stylesheets/alerts.css.scss b/app/assets/stylesheets/alerts.css.scss deleted file mode 100644 index c01a620..0000000 --- a/app/assets/stylesheets/alerts.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the alerts controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css deleted file mode 100644 index 3192ec8..0000000 --- a/app/assets/stylesheets/application.css +++ /dev/null @@ -1,13 +0,0 @@ -/* - * This is a manifest file that'll be compiled into application.css, which will include all the files - * listed below. - * - * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, - * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. - * - * You're free to add application-wide styles to this file and they'll appear at the top of the - * compiled file, but it's generally better to create a new file per style scope. - * - *= require_self - *= require_tree . - */ diff --git a/app/assets/stylesheets/application.css.less b/app/assets/stylesheets/application.css.less new file mode 100644 index 0000000..c6020bd --- /dev/null +++ b/app/assets/stylesheets/application.css.less @@ -0,0 +1,8 @@ +/* + * This is a manifest file that'll be compiled into application.css. + */ +/* If you put any styles in this file directly, I will knife you. */ + +@import "colors"; +@import "bootstrapify"; +@import "scaffolds"; diff --git a/app/assets/stylesheets/bootstrapify.less b/app/assets/stylesheets/bootstrapify.less new file mode 100644 index 0000000..eb3b86b --- /dev/null +++ b/app/assets/stylesheets/bootstrapify.less @@ -0,0 +1,117 @@ +/* Copyright (C) 2014 Andrew Murrell + * Copyright (C) 2014 Davis Webb + * Copyright (C) 2014 Guntas Grewal + * Copyright (C) 2014 Luke Shumaker + * Copyright (C) 2014 Nathaniel Foy + * Copyright (C) 2014 Tomer Kimia + * + * This file is part of Leaguer. + * + * Leaguer is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Leaguer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the Affero GNU General Public License + * along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + */ + +@import "bootstrap"; + +// Connect Bootstrap classes to reasonable defaults + +.btn { + &:extend(.btn-default); +} + +button, +*[role="button"], +input[type="submit"], +input[type="reset"], +input[type="button"] { + &:extend(.btn); +} + +.navbar { + form { + &:extend(.navbar-form); + } + .nav { + &:extend(.navbar-nav); + } + ul { + &:extend(.nav); + } +} +form { + // This list of types is taken from the 2014-04-29 draft of + // the HTML5 spec: + // http://www.w3.org/TR/2014/CR-html5-20140429/forms.html#attr-input-type + input[type="text"], + input[type="search"], + input[type="tel"], + input[type="url"], + input[type="email"], + input[type="password"], + input[type="date"], + input[type="time"], + input[type="number"], + input[type="range"], + input[type="color"], + select, textarea { + &:extend(.form-control); + } + label { + &:extend(.control-label); + } +} + +header nav { + &:extend(.navbar); + &:extend(.navbar-default); +} + +.alert:extend(.alert-default) {} +.alert-success, +.alert-info, +.alert-warning, +.alert-danger { &:extend(.alert); } + +.panel-primary, +.panel-success, +.panel-info, +.panel-warning, +.panel-danger { &:extend(.panel); } + +.panel { + h1, h2, h3, h4, h5, h6 { + &:extend(.panel-heading); + &:extend(.panel-title); + } +} + +// Connect built-in Rails classes to the Bootstrap classes. + +form { + .field { + &:extend(.form-group); + .field_with_errors { + display: inline !important; + } + } + .field_with_errors { + &:extend(.has-error); + } +} + +#error_explanation { + &:extend(.panel-danger); + &:extend(.container); + padding-left: 0; + padding-right: 0; +} diff --git a/app/assets/stylesheets/brackets.css.scss b/app/assets/stylesheets/brackets.css.scss deleted file mode 100644 index 481e6e6..0000000 --- a/app/assets/stylesheets/brackets.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the brackets controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/colors.less b/app/assets/stylesheets/colors.less new file mode 100644 index 0000000..61e1e57 --- /dev/null +++ b/app/assets/stylesheets/colors.less @@ -0,0 +1,32 @@ +/* +@darker-orange: #9D4102; +@link-yellow: #FFC50D; +@orange: #DD9125; +@page-color: #444; +@toolbar-color: black; +*/ + +// See this file for a complete list of variables: +// vendor/bundle/ruby/2.0.0/gems/bootstrap-sass-3.1.1.1/vendor/assets/stylesheets/bootstrap/_variables.less +// Or visit: +// http://getbootstrap.com/customize/#less-variables +/* +@gray-darker: +@gray-dark: +@gray: +@gray-light: +@gray-lighter: + +@brand-primary: +@brand-success: +@brand-info: +@brand-warning: +@brand-danger: +*/ + +/* +@text-color: #DD9125; +@body-bg: #333; +*/ + +@legend-border-color: #ccc; // matches the default @input-border and @btn-default-border diff --git a/app/assets/stylesheets/games.css.scss b/app/assets/stylesheets/games.css.scss deleted file mode 100644 index db1b7bc..0000000 --- a/app/assets/stylesheets/games.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the games controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/main.css.scss b/app/assets/stylesheets/main.css.scss deleted file mode 100644 index a0d94c1..0000000 --- a/app/assets/stylesheets/main.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the main controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/matches.css.scss b/app/assets/stylesheets/matches.css.scss deleted file mode 100644 index 4c396e3..0000000 --- a/app/assets/stylesheets/matches.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the matches controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/pms.css.scss b/app/assets/stylesheets/pms.css.scss deleted file mode 100644 index 5106093..0000000 --- a/app/assets/stylesheets/pms.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the pms controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/scaffolds.css.scss b/app/assets/stylesheets/scaffolds.css.scss deleted file mode 100644 index 6ec6a8f..0000000 --- a/app/assets/stylesheets/scaffolds.css.scss +++ /dev/null @@ -1,69 +0,0 @@ -body { - background-color: #fff; - color: #333; - font-family: verdana, arial, helvetica, sans-serif; - font-size: 13px; - line-height: 18px; -} - -p, ol, ul, td { - font-family: verdana, arial, helvetica, sans-serif; - font-size: 13px; - line-height: 18px; -} - -pre { - background-color: #eee; - padding: 10px; - font-size: 11px; -} - -a { - color: #000; - &:visited { - color: #666; - } - &:hover { - color: #fff; - background-color: #000; - } -} - -div { - &.field, &.actions { - margin-bottom: 10px; - } -} - -#notice { - color: green; -} - -.field_with_errors { - padding: 2px; - background-color: red; - display: table; -} - -#error_explanation { - width: 450px; - border: 2px solid red; - padding: 7px; - padding-bottom: 0; - margin-bottom: 20px; - background-color: #f0f0f0; - h2 { - text-align: left; - font-weight: bold; - padding: 5px 5px 5px 15px; - font-size: 12px; - margin: -7px; - margin-bottom: 0px; - background-color: #c00; - color: #fff; - } - ul li { - font-size: 12px; - list-style: square; - } -} diff --git a/app/assets/stylesheets/scaffolds.less b/app/assets/stylesheets/scaffolds.less new file mode 100644 index 0000000..bbdd989 --- /dev/null +++ b/app/assets/stylesheets/scaffolds.less @@ -0,0 +1,305 @@ +/* Copyright (C) 2014 Andrew Murrell + * Copyright (C) 2014 Davis Webb + * Copyright (C) 2014 Guntas Grewal + * Copyright (C) 2014 Luke Shumaker + * Copyright (C) 2014 Nathaniel Foy + * Copyright (C) 2014 Tomer Kimia + * + * This file is part of Leaguer. + * + * Leaguer is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Leaguer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the Affero GNU General Public License + * along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + */ + +/* Mixins ***********************************************************/ +/* These are just here for other things to @extend. */ +/* Ok, they're really classes, but we don't use them like it. */ + +/* More elegant version of .input-group, which is over-complicated + because it supports all kind of things we don't always need to. + This is useful because it doesn't require extra HTML elements, + where .input-group does. */ +.simple-input-group { + white-space: nowrap; + display: table; + span { + display: table-cell; + } + .btn, .form-control { + display: table-cell !important; + /* .simple-input-group .btn:not(:last-child), + * .simple-input-group .form-control:not(:last-child) { ... } */ + &:not(:last-child) { + @include border-right-radius(0); + } + &:not(:first-child) { + @include border-left-radius(0); + border-left: 0; + } + } +} + +/* IDs **************************************************************/ +/* Specific page elements */ + +#notice { + &:extend(.alert-success); + &:extend(.container); + text-align: center; +} + +#alerts-ajax { + display: none; +} + + +form#search { + &:extend(.navbar-left); + div { + &:extend(.simple-input-group); + } +} + +#user-actions { + &:extend(.navbar-btn); + &:extend(.navbar-right); + &:extend(.simple-input-group); + span { + padding-right: .25em; + } +} + +#error_explanation ul { + list-style: disc outside none; +} + +#players-needed { + text-align: center; + font-style: italic; +} + +#tournament-side-params { + background: none repeat scroll 0 0 rgba(0,0,0,0.5); + border-radius: 5px; + float: right; + font-size: 7px; + padding: 10px; + + p { + font-size: 10px; + margin-bottom: 5px; + } + +} + +#peer_review_boxes li { + cursor: move; + position: relative; + float: left; + margin: 5px; + width: 180px; + height: 240px; + border: 1px solid rgb(0, 0, 0); + text-align: center; + padding-top: 10px; + background-color: rgb(238, 238, 255); +} + +// Nothing uses this one right now +#peer_review_numeric li { + cursor: move; + position: relative; + float: left; + margin: 5px; + width: 180px; + height: 240px; + border: 1px solid rgb(0, 0, 0); + text-align: center; + padding-top: 10px; + background-color: rgb(238, 238, 255); +} + +/**** INDEX PAGE - TABLE AND GRAPH ****/ +#matches-table { + &:extend(.table); + color: #FFF; + + form { + color: #333; + } +} + +/* Classes **********************************************************/ + +/* +.btn { + &.user:extend(.btn-info) {} + &.signup:extend(.btn-success) {} + &.signin:extend(.btn-warning) {} + &.signout:extend(.btn-danger) {} + &.server:extend(.btn-warning) {} + &.create-alert { + color: white; + background-color: rgb(255, 69, 0); + border-color: rgb(255, 69, 0); + } + &.alerts { + color: white; + background-color: hsl(0, 69%, 22%); + } +} +*/ + +form.button_to, form.button_to div { + display: inline; +} + +div.field span.help-block { + float: right; + margin-top: 0; + margin-bottom: 0; +} + +/* Elements *********************************************************/ + +footer { + &:extend(.container); + margin-top: 1em; + border-top: solid 1px $hr-border; + text-align: center; +} + +fieldset { + border: solid 1px $legend-border-color; + border-radius: .5em; + padding: 1em; + margin: 1em 0; + legend { + display: block; + margin: 0; + padding: .25em .5em; + width: auto; + border: solid 1px $legend-border-color; + border-radius: .5em; + } +} + +form ul { + list-style: none; +} + +pre { + text-align: left; +} + +/* Misc *************************************************************/ + +.tournament-listing { + margin: 10px 0px; + border-radius: 5px; + box-shadow: 0px 0px 3px #B8B8B8; + background-color: rgba(0, 0, 0, 0.6); + border: 1px solid #AAAAAA; + min-height: 100px; + padding: 8px 4px; + + div.row { + margin-left: 2%; + } + p.message { + margin-top: 10px; + } + + /* AKA the listing title */ + h3 { + margin-top: 0px; + color: #F0AD4E; + font-weight: bold; + } + + h3:hover { + color: #D09D3E; + } + + /* host of the tournament */ + .host { + font-weight: bold; + color: #FFF; + } + + .col-md-8 { + padding: 0; + a { + padding: 5px 0 0 0; + } + } + + .t-game{ + font-weight: bold; + text-align: center; + } + + .t-image{ + display: block; + margin:auto; + } +} + + +.user-listing { + margin: 10px 0px; + border-radius: 5px; + box-shadow: 0px 0px 3px #B8B8B8; + background-color: rgba(0, 0, 0, 0.6); + border: 1px solid #AAAAAA; + min-height: 100px; + padding: 8px 4px; + display: inline-table; + + /* AKA the listing title */ + h3 { + margin-top: 0px; + color: #F0AD4E; + font-weight: bold; + } + + h3:hover { + color: #D09D3E; + } + + .things { + padding: 0px 10px; + } + + p { + margin: 0; + } + div.row { + margin-left: 2%; + } +} + +// Limitation: Only one box can be expanded at a time +.collapsible { + .collapsed { display: block; } + .expanded { display: none; } + &:target { + .collapsed { display: none; } + .expanded { display: block; } + } +} + +.simple_captcha { + background-color: rgba(255, 255, 255, 0.7); + margin: 10px 0px; +} diff --git a/app/assets/stylesheets/search.css.scss b/app/assets/stylesheets/search.css.scss deleted file mode 100644 index 22fd394..0000000 --- a/app/assets/stylesheets/search.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the search controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/servers.css.scss b/app/assets/stylesheets/servers.css.scss deleted file mode 100644 index 4710386..0000000 --- a/app/assets/stylesheets/servers.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the servers controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/sessions.css.scss b/app/assets/stylesheets/sessions.css.scss deleted file mode 100644 index 7bef9cf..0000000 --- a/app/assets/stylesheets/sessions.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the sessions controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/teams.css.scss b/app/assets/stylesheets/teams.css.scss deleted file mode 100644 index 320d00d..0000000 --- a/app/assets/stylesheets/teams.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the teams controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/tournaments.css.scss b/app/assets/stylesheets/tournaments.css.scss deleted file mode 100644 index e372b90..0000000 --- a/app/assets/stylesheets/tournaments.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the tournaments controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/users.css.scss b/app/assets/stylesheets/users.css.scss deleted file mode 100644 index 1efc835..0000000 --- a/app/assets/stylesheets/users.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the users controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/alerts_controller.rb b/app/controllers/alerts_controller.rb index a3cb8f9..1da2c9b 100644 --- a/app/controllers/alerts_controller.rb +++ b/app/controllers/alerts_controller.rb @@ -1,6 +1,26 @@ -class AlertsController < ApplicationController - before_action :set_alert, only: [:show, :edit, :update, :destroy] +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. +class AlertsController < ApplicationController # GET /alerts # GET /alerts.json def index @@ -25,6 +45,13 @@ class AlertsController < ApplicationController # POST /alerts.json def create @alert = Alert.new(alert_params) + @alert.author = current_user + users = {} + users = User.all + + for i in 0..users.length + current_user.send_message(users[i], @alert.message, "Pay Attention!") + end respond_to do |format| if @alert.save @@ -62,6 +89,7 @@ class AlertsController < ApplicationController end private + # Use callbacks to share common setup or constraints between actions. def set_alert @alert = Alert.find(params[:id]) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 27ef6a7..f45eb49 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,72 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + class ApplicationController < ActionController::Base + before_action :set_object, only: [:show] + before_action :check_create, only: [:new, :create] + before_action :check_edit, only: [:edit, :update] + before_action :check_delete, only: [:destroy] + # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception + + #include sessionhelper for the session controller and view + include SessionsHelper + + include SimpleCaptcha::ControllerHelpers + + def check_permission(verb, object=nil) + unless current_user.can?("#{verb.to_s}_#{noun}".to_sym) or object.try(:check_permission, current_user, verb) + respond_to do |format| + format.html do + if object.nil? + redirect_to send(noun.pluralize+"_url"), notice: "You don't have permission to #{verb} #{noun.pluralize}." + else + redirect_to object, notice: "You don't have permission to #{verb} this #{noun}." + end + end + format.json { render json: "Permission denied", status: :forbidden } + end + end + end + + def noun + @noun ||= self.class.name.underscore.sub(/_controller$/, '').singularize + end + + def set_object + object = send("set_"+noun) + end + + def check_create + check_permission(:create) + end + def check_edit + object = send("set_"+noun) + check_permission(:edit, object) + end + def check_delete + object = send("set_"+noun) + check_permission(:edit, object) + end end diff --git a/app/controllers/brackets_controller.rb b/app/controllers/brackets_controller.rb index fe43ca9..014687f 100644 --- a/app/controllers/brackets_controller.rb +++ b/app/controllers/brackets_controller.rb @@ -1,20 +1,52 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + class BracketsController < ApplicationController - before_action :set_bracket, only: [:show, :edit, :update, :destroy] + before_action :set_tournament, only: [:index, :create] # GET /brackets # GET /brackets.json def index - @brackets = Bracket.all + @tournament = Tournament.find(params[:tournament_id]) + @brackets = @tournament.brackets end # GET /brackets/1 # GET /brackets/1.json def show - end + @results = (@tournament.status == 4)? @bracket.calcResult : nil; + @matches = @tournament.stages.order(:id).first.matches_ordered + @numTeams = @tournament.min_teams_per_match + @logBase = @numTeams + + # depth of SVG tree + @depth = Math.log(@matches.count*(@logBase-1),@logBase).floor+1; + + # height of SVG + @matchHeight = 50*@logBase; + @height = [(@matchHeight+50) * @logBase**(@depth-1) + 100, 500].max; - # GET /brackets/new - def new - @bracket = Bracket.new + @base = 1 + @pBase = 1 end # GET /brackets/1/edit @@ -24,14 +56,17 @@ class BracketsController < ApplicationController # POST /brackets # POST /brackets.json def create - @bracket = Bracket.new(bracket_params) + @bracket = @tournament.brackets.build(user: current_user) + @bracket.name = current_user.user_name + "'s Prediction for " + @tournament.name respond_to do |format| - if @bracket.save + if @tournament.status == 1 && @tournament.stages.first.scheduling_method == "elimination" && @tournament.stages.first.matches.first.status < 2 + @bracket.save + @bracket.create_matches format.html { redirect_to @bracket, notice: 'Bracket was successfully created.' } - format.json { render action: 'show', status: :created, location: @bracket } + format.json { render action: 'edit', status: :created, location: @bracket } else - format.html { render action: 'new' } + format.html { redirect_to tournaments_path action: 'You can\'t make a bracket for this tournament' } format.json { render json: @bracket.errors, status: :unprocessable_entity } end end @@ -41,11 +76,11 @@ class BracketsController < ApplicationController # PATCH/PUT /brackets/1.json def update respond_to do |format| - if @bracket.update(bracket_params) - format.html { redirect_to @bracket, notice: 'Bracket was successfully updated.' } + if @bracket.predict_winners(prediction_params) + format.html { redirect_to @tournament, notice: 'Your bracket was made! Check back when this stage finishes to see how you did!' } format.json { head :no_content } else - format.html { render action: 'edit' } + format.html { redirect_to @tournament, notice: 'bracket was not made... :('} format.json { render json: @bracket.errors, status: :unprocessable_entity } end end @@ -64,11 +99,24 @@ class BracketsController < ApplicationController private # Use callbacks to share common setup or constraints between actions. def set_bracket + @tournament = Tournament.find(params[:tournament_id]) @bracket = Bracket.find(params[:id]) end + def set_tournament + @tournament = Tournament.find(params[:tournament_id]) + end + # Never trust parameters from the scary internet, only allow the white list through. def bracket_params + # bracket[user_id] + # bracket[tournament_id] + # bracket[name] + # bracket[matches][#{i}] params.require(:bracket).permit(:user_id, :tournament_id, :name) end + + def prediction_params + params.require(:bracket).require(:matches) + end end diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 27df771..b724d3a 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -1,6 +1,26 @@ -class GamesController < ApplicationController - before_action :set_game, only: [:show, :edit, :update, :destroy] +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. +class GamesController < ApplicationController # GET /games # GET /games.json def index diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index 6519d7b..0ba4d94 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -1,2 +1,4 @@ class MainController < ApplicationController + def homepage + end end diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 4042d3c..70d7359 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -1,62 +1,92 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + class MatchesController < ApplicationController - before_action :set_match, only: [:show, :edit, :update, :destroy] + require 'httparty' + require 'json' + require 'delayed_job' + + before_action :set_tournament, only: [:index] - # GET /matches - # GET /matches.json + # GET /tournaments/1/matches + # GET /tournaments/1/matches.json def index - @matches = Match.all end - # GET /matches/1 - # GET /matches/1.json + # GET /tournaments/1/matches/1 + # GET /tournaments/1/matches/1.json def show end - # GET /matches/new - def new - @match = Match.new - end - - # GET /matches/1/edit - def edit - end - - # POST /matches - # POST /matches.json - def create - @match = Match.new(match_params) - - respond_to do |format| - if @match.save - format.html { redirect_to @match, notice: 'Match was successfully created.' } - format.json { render action: 'show', status: :created, location: @match } - else - format.html { render action: 'new' } - format.json { render json: @match.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /matches/1 - # PATCH/PUT /matches/1.json + # PATCH/PUT /tournaments/1/matches/1 + # PATCH/PUT /tournaments/1/matches/1.json def update - respond_to do |format| - if @match.update(match_params) - format.html { redirect_to @match, notice: 'Match was successfully updated.' } - format.json { head :no_content } - else - format.html { render action: 'edit' } - format.json { render json: @match.errors, status: :unprocessable_entity } + notice = nil + case @match.status + when 0 + # Created, waiting to be scheduled + when 1 + # Scheduled, waiting to start + if (@tournament.hosts.include? current_user) and (params[:update_action] == "start") + @match.status = 2 + @match.start_sampling + if @match.save + notice = 'Match has started.' + else + respond_to do |format| + format.html { render action: 'show' } + format.json { render json: @match.errors, status: :unprocessable_entity } + end + return + end + end + when 2 + # Started, waiting to finish + @match.handle_sampling(current_user, params) + # The @match.status will be updated by Statistic's after_save hook + if @match.status == 3 + notice = 'Match has finished' + end + when 3 + if (@tournament.hosts.include? current_user) and (params[:update_action] == "start") + ok = true + ActiveRecord::Base.transaction do + ok &= @match.statistics.destroy_all + ok &- @match.status = 1 + ok &= @match.save + end + if ok + notice = "Match has been reset" + else + respond_to do |format| + format.html { render action: 'show' } + format.json { render json: @match.errors, status: :unprocessable_entity } + end + return + end end end - end - - # DELETE /matches/1 - # DELETE /matches/1.json - def destroy - @match.destroy respond_to do |format| - format.html { redirect_to matches_url } + format.html { redirect_to match_path(@match), notice: notice } format.json { head :no_content } end end @@ -65,10 +95,21 @@ class MatchesController < ApplicationController # Use callbacks to share common setup or constraints between actions. def set_match @match = Match.find(params[:id]) + @tournament = @match.tournament_stage.tournament + end + + def set_tournament + @tournament = Tournament.find(params[:tournament_id]) end # Never trust parameters from the scary internet, only allow the white list through. def match_params params.require(:match).permit(:status, :tournament_stage_id, :winner_id) + params.require(:match).permit(:status, :tournament_stage_id, :winner_id) + end + + # Turn of check_edit, since our #update is flexible + def check_edit + set_match end end diff --git a/app/controllers/pms_controller.rb b/app/controllers/pms_controller.rb index 11f51c8..faaa38f 100644 --- a/app/controllers/pms_controller.rb +++ b/app/controllers/pms_controller.rb @@ -1,6 +1,26 @@ -class PmsController < ApplicationController - before_action :set_pm, only: [:show, :edit, :update, :destroy] +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. +class PmsController < ApplicationController # GET /pms # GET /pms.json def index @@ -25,6 +45,10 @@ class PmsController < ApplicationController # POST /pms.json def create @pm = Pm.new(pm_params) + @pm.author = current_user + @pm.recipient = User.find_by_user_name(pm_params['recipient_id']) + + @pm.conversation = @pm.author.send_message(@pm.recipient, @pm.message, @pm.subject).conversation respond_to do |format| if @pm.save @@ -37,6 +61,10 @@ class PmsController < ApplicationController end end + #def reply + # current_user.reply_to_conversation(conversation, message) + #end + # PATCH/PUT /pms/1 # PATCH/PUT /pms/1.json def update @@ -49,6 +77,7 @@ class PmsController < ApplicationController format.json { render json: @pm.errors, status: :unprocessable_entity } end end + current_user.reply_to_conversation(@pm.conversation, @pm.message) end # DELETE /pms/1 diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index ee61487..a66fb40 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -1,2 +1,63 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + class SearchController < ApplicationController + + def go + @games = Game.all + @query = params[:query] + @gametype = params[:game_type] + + if ( @gametype.nil? and (@query.nil? or @query.empty?)) then + return + end + + tour_filters = [] + user_filters = [] + unless @query.empty? + tour_filters.push(["name LIKE ?", "%#{@query}%"]) + user_filters.push(["name LIKE ?", "%#{@query}%"]) + end + unless @gametype.nil? or @gametype.empty? + tour_filters.push(["game_id = ?", @gametype]) + end + + if tour_filters.empty? + @tournamets = [] + else + @tournaments = Tournament + tour_filters.each do |filter| + @tournaments = @tournaments.where(*filter) + end + end + + if user_filters.empty? + @players = [] + else + @players = User + user_filters.each do |filter| + @players = @players.where(*filter) + end + end + end + end diff --git a/app/controllers/servers_controller.rb b/app/controllers/servers_controller.rb index 4c12c7e..2a2ce5f 100644 --- a/app/controllers/servers_controller.rb +++ b/app/controllers/servers_controller.rb @@ -1,48 +1,41 @@ -class ServersController < ApplicationController - before_action :set_server, only: [:show, :edit, :update, :destroy] - - # GET /servers - # GET /servers.json - def index - @servers = Server.all - end +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. - # GET /servers/1 - # GET /servers/1.json +class ServersController < ApplicationController + # GET /server + # GET /server.json def show end - # GET /servers/new - def new - @server = Server.new - end - - # GET /servers/1/edit + # GET /server/edit def edit end - # POST /servers - # POST /servers.json - def create - @server = Server.new(server_params) - - respond_to do |format| - if @server.save - format.html { redirect_to @server, notice: 'Server was successfully created.' } - format.json { render action: 'show', status: :created, location: @server } - else - format.html { render action: 'new' } - format.json { render json: @server.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /servers/1 - # PATCH/PUT /servers/1.json + # PATCH/PUT /server + # PATCH/PUT /server.json def update respond_to do |format| if @server.update(server_params) - format.html { redirect_to @server, notice: 'Server was successfully updated.' } + format.html { redirect_to edit_server_url, notice: 'Server was successfully updated.' } format.json { head :no_content } else format.html { render action: 'edit' } @@ -51,24 +44,15 @@ class ServersController < ApplicationController end end - # DELETE /servers/1 - # DELETE /servers/1.json - def destroy - @server.destroy - respond_to do |format| - format.html { redirect_to servers_url } - format.json { head :no_content } - end - end - private + # Use callbacks to share common setup or constraints between actions. def set_server - @server = Server.find(params[:id]) + @server = Server.first end # Never trust parameters from the scary internet, only allow the white list through. def server_params - params.require(:server).permit(:default_user_permissions) + params.require(:server).permit(:default_user_permissions, :default_user_abilities => User.permission_bits.keys) end end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index b035ea0..ead53f0 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,52 +1,47 @@ -class SessionsController < ApplicationController - before_action :set_session, only: [:show, :edit, :update, :destroy] - - # GET /sessions - # GET /sessions.json - def index - @sessions = Session.all - end +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. - # GET /sessions/1 - # GET /sessions/1.json - def show - end +class SessionsController < ApplicationController # GET /sessions/new def new - @session = Session.new - end - - # GET /sessions/1/edit - def edit end # POST /sessions # POST /sessions.json def create - @session = Session.new(session_params) + # find the user... + user = User.find_by_email(params[:username_or_email].to_s) || User.find_by_user_name(params[:username_or_email].to_s) + #@session = Session.new(@user) + # ... and create a new session respond_to do |format| - if @session.save - format.html { redirect_to @session, notice: 'Session was successfully created.' } - format.json { render action: 'show', status: :created, location: @session } + if user && user.authenticate(params[:password].to_s) + sign_in user + format.html { redirect_to root_path, notice: "Welcome, #{user.name}" } # TODO; previous URL + #format.json { # TODO } else format.html { render action: 'new' } - format.json { render json: @session.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /sessions/1 - # PATCH/PUT /sessions/1.json - def update - respond_to do |format| - if @session.update(session_params) - format.html { redirect_to @session, notice: 'Session was successfully updated.' } - format.json { head :no_content } - else - format.html { render action: 'edit' } - format.json { render json: @session.errors, status: :unprocessable_entity } + format.json { render json: user.errors, status: :unprocessable_entity } end end end @@ -54,21 +49,32 @@ class SessionsController < ApplicationController # DELETE /sessions/1 # DELETE /sessions/1.json def destroy - @session.destroy + #@session.destroy + sign_out respond_to do |format| - format.html { redirect_to sessions_url } + format.html { redirect_to root_path } format.json { head :no_content } end end private - # Use callbacks to share common setup or constraints between actions. - def set_session - @session = Session.find(params[:id]) + + # Only allow creating a session if not logged in. + def check_create + unless current_user.nil? + respond_to do |format| + format.html { redirect_to root_path, notice: "You are already logged in" } # TODO: previous URL + format.json { render json: {"errors" => ["already logged in"]}, status: :forbidden } + end + end end - # Never trust parameters from the scary internet, only allow the white list through. - def session_params - params.require(:session).permit(:user_id, :token) + def check_delete + unless signed_in? + respond_to do |format| + format.html { redirect_to root_path, notice: "You are not logged in" } # TODO: previous URL + format.json { render json: {"errors" => ["not logged in"]}, status: :forbidden } + end + end end end diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb index 57b3d91..9dbdd82 100644 --- a/app/controllers/teams_controller.rb +++ b/app/controllers/teams_controller.rb @@ -1,5 +1,26 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + class TeamsController < ApplicationController - before_action :set_team, only: [:show, :edit, :update, :destroy] # GET /teams # GET /teams.json diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 51229cb..8458ba1 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -1,5 +1,26 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + class TournamentsController < ApplicationController - before_action :set_tournament, only: [:show, :edit, :update, :destroy] # GET /tournaments # GET /tournaments.json @@ -10,24 +31,73 @@ class TournamentsController < ApplicationController # GET /tournaments/1 # GET /tournaments/1.json def show + respond_to do |format| + format.html { + case @tournament.status + when 0 + render action: 'show' + when 1 + redirect_to tournament_matches_path(@tournament) + when 2 + redirect_to tournaments_page + end + } + format.json { + data = JSON.parse(@tournament.to_json) + data["players"] = @tournament.players; + render :json => data.to_json + } + end end # GET /tournaments/new def new - @tournament = Tournament.new + @tournament = Tournament.new(tournament_attribute_params) + if @tournament.game + @tournament.game.settings.each do |game_setting| + @tournament.tournament_settings.build( + name: game_setting.name, + value: game_setting.value, + vartype: game_setting.vartype, + type_opt: game_setting.type_opt, + description: game_setting.description, + display_order: game_setting.display_order) + end + end end # GET /tournaments/1/edit def edit + check_permission(:edit, @tournament) end # POST /tournaments # POST /tournaments.json def create - @tournament = Tournament.new(tournament_params) - + ok = true + begin + ActiveRecord::Base.transaction do + ok &= @tournament = Tournament.new(tournament_attribute_params.merge({hosts: [current_user]})) + ok &= @tournament.update(tournament_setting_params) + for i in 1..(params[:num_stages].to_i) do + begin + ok &= @tournament.stages.build(tournament_stage_params(i)) + rescue ActionController::ParameterMissing => e + ok = false + @tournament.errors.add("stages[#{i}]", "needs to be set") + end + end + ok &= @tournament.save + end + rescue ActiveRecord::RecordNotUnique => e + ok = false + @tournament.errors.add(:name, "must be unique") + rescue => e + ok = false + @tournament.errors.add(:exception, "Unknown error: ``#{e.class.name}'' -- #{e.inspect} -- #{e.methods - Object.new.methods}") + end respond_to do |format| - if @tournament.save + if ok format.html { redirect_to @tournament, notice: 'Tournament was successfully created.' } format.json { render action: 'show', status: :created, location: @tournament } else @@ -40,12 +110,71 @@ class TournamentsController < ApplicationController # PATCH/PUT /tournaments/1 # PATCH/PUT /tournaments/1.json def update - respond_to do |format| - if @tournament.update(tournament_params) - format.html { redirect_to @tournament, notice: 'Tournament was successfully updated.' } - format.json { head :no_content } - else - format.html { render action: 'edit' } + case params[:update_action] + when nil + check_permission(:edit, @tournament) + ok = true + ActiveRecord::Base.transaction do + ok &= @tournament.update(tournament_attribute_params) + ok &= @tournament.update(tournament_setting_params) + end + respond_to do |format| + if ok + format.html { redirect_to @tournament, notice: 'Tournament was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: 'edit' } + format.json { render json: @tournament.errors, status: :unprocessable_entity } + end + end + when "join" + # permission checking for join is done in the Tournament model + respond_to do |format| + if @tournament.join(current_user) + format.html { redirect_to @tournament, notice: 'You have joined this tournament.' } + format.json { head :no_content } + else + format.html { redirect_to @tournament, notice: "You can't join this tournament." } + format.json { render json: "Permission denied", status: :forbidden } + end + end + when "leave" + respond_to do |format| + if @tournament.leave(current_user) + format.html { redirect_to tournaments_url, notice: 'You have left the tournament.' } + format.json { head :no_content } + else + format.html { redirect_to @tournament, notice: 'You were\'t a part of this tournament.' } + format.json { render json: "Permission denied", status: :forbidden } + end + end + when "start" + check_permission(:edit, @tournament) + respond_to do |format| + if @tournament.status == 0 + @tournament.status = 1 + @tournament.save + success = true + ActiveRecord::Base.transaction do + # sched = tournament_attribute_params[:type_opt] + # success &= @tournament.stages.create(scheduling_method: sched) + success &= @tournament.stages.first.create_matches + end + if success + format.html { redirect_to @tournament, notice: 'You have started this tournament.' } + format.json { head :no_content } + else + format.html { redirect_to @tournament, notice: "You don't have permission to start this tournament." } + format.json { render json: "Permission denied", status: :forbidden } + end + else + format.html { redirect_to @tournament, notice: "This tournament is not in a state that it can be started." } + format.json { render json: "Permission denied", status: :forbidden } + end + end + else + respond_to do |format| + format.html { redirect_to @tournament, notice: "Invalid action", status: :unprocessable_entity } format.json { render json: @tournament.errors, status: :unprocessable_entity } end end @@ -64,11 +193,48 @@ class TournamentsController < ApplicationController private # Use callbacks to share common setup or constraints between actions. def set_tournament - @tournament = Tournament.find(params[:id]) + begin + @tournament = Tournament.find(params[:id]) + rescue + redirect_to tournaments_url, notice: 'That tournament no longer exists.' + end end # Never trust parameters from the scary internet, only allow the white list through. - def tournament_params - params.require(:tournament).permit(:game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :scoring_method) + def tournament_attribute_params + params[:num_stages] ||= 1 + if params[:tournament] + p = params.require(:tournament).permit(:game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :scoring_method) + if p[:game_id] + game = Game.find(p[:game_id]) + p[:min_players_per_team] ||= game.min_players_per_team + p[:max_players_per_team] ||= game.max_players_per_team + p[:min_teams_per_match] ||= game.min_teams_per_match + p[:max_teams_per_match] ||= game.max_teams_per_match + p[:scoring_method] ||= game.scoring_method + end + return p + else + return {} + end end + + def tournament_setting_params + if tournament_attribute_params[:game_id] + game = Game.find(params[:tournament][:game_id]) + params.require(:tournament).permit({:settings => game.settings.collect{|s| s.name}}) + else + return {} + end + end + + def tournament_stage_params(i) + params.require(:tournament).require(:stages).require(i.to_s).permit(:scheduling_method, :seeding_method) + end + + # Turn of check_edit, since our #update is flexible + def check_edit + set_tournament + end + end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 58bf4c6..37c84ae 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,7 +1,32 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + class UsersController < ApplicationController - before_action :set_user, only: [:show, :edit, :update, :destroy] + + require 'httparty' + require 'json' # GET /users + # GET /users.json def index @users = User.all @@ -25,13 +50,26 @@ class UsersController < ApplicationController # POST /users.json def create @user = User.new(user_params) + unless (true) # simple_captcha_valid?) + respond_to do |format| + format.html { render action: 'new', status: :unprocessable_entity } + format.json { render json: @user.errors, status: :unprocessable_entity } + end + return + end respond_to do |format| if @user.save - format.html { redirect_to @user, notice: 'User was successfully created.' } + sign_in @user + if @user.id == 1 + # This is the first user, so give them all the power + @user.permissions = 0x7FFFFFFF + @user.save + end + format.html { redirect_to root_path, notice: 'User was successfully created.' } format.json { render action: 'show', status: :created, location: @user } else - format.html { render action: 'new' } + format.html { render action: 'new', status: :unprocessable_entity } format.json { render json: @user.errors, status: :unprocessable_entity } end end @@ -40,8 +78,17 @@ class UsersController < ApplicationController # PATCH/PUT /users/1 # PATCH/PUT /users/1.json def update + ok = true + if params[:user][:remote_usernames].nil? + ok &= @user.update(user_params) + else + params[:user][:remote_usernames].each do |game_name,user_name| + game = Game.find_by_name(game_name) + Sampling::RiotApi::set_remote_name(@user, game, user_name) + end + end respond_to do |format| - if @user.update(user_params) + if ok format.html { redirect_to @user, notice: 'User was successfully updated.' } format.json { head :no_content } else @@ -61,6 +108,7 @@ class UsersController < ApplicationController end end + private # Use callbacks to share common setup or constraints between actions. def set_user @@ -69,6 +117,10 @@ class UsersController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def user_params - params.require(:user).permit(:name, :email, :user_name) + permitted = [ :name, :email, :user_name, :password, :password_confirmation ] + if current_user.can? :edit_permissions + permitted.push(:abilities => User.permission_bits.keys) + end + params.require(:user).permit(permitted) end end diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb index 309f8b2..a0367f6 100644 --- a/app/helpers/sessions_helper.rb +++ b/app/helpers/sessions_helper.rb @@ -1,2 +1,87 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + +require 'user' + module SessionsHelper + def sign_in(user) + session = Session.new(user: user) + raw_token = session.create_token + session.save! + + token = Session.hash_token(raw_token) + cookies.permanent[:remember_token] = { value: raw_token, expires: 20.minutes.from_now.utc } + end + + def current_session + Session.find_by(token: Session.hash_token(cookies[:remember_token])) + end + + # sets the @current_user instance varable to the user corresponding + # to the remember token, but only if @current_user is undefined + # since the remember token is hashed, we need to hash the cookie + # to find match the remember token + def current_user + return (current_session.nil? ? User::NilUser.new : current_session.user) + end + + # checks if someone is currently signed in + def signed_in? + !current_user.nil? + end + + def sign_out + if signed_in? + current_session.destroy + end + cookies.delete(:remember_token) + end + + # This is for anyone that cares about how long a user is signed + # in: + # + # Currently I have a user to be signed in forever unless they + # log out (cookies.permanent....). + # + # If you want to change that, change line 7 to this: + # + # cookies[:remember_token] = { value: remember_token, + # expires: 20.years.from_now.utc } + # + # which will expire the cookie in 20 years from its date of + # creation. + # + # Oddly enough, this line above is equivalent to the: + # + # cookies.permanent + # + # This is just a short cut for this line since most people + # create permanent cookies these days. + # + # Other times are: + # + # 10.weeks.from_now + # + # 5.days.ago + # + # etc... end diff --git a/app/models/alert.rb b/app/models/alert.rb index 0516355..189dfde 100644 --- a/app/models/alert.rb +++ b/app/models/alert.rb @@ -1,3 +1,29 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + class Alert < ActiveRecord::Base - belongs_to :author + belongs_to :author, class_name: "User" + + def owned_by?(user) + self.author == user + end end diff --git a/app/models/bracket.rb b/app/models/bracket.rb index e8d9c5a..930015a 100644 --- a/app/models/bracket.rb +++ b/app/models/bracket.rb @@ -1,4 +1,54 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + class Bracket < ActiveRecord::Base belongs_to :user belongs_to :tournament + has_many :bracket_matches + + def owned_by?(tuser) + self.user == tuser + end + + def create_matches + tournament.stages.order(:id).first.matches.order(:id).each do |m| + bracket_matches.create(match: m) + end + end + + + def predict_winners(predictions) + (0..bracket_matches.count-1).each do |i| + bracket_matches.order(:match_id)[i].update(predicted_winner: Team.find(predictions[(i+1).to_s])); + end + return true + end + + + def calcResults + results = Array.new + (0..bracket_matches.count-1).each do |i| + results.push(bracket_matches.order(:match_id)[i].predicted_winner == tournament.stages.order(:id).first.matches.order(:id).winner) + end + return results + end end diff --git a/app/models/bracket_match.rb b/app/models/bracket_match.rb index 823bc40..d6e53c6 100644 --- a/app/models/bracket_match.rb +++ b/app/models/bracket_match.rb @@ -1,5 +1,31 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + class BracketMatch < ActiveRecord::Base belongs_to :bracket belongs_to :match - belongs_to :predicted_winner + belongs_to :predicted_winner, class_name: "Team" + + def owned_by?(user) + self.bracket.owned_by?(user) + end end diff --git a/app/models/game.rb b/app/models/game.rb index 13520ac..f27f174 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -1,3 +1,67 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + class Game < ActiveRecord::Base - belongs_to :parent + belongs_to :parent, class_name: "Game" + + has_many :children, class_name: "Game" + + has_many :game_settings + validates_associated :game_settings + alias_attribute :settings, :game_settings + + validates(:name, + presence: true, + length: {minimum: 5}, + uniqueness: {case_sensitive: true}) + + validates(:min_players_per_team, + presence: true, + numericality: { + only_integer: true, + less_than_or_equal_to: :max_players_per_team, + }) + validates(:max_players_per_team, + presence: true, + numericality: { + only_integer: true, + greater_than_or_equal_to: :min_players_per_team, + }) + + validates(:min_teams_per_match, + presence: true, + numericality: { + only_integer: true, + less_than_or_equal_to: :max_teams_per_match, + }) + validates(:max_teams_per_match, + presence: true, + numericality: { + only_integer: true, + greater_than_or_equal_to: :min_teams_per_match, + }) + + validate :validate_scoring_method + def validate_scoring_method + (not self.scoring_method.try(:empty?)) and (Tournament.scoring_methods.include? scoring_method) + end end diff --git a/app/models/game_setting.rb b/app/models/game_setting.rb index bff8d97..514b57c 100644 --- a/app/models/game_setting.rb +++ b/app/models/game_setting.rb @@ -1,3 +1,49 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + class GameSetting < ActiveRecord::Base belongs_to :game + + alias_attribute :value, :default + + validates(:vartype, presence: true, numericality: {only_integer: true}) + validates(:type_opt, presence: true, if: :needs_type_opt?) + + def needs_type_opt? + [ + GameSetting.types[:pick_one_radio], + GameSetting.types[:pick_one_dropdown], + GameSetting.types[:pick_several], + ].include? self.vartype + end + + def self.types + return { + :text_short => 0, + :text_long => 1, + :pick_one_radio => 2, + :pick_several => 3, + :true_false => 4, + :pick_one_dropdown => 5, + } + end end diff --git a/app/models/match.rb b/app/models/match.rb index b5f539b..27c4fbe 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -1,4 +1,148 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + class Match < ActiveRecord::Base belongs_to :tournament_stage - belongs_to :winner + has_many :statistics + has_and_belongs_to_many :teams + + belongs_to :winner, class_name: "Team" + + # status:integer + before_save { self.status ||= 0 } + + # tournament_stage:references + validates_presence_of :tournament_stage + + # winner:references + # not validated + + def owned_by?(user) + self.tournament_stage.owned_by?(user) + end + + ## + # Returns whether or not all the statistics have been collected + # such that the match may be considered finished. + def finished? + ok = true + self.tournament_stage.scoring.stats_needed(self).each do |stat| + self.users.each do |user| + ok &= self.statistics.where(user: user, name: stat).first + end + end + ok + end + + ## + # Returns all players involved in this match (from all teams). + def users + ret = [] + self.teams.each{|t| ret.concat(t.users)} + return ret + end + + ## + # Given a sampling class (a class that implements the interface + # described in `/lib/sampling/README.md`), this returns which + # statistics (in an Array of Strings) an instance of the class + # should collect. + def stats_from(sampling_class) + figure_sampling_methods.map{|stat,klass| (sampling_class==klass) ? stat : nil}.select{|s| not s.nil?} + end + + ## + # Delagates PUT/PATCH HTTP params to the appropriate sampling + # methods. + def handle_sampling(user, params) + method_classes.each do |klass| + klass.new(self).handle_user_interaction(user, params) + end + end + + ## + # Delagates out rendering forms to the appropriate sampling + # methods. + def render_sampling(user) + require 'set' + html = '' + + method_classes.each do |klass| + html += '<div>' + html += klass.new(self).render_user_interaction(user) + html += '</div>' + end + + return html.html_safe + end + + ## + # Calls `Sampling#start` on every sampling method that this match + # uses. + def start_sampling + method_classes.each do |klass| + klass.new(self).start + end + end + + private + def figure_sampling_methods + if @sampling_methods.nil? + data = {} + needed = self.tournament_stage.scoring.stats_needed(self) + methods_names = self.tournament_stage.tournament.sampling_methods + methods_names.each do |method_name| + method_class = "Sampling::#{method_name.camelcase}".constantize + needed.each do |stat| + data[stat] ||= {} + data[stat][method_class] = method_class.can_get?(stat) + end + end + + needed.each do |stat| + max_val = nil + max_pri = 0 + data[stat].each do |method,priority| + if priority > max_pri + max_val = method + max_pri = priority + end + end + data[stat] = max_val + end + @sampling_methods = data + end + return @sampling_methods + end + + def method_classes + if @method_classes.nil? + data = Set.new + figure_sampling_methods.each do |stat,method| + data.add(method) + end + @method_classes = data + end + return @method_classes + end + end diff --git a/app/models/pm.rb b/app/models/pm.rb index 0e60f3e..31a04b7 100644 --- a/app/models/pm.rb +++ b/app/models/pm.rb @@ -1,5 +1,41 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + class Pm < ActiveRecord::Base - belongs_to :author - belongs_to :recipient + belongs_to :author, class_name: "User" + belongs_to :recipient, class_name: "User" belongs_to :conversation + + def name + return current_user.name + end + + def owned_by?(user) + self.author == user + end + +=begin + def mailboxer_email(email) + return current_user.email + end +=end end diff --git a/app/models/remote_username.rb b/app/models/remote_username.rb index c477f8a..e952779 100644 --- a/app/models/remote_username.rb +++ b/app/models/remote_username.rb @@ -1,4 +1,42 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + class RemoteUsername < ActiveRecord::Base belongs_to :game belongs_to :user -end + + def owned_by?(tuser) + self.user == tuser + end + + def value + begin + return JSON::restore(self.json_value) + rescue + return {} + end + end + + def value=(v) + self.json_value = v.to_json + end +end diff --git a/app/models/server.rb b/app/models/server.rb index 120f0fa..df053ca 100644 --- a/app/models/server.rb +++ b/app/models/server.rb @@ -1,2 +1,60 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + class Server < ActiveRecord::Base + def default_user_abilities + @abilities ||= User::Abilities.new(DefaultUser.new(self)) + end + def default_user_abilities=(new) + new.each do |k,v| + if v == "0" + v = false + end + default_user_abilities[k] = v + end + end + class DefaultUser + def initialize(server) + @server = server + end + def can?(action) + bit = User.permission_bits[action] + if bit.nil? + return false + else + return (@server.default_user_permissions & bit != 0) + end + end + def add_ability(action) + bit = User.permission_bits[action.to_sym] + unless bit.nil? + @server.default_user_permissions |= bit + end + end + def remove_ability(action) + bit = User.permission_bits[action.to_sym] + unless bit.nil? + @server.default_user_permissions &= ~ bit + end + end + end end diff --git a/app/models/session.rb b/app/models/session.rb index a5fd26e..a85e4fc 100644 --- a/app/models/session.rb +++ b/app/models/session.rb @@ -1,3 +1,68 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + class Session < ActiveRecord::Base belongs_to :user + + def owned_by?(tuser) + self.user == tuser + end + + ## + # Create a random remember token for the user. This will be + # changed every time the user creates a new session. + # + # If you want this value, hang on to it; the raw value is + # discarded afterward. + # + # By changing the cookie every new session, any hijacked sessions + # (where the attacker steals a cookie to sign in as a certain + # user) will expire the next time the user signs back in. + # + # The random string is of length 16 composed of A-Z, a-z, 0-9 + # This is the browser's cookie value. + def create_token() + t = SecureRandom.urlsafe_base64 + self.token = Session.hash_token(t) + t + end + + ## + # Encrypt the remember token. + # This is the encrypted version of the cookie stored on + # the database. + # + # The reasoning for storing a hashed token is so that even if + # the database is compromised, the attacker won't be able to use + # the remember tokens to sign in. + def Session.hash_token(token) + # SHA-1 (Secure Hash Algorithm) is a US engineered hash + # function that produces a 20 byte hash value which typically + # forms a hexadecimal number 40 digits long. + # The reason I am not using the Bcrypt algorithm is because + # SHA-1 is much faster and I will be calling this on + # every page a user accesses. + # + # https://en.wikipedia.org/wiki/SHA-1 + Digest::SHA1.hexdigest(token.to_s) + end end diff --git a/app/models/statistic.rb b/app/models/statistic.rb index 341fd9d..6a79e99 100644 --- a/app/models/statistic.rb +++ b/app/models/statistic.rb @@ -1,4 +1,54 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + class Statistic < ActiveRecord::Base belongs_to :user belongs_to :match + + validates(:name, presence: true, length: { minimum: 1 }) + + def value + begin + return JSON::restore(self.json_value) + rescue + return {} + end + end + + def value=(v) + self.json_value = v.to_json + end + + after_save :update_match + def update_match + ActiveRecord::Base.transaction do + if (self.name == "win") and (self.value) + self.match.winner = self.match.teams.find{|t| t.users.include? self.user} + end + if (self.match.status == 2) and (self.match.finished?) + self.match.status = 3 + self.match.tournament_stage.scheduling.finish_match(self.match) + end + self.match.save! + end + end end diff --git a/app/models/team.rb b/app/models/team.rb index fa7ba9e..76ee510 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -1,2 +1,32 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + class Team < ActiveRecord::Base + has_and_belongs_to_many :matches + has_and_belongs_to_many :users + + alias_attribute :players, :users + + def owned_by?(user) + self.users.include?(user) + end end diff --git a/app/models/tournament.rb b/app/models/tournament.rb index dcdb8d5..b18e359 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -1,3 +1,206 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + class Tournament < ActiveRecord::Base belongs_to :game + + has_many :tournament_stages + # Don't validate presence of stages; sadly, it seems to break things + #validates_presence_of :tournament_stages + alias_attribute :stages, :tournament_stages + + has_many :brackets + + has_many :tournament_settings + + has_and_belongs_to_many :players, class_name: "User", association_foreign_key: "player_id", join_table: "players_tournaments" + + has_and_belongs_to_many :hosts, class_name: "User", association_foreign_key: "host_id", join_table: "hosts_tournaments" + validates_presence_of :hosts + + validates_presence_of :game + + before_save { self.status ||= 0 } + + validates(:name, + presence: true, + length: {minimum: 5}, + uniqueness: {case_sensitive: true}) + + validates(:min_players_per_team, + presence: true, + numericality: { + only_integer: true, + less_than_or_equal_to: :max_players_per_team, + }) + validates(:max_players_per_team, + presence: true, + numericality: { + only_integer: true, + greater_than_or_equal_to: :min_players_per_team, + }) + + validates(:min_teams_per_match, + presence: true, + numericality: { + only_integer: true, + less_than_or_equal_to: :max_teams_per_match, + }) + validates(:max_teams_per_match, + presence: true, + numericality: { + only_integer: true, + greater_than_or_equal_to: :min_teams_per_match, + }) + + validate :validate_scoring_method + def validate_scoring_method + (not self.scoring_method.try(:empty?)) and (scoring_methods.include? scoring_method) + end + + def owned_by?(user) + self.hosts.include?(user) + end + + # Settings ################################################################# + + def settings + @settings ||= Settings.new(self) + end + + def settings=(setting) + setting.each do |key, value| + value = false if value == "0" + settings[key] = value + end + end + + class Settings + def initialize(tournament) + @tournament = tournament + end + + def [](setting_name) + tournament_setting = @tournament.tournament_settings.find{|s|s.name==setting_name} + if tournament_setting.nil? + return nil + else + return tournament_setting.value + end + end + + def []=(setting_name, val) + tournament_setting = @tournament.tournament_settings.find{|s|s.name==setting_name} + if tournament_setting.nil? + game_setting = @tournament.game.settings.find_by_name(setting_name) + @tournament.tournament_settings.build(name: setting_name, value: val, + vartype: game_setting.vartype, + type_opt: game_setting.type_opt, + description: game_setting.description, + display_order: game_setting.display_order) + else + tournament_setting.value = val + end + end + + def keys + @tournament.tournament_settings.all.collect { |x| x.name } + end + + def empty?() keys.empty? end + def count() keys.count end + def length() count end + def size() count end + + def method_missing(name, *args) + if name.to_s.ends_with?('=') + self[name.to_s.sub(/=$/, '').to_s] = args.first + else + return self[name.to_s] + end + end + end + + # Joining/Leaving ########################################################## + + def joinable_by?(user) + return (status==0 and user.can?(:join_tournament) and !players.include?(user)) + end + + def join(user) + unless joinable_by?(user) + return false + end + players.push(user) + end + + def leave(user) + if players.include?(user) && status == 0 + players.delete(user) + end + end + + # Configured methods ####################################################### + + def scoring + @scoring ||= "Scoring::#{self.scoring_method.camelcase}".constantize + end + + # Options for configured methods/modules ################################### + # We're conflicted about whether these should be `self.` or not. ########### + + def self.scoring_methods + make_methods "scoring" + end + def scoring_methods + self.class.scoring_methods + end + + def sampling_methods + self.class.make_methods("sampling").select do |name| + "Sampling::#{name.camelcase}".constantize.works_with?(self.game) + end + end + + def self.scheduling_methods + make_methods "scheduling" + end + def scheduling_methods + self.class.scheduling_methods + end + + def self.seeding_methods + make_methods "seeding" + end + def seeding_methods + self.class.seeding_methods + end + + private + def self.make_methods(dir) + @methods ||= {} + if @methods[dir].nil? or Rails.env.development? + @methods[dir] = Dir.glob("#{Rails.root}/lib/#{dir}/*.rb").map{|filename| File.basename(filename, ".rb") } + end + return @methods[dir] + end end diff --git a/app/models/tournament_setting.rb b/app/models/tournament_setting.rb index b3e6ace..cbf607a 100644 --- a/app/models/tournament_setting.rb +++ b/app/models/tournament_setting.rb @@ -1,3 +1,45 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + class TournamentSetting < ActiveRecord::Base belongs_to :tournament + + validates(:vartype, presence: true, numericality: {only_integer: true}) + validates(:type_opt, presence: true, if: :needs_type_opt?) + + def owned_by?(user) + self.tournament.owned_by?(user) + end + + def needs_type_opt? + [ + GameSetting.types[:pick_one_radio], + GameSetting.types[:pick_one_dropdown], + GameSetting.types[:pick_several], + ].include? self.vartype + end + + + def self.types + GameSetting.types + end end diff --git a/app/models/tournament_stage.rb b/app/models/tournament_stage.rb index 205c8cc..4695238 100644 --- a/app/models/tournament_stage.rb +++ b/app/models/tournament_stage.rb @@ -1,3 +1,77 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + class TournamentStage < ActiveRecord::Base belongs_to :tournament + validates_presence_of :tournament + + has_many :matches + + validates(:scheduling_method, + presence: true, + inclusion: {in: Tournament.new.scheduling_methods}) + + validates(:seeding_method, + presence: true, + inclusion: {in: Tournament.new.seeding_methods}) + + def owned_by?(user) + self.tournament.owned_by?(user) + end + + # A 1-indexed hash of matches + def matches_ordered + h = {} + i = 1 + self.matches.order(:id).each do |m| + h[i] = m + i += 1 + end + return h + end + + def create_matches + scheduling.create_matches + end + + def to_svg(highlight_user) + return scheduling.graph(highlight_user) + end + + def seed + return seeding.seed.pair(matches, players) + end + + # Accessors to the configured methods + + def scoring + @scoring ||= tournament.scoring + end + + def scheduling + @scheduling ||= "Scheduling::#{self.scheduling_method.camelcase}".constantize.new(self) + end + + def seeding + @seeding ||= "Seeding::#{self.seeding_method.camelcase}".constantize + end end diff --git a/app/models/user.rb b/app/models/user.rb index 4a57cf0..effe166 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,2 +1,234 @@ +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. + class User < ActiveRecord::Base + def owned_by?(tuser) + self == tuser + end + ################################################################## + # Relationships # + ################################################################## + has_and_belongs_to_many :tournaments_played, class_name: "Tournament", foreign_key: "player_id", join_table: "players_tournaments" + has_and_belongs_to_many :tournaments_hosted, class_name: "Tournament", foreign_key: "host_id", join_table: "hosts_tournaments" + has_and_belongs_to_many :teams + has_many :sessions + has_many :statistics + has_many :remote_usernames + + ################################################################## + # Attributes # + ################################################################## + + # name:string + validates(:name, presence: true, length: { maximum: 50 }) + + # email:string:uniq + before_save { self.email = email.downcase } + validates(:email, + presence: true, + # This regex is taken from http://www.w3.org/TR/html5/forms.html#e-mail-state-%28type=email%29 + format: { with: /\A[a-zA-Z0-9.!\#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\z/ }, + uniqueness: { case_sensitive: false }) + + # user_name:string_uniq + validates(:user_name, + presence: true, + length:{maximum: 50}, + format: {with: /\A[a-zA-Z0-9_-]+\z/}, + uniqueness: {case_sensitive: false }) + + # password_digest:string + has_secure_password validations: false # maps :password and :password_confirmation to :password_digest + validates(:password, + length: { minimum: 6 }, + confirmation: true, + unless: Proc.new { |u| u.password.try(:empty?) and not u.password_digest.try(:empty?) }) + + # permissions:integer + before_save { self.permissions ||= Server.first.default_user_permissions } + + ################################################################## + # XXX: hard-coded-ish. It makes me feel dirty. # + ################################################################## + apply_simple_captcha + acts_as_messageable + def mailboxer_email(object) + return nil + end + + ################################################################## + # remote_usernames # + ################################################################## + + def set_remote_username(game, data) + remote = self.remote_usernames.where(:game => game).first + if remote.nil? + self.remote_usernames.create(game: game, value: data) + else + remote.value = data + remote.save + end + end + + def get_remote_username(game) + obj = self.remote_usernames.where(:game => game).first + if obj.nil? + if game.parent.nil? + return nil + else + return get_remote_username(game.parent) + end + else + return obj.value + end + end + + ################################################################## + # Permissions # + ################################################################## + + def self.permission_bits + return { + :create_tournament => (2**1), + :edit_tournament => (2**2), + :join_tournament => (2**3), + :delete_tournament => (2**4), + + :create_game => (2**5), + :edit_game => (2**6), + :delete_game => (2**7), + + :create_user => (2**8), + :edit_user => (2**9), + :delete_user => (2**10), + + :create_alert => (2**11), + :edit_alert => (2**12), + :delete_alert => (2**13), + + :create_pm => (2**14), + :edit_pm => (2**15), + :delete_pm => (2**16), + + :create_session => (2**17), + :delete_session => (2**18), + + :edit_permissions => (2**19), + :edit_server => (2**20), + + :create_bracket => (2**21), + :edit_bracket => (2**22), + :delete_bracket => (2**23) + } + end + + def can?(action) + bit = User.permission_bits[action] + if bit.nil? + return false + else + return (self.permissions & bit != 0) + end + end + + def add_ability(action) + bit = User.permission_bits[action.to_sym] + unless bit.nil? + self.permissions |= bit + end + end + + def remove_ability(action) + bit = User.permission_bits[action.to_sym] + unless bit.nil? + self.permissions &= ~ bit + end + end + + # A representation of the permission bits as a mock-array. + def abilities + @abilities ||= Abilities.new(self) + end + def abilities=(new) + new.each do |k,v| + if v == "0" + v = false + end + abilities[k] = v + end + end + + # A thin array-like wrapper around the permission bits to make it + # easy to modify them using a form. + class Abilities + def initialize(user) +o @user = user + end + def [](ability) + return @user.can?(ability) + end + def []=(ability, val) + if val + @user.add_ability(ability) + else + @user.remove_ability(ability) + end + end + def keys + User.permission_bits.keys + end + def method_missing(name, *args) + if name.to_s.ends_with?('=') + self[name.to_s.sub(/=$/, '').to_sym] = args.first + else + return self[name.to_sym] + end + end + end + + ################################################################## + # Null-object pattern # + ################################################################## + + class NilUser + def nil? + return true + end + def can?(action) + case action + when :create_user + return true + when :create_session + return true + else + return false + end + end + def method_missing(name, *args) + # Throw an error if User doesn't have this method + super unless User.new.respond_to?(name) + # User has this method -- return a blank value + # 'false' if the method ends with '?'; 'nil' otherwise. + name.to_s.ends_with?('?') ? false : nil + end + end end diff --git a/app/views/alerts/_form.html.erb b/app/views/alerts/_form.html.erb index b60eaf2..e7a2444 100644 --- a/app/views/alerts/_form.html.erb +++ b/app/views/alerts/_form.html.erb @@ -10,11 +10,6 @@ </ul> </div> <% end %> - - <div class="field"> - <%= f.label :author_id %><br> - <%= f.text_field :author_id %> - </div> <div class="field"> <%= f.label :message %><br> <%= f.text_area :message %> diff --git a/app/views/alerts/index.html.erb b/app/views/alerts/index.html.erb index 458b951..5695486 100644 --- a/app/views/alerts/index.html.erb +++ b/app/views/alerts/index.html.erb @@ -12,14 +12,18 @@ </thead> <tbody> - <% @alerts.each do |alert| %> - <tr> - <td><%= alert.author %></td> - <td><%= alert.message %></td> - <td><%= link_to 'Show', alert %></td> - <td><%= link_to 'Edit', edit_alert_path(alert) %></td> - <td><%= link_to 'Destroy', alert, method: :delete, data: { confirm: 'Are you sure?' } %></td> - </tr> + <% if !@alerts.nil? %> + <% @alerts.each do |alert| %> + <tr> + <td><%= alert.author.user_name %></td> + <td><%= alert.message %></td> + <td><%= link_to 'Show', alert %></td> + <td><%= link_to 'Edit', edit_alert_path(alert) %></td> + <td><%= button_to 'Destroy', alert, method: :delete, data: { confirm: 'Are you sure?' } %></td> + </tr> + <% end %> + <% else %> + <td><p>There are no alerts!</p></td> <% end %> </tbody> </table> diff --git a/app/views/alerts/new.html.erb b/app/views/alerts/new.html.erb index 6d04589..db5af2d 100644 --- a/app/views/alerts/new.html.erb +++ b/app/views/alerts/new.html.erb @@ -2,4 +2,4 @@ <%= render 'form' %> -<%= link_to 'Back', alerts_path %> +<%= link_to 'See past Alerts', alerts_path %> diff --git a/app/views/alerts/show.html.erb b/app/views/alerts/show.html.erb index eeab7f7..398a10e 100644 --- a/app/views/alerts/show.html.erb +++ b/app/views/alerts/show.html.erb @@ -1,8 +1,6 @@ -<p id="notice"><%= notice %></p> - <p> <strong>Author:</strong> - <%= @alert.author %> + <%= @alert.author.user_name %> </p> <p> diff --git a/app/views/application/.keep b/app/views/application/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/views/application/.keep diff --git a/app/views/brackets/index.html.erb b/app/views/brackets/index.html.erb index 2195d69..9effe37 100644 --- a/app/views/brackets/index.html.erb +++ b/app/views/brackets/index.html.erb @@ -8,7 +8,6 @@ <th>Name</th> <th></th> <th></th> - <th></th> </tr> </thead> @@ -18,9 +17,8 @@ <td><%= bracket.user %></td> <td><%= bracket.tournament %></td> <td><%= bracket.name %></td> - <td><%= link_to 'Show', bracket %></td> - <td><%= link_to 'Edit', edit_bracket_path(bracket) %></td> - <td><%= link_to 'Destroy', bracket, method: :delete, data: { confirm: 'Are you sure?' } %></td> + <td><%= link_to 'Show', tournament_bracket_path(@tournament, bracket) %></td> + <td><%= link_to 'Edit', edit_tournament_bracket_path(@tournament, bracket) %></td> </tr> <% end %> </tbody> @@ -28,4 +26,3 @@ <br> -<%= link_to 'New Bracket', new_bracket_path %> diff --git a/app/views/brackets/new.html.erb b/app/views/brackets/new.html.erb index c379c15..91d0033 100644 --- a/app/views/brackets/new.html.erb +++ b/app/views/brackets/new.html.erb @@ -1,5 +1,3 @@ <h1>New bracket</h1> -<%= render 'form' %> - -<%= link_to 'Back', brackets_path %> +<%= link_to 'Back', tournament_brackets_path %> diff --git a/app/views/brackets/show.html.erb b/app/views/brackets/show.html.erb index 9c7c14b..fc722a6 100644 --- a/app/views/brackets/show.html.erb +++ b/app/views/brackets/show.html.erb @@ -1,19 +1,130 @@ -<p id="notice"><%= notice %></p> +<% +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. +%> +<h2><%= @bracket.name %></h2> -<p> - <strong>User:</strong> - <%= @bracket.user %> -</p> + <h4> Make your prediction for the tournament by clicking on the teams you think will win </h4> -<p> - <strong>Tournament:</strong> - <%= @bracket.tournament %> -</p> +<svg id="prediction-svg" version="1.1" baseProfile="full" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + width="100%" height=<%= "#{@height * 0.66}"%>> + <defs> + <radialGradient id="gradMatch" cx="50%" cy="50%" r="80%" fx="50%" fy="50%"> + <stop offset="0%" style="stop-color:#fff; stop-opacity:1" /> + <stop offset="100%" style="stop-color:#ccc;stop-opacity:0" /> + </radialGradient> + </defs> + <script type="text/ecmascript"><![CDATA[ + <%# + This method does two things: + 1) fill out hidden form with id of matchNum + 2) calculate where the next text is going, and place it there + %> + function chooseWinner(matchNum, teamNum, currentBox){ + console.log(matchNum, teamNum); + var id = '#bracket_matches_'+matchNum; + $(id).val(teamNum); -<p> - <strong>Name:</strong> - <%= @bracket.name %> -</p> + if (matchNum != 1) { + var parent = parseFloat(matchNum+<%= @logBase%> -2)/<%=@logBase%>; + var textBox = (parent - Math.floor(parent)) * <%= @logBase %>; + var parent = Math.floor(parent); + var textBox = Math.round(textBox); + var id = "#svg-match-"+parent+"-team-"+textBox; -<%= link_to 'Edit', edit_bracket_path(@bracket) %> | -<%= link_to 'Back', brackets_path %> + console.log(id); + + $(id).text("Team "+teamNum); + $(id).attr("onclick", "chooseWinner("+parent+", "+teamNum+", "+textBox+")"); + } + else + { + console.log("final countdown"); + for(var i = 0; i < 3; i++){ + id = "#svg-match-"+matchNum+"-team-"+i; + $(id).attr("fill", "black"); + } + id = "#svg-match-"+matchNum+"-team-"+currentBox; + $(id).attr("fill", "green"); + $("#bracket-submit").prop('disabled', false); + } + } + ]]> + </script> + + <% (1..@matches.count).each do |i| %> + <% matchDepth = Math.log(i*(@logBase-1), @logBase).floor+1 %> + <% if matchDepth > Math.log(@base*(@logBase-1), @logBase).floor+1 + @pBase = @base + @base = i + end %> + <g id="svg-match-<%= i %>"> + <rect height="<%= rh = 100 / (@logBase**(@depth-1)+1) - 100/@height %>%" + width="<%= rw = 100/(@depth+1) - 5 %>%" + x="<%= rx = 50/(@depth+1) + 100/(@depth+1)*(@depth-matchDepth) %>%" + y="<%= ry = 100/(@logBase**(matchDepth-1)+1) * (i-@base+1) - rh/2 %>%" + fill="url(#gradMatch)" + rx="5px" + stroke="black" + /> + + <% t = 1 + while t <= @numTeams %> + <rect width="<%= rw-5 %>%" height="<%= rh*Float(30)/(@matchHeight) %>%" x="<%= rx + 2.5 %>%" y="<%= ry + (Float(t-1)/@numTeams)*rh + 1 %>%" fill="white" /> + <text id="svg-match-<%= i %>-team-<%= t-1 %>" x="<%= rx + rw/4 %>%" y="<%= ry + (Float(t-1)/@numTeams + Float(33)/(@matchHeight))*rh %>%" font-size="150%" + <% if @matches[i].teams[t-1] && !@results %> + onclick="chooseWinner(<%= @matches[i].id%>, <%= @matches[i].teams[t-1].id %>)" + <% end %> + > + <% if @matches[i].teams[t-1] %> + Team <%= @matches[i].teams[t-1].id %> + <% end %> + </text> + <% if (t < @numTeams) %> + <text x="<%= rx + 1.3*rw/3 %>%" y="<%= ry + (Float(t)/@numTeams)*rh + 1%>%" font-size="150%"> VS </text> + <% end %> + <% t = t + 1 %> + <% end %> + + <% if i > 1 %> + <% parent = (i+@logBase-2)/@logBase + pDepth = Math.log(parent*(@logBase-1), @logBase).floor+1 + lastrx = 50/(@depth+1) + 100/(@depth+1)*(@depth-pDepth) + lastry = 100/(@logBase**(pDepth-1)+1) * (parent-@pBase+1) - rh/2 %> + <line x1="<%= rx+rw %>%" y1="<%= ry+rh/2 %>%" x2="<%= lastrx%>%" y2="<%= lastry+rh/2%>%" stroke="white" stroke-width="2" > + <% end %> + </g> + + <% end %> +</SVG> + + <%= form_tag(tournament_bracket_path(@tournament, @bracket), method: 'put') do %> + <input type="hidden" name="update_action" value="predict"> + <% for i in 1..@matches.length %> + <%= hidden_field_tag("bracket[matches][#{@matches[i].id.to_s}]", value = nil) %> + <% end %> + <%= submit_tag("Submit Prediction", disabled: true, id: "bracket-submit") %> + <% end %> + +<%= link_to 'Back', tournaments_path %> diff --git a/app/views/common/_error_messages.html.erb b/app/views/common/_error_messages.html.erb new file mode 100644 index 0000000..fdeaf65 --- /dev/null +++ b/app/views/common/_error_messages.html.erb @@ -0,0 +1,11 @@ +<%# http://railscasts.com/episodes/211-validations-in-rails-3 %> +<% if target.errors.any? %> +<div id="error_explanation"> + <h2><%= pluralize(target.errors.count, "error") %> prohibited this form from being submitted:</h2> + <ul> + <% target.errors.full_messages.each do |msg| %> + <li><%= msg %></li> + <% end %> + </ul> +</div> +<% end %> diff --git a/app/views/common/_show_tournament.html.erb b/app/views/common/_show_tournament.html.erb new file mode 100644 index 0000000..3d4b066 --- /dev/null +++ b/app/views/common/_show_tournament.html.erb @@ -0,0 +1,70 @@ +<% +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. +%> +<div class="row tournament-listing"> + <div class="col-md-2 col-sm-3 col-xs-6"> + <%= image_tag(target.game.name.parameterize.underscore + ".png", class: "t-image") %> + <p class="t-game"><%= Game.find(target.game_id).name %></p> + </div> + <div class="col-md-8 col-sm-7 col-xs-6"> + <%# "header" %> + <%= link_to(target) do %><h3><%= target.name %></h3><% end %> + <div class="row"> + <div class="col-md-4 host"> + <%= image_tag('http://www.gravatar.com/avatar/' + Digest::MD5.hexdigest(target.hosts.first.email) + '?s=45&d=identicon') %> + <%= target.hosts.first.name %>'s tournament + </div> + <div class="col-md-4 things"> + <p>Players per team: <%= target.min_players_per_team %></p> + <p>Players signed up: <%= target.players.count %></p> + </div> + <div class="col-md-4 things"> + <p><%# (target.randomized_teams)? "Teams are Random" : "Teams are Chosen" %></p> + <p>Players signed up: <%= target.players.count %></p> + </div> + </div> + </div> + <div class="col-md-2 col-sm-2 col-xs-2"> + <% if signed_in? %> + <% if !target.players.include?(current_user) && target.status == 0 %> + <%= form_tag(tournament_path(target), method: "put", class: :button_to) do %> + <input type="hidden" name="update_action" value="join"> + <%= submit_tag("Join")%> + <% end %> + <% elsif target.players.include?(current_user)%> + <p class="message">You've signed up for this tournament!</p> + <% end %> + <% @user_bracket = target.brackets.find_by(user: current_user) %> + <% if target.status == 1 && target.stages.order(:id).first.scheduling_method == "elimination" && target.stages.order(:id).first.matches.order(:id).first.status < 2 && !@user_bracket %> + <%= form_tag(tournament_brackets_path(target), method: "post", class: :button_to) do %> + <%= submit_tag("Make Bracket") %> + <% end %> + <% elsif @user_bracket && target.status == 4 %> + <%= form_tag(tournament_bracket_path(@tournament, @bracket), method: 'put', class: :button_to) do %> + <input type="hidden" name="update_action" value="results"> + <%= submit_tag("Bracket Results") %> + <% end %> + <% end %> + <% end %> + </div> +</div> diff --git a/app/views/common/_show_user.html.erb b/app/views/common/_show_user.html.erb new file mode 100644 index 0000000..46a7a77 --- /dev/null +++ b/app/views/common/_show_user.html.erb @@ -0,0 +1,47 @@ +<% +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. +%> +<div class="row user-listing"> + <div class="col-md-3 col-sm-4 col-xs-4"><%= image_tag ('http://www.gravatar.com/avatar/' + Digest::MD5.hexdigest(target.email) + '?s=100&d=mm') %></div> + + + <div class="col-md-9 col-sm-8 col-xs-8"> + <%# "header" %> + <%= link_to(target) do %><h3><%= target.user_name %></h3><% end %> + + <div class="row"> + <div class="col-md-6 things"> + <p> Preferred Name: </p> + <p> <%= target.name %></p> + </div> + <div class="col-md-6 things"> + <p>Latest Tournament: + <% if !target.tournaments_played.first.nil? %> + <%= target.tournaments_played.first.name %> + <% end %> + </p> + </div> + </div> + + </div> +</div> diff --git a/app/views/games/index.html.erb b/app/views/games/index.html.erb index 71e59a0..5a1a270 100644 --- a/app/views/games/index.html.erb +++ b/app/views/games/index.html.erb @@ -1,6 +1,6 @@ <h1>Listing games</h1> -<table> +<table class="table table-hover"> <thead> <tr> <th>Parent</th> @@ -28,7 +28,7 @@ <td><%= game.scoring_method %></td> <td><%= link_to 'Show', game %></td> <td><%= link_to 'Edit', edit_game_path(game) %></td> - <td><%= link_to 'Destroy', game, method: :delete, data: { confirm: 'Are you sure?' } %></td> + <td><%= button_to 'Destroy', game, method: :delete, data: { confirm: 'Are you sure?' } %></td> </tr> <% end %> </tbody> @@ -36,4 +36,6 @@ <br> -<%= link_to 'New Game', new_game_path %> + +<%= link_to 'New Game', new_game_path, {:class => "btn btn-warning"} %> + diff --git a/app/views/games/show.html.erb b/app/views/games/show.html.erb index 28da040..6184784 100644 --- a/app/views/games/show.html.erb +++ b/app/views/games/show.html.erb @@ -1,5 +1,3 @@ -<p id="notice"><%= notice %></p> - <p> <strong>Parent:</strong> <%= @game.parent %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index cefd1be..ae8b679 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,14 +1,95 @@ -<!DOCTYPE html> -<html> +<% +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. +%><!DOCTYPE html> +<html lang="en"> <head> - <title>Leaguer</title> - <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> - <%= javascript_include_tag "application", "data-turbolinks-track" => true %> - <%= csrf_meta_tags %> + <title>Leaguer</title> + + <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> + + <%= javascript_include_tag "application", "data-turbolinks-track" => true %> + <%= javascript_include_tag "#{params[:controller]}", "data-turbolinks-track" => true %> + <%= javascript_include_tag "#{params[:controller]}/#{params[:action]}", "data-turbolinks-track" => true %> + + <%= csrf_meta_tags %> + <%= yield :head %> </head> <body> +<header> + <nav> + <div class="container-fluid"> + <div class="navbar-header"> + <%= link_to('Leaguer', root_path, class: "navbar-brand") %> + </div> + <div class="navbar-collapse"> + <div id="user-actions"> + <span> + <% if signed_in? %> + <%= link_to current_user.user_name, current_user, :class => "user", :role => :button %> + <%= link_to "Sign out", session_path("current"), method: "delete", :class => "signout", :role => :button %> + <% else %> + <%= link_to "Log in", new_session_path, :class => "signin", :role => :button %> + <%= link_to "Sign up", new_user_path, :class => "signup", :role => :button %> + <% end %> + </span> + <% if current_user.can? :create_alert %> + <span><%= link_to "Create Alert", new_alert_path, :class => "create-alert", :role => :button %></span> + <% end %> + </div> + <% if signed_in? %> + <ul> + <li><%= link_to "Tournaments", tournaments_path %></li> + <li><%= link_to "Messages", pms_path %></li> + <% if current_user.can? :edit_server %> + <li><%= link_to "Server settings", edit_server_path, :class => "server" %></li> + <% end %> + </ul> + <%# If there is an unread alert then I want to be able + to show the notification icon by saying :style => + display:inline. This will be Done by Guntas once + he figures out how to get unread alerts. Psuedo if + alerts.unread > 0 then display else don't.%> + <%= link_to "", alerts_path, :class => "alerts", :id => "alerts-ajax"%> + <% end %> + <%= form_tag("/search", method: :get, :id => "search") do %><div> + <%= text_field_tag(:query, params[:query], type: :search) %> + <%= submit_tag "Search" %> + </div><% end %> + </div> + </div> + </nav> +</header> + +<% if notice %><div id="notice"><p><%= notice %></p></div><% end %> + +<div class="container"> + <%= yield %> +</div> -<%= yield %> +<footer> + <p>Leaguer © 2014, Tomer Kimia, Andrew Murrell, Luke Shumaker, Nathaniel Foy, Davis Webb, and Guntas Grewal</p> + <%= debug(params) if Rails.env.development? %> +</footer> </body> </html> diff --git a/app/views/main/homepage.html.erb b/app/views/main/homepage.html.erb new file mode 100644 index 0000000..81a991d --- /dev/null +++ b/app/views/main/homepage.html.erb @@ -0,0 +1,36 @@ +<% +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. +%> +<div class="jumbotron"> + <h1>Welcome to Leaguer</h1> + <p>This is a tournment management system designed to be used for any team sport. Our peer review system ensures that the best players move on to the next round! Try creating a new tournament and having people sign up for it. </p> + <p id="jumbo-buttons"> + <% if !signed_in? %> + <%= link_to 'Log In', new_session_path, :class => "signin", :role => "button" %> + <%= link_to 'Sign Up', new_user_path, :class => "signup", :role => "button" %> + <% else %> + <%= link_to 'Start a Tournament', new_tournament_path, :role => "button" %> + <% end %> + <%= link_to 'See Ongoing Tournaments', tournaments_path, :role => "button" %> + </p> +</div> diff --git a/app/views/matches/_form.html.erb b/app/views/matches/_form.html.erb index 768b655..a045e98 100644 --- a/app/views/matches/_form.html.erb +++ b/app/views/matches/_form.html.erb @@ -1,16 +1,5 @@ -<%= form_for(@match) do |f| %> - <% if @match.errors.any? %> - <div id="error_explanation"> - <h2><%= pluralize(@match.errors.count, "error") %> prohibited this match from being saved:</h2> - - <ul> - <% @match.errors.full_messages.each do |msg| %> - <li><%= msg %></li> - <% end %> - </ul> - </div> - <% end %> - +<%= form_for([@tournament, @tournament.matches.build]) do |f| %> + <div class="field"> <%= f.label :status %><br> <%= f.number_field :status %> diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb index 85c94f2..eb827f3 100644 --- a/app/views/matches/index.html.erb +++ b/app/views/matches/index.html.erb @@ -1,31 +1,62 @@ -<h1>Listing matches</h1> +<% +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. +%> +<h1><%= @tournament.name %> - Matches</h1> -<table> - <thead> - <tr> - <th>Status</th> - <th>Tournament stage</th> - <th>Winner</th> - <th></th> - <th></th> - <th></th> - </tr> - </thead> - - <tbody> - <% @matches.each do |match| %> - <tr> - <td><%= match.status %></td> - <td><%= match.tournament_stage %></td> - <td><%= match.winner %></td> - <td><%= link_to 'Show', match %></td> - <td><%= link_to 'Edit', edit_match_path(match) %></td> - <td><%= link_to 'Destroy', match, method: :delete, data: { confirm: 'Are you sure?' } %></td> - </tr> - <% end %> - </tbody> +<table id="matches-table" class="table"> + <thead> + <tr> + <th>Name</th> + <th>Status</th> + <th>Winner</th> + <th><!-- link to --></th> + <th><!-- start button --></th> + </tr> + </thead> + <tbody> + <% @tournament.stages.order(:id).each do |stage| %> + <% stage.matches_ordered.keys.sort.reverse.each do |match_key| %><tr> + <% match = stage.matches_ordered[match_key] %> + <td><%= "Match #{match.id}" %></td> + <td><%= match.status %></td> + <td><%= (match.winner.nil? ? "-" : "Team #{match.winner.id}") %></td> + <td><%= link_to "See Match", tournament_match_path(@tournament, match) %> + <td> + <% if match.check_permission(current_user, :edit) %> + <%= form_tag(tournament_match_path(@tournament, match), method: "put") do %> + <input type="hidden" name="update_action" value="start"> + <% @startable = (match.status == 1) and (match.teams.count >= @tournament.min_teams_per_match) %> + <%= submit_tag("Start Match", :disabled => ! @startable) %> + <% end %> + <% end %> + </td> + </tr><% end %> + <% end %> + </tbody> </table> <br> -<%= link_to 'New Match', new_match_path %> +<% @tournament.stages.order(:id).each do |stage| %> + <div class="graph"><%= raw stage.to_svg(current_user) %></div> +<% end %> diff --git a/app/views/matches/new.html.erb b/app/views/matches/new.html.erb index bd4c78c..74e7e3a 100644 --- a/app/views/matches/new.html.erb +++ b/app/views/matches/new.html.erb @@ -1,5 +1,3 @@ <h1>New match</h1> <%= render 'form' %> - -<%= link_to 'Back', matches_path %> diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb index b47a045..5ee4ecb 100644 --- a/app/views/matches/show.html.erb +++ b/app/views/matches/show.html.erb @@ -1,19 +1,108 @@ -<p id="notice"><%= notice %></p> - +<% +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. +%> <p> - <strong>Status:</strong> - <%= @match.status %> + <strong>Status:</strong> + <%= @match.status %> </p> - <p> - <strong>Tournament stage:</strong> - <%= @match.tournament_stage %> + <strong>Tournament stage:</strong> + <%= @tournament.stages.order(:id).index(@match.tournament_stage)+1 %> </p> -<p> - <strong>Winner:</strong> - <%= @match.winner %> -</p> +<%# + Match Status 0 => Created, waiting to be scheduled + Match Status 1 => Scheduled, waiting to start + Match Status 2 => Started, waiting to finish + Match Status 3 => Finished + + Four views:- (status is Match status) + A. Pairings, when status is 1 for either Host or Player Or when status is 2 for player + B. A page the host will see if status is 2 OR 3 + C. The Peer review page that the players will see if status is 3. + D. The page everyone will see when status is 4. + + Note: The change of status from 2 to 3 for League of Legends is coming from League Data Pull (RIOT API) +%> + +<div> + <h2>Teams/users</h2> + <ul> + <% if @match.status == 3 + scores = @match.tournament_stage.scoring.score(@match) + end + %> + <% @match.teams.each do |team| %> + <li>Team <%= team.id %><ul> + <% team.users.each do |user| %> + <% if @match.status < 3 %> + <li><%= user.user_name %></li> + <% else %> + <% stats = Statistic.where(user: user, match: @match) %> + <li><%= user.user_name %> - Score: <%= scores[user] %><ul> + <% stats.all.reject{|s|s.name=="score"}.each do |stat| %> + <li><%= stat.name %>: <%= stat.value %></li> + <% end %> + </ul></li> + <% end %> + <% end %> + </ul></li> + <% end %> + </ul> +</div> + +<% unless @match.winner.nil? %> + <p> + <strong>Winner:</strong> + <%= @match.winner.users.collect{|u| u.user_name}.join(", ") %> + </p> +<% end %> -<%= link_to 'Edit', edit_match_path(@match) %> | -<%= link_to 'Back', matches_path %> +<div id="action"> + <%= form_tag(tournament_match_path(@tournament, @match), method: "put") do %> + <% case @match.status %> + <% when 0 %> + <!-- Created, waiting to be scheduled --> + <p>This match has not yet been scheduled.</p> + <% when 1 %> + <!-- Scheduled, waiting to start --> + <% if @tournament.hosts.include? current_user %> + <input type="hidden" name="update_action" value="start"> + <%= submit_tag("Start Match") %> + <% else %> + <p>Match is waiting to start.</p> + <% end %> + <% when 2 %> + <!-- Started, waiting to finish --> + <%= @match.render_sampling(current_user) %> + <% when 3 %> + <!-- Finished --> + <p>This match is finished.</p> + <% if @tournament.hosts.include? current_user %> + <input type="hidden" name="update_action" value="reset"> + <%= submit_tag("Reset Status") %> + <% end %> + <% end %> + <% end %> + <%= link_to "Back to Tournament", @match.tournament_stage.tournament %> +</div> diff --git a/app/views/pms/_form.html.erb b/app/views/pms/_form.html.erb index 80781a5..b329e24 100644 --- a/app/views/pms/_form.html.erb +++ b/app/views/pms/_form.html.erb @@ -12,24 +12,16 @@ <% end %> <div class="field"> - <%= f.label :author_id %><br> - <%= f.text_field :author_id %> - </div> - <div class="field"> <%= f.label :recipient_id %><br> <%= f.text_field :recipient_id %> </div> - <div class="field"> - <%= f.label :message %><br> - <%= f.text_area :message %> - </div> - <div class="field"> + <div class="field"> <%= f.label :subject %><br> - <%= f.text_area :subject %> + <%= f.text_field :subject %> </div> <div class="field"> - <%= f.label :conversation_id %><br> - <%= f.text_field :conversation_id %> + <%= f.label :message %><br> + <%= f.text_area :message %> </div> <div class="actions"> <%= f.submit %> diff --git a/app/views/pms/index.html.erb b/app/views/pms/index.html.erb index b5169f5..159b3f9 100644 --- a/app/views/pms/index.html.erb +++ b/app/views/pms/index.html.erb @@ -1,35 +1,160 @@ -<h1>Listing pms</h1> +<% +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. +%> +<h1> Your Conversations </h1> + +<%= link_to 'Start a new conversation', new_pm_path %> +<br> + +<h3>Unread Conversations</h3> +<% conversations = current_user.mailbox.conversations %> <table> - <thead> - <tr> - <th>Author</th> - <th>Recipient</th> - <th>Message</th> - <th>Subject</th> - <th>Conversation</th> - <th></th> - <th></th> - <th></th> - </tr> - </thead> + <col width="150"> + <col width="250"> + <col width="300"> + <tbody> + <%# if conversations.reject { |c| c.is_unread?(current_user) && (c.receipts_for current_user).last.message.sender != current_user }.empty? %> + <tr> + <tr> + <td><b>With</b></td> + <td><b>Subject</b></td> + <td><b>Body</b></td> + </tr> + <% conversations.each do |conversation| %> + <% receipts = conversation.receipts_for current_user %> + <% if conversation.is_unread?(current_user) && receipts.last.message.sender != current_user %> + <% message = receipts.last.message %> + <tr> + <% if conversation.subject == "Pay Attention!" %> + <% conversation.mark_as_read(current_user) %> + <% end %> + <td> + <% people = conversation.participants %> + <% people.each do |person| %> + <% unless person == current_user %> + <%= truncate(person.user_name, length: 20) %> + <% end %> + <% end %> + </td> + <td><%= truncate(conversation.subject, length: 30) %></td> + <td><%= truncate(message.body, length: 42) %></td> + <td><%= link_to 'View', @pms.find_by(conversation: conversation) %></td> + </tr> + <% end %> + <% end %> + </tr> + <%# else %> + + <%# end %> + </tbody> +</table> +<br> +<h3>Read Conversations</h3> +<% conversations = current_user.mailbox.conversations %> + +<table> + <col width="150"> + <col width="250"> + <col width="300"> <tbody> - <% @pms.each do |pm| %> + <%# if conversations.reject { |c| c.is_read?(current_user) || (c.receipts_for current_user).last.message.sender == current_user }.empty? %> <tr> - <td><%= pm.author %></td> - <td><%= pm.recipient %></td> - <td><%= pm.message %></td> - <td><%= pm.subject %></td> - <td><%= pm.conversation %></td> - <td><%= link_to 'Show', pm %></td> - <td><%= link_to 'Edit', edit_pm_path(pm) %></td> - <td><%= link_to 'Destroy', pm, method: :delete, data: { confirm: 'Are you sure?' } %></td> + <tr> + <td><b>With</b></td> + <td><b>Subject</b></td> + <td><b>Body</b></td> + </tr> + <% conversations.each do |conversation| %> + <% receipts = conversation.receipts_for current_user %> + <% if conversation.is_read?(current_user) || receipts.last.message.sender == current_user %> + <% message = receipts.last.message %> + <tr> + <% if conversation.subject != "Pay Attention!" %> + <td> + <% people = conversation.participants %> + <% people.each do |person| %> + <% unless person == current_user %> + <%= truncate(person.user_name, length: 20) %> + <% end %> + <% end %> + </td> + <td><%= truncate(conversation.subject, length: 30) %></td> + <td><%= truncate(message.body, length: 42) %></td> + <td><%= link_to 'View', @pms.find_by(conversation: conversation) %></td> + <% end %> + </tr> + <% end %> + <% end %> </tr> - <% end %> + <% #else %> + + <% #end %> </tbody> </table> <br> +<h3>Alerts</h3> +<% conversations = current_user.mailbox.conversations %> -<%= link_to 'New Pm', new_pm_path %> +<table> + <col width="150"> + <col width="650"> + <tbody> + <%# if conversations.reject { |c| c.is_read?(current_user) || (c.receipts_for current_user).last.message.sender == current_user }.empty? %> + <tr> + <tr> + <td><b>With</b></td> + <td><b>Body</b></td> + </tr> + <% conversations.each do |conversation| %> + <% receipts = conversation.receipts_for current_user %> + <% if conversation.is_read?(current_user) || receipts.last.message.sender == current_user %> + <% message = receipts.last.message %> + <tr> + <% if conversation.subject == "Pay Attention!" && message.sender != current_user %> + <td> + <% people = conversation.participants %> + <% people.each do |person| %> + <% unless person == current_user %> + <%= truncate(person.user_name, length: 20) %> + <% end %> + <% end %> + </td> + <td><%= truncate(message.body, length: 80) %></td> + <td><%= link_to 'View', @pms.find_by(conversation: conversation) %></td> + <% end %> + </tr> + <% end %> + <% end %> + </tr> + <% #else %> + + <% #end %> + </tbody> +</table> + +<br> +<br> +<br> diff --git a/app/views/pms/show.html.erb b/app/views/pms/show.html.erb index 2f3b944..5ef0b41 100644 --- a/app/views/pms/show.html.erb +++ b/app/views/pms/show.html.erb @@ -1,29 +1,69 @@ -<p id="notice"><%= notice %></p> +<% +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. +%> +<%= link_to '« Back to all private messages', pms_path, class: :breadcrumb %> -<p> - <strong>Author:</strong> - <%= @pm.author %> -</p> +<div> + <p> + <strong>Participants:</strong> + <% receps = @pm.conversation.participants %> + <% receps.each do |recep| %> + <% #unless recep == @pm.conversation.last_sender %> + <%= recep.user_name %>, + <% #end %> + <% end %> + <%= "and the NSA" %> + </p> -<p> - <strong>Recipient:</strong> - <%= @pm.recipient %> -</p> + <p> + <strong>Subject:</strong> + <%= @pm.conversation.subject %> + </p> +</div> -<p> - <strong>Message:</strong> - <%= @pm.message %> -</p> +<% receipts = @pm.conversation.receipts_for current_user %> +<% receipts.each do |receipt| %> + <% message = receipt.message %> + <hr> + <p> + <strong><%= message.sender.user_name %>:</strong> + <%= message.body %> + </p> +<% end %> -<p> - <strong>Subject:</strong> - <%= @pm.subject %> -</p> +<hr> -<p> - <strong>Conversation:</strong> - <%= @pm.conversation %> -</p> +<div> + <% @pm.message = "" %> + <%= form_for(@pm) do |f| %> + <div class="field"> + <%= f.text_area :message %> + </div> -<%= link_to 'Edit', edit_pm_path(@pm) %> | -<%= link_to 'Back', pms_path %> + <div class="actions"> + <%= submit_tag("Reply", :class => "signup") %> + </div> + <% end %> +</div> + +<% @pm.conversation.mark_as_read(current_user) %> diff --git a/app/views/search/go.html.erb b/app/views/search/go.html.erb new file mode 100644 index 0000000..4784ba9 --- /dev/null +++ b/app/views/search/go.html.erb @@ -0,0 +1,68 @@ +<% +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. +%> +<div id="advanced_search" class="collapsible"> + <div class="collapsed"> + <h5><a href="#advanced_search">Advanced Search [show]</a></h5> + </div> + <div class="expanded"> + <h5><a href="#collapse">Advanced Search [hide]</a></h5> + <%= form_tag("/search", method: "get") do %> + <div class="form-group"> + <%= label_tag :query, 'Find:' %> + <%= text_field_tag(:query, params[:query]) %> + </div> + <div class="form-group"> + <%= label_tag :game_type, 'Game Type:' %> + <%= select_tag(:game_type, options_from_collection_for_select(@games, 'id', 'name'), :prompt => 'All Games') %> + </div> + <div> + <%= submit_tag("Search", :name=>nil) %> + </div> + <% end %> + </div> +</div> + +<%# Show search results if a query was not nill %> +<% if !@query.nil? and !@query.empty? %> + + <% if @tournaments.empty? and @players.empty? %> + <h3> No results found for "<%= @query %>" </h3> + <% else %> + <h3> Showing results for: <span><%= @query %></span></h3> + <% if @tournaments.length > 0 %> + <h4> Tournaments </h4> + <% end %> + <% @tournaments.each do |t| %> + <%= render "common/show_tournament", :target => t %> + <% end %> + + <% if @players.length > 0 %> + <h4> Players </h4> + <% end %> + <% @players.each do |p| %> + <%= render "common/show_user", :target => p %> + <% end %> + + <% end %> +<% end %> diff --git a/app/views/servers/_form.html.erb b/app/views/servers/_form.html.erb index 6211f9a..0cdaf15 100644 --- a/app/views/servers/_form.html.erb +++ b/app/views/servers/_form.html.erb @@ -1,21 +1,39 @@ +<% +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. +%> <%= form_for(@server) do |f| %> - <% if @server.errors.any? %> - <div id="error_explanation"> - <h2><%= pluralize(@server.errors.count, "error") %> prohibited this server from being saved:</h2> + <%= render "common/error_messages", :target => @server %> - <ul> - <% @server.errors.full_messages.each do |msg| %> - <li><%= msg %></li> - <% end %> - </ul> - </div> - <% end %> + <%= fields_for "server[default_user_abilities]", @server.default_user_abilities do |a| %> + <fieldset> + <legend>Default permissions for new users</legend> + <ul> + <% @server.default_user_abilities.keys.each do |ability| %> + <li><%= a.check_box(ability) %> <%= a.label(ability) %></li> + <% end %> + </ul> + </fieldset> + <% end %> - <div class="field"> - <%= f.label :default_user_permissions %><br> - <%= f.number_field :default_user_permissions %> - </div> - <div class="actions"> - <%= f.submit %> - </div> + <%= f.submit %> <% end %> diff --git a/app/views/servers/edit.html.erb b/app/views/servers/edit.html.erb index a92cdb5..f29a65c 100644 --- a/app/views/servers/edit.html.erb +++ b/app/views/servers/edit.html.erb @@ -1,6 +1,3 @@ <h1>Editing server</h1> <%= render 'form' %> - -<%= link_to 'Show', @server %> | -<%= link_to 'Back', servers_path %> diff --git a/app/views/servers/index.html.erb b/app/views/servers/index.html.erb deleted file mode 100644 index b3064f4..0000000 --- a/app/views/servers/index.html.erb +++ /dev/null @@ -1,27 +0,0 @@ -<h1>Listing servers</h1> - -<table> - <thead> - <tr> - <th>Default user permissions</th> - <th></th> - <th></th> - <th></th> - </tr> - </thead> - - <tbody> - <% @servers.each do |server| %> - <tr> - <td><%= server.default_user_permissions %></td> - <td><%= link_to 'Show', server %></td> - <td><%= link_to 'Edit', edit_server_path(server) %></td> - <td><%= link_to 'Destroy', server, method: :delete, data: { confirm: 'Are you sure?' } %></td> - </tr> - <% end %> - </tbody> -</table> - -<br> - -<%= link_to 'New Server', new_server_path %> diff --git a/app/views/servers/index.json.jbuilder b/app/views/servers/index.json.jbuilder deleted file mode 100644 index 3c9df60..0000000 --- a/app/views/servers/index.json.jbuilder +++ /dev/null @@ -1,4 +0,0 @@ -json.array!(@servers) do |server| - json.extract! server, :id, :default_user_permissions - json.url server_url(server, format: :json) -end diff --git a/app/views/servers/new.html.erb b/app/views/servers/new.html.erb deleted file mode 100644 index 0422009..0000000 --- a/app/views/servers/new.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -<h1>New server</h1> - -<%= render 'form' %> - -<%= link_to 'Back', servers_path %> diff --git a/app/views/servers/show.html.erb b/app/views/servers/show.html.erb index b18f09f..54aaf66 100644 --- a/app/views/servers/show.html.erb +++ b/app/views/servers/show.html.erb @@ -1,9 +1,6 @@ -<p id="notice"><%= notice %></p> - <p> <strong>Default user permissions:</strong> <%= @server.default_user_permissions %> </p> -<%= link_to 'Edit', edit_server_path(@server) %> | -<%= link_to 'Back', servers_path %> +<%= link_to 'Edit', edit_server_path %> diff --git a/app/views/sessions/_form.html.erb b/app/views/sessions/_form.html.erb deleted file mode 100644 index 90ad0ad..0000000 --- a/app/views/sessions/_form.html.erb +++ /dev/null @@ -1,25 +0,0 @@ -<%= form_for(@session) do |f| %> - <% if @session.errors.any? %> - <div id="error_explanation"> - <h2><%= pluralize(@session.errors.count, "error") %> prohibited this session from being saved:</h2> - - <ul> - <% @session.errors.full_messages.each do |msg| %> - <li><%= msg %></li> - <% end %> - </ul> - </div> - <% end %> - - <div class="field"> - <%= f.label :user_id %><br> - <%= f.text_field :user_id %> - </div> - <div class="field"> - <%= f.label :token %><br> - <%= f.text_field :token %> - </div> - <div class="actions"> - <%= f.submit %> - </div> -<% end %> diff --git a/app/views/sessions/edit.html.erb b/app/views/sessions/edit.html.erb deleted file mode 100644 index bbd8407..0000000 --- a/app/views/sessions/edit.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -<h1>Editing session</h1> - -<%= render 'form' %> - -<%= link_to 'Show', @session %> | -<%= link_to 'Back', sessions_path %> diff --git a/app/views/sessions/index.html.erb b/app/views/sessions/index.html.erb deleted file mode 100644 index 43a7e1f..0000000 --- a/app/views/sessions/index.html.erb +++ /dev/null @@ -1,29 +0,0 @@ -<h1>Listing sessions</h1> - -<table> - <thead> - <tr> - <th>User</th> - <th>Token</th> - <th></th> - <th></th> - <th></th> - </tr> - </thead> - - <tbody> - <% @sessions.each do |session| %> - <tr> - <td><%= session.user %></td> - <td><%= session.token %></td> - <td><%= link_to 'Show', session %></td> - <td><%= link_to 'Edit', edit_session_path(session) %></td> - <td><%= link_to 'Destroy', session, method: :delete, data: { confirm: 'Are you sure?' } %></td> - </tr> - <% end %> - </tbody> -</table> - -<br> - -<%= link_to 'New Session', new_session_path %> diff --git a/app/views/sessions/index.json.jbuilder b/app/views/sessions/index.json.jbuilder deleted file mode 100644 index 5205ede..0000000 --- a/app/views/sessions/index.json.jbuilder +++ /dev/null @@ -1,4 +0,0 @@ -json.array!(@sessions) do |session| - json.extract! session, :id, :user_id, :token - json.url session_url(session, format: :json) -end diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb index 55c9eca..ba125e5 100644 --- a/app/views/sessions/new.html.erb +++ b/app/views/sessions/new.html.erb @@ -1,5 +1,49 @@ -<h1>New session</h1> +<% +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. +%> +<h1>Sign in</h1> -<%= render 'form' %> +<div> + <%= form_tag(sessions_path, method: :post, id: :new_session) do %> + <% if params[:action] == "create" %> + <div class="alert-danger"> + <p>The username/password pair you entered did + not match our records. Check your typing and + try again.</p> + </div> + <% end %> + <div class="field"> + <%= label_tag(:username_or_email, "Username/Email") %><br/> + <%= text_field_tag(:username_or_email) %> + </div> + <div class="field"> + <%= label_tag(:password) %><br/> + <%= password_field_tag(:password) %> + </div> + <div class="field"> + <%= submit_tag("Log in", class: :signin) %> + </div> + <% end %> -<%= link_to 'Back', sessions_path %> + <p>New user? <%= link_to("Sign up now!", new_user_path) %></p> +</div> diff --git a/app/views/sessions/show.html.erb b/app/views/sessions/show.html.erb deleted file mode 100644 index 230e6bd..0000000 --- a/app/views/sessions/show.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -<p id="notice"><%= notice %></p> - -<p> - <strong>User:</strong> - <%= @session.user %> -</p> - -<p> - <strong>Token:</strong> - <%= @session.token %> -</p> - -<%= link_to 'Edit', edit_session_path(@session) %> | -<%= link_to 'Back', sessions_path %> diff --git a/app/views/sessions/show.json.jbuilder b/app/views/sessions/show.json.jbuilder deleted file mode 100644 index c9efd3b..0000000 --- a/app/views/sessions/show.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.extract! @session, :id, :user_id, :token, :created_at, :updated_at diff --git a/app/views/simple_captcha/_simple_captcha.erb b/app/views/simple_captcha/_simple_captcha.erb index 9968910..5e9da76 100644 --- a/app/views/simple_captcha/_simple_captcha.erb +++ b/app/views/simple_captcha/_simple_captcha.erb @@ -1,37 +1,6 @@ -<style type="text/CSS"> - .simple_captcha{border: 1px solid #ccc; padding: 5px !important;} - .simple_captcha, - .simple_captcha div{display: table;} - .simple_captcha .simple_captcha_field, - .simple_captcha .simple_captcha_image{ - border: 1px solid #ccc; - margin: 0px 0px 2px 0px !important; - padding: 0px !important; - } - .simple_captcha .simple_captcha_image img{ - margin: 0px !important; - padding: 0px !important; - width: 110px !important; - } - .simple_captcha .simple_captcha_label{font-size: 12px;} - .simple_captcha .simple_captcha_field input{ - width: 150px !important; - font-size: 16px; - border: none; - background-color: #efefef; - } -</style> - -<div class='simple_captcha'> - <div class='simple_captcha_image'> - <%= simple_captcha_options[:image] %> - </div> - - <div class='simple_captcha_field'> - <%= simple_captcha_options[:field] %> - </div> - - <div class='simple_captcha_label'> - <%= simple_captcha_options[:label] %> - </div> +<div class="field simple_captcha"> + <label for="captcha"><%= simple_captcha_options[:label] %></label> + <%= simple_captcha_options[:image] %> + <span class="help-block">To make sure you aren't a robot.</span> + <%= simple_captcha_options[:field] %> </div> diff --git a/app/views/teams/index.html.erb b/app/views/teams/index.html.erb index b077e10..397bfc6 100644 --- a/app/views/teams/index.html.erb +++ b/app/views/teams/index.html.erb @@ -14,7 +14,7 @@ <tr> <td><%= link_to 'Show', team %></td> <td><%= link_to 'Edit', edit_team_path(team) %></td> - <td><%= link_to 'Destroy', team, method: :delete, data: { confirm: 'Are you sure?' } %></td> + <td><%= button_to 'Destroy', team, method: :delete, data: { confirm: 'Are you sure?' } %></td> </tr> <% end %> </tbody> diff --git a/app/views/teams/show.html.erb b/app/views/teams/show.html.erb index 5b18d33..ab49d65 100644 --- a/app/views/teams/show.html.erb +++ b/app/views/teams/show.html.erb @@ -1,4 +1,2 @@ -<p id="notice"><%= notice %></p> - <%= link_to 'Edit', edit_team_path(@team) %> | <%= link_to 'Back', teams_path %> diff --git a/app/views/tournaments/_form.html.erb b/app/views/tournaments/_form.html.erb index 340efab..c478ce6 100644 --- a/app/views/tournaments/_form.html.erb +++ b/app/views/tournaments/_form.html.erb @@ -1,49 +1,140 @@ -<%= form_for(@tournament) do |f| %> - <% if @tournament.errors.any? %> - <div id="error_explanation"> - <h2><%= pluralize(@tournament.errors.count, "error") %> prohibited this tournament from being saved:</h2> - - <ul> - <% @tournament.errors.full_messages.each do |msg| %> - <li><%= msg %></li> - <% end %> - </ul> - </div> - <% end %> - - <div class="field"> - <%= f.label :game_id %><br> - <%= f.text_field :game_id %> - </div> - <div class="field"> - <%= f.label :status %><br> - <%= f.number_field :status %> - </div> - <div class="field"> - <%= f.label :name %><br> - <%= f.text_field :name %> - </div> - <div class="field"> - <%= f.label :min_players_per_team %><br> - <%= f.number_field :min_players_per_team %> - </div> - <div class="field"> - <%= f.label :max_players_per_team %><br> - <%= f.number_field :max_players_per_team %> - </div> - <div class="field"> - <%= f.label :min_teams_per_match %><br> - <%= f.number_field :min_teams_per_match %> - </div> - <div class="field"> - <%= f.label :max_teams_per_match %><br> - <%= f.number_field :max_teams_per_match %> - </div> - <div class="field"> - <%= f.label :scoring_method %><br> - <%= f.text_field :scoring_method %> - </div> - <div class="actions"> - <%= f.submit %> - </div> +<% +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. +%> +<%= render "common/error_messages", :target => @tournament %> +<fieldset> + <legend>Basic information</legend> + <%= form_for(@tournament, url: new_tournament_path, method: "get") do |f| %> + <div class="field"> + <%= f.label :game_id, "Select a Game Type" %> + <%= f.select(:game_id, Game.all.map{|game| [game.name, game.id]}) %> + </div> + <div class="field"> + <label for="num_stages">Number of Tournament Stages</label> + <input type="number" id="num_stages" name="num_stages" min="1" value="<%= params[:num_stages].to_i %>"> + </div> + <% if @tournament.game %> + <%= f.submit("Update (Will reset the rest of the form)", class: "btn-danger") %> + <% else %> + <%= f.submit("Submit") %> + <% end %> + <% end %> + +</fieldset> +<% if @tournament.game %> + <%= form_for(@tournament, url: tournaments_path, method: "post") do |f| %> + <fieldset> + <legend>Attributes</legend> + + <%= f.hidden_field(:game_id) %> + <div class="field"> + <%= f.label :name %> + <%= f.text_field :name %> + </div> + + <table> + <tbody> + <tr> + <td></td> + <th>Minimum</th> + <th>Maximum</th> + </tr> + <tr> + <th>Players per Team: </th> + <td><%= f.number_field(:min_players_per_team, min: 1) %></td> + <td><%= f.number_field(:max_players_per_team, min: 1) %></td> + </tr> + <tr> + <th>Teams per Match: </th> + <td><%= f.number_field(:min_teams_per_match, min: 1) %></td> + <td><%= f.number_field(:max_teams_per_match, min: 1) %></td> + </tr> + </tbody> + </table> + + <div class="field"> + <%= f.label :scoring_method, :scoring_method.to_s.titleize %> + <%= f.select(:scoring_method, @tournament.scoring_methods.map{|method| [method.humanize.titleize, method]}) %> + </div> + </fieldset> + + <fieldset> + <legend>Settings</legend> + <%= f.fields_for :settings do |setting_fields| %> + <% @tournament.tournament_settings.each do |setting| %> + <div class="field"> + <%= setting_fields.label setting.name, setting.name.to_s.titleize %> + <br> + <% case setting.vartype %> + <% when 0 %> + <%= setting_fields.text_field( setting.name ) %> + <% when 1 %> + <%= setting_fields.text_area( setting.name ) %> + <% when 2 %> + <ul> + <% setting.type_opt.split(',').each do |option|%> + <li><label><%= setting_fields.radio_button( setting.name, option ) %><%= option.humanize.titleize %></label></li> + <% end %> + </ul> + <% when 3 %> + <ul> + <% setting.type_opt.split(',').each do |option|%> + <li><label><%= check_box_tag("tournament[settings][#{setting.name}][]", option, setting.value.split(',').include?(option)) %><%= option.humanize.titleize %></label></li> + <% end %> + </ul> + <% when 4 %> + <%= setting_fields.radio_button( setting.name, "true" ) %> <b>True</b> + <%= setting_fields.radio_button( setting.name, "false" ) %> <b>False</b> + <% when 5 %> + <%= setting_fields.select( setting.name, setting.type_opt.split(',').collect {|opt| opt.humanize.titleize} ) %> + <% end %> + </div> + <% end %> + <% end %> + </fieldset> + + <%= f.fields_for :stages do |stages_fields| %> + <fieldset> + <legend>Stages</legend> + <% for i in 1..(params[:num_stages].to_i) do %> + <%= stages_fields.fields_for i.to_s do |stage_fields| %> + <fieldset> + <legend>Stage <%= i %></legend> + <div class="field"> + <%= stage_fields.label :scheduling_method, :scheduling_method.to_s.titleize %> + <%= stage_fields.select(:scheduling_method, @tournament.scheduling_methods.map{|method| [method.humanize.titleize, method]}) %> + </div> + <div class="field"> + <%= stage_fields.label :seeding_method, :seeding_method.to_s.titleize %> + <%= stage_fields.select(:seeding_method, @tournament.seeding_methods.map{|method| [method.humanize.titleize, method]}) %> + </div> + </fieldset> + <% end %> + <% end %> + </fieldset> + <% end %> + + <%= f.submit %> + + <% end %> <% end %> diff --git a/app/views/tournaments/index.html.erb b/app/views/tournaments/index.html.erb index 7bf8aa0..06e1b25 100644 --- a/app/views/tournaments/index.html.erb +++ b/app/views/tournaments/index.html.erb @@ -1,41 +1,24 @@ -<h1>Listing tournaments</h1> +<h1>Listing Tournaments</h1> -<table> - <thead> - <tr> - <th>Game</th> - <th>Status</th> - <th>Name</th> - <th>Min players per team</th> - <th>Max players per team</th> - <th>Min teams per match</th> - <th>Max teams per match</th> - <th>Scoring method</th> - <th></th> - <th></th> - <th></th> - </tr> - </thead> +<div id="tournament-list"> + <% if @tournaments.length > 0 %> - <tbody> - <% @tournaments.each do |tournament| %> - <tr> - <td><%= tournament.game %></td> - <td><%= tournament.status %></td> - <td><%= tournament.name %></td> - <td><%= tournament.min_players_per_team %></td> - <td><%= tournament.max_players_per_team %></td> - <td><%= tournament.min_teams_per_match %></td> - <td><%= tournament.max_teams_per_match %></td> - <td><%= tournament.scoring_method %></td> - <td><%= link_to 'Show', tournament %></td> - <td><%= link_to 'Edit', edit_tournament_path(tournament) %></td> - <td><%= link_to 'Destroy', tournament, method: :delete, data: { confirm: 'Are you sure?' } %></td> - </tr> - <% end %> - </tbody> -</table> + <%# Each tournament has a div for its listing %> + <% @tournaments.each do |t| %> + <%= render "common/show_tournament", :target => t %> + <% end %> -<br> + <% else %> -<%= link_to 'New Tournament', new_tournament_path %> + <p class="no-entries"> No tournaments going on right now... + <% if current_user.can?(:create_tournament) %> + Why not start your own? + <% end %> + </p> + + <% end %> +</div> + +<% if current_user.can?(:create_tournament) %> + <div><%= link_to 'New Tournament', new_tournament_path, :class => "btn btn-warning btn-lg" %></div> +<% end %> diff --git a/app/views/tournaments/join.html.erb b/app/views/tournaments/join.html.erb new file mode 100644 index 0000000..1d38d68 --- /dev/null +++ b/app/views/tournaments/join.html.erb @@ -0,0 +1,2 @@ + <%= @user.name %> + diff --git a/app/views/tournaments/new.html.erb b/app/views/tournaments/new.html.erb index 2a60539..9c741e0 100644 --- a/app/views/tournaments/new.html.erb +++ b/app/views/tournaments/new.html.erb @@ -1,4 +1,4 @@ -<h1>New tournament</h1> +<h1>New Tournament</h1> <%= render 'form' %> diff --git a/app/views/tournaments/show.html.erb b/app/views/tournaments/show.html.erb index ca65ac6..55a8f14 100644 --- a/app/views/tournaments/show.html.erb +++ b/app/views/tournaments/show.html.erb @@ -1,44 +1,122 @@ -<p id="notice"><%= notice %></p> - -<p> - <strong>Game:</strong> - <%= @tournament.game %> -</p> - -<p> - <strong>Status:</strong> - <%= @tournament.status %> -</p> - -<p> - <strong>Name:</strong> - <%= @tournament.name %> -</p> - -<p> - <strong>Min players per team:</strong> - <%= @tournament.min_players_per_team %> -</p> - -<p> - <strong>Max players per team:</strong> - <%= @tournament.max_players_per_team %> -</p> - -<p> - <strong>Min teams per match:</strong> - <%= @tournament.min_teams_per_match %> -</p> - -<p> - <strong>Max teams per match:</strong> - <%= @tournament.max_teams_per_match %> -</p> - -<p> - <strong>Scoring method:</strong> - <%= @tournament.scoring_method %> -</p> - -<%= link_to 'Edit', edit_tournament_path(@tournament) %> | -<%= link_to 'Back', tournaments_path %> +<% +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. +%> +<%= link_to '« Back to all tournaments', tournaments_path, class: :breadcrumb %> + +<h2 id="tournament-name"> + <%= @tournament.name %> +</h2> + +<div class="progress"> + <%# FIXME: What's up with this? Hardcoded 60%? %> + <%= tag("div", {:id => "prog-bar", :class => "progress-bar progress-bar-warning", :style => "width: " +(@tournament.players.count * 100 / (@tournament.min_players_per_team * @tournament.min_teams_per_match)).to_s + "%", "aria-valuemax" => "100", "aria-valuemin" => "0", "aria-valuenow" => (@tournament.players.count * 100 / (@tournament.min_players_per_team * @tournament.min_teams_per_match)).to_s, "role" => "progressbar"}) %> + <span class="sr-only">60% Complete (warning)</span> + </div> +</div> + +<p id="players-needed"><%= pluralize(@tournament.players.count, "player has", "players have") %> signed up. <%= @tournament.min_players_per_team * @tournament.min_teams_per_match %> needed. </p> + +<div id="tournament-side-params"> + <p> + <strong>Status:</strong> + <% if @tournament.status == 0 %> + Waiting for players... + <% else %> + Started + <% end %> + </p> + + <p> + <strong>Name:</strong> + <%= @tournament.name %> + </p> + + <p> + <strong>Min players per team:</strong> + <%= @tournament.min_players_per_team %> + </p> + + <p> + <strong>Max players per team:</strong> + <%= @tournament.max_players_per_team %> + </p> + + <p> + <strong>Min teams per match:</strong> + <%= @tournament.min_teams_per_match %> + </p> + + <p> + <strong>Max teams per match:</strong> + <%= @tournament.max_teams_per_match %> + </p> + + <p> + <strong>Scoring method:</strong> + <%= @tournament.scoring_method.titleize %> + </p> + + <% @tournament.settings.each do |setting| %> + <p> + <strong><%= setting.name %></strong> + <%= setting.value %> + </p> + <% end %> +</div> + +<div> + <% if @tournament.players.length > 0 %> + <h3>Players Here:</h3> + <ul id="tournament-users"> + <% @tournament.players.each do |p| %> + <li><%= p.user_name %></li> + <% end %> + </ul> + <% else %> + <h3 div="players-needed">Hmmm.... nobody's here yet! You and your friends should join the tournament.</h3> + <% end %> +</div> + +<div class="actions"> + <%# If user can join, and user hasn't joined already, show a join tournment button %> + <% if @tournament.joinable_by?(current_user) && !@tournament.players.include?(current_user) %> + <%= form_tag(tournament_path(@tournament), method: "put", class: :button_to) do %> + <input type="hidden" name="update_action" value="join"> + <%= submit_tag("Join Tournament") %> + <% end %> + <% elsif @tournament.players.include?(current_user) %> + <%= form_tag(tournament_path(@tournament), method: "put", class: :button_to) do %> + <input type="hidden" name="update_action" value="leave"> + <%= submit_tag("Leave Tournament") %> + <% end %> + <% end %> + <%# If user is the host, let them start the tournment %> + <% if @tournament.check_permission(current_user, :edit) %> + <%= form_tag(tournament_path(@tournament), method: "put", class: :button_to) do %> + <input type="hidden" name="update_action" value="start"> + <%= submit_tag("Start Tournament", disabled: (@tournament.players.count < @tournament.min_players_per_team * @tournament.min_teams_per_match)) %> + <% end %> + <%= link_to 'Edit Tournament', edit_tournament_path(@tournament), role: :button %> + <%= button_to 'Cancel Tournament', @tournament, method: :delete, data: { confirm: 'Are you sure?' } %> + <% end %> +</div> diff --git a/app/views/tournaments/standings.html.erb b/app/views/tournaments/standings.html.erb new file mode 100644 index 0000000..15dd325 --- /dev/null +++ b/app/views/tournaments/standings.html.erb @@ -0,0 +1,51 @@ +<% +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. +%> +<% playerscores = @tournament.players.collect {|player| player => @tournament.statistics.where(match: player.matches.last, user: player, name: :score) } %> +<% teams = tournament_stage.matches.collect +{ |match| match.teams.collect { |team| team.id => team.players.collect +{ |player| player.user_name => @tournament.statistics.where(match: player.matches.last, user: player, name: :score } } } %> + +<table> + <tr> + <td>Standings:</td> + <% place = 0 %> + <% playerscores.sort {|player1, player2| playerscores[player1] <=> playerscores[player2] }.each |player| %> + <td><%= place.to_s + ":" %> <%= player.user_name %></td> + <% place += 1%> + <% end %> + </tr> +</table> + +<% teams.each do |team| %> + <table> + <tr> + <td>Standings:</td> + <% place = 0 %> + <% team.values.sort {|player1, player2| playerscores[player1] <=> playerscores[player2] }.each |player| %> + <td><%= place.to_s + ":" %> <%= player.user_name %></td> + <% place += 1%> + <% end %> + </tr> + </table> +<% end %> diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb index 4d28738..e4e49f4 100644 --- a/app/views/users/_form.html.erb +++ b/app/views/users/_form.html.erb @@ -1,29 +1,68 @@ +<% +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. +%> <%= form_for(@user) do |f| %> - <% if @user.errors.any? %> - <div id="error_explanation"> - <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2> - - <ul> - <% @user.errors.full_messages.each do |msg| %> - <li><%= msg %></li> - <% end %> - </ul> - </div> - <% end %> + <%= render "common/error_messages", :target => @user %> <div class="field"> <%= f.label :name %><br> <%= f.text_field :name %> </div> + <div class="field"> <%= f.label :email %><br> - <%= f.text_field :email %> + <%= f.email_field(:email) %> </div> + <div class="field"> <%= f.label :user_name %><br> <%= f.text_field :user_name %> </div> + + <div> + <%= f.label(:password, "New Password (or use old)") %><br> + <%= f.password_field :password %> + </div> + <div> + <%= f.label(:password_confirmation, "Confirm Password") %><br> + <%= f.password_field :password_confirmation %> + </div> + + <% if current_user.can? :edit_permissions %> + <fieldset> + <legend>User permissions</legend> + <ul> + <%= fields_for "user[abilities]", @user.abilities do |abilities_fields| %> + <% @user.abilities.keys.each do |ability| %> + <li><%= abilities_fields.check_box(ability) %> <%= abilities_fields.label(ability) %></li> + <% end %> + <% end %> + </ul> + </fieldset> + <% end %> + <div class="actions"> <%= f.submit %> </div> + <% end %> diff --git a/app/views/users/already_signed_in.html.erb b/app/views/users/already_signed_in.html.erb new file mode 100644 index 0000000..04b4248 --- /dev/null +++ b/app/views/users/already_signed_in.html.erb @@ -0,0 +1 @@ +<h1>You are currently signed in</h1> diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 99bd4cc..52f32a2 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -3,4 +3,4 @@ <%= render 'form' %> <%= link_to 'Show', @user %> | -<%= link_to 'Back', users_path %> +<%= link_to 'Users', users_path %> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 3692112..53b37b8 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,8 +1,32 @@ +<% +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. +%> <h1>Listing users</h1> -<table> +<table class="table table-hover"> <thead> <tr> + <th>Username</th> <th>Name</th> <th>Email</th> <th>User name</th> @@ -15,12 +39,13 @@ <tbody> <% @users.each do |user| %> <tr> + <td><%= image_tag('http://www.gravatar.com/avatar/' + Digest::MD5.hexdigest(user.email) + '?s=30&d=identicon') %> <%= link_to("#{user.user_name}", user, nil) %></td> <td><%= user.name %></td> - <td><%= user.email %></td> + <td> ******* </td> <td><%= user.user_name %></td> <td><%= link_to 'Show', user %></td> <td><%= link_to 'Edit', edit_user_path(user) %></td> - <td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td> + <td><%= button_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td> </tr> <% end %> </tbody> diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index efc0404..1445a0d 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -1,5 +1,70 @@ -<h1>New user</h1> +<% +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. +%> +<h1> Sign Up </h1> -<%= render 'form' %> +<%= form_for @user do |f| %> + <%= render "common/error_messages", :target => @user %> + <div class="field"> + <%= f.label :user_name %> + <span class="help-block"> + This is the name you will use to log in. + It may consist of letters, numbers, <kbd>_</kbd>, and <kbd>-</kbd>. + </span> + <br> + <%= f.text_field :user_name %> + </div> + <div class="field"> + <%= f.label :password %> + <span class="help-block"> + Must be at least 6 characters long. + </span> + <br> + <%= f.password_field(:password, required: :required, minlength: 6) %> + </div> + <div class="field"> + <%= f.label(:password_confirmation, "Confirm Password") %><br> + <%= f.password_field(:password_confirmation, required: :required, minlength: 6) %> + </div> + <div class="field"> + <%= f.label :name %> + <span class="help-block"> + A display name; perhaps your real name, or perhaps an alias. + </span> + <br> + <%= f.text_field :name %> + </div> + <div class="field"> + <%= f.label :email %><br> + <%= f.email_field(:email) %> + </div> + <div class="field"> + <%= show_simple_captcha %> + </div> + <div class="actions"> + <%= f.submit("Be a Leaguer", :class => "signup") %> + </div> +<% end %> + +<%= link_to 'Already Have an Account? Log in', new_session_path, :class => "signin" %> -<%= link_to 'Back', users_path %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 9455a3c..ab17b9a 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,19 +1,79 @@ -<p id="notice"><%= notice %></p> +<% +# Copyright (C) 2014 Andrew Murrell +# Copyright (C) 2014 Davis Webb +# Copyright (C) 2014 Guntas Grewal +# Copyright (C) 2014 Luke Shumaker +# Copyright (C) 2014 Nathaniel Foy +# Copyright (C) 2014 Tomer Kimia +# +# This file is part of Leaguer. +# +# Leaguer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Leaguer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the Affero GNU General Public License +# along with Leaguer. If not, see <http://www.gnu.org/licenses/>. +%> + +<h1> <%= @user.user_name %>'s Profile </h1> <p> - <strong>Name:</strong> - <%= @user.name %> + <%= image_tag 'http://www.gravatar.com/avatar/' + Digest::MD5.hexdigest(@user.email) + '?s=100&d=identicon' %> </p> <p> - <strong>Email:</strong> - <%= @user.email %> -</p> + <strong>Name:</strong> + <%= @user.name %> +<p> <p> - <strong>User name:</strong> - <%= @user.user_name %> + <strong>Alias:</strong> + <%= @user.user_name %> +<p> + <strong>Email:</strong> + <%= @user.email %> </p> -<%= link_to 'Edit', edit_user_path(@user) %> | -<%= link_to 'Back', users_path %> +<% if @user.remote_usernames.empty? and @user.check_permission(current_user, :edit) %> + <%= form_for @user do |f| %> + <div class="field"> + <label for="summoner_name">Have a League of Legends Account?</label> + <div class="simple-input-group"> + <input type="text" id="summoner_name" name="user[remote_usernames][League of Legends]"> + <%= f.submit "Add Username", :class => 'signup' %> + </div> + </div> + <% end %> +<% end %> + +<div class="row"> + <div class="col-md-6"> + <h3>Recent Tournaments Played</h3> + <ul> + <% @user.tournaments_played.each do |t| %> + <li><%= t.name %></li> + <% end %> + </ul> + </div> + <div class="col-md-6"> + <h3>Recent Tournaments Hosted</h3> + <% if @user.tournaments_hosted.empty? %> + <p><%= @user.user_name %> has never hosted a tournament.</p> + <% else %> + <ul> + <% @user.tournaments_hosted.each do |t| %> + <li><%= t.name %></li> + <% end %> + </ul> + <% end %> + </div> +</div> + +<%= link_to 'Edit', edit_user_path(@user), role: :button %> |