<%= get_flash(@conn, :info) %>
32 |<%= get_flash(@conn, :error) %>
33 | <%= render @view_module, @view_template, assigns %> 34 |├── .formatter.exs ├── .gitignore ├── LICENSE ├── README.md ├── assets ├── .babelrc ├── css │ ├── app.css │ └── phoenix.css ├── js │ ├── app.js │ ├── socket.js │ └── users.js ├── package-lock.json ├── package.json ├── static │ ├── favicon.ico │ ├── images │ │ ├── phoenix.png │ │ └── pointing-party-logo.png │ └── robots.txt └── webpack.config.js ├── config ├── cards.exs ├── config.exs ├── dev.exs ├── prod.exs └── test.exs ├── lib ├── pointing_party.ex ├── pointing_party │ ├── account.ex │ ├── account │ │ └── auth.ex │ ├── application.ex │ ├── card.ex │ └── vote_calculator.ex ├── pointing_party_web.ex └── pointing_party_web │ ├── channels │ ├── presence.ex │ ├── room_channel.ex │ └── user_socket.ex │ ├── controllers │ ├── card_controller.ex │ ├── page_controller.ex │ └── session_controller.ex │ ├── endpoint.ex │ ├── gettext.ex │ ├── plugs │ └── auth.ex │ ├── router.ex │ ├── templates │ ├── card │ │ └── index.html.eex │ ├── layout │ │ └── app.html.eex │ ├── page │ │ └── index.html.eex │ └── session │ │ └── new.html.eex │ └── views │ ├── card_view.ex │ ├── error_helpers.ex │ ├── error_view.ex │ ├── layout_helpers.ex │ ├── layout_view.ex │ ├── page_view.ex │ └── session_view.ex ├── mix.exs ├── mix.lock ├── package-lock.json ├── priv ├── gettext │ ├── en │ │ └── LC_MESSAGES │ │ │ └── errors.po │ └── errors.pot ├── repo │ ├── migrations │ │ ├── .formatter.exs │ │ ├── 20190708014847_create_cards.exs │ │ └── 20190714140153_add_points_to_cards.exs │ └── seeds.exs └── static │ ├── css │ └── app.css │ ├── favicon.ico │ ├── images │ ├── phoenix.png │ ├── pointing-party-logo.png │ └── pp-logo.png │ ├── js │ └── app.js │ └── robots.txt └── test ├── pointing_party └── vote_calculator_test.exs ├── pointing_party_web ├── controllers │ ├── card_controller_test.exs │ └── page_controller_test.exs └── views │ ├── error_view_test.exs │ ├── layout_view_test.exs │ └── page_view_test.exs ├── support ├── channel_case.ex └── conn_case.ex └── test_helper.exs /.formatter.exs: -------------------------------------------------------------------------------- 1 | [ 2 | import_deps: [:ecto, :phoenix], 3 | inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"], 4 | subdirectories: ["priv/*/migrations"] 5 | ] 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /_build 2 | /cover 3 | /deps 4 | /doc 5 | /.fetch 6 | erl_crash.dump 7 | *.ez 8 | *.beam 9 | /config/*.secret.exs 10 | /assets/node_modules 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pointing Party 2 | Welcome to Elixir School's workshop on Real-Time Phoenix with Channels, PubSub, Presence and LiveView! This application exists to guide workshop participants through each of these topics by allowing them to build out a set of features to support a fantastically fun game of "pointing party". 3 | 4 | Collaborators can sign in with a username and click a button to start the "pointing party". Tickets are displayed for estimation and each user can cast their store point estimate vote. Once all the votes are cast, a winner is declared and the participants can move on to estimate the next ticket. 5 | 6 | The master branch of this app represents the starting state of the code for this workshop. Clone down and make sure you're on the master branch in order to follow along. 7 | 8 | ## Resources 9 | 10 | ### Phoenix Channels 11 | 12 | * [Official guide](https://hexdocs.pm/phoenix/channels.html) 13 | * [API documentation](https://hexdocs.pm/phoenix/Phoenix.Channel.html#content) 14 | 15 | ### Phoenix PubSub 16 | 17 | * [API documentation](https://hexdocs.pm/phoenix_pubsub/Phoenix.PubSub.html) 18 | 19 | ### Phoenix LiveView 20 | 21 | * [LiveView announcement](https://dockyard.com/blog/2018/12/12/phoenix-liveview-interactive-real-time-apps-no-need-to-write-javascript) by Chris McCord 22 | * [API documentation](https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html) 23 | * ["Walk-Through of Phoenix LiveView"](https://elixirschool.com/blog/phoenix-live-view/) by Sophie DeBenedetto 24 | * ["Building Real-Time Features with Phoenix Live View and PubSub"](https://elixirschool.com/blog/live-view-with-pub-sub/) by Sophie DeBenedetto 25 | * ["Using Channels with LiveView for Better UX"](https://elixirschool.com/blog/live-view-with-channels/) by Sophie DeBenedetto 26 | * ["Tracking Users in a Chat App with LiveView, PubSub Presence"](https://elixirschool.com/blog/live-view-with-presence/) by Sophie DeBenedetto 27 | 28 | ### Property-based Testing and StreamData 29 | 30 | * [StreamData on GitHub](https://github.com/whatyouhide/stream_data) 31 | * [StreamData documentation](https://hexdocs.pm/stream_data/StreamData.html) 32 | * [Elixir School article on StreamData](https://elixirschool.com/en/lessons/libraries/stream-data/) 33 | * [_Property-Based Testing with PropEr, Erlang, and Elixir_ and _PropEr Testing_](https://propertesting.com/) by Fred Hebert 34 | * ["An introduction to property-based testing"](https://fsharpforfunandprofit.com/posts/property-based-testing/) by Scott Wlaschin 35 | * ["Choosing properties for property-based testing"](https://fsharpforfunandprofit.com/posts/property-based-testing-2/) by Scott Wlaschin 36 | 37 | ### Estimation 38 | 39 | * [_Agile Estimating and Planning_](https://www.mountaingoatsoftware.com/books/agile-estimating-and-planning) by Mike Cohn of Mountain Goat Software 40 | * [planningpoker.com](https://www.planningpoker.com/) is a full-featured estimation tool that may work well for your team. 41 | 42 | Thanks to James Grenning and Mike Cohn for their inspiration and their work in software estimation! 43 | -------------------------------------------------------------------------------- /assets/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-env" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /assets/css/app.css: -------------------------------------------------------------------------------- 1 | /* This file is for your main application css. */ 2 | 3 | @import "./phoenix.css"; 4 | -------------------------------------------------------------------------------- /assets/css/phoenix.css: -------------------------------------------------------------------------------- 1 | /* Includes some default style for the starter application. 2 | * This can be safely deleted to start fresh. 3 | */ 4 | 5 | /* Milligram v1.3.0 https://milligram.github.io 6 | * Copyright (c) 2017 CJ Patoilo Licensed under the MIT license 7 | */ 8 | 9 | *,*:after,*:before{box-sizing:inherit}html{box-sizing:border-box;font-size:62.5%}body{color:#000000;font-family:'Helvetica', 'Arial', sans-serif;font-size:1.6em;font-weight:300;line-height:1.6}blockquote{border-left:0.3rem solid #d1d1d1;margin-left:0;margin-right:0;padding:1rem 1.5rem}blockquote *:last-child{margin-bottom:0}.button,button,input[type='button'],input[type='reset'],input[type='submit']{background-color:#0069d9;border:0.1rem solid #0069d9;border-radius:.4rem;color:#fff;cursor:pointer;display:inline-block;font-size:1.1rem;font-weight:700;height:3.8rem;letter-spacing:.1rem;line-height:3.8rem;padding:0 3.0rem;text-align:center;text-decoration:none;text-transform:uppercase;white-space:nowrap}.button:focus,.button:hover,button:focus,button:hover,input[type='button']:focus,input[type='button']:hover,input[type='reset']:focus,input[type='reset']:hover,input[type='submit']:focus,input[type='submit']:hover{background-color:#606c76;border-color:#606c76;color:#fff;outline:0}.button[disabled],button[disabled],input[type='button'][disabled],input[type='reset'][disabled],input[type='submit'][disabled]{cursor:default;opacity:.5}.button[disabled]:focus,.button[disabled]:hover,button[disabled]:focus,button[disabled]:hover,input[type='button'][disabled]:focus,input[type='button'][disabled]:hover,input[type='reset'][disabled]:focus,input[type='reset'][disabled]:hover,input[type='submit'][disabled]:focus,input[type='submit'][disabled]:hover{background-color:#0069d9;border-color:#0069d9}.button.button-outline,button.button-outline,input[type='button'].button-outline,input[type='reset'].button-outline,input[type='submit'].button-outline{background-color:transparent;color:#0069d9}.button.button-outline:focus,.button.button-outline:hover,button.button-outline:focus,button.button-outline:hover,input[type='button'].button-outline:focus,input[type='button'].button-outline:hover,input[type='reset'].button-outline:focus,input[type='reset'].button-outline:hover,input[type='submit'].button-outline:focus,input[type='submit'].button-outline:hover{background-color:transparent;border-color:#606c76;color:#606c76}.button.button-outline[disabled]:focus,.button.button-outline[disabled]:hover,button.button-outline[disabled]:focus,button.button-outline[disabled]:hover,input[type='button'].button-outline[disabled]:focus,input[type='button'].button-outline[disabled]:hover,input[type='reset'].button-outline[disabled]:focus,input[type='reset'].button-outline[disabled]:hover,input[type='submit'].button-outline[disabled]:focus,input[type='submit'].button-outline[disabled]:hover{border-color:inherit;color:#0069d9}.button.button-clear,button.button-clear,input[type='button'].button-clear,input[type='reset'].button-clear,input[type='submit'].button-clear{background-color:transparent;border-color:transparent;color:#0069d9}.button.button-clear:focus,.button.button-clear:hover,button.button-clear:focus,button.button-clear:hover,input[type='button'].button-clear:focus,input[type='button'].button-clear:hover,input[type='reset'].button-clear:focus,input[type='reset'].button-clear:hover,input[type='submit'].button-clear:focus,input[type='submit'].button-clear:hover{background-color:transparent;border-color:transparent;color:#606c76}.button.button-clear[disabled]:focus,.button.button-clear[disabled]:hover,button.button-clear[disabled]:focus,button.button-clear[disabled]:hover,input[type='button'].button-clear[disabled]:focus,input[type='button'].button-clear[disabled]:hover,input[type='reset'].button-clear[disabled]:focus,input[type='reset'].button-clear[disabled]:hover,input[type='submit'].button-clear[disabled]:focus,input[type='submit'].button-clear[disabled]:hover{color:#0069d9}code{background:#f4f5f6;border-radius:.4rem;font-size:86%;margin:0 .2rem;padding:.2rem .5rem;white-space:nowrap}pre{background:#f4f5f6;border-left:0.3rem solid #0069d9;overflow-y:hidden}pre>code{border-radius:0;display:block;padding:1rem 1.5rem;white-space:pre}hr{border:0;border-top:0.1rem solid #f4f5f6;margin:3.0rem 0}input[type='email'],input[type='number'],input[type='password'],input[type='search'],input[type='tel'],input[type='text'],input[type='url'],textarea,select{-webkit-appearance:none;-moz-appearance:none;appearance:none;background-color:transparent;border:0.1rem solid #d1d1d1;border-radius:.4rem;box-shadow:none;box-sizing:inherit;height:3.8rem;padding:.6rem 1.0rem;width:100%}input[type='email']:focus,input[type='number']:focus,input[type='password']:focus,input[type='search']:focus,input[type='tel']:focus,input[type='text']:focus,input[type='url']:focus,textarea:focus,select:focus{border-color:#0069d9;outline:0}select{background:url('data:image/svg+xml;utf8,') center right no-repeat;padding-right:3.0rem}select:focus{background-image:url('data:image/svg+xml;utf8,')}textarea{min-height:6.5rem}label,legend{display:block;font-size:1.6rem;font-weight:700;margin-bottom:.5rem}fieldset{border-width:0;padding:0}input[type='checkbox'],input[type='radio']{display:inline}.label-inline{display:inline-block;font-weight:normal;margin-left:.5rem}.row{display:flex;flex-direction:column;padding:0;width:100%}.row.row-no-padding{padding:0}.row.row-no-padding>.column{padding:0}.row.row-wrap{flex-wrap:wrap}.row.row-top{align-items:flex-start}.row.row-bottom{align-items:flex-end}.row.row-center{align-items:center}.row.row-stretch{align-items:stretch}.row.row-baseline{align-items:baseline}.row .column{display:block;flex:1 1 auto;margin-left:0;max-width:100%;width:100%}.row .column.column-offset-10{margin-left:10%}.row .column.column-offset-20{margin-left:20%}.row .column.column-offset-25{margin-left:25%}.row .column.column-offset-33,.row .column.column-offset-34{margin-left:33.3333%}.row .column.column-offset-50{margin-left:50%}.row .column.column-offset-66,.row .column.column-offset-67{margin-left:66.6666%}.row .column.column-offset-75{margin-left:75%}.row .column.column-offset-80{margin-left:80%}.row .column.column-offset-90{margin-left:90%}.row .column.column-10{flex:0 0 10%;max-width:10%}.row .column.column-20{flex:0 0 20%;max-width:20%}.row .column.column-25{flex:0 0 25%;max-width:25%}.row .column.column-33,.row .column.column-34{flex:0 0 33.3333%;max-width:33.3333%}.row .column.column-40{flex:0 0 40%;max-width:40%}.row .column.column-50{flex:0 0 50%;max-width:50%}.row .column.column-60{flex:0 0 60%;max-width:60%}.row .column.column-66,.row .column.column-67{flex:0 0 66.6666%;max-width:66.6666%}.row .column.column-75{flex:0 0 75%;max-width:75%}.row .column.column-80{flex:0 0 80%;max-width:80%}.row .column.column-90{flex:0 0 90%;max-width:90%}.row .column .column-top{align-self:flex-start}.row .column .column-bottom{align-self:flex-end}.row .column .column-center{-ms-grid-row-align:center;align-self:center}@media (min-width: 40rem){.row{flex-direction:row;margin-left:-1.0rem;width:calc(100% + 2.0rem)}.row .column{margin-bottom:inherit;padding:0 1.0rem}}a{color:#0069d9;text-decoration:none}a:focus,a:hover{color:#606c76}dl,ol,ul{list-style:none;margin-top:0;padding-left:0}dl dl,dl ol,dl ul,ol dl,ol ol,ol ul,ul dl,ul ol,ul ul{font-size:90%;margin:1.5rem 0 1.5rem 3.0rem}ol{list-style:decimal inside}ul{list-style:circle inside}.button,button,dd,dt,li{margin-bottom:1.0rem}fieldset,input,select,textarea{margin-bottom:1.5rem}blockquote,dl,figure,form,ol,p,pre,table,ul{margin-bottom:2.5rem}table{border-spacing:0;width:100%}td,th{border-bottom:0.1rem solid #e1e1e1;padding:1.2rem 1.5rem;text-align:left}td:first-child,th:first-child{padding-left:0}td:last-child,th:last-child{padding-right:0}b,strong{font-weight:bold}p{margin-top:0}h1,h2,h3,h4,h5,h6{font-weight:300;letter-spacing:-.1rem;margin-bottom:2.0rem;margin-top:0}h1{font-size:4.6rem;line-height:1.2}h2{font-size:3.6rem;line-height:1.25}h3{font-size:2.8rem;line-height:1.3}h4{font-size:2.2rem;letter-spacing:-.08rem;line-height:1.35}h5{font-size:1.8rem;letter-spacing:-.05rem;line-height:1.5}h6{font-size:1.6rem;letter-spacing:0;line-height:1.4}img{max-width:100%}.clearfix:after{clear:both;content:' ';display:table}.float-left{float:left}.float-right{float:right} 10 | 11 | /* General style */ 12 | h1{font-size: 3.6rem; line-height: 1.25} 13 | h2{font-size: 2.8rem; line-height: 1.3} 14 | h3{font-size: 2.2rem; letter-spacing: -.08rem; line-height: 1.35} 15 | h4{font-size: 1.8rem; letter-spacing: -.05rem; line-height: 1.5} 16 | h5{font-size: 1.6rem; letter-spacing: 0; line-height: 1.4} 17 | h6{font-size: 1.4rem; letter-spacing: 0; line-height: 1.2} 18 | 19 | .container{ 20 | margin: 0 auto; 21 | max-width: 80.0rem; 22 | padding: 0 2.0rem; 23 | position: relative; 24 | width: 100% 25 | } 26 | select { 27 | width: auto; 28 | } 29 | 30 | /* Alerts and form errors */ 31 | .alert { 32 | padding: 15px; 33 | margin-bottom: 20px; 34 | border: 1px solid transparent; 35 | border-radius: 4px; 36 | } 37 | .alert-info { 38 | color: #31708f; 39 | background-color: #d9edf7; 40 | border-color: #bce8f1; 41 | } 42 | .alert-warning { 43 | color: #8a6d3b; 44 | background-color: #fcf8e3; 45 | border-color: #faebcc; 46 | } 47 | .alert-danger { 48 | color: #a94442; 49 | background-color: #f2dede; 50 | border-color: #ebccd1; 51 | } 52 | .alert p { 53 | margin-bottom: 0; 54 | } 55 | .alert:empty { 56 | display: none; 57 | } 58 | .help-block { 59 | color: #a94442; 60 | display: block; 61 | margin: -1rem 0 2rem; 62 | } 63 | 64 | /* Phoenix promo and logo */ 65 | .phx-hero { 66 | text-align: center; 67 | border-bottom: 1px solid #e3e3e3; 68 | background: #eee; 69 | border-radius: 6px; 70 | padding: 3em; 71 | margin-bottom: 3rem; 72 | font-weight: 200; 73 | font-size: 120%; 74 | } 75 | .phx-hero p { 76 | margin: 0; 77 | } 78 | .phx-logo { 79 | min-width: 300px; 80 | margin: 1rem; 81 | display: block; 82 | } 83 | .phx-logo img { 84 | width: auto; 85 | display: block; 86 | } 87 | 88 | /* Headers */ 89 | header { 90 | width: 100%; 91 | background: #fdfdfd; 92 | border-bottom: 1px solid #eaeaea; 93 | margin-bottom: 2rem; 94 | } 95 | header section { 96 | align-items: center; 97 | display: flex; 98 | flex-direction: column; 99 | justify-content: space-between; 100 | } 101 | header section :first-child { 102 | order: 2; 103 | } 104 | header section :last-child { 105 | order: 1; 106 | } 107 | header nav ul, 108 | header nav li { 109 | margin: 0; 110 | padding: 0; 111 | display: block; 112 | text-align: right; 113 | white-space: nowrap; 114 | } 115 | header nav ul { 116 | margin: 1rem; 117 | margin-top: 0; 118 | } 119 | header nav a { 120 | display: block; 121 | } 122 | 123 | @media (min-width: 40.0rem) { /* Small devices (landscape phones, 576px and up) */ 124 | header section { 125 | flex-direction: row; 126 | } 127 | header nav ul { 128 | margin: 1rem; 129 | } 130 | .phx-logo { 131 | flex-basis: 527px; 132 | margin: 2rem 1rem; 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /assets/js/app.js: -------------------------------------------------------------------------------- 1 | // We need to import the CSS so that webpack will load it. 2 | // The MiniCssExtractPlugin is used to separate it out into 3 | // its own CSS file. 4 | import css from "../css/app.css" 5 | 6 | // webpack automatically bundles all modules in your 7 | // entry points. Those entry points can be configured 8 | // in "webpack.config.js". 9 | // 10 | // Import dependencies 11 | // 12 | import "phoenix_html" 13 | 14 | // Import local files 15 | // 16 | // Local files can be imported directly using relative paths, for example: 17 | import socket from "./socket" 18 | -------------------------------------------------------------------------------- /assets/js/socket.js: -------------------------------------------------------------------------------- 1 | import { Socket, Presence } from 'phoenix' 2 | import updateUsers from './users' 3 | 4 | const socket = new Socket('/socket', {params: {username: window.pointingParty.username}}) 5 | socket.connect() 6 | 7 | let driving = false; 8 | 9 | // connect to Presence here 10 | // set up your syncDiff function using updateUsers as a callback 11 | 12 | const startButton = document.querySelector('.start-button') 13 | startButton.addEventListener('click', event => { 14 | driving = true; 15 | // send 'start_pointing' message to the channel here 16 | }) 17 | 18 | document 19 | .querySelectorAll('.next-card') 20 | .forEach(elem => { 21 | elem.addEventListener('click', event => { 22 | // send 'finalized_points' message to the channel here 23 | }) 24 | }) 25 | 26 | document 27 | .querySelector('.calculate-points') 28 | .addEventListener('click', event => { 29 | const storyPoints = document.querySelector('.story-points') 30 | // send 'user_estimated' to the channel here 31 | }) 32 | 33 | // call the relevant function defined below when you receive the following events from the channel: 34 | // 'next_card' 35 | // 'winner' 36 | // 'tie' 37 | 38 | const showCard = state => { 39 | document 40 | .querySelector('.start-button') 41 | .style.display = "none" 42 | document 43 | .querySelector('.winner') 44 | .style.display = "none" 45 | document 46 | .querySelector('.tie') 47 | .style.display = "none" 48 | document 49 | .querySelector('.calculate-points') 50 | .style.display = "inline-block" 51 | document 52 | .querySelector('.ticket') 53 | .style.display = "block" 54 | document 55 | .querySelector('.ticket-title') 56 | .innerHTML = state.card.title 57 | document 58 | .querySelector('.ticket-description') 59 | .innerHTML = state.card.description 60 | } 61 | 62 | const showWinner = state => { 63 | document 64 | .querySelector('.winner') 65 | .style.display = "block" 66 | document 67 | .querySelector('.calculate-points') 68 | .style.display = "none" 69 | document 70 | .querySelector('.final-points') 71 | .innerHTML = "Winner: " + state.points + " Points" 72 | document 73 | .querySelector('.next-card') 74 | .value = state.points 75 | document 76 | .querySelector('.next-card') 77 | .disabled = !driving 78 | } 79 | 80 | const showTie = state => { 81 | document 82 | .querySelector('.tie') 83 | .style.display = "block" 84 | document 85 | .querySelector('.calculate-points') 86 | .style.display = "none" 87 | document 88 | .querySelector('.tie') 89 | .getElementsByClassName('next-card')[0] 90 | .value = state.points[0] 91 | document 92 | .querySelector('.tie') 93 | .getElementsByClassName('next-card')[0] 94 | .innerHTML = state.points[0] + " Points" 95 | document 96 | .querySelector('.tie') 97 | .getElementsByClassName('next-card')[0] 98 | .disabled = !driving 99 | document 100 | .querySelector('.tie') 101 | .getElementsByClassName('next-card')[1] 102 | .value = state.points[1] 103 | document 104 | .querySelector('.tie') 105 | .getElementsByClassName('next-card')[1] 106 | .innerHTML = state.points[1] + " Points" 107 | document 108 | .querySelector('.tie') 109 | .getElementsByClassName('next-card')[1] 110 | .disabled = !driving 111 | } 112 | 113 | export default socket 114 | -------------------------------------------------------------------------------- /assets/js/users.js: -------------------------------------------------------------------------------- 1 | import {every} from 'lodash' 2 | 3 | const usersElem = document.querySelector('.users') 4 | 5 | const updateUsers = presence => { 6 | usersElem.innerHTML = '' 7 | 8 | // let users = list presences with the help of a listBy function 9 | users.forEach(addUser) 10 | 11 | // implement a feature that 12 | // 1. checks if all fo the users in the present list have voted, i.e. have points values that are not null 13 | // 2. displays the user's vote next to their name if so 14 | } 15 | 16 | const listBy = (username, {metas: [{points}, ..._rest]}) => { 17 | // build out the listBy function so that it returns a list of users 18 | // where each user looks like this: 19 | // {username: username, points: points} 20 | } 21 | 22 | const showPoints = ({userId, points}) => { 23 | const userElem = document.querySelector(`.${userId}.user-estimate`) 24 | userElem.innerHTML = points 25 | } 26 | 27 | const addUser = user => { 28 | const userElem = document.createElement('dt') 29 | userElem.appendChild(document.createTextNode(user.username)) 30 | userElem.setAttribute('class', 'col-8') 31 | 32 | const estimateElem = document.createElement('dd') 33 | estimateElem.setAttribute('class', `${user.username} user-estimate col-4`) 34 | 35 | usersElem.appendChild(userElem) 36 | usersElem.appendChild(estimateElem) 37 | } 38 | 39 | export default updateUsers 40 | -------------------------------------------------------------------------------- /assets/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "repository": {}, 3 | "license": "MIT", 4 | "scripts": { 5 | "deploy": "webpack --mode production", 6 | "watch": "webpack --mode development --watch" 7 | }, 8 | "dependencies": { 9 | "lodash": "^4.17.19", 10 | "phoenix": "file:../deps/phoenix", 11 | "phoenix_html": "file:../deps/phoenix_html" 12 | }, 13 | "devDependencies": { 14 | "@babel/core": "^7.0.0", 15 | "@babel/preset-env": "^7.0.0", 16 | "babel-loader": "^8.0.0", 17 | "copy-webpack-plugin": "^4.5.0", 18 | "css-loader": "^2.1.1", 19 | "mini-css-extract-plugin": "^0.4.0", 20 | "optimize-css-assets-webpack-plugin": "^5.0.3", 21 | "uglifyjs-webpack-plugin": "^1.2.4", 22 | "webpack": "4.4.0", 23 | "webpack-cli": "^3.3.5" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /assets/static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elixirschool/pointing-party/700131c05024c5de4cec6f0014dc28af52bbdc18/assets/static/favicon.ico -------------------------------------------------------------------------------- /assets/static/images/phoenix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elixirschool/pointing-party/700131c05024c5de4cec6f0014dc28af52bbdc18/assets/static/images/phoenix.png -------------------------------------------------------------------------------- /assets/static/images/pointing-party-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elixirschool/pointing-party/700131c05024c5de4cec6f0014dc28af52bbdc18/assets/static/images/pointing-party-logo.png -------------------------------------------------------------------------------- /assets/static/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | # 3 | # To ban all spiders from the entire site uncomment the next two lines: 4 | # User-agent: * 5 | # Disallow: / 6 | -------------------------------------------------------------------------------- /assets/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const glob = require('glob'); 3 | const MiniCssExtractPlugin = require('mini-css-extract-plugin'); 4 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); 5 | const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); 6 | const CopyWebpackPlugin = require('copy-webpack-plugin'); 7 | 8 | module.exports = (env, options) => ({ 9 | optimization: { 10 | minimizer: [ 11 | new UglifyJsPlugin({ cache: true, parallel: true, sourceMap: false }), 12 | new OptimizeCSSAssetsPlugin({}) 13 | ] 14 | }, 15 | entry: { 16 | './js/app.js': glob.sync('./vendor/**/*.js').concat(['./js/app.js']) 17 | }, 18 | output: { 19 | filename: 'app.js', 20 | path: path.resolve(__dirname, '../priv/static/js') 21 | }, 22 | module: { 23 | rules: [ 24 | { 25 | test: /\.js$/, 26 | exclude: /node_modules/, 27 | use: { 28 | loader: 'babel-loader' 29 | } 30 | }, 31 | { 32 | test: /\.css$/, 33 | use: [MiniCssExtractPlugin.loader, 'css-loader'] 34 | } 35 | ] 36 | }, 37 | plugins: [ 38 | new MiniCssExtractPlugin({ filename: '../css/app.css' }), 39 | new CopyWebpackPlugin([{ from: 'static/', to: '../' }]) 40 | ] 41 | }); 42 | -------------------------------------------------------------------------------- /config/cards.exs: -------------------------------------------------------------------------------- 1 | use Mix.Config 2 | 3 | config :pointing_party, 4 | cards: [ 5 | %{ 6 | title: "Support loading data from a database", 7 | description: """ 8 | We need to update the application to read users and cards from the database. This work includes adding Repo to the 9 | project, creating migrations, and a seed.exs file. 10 | """ 11 | }, 12 | %{ 13 | title: "Save pointing results to database", 14 | description: """ 15 | Update the application to save an individual's vote and the final card points to the database. 16 | """ 17 | }, 18 | 19 | %{ 20 | title: "Add Guardian dependency", 21 | description: """ 22 | In preparation for adding authentication to the application, we need to add the Guardian dependency. 23 | """ 24 | }, 25 | %{ 26 | title: "Create Auth module and config", 27 | description: """ 28 | Create a module that uses the Guardian package and implements the approach set of callbacks. Additionally, 29 | add the Guardian configuration. 30 | """ 31 | }, 32 | %{ 33 | title: "Update authenication flow to use new auth", 34 | description: """ 35 | Update our existing authentication flow to use the newly created Auth module. 36 | """ 37 | } 38 | ] 39 | -------------------------------------------------------------------------------- /config/config.exs: -------------------------------------------------------------------------------- 1 | use Mix.Config 2 | 3 | config :pointing_party, 4 | ecto_repos: [PointingParty.Repo] 5 | 6 | # Configures the endpoint 7 | config :pointing_party, PointingPartyWeb.Endpoint, 8 | url: [host: "localhost"], 9 | secret_key_base: "w1I+WClCAIRKxSX5/M7gFHQLa9pnn4AuVDO6XmUgTZxJl+VqMOr2Q5Ou+2CSoLdJ", 10 | render_errors: [view: PointingPartyWeb.ErrorView, accepts: ~w(html json)], 11 | pubsub: [name: PointingParty.PubSub, adapter: Phoenix.PubSub.PG2] 12 | 13 | # Configures Elixir's Logger 14 | config :logger, :console, 15 | format: "$time $metadata[$level] $message\n", 16 | metadata: [:request_id] 17 | 18 | # Use Jason for JSON parsing in Phoenix 19 | config :phoenix, :json_library, Jason 20 | 21 | import_config "cards.exs" 22 | 23 | # Import environment specific config. This must remain at the bottom 24 | # of this file so it overrides the configuration defined above. 25 | import_config "#{Mix.env()}.exs" 26 | -------------------------------------------------------------------------------- /config/dev.exs: -------------------------------------------------------------------------------- 1 | use Mix.Config 2 | 3 | # The watchers configuration can be used to run external 4 | # watchers to your application. For example, we use it 5 | # with webpack to recompile .js and .css sources. 6 | config :pointing_party, PointingPartyWeb.Endpoint, 7 | http: [port: 4000], 8 | debug_errors: true, 9 | code_reloader: true, 10 | check_origin: false, 11 | watchers: [ 12 | node: [ 13 | "node_modules/webpack/bin/webpack.js", 14 | "--mode", 15 | "development", 16 | "--watch-stdin", 17 | cd: Path.expand("../assets", __DIR__) 18 | ] 19 | ] 20 | 21 | # ## SSL Support 22 | # 23 | # In order to use HTTPS in development, a self-signed 24 | # certificate can be generated by running the following 25 | # Mix task: 26 | # 27 | # mix phx.gen.cert 28 | # 29 | # Note that this task requires Erlang/OTP 20 or later. 30 | # Run `mix help phx.gen.cert` for more information. 31 | # 32 | # The `http:` config above can be replaced with: 33 | # 34 | # https: [ 35 | # port: 4001, 36 | # cipher_suite: :strong, 37 | # keyfile: "priv/cert/selfsigned_key.pem", 38 | # certfile: "priv/cert/selfsigned.pem" 39 | # ], 40 | # 41 | # If desired, both `http:` and `https:` keys can be 42 | # configured to run both http and https servers on 43 | # different ports. 44 | 45 | # Watch static and templates for browser reloading. 46 | config :pointing_party, PointingPartyWeb.Endpoint, 47 | live_reload: [ 48 | patterns: [ 49 | ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$", 50 | ~r"priv/gettext/.*(po)$", 51 | ~r"lib/pointing_party_web/{live,views}/.*(ex)$", 52 | ~r"lib/pointing_party_web/templates/.*(eex)$" 53 | ] 54 | ] 55 | 56 | # Do not include metadata nor timestamps in development logs 57 | config :logger, :console, format: "[$level] $message\n" 58 | 59 | # Set a higher stacktrace during development. Avoid configuring such 60 | # in production as building large stacktraces may be expensive. 61 | config :phoenix, :stacktrace_depth, 20 62 | 63 | # Initialize plugs at runtime for faster development compilation 64 | config :phoenix, :plug_init_mode, :runtime 65 | -------------------------------------------------------------------------------- /config/prod.exs: -------------------------------------------------------------------------------- 1 | use Mix.Config 2 | 3 | # For production, don't forget to configure the url host 4 | # to something meaningful, Phoenix uses this information 5 | # when generating URLs. 6 | # 7 | # Note we also include the path to a cache manifest 8 | # containing the digested version of static files. This 9 | # manifest is generated by the `mix phx.digest` task, 10 | # which you should run after static files are built and 11 | # before starting your production server. 12 | config :pointing_party, PointingPartyWeb.Endpoint, 13 | url: [host: "example.com", port: 80], 14 | cache_static_manifest: "priv/static/cache_manifest.json" 15 | 16 | # Do not print debug messages in production 17 | config :logger, level: :info 18 | 19 | # ## SSL Support 20 | # 21 | # To get SSL working, you will need to add the `https` key 22 | # to the previous section and set your `:url` port to 443: 23 | # 24 | # config :pointing_party, PointingPartyWeb.Endpoint, 25 | # ... 26 | # url: [host: "example.com", port: 443], 27 | # https: [ 28 | # :inet6, 29 | # port: 443, 30 | # cipher_suite: :strong, 31 | # keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"), 32 | # certfile: System.get_env("SOME_APP_SSL_CERT_PATH") 33 | # ] 34 | # 35 | # The `cipher_suite` is set to `:strong` to support only the 36 | # latest and more secure SSL ciphers. This means old browsers 37 | # and clients may not be supported. You can set it to 38 | # `:compatible` for wider support. 39 | # 40 | # `:keyfile` and `:certfile` expect an absolute path to the key 41 | # and cert in disk or a relative path inside priv, for example 42 | # "priv/ssl/server.key". For all supported SSL configuration 43 | # options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1 44 | # 45 | # We also recommend setting `force_ssl` in your endpoint, ensuring 46 | # no data is ever sent via http, always redirecting to https: 47 | # 48 | # config :pointing_party, PointingPartyWeb.Endpoint, 49 | # force_ssl: [hsts: true] 50 | # 51 | # Check `Plug.SSL` for all available options in `force_ssl`. 52 | 53 | # Finally import the config/prod.secret.exs which loads secrets 54 | # and configuration from environment variables. 55 | import_config "prod.secret.exs" 56 | -------------------------------------------------------------------------------- /config/test.exs: -------------------------------------------------------------------------------- 1 | use Mix.Config 2 | 3 | # We don't run a server during test. If one is required, 4 | # you can enable the server option below. 5 | config :pointing_party, PointingPartyWeb.Endpoint, 6 | http: [port: 4002], 7 | server: false 8 | 9 | # Print only warnings and errors during test 10 | config :logger, level: :warn 11 | -------------------------------------------------------------------------------- /lib/pointing_party.ex: -------------------------------------------------------------------------------- 1 | defmodule PointingParty do 2 | @moduledoc """ 3 | PointingParty keeps the contexts that define your domain 4 | and business logic. 5 | 6 | Contexts are also responsible for managing your data, regardless 7 | if it comes from the database, an external API or others. 8 | """ 9 | end 10 | -------------------------------------------------------------------------------- /lib/pointing_party/account.ex: -------------------------------------------------------------------------------- 1 | defmodule PointingParty.Account do 2 | use Ecto.Schema 3 | 4 | import Ecto.Changeset 5 | 6 | alias PointingParty.Account 7 | 8 | schema "accounts" do 9 | field :username, :string 10 | end 11 | 12 | def create(attrs) do 13 | changeset = changeset(%Account{}, attrs) 14 | 15 | if changeset.valid? do 16 | account = apply_changes(changeset) 17 | {:ok, account} 18 | else 19 | {:error, %{changeset | action: :insert}} 20 | end 21 | end 22 | 23 | def changeset(account, attrs \\ %{}) do 24 | account 25 | |> cast(attrs, [:username]) 26 | |> validate_required([:username]) 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /lib/pointing_party/account/auth.ex: -------------------------------------------------------------------------------- 1 | defmodule PointingParty.Account.Auth do 2 | alias PointingParty.Account 3 | 4 | def login(params) do 5 | Account.create(params) 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/pointing_party/application.ex: -------------------------------------------------------------------------------- 1 | defmodule PointingParty.Application do 2 | # See https://hexdocs.pm/elixir/Application.html 3 | # for more information on OTP Applications 4 | @moduledoc false 5 | 6 | use Application 7 | 8 | def start(_type, _args) do 9 | children = [ 10 | PointingPartyWeb.Endpoint, 11 | PointingPartyWeb.Presence 12 | ] 13 | 14 | # See https://hexdocs.pm/elixir/Supervisor.html 15 | # for other strategies and supported options 16 | opts = [strategy: :one_for_one, name: PointingParty.Supervisor] 17 | Supervisor.start_link(children, opts) 18 | end 19 | 20 | # Tell Phoenix to update the endpoint configuration 21 | # whenever the application is updated. 22 | def config_change(changed, _new, removed) do 23 | PointingPartyWeb.Endpoint.config_change(changed, removed) 24 | :ok 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /lib/pointing_party/card.ex: -------------------------------------------------------------------------------- 1 | defmodule PointingParty.Card do 2 | use Ecto.Schema 3 | 4 | import Ecto.Changeset 5 | 6 | @pointing_scale [0, 1, 3, 5] 7 | 8 | schema "cards" do 9 | field :description, :string 10 | field :points, :integer 11 | field :title, :string 12 | 13 | timestamps() 14 | end 15 | 16 | def changeset(card, attrs) do 17 | card 18 | |> cast(attrs, [:title, :description, :points]) 19 | |> validate_required([:title, :description]) 20 | |> validate_inclusion(:points, @pointing_scale) 21 | end 22 | 23 | def cards do 24 | :pointing_party 25 | |> Application.get_env(:cards) 26 | |> Enum.map(&struct(__MODULE__, &1)) 27 | end 28 | 29 | def points_range, do: @pointing_scale 30 | end 31 | -------------------------------------------------------------------------------- /lib/pointing_party/vote_calculator.ex: -------------------------------------------------------------------------------- 1 | defmodule PointingParty.VoteCalculator do 2 | def calculate_votes(users) do 3 | case winning_vote(users) do 4 | top_two when is_list(top_two) -> {"tie", top_two} 5 | winner -> {"winner", winner} 6 | end 7 | end 8 | 9 | def winning_vote(users) do 10 | initial_score_card() 11 | |> get_points(users) 12 | |> calculate_vote_ratios() 13 | |> calculate_majority() 14 | |> handle_tie() 15 | end 16 | 17 | def initial_score_card do 18 | %{votes: nil, calculated_votes: nil, majority: nil} 19 | end 20 | 21 | defp get_points(score_card, users) do 22 | votes = Enum.map(users, fn {_username, %{metas: [%{points: points}]}} -> points end) 23 | 24 | update_score_card(score_card, :votes, votes) 25 | end 26 | 27 | defp calculate_vote_ratios(%{votes: votes} = score_card) do 28 | calculated_votes = 29 | Enum.reduce(votes, %{}, fn vote, acc -> 30 | acc 31 | |> Map.get_and_update(vote, &{&1, (&1 || 0) + 1}) 32 | |> elem(1) 33 | end) 34 | 35 | update_score_card(score_card, :calculated_votes, calculated_votes) 36 | end 37 | 38 | defp calculate_majority(score_card) do 39 | total_votes = length(score_card.votes) 40 | majority_share = (total_votes / 2) |> Float.floor() 41 | 42 | majority = 43 | Enum.reduce_while(score_card.calculated_votes, nil, fn {point, vote_count}, _acc -> 44 | if vote_count == total_votes or rem(vote_count, total_votes) > majority_share do 45 | {:halt, point} 46 | else 47 | {:cont, nil} 48 | end 49 | end) 50 | 51 | update_score_card(score_card, :majority, majority) 52 | end 53 | 54 | defp handle_tie(%{majority: nil, calculated_votes: calculated_votes}) do 55 | calculated_votes 56 | |> Enum.sort_by(&elem(&1, 1), &>=/2) 57 | |> Enum.map(&elem(&1, 0)) 58 | |> Enum.sort() 59 | |> Enum.take(2) 60 | end 61 | 62 | defp handle_tie(%{majority: majority}), do: majority 63 | 64 | defp update_score_card(score_card, key, value) do 65 | Map.put(score_card, key, value) 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /lib/pointing_party_web.ex: -------------------------------------------------------------------------------- 1 | defmodule PointingPartyWeb do 2 | @moduledoc """ 3 | The entrypoint for defining your web interface, such 4 | as controllers, views, channels and so on. 5 | 6 | This can be used in your application as: 7 | 8 | use PointingPartyWeb, :controller 9 | use PointingPartyWeb, :view 10 | 11 | The definitions below will be executed for every view, 12 | controller, etc, so keep them short and clean, focused 13 | on imports, uses and aliases. 14 | 15 | Do NOT define functions inside the quoted expressions 16 | below. Instead, define any helper function in modules 17 | and import those modules here. 18 | """ 19 | 20 | def controller do 21 | quote do 22 | use Phoenix.Controller, namespace: PointingPartyWeb 23 | 24 | import Plug.Conn 25 | import PointingPartyWeb.Gettext 26 | alias PointingPartyWeb.Router.Helpers, as: Routes 27 | end 28 | end 29 | 30 | def view do 31 | quote do 32 | use Phoenix.View, 33 | root: "lib/pointing_party_web/templates", 34 | namespace: PointingPartyWeb 35 | 36 | # Import convenience functions from controllers 37 | import Phoenix.Controller, only: [get_flash: 1, get_flash: 2, view_module: 1] 38 | 39 | # Use all HTML functionality (forms, tags, etc) 40 | use Phoenix.HTML 41 | 42 | import PointingPartyWeb.ErrorHelpers 43 | import PointingPartyWeb.LayoutHelpers 44 | import PointingPartyWeb.Gettext 45 | alias PointingPartyWeb.Router.Helpers, as: Routes 46 | end 47 | end 48 | 49 | def router do 50 | quote do 51 | use Phoenix.Router 52 | import Plug.Conn 53 | import Phoenix.Controller 54 | end 55 | end 56 | 57 | def channel do 58 | quote do 59 | use Phoenix.Channel 60 | import PointingPartyWeb.Gettext 61 | end 62 | end 63 | 64 | @doc """ 65 | When used, dispatch to the appropriate controller/view/etc. 66 | """ 67 | defmacro __using__(which) when is_atom(which) do 68 | apply(__MODULE__, which, []) 69 | end 70 | end 71 | -------------------------------------------------------------------------------- /lib/pointing_party_web/channels/presence.ex: -------------------------------------------------------------------------------- 1 | defmodule PointingPartyWeb.Presence do 2 | use Phoenix.Presence, otp_app: :pointing_party, 3 | pubsub_server: PointingParty.PubSub 4 | end 5 | -------------------------------------------------------------------------------- /lib/pointing_party_web/channels/room_channel.ex: -------------------------------------------------------------------------------- 1 | defmodule PointingPartyWeb.RoomChannel do 2 | use PointingPartyWeb, :channel 3 | 4 | alias PointingParty.Card 5 | 6 | def join("room:lobby", _payload, socket) do 7 | send(self(), :after_join) 8 | 9 | {:ok, socket} 10 | end 11 | 12 | def handle_info(:after_join, socket) do 13 | # handle Presence listing and tracking here 14 | 15 | {:noreply, socket} 16 | end 17 | 18 | def handle_in("start_pointing", _params, socket) do 19 | updated_socket = initialize_state(socket) 20 | # broadcast the "new_card" message with a payload of %{card: current_card} 21 | 22 | {:reply, :ok, updated_socket} 23 | end 24 | 25 | def handle_in("user_estimated", %{"points" => points}, socket) do 26 | # update votes for user presence 27 | # if everyone voted, calculate story point estimate with the help of the VoteCalculator 28 | # broadcast the 'winner'/'tie' event with a payload of %{points: points} 29 | 30 | {:noreply, socket} 31 | end 32 | 33 | def handle_in("next_card", %{"points" => points}, socket) do 34 | save_vote_next_card(points, socket) 35 | # broadcast the "new_card" message with a payload of %{card: new_current_card} 36 | 37 | {:reply, :ok, socket} 38 | end 39 | 40 | defp initialize_state(%{assigns: %{cards: _cards}} = socket), do: socket 41 | 42 | defp initialize_state(socket) do 43 | [first | cards] = Card.cards() 44 | 45 | socket 46 | |> assign(:unvoted, cards) 47 | |> assign(:current, first) 48 | end 49 | 50 | defp save_vote_next_card(points, socket) do 51 | # save the points on the card 52 | latest_card = 53 | socket.assigns 54 | |> Map.get(:current) 55 | |> Map.put(:points, points) 56 | 57 | # fetch the next card from the list of cards 58 | {next, remaining} = 59 | socket.assigns 60 | |> Map.get(:unvoted) 61 | |> List.pop_at(0) 62 | 63 | # update socket state by moving the current card into `voted` and the next card into `current_card` 64 | socket 65 | |> assign(:unvoted, remaining) 66 | |> assign(:current, next) 67 | |> assign(:voted, [latest_card | socket.assigns[:voted]]) 68 | end 69 | end 70 | -------------------------------------------------------------------------------- /lib/pointing_party_web/channels/user_socket.ex: -------------------------------------------------------------------------------- 1 | defmodule PointingPartyWeb.UserSocket do 2 | use Phoenix.Socket 3 | 4 | ## Channels 5 | channel "room:lobby", PointingPartyWeb.RoomChannel 6 | 7 | # Socket params are passed from the client and can 8 | # be used to verify and authenticate a user. After 9 | # verification, you can put default assigns into 10 | # the socket that will be set for all channels, ie 11 | # 12 | # {:ok, assign(socket, :user_id, verified_user_id)} 13 | # 14 | # To deny connection, return `:error`. 15 | # 16 | # See `Phoenix.Token` documentation for examples in 17 | # performing token verification on connect. 18 | def connect(_params, socket, _connect_info) do 19 | {:ok, socket} 20 | end 21 | 22 | # Socket id's are topics that allow you to identify all sockets for a given user: 23 | # 24 | # def id(socket), do: "user_socket:#{socket.assigns.user_id}" 25 | # 26 | # Would allow you to broadcast a "disconnect" event and terminate 27 | # all active sockets and channels for a given user: 28 | # 29 | # PointingPartyWeb.Endpoint.broadcast("user_socket:#{user.id}", "disconnect", %{}) 30 | # 31 | # Returning `nil` makes this socket anonymous. 32 | def id(_socket), do: nil 33 | end 34 | -------------------------------------------------------------------------------- /lib/pointing_party_web/controllers/card_controller.ex: -------------------------------------------------------------------------------- 1 | defmodule PointingPartyWeb.CardController do 2 | use PointingPartyWeb, :controller 3 | 4 | def index(conn, _params) do 5 | render(conn, "index.html") 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/pointing_party_web/controllers/page_controller.ex: -------------------------------------------------------------------------------- 1 | defmodule PointingPartyWeb.PageController do 2 | use PointingPartyWeb, :controller 3 | 4 | def index(conn, _params) do 5 | render(conn, "index.html") 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/pointing_party_web/controllers/session_controller.ex: -------------------------------------------------------------------------------- 1 | defmodule PointingPartyWeb.SessionController do 2 | use PointingPartyWeb, :controller 3 | 4 | alias PointingParty.{Account, Account.Auth} 5 | 6 | def new(conn, _params) do 7 | changeset = Account.changeset(%Account{}) 8 | render(conn, "new.html", changeset: changeset) 9 | end 10 | 11 | def create(conn, params) do 12 | case Auth.login(params["account"]) do 13 | {:ok, %{username: username}} -> 14 | conn 15 | |> put_session(:username, username) 16 | |> redirect(to: "/cards") 17 | |> halt() 18 | 19 | {:error, changeset} -> 20 | render(conn, "new.html", changeset: changeset) 21 | end 22 | end 23 | 24 | def delete(conn, _params) do 25 | conn 26 | |> clear_session() 27 | |> redirect(to: "/login") 28 | |> halt() 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /lib/pointing_party_web/endpoint.ex: -------------------------------------------------------------------------------- 1 | defmodule PointingPartyWeb.Endpoint do 2 | use Phoenix.Endpoint, otp_app: :pointing_party 3 | 4 | socket "/socket", PointingPartyWeb.UserSocket, 5 | websocket: true, 6 | longpoll: false 7 | 8 | # Serve at "/" the static files from "priv/static" directory. 9 | # 10 | # You should set gzip to true if you are running phx.digest 11 | # when deploying your static files in production. 12 | plug Plug.Static, 13 | at: "/", 14 | from: :pointing_party, 15 | gzip: false, 16 | only: ~w(css fonts images js favicon.ico robots.txt) 17 | 18 | # Code reloading can be explicitly enabled under the 19 | # :code_reloader configuration of your endpoint. 20 | if code_reloading? do 21 | socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket 22 | plug Phoenix.LiveReloader 23 | plug Phoenix.CodeReloader 24 | end 25 | 26 | plug Plug.RequestId 27 | plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint] 28 | 29 | plug Plug.Parsers, 30 | parsers: [:urlencoded, :multipart, :json], 31 | pass: ["*/*"], 32 | json_decoder: Phoenix.json_library() 33 | 34 | plug Plug.MethodOverride 35 | plug Plug.Head 36 | 37 | # The session will be stored in the cookie and signed, 38 | # this means its contents can be read but not tampered with. 39 | # Set :encryption_salt if you would also like to encrypt it. 40 | plug Plug.Session, 41 | store: :cookie, 42 | key: "_pointing_party_key", 43 | signing_salt: "ZiaHWw6D" 44 | 45 | plug PointingPartyWeb.Router 46 | end 47 | -------------------------------------------------------------------------------- /lib/pointing_party_web/gettext.ex: -------------------------------------------------------------------------------- 1 | defmodule PointingPartyWeb.Gettext do 2 | @moduledoc """ 3 | A module providing Internationalization with a gettext-based API. 4 | 5 | By using [Gettext](https://hexdocs.pm/gettext), 6 | your module gains a set of macros for translations, for example: 7 | 8 | import PointingPartyWeb.Gettext 9 | 10 | # Simple translation 11 | gettext("Here is the string to translate") 12 | 13 | # Plural translation 14 | ngettext("Here is the string to translate", 15 | "Here are the strings to translate", 16 | 3) 17 | 18 | # Domain-based translation 19 | dgettext("errors", "Here is the error message to translate") 20 | 21 | See the [Gettext Docs](https://hexdocs.pm/gettext) for detailed usage. 22 | """ 23 | use Gettext, otp_app: :pointing_party 24 | end 25 | -------------------------------------------------------------------------------- /lib/pointing_party_web/plugs/auth.ex: -------------------------------------------------------------------------------- 1 | defmodule PointingPartyWeb.Plugs.Auth do 2 | import Plug.Conn 3 | import Phoenix.Controller 4 | 5 | def init(default), do: default 6 | 7 | def call(conn, _default) do 8 | case authenticate(conn) do 9 | nil -> 10 | conn 11 | |> redirect(to: "/login") 12 | |> halt() 13 | 14 | username -> 15 | assign(conn, :username, username) 16 | end 17 | end 18 | 19 | defp authenticate(conn) do 20 | get_session(conn, :username) 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /lib/pointing_party_web/router.ex: -------------------------------------------------------------------------------- 1 | defmodule PointingPartyWeb.Router do 2 | use PointingPartyWeb, :router 3 | 4 | pipeline :browser do 5 | plug :accepts, ["html"] 6 | plug :fetch_session 7 | plug :fetch_flash 8 | plug :protect_from_forgery 9 | plug :put_secure_browser_headers 10 | end 11 | 12 | pipeline :api do 13 | plug :accepts, ["json"] 14 | end 15 | 16 | scope "/", PointingPartyWeb do 17 | pipe_through :browser 18 | get "/login", SessionController, :new 19 | post "/login", SessionController, :create 20 | delete "/logout", SessionController, :delete 21 | get "/", PageController, :index 22 | end 23 | 24 | scope "/", PointingPartyWeb do 25 | pipe_through [:browser, PointingPartyWeb.Plugs.Auth] 26 | get "/cards", CardController, :index 27 | end 28 | 29 | # Other scopes may use custom stacks. 30 | # scope "/api", PointingPartyWeb do 31 | # pipe_through :api 32 | # end 33 | end 34 | -------------------------------------------------------------------------------- /lib/pointing_party_web/templates/card/index.html.eex: -------------------------------------------------------------------------------- 1 |
<%= get_flash(@conn, :info) %>
32 |<%= get_flash(@conn, :error) %>
33 | <%= render @view_module, @view_template, assigns %> 34 |A ticket estimation tool backed by the awesome real-time power of Phoenix.
4 |